feat(dify): 添加 Docker 支持并进行代码优化
- 添加 Dockerfile 以支持 Docker部署 - 更新 Maven 配置,添加 Docker 插件- 优化部分代码结构,提高可维护性 - 新增消息列表查询功能 - 修复用户密码编码问题
This commit is contained in:
parent
cdf5842f01
commit
92ff130b0d
7
Dockerfile
Normal file
7
Dockerfile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
FROM openjdk:17
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
VOLUME /tmp
|
||||||
|
ADD target/dify-backend-0.0.1-SNAPSHOT.jar /app.jar
|
||||||
|
RUN bash -c 'touch /app.jar'
|
||||||
|
ENTRYPOINT ["java","-jar","/app.jar"]
|
51
pom.xml
51
pom.xml
@ -9,7 +9,7 @@
|
|||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.zsc.edu</groupId>
|
<groupId>com.zsc.edu</groupId>
|
||||||
<artifactId>dify</artifactId>
|
<artifactId>dify-backend</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>dify-backend</name>
|
<name>dify-backend</name>
|
||||||
<description>dify-backend</description>
|
<description>dify-backend</description>
|
||||||
@ -31,6 +31,7 @@
|
|||||||
<mybatis-plus.version>3.5.11</mybatis-plus.version>
|
<mybatis-plus.version>3.5.11</mybatis-plus.version>
|
||||||
<mapstruct.version>1.6.2</mapstruct.version>
|
<mapstruct.version>1.6.2</mapstruct.version>
|
||||||
<fastjson.version>2.0.53</fastjson.version>
|
<fastjson.version>2.0.53</fastjson.version>
|
||||||
|
<docker-maven-plugin.version>0.44.0</docker-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<!-- <dependency>-->
|
<!-- <dependency>-->
|
||||||
@ -96,7 +97,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
<scope>42.6</scope>
|
<version>42.7.3</version> <!-- 使用最新版本 -->
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
@ -118,16 +119,6 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
|
||||||
<!-- <artifactId>spring-boot-starter-data-r2dbc</artifactId>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<!-- <dependency>-->
|
|
||||||
<!-- <groupId>io.r2dbc</groupId>-->
|
|
||||||
<!-- <artifactId>r2dbc-postgresql</artifactId>-->
|
|
||||||
<!-- <version>0.8.13.RELEASE</version>-->
|
|
||||||
<!-- </dependency>-->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mapstruct</groupId>
|
<groupId>org.mapstruct</groupId>
|
||||||
<artifactId>mapstruct</artifactId>
|
<artifactId>mapstruct</artifactId>
|
||||||
@ -230,6 +221,42 @@
|
|||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>io.fabric8</groupId>
|
||||||
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
|
<version>${docker-maven-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>docker-build</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>build</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<!-- <dockerHost>tcp://127.0.0.1:2375</dockerHost>-->
|
||||||
|
<pushRegistry>registry.cn-hangzhou.aliyuncs.com</pushRegistry>
|
||||||
|
<authConfig>
|
||||||
|
<username>vertoryao</username>
|
||||||
|
<password>71127217311Yao</password>
|
||||||
|
</authConfig>
|
||||||
|
<images>
|
||||||
|
<image>
|
||||||
|
<!-- <name>harry_yao/${project.artifactId}:${project.version}</name>-->
|
||||||
|
<name>registry.cn-hangzhou.aliyuncs.com/harry_yao/${project.artifactId}:latest</name>
|
||||||
|
<registry>registry.cn-hangzhou.aliyuncs.com/harry_yao/${project.artifactId}</registry>
|
||||||
|
<build>
|
||||||
|
<dockerFile>${project.basedir}/Dockerfile</dockerFile>
|
||||||
|
</build>
|
||||||
|
</image>
|
||||||
|
</images>
|
||||||
|
<buildArgs>
|
||||||
|
<JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE>
|
||||||
|
</buildArgs>
|
||||||
|
</configuration>
|
||||||
|
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ public class CustomAccessDeniedHandler implements AccessDeniedHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(HttpServletRequest request, HttpServletResponse response,
|
public void handle(HttpServletRequest request, HttpServletResponse response,
|
||||||
AccessDeniedException ex) throws IOException, ServletException {
|
AccessDeniedException ex) throws IOException, ServletException {
|
||||||
|
ex.printStackTrace();
|
||||||
response.setContentType("application/json;charset=utf-8");
|
response.setContentType("application/json;charset=utf-8");
|
||||||
ExceptionResult result;
|
ExceptionResult result;
|
||||||
if (ex instanceof MissingCsrfTokenException) {
|
if (ex instanceof MissingCsrfTokenException) {
|
||||||
|
@ -9,10 +9,12 @@ import com.zsc.edu.dify.modules.system.service.UserService;
|
|||||||
import io.github.guoshiqiufeng.dify.chat.DifyChat;
|
import io.github.guoshiqiufeng.dify.chat.DifyChat;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
|
import io.github.guoshiqiufeng.dify.chat.dto.request.ChatMessageSendRequest;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.request.MessageConversationsRequest;
|
import io.github.guoshiqiufeng.dify.chat.dto.request.MessageConversationsRequest;
|
||||||
|
import io.github.guoshiqiufeng.dify.chat.dto.request.MessagesRequest;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
|
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendCompletionResponse;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendResponse;
|
import io.github.guoshiqiufeng.dify.chat.dto.response.ChatMessageSendResponse;
|
||||||
import io.github.guoshiqiufeng.dify.chat.dto.response.MessageConversationsResponse;
|
import io.github.guoshiqiufeng.dify.chat.dto.response.MessageConversationsResponse;
|
||||||
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
import io.github.guoshiqiufeng.dify.core.pojo.DifyPageResult;
|
||||||
|
import io.github.guoshiqiufeng.dify.core.pojo.response.MessagesResponseVO;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -86,6 +88,22 @@ public class V1ChatController {
|
|||||||
request.setUserId(SecurityUtil.getUserInfo().id.toString());
|
request.setUserId(SecurityUtil.getUserInfo().id.toString());
|
||||||
return difyChat.conversations(request);
|
return difyChat.conversations(request);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 获取会话的消息列表
|
||||||
|
*
|
||||||
|
* @param request 请求参数
|
||||||
|
* @return 消息列表
|
||||||
|
*/
|
||||||
|
@PostMapping("/messages/{appid}")
|
||||||
|
@PreAuthorize("hasAuthority('dify:chat:query')")
|
||||||
|
public DifyPageResult<MessagesResponseVO> conversations(
|
||||||
|
@RequestBody MessagesRequest request,
|
||||||
|
@PathVariable String appid
|
||||||
|
) {
|
||||||
|
String apiKey = appEntityService.getApikey(appid);
|
||||||
|
request.setApiKey(apiKey);
|
||||||
|
return difyChat.messages(request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 停止流式消息
|
* 停止流式消息
|
||||||
|
@ -31,7 +31,7 @@ public class RoleController {
|
|||||||
*
|
*
|
||||||
* @return 所有角色列表
|
* @return 所有角色列表
|
||||||
*/
|
*/
|
||||||
@DataPermission
|
// @DataPermission
|
||||||
@GetMapping
|
@GetMapping
|
||||||
@PreAuthorize("hasAuthority('system:role:query')")
|
@PreAuthorize("hasAuthority('system:role:query')")
|
||||||
public Page<Role> query(RoleQuery query, Page<Role> page) {
|
public Page<Role> query(RoleQuery query, Page<Role> page) {
|
||||||
|
@ -53,6 +53,7 @@ public class UserServiceImpl extends ServiceImpl<UserRepository, User> implement
|
|||||||
dto.setRoleId(dto.getRoleIds().get(0));
|
dto.setRoleId(dto.getRoleIds().get(0));
|
||||||
userMapper.convert(dto, user);
|
userMapper.convert(dto, user);
|
||||||
user.setName(dto.getName());
|
user.setName(dto.getName());
|
||||||
|
user.setPassword(passwordEncoder.encode(dto.password));
|
||||||
boolean existsByPhone = count(new LambdaQueryWrapper<User>().eq(User::getPhone, dto.getPhone())) > 0;
|
boolean existsByPhone = count(new LambdaQueryWrapper<User>().eq(User::getPhone, dto.getPhone())) > 0;
|
||||||
boolean existsByEmail = count(new LambdaQueryWrapper<User>().eq(User::getEmail, dto.getEmail())) > 0;
|
boolean existsByEmail = count(new LambdaQueryWrapper<User>().eq(User::getEmail, dto.getEmail())) > 0;
|
||||||
if (user.getPhone().equals(dto.getPhone()) && existsByPhone) {
|
if (user.getPhone().equals(dto.getPhone()) && existsByPhone) {
|
||||||
|
@ -93,8 +93,7 @@ class DeptServiceTest {
|
|||||||
assertEquals(tmp.getId(), dept2.id);
|
assertEquals(tmp.getId(), dept2.id);
|
||||||
// 不能改为其他已存在的同名同代码部门
|
// 不能改为其他已存在的同名同代码部门
|
||||||
assertThrows(ConstraintException.class,
|
assertThrows(ConstraintException.class,
|
||||||
() -> service.edit(
|
() -> service.edit(new DeptDto(dept3.getName(), true, "remark",null), dept2.id));
|
||||||
new DeptDto(dept3.getName(), "remark",null), dept2.id));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class RoleServiceTest {
|
|||||||
assertNotNull(Role.getId());
|
assertNotNull(Role.getId());
|
||||||
assertEquals(3, service.list(new QueryWrapper<Role>().like("name", "A")).size());
|
assertEquals(3, service.list(new QueryWrapper<Role>().like("name", "A")).size());
|
||||||
// 不能创建其他已存在的同名同代码部门
|
// 不能创建其他已存在的同名同代码部门
|
||||||
assertThrows(ConstraintException.class, () -> service.create(new RoleDto(role1.getName(), "remark...", null)));
|
assertThrows(ConstraintException.class, () -> service.create(new RoleDto(role1.getName(), true,"remark...", null)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -79,7 +79,7 @@ public class UserServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
void update() {
|
void update() {
|
||||||
UserUpdateDto dto = new UserUpdateDto();
|
UserUpdateDto dto = new UserUpdateDto();
|
||||||
dto.setEnable(false);
|
dto.setEnableState(false);
|
||||||
dto.setRemark("remark...");
|
dto.setRemark("remark...");
|
||||||
dto.setPhone("16786899221");
|
dto.setPhone("16786899221");
|
||||||
dto.setEmail("@abc.com");
|
dto.setEmail("@abc.com");
|
||||||
|
Loading…
Reference in New Issue
Block a user