From 2f432f52c1cfb1567dadcf6e040c5d38b0a26a79 Mon Sep 17 00:00:00 2001
From: czt <czt18638530771@163.com>
Date: 星期五, 28 十一月 2025 17:31:49 +0800
Subject: [PATCH] 数量检测配置页面
---
fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotConfService.java | 249 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 249 insertions(+), 0 deletions(-)
diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotConfService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotConfService.java
new file mode 100644
index 0000000..1dcfdd3
--- /dev/null
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/DepotConfService.java
@@ -0,0 +1,249 @@
+package com.fzzy.igds.service;
+
+import com.fzzy.igds.constant.RedisConst;
+import com.fzzy.igds.domain.Depot;
+import com.fzzy.igds.domain.DepotConf;
+import com.fzzy.igds.repository.DepotConfRepository;
+import com.fzzy.igds.utils.ContextUtil;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @Description
+ * @Author CZT
+ * @Date 2025/11/28 15:42
+ */
+@Slf4j
+@Service
+public class DepotConfService {
+
+ @Resource
+ private DepotConfRepository depotConfRepository;
+ @Resource
+ private DepotService depotService;
+ @Resource
+ private RedisCache redisCache;
+
+ /**
+ * jpa鏌ヨ閰嶇疆淇℃伅
+ *
+ * @param companyId
+ * @param deptId
+ * @return
+ */
+ public List<DepotConf> getConfList(String companyId, String deptId) {
+
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ if (StringUtils.isEmpty(deptId)) {
+ deptId = ContextUtil.subDeptId(null);
+ }
+ return depotConfRepository.getDepotConf(companyId, deptId);
+ }
+
+ /**
+ * jpa鏇存柊淇濆瓨閰嶇疆淇℃伅
+ *
+ * @param conf
+ */
+ public void saveConf(DepotConf conf) {
+ if (StringUtils.isEmpty(conf.getCompanyId())) {
+ conf.setCompanyId(ContextUtil.getCompanyId());
+ }
+ if (StringUtils.isEmpty(conf.getDeptId())) {
+ conf.setDeptId(ContextUtil.subDeptId(null));
+ conf.setCreateBy(ContextUtil.getLoginUserName());
+ conf.setCreateTime(new Date());
+ }
+ conf.setUpdateBy(ContextUtil.getLoginUserName());
+ conf.setUpdateTime(new Date());
+ depotConfRepository.save(conf);
+ flushConfCache(conf.getCompanyId());
+ }
+
+ /**
+ * jpa鍒犻櫎閰嶇疆淇℃伅
+ *
+ * @param conf
+ * @return
+ */
+ public void deleteDepotConf(DepotConf conf) {
+ depotConfRepository.delete(conf);
+
+ //鍒犻櫎閰嶇疆缂撳瓨
+ this.delCacheDepotConf(conf, conf.getCompanyId());
+ }
+
+ /**
+ * 璁剧疆缂撳瓨淇℃伅
+ *
+ * @param list
+ * @param companyId
+ */
+ public void setCacheDepotConf(List<DepotConf> list, String companyId) {
+ if (null != list) {
+ Depot depot;
+ String key;
+ for (DepotConf depotConf : list) {
+ depot = depotService.getCacheDepot(companyId, depotConf.getDepotId());
+ if (null != depot) {
+ depotConf.setDepotName(depot.getName());
+ depotConf.setDepotType(depot.getDepotType());
+ }
+ key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotConf.getDepotId());
+ redisCache.setCacheObject(key, depotConf);
+ }
+ }
+ }
+
+ /**
+ * 鍒犻櫎缂撳瓨淇℃伅
+ *
+ * @param depotConf
+ * @param companyId
+ */
+ public void delCacheDepotConf(DepotConf depotConf, String companyId) {
+ if (null == depotConf) {
+ return;
+ }
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotConf.getDepotId());
+ redisCache.deleteObject(key);
+ }
+
+ /**
+ * 鑾峰彇缂撳瓨-鏍规嵁缁勭粐缂栫爜鑾峰彇閰嶇疆淇℃伅闆嗗悎
+ *
+ * @param companyId
+ * @return
+ */
+ public List<DepotConf> getCacheDepotConfList(String companyId) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ String patten = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF) + "*";
+
+ Collection<String> keys = redisCache.keys(patten);
+ if (null == keys || keys.isEmpty()) {
+ return null;
+ }
+
+ List<DepotConf> result = new ArrayList<>();
+ for (String key : keys) {
+ result.add((DepotConf) redisCache.getCacheObject(key));
+ }
+
+ return result;
+ }
+
+ /**
+ * 鑾峰彇缂撳瓨-鏍规嵁缁勭粐缂栫爜鍜岀伯鎯呭垎鏈篒D鑾峰彇閰嶇疆淇℃伅闆嗗悎
+ *
+ * @param companyId
+ * @param serId
+ * @return
+ */
+ public List<DepotConf> getCacheDepotConfList(String companyId, String serId) {
+ List<DepotConf> list = getCacheDepotConfList(companyId);
+
+ if (null == list || list.isEmpty()) {
+ return null;
+ }
+ return list.stream()
+ .filter(item -> null != item.getGrainSer() && item.getGrainSer().equals(serId))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * 鑾峰彇缂撳瓨-鏍规嵁缁勭粐缂栫爜鍜岀伯鎯呭垎鏈篒D鑾峰彇閰嶇疆淇℃伅
+ *
+ * @param companyId
+ * @param serId
+ * @return
+ */
+ public DepotConf getCacheDepotConfBySerId(String companyId, String serId) {
+ List<DepotConf> data = getCacheDepotConfList(companyId);
+ if (null == data) {
+ return null;
+ }
+
+ return data.stream().filter(item -> serId.equals(item.getGrainSer()))
+ .findAny().orElse(null);
+ }
+
+ /**
+ * 鑾峰彇缂撳瓨-鏍规嵁缁勭粐缂栫爜鍜屼粨搴撶紪鐮佽幏鍙栭厤缃俊鎭�
+ *
+ * @param companyId
+ * @param depotId
+ * @return
+ */
+ public DepotConf getCacheDepotConfByDepotId(String companyId, String depotId) {
+ if (StringUtils.isEmpty(depotId)) {
+ return null;
+ }
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ String key = RedisConst.buildKey(companyId, RedisConst.KEY_DEPOT_CONF, depotId);
+ DepotConf depotConf = redisCache.getCacheObject(key);
+ if (null == depotConf) {
+ depotConf = depotConfRepository.getDepotConfByDepotId(companyId, depotId);
+ redisCache.setCacheObject(key, depotConf);
+ }
+
+ return depotConf;
+ }
+
+ /**
+ * 鏍规嵁浠撳簱鍒楄〃锛岃嚜鍔ㄧ敓鎴愪粨搴撻厤缃俊鎭�
+ * @param companyId
+ */
+ private void addConfByDepot(String companyId) {
+ List<Depot> list = depotService.getCacheDepotList(companyId);
+ if (null == list || list.isEmpty()) {
+ return;
+ }
+ DepotConf conf;
+ for (Depot depot : list) {
+ conf = new DepotConf();
+ conf.setDepotId(depot.getId());
+ conf.setCompanyId(depot.getCompanyId());
+ conf.setDeptId(depot.getDeptId());
+ this.saveConf(conf);
+ }
+ }
+
+ /**
+ * 鍒锋柊浠撳簱閰嶇疆缂撳瓨
+ * @param companyId
+ */
+ public void flushConfCache(String companyId) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+
+ List<DepotConf> list = depotConfRepository.getDepotConfByCompanyId(companyId);
+
+ this.setCacheDepotConf(list, companyId);
+ }
+
+ /**
+ * 鏇存柊绮儏淇濆瓨棰戠巼
+ * @param freq
+ */
+ public void updateFreq(String freq) {
+ depotConfRepository.updateGrainFreq(ContextUtil.getCompanyId(), ContextUtil.subDeptId(null), freq);
+ }
+}
--
Gitblit v1.9.3