Bläddra i källkod

报警阀值云端多仓选择

hanqingsong 5 år sedan
förälder
incheckning
7cf72d403c

+ 49 - 4
src/main/java/com/chinaitop/depot/intelligent/basicdata/controller/WarningThresholdController.java

@@ -1,8 +1,10 @@
1 1
 package com.chinaitop.depot.intelligent.basicdata.controller;
2 2
 
3
+import com.alibaba.fastjson.JSON;
3 4
 import com.chinaitop.depot.intelligent.basicdata.model.TWarningThreshold;
4 5
 import com.chinaitop.depot.intelligent.basicdata.model.TWarningThresholdList;
5 6
 import com.chinaitop.depot.intelligent.basicdata.service.WarningThresholdService;
7
+import com.chinaitop.depot.intelligent.utils.DepotStringUtil;
6 8
 import com.chinaitop.depot.intelligent.utils.JsonToObjectUtils;
7 9
 import com.fasterxml.jackson.core.type.TypeReference;
8 10
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -34,6 +36,8 @@ public class WarningThresholdController {
34 36
 
35 37
     @Autowired
36 38
     private WarningThresholdService warningThresholdService;
39
+    @Autowired
40
+    private DepotStringUtil stringUtil;
37 41
 
38 42
     @RequestMapping(value = "/getList", method = RequestMethod.GET)
39 43
     @ApiOperation(value = "查询 预警阈值 信息列表", notes = "查询 预警阈值 信息列表,支持分页")
@@ -75,13 +79,37 @@ public class WarningThresholdController {
75 79
         return ResponseEntity.ok(bycfCodeList);
76 80
     }
77 81
 
82
+    /**
83
+     * 根据时间和组织编码查询多仓房编码,组织编码拦截器获取
84
+     * @param updateTime
85
+     * @param vCfCode
86
+     * @return
87
+     */
88
+    @RequestMapping(value = "/getByTime", method = RequestMethod.GET)
89
+    @ApiOperation(value = "根据编辑时间查询 多个仓房编号", notes = "根据编辑时间查询 多个仓房编号")
90
+    @ApiImplicitParams({
91
+            @ApiImplicitParam(name = "getByTime", value = "编辑时间", paramType = "query")
92
+    })
93
+    public ResponseEntity getByTime(String updateTime, String vCfCode) {
94
+        // 查询条件为空直接返回单个仓房
95
+        if (StringUtils.isBlank(updateTime))
96
+            return ResponseEntity.ok(vCfCode);
97
+        // 获取带逗号的仓房编号字符串
98
+        String neverSeparateStoreCode = warningThresholdService.getCfCodeByTime(updateTime);
99
+        return ResponseEntity.ok(neverSeparateStoreCode);
100
+    }
101
+
78 102
     @RequestMapping(value = "/save", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
79 103
     @ApiOperation(value = "数据更新与添加", notes = "数据更新与添加")
80 104
     @ApiImplicitParams({
81 105
             @ApiImplicitParam(name = "thresholdListJson", value = "表数据", paramType = "form"),
82
-            @ApiImplicitParam(name = "deleteRowId", value = "删除一条数据id", paramType = "query")
106
+            @ApiImplicitParam(name = "deleteRowId", value = "删除一条数据id", paramType = "query"),
107
+            @ApiImplicitParam(name = "orgId", value = "组织机构编码", paramType = "query"),
108
+            @ApiImplicitParam(name = "updateFlag", value = "修改标记", paramType = "query"),
109
+            @ApiImplicitParam(name = "updatevCfCode", value = "添加或减少后的仓房", paramType = "query"),
110
+            @ApiImplicitParam(name = "neverUpdateStoreCodes", value = "要修改前的仓房数", paramType = "query")
83 111
     })
84
-    public ResponseEntity save(String thresholdListJson, String deleteRowId) {
112
+    public ResponseEntity save(String thresholdListJson, String deleteRowId, String updateFlag, String orgId, String updatevCfCode, String neverUpdateStoreCodes) {
85 113
         // deleteRowId 为删除一条数据,再保存时才确定删除.
86 114
         if (StringUtils.isNotBlank(deleteRowId)) {
87 115
             // 调用删除方法
@@ -89,12 +117,29 @@ public class WarningThresholdController {
89 117
         }
90 118
         try {
91 119
             // JSON字符串转对象
92
-            if (thresholdListJson != null) {
120
+            if (StringUtils.isNotBlank(thresholdListJson)) {
93 121
                 ObjectMapper mapper = new ObjectMapper();
94 122
                 mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
95 123
                 List<TWarningThreshold> thresholdList = mapper.readValue(thresholdListJson, new TypeReference<List<TWarningThreshold>>() {
96 124
                 });
97
-                warningThresholdService.saveAndUpdate(thresholdList);
125
+                // 截取仓房编码
126
+                String[] splitBehindCode = updatevCfCode.split(","); // 修改后的仓房
127
+                // 判断需要修改还是保存,是否新增设置仓房
128
+                if ("U_FLAG".equals(updateFlag)) { // 修改
129
+                    thresholdList.forEach(tl -> {
130
+                        // 将id置空,不走updae方法
131
+                        tl.setId("");
132
+                    });
133
+                    // 需要删除的仓房信息=修改前∪修改后(并集)
134
+                    String union = stringUtil.getUnion(updatevCfCode, neverUpdateStoreCodes, ",");
135
+                    String[] split = union.split(",");
136
+                    thresholdListJson = JSON.toJSONString(thresholdList); // id置空的json字符串
137
+                    // 根据仓房编码和orgId删除主表和详情数据
138
+                    warningThresholdService.deleteByStoreCodeAndOrgId(split, orgId);
139
+                }
140
+                // 新增,修改处理数据
141
+                List<TWarningThreshold> newThresholdList = warningThresholdService.storeListData(thresholdListJson, splitBehindCode);
142
+                warningThresholdService.saveAndUpdate(newThresholdList, splitBehindCode); // splitBehindCode 截取之后的仓房数组
98 143
             }
99 144
         } catch (Exception e) {
100 145
             e.printStackTrace();

+ 7 - 0
src/main/java/com/chinaitop/depot/intelligent/basicdata/mapper/TWarningThresholdListMapper.java

@@ -27,4 +27,11 @@ public interface TWarningThresholdListMapper {
27 27
     int updateByPrimaryKeySelective(TWarningThresholdList record);
28 28
 
29 29
     int updateByPrimaryKey(TWarningThresholdList record);
30
+
31
+    /**
32
+     * 根据时间和组织编码查询多仓房编码,组织编码拦截器获取
33
+     * @param updateTime
34
+     * @return
35
+     */
36
+    String getCfCodeByTime(String updateTime);
30 37
 }

+ 9 - 0
src/main/java/com/chinaitop/depot/intelligent/basicdata/mapper/TWarningThresholdListMapper.xml

@@ -303,4 +303,13 @@
303 303
       del_flag = #{delFlag,jdbcType=INTEGER}
304 304
     where id = #{id,jdbcType=VARCHAR}
305 305
   </update>
306
+  <select id="getCfCodeByTime" parameterType="java.lang.String" resultType="java.lang.String">
307
+    SELECT
308
+        GROUP_CONCAT(v_cf_code) v_cf_code
309
+    FROM
310
+        t_warning_threshold_list
311
+    WHERE
312
+        del_flag = '1'
313
+    AND update_time = #{updateTime}
314
+  </select>
306 315
 </mapper>

+ 18 - 1
src/main/java/com/chinaitop/depot/intelligent/basicdata/service/WarningThresholdService.java

@@ -12,7 +12,7 @@ public interface WarningThresholdService {
12 12
 
13 13
     List<TWarningThreshold> getByCfCode(String cfCode, Integer wState,String orgId);
14 14
 
15
-    void saveAndUpdate(List<TWarningThreshold> thresholdList);
15
+    void saveAndUpdate(List<TWarningThreshold> thresholdList, String[] splitBehindCode);
16 16
 
17 17
     int deleteById(String id);
18 18
 
@@ -36,4 +36,21 @@ public interface WarningThresholdService {
36 36
      * @return
37 37
      */
38 38
     Map<String, Map<String, Object>> getValueByOrgIdOrCfCode(String orgId, String vCfCode);
39
+
40
+    /**
41
+     * 根据时间和组织编码查询多仓房编码,组织编码拦截器获取
42
+     * @param updateTime
43
+     * @return
44
+     */
45
+    String getCfCodeByTime(String updateTime);
46
+
47
+    //    String checkAddStore(String storeCodes);
48
+    List<TWarningThreshold> storeListData(String thresholdListJson, String[] splitBehindCode);
49
+
50
+    /**
51
+     * 根据仓房编码和orgId批量删除主表和详情数据
52
+     * @param splitBehindCode
53
+     * @param orgId
54
+     */
55
+    void deleteByStoreCodeAndOrgId(String[] splitBehindCode, String orgId);
39 56
 }

+ 77 - 22
src/main/java/com/chinaitop/depot/intelligent/basicdata/service/impl/WarningThresholdServiceImpl.java

@@ -1,5 +1,6 @@
1 1
 package com.chinaitop.depot.intelligent.basicdata.service.impl;
2 2
 
3
+import com.alibaba.fastjson.JSON;
3 4
 import com.chinaitop.depot.intelligent.basicdata.mapper.TWarningThresholdListMapper;
4 5
 import com.chinaitop.depot.intelligent.basicdata.mapper.TWarningThresholdMapper;
5 6
 import com.chinaitop.depot.intelligent.basicdata.model.TWarningThreshold;
@@ -72,42 +73,50 @@ public class WarningThresholdServiceImpl implements WarningThresholdService {
72 73
      * @param thresholdList
73 74
      */
74 75
     @Override
75
-    public void saveAndUpdate(List<TWarningThreshold> thresholdList) {
76
+    public void saveAndUpdate(List<TWarningThreshold> thresholdList, String[] splitBehindCode) {
77
+        // 使用时间作为组条件
78
+        Date date = new Date();
76 79
         for (TWarningThreshold tWarningThreshold : thresholdList) {
80
+            // 保存,修改共用set数据
81
+            tWarningThreshold.setwUpdateTime(date);
77 82
             // 保存详情
78 83
             if (StringUtils.isBlank(tWarningThreshold.getId())) {
79 84
                 tWarningThreshold.setId(uUidUtils.getCodeId(tWarningThreshold.getOrgId(), "t_warning_threshold"));
80
-                tWarningThreshold.setwUpdateTime(new Date());
81 85
                 tWarningThreshold.setDelFlag(1); //未删除
82 86
                 tWarningThresholdMapper.insert(tWarningThreshold);
83 87
             } else {
84 88
                 // 更新详情
85
-                tWarningThreshold.setwUpdateTime(new Date());
86 89
                 tWarningThresholdMapper.updateByPrimaryKeySelective(tWarningThreshold);
87 90
             }
88 91
         }
89 92
         // 保存,修改列表
90 93
         TWarningThreshold tWarningThreshold = thresholdList.get(0);
91
-        List<TWarningThresholdList> list = this.getList(tWarningThreshold.getvCfCode(),tWarningThreshold.getOrgId());
92
-        TWarningThresholdList tWarningThresholdList = new TWarningThresholdList();
93
-        if (list.size() == 0) {
94
-            // 保存
95
-            tWarningThresholdList.setId(uUidUtils.getCodeId(tWarningThreshold.getOrgId(), "t_warning_threshold"));
96
-            tWarningThresholdList.setOrgId(tWarningThreshold.getOrgId());
97
-            tWarningThresholdList.setvCfCode(tWarningThreshold.getvCfCode());
94
+        // 根据仓房编码多次修改列表
95
+        for (int i = 0; i < splitBehindCode.length; i++) {
96
+            // 获取每一个仓房编码
97
+            String storCode = splitBehindCode[i];
98
+            List<TWarningThresholdList> list = this.getList(storCode, tWarningThreshold.getOrgId());
99
+            TWarningThresholdList tWarningThresholdList = new TWarningThresholdList();
100
+            // 保存,修改共用set数据
101
+            tWarningThresholdList.setUpdateTime(date);
98 102
             tWarningThresholdList.setUpdatePerson(tWarningThreshold.getwUpdatePerson());
99
-            tWarningThresholdList.setUpdateTime(new Date());
100
-            tWarningThresholdList.setDelFlag(1); //未删除
101
-            tWarningThresholdListMapper.insert(tWarningThresholdList);
102
-        } else {
103
-            // 更新
104
-            TWarningThresholdListExample example = new TWarningThresholdListExample();
105
-            TWarningThresholdListExample.Criteria criteria = example.createCriteria();
106
-            if (StringUtils.isNotBlank(tWarningThreshold.getvCfCode()))
107
-                criteria.andVCfCodeEqualTo(tWarningThreshold.getvCfCode());
108
-            tWarningThresholdList.setUpdatePerson(tWarningThreshold.getwUpdatePerson());
109
-            tWarningThresholdList.setUpdateTime(new Date());
110
-            tWarningThresholdListMapper.updateByExampleSelective(tWarningThresholdList, example);
103
+            if (list.size() == 0) {
104
+                // 保存
105
+                tWarningThresholdList.setId(uUidUtils.getCodeId(tWarningThreshold.getOrgId(), "t_warning_threshold"));
106
+                tWarningThresholdList.setOrgId(tWarningThreshold.getOrgId());
107
+                tWarningThresholdList.setvCfCode(storCode);
108
+                tWarningThresholdList.setUpdatePerson(tWarningThreshold.getwUpdatePerson());
109
+                tWarningThresholdList.setDelFlag(1); //未删除
110
+                tWarningThresholdListMapper.insert(tWarningThresholdList);
111
+            } else {
112
+                // 更新
113
+                TWarningThresholdListExample example = new TWarningThresholdListExample();
114
+                TWarningThresholdListExample.Criteria criteria = example.createCriteria();
115
+                if (StringUtils.isNotBlank(storCode))
116
+                    criteria.andVCfCodeEqualTo(storCode);
117
+                tWarningThresholdList.setUpdatePerson(tWarningThreshold.getwUpdatePerson());
118
+                tWarningThresholdListMapper.updateByExampleSelective(tWarningThresholdList, example);
119
+            }
111 120
         }
112 121
     }
113 122
 
@@ -275,4 +284,50 @@ public class WarningThresholdServiceImpl implements WarningThresholdService {
275 284
         return mapObj;
276 285
     }
277 286
 
287
+    /**
288
+     * 根据时间和组织编码查询多仓房编码,组织编码拦截器获取
289
+     *
290
+     * @param updateTime
291
+     * @return
292
+     */
293
+    @Override
294
+    public String getCfCodeByTime(String updateTime) {
295
+        return tWarningThresholdListMapper.getCfCodeByTime(updateTime);
296
+    }
297
+
298
+    // 改变list数组,多仓房编码拆分成多个list
299
+    public List<TWarningThreshold> storeListData(String thresholdListJson, String[] splitBehindCode) {
300
+        // 缓存空间
301
+        List<TWarningThreshold> newThresholdList = new ArrayList<>();
302
+        // 截取仓房编码
303
+        for (int i = 0; i < splitBehindCode.length; i++) {
304
+            // 数据倍增,防止list数据"$ref": "$[0]" 重复引用对象地址
305
+            List<TWarningThreshold> tWarningThresholds = JSON.parseArray(thresholdListJson, TWarningThreshold.class);
306
+            for (int y = 0; y < tWarningThresholds.size(); y++) {
307
+                TWarningThreshold tWarningThreshold = tWarningThresholds.get(y);
308
+                tWarningThreshold.setvCfCode(splitBehindCode[i]);
309
+                newThresholdList.add(tWarningThreshold);
310
+            }
311
+        }
312
+        return newThresholdList;
313
+    }
314
+
315
+    @Override
316
+    public void deleteByStoreCodeAndOrgId(String[] splitBehindCode, String orgId) {
317
+        for (int i = 0; i < splitBehindCode.length; i++) {
318
+            // 删除列表数据
319
+            TWarningThresholdListExample example = new TWarningThresholdListExample();
320
+            TWarningThresholdListExample.Criteria criteria = example.createCriteria();
321
+            criteria.andVCfCodeEqualTo(splitBehindCode[i]);
322
+            criteria.andOrgIdEqualTo(orgId);
323
+            tWarningThresholdListMapper.deleteByExample(example);
324
+            // 删除详情数据
325
+            TWarningThresholdExample example1 = new TWarningThresholdExample();
326
+            TWarningThresholdExample.Criteria criteria1 = example1.createCriteria();
327
+            criteria1.andVCfCodeEqualTo(splitBehindCode[i]);
328
+            criteria1.andOrgIdEqualTo(orgId);
329
+            tWarningThresholdMapper.deleteByExample(example1);
330
+        }
331
+    }
332
+
278 333
 }

+ 33 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/DepotStringUtil.java

@@ -0,0 +1,33 @@
1
+package com.chinaitop.depot.intelligent.utils;
2
+
3
+import org.apache.commons.lang3.StringUtils;
4
+import org.springframework.stereotype.Component;
5
+
6
+/**
7
+ * @author qingsong.han
8
+ * @description: 库级字符串处理工具类
9
+ * @create 2020-09-14 11:22
10
+ */
11
+@Component
12
+public class DepotStringUtil {
13
+
14
+    // 获取两个字符串的并集(去重后取并集)
15
+    public static String getUnion(String str1,String str2,String regex) {
16
+
17
+        if (StringUtils.isEmpty(str1) || StringUtils.isEmpty(str2)) {
18
+            return StringUtils.isEmpty(str1) ? str2 : str1;
19
+        }
20
+        StringBuilder sBuilder = new StringBuilder(str2);
21
+        String[] array = str1.split(regex);
22
+        for (String s : array) {
23
+            if (StringUtils.isEmpty(s)) {
24
+                continue;
25
+            }
26
+            if (!str2.contains(s)) {
27
+                sBuilder.append(",").append(s);
28
+            }
29
+        }
30
+        return sBuilder.toString();
31
+    }
32
+
33
+}