Browse Source

配置管理

wudingsheng 1 week ago
parent
commit
4cbced9148

+ 4 - 0
imcs-admin-boot/imcs-tenant-biz/src/main/java/com/github/zuihou/tenant/service/ProductionlineService.java

@@ -1,5 +1,6 @@
 package com.github.zuihou.tenant.service;
 
+import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperCacheService;
 import com.github.zuihou.security.model.SysUser;
 import com.github.zuihou.tenant.dto.ProductionlineBoxDTO;
@@ -69,4 +70,7 @@ public interface ProductionlineService extends SuperCacheService<Productionline>
     Productionline getCurrentProductionline(SysUser sysUser);
 
     void setProductionlineBoxConf(ProductionlineBoxDTO model);
+
+    R<Map<String, Object>> getLineProps(Map<String, Object> body);
+    R saveLineProps(Map<String, Object> req);
 }

+ 88 - 2
imcs-admin-boot/imcs-tenant-biz/src/main/java/com/github/zuihou/tenant/service/impl/ProductionlineServiceImpl.java

@@ -1,6 +1,7 @@
 package com.github.zuihou.tenant.service.impl;
 
 import cn.hutool.core.convert.Convert;
+import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperCacheServiceImpl;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CacheKey;
@@ -30,8 +31,7 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.github.zuihou.common.constant.CacheKey.TENANT;
@@ -77,6 +77,7 @@ public class ProductionlineServiceImpl extends SuperCacheServiceImpl<Productionl
     private RedisTemplate<String, Object> redisTemplate;
 
 
+
     @Override
     protected String getRegion() {
         return TENANT;
@@ -289,4 +290,89 @@ public class ProductionlineServiceImpl extends SuperCacheServiceImpl<Productionl
         redisTemplate.opsForValue().set(CacheKey.PROPERTIES
                 + model.getZoneId() + CacheKey.BOX_CAPACITY, model.getBomCount());
     }
+
+    @Override
+    public R<Map<String, Object>> getLineProps(Map<String, Object> body) {
+        String zoneId = (String) body.get("zoneId");
+        if (StringUtils.isEmpty(zoneId)) {
+            return R.fail("zoneId 不能为空");
+        }
+
+        // 构建 Redis Key
+        String keyWms = "PROPERTIES:WMS_FLAG";
+        String keyThree = "PROPERTIES:THREE_FLAG";
+        String keyBox = "PROPERTIES:" + zoneId + "_BOX_CAPACITY";
+
+        List<String> keys = Arrays.asList(keyWms, keyThree, keyBox);
+        List<Object> values = redisTemplate.opsForValue().multiGet(keys);
+
+        Map<String, Object> result = new LinkedHashMap<>();
+
+        // 保证顺序对应
+        Object valWms = values.get(0);
+        Object valThree = values.get(1);
+        Object valBox = values.get(2);
+
+        // ✅ 转换为 Boolean
+        Boolean wmsFlag = (valWms == null) ? false : (Boolean)valWms;
+        Boolean threeFlag = (valThree == null) ? false : (Boolean)valThree;
+        int boxCapacity = (valBox == null) ? 1 : (Integer) valBox;
+
+        result.put(keyWms, wmsFlag);
+        result.put(keyThree, threeFlag);
+        result.put(keyBox, boxCapacity);
+
+        // 如果 Redis 没有,就写入默认值
+        if (valWms == null || valThree == null || valBox == null) {
+            Map<String, Object> defaults = new LinkedHashMap<>();
+            defaults.put(keyWms, wmsFlag);
+            defaults.put(keyThree, threeFlag);
+            defaults.put(keyBox, boxCapacity);
+            redisTemplate.opsForValue().multiSet(defaults);
+        }
+
+        return R.success(result);
+    }
+
+    public R saveLineProps(Map<String, Object> req) {
+        try {
+            // 从 Map 中直接取 zoneId 和 properties
+            String zoneId = (String) req.get("zoneId");
+            if (StringUtils.isEmpty(zoneId)) {
+                return R.fail("zoneId 不能为空");
+            }
+
+            Object propsObj = req.get("properties");
+            if (!(propsObj instanceof List)) {
+                return R.fail("properties 参数格式错误,应为数组");
+            }
+
+            @SuppressWarnings("unchecked")
+            List<Map<String, Object>> props = (List<Map<String, Object>>) propsObj;
+
+
+            Map<String, Object> stringObjectMap = props.get(0);
+            stringObjectMap.put("value",Boolean.valueOf(stringObjectMap.get("value").toString()));
+
+            Map<String, Object> stringObjectMap1 = props.get(1);
+            stringObjectMap1.put("value",Boolean.valueOf(stringObjectMap1.get("value").toString()));
+
+            Map<String, Object> stringObjectMap2 = props.get(2);
+            stringObjectMap2.put("value",Integer.valueOf(stringObjectMap2.get("value").toString()));
+
+            Map<String,Object> result=new HashMap<>();
+            props.stream().forEach(vo->{
+                result.put(vo.get("code").toString(),vo.get("value"));
+            });
+
+            // 批量写入 Redis
+            if (!result.isEmpty()) {
+                redisTemplate.opsForValue().multiSet(result);
+            }
+
+            return R.success();
+        } catch (Exception e) {
+            return R.fail("保存失败:" + e.getMessage());
+        }
+    }
 }

+ 13 - 0
imcs-admin-boot/imcs-tenant-controller/src/main/java/com/github/zuihou/tenant/controller/ProductionlineController.java

@@ -121,4 +121,17 @@ public class ProductionlineController  extends SuperCacheController<Productionli
         return success(productionline);
     }
 
+
+    @PostMapping("/getLineProps")
+    public R<Map<String, Object>> getLineProps(@RequestBody Map<String, Object> body) {
+        return baseService.getLineProps(body);
+    }
+
+
+    @PostMapping("/saveLineProps")
+    public R<Map<String, String>> saveLineProps(@RequestBody Map<String, Object> req ) {
+
+        return baseService.saveLineProps(req);
+    }
+
 }