From c3fc4153f75b6467126081191f4d5fa1152ea386 Mon Sep 17 00:00:00 2001
From: sgj <1442489573@qq.com>
Date: 星期一, 09 三月 2026 11:21:07 +0800
Subject: [PATCH] 仓库缓存添加24小时保存限制

---
 fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java |  126 +++++++++++++++++++++++++++++++++++------
 1 files changed, 107 insertions(+), 19 deletions(-)

diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java
index 1ce91a6..662b777 100644
--- a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotService.java
@@ -10,9 +10,12 @@
 import com.ruoyi.common.core.redis.RedisCache;
 import com.ruoyi.common.utils.StringUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @Description
@@ -27,30 +30,32 @@
     private DepotMapper depotMapper;
     @Resource
     private RedisCache redisCache;
+    @Resource
+    private DepotStoreService depotStoreService;
 
     /**
      * 鏌ヨ搴撳尯涓嬩粨搴撳垪琛�
      *
      * @param companyId
      * @param deptId
-     * @param idDesc 鏄惁ID鍊掑簭鎺掑垪
+     * @param idDesc    鏄惁ID鍊掑簭鎺掑垪
      * @return
      */
     public List<Depot> getData(String companyId, String deptId, boolean idDesc) {
         if (StringUtils.isEmpty(companyId)) {
             companyId = ContextUtil.getCompanyId();
         }
-        
+
         QueryWrapper<Depot> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("company_id", companyId);
-        if(StringUtils.isNotBlank(deptId)){
+        if (StringUtils.isNotBlank(deptId)) {
             queryWrapper.likeRight("dept_id", deptId);
         }
-        
-        if(idDesc){
+
+        if (idDesc) {
             //ID鍊掑簭
             queryWrapper.orderByDesc("id");
-        }else {
+        } else {
             //搴忓彿姝e簭
             queryWrapper.orderByAsc("order_num");
         }
@@ -60,6 +65,7 @@
 
     /**
      * 鏍规嵁搴撳瓨琛ㄤ俊鎭紝鏇存柊浠撳簱搴撳瓨
+     *
      * @param data
      */
     public void updateByDepotStore(DepotStore data) {
@@ -91,11 +97,55 @@
             depot.setCreateBy(ContextUtil.getLoginUserName());
             depot.setCreateTime(new Date());
             depotMapper.insert(depot);
-        }else {
+        } else {
             depot.setUpdateBy(ContextUtil.getLoginUserName());
             depot.setUpdateTime(new Date());
             depotMapper.updateById(depot);
         }
+        flushCache(depot.getCompanyId());
+    }
+
+    /**
+     * 鏇存柊搴撳瓨淇℃伅
+     *
+     * @param depot
+     */
+    public void updateStorageReal(Depot depot) {
+
+        Depot cacheDepot = this.getCacheDepot(depot.getCompanyId(), depot.getId());
+
+        depot.setUpdateBy(ContextUtil.getLoginUserName());
+        depot.setUpdateTime(new Date());
+        depot.setRemark("銆�" + ContextUtil.getLoginUserName() + "銆戜簬[" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + "]淇敼搴撳瓨锛�" + cacheDepot.getStorageReal() + "-->" + depot.getStorageReal());
+        depotMapper.updateById(depot);
+
+        DepotStore lastData = new DepotStore();
+
+        //涓婚敭ID瑙勫垯锛歽yyyMMddHHmm_浠撳簱缂栫爜
+        lastData.setId(DateFormatUtils.format(new Date(), "yyyyMMddHHmm") + "_" + depot.getId() + "_HAND");
+        lastData.setCompanyId(depot.getCompanyId());
+        lastData.setDeptId(depot.getDeptId());
+        lastData.setDepotId(depot.getId());
+        lastData.setStorageReal(0.0);
+        lastData.setUpdateTime(new Date());
+        lastData.setUpdateBy("绯荤粺瀹氭椂缁熻");
+
+
+        lastData.setDepotStatus(depot.getDepotStatus());
+        lastData.setFoodVariety(depot.getFoodVariety());
+        lastData.setFoodLevel(depot.getFoodLevel());
+        lastData.setFoodLocation(depot.getFoodLocation());
+        lastData.setFoodLocationId(depot.getFoodLocationId());
+        lastData.setFoodType(depot.getFoodType());
+        lastData.setFoodYear(depot.getFoodYear());
+
+
+        lastData.setStorageReal(depot.getStorageReal());
+        lastData.setCreateTime(new Date()); //璁剧疆涓烘渶鏂版椂闂达紝鍏朵粬绯荤粺鍙互閫氳繃姝ゆ椂闂存煡璇㈡暟鎹槸鍚︽湁鏇存柊淇敼锛屽悓姝ュ埌鐪佸钩鍙版帴鍙c��
+        lastData.setCreateBy(ContextUtil.getLoginUserName());
+        lastData.setRemark("銆�" + ContextUtil.getLoginUserName() + "銆戜簬[" + DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss") + "]淇敼搴撳瓨涓猴細" + depot.getStorageReal());
+
+        depotStoreService.updateAndSave(lastData);
         flushCache(depot.getCompanyId());
     }
 
@@ -124,7 +174,7 @@
         if (StringUtils.isEmpty(depotId)) {
             return;
         }
-        
+
         UpdateWrapper<Depot> updateWrapper = new UpdateWrapper<>();
         updateWrapper.eq("id", depotId).set("depot_status", status);
         depotMapper.update(null, updateWrapper);
@@ -152,7 +202,7 @@
             companyId = ContextUtil.getCompanyId();
         }
 
-        List<Depot> list = this.getData(companyId,null, false);
+        List<Depot> list = this.getData(companyId, null, false);
 
         this.setCacheDepotList(list, companyId);
     }
