|
|
@@ -1,5 +1,7 @@
|
|
|
package com.fs.handwrite.service.impl;
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
@@ -15,7 +17,10 @@ import com.fs.his.param.CollectionOrcParam;
|
|
|
import com.fs.his.service.IFsOrcAiRecordService;
|
|
|
import com.fs.his.vo.CollectionOrcVO;
|
|
|
import com.fs.hisStore.domain.FsStoreOrderScrm;
|
|
|
+import com.fs.hisStore.mapper.FsStoreOrderItemScrmMapper;
|
|
|
import com.fs.hisStore.mapper.FsStoreOrderScrmMapper;
|
|
|
+import com.fs.hisStore.vo.FsStoreOrderItemVO;
|
|
|
+import com.fs.qw.vo.FsStoreOrderScrmIdVo;
|
|
|
import com.google.gson.Gson;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
@@ -26,9 +31,7 @@ import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -47,12 +50,18 @@ public class HandwriteCollectionServiceImpl implements IHandwriteCollectionServi
|
|
|
@Autowired
|
|
|
private FsStoreOrderScrmMapper storeOrderScrmMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private FsStoreOrderItemScrmMapper itemScrmMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ChatService chatService;
|
|
|
|
|
|
@Autowired
|
|
|
private IFsOrcAiRecordService orcAiRecordService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ObjectMapper objectMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public HandwriteCollection selectHandwriteCollectionById(Integer id)
|
|
|
{
|
|
|
@@ -60,9 +69,68 @@ public class HandwriteCollectionServiceImpl implements IHandwriteCollectionServi
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<HandwriteCollection> selectHandwriteCollectionList(HandwriteCollection handwriteCollection)
|
|
|
- {
|
|
|
- return handwriteCollectionMapper.selectHandwriteCollectionList(handwriteCollection);
|
|
|
+ public List<HandwriteCollection> selectHandwriteCollectionList(HandwriteCollection handwriteCollection) {
|
|
|
+ List<HandwriteCollection> handwriteCollections = handwriteCollectionMapper.selectHandwriteCollectionList(handwriteCollection);
|
|
|
+ if (CollectionUtils.isEmpty(handwriteCollections)) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 获取所有手写采集ID
|
|
|
+ List<Long> handwriteCollectionIds = handwriteCollections.stream()
|
|
|
+ .map(HandwriteCollection::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 2. 查出关联的订单信息
|
|
|
+ List<FsStoreOrderScrmIdVo> orderScrmList = storeOrderScrmMapper.selectIdListByHandleCollectionIds(handwriteCollectionIds);
|
|
|
+ if (CollectionUtils.isEmpty(orderScrmList)) {
|
|
|
+ return handwriteCollections;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 构建 Map:Key = handle_collection_id, Value = order_id
|
|
|
+ Map<Long, Long> collectionToOrderMap = orderScrmList.stream()
|
|
|
+ .filter(o -> o.getHandleCollectionId() != null && o.getId() != null)
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ FsStoreOrderScrmIdVo::getHandleCollectionId,
|
|
|
+ FsStoreOrderScrmIdVo::getId,
|
|
|
+ (v1, v2) -> v1
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 4. 获取所有订单ID,并查出订单商品明细
|
|
|
+ List<Long> orderScrmIds = new ArrayList<>(collectionToOrderMap.values());
|
|
|
+ List<FsStoreOrderItemVO> fsStoreOrderItemVOS = itemScrmMapper.selectByOrderIds(orderScrmIds);
|
|
|
+
|
|
|
+ // 5. 解析 JSON 提取商品名称
|
|
|
+ for (FsStoreOrderItemVO item : fsStoreOrderItemVOS) {
|
|
|
+ if (StringUtils.isNotBlank(item.getJsonInfo())) {
|
|
|
+ try {
|
|
|
+ JsonNode jsonNode = objectMapper.readTree(item.getJsonInfo());
|
|
|
+ String productName = jsonNode.has("productName") ? jsonNode.get("productName").asText() : null;
|
|
|
+ item.setProductName(productName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("解析商品JSON失败, itemId: {}", item.getItemId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 【核心】按订单ID分组,并将商品名称用逗号拼接
|
|
|
+ // Key: orderId, Value: "商品A,商品B"
|
|
|
+ Map<Long, String> orderProductMap = fsStoreOrderItemVOS.stream()
|
|
|
+ .filter(item -> item.getOrderId() != null && StringUtils.isNotBlank(item.getProductName()))
|
|
|
+ .collect(Collectors.groupingBy(
|
|
|
+ FsStoreOrderItemVO::getOrderId,
|
|
|
+ Collectors.mapping(FsStoreOrderItemVO::getProductName, Collectors.joining(","))
|
|
|
+ ));
|
|
|
+
|
|
|
+ // 7. 将拼接好的商品名称回填到 HandwriteCollection 中
|
|
|
+ for (HandwriteCollection collection : handwriteCollections) {
|
|
|
+ Long orderId = collectionToOrderMap.get(collection.getId());
|
|
|
+ if (orderId != null) {
|
|
|
+ String productNames = orderProductMap.get(orderId);
|
|
|
+ collection.setProductName(productNames); // 如果没有商品,设为 null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return handwriteCollections;
|
|
|
}
|
|
|
|
|
|
@Override
|