From 7f5a1615b34fd96e354dca4ce495b899a32a7a60 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 10:29:22 +0800 Subject: [PATCH 01/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/mapper/primary/entity/ChatMessage.java | 2 + .../model/dto/ReceiveCollectionElement.java | 1 + .../com/ai/da/model/vo/ChatMessageVO.java | 8 ++ .../ai/da/service/impl/LLMServiceImpl.java | 108 ++++++++++++++---- 4 files changed, 94 insertions(+), 25 deletions(-) create mode 100644 src/main/java/com/ai/da/model/vo/ChatMessageVO.java diff --git a/src/main/java/com/ai/da/mapper/primary/entity/ChatMessage.java b/src/main/java/com/ai/da/mapper/primary/entity/ChatMessage.java index b1886773..70859881 100644 --- a/src/main/java/com/ai/da/mapper/primary/entity/ChatMessage.java +++ b/src/main/java/com/ai/da/mapper/primary/entity/ChatMessage.java @@ -31,5 +31,7 @@ public class ChatMessage implements Serializable { private Long accountId; + private Integer isImage; + private LocalDateTime createTime; } diff --git a/src/main/java/com/ai/da/model/dto/ReceiveCollectionElement.java b/src/main/java/com/ai/da/model/dto/ReceiveCollectionElement.java index ab6f257b..3c980a3c 100644 --- a/src/main/java/com/ai/da/model/dto/ReceiveCollectionElement.java +++ b/src/main/java/com/ai/da/model/dto/ReceiveCollectionElement.java @@ -9,4 +9,5 @@ public class ReceiveCollectionElement { private String level2Type; private String rgb; private String hsv; + private String minioUrl; } diff --git a/src/main/java/com/ai/da/model/vo/ChatMessageVO.java b/src/main/java/com/ai/da/model/vo/ChatMessageVO.java new file mode 100644 index 00000000..db179a62 --- /dev/null +++ b/src/main/java/com/ai/da/model/vo/ChatMessageVO.java @@ -0,0 +1,8 @@ +package com.ai.da.model.vo; + +import com.ai.da.mapper.primary.entity.ChatMessage; +import lombok.Data; + +@Data +public class ChatMessageVO extends ChatMessage { +} diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 68717832..dc8ef5c2 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -9,6 +9,7 @@ import com.ai.da.common.utils.MinioUtil; import com.ai.da.mapper.primary.*; import com.ai.da.mapper.primary.entity.*; import com.ai.da.model.dto.ChatHistoryDTO; +import com.ai.da.model.dto.ReceiveCollectionElement; import com.ai.da.model.dto.ReceiveDesignParam; import com.ai.da.model.enums.*; import com.ai.da.model.vo.AuthPrincipalVo; @@ -22,6 +23,7 @@ import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; @@ -77,16 +79,18 @@ public class LLMServiceImpl implements LLMService { AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token); Long accountId = principal.getId(); int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号 - String url = "http://18.167.251.121:10002/chat-stream"; + String url = "http://18.167.251.121:2011/chat-stream"; +// String url = "http://10.1.1.240:1013/chat-stream"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("POST"); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/json"); JSONObject jsonBodyObject = new JSONObject(); - jsonBodyObject.put("session_id", projectId.toString()); + jsonBodyObject.put("project_id", projectId.toString()); jsonBodyObject.put("role", "user"); - jsonBodyObject.put("image", imageUrlList); // 可扩展 +// jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : ""); // 可扩展 + jsonBodyObject.put("image", ""); // 可扩展 jsonBodyObject.put("file", fileUrl != null ? fileUrl : ""); jsonBodyObject.put("message", prompt); jsonBodyObject.put("enable_thinking", false); @@ -107,7 +111,18 @@ public class LLMServiceImpl implements LLMService { } // 2. 流式接收并累积内容 - StringBuilder responseBuilder = new StringBuilder(); + // 3. 存储系统回复 + int systemSeq = getNextSeq(projectId); + ChatMessage systemMessage = new ChatMessage(); + systemMessage.setRole("system"); + systemMessage.setIsImage(0); + systemMessage.setProjectId(projectId); + systemMessage.setSeq(systemSeq); +// systemMessage.setCreateTime(LocalDateTime.now()); +// systemMessage.setContent(responseBuilder.toString()); + systemMessage.setAccountId(accountId); +// chatMessageMapper.insert(systemMessage); + StringBuilder responseContentBuilder = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { @@ -117,42 +132,65 @@ public class LLMServiceImpl implements LLMService { System.out.println(jsonStr); JSONObject json = JSON.parseObject(jsonStr); String status = json.getString("status"); - - if ("[DONE]".equals(status)) { - break; - } - if (!StringUtils.isEmpty(status)) { String content = json.getString("content"); - if (!status.equals("[RUNNING]") && !status.equals("[DESIGN_SIGNAL]")) { + // 结束标识 + if ("[DONE]".equals(status)) { + break; + }else if ("[RUNNING]".equals(status)) { + if (content.startsWith("\n[TOOL_CALL]") || content.startsWith("\n[TOOL_RESPONSE]")) { + // 不发送不存储 + }else { + responseContentBuilder.append(content); + emitter.send(json.toJSONString()); + } + }else { + if (responseContentBuilder.length() != 0) { + systemMessage.setCreateTime(LocalDateTime.now()); + systemMessage.setContent(responseContentBuilder.toString()); + chatMessageMapper.insert(systemMessage); + systemMessage.setId(null); + systemMessage.setSeq(getNextSeq(projectId)); + responseContentBuilder = new StringBuilder(); + } JSONObject toolsData = json.getJSONObject("tools_data"); ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); receiveDesignParam.setProjectId(projectId); designService.receiveDesignParams(receiveDesignParam); - } - if (content != null) { - responseBuilder.append(content); + for (ReceiveCollectionElement receiveCollectionElement : receiveDesignParam.getReceiveCollectionElementList()) { + if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) { + receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); + } + } + String jsonString = JSONObject.toJSONString(receiveDesignParam); + json.put("tools_data", jsonString); + + ChatMessage systemImage = new ChatMessage(); + systemImage.setRole("system"); + systemImage.setIsImage(1); + systemImage.setProjectId(projectId); + systemImage.setSeq(getNextSeq(projectId)); + systemImage.setCreateTime(LocalDateTime.now()); + systemImage.setContent(JSONObject.toJSONString(receiveDesignParam.getReceiveCollectionElementList())); + systemImage.setAccountId(accountId); + chatMessageMapper.insert(systemImage); + emitter.send(json.toJSONString()); } } } } + if (responseContentBuilder.length() != 0) { + systemMessage.setCreateTime(LocalDateTime.now()); + systemMessage.setContent(responseContentBuilder.toString()); + chatMessageMapper.insert(systemMessage); + } } - - // 3. 存储系统回复 - int systemSeq = getNextSeq(projectId); - ChatMessage systemMessage = new ChatMessage(); - systemMessage.setRole("user"); - systemMessage.setProjectId(projectId); - systemMessage.setSeq(systemSeq); - systemMessage.setCreateTime(LocalDateTime.now()); - systemMessage.setContent(responseBuilder.toString()); - systemMessage.setAccountId(accountId); - chatMessageMapper.insert(systemMessage); } emitter.complete(); } catch (Exception e) { + System.out.println("走进异常"); emitter.completeWithError(e); } }); @@ -274,9 +312,29 @@ public class LLMServiceImpl implements LLMService { @Override public PageBaseResponse getChatHistory(ChatHistoryDTO chatHistoryDTO) { QueryWrapper qw = new QueryWrapper<>(); - qw.lambda().eq(ChatMessage::getProjectId, chatHistoryDTO); + qw.lambda().eq(ChatMessage::getProjectId, chatHistoryDTO.getProjectId()); qw.lambda().orderByDesc(ChatMessage::getSeq); Page chatMessagePage = chatMessageMapper.selectPage(new Page<>(chatHistoryDTO.getPage(), chatHistoryDTO.getSize()), qw); + for (ChatMessage record : chatMessagePage.getRecords()) { + if (record.getIsImage() == 1) { + String content = record.getContent(); + List list = JSONObject.parseArray(content, ReceiveCollectionElement.class); + for (ReceiveCollectionElement receiveCollectionElement : list) { + if (StringUtils.isEmpty(receiveCollectionElement.getUrl())) { + receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); + } + } + record.setContent(JSONObject.toJSONString(list)); + } + if (record.getRole().equals("user")) { + String content = record.getContent(); + JSONObject jsonObject = JSONObject.parseObject(content); + String file = jsonObject.getString("file"); + if (!StringUtils.isEmpty(file)) { + jsonObject.put("file", minioUtil.getPreSignedUrl(file, 24 * 60)); + } + } + } return PageBaseResponse.success(chatMessagePage); } From cef2fca09976854e3280482ca09872f5ce04d4c0 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 10:39:00 +0800 Subject: [PATCH 02/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index dc8ef5c2..f9b1303c 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -79,7 +79,7 @@ public class LLMServiceImpl implements LLMService { AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token); Long accountId = principal.getId(); int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号 - String url = "http://18.167.251.121:2011/chat-stream"; + String url = "http://127.0.0.1:2011/chat-stream"; // String url = "http://10.1.1.240:1013/chat-stream"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("POST"); From ab804d57c12cf175d9763bda3ffe02b726779f76 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 10:42:18 +0800 Subject: [PATCH 03/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index f9b1303c..dc8ef5c2 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -79,7 +79,7 @@ public class LLMServiceImpl implements LLMService { AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token); Long accountId = principal.getId(); int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号 - String url = "http://127.0.0.1:2011/chat-stream"; + String url = "http://18.167.251.121:2011/chat-stream"; // String url = "http://10.1.1.240:1013/chat-stream"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("POST"); From a2625fa73f550c477d3639b71233d62bd5bf7ff9 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 11:24:02 +0800 Subject: [PATCH 04/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index dc8ef5c2..e4ed1a90 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -79,7 +79,7 @@ public class LLMServiceImpl implements LLMService { AuthPrincipalVo principal = jwtTokenHelper.parserToUser(token); Long accountId = principal.getId(); int userSeq = getNextSeq(projectId); // 获取当前session下一条消息序号 - String url = "http://18.167.251.121:2011/chat-stream"; + String url = "http://18.167.251.121:10002/chat-stream"; // String url = "http://10.1.1.240:1013/chat-stream"; HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); conn.setRequestMethod("POST"); From e9e40e53bc8ceb7ea0dc479e1f306b66ecb2acdc Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 13:16:57 +0800 Subject: [PATCH 05/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index e4ed1a90..34e632af 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -316,11 +316,11 @@ public class LLMServiceImpl implements LLMService { qw.lambda().orderByDesc(ChatMessage::getSeq); Page chatMessagePage = chatMessageMapper.selectPage(new Page<>(chatHistoryDTO.getPage(), chatHistoryDTO.getSize()), qw); for (ChatMessage record : chatMessagePage.getRecords()) { - if (record.getIsImage() == 1) { + if (record.getIsImage() != null && record.getIsImage() == 1) { String content = record.getContent(); List list = JSONObject.parseArray(content, ReceiveCollectionElement.class); for (ReceiveCollectionElement receiveCollectionElement : list) { - if (StringUtils.isEmpty(receiveCollectionElement.getUrl())) { + if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) { receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); } } From 16e4f7c5b5ce443dff84481456e19e935691d04b Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 13:37:46 +0800 Subject: [PATCH 06/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 34e632af..458742c5 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -112,12 +112,10 @@ public class LLMServiceImpl implements LLMService { // 2. 流式接收并累积内容 // 3. 存储系统回复 - int systemSeq = getNextSeq(projectId); ChatMessage systemMessage = new ChatMessage(); systemMessage.setRole("system"); systemMessage.setIsImage(0); systemMessage.setProjectId(projectId); - systemMessage.setSeq(systemSeq); // systemMessage.setCreateTime(LocalDateTime.now()); // systemMessage.setContent(responseBuilder.toString()); systemMessage.setAccountId(accountId); @@ -146,11 +144,11 @@ public class LLMServiceImpl implements LLMService { } }else { if (responseContentBuilder.length() != 0) { + systemMessage.setSeq(getNextSeq(projectId)); systemMessage.setCreateTime(LocalDateTime.now()); systemMessage.setContent(responseContentBuilder.toString()); chatMessageMapper.insert(systemMessage); systemMessage.setId(null); - systemMessage.setSeq(getNextSeq(projectId)); responseContentBuilder = new StringBuilder(); } JSONObject toolsData = json.getJSONObject("tools_data"); @@ -181,6 +179,7 @@ public class LLMServiceImpl implements LLMService { } } if (responseContentBuilder.length() != 0) { + systemMessage.setSeq(getNextSeq(projectId)); systemMessage.setCreateTime(LocalDateTime.now()); systemMessage.setContent(responseContentBuilder.toString()); chatMessageMapper.insert(systemMessage); From 4dfee09abb4b0caf19b5625d0f7db212a0e80c80 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 13:56:42 +0800 Subject: [PATCH 07/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 458742c5..9dc5c9a6 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -155,8 +155,10 @@ public class LLMServiceImpl implements LLMService { ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); receiveDesignParam.setProjectId(projectId); designService.receiveDesignParams(receiveDesignParam); + boolean color = true; for (ReceiveCollectionElement receiveCollectionElement : receiveDesignParam.getReceiveCollectionElementList()) { if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) { + color = false; receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); } } @@ -165,7 +167,11 @@ public class LLMServiceImpl implements LLMService { ChatMessage systemImage = new ChatMessage(); systemImage.setRole("system"); - systemImage.setIsImage(1); + if (color) { + systemImage.setIsImage(1); + }else { + systemImage.setIsImage(2); + } systemImage.setProjectId(projectId); systemImage.setSeq(getNextSeq(projectId)); systemImage.setCreateTime(LocalDateTime.now()); From f1adbb4da7254c3bc1dda2444a7a61ac0a9c9d70 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 14:24:16 +0800 Subject: [PATCH 08/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 9dc5c9a6..a806995b 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -306,7 +306,7 @@ public class LLMServiceImpl implements LLMService { @Override public List uploadFile(MultipartFile file) { AuthPrincipalVo userHolder = UserContext.getUserHolder(); - String minioUrl = minioUtil.upload("chat-message", userHolder.getId() + "", file); + String minioUrl = minioUtil.upload("chat-message", userHolder.getId() + "/" + file.getOriginalFilename(), file, null); String preSignedUrl = minioUtil.getPreSignedUrl(minioUrl, CommonConstant.MINIO_IMAGE_EXPIRE_TIME); List result = new ArrayList<>(); result.add(minioUrl); From b030e9c09be49bcd41c01aa844f8a74d074b5eda Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 14:31:05 +0800 Subject: [PATCH 09/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ai/da/service/impl/LLMServiceImpl.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index a806995b..5921a8a5 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -152,33 +152,33 @@ public class LLMServiceImpl implements LLMService { responseContentBuilder = new StringBuilder(); } JSONObject toolsData = json.getJSONObject("tools_data"); - ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); - receiveDesignParam.setProjectId(projectId); - designService.receiveDesignParams(receiveDesignParam); - boolean color = true; - for (ReceiveCollectionElement receiveCollectionElement : receiveDesignParam.getReceiveCollectionElementList()) { - if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) { - color = false; - receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); + if (Objects.nonNull(toolsData)) { + boolean color = true; + ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); + receiveDesignParam.setProjectId(projectId); + designService.receiveDesignParams(receiveDesignParam); + for (ReceiveCollectionElement receiveCollectionElement : receiveDesignParam.getReceiveCollectionElementList()) { + if (!StringUtils.isEmpty(receiveCollectionElement.getUrl())) { + color = false; + receiveCollectionElement.setMinioUrl(minioUtil.getPreSignedUrl(receiveCollectionElement.getUrl(), 24 * 60)); + } } + String jsonString = JSONObject.toJSONString(receiveDesignParam); + json.put("tools_data", jsonString); + ChatMessage systemImage = new ChatMessage(); + systemImage.setRole("system"); + if (color) { + systemImage.setIsImage(1); + }else { + systemImage.setIsImage(2); + } + systemImage.setProjectId(projectId); + systemImage.setSeq(getNextSeq(projectId)); + systemImage.setCreateTime(LocalDateTime.now()); + systemImage.setContent(JSONObject.toJSONString(receiveDesignParam.getReceiveCollectionElementList())); + systemImage.setAccountId(accountId); + chatMessageMapper.insert(systemImage); } - String jsonString = JSONObject.toJSONString(receiveDesignParam); - json.put("tools_data", jsonString); - - ChatMessage systemImage = new ChatMessage(); - systemImage.setRole("system"); - if (color) { - systemImage.setIsImage(1); - }else { - systemImage.setIsImage(2); - } - systemImage.setProjectId(projectId); - systemImage.setSeq(getNextSeq(projectId)); - systemImage.setCreateTime(LocalDateTime.now()); - systemImage.setContent(JSONObject.toJSONString(receiveDesignParam.getReceiveCollectionElementList())); - systemImage.setAccountId(accountId); - chatMessageMapper.insert(systemImage); - emitter.send(json.toJSONString()); } } From 46820505ae39ee261be46111ceb6241f4c9ae333 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 14:37:34 +0800 Subject: [PATCH 10/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 5921a8a5..0ac23ca2 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -152,7 +152,7 @@ public class LLMServiceImpl implements LLMService { responseContentBuilder = new StringBuilder(); } JSONObject toolsData = json.getJSONObject("tools_data"); - if (Objects.nonNull(toolsData)) { + if (Objects.nonNull(toolsData) && !status.equals("[DESIGN_SIGNAL]")) { boolean color = true; ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); receiveDesignParam.setProjectId(projectId); From 588202311c298f4afa48e3dd3b6d4f6157bf042c Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 16:02:38 +0800 Subject: [PATCH 11/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/service/LLMService.java | 2 +- .../ai/da/service/impl/LLMServiceImpl.java | 40 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ai/da/service/LLMService.java b/src/main/java/com/ai/da/service/LLMService.java index 016e033c..807817a6 100644 --- a/src/main/java/com/ai/da/service/LLMService.java +++ b/src/main/java/com/ai/da/service/LLMService.java @@ -31,7 +31,7 @@ import java.util.Set; */ public interface LLMService { - SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token); + SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking); Long chatCreateProject(String prompt, String process); diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 0ac23ca2..0e410777 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -19,6 +19,7 @@ import com.ai.da.service.DesignService; import com.ai.da.service.LLMService; import com.ai.da.service.SysFileService; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -36,10 +37,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -69,7 +67,7 @@ public class LLMServiceImpl implements LLMService { private final ExecutorService executor = Executors.newCachedThreadPool(); @Override - public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token) { + public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking) { SseEmitter emitter = new SseEmitter(0L); // 永不超时 executor.submit(() -> { @@ -89,11 +87,11 @@ public class LLMServiceImpl implements LLMService { JSONObject jsonBodyObject = new JSONObject(); jsonBodyObject.put("project_id", projectId.toString()); jsonBodyObject.put("role", "user"); -// jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : ""); // 可扩展 - jsonBodyObject.put("image", ""); // 可扩展 - jsonBodyObject.put("file", fileUrl != null ? fileUrl : ""); + jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); // 可扩展 +// jsonBodyObject.put("image", ""); // 可扩展 + jsonBodyObject.put("file", fileUrl != null ? Collections.singletonList(fileUrl) : null); jsonBodyObject.put("message", prompt); - jsonBodyObject.put("enable_thinking", false); + jsonBodyObject.put("enable_thinking", enableThinking); // 1. 存储用户输入 ChatMessage userMessage = new ChatMessage(); @@ -334,10 +332,28 @@ public class LLMServiceImpl implements LLMService { if (record.getRole().equals("user")) { String content = record.getContent(); JSONObject jsonObject = JSONObject.parseObject(content); - String file = jsonObject.getString("file"); - if (!StringUtils.isEmpty(file)) { - jsonObject.put("file", minioUtil.getPreSignedUrl(file, 24 * 60)); + JSONArray fileArray = jsonObject.getJSONArray("file"); + if (!CollectionUtils.isEmpty(fileArray)) { + for (int i = 0; i < fileArray.size(); i++) { + String string = fileArray.getString(i); + if (!StringUtils.isEmpty(string)) { + fileArray.set(i, minioUtil.getPreSignedUrl(string, 24 * 60)); + } + } + jsonObject.put("file", fileArray); } + + JSONArray imageArray = jsonObject.getJSONArray("image"); + if (!CollectionUtils.isEmpty(imageArray)) { + for (int i = 0; i < imageArray.size(); i++) { + String string = imageArray.getString(i); + if (!StringUtils.isEmpty(string)) { + imageArray.set(i, minioUtil.getPreSignedUrl(string, 24 * 60)); + } + } + jsonObject.put("image", imageArray); + } + record.setContent(JSONObject.toJSONString(jsonObject)); } } return PageBaseResponse.success(chatMessagePage); From 82388b0c197abefe813566fffc6ae7f8ec403d75 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 16:12:08 +0800 Subject: [PATCH 12/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 0e410777..af8cc65f 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -89,7 +89,7 @@ public class LLMServiceImpl implements LLMService { jsonBodyObject.put("role", "user"); jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); // 可扩展 // jsonBodyObject.put("image", ""); // 可扩展 - jsonBodyObject.put("file", fileUrl != null ? Collections.singletonList(fileUrl) : null); + jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : null); jsonBodyObject.put("message", prompt); jsonBodyObject.put("enable_thinking", enableThinking); From a0bd4cfa38fa247d848461b9fcdc4584b3f70946 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 16:47:43 +0800 Subject: [PATCH 13/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/controller/LLMController.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ai/da/controller/LLMController.java b/src/main/java/com/ai/da/controller/LLMController.java index f6053132..bfb16785 100644 --- a/src/main/java/com/ai/da/controller/LLMController.java +++ b/src/main/java/com/ai/da/controller/LLMController.java @@ -58,8 +58,9 @@ public class LLMController { @RequestParam Long projectId, @RequestParam(required = false) String fileUrl, @RequestParam(required = false) List imageUrlList, - @RequestParam String token) { - return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token); + @RequestParam String token, + @RequestParam Boolean enableThinking) { + return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking); } @ApiOperation(value = "对话创建项目") From 8c597db8a9b41412db6961ae5864b861309b8014 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 16:54:20 +0800 Subject: [PATCH 14/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/controller/LLMController.java | 6 ++++-- src/main/java/com/ai/da/python/PythonService.java | 4 +++- src/main/java/com/ai/da/service/LLMService.java | 2 +- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/ai/da/controller/LLMController.java b/src/main/java/com/ai/da/controller/LLMController.java index bfb16785..d54490be 100644 --- a/src/main/java/com/ai/da/controller/LLMController.java +++ b/src/main/java/com/ai/da/controller/LLMController.java @@ -65,8 +65,10 @@ public class LLMController { @ApiOperation(value = "对话创建项目") @GetMapping(value = "/chatCreateProject") - public Response chatCreateProject(@RequestParam String prompt, @RequestParam String process) { - return Response.success(llmService.chatCreateProject(prompt, process)); + public Response chatCreateProject(@RequestParam String prompt, @RequestParam String process, + @RequestParam(required = false) String fileUrl, + @RequestParam(required = false) List imageUrlList) { + return Response.success(llmService.chatCreateProject(prompt, process, fileUrl, imageUrlList)); } @ApiOperation(value = "上传文件") diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 18623875..f686f881 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -4383,7 +4383,7 @@ public class PythonService { throw new BusinessException("poseTransferBatch.interface.exception"); } - public JSONObject getProjectParam(String prompt) { + public JSONObject getProjectParam(String prompt, String fileUrl, List imageUrlList) { OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(30, TimeUnit.SECONDS) .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) @@ -4393,6 +4393,8 @@ public class PythonService { MediaType mediaType = MediaType.parse("application/json"); Map content = Maps.newHashMap(); content.put("prompt", prompt); + content.put("image_list", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); + content.put("file_list", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : null); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); log.info("getProjectParam 请求地址: {}", accessPythonIp + ":" + accessPythonPort + "/api/extraction_project_info"); diff --git a/src/main/java/com/ai/da/service/LLMService.java b/src/main/java/com/ai/da/service/LLMService.java index 807817a6..5c370d32 100644 --- a/src/main/java/com/ai/da/service/LLMService.java +++ b/src/main/java/com/ai/da/service/LLMService.java @@ -33,7 +33,7 @@ public interface LLMService { SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking); - Long chatCreateProject(String prompt, String process); + Long chatCreateProject(String prompt, String process, String fileUrl, List imageUrlList); List uploadFile(MultipartFile file); diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index af8cc65f..97445da1 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -202,9 +202,9 @@ public class LLMServiceImpl implements LLMService { } @Override - public Long chatCreateProject(String prompt, String process) { + public Long chatCreateProject(String prompt, String process, String fileUrl, List imageUrlList) { AuthPrincipalVo userHolder = UserContext.getUserHolder(); - JSONObject jsonObject = pythonService.getProjectParam(prompt); + JSONObject jsonObject = pythonService.getProjectParam(prompt, fileUrl, imageUrlList); JSONObject data = jsonObject.getJSONObject("data"); Project project = new Project(); LocalDateTime now = LocalDateTime.now(); From 961498569009958a3067aa9a27f9a1eaf61df38c Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Tue, 20 May 2025 16:59:07 +0800 Subject: [PATCH 15/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/python/PythonService.java | 4 ++-- src/main/java/com/ai/da/service/impl/LLMServiceImpl.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index f686f881..d4604c3c 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -4393,8 +4393,8 @@ public class PythonService { MediaType mediaType = MediaType.parse("application/json"); Map content = Maps.newHashMap(); content.put("prompt", prompt); - content.put("image_list", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); - content.put("file_list", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : null); + content.put("image_list", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : new ArrayList<>()); + content.put("file_list", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); log.info("getProjectParam 请求地址: {}", accessPythonIp + ":" + accessPythonPort + "/api/extraction_project_info"); diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index 97445da1..c6762cfc 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -87,9 +87,9 @@ public class LLMServiceImpl implements LLMService { JSONObject jsonBodyObject = new JSONObject(); jsonBodyObject.put("project_id", projectId.toString()); jsonBodyObject.put("role", "user"); - jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : null); // 可扩展 + jsonBodyObject.put("image", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : new ArrayList<>()); // 可扩展 // jsonBodyObject.put("image", ""); // 可扩展 - jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : null); + jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); jsonBodyObject.put("message", prompt); jsonBodyObject.put("enable_thinking", enableThinking); From 94e00459b6f6d2a3532e9c33c8962b03599b6451 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Wed, 21 May 2025 21:03:15 +0800 Subject: [PATCH 16/32] =?UTF-8?q?TASK:LLM=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/controller/LLMController.java | 3 +- .../java/com/ai/da/service/LLMService.java | 2 +- .../ai/da/service/impl/LLMServiceImpl.java | 101 +++++++++++++++++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ai/da/controller/LLMController.java b/src/main/java/com/ai/da/controller/LLMController.java index d54490be..cf58932f 100644 --- a/src/main/java/com/ai/da/controller/LLMController.java +++ b/src/main/java/com/ai/da/controller/LLMController.java @@ -58,9 +58,10 @@ public class LLMController { @RequestParam Long projectId, @RequestParam(required = false) String fileUrl, @RequestParam(required = false) List imageUrlList, + @RequestParam(required = false) String process, @RequestParam String token, @RequestParam Boolean enableThinking) { - return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking); + return llmService.stream(prompt, projectId, fileUrl, imageUrlList, token, enableThinking, process); } @ApiOperation(value = "对话创建项目") diff --git a/src/main/java/com/ai/da/service/LLMService.java b/src/main/java/com/ai/da/service/LLMService.java index 5c370d32..5ecbe895 100644 --- a/src/main/java/com/ai/da/service/LLMService.java +++ b/src/main/java/com/ai/da/service/LLMService.java @@ -31,7 +31,7 @@ import java.util.Set; */ public interface LLMService { - SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking); + SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking, String process); Long chatCreateProject(String prompt, String process, String fileUrl, List imageUrlList); diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index c6762cfc..68fd76fc 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -67,7 +67,7 @@ public class LLMServiceImpl implements LLMService { private final ExecutorService executor = Executors.newCachedThreadPool(); @Override - public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking) { + public SseEmitter stream(String prompt, Long projectId, String fileUrl, List imageUrlList, String token, Boolean enableThinking, String process) { SseEmitter emitter = new SseEmitter(0L); // 永不超时 executor.submit(() -> { @@ -92,6 +92,7 @@ public class LLMServiceImpl implements LLMService { jsonBodyObject.put("file", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); jsonBodyObject.put("message", prompt); jsonBodyObject.put("enable_thinking", enableThinking); +// jsonBodyObject.put("process", process); // 1. 存储用户输入 ChatMessage userMessage = new ChatMessage(); @@ -150,7 +151,7 @@ public class LLMServiceImpl implements LLMService { responseContentBuilder = new StringBuilder(); } JSONObject toolsData = json.getJSONObject("tools_data"); - if (Objects.nonNull(toolsData) && !status.equals("[DESIGN_SIGNAL]")) { + if (Objects.nonNull(toolsData) && !status.equals("[DESIGN_SIGNAL]") && !status.equals("[PROJECT_CREATE_SIGNAL]")) { boolean color = true; ReceiveDesignParam receiveDesignParam = JSONObject.parseObject(JSONObject.toJSONString(toolsData), ReceiveDesignParam.class); receiveDesignParam.setProjectId(projectId); @@ -177,6 +178,102 @@ public class LLMServiceImpl implements LLMService { systemImage.setAccountId(accountId); chatMessageMapper.insert(systemImage); } + if (status.equals("[PROJECT_CREATE_SIGNAL]")) { + JSONObject data = toolsData; + Project project = new Project(); + LocalDateTime now = LocalDateTime.now(); + project.setUpdateTime(now); + project.setCreateTime(now); + project.setAccountId(accountId); + project.setName(data.getString("project_name")); + project.setOriginal(1); +// String process = data.getString("process"); +// if (StringUtils.isEmpty(process)) { +// project.setProcess(DesignProcess.SERIES_DESIGN.name()); +// }else { +// if (DesignProcess.isValidName(process)) { +// project.setProcess(process); +// }else { +// project.setProcess(DesignProcess.SERIES_DESIGN.name()); +// } +// } + project.setProcess(process); + projectMapper.insert(project); + + Workspace workspace = new Workspace(); + workspace.setAccountId(accountId); + workspace.setCreateTime(now); + String ageGroup = data.getString("ageGroup"); + if (StringUtils.isEmpty(ageGroup)) { + workspace.setAgeGroup("Adult"); + }else { + if (AgeGroup.isValidName(process)) { + workspace.setAgeGroup(ageGroup); + }else { + workspace.setAgeGroup("Adult"); + } + } + String gender = data.getString("gender"); + if (StringUtils.isEmpty(gender)) { + workspace.setSex("Female"); + }else { + if (Sex.isValidName(gender)) { + workspace.setSex(gender); + }else { + workspace.setSex("Female"); + } + } + String position = data.getString("position"); + if (StringUtils.isEmpty(position)) { + workspace.setPosition("Overall"); + }else { + if (Position.isValidName(position)) { + workspace.setPosition(position); + }else { + workspace.setPosition("Overall"); + } + } + workspace.setSystemDesignerPercentage(30); + workspace.setProjectId(project.getId()); + + String style = data.getString("style"); + String styleName = null; + if (StringUtils.isEmpty(style)) { + styleName = StyleEnum.NEW_CHINESE.name(); + }else { + if (StyleEnum.isValidName(style)) { + styleName = style; + }else { + styleName = StyleEnum.NEW_CHINESE.name(); + } + } + + SysFile sysFile = sysFileService.getOneBySex(styleName, workspace.getSex(), workspace.getAgeGroup()); + + if (workspace.getSex().equals(Sex.FEMALE.getValue())) { + workspace.setMannequinFemaleId(sysFile.getId()); + workspace.setMannequinFemaleType("System"); + }else { + workspace.setMannequinMaleId(sysFile.getId()); + workspace.setMannequinMaleType("System"); + } + + workspaceMapper.insert(workspace); + + if (!StringUtils.isEmpty(styleName)) { + QueryWrapper