@@ -168,7 +218,7 @@
         String key;
         for (Depot depot : list) {
             key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT, depot.getId());
-            redisCache.setCacheObject(key, depot);
+            redisCache.setCacheObject(key, depot, 24, TimeUnit.HOURS);
         }
     }
 
@@ -200,6 +250,8 @@
             companyId = ContextUtil.getCompanyId();
         }
         List<Depot> list = new ArrayList<>();
+        List<Depot> resultList = new ArrayList<>();
+
 
         String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT) + "*";
         Collection<String> keys = redisCache.keys(patten);
@@ -211,14 +263,31 @@
 
         //缂撳瓨鑾峰彇涓虹┖锛屽垯鏌ヨ鏁版嵁搴�
         if (list.isEmpty()) {
-            list = this.getData(companyId,null, false);
+            list = this.getData(companyId, null, false);
             setCacheDepotList(list, companyId);
         }
-        if(!list.isEmpty()){
+        if (!list.isEmpty()) {
             //閲嶆柊鎺掑簭
-            Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
+            //妫�鏌ユ暟鎹槸鍚︿负绌�
+            for (Depot depot : list) {
+                if( null!=depot){
+                    resultList.add(depot);
+                }
+            }
+            boolean hasNullOrderNum = true;
+            // 妫�鏌ユ槸鍚︽湁浠撳簱鐨勬帓搴忓彿涓虹┖
+            for (Depot depot : resultList) {
+                if ( null== depot.getOrderNum()) {
+                    hasNullOrderNum = true;
+                    break;
+                }
+            }
+            // 濡傛灉瀛樺湪鎺掑簭鍙蜂负绌虹殑浠撳簱锛屽垯涓嶈繘琛屾帓搴�
+            if (!hasNullOrderNum) {
+                Collections.sort(resultList, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
+            }
         }
-        return list;
+        return resultList;
     }
 
     /**
@@ -233,6 +302,8 @@
             return null;
         }
         List<Depot> list = getCacheDepotList(companyId);
+        List<Depot> resultList = new ArrayList<>();
+
         if (null == list || list.isEmpty()) {
             return null;
         }
@@ -242,9 +313,26 @@
                 result.add(depot);
             }
         }
-        if(!result.isEmpty()){
+        if (!list.isEmpty()) {
             //閲嶆柊鎺掑簭
-            Collections.sort(list, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
+            //妫�鏌ユ暟鎹槸鍚︿负绌�
+            for (Depot depot : list) {
+                if( null!=depot){
+                    resultList.add(depot);
+                }
+            }
+            boolean hasNullOrderNum = true;
+            // 妫�鏌ユ槸鍚︽湁浠撳簱鐨勬帓搴忓彿涓虹┖
+            for (Depot depot : resultList) {
+                if ( null== depot.getOrderNum()) {
+                    hasNullOrderNum = true;
+                    break;
+                }
+            }
+            // 濡傛灉瀛樺湪鎺掑簭鍙蜂负绌虹殑浠撳簱锛屽垯涓嶈繘琛屾帓搴�
+            if (!hasNullOrderNum) {
+                Collections.sort(resultList, (p1, p2) -> p1.getOrderNum() - p2.getOrderNum());
+            }
         }
         return result;
     }
@@ -266,7 +354,7 @@
         String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT, depotId);
         Depot depot = redisCache.getCacheObject(key);
         if (null == depot) {
-            depot =  depotMapper.selectById(depotId);
+            depot = depotMapper.selectById(depotId);
             redisCache.setCacheObject(key, depot);
         }
         return depot;
@@ -287,11 +375,11 @@
         }
 
         List<Depot> depotList = getCacheDepotList(ContextUtil.getCompanyId(), deptId);
-        if(null == depotList || depotList.isEmpty()){
+        if (null == depotList || depotList.isEmpty()) {
             return null;
         }
         for (Depot depot : depotList) {
-            if(depotName.equals(depot.getName())){
+            if (depotName.equals(depot.getName())) {
                 return depot.getId();
             }
         }

--
Gitblit v1.9.3