From 7cd52b112a2e7da06aa8cfebf19a337be858762f Mon Sep 17 00:00:00 2001
From: hongjli <3117313295@qq.com>
Date: 星期五, 16 五月 2025 11:32:39 +0800
Subject: [PATCH] 查询气体管路产能规划列表补充“OrgCode”字段值

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlatePlanServiceImpl.java |   52 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 46 insertions(+), 6 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 15d21c4..51e6618 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,6 +1,8 @@
 package com.aps.core.service.impl;
 
 import cn.hutool.core.util.IdUtil;
+import com.alibaba.fastjson2.JSONArray;
+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;
@@ -14,12 +16,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.math.BigDecimal;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 閽i噾璁″垝绠$悊Service涓氬姟灞傚鐞�
@@ -35,8 +37,12 @@
 
     @Autowired
     private ApsPartPlanTempMapper apsPartPlanTempMapper;
+
     @Autowired
     private ApsPlatePlanTempMapper apsPlatePlanTempMapper;
+
+    @Autowired
+    public RedisTemplate redisTemplate;
 
     /**
      * 鏌ヨ閽i噾璁″垝绠$悊
@@ -199,10 +205,10 @@
     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);
+           Optional<ApsPlatePlan> planOptional = subPlanList.stream().filter(x -> x.getUnmatchedQuantity().compareTo(BigDecimal.ZERO) > 0).findFirst();
+           return planOptional.orElse(null);
        }else {
-           List<ApsPlatePlan> plans = apsPlatePlanMapper.selectUnMatchPlateSubPlanList(plant, itemNumber);
+           List<ApsPlatePlan> plans = getSubPlansFromRedis(itemNumber);
            if (!plans.isEmpty()) {
                subPlans.put(itemNumber, plans);
                return selectUnMatchPlateSubPlan(plant, itemNumber, subPlans);
@@ -211,4 +217,38 @@
            }
        }
     }
+
+    @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;
+        }
+    }
+
+    public List<ApsPlatePlan> getSubPlansFromRedis(String itemNumber) {
+        List<ApsPlatePlan> subPlans=new ArrayList<>();
+        JSONArray jsonArray =(JSONArray) redisTemplate.opsForValue().get("PLATE_SUB_PLAN:" + itemNumber);
+        if (jsonArray != null && !jsonArray.isEmpty()) {
+            subPlans = jsonArray.stream().map(obj -> JSONObject.parseObject(String.valueOf(obj), ApsPlatePlan.class)).toList();
+            subPlans.forEach(subPlan -> subPlan.setVersion(0));
+        }
+        return subPlans;
+    }
 }

--
Gitblit v1.9.3