From 46adcbf7494340a495539708210bb39110bdc33b Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期六, 29 十一月 2025 17:35:03 +0800
Subject: [PATCH] 快速登记、化验及称重作业页面提交1

---
 fzzy-igdss-core/src/main/java/com/fzzy/igds/service/SysDeptService.java |  171 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 171 insertions(+), 0 deletions(-)

diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/SysDeptService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/SysDeptService.java
new file mode 100644
index 0000000..c66bfc1
--- /dev/null
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/SysDeptService.java
@@ -0,0 +1,171 @@
+package com.fzzy.igds.service;
+
+import com.fzzy.igds.constant.Constant;
+import com.fzzy.igds.constant.RedisConst;
+import com.fzzy.igds.utils.ContextUtil;
+import com.ruoyi.common.core.domain.entity.SysDept;
+import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.system.mapper.SysUserMapper;
+import com.ruoyi.system.service.ISysDeptService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @Description
+ * @Author CZT
+ * @Date 2024/11/22 18:03
+ */
+@Slf4j
+@Service
+public class SysDeptService {
+
+    @Resource
+    private SysUserMapper userMapper;
+    @Resource
+    private ISysDeptService iSysDeptService;
+    @Resource
+    private RedisCache redisCache;
+
+    public void initUserDeptMap(String companyId) {
+        if(StringUtils.isEmpty(companyId)){
+            companyId = ContextUtil.getCompanyId();
+        }
+
+        SysUser sysUser = new SysUser();
+        sysUser.setCompanyId(companyId);
+        List<SysUser> list = userMapper.selectUserList(sysUser);
+        if (null == list || list.isEmpty()){
+            return;
+        }
+        for (SysUser userDept : list) {
+            ContextUtil.updateSubDept(userDept.getLoginName(), userDept.getDeptId().toString());
+        }
+    }
+
+    /**
+     * 鍒锋柊閮ㄩ棬鏋舵瀯淇℃伅鍒扮紦瀛�
+     * @param companyId
+     */
+    public List<SysDept> flushDeptCache(String companyId) {
+        if (StringUtils.isEmpty(companyId)) {
+            companyId = ContextUtil.getCompanyId();
+        }
+        SysDept sysDept = new SysDept();
+        sysDept.setCompanyId(companyId);
+        List<SysDept> listSysDept = iSysDeptService.selectDeptList(sysDept);
+
+        String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPT_LIST);
+
+        redisCache.setCacheObject(key, listSysDept);
+        return listSysDept;
+    }
+
+    /**
+     * 鏍规嵁缁勭粐缂栫爜鑾峰彇鎵�鏈夐儴闂ㄤ俊鎭�
+     * @param companyId
+     * @return
+     */
+    public List<SysDept> getCacheDept(String companyId) {
+        if (StringUtils.isEmpty(companyId)) {
+            companyId = ContextUtil.getCompanyId();
+        }
+        String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPT_LIST);
+
+        List<SysDept> listSysDept = redisCache.getCacheObject(key);
+        if(null == listSysDept){
+            listSysDept = flushDeptCache(companyId);
+        }
+        return listSysDept;
+    }
+
+    /**
+     * 缂撳瓨鑾峰彇缁勭粐涓嬫墍鏈夊簱鍖哄垪琛�
+     * @param companyId
+     */
+    public List<SysDept> getAllDeptByCompanyId(String companyId) {
+        List<SysDept> list = getCacheDept(companyId);
+        return list.stream()
+                .filter(item -> item.getType().equals(Constant.DEPT_TYPE_20))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * 鏍规嵁id鑾峰彇閮ㄩ棬淇℃伅
+     * @param companyId
+     * @param deptId
+     * @return
+     */
+    public SysDept getCacheDept(String companyId, String deptId) {
+        if (StringUtils.isEmpty(deptId)) {
+            return null;
+        }
+        List<SysDept> list = getCacheDept(companyId);
+
+        if (null == list || list.isEmpty()){
+            return null;
+        }
+
+        for (SysDept dept : list) {
+            if (deptId.equals(dept.getDeptId() + ""))
+                return dept;
+        }
+        return null;
+    }
+
+    /**
+     * 鏍规嵁绫诲瀷鑾峰彇閮ㄩ棬淇℃伅
+     * type: 10-鍏徃锛�20-搴撳尯锛�30-閮ㄩ棬
+     * @param type
+     * @return
+     */
+    public List<SysDept> getDeptByType(String type) {
+        if (StringUtils.isEmpty(type)) {
+            return null;
+        }
+        List<SysDept> list = getCacheDept(null);
+        if (null == list || list.isEmpty()) {
+            return null;
+        }
+        //鏍规嵁绫诲瀷鏌ヨ
+        return list.stream()
+                .filter(item -> type.equals(item.getType()))
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * 鏍规嵁绫诲瀷鑾峰彇閮ㄩ棬淇℃伅
+     * type: 00-鍏徃锛�10-鍏徃锛�20-搴撳尯,澶氫釜鐢ㄨ嫳鏂囬�楀彿闅斿紑
+     *
+     * @param
+     * @return
+     */
+    public List<SysDept> getDeptById(SysDept dept) {
+
+        if (null == dept) {
+            return null;
+        }
+        List<SysDept> list = getCacheDept(null);
+        if ("20".equals(dept.getType())) {
+            //鏍规嵁绫诲瀷鏌ヨ
+            return list.stream()
+                    .filter(item -> dept.getDeptId().longValue() == item.getDeptId())
+                    .collect(Collectors.toList());
+        } else if ("10".equals(dept.getType())) {
+            //鏍规嵁绫诲瀷鏌ヨ
+            return list.stream()
+                    .filter(item -> dept.getDeptId().longValue() == item.getParentId())
+                    .collect(Collectors.toList());
+        } else {
+            return list.stream()
+                    .filter(item -> dept.getDeptId().toString().equals(item.getCompanyId()) && "20".equals(item.getType()))
+                    .collect(Collectors.toList());
+        }
+
+    }
+}

--
Gitblit v1.9.3