From dbcc9f8992c97b84aa6ae0a381c807ba6239ae2c Mon Sep 17 00:00:00 2001
From: huangjiayang <5265313@qq.com>
Date: 星期四, 15 五月 2025 16:47:08 +0800
Subject: [PATCH] 【UPDATE】刷新BOM、库存、工艺路线数据缓存接口增加刷新钣金子单数据

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java
index be58e7a..3792967 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java
@@ -1,5 +1,7 @@
 package com.aps.core.service.impl;
 
+import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson2.JSONObject;
 import com.aps.common.core.utils.DateUtils;
 import com.aps.common.core.utils.uuid.IdUtils;
 import com.aps.common.security.utils.DictUtils;
@@ -13,10 +15,12 @@
 import org.apache.logging.log4j.util.Strings;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-import java.util.Optional;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 閽i噾璁″垝绠$悊Service涓氬姟灞傚鐞�
@@ -32,8 +36,12 @@
 
     @Autowired
     private ApsPartPlanTempMapper apsPartPlanTempMapper;
+
     @Autowired
     private ApsPlatePlanTempMapper apsPlatePlanTempMapper;
+
+    @Autowired
+    public RedisTemplate redisTemplate;
 
     /**
      * 鏌ヨ閽i噾璁″垝绠$悊
@@ -68,7 +76,7 @@
     @Override
     public int insertApsPlatePlan(ApsPlatePlan apsPlatePlan)
     {
-        apsPlatePlan.setId(IdUtils.fastUUID());
+        apsPlatePlan.setId(IdUtil.getSnowflakeNextId());
         apsPlatePlan.setCreateTime(DateUtils.getNowDate());
         return apsPlatePlanMapper.insertApsPlatePlan(apsPlatePlan);
     }
@@ -122,7 +130,7 @@
             ids[i]=apsPartPlanTemps.get(i).getId();
             ApsPlatePlan platePlan=new ApsPlatePlan();
             BeanUtils.copyProperties(apsPartPlanTemps.get(i), platePlan);
-            platePlan.setId(IdUtils.fastUUID());
+            platePlan.setId(IdUtil.getSnowflakeNextId());
             platePlan.setCreateTime(DateUtils.getNowDate());
             //鎻掑叆姝e紡琛紝骞惰褰�
             apsPlatePlanMapper.insertApsPlatePlan(platePlan);
@@ -191,4 +199,45 @@
     public List<ApsPlatePlan> selectPlateRedundantOrderList(ApsPlatePlan apsPlatePlan) {
         return apsPlatePlanMapper.selectPlateRedundantOrderList(apsPlatePlan);
     }
+
+    @Override
+    public ApsPlatePlan selectUnMatchPlateSubPlan(String plant, String itemNumber, Hashtable<String, List<ApsPlatePlan>> subPlans) {
+       if(subPlans.containsKey(itemNumber)) {
+           List<ApsPlatePlan> subPlanList = subPlans.get(itemNumber);
+           Optional<ApsPlatePlan> firstPlant = subPlanList.stream().filter(x -> x.getUnmatchedQuantity().compareTo(BigDecimal.ZERO) > 0).findFirst();
+           return firstPlant.orElse(null);
+       }else {
+           List<ApsPlatePlan> plans = apsPlatePlanMapper.selectUnMatchPlateSubPlanList(plant, itemNumber);
+           if (!plans.isEmpty()) {
+               subPlans.put(itemNumber, plans);
+               return selectUnMatchPlateSubPlan(plant, itemNumber, subPlans);
+           } else {
+               return null;
+           }
+       }
+    }
+
+    @Override
+    public boolean setSubPlansToRedis() {
+        try {
+            Set<String> keys = redisTemplate.keys("PLATE_SUB_PLAN:*");
+            if (keys != null && !keys.isEmpty()) {
+                redisTemplate.delete(keys);
+            }
+            List<JSONObject> subPlans = apsPlatePlanMapper.selectApsSubPlatePlan();
+//            ApsPlatePlan a = JSONObject.parseObject(String.valueOf(subPlans.get(0)), ApsPlatePlan.class);
+            Map<String, List<JSONObject>> groupByItemNumber = subPlans.stream().collect(Collectors.groupingBy(obj -> obj.getString("itemNumber")));
+            Map<String, Object> bulkData = new HashMap<>();
+            for (Map.Entry<String, List<JSONObject>> entry : groupByItemNumber.entrySet()) {
+                String key = entry.getKey();
+                List<JSONObject> value = entry.getValue();
+                bulkData.put("PLATE_SUB_PLAN:"+key, value);
+            }
+            redisTemplate.opsForValue().multiSet(bulkData);
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        }
+    }
 }

--
Gitblit v1.9.3