From 181252cf8ba494441b1fdb3873da7afa90ff0813 Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期四, 26 二月 2026 10:51:49 +0800
Subject: [PATCH] 库存统计优化,增加手动统计

---
 fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java |   79 +++++++++++++++++++++++++++++----------
 1 files changed, 59 insertions(+), 20 deletions(-)

diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java
index 4ec5982..c76b494 100644
--- a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/InoutConfService.java
@@ -4,6 +4,7 @@
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.fzzy.igds.constant.Constant;
 import com.fzzy.igds.constant.RedisConst;
+import com.fzzy.igds.domain.Dept;
 import com.fzzy.igds.mapper.InoutConfMapper;
 import com.fzzy.igds.mapper.InoutSysConfMapper;
 import com.fzzy.igds.domain.InoutConf;
@@ -16,6 +17,7 @@
 import com.ruoyi.system.service.ISysDeptService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+
 import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
@@ -30,6 +32,8 @@
 public class InoutConfService {
     @Resource
     private ISysDeptService iSysDeptService;
+    @Resource
+    private CoreDeptService deptService;
     @Resource
     private InoutConfMapper inoutConfMapper;
     @Resource
@@ -62,6 +66,22 @@
     }
 
     /**
+     * 鏍规嵁鏉′欢鏌ヨ娴佺▼淇℃伅
+     *
+     * @param deptId
+     * @return
+     */
+    public InoutSysConf getInoutSysConf(String deptId) {
+
+        List<InoutSysConf> list = listInoutSysConf(deptId, null);
+
+        if (null == list || list.isEmpty()) {
+            return null;
+        }
+        return list.get(0);
+    }
+
+    /**
      * 鏌ヨ娴佺▼閰嶇疆
      *
      * @return
@@ -89,7 +109,7 @@
         inoutSysConf.setProgressOut("REGISTER-WEIGHT_EMPTY-HANDLE-WEIGHT_FULL-RECORD");
         this.saveSysConfData(inoutSysConf);
 
-        this.flushInoutSysConfCache(inoutSysConf);
+        this.flushInoutSysConfCache();
     }
 
     /**
@@ -118,20 +138,25 @@
         } else {
             data.setUpdateBy(ContextUtil.getLoginUserName());
             data.setUpdateTime(new Date());
-            inoutSysConfMapper.updateById(data);
+            inoutSysConfMapper.update(data, new UpdateWrapper<InoutSysConf>().eq("dept_id", data.getDeptId()));
         }
 
-        this.flushInoutSysConfCache(data);
+        this.flushInoutSysConfCache();
     }
 
     /**
      * 璁剧疆缂撳瓨
      *
-     * @param data
      */
-    public void flushInoutSysConfCache(InoutSysConf data) {
-        String key = RedisConst.buildKey(data.getDeptId(), Constant.CACHE_INOUT_SYS_CONF);
-        redisCache.setCacheObject(key, data);
+    public void flushInoutSysConfCache() {
+        List<InoutSysConf> list = listInoutSysConf(null,null);
+        if(null == list || list.isEmpty()){
+            return;
+        }
+        for (InoutSysConf conf : list) {
+            String key = RedisConst.buildKey(conf.getDeptId(), Constant.CACHE_INOUT_SYS_CONF);
+            redisCache.setCacheObject(key, conf);
+        }
     }
 
     /**
@@ -143,7 +168,12 @@
      */
     public InoutSysConf getCacheInoutSysConf(String companyId, String deptId) {
         String key = RedisConst.buildKey(deptId, Constant.CACHE_INOUT_SYS_CONF);
-        return (InoutSysConf) redisCache.getCacheObject(key);
+        InoutSysConf conf = (InoutSysConf) redisCache.getCacheObject(key);
+        if (null == conf) {
+            conf = getInoutSysConf(deptId);
+            flushInoutSysConfCache();
+        }
+        return conf;
     }
 
     /*--------------- 鍑哄叆搴撹澶� ---------------*/
@@ -154,16 +184,16 @@
      * @return
      */
     public List<InoutConf> getInoutConfList(String companyId, String deptId) {
+        QueryWrapper<InoutConf> queryWrapper = new QueryWrapper<>();
+
         if (StringUtils.isEmpty(companyId)) {
             companyId = ContextUtil.getCompanyId();
         }
-        if (StringUtils.isEmpty(deptId)) {
-            deptId = ContextUtil.subDeptId(null);
-        }
-        QueryWrapper<InoutConf> queryWrapper = new QueryWrapper<>();
-
-        queryWrapper.eq("dept_id", deptId);
         queryWrapper.eq("company_id", companyId);
+
+        if (StringUtils.isNotEmpty(deptId)) {
+            queryWrapper.eq("dept_id", deptId);
+        }
 
         return inoutConfMapper.selectList(queryWrapper);
     }
@@ -194,7 +224,7 @@
             data.setUpdateBy(ContextUtil.getLoginUserName());
             data.setUpdateTime(new Date());
             inoutConfMapper.insert(data);
-        }else {
+        } else {
             data.setUpdateBy(ContextUtil.getLoginUserName());
             data.setUpdateTime(new Date());
             inoutConfMapper.updateById(data);
@@ -217,12 +247,21 @@
      * 璁剧疆缂撳瓨
      *
      * @param companyId
-     * @param deptId
      */
-    public void flushInoutConfCache(String companyId, String deptId) {
-        List<InoutConf> list = this.getInoutConfList(companyId, deptId);
-        String key = RedisConst.buildKey(companyId, Constant.CACHE_INOUT_CONF_LIST, deptId);
-        redisCache.setCacheObject(key, list);
+    public void flushInoutConfCache(String companyId) {
+        List<Dept> depts = deptService.listDept(null, companyId, null);
+        if(null == depts || depts.isEmpty()){
+            return;
+        }
+        List<InoutConf> inoutConfList;
+        for (Dept dept : depts) {
+            inoutConfList = this.getInoutConfList(companyId, dept.getId());
+            if(null == inoutConfList || inoutConfList.isEmpty()){
+                continue;
+            }
+            String key = RedisConst.buildKey(companyId, Constant.CACHE_INOUT_CONF_LIST, dept.getId());
+            redisCache.setCacheObject(key, inoutConfList);
+        }
     }
 
     /**

--
Gitblit v1.9.3