From 088afbe5c16680c72122d1d2bbb144c557a32617 Mon Sep 17 00:00:00 2001 From: Timi Date: Thu, 17 Sep 2026 01:31:02 +0800 Subject: [PATCH] update customer in list --- .../gao/ai/mcp/GaoAiMcpAuthentication.java | 2 - .../implement/GaoAiChatServiceImplement.java | 23 ++++++++-- .../modules/gao/bean/GaoSystemSetting.java | 6 +-- .../controller/GaoFundRecordController.java | 16 +++++++ .../api/modules/gao/entity/GaoFundRecord.java | 4 ++ .../gao/entity/GaoProductStockRecord.java | 4 ++ .../gao/mapper/GaoOrderFulfillmentMapper.java | 4 ++ .../GaoCustomerServiceImplement.java | 16 +++++++ ...GaoProductStockRecordServiceImplement.java | 45 ++++++++++++++++++- .../gao/GaoOrderFulfillmentMapper.xml | 5 +++ 10 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/imyeyu/api/modules/gao/ai/mcp/GaoAiMcpAuthentication.java b/src/main/java/com/imyeyu/api/modules/gao/ai/mcp/GaoAiMcpAuthentication.java index be3fd04..4982419 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/ai/mcp/GaoAiMcpAuthentication.java +++ b/src/main/java/com/imyeyu/api/modules/gao/ai/mcp/GaoAiMcpAuthentication.java @@ -1,7 +1,6 @@ package com.imyeyu.api.modules.gao.ai.mcp; import com.imyeyu.api.modules.common.service.SettingService; -import com.imyeyu.api.modules.gao.ai.config.GaoAiProperties; import com.imyeyu.api.modules.gao.ai.entity.GaoAiSession; import com.imyeyu.api.modules.gao.ai.service.GaoAiSessionService; import com.imyeyu.api.modules.gao.ai.service.implement.GaoAiSessionServiceImplement.GaoAiSessionException; @@ -22,7 +21,6 @@ import java.security.MessageDigest; @RequiredArgsConstructor public class GaoAiMcpAuthentication { - private final GaoAiProperties properties; private final SettingService settingService; private final GaoAiSessionService sessionService; diff --git a/src/main/java/com/imyeyu/api/modules/gao/ai/service/implement/GaoAiChatServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/ai/service/implement/GaoAiChatServiceImplement.java index 7c6eeb6..38f22a4 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/ai/service/implement/GaoAiChatServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/ai/service/implement/GaoAiChatServiceImplement.java @@ -501,7 +501,11 @@ public class GaoAiChatServiceImplement implements GaoAiChatService { if (line.startsWith("event:")) { sseEvent.set(line.substring(6).trim()); } else if (line.startsWith("data:")) { - data.append(line.substring(5).trim()); + if (!data.isEmpty()) { + data.append('\n'); + } + String dataLine = line.substring(5); + data.append(dataLine.startsWith(" ") ? dataLine.substring(1) : dataLine); } else if (line.isEmpty() && !data.isEmpty()) { processData(data.toString(), sseEvent.get(), emitter, status, finished, timeoutRef, auditRecorded, session, message, startedAt); @@ -565,9 +569,13 @@ public class GaoAiChatServiceImplement implements GaoAiChatService { } switch (event) { case "message", "agent_message", "text_chunk" -> { - String answer = firstText(text(payload, "answer", null), text(payload, "text", null)); - if (answer != null) { - safeSend(emitter, SseEmitter.event().name("message").data(answer), finished); + String answer = firstRawText(payload, "answer"); + if (answer == null) { + answer = firstRawText(payload, "text"); + } + if (answer != null && !answer.isEmpty()) { + Map messageData = Map.of("answer", answer); + safeSend(emitter, SseEmitter.event().name("message").data(messageData), finished); } } case "message_end" -> emitDone(emitter, session, startedAt, finished, timeoutRef, auditRecorded, message, status); @@ -719,6 +727,13 @@ public class GaoAiChatServiceImplement implements GaoAiChatService { return fallback; } + private String firstRawText(JsonNode node, String field) { + if (node != null && node.hasNonNull(field)) { + return node.get(field).asText(); + } + return null; + } + private String firstText(String... values) { for (String value : values) { if (!isBlank(value)) { diff --git a/src/main/java/com/imyeyu/api/modules/gao/bean/GaoSystemSetting.java b/src/main/java/com/imyeyu/api/modules/gao/bean/GaoSystemSetting.java index 0a38e9c..3a95d7c 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/bean/GaoSystemSetting.java +++ b/src/main/java/com/imyeyu/api/modules/gao/bean/GaoSystemSetting.java @@ -19,11 +19,9 @@ public enum GaoSystemSetting implements SettingEnum { DIFY_MCP_SERVICE_KEY(null, Setting.ValueType.STRING), - SERVICE_LICENSE(null, Setting.ValueType.STRING), + AI_AGENT_EXAMPLE(null, Setting.ValueType.JSON_LIST), - PRIVACY_LICENSE(null, Setting.ValueType.STRING), - - OPEN_SOURCE_LICENSE(null, Setting.ValueType.STRING); + AGREEMENT(null, Setting.ValueType.JSON_OBJECT); final String defaultValue; diff --git a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoFundRecordController.java b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoFundRecordController.java index f4681f6..aa90fdb 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/controller/GaoFundRecordController.java +++ b/src/main/java/com/imyeyu/api/modules/gao/controller/GaoFundRecordController.java @@ -4,7 +4,9 @@ import com.imyeyu.api.modules.common.entity.Attachment; import com.imyeyu.api.modules.common.service.AttachmentService; import com.imyeyu.api.modules.gao.annotation.RequireGaoPermission; import com.imyeyu.api.modules.gao.bean.GaoPermissionCode; +import com.imyeyu.api.modules.gao.entity.GaoCustomer; import com.imyeyu.api.modules.gao.entity.GaoFundRecord; +import com.imyeyu.api.modules.gao.service.GaoCustomerService; import com.imyeyu.api.modules.gao.service.GaoFundRecordService; import com.imyeyu.api.modules.gao.service.GaoOrderPaymentService; import com.imyeyu.api.modules.gao.service.GaoStoreScopeService; @@ -39,6 +41,7 @@ import java.util.stream.Stream; public class GaoFundRecordController { private final GaoFundRecordService service; + private final GaoCustomerService customerService; private final GaoOrderPaymentService orderPaymentService; private final GaoStoreScopeService storeScopeService; private final AttachmentService attachmentService; @@ -124,10 +127,23 @@ public class GaoFundRecordController { .distinct() .toList(); Map userMap = userIdList.isEmpty() ? Map.of() : userService.mapByIdList(userIdList); + List customerIdList = recordList.stream() + .map(GaoFundRecord::getCustomerId) + .filter(value -> value != null && !value.isBlank()) + .distinct() + .toList(); + Map customerMap = customerIdList.isEmpty() ? Map.of() : customerService.mapByIdList(customerIdList); + Map> customerPhotoMap = customerIdList.isEmpty() + ? Map.of() : attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList, GaoCustomer.AttachType.PHOTO.name()); for (GaoFundRecord record : recordList) { record.setAttachmentList(attachmentMap.getOrDefault(record.getId(), List.of())); record.setOperator(userMap.get(record.getOperatorUserId())); record.setVerifier(userMap.get(record.getVerifierUserId())); + GaoCustomer customer = customerMap.get(record.getCustomerId()); + if (customer != null) { + customer.setAttachmentList(customerPhotoMap.getOrDefault(customer.getId(), List.of())); + } + record.setCustomer(customer); } } } diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java index 20390d0..f4eb139 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoFundRecord.java @@ -120,6 +120,10 @@ public class GaoFundRecord extends UUIDEntity { @Transient private User verifier; + /// 所属客户 + @Transient + private GaoCustomer customer; + /// 附件 @Transient private List attachmentList; diff --git a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java index 02fb527..fa696d9 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java +++ b/src/main/java/com/imyeyu/api/modules/gao/entity/GaoProductStockRecord.java @@ -168,6 +168,10 @@ public class GaoProductStockRecord implements IDEntity, Creatable { @Transient private User operator; + /// 所属客户 + @Transient + private GaoCustomer customer; + /// 附件 @Transient private List attachmentList; diff --git a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoOrderFulfillmentMapper.java b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoOrderFulfillmentMapper.java index 55fc95c..93209b2 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoOrderFulfillmentMapper.java +++ b/src/main/java/com/imyeyu/api/modules/gao/mapper/GaoOrderFulfillmentMapper.java @@ -5,6 +5,7 @@ import com.imyeyu.api.modules.gao.vo.GaoOrderFulfillmentPage; import com.imyeyu.spring.mapper.BaseMapper; import org.apache.ibatis.annotations.Param; +import java.util.Collection; import java.util.List; /// GAO 统一履约 Mapper @@ -19,6 +20,9 @@ public interface GaoOrderFulfillmentMapper extends BaseMapper selectByIdList(@Param("idList") Collection idList); + /// 锁定履约单 GaoOrderFulfillment selectForUpdate(@Param("id") String id); diff --git a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoCustomerServiceImplement.java b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoCustomerServiceImplement.java index 3634c13..c270049 100644 --- a/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoCustomerServiceImplement.java +++ b/src/main/java/com/imyeyu/api/modules/gao/service/implement/GaoCustomerServiceImplement.java @@ -159,6 +159,17 @@ public class GaoCustomerServiceImplement extends AbstractEntityService implements GaoProductStockRecordService { private final GaoProductStockRecordMapper mapper; + private final GaoOrderFulfillmentMapper orderFulfillmentMapper; private final AttachmentService attachmentService; + private final GaoCustomerService customerService; private final UserService userService; @Override @@ -133,10 +140,46 @@ public class GaoProductStockRecordServiceImplement extends AbstractEntityService List userIdList = recordList.stream().map(GaoProductStockRecord::getOperatorUserId) .filter(value -> value != null && !value.isBlank()).distinct().toList(); Map userMap = userIdList.isEmpty() ? Map.of() : userService.mapByIdList(userIdList); + Map> userAvatarMap = userIdList.isEmpty() + ? Map.of() : attachmentService.mapByBizIdList(Attachment.BizType.USER, userIdList, User.AttachType.AVATAR.name()); + List fulfillmentIdList = recordList.stream() + .filter(record -> record.getBizType() == GaoProductStockRecord.BizType.ORDER_FULFILLMENT) + .map(GaoProductStockRecord::getBizId) + .filter(value -> value != null && !value.isBlank()) + .distinct() + .toList(); + Map fulfillmentMap = fulfillmentIdList.isEmpty() + ? Map.of() : orderFulfillmentMapper.selectByIdList(fulfillmentIdList).stream() + .collect(Collectors.toMap(GaoOrderFulfillment::getId, item -> item)); + List customerIdList = recordList.stream() + .map(record -> getCustomerId(record, fulfillmentMap)) + .filter(value -> value != null && !value.isBlank()) + .distinct() + .toList(); + Map customerMap = customerIdList.isEmpty() ? Map.of() : customerService.mapByIdList(customerIdList); + Map> customerPhotoMap = customerIdList.isEmpty() + ? Map.of() : attachmentService.mapByBizIdList(Attachment.BizType.GAO_CUSTOMER, customerIdList, GaoCustomer.AttachType.PHOTO.name()); for (GaoProductStockRecord record : recordList) { record.setAttachmentList(attachmentMap.getOrDefault(record.getId(), List.of())); - record.setOperator(userMap.get(record.getOperatorUserId())); + User operator = userMap.get(record.getOperatorUserId()); + if (operator != null) { + operator.setAttachmentList(userAvatarMap.getOrDefault(operator.getId(), List.of())); + } + record.setOperator(operator); + GaoCustomer customer = customerMap.get(getCustomerId(record, fulfillmentMap)); + if (customer != null) { + customer.setAttachmentList(customerPhotoMap.getOrDefault(customer.getId(), List.of())); + } + record.setCustomer(customer); } } + private String getCustomerId(GaoProductStockRecord record, Map fulfillmentMap) { + if (record.getBizType() != GaoProductStockRecord.BizType.ORDER_FULFILLMENT) { + return null; + } + GaoOrderFulfillment fulfillment = fulfillmentMap.get(record.getBizId()); + return fulfillment == null ? null : fulfillment.getCustomerId(); + } + } diff --git a/src/main/resources/mapper/timi-server/gao/GaoOrderFulfillmentMapper.xml b/src/main/resources/mapper/timi-server/gao/GaoOrderFulfillmentMapper.xml index b783c47..7f22b1f 100644 --- a/src/main/resources/mapper/timi-server/gao/GaoOrderFulfillmentMapper.xml +++ b/src/main/resources/mapper/timi-server/gao/GaoOrderFulfillmentMapper.xml @@ -10,6 +10,11 @@ SELECT * FROM `gao_order_fulfillment` WHERE `id` = #{id} +