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/QuantityService.java | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 239 insertions(+), 0 deletions(-)
diff --git a/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/QuantityService.java b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/QuantityService.java
new file mode 100644
index 0000000..b50bdb5
--- /dev/null
+++ b/fzzy-igdss-core/src/main/java/com/fzzy/igds/service/QuantityService.java
@@ -0,0 +1,239 @@
+package com.fzzy.igds.service;
+
+import com.fzzy.igds.constant.RedisConst;
+import com.fzzy.igds.domain.QuantityConf;
+import com.fzzy.igds.repository.QuantityConfRepository;
+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;
+
+/**
+ * @Description
+ * @Author CZT
+ * @Date 2025/11/28 16:55
+ */
+@Slf4j
+@Service
+public class QuantityService {
+
+ @Resource
+ private QuantityConfRepository quantityConfRepository;
+ @Resource
+ private RedisCache redisCache;
+
+ /**
+ * JPA - 鏌ヨ閰嶇疆淇℃伅锛屾牴鎹簱鍖虹紪鐮佽幏鍙�
+ *
+ * @param companyId
+ * @param deptId
+ * @return
+ */
+ public List<QuantityConf> getConfList(String companyId, String deptId) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+
+ if (StringUtils.isEmpty(deptId)) {
+ deptId = ContextUtil.subDeptId(null);
+ }
+ return quantityConfRepository.listQuantityConf(companyId, deptId);
+ }
+
+ /**
+ * JPA - 鏌ヨ閰嶇疆淇℃伅锛屾牴鎹粍缁囩紪鐮佽幏鍙�
+ *
+ * @param companyId
+ * @return
+ */
+ public List<QuantityConf> getConfList(String companyId) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+
+ return quantityConfRepository.listQuantityConf(companyId);
+ }
+
+ /**
+ * JPA - 鏇存柊淇濆瓨鏁版嵁
+ *
+ * @param conf
+ */
+ public void saveConf(QuantityConf conf) {
+ if (StringUtils.isEmpty(conf.getDepotId())) {
+ return;
+ }
+ 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());
+ quantityConfRepository.save(conf);
+ //鍒锋柊缂撳瓨
+ setCacheQuantityConf(conf);
+ }
+
+ /**
+ * JPA- 鏇存柊閰嶇疆鍜嬫贩涓お
+ *
+ * @param conf
+ */
+ public void updateQuantityConfBySn(QuantityConf conf) {
+ //鏇存柊鐘舵��
+ quantityConfRepository.updateConfStatus(conf.getIp(), conf.getPort(), conf.getStatus(), conf.getSn());
+
+ setCacheQuantityConf(conf);
+ }
+
+ /**
+ * JPA - 鍒犻櫎鏁版嵁
+ *
+ * @param conf
+ * @return
+ */
+ public String delQuantityConf(QuantityConf conf) {
+ quantityConfRepository.delete(conf);
+ //鍒犻櫎閰嶇疆淇℃伅
+
+ flushConfCache(conf.getCompanyId(), conf.getDeptId());
+ return null;
+ }
+
+ /**
+ * 鍒锋柊缂撳瓨
+ *
+ * @param companyId
+ * @param deptId
+ */
+ public void flushConfCache(String companyId, String deptId) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ if (StringUtils.isEmpty(deptId)) {
+ deptId = ContextUtil.subDeptId(null);
+ }
+ List<QuantityConf> list = this.getConfList(companyId, deptId);
+
+ this.setCacheQuantityConf(list);
+ }
+
+ /**
+ * 璁剧疆缂撳瓨
+ *
+ * @param list
+ */
+ public void setCacheQuantityConf(List<QuantityConf> list) {
+ if (null == list || list.isEmpty()) {
+ return;
+ }
+ String key;
+ for (QuantityConf conf : list) {
+ if (StringUtils.isEmpty(conf.getSn())) {
+ conf.setSn(conf.getYtIp());
+ }
+ key = RedisConst.buildKeyByPrefix(RedisConst.KEY_QUANTITY_CONF, conf.getSn());
+ redisCache.setCacheObject(key, conf);
+ }
+ }
+
+ /**
+ * 璁剧疆缂撳瓨
+ *
+ * @param conf
+ */
+ public void setCacheQuantityConf(QuantityConf conf) {
+ if (StringUtils.isEmpty(conf.getSn())) {
+ conf.setSn(conf.getYtIp());
+ }
+ String key = RedisConst.buildKeyByPrefix(RedisConst.KEY_QUANTITY_CONF, conf.getSn());
+ redisCache.setCacheObject(key, conf);
+ }
+
+ /**
+ * 鑾峰彇鎵�鏈夐厤缃紦瀛�
+ *
+ * @return
+ */
+ public List<QuantityConf> getCacheConfList(String companyId) {
+
+ String pattern = RedisConst.buildKeyByPrefix(RedisConst.KEY_QUANTITY_CONF, null) + "*";
+ Collection<String> keys = redisCache.keys(pattern);
+ if (null == keys || keys.isEmpty()) {
+ return null;
+ }
+ List<QuantityConf> list = new ArrayList<>();
+ QuantityConf conf;
+ for (String key : keys) {
+ conf = (QuantityConf) redisCache.getCacheObject(key);
+ if (null == conf) {
+ continue;
+ }
+ list.add(conf);
+ }
+ if (list.isEmpty()) {
+ if (StringUtils.isEmpty(companyId)) {
+ companyId = ContextUtil.getCompanyId();
+ }
+ list = this.getConfList(companyId);
+ this.setCacheQuantityConf(list);
+ }
+ return list;
+ }
+
+ /**
+ * 鏍规嵁浠撳簱缂栫爜鑾峰彇鑾峰彇缂撳瓨
+ *
+ * @param companyId
+ * @param depotId
+ * @return
+ */
+ public QuantityConf getCacheQuantityConf(String companyId, String depotId) {
+ if (StringUtils.isEmpty(depotId)) {
+ return null;
+ }
+ List<QuantityConf> list = getCacheConfList(companyId);
+ if (null == list || list.isEmpty()) {
+ return null;
+ }
+ for (QuantityConf conf : list) {
+ if (conf.getCompanyId().equals(companyId) && conf.getDepotId().equals(depotId)) {
+ return conf;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 鏍规嵁SN鑾峰彇閰嶇疆淇℃伅
+ *
+ * @param sn
+ * @return
+ */
+ public QuantityConf getCacheQuantityConfBySn(String sn) {
+ if (StringUtils.isEmpty(sn)) {
+ return null;
+ }
+ List<QuantityConf> list = getCacheConfList(null);
+ if (null == list || list.isEmpty()) {
+ return null;
+ }
+ for (QuantityConf conf : list) {
+ if (conf.getSn().equals(sn)) {
+ return conf;
+ }
+ }
+ return null;
+ }
+
+}
--
Gitblit v1.9.3