Ver código fonte

:space_invader:feat: 关闭物料监控,代码优化

Ritchie 1 ano atrás
pai
commit
d0737bc56d

+ 100 - 67
src/main/java/com/szwl/controller/THotUpdateController.java

@@ -4,6 +4,7 @@ package com.szwl.controller;
 import cn.hutool.http.HttpRequest;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.szwl.constant.ResponseCodesEnum;
 import com.szwl.model.bo.R;
 import com.szwl.model.bo.ResponseModel;
 import com.szwl.model.entity.*;
@@ -17,9 +18,9 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * <p>
@@ -34,9 +35,7 @@ import java.util.Objects;
 public class THotUpdateController {
 
     THotUpdateService hotUpdateService;
-
     TEquipmentService equipmentService;
-
     TEquipmentDescService equipmentDescService;
     TAdminService adminService;
 
@@ -51,7 +50,7 @@ public class THotUpdateController {
     @GetMapping("/getPatchUrl")
     public ResponseModel<?> getPatchUrl(String clientId, String isForeign) {
         if (StringUtils.isEmpty(clientId) || StringUtils.isEmpty(isForeign)) {
-            return R.fail("参数不能为空");
+            return R.fail(ResponseCodesEnum.B0001, "参数不能为空");
         }
         LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(TEquipment::getClientId, clientId);
@@ -60,7 +59,7 @@ public class THotUpdateController {
         TAdmin admin = adminService.getById(adminId);
         String ifForeign = admin.getIfForeign();
         if (!isForeign.equals(ifForeign)) {
-            return R.fail("海外内不匹配");
+            return R.fail(ResponseCodesEnum.B0001, "海外内不匹配");
         }
         Long equipmentId = equipment.getId();
         LambdaQueryWrapper<TEquipmentDesc> lqw = Wrappers.lambdaQuery();
@@ -74,10 +73,13 @@ public class THotUpdateController {
         return R.ok(hotUpdate);
     }
 
+
+
     @ApiOperation(value = "录入热更新补丁信息")
     @PostMapping("/postPatchInfo")
     public ResponseModel<?> postPatchInfo(@RequestBody THotUpdate hotUpdate) {
 
+
         String patchVersion = hotUpdate.getPatchVersion(); // 补丁版本号
         String patchStatus = hotUpdate.getPatchStatus(); // 补丁状态,0停止,1发布
         String targetAreas = hotUpdate.getTargetAreas(); // 目标区域,0部分设备,1国内,2海外,3全球
@@ -85,14 +87,20 @@ public class THotUpdateController {
         String clientIdS = hotUpdate.getClientId(); // 设备编号
         String note = hotUpdate.getNote(); // 更新内容
 
-        if (StringUtils.isEmpty(patchVersion) || StringUtils.isEmpty(patchStatus) || StringUtils.isEmpty(patchLink) || StringUtils.isEmpty(note)) {
-            return R.fail("参数不完整");
-        }
+//        if (StringUtils.isEmpty(patchVersion) || StringUtils.isEmpty(patchStatus) || StringUtils.isEmpty(patchLink) || StringUtils.isEmpty(note)) {
+//            return R.fail(ResponseCodesEnum.A0001,"参数不完整");
+//        }
+
+        assert StringUtils.isNotEmpty(patchVersion) : R.fail(ResponseCodesEnum.B0001, "补丁版本号不能为空");
+        assert StringUtils.isNotEmpty(patchStatus) : R.fail(ResponseCodesEnum.B0001, "补丁状态不能为空");
+        assert StringUtils.isNotEmpty(patchLink) : R.fail(ResponseCodesEnum.B0001, "补丁外链不能为空");
+        assert StringUtils.isNotEmpty(note) : R.fail(ResponseCodesEnum.B0001, "更新内容不能为空");
+
         LambdaQueryWrapper<THotUpdate> lqwHot = Wrappers.lambdaQuery();
         lqwHot.eq(THotUpdate::getPatchVersion, patchVersion);
         List<THotUpdate> hotUpdates = hotUpdateService.list(lqwHot);
         if (hotUpdates.size() > 0) {
-            return R.fail("该补丁版本号已存在");
+            return R.fail(ResponseCodesEnum.B0001, "该补丁版本号已存在");
         }
         THotUpdate tHotUpdate = new THotUpdate();
         long hotUpdateId = IDGenerator.commonID();
@@ -108,77 +116,112 @@ public class THotUpdateController {
         switch (targetAreas) {
             case "0":
                 if (StringUtils.isEmpty(clientIdS)) {
-                    return R.fail("推送区域为空时,需要填写设备编号");
+                    return R.fail(ResponseCodesEnum.B0001, "推送区域为空时,需要填写设备编号");
                 }
                 // 推送指定设备
-                tHotUpdate.setClientId(clientIdS);
-                String[] clientIdArray = clientIdS.split(",");
-                for (String s : clientIdArray) {
-                    String clientId = s.trim();
-                    if (StringUtils.isNotEmpty(clientId)) {
-                        LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
-                        wrapper.eq(TEquipment::getClientId, clientId);
-                        TEquipment equipment = equipmentService.getOne(wrapper);
-                        if (Objects.isNull(equipment)) {
-                            return R.fail("设备信息不存在");
-                        }
-                        Long equipmentId = equipment.getId();
-
-                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
-                    }
+//                tHotUpdate.setClientId(clientIdS);
+//                String[] clientIdArray = clientIdS.split(",");
+//                ArrayList<Long> equipmentIdList0 = new ArrayList<>();
+//
+//                for (String s : clientIdArray) {
+//                    String clientId = s.trim();
+//                    if (StringUtils.isNotEmpty(clientId)) {
+//                        LambdaQueryWrapper<TEquipment> wrapper = Wrappers.lambdaQuery();
+//                        wrapper.eq(TEquipment::getClientId, clientId);
+//                        TEquipment equipment = equipmentService.getOne(wrapper);
+//                        if (Objects.isNull(equipment)) {
+//                            return R.fail(ResponseCodesEnum.B0001, "设备信息不存在");
+//                        }
+//                        Long equipmentId = equipment.getId();
+//                        equipmentIdList0.add(equipmentId);
+////                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+//                    }
+//                }
+//                if (!equipmentIdList0.isEmpty()) {
+////                    saveOrUpdateEquipmentDescBatch(equipmentIdList0, hotUpdateId);
+//                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList0, hotUpdateId);
+//                }
+
+                List<String> clientIdList = Arrays.asList(clientIdS.split(","));
+                LambdaQueryWrapper<TEquipment> wrapper1 = Wrappers.lambdaQuery();
+                wrapper1.in(TEquipment::getClientId, clientIdList);
+                List<TEquipment> equipmentList1 = equipmentService.list(wrapper1);
+                if (equipmentList1.isEmpty()) {
+                    return R.fail(ResponseCodesEnum.B0001,"设备信息不存在");
                 }
+                List<Long> equipmentIdList = equipmentList1.stream().map(TEquipment::getId).collect(Collectors.toList());
+                hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList, hotUpdateId);
                 break;
             case "1":
                 // 推送国内
                 LambdaQueryWrapper<TAdmin> wrapper = Wrappers.lambdaQuery();
-                wrapper.eq(TAdmin::getIfForeign,"0");
+                wrapper.eq(TAdmin::getIfForeign, "0");
                 List<TAdmin> list = adminService.list(wrapper);
+                ArrayList<Long> equipmentIdList1 = new ArrayList<>();
+
                 for (TAdmin admin : list) {
                     Long adminId = admin.getId();
-
                     LambdaQueryWrapper<TEquipment> lqw = Wrappers.lambdaQuery();
                     lqw.eq(TEquipment::getAdminId, adminId);
                     List<TEquipment> equipmentList = equipmentService.list(lqw);
                     for (TEquipment equipment : equipmentList) {
                         Long equipmentId = equipment.getId();
-                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+                        equipmentIdList1.add(equipmentId);
                     }
                 }
+                if (!equipmentIdList1.isEmpty()) {
+//                    saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
+                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList1, hotUpdateId);
+                }
 
                 break;
             case "2":
                 // 推送海外
-                LambdaQueryWrapper<TAdmin> lambdaQuery = Wrappers.lambdaQuery();
-                lambdaQuery.eq(TAdmin::getIfForeign,"1");
-                List<TAdmin> abroadList = adminService.list(lambdaQuery);
-                for (TAdmin admin : abroadList) {
-                    Long adminId = admin.getId();
-                    LambdaQueryWrapper<TEquipment> lqw = Wrappers.lambdaQuery();
-                    lqw.eq(TEquipment::getAdminId, adminId);
-                    List<TEquipment> equipmentList = equipmentService.list(lqw);
-                    for (TEquipment equipment : equipmentList) {
-                        Long equipmentId = equipment.getId();
-//                        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
-//                        if (Objects.isNull(equipmentDesc)) {
-//                            TEquipmentDesc equipmentDesc1 = new TEquipmentDesc();
-//                            equipmentDesc1.setEquipmentId(equipmentId);
-//                            equipmentDesc1.setPatchId(hotUpdateId);
-//                            equipmentDescService.save(equipmentDesc1);
-//                        } else {
-//                            equipmentDesc.setPatchId(hotUpdateId);
-//                            equipmentDescService.saveOrUpdate(equipmentDesc);
-//                        }
-                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
-                    }
+//                LambdaQueryWrapper<TAdmin> lambdaQuery = Wrappers.lambdaQuery();
+//                lambdaQuery.eq(TAdmin::getIfForeign, "1");
+//                List<TAdmin> abroadList = adminService.list(lambdaQuery);
+//                ArrayList<Long> equipmentIdList2 = new ArrayList<>();
+//                for (TAdmin admin : abroadList) {
+//                    Long adminId = admin.getId();
+//                    LambdaQueryWrapper<TEquipment> lqw = Wrappers.lambdaQuery();
+//                    lqw.eq(TEquipment::getAdminId, adminId);
+//                    List<TEquipment> equipmentList = equipmentService.list(lqw);
+//                    for (TEquipment equipment : equipmentList) {
+//                        Long equipmentId = equipment.getId();
+//                        equipmentIdList2.add(equipmentId);
+////                        saveOrUpdateEquipmentDesc(equipmentId, hotUpdateId);
+//                    }
+//                }
+//                if (!equipmentIdList2.isEmpty()) {
+////                    saveOrUpdateEquipmentDescBatch(equipmentIdList2, hotUpdateId);
+//                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList2,hotUpdateId);
+//                }
+
+                List<TAdmin> adminList = adminService.lambdaQuery().eq(TAdmin::getIfForeign, "1").list();
+                List<Long> equipmentIdList3 = adminList.stream().flatMap(admin -> equipmentService.lambdaQuery().eq(TEquipment::getAdminId, admin.getId()).list().stream()).map(TEquipment::getId).collect(Collectors.toList());
+                if (!equipmentIdList3.isEmpty()) {
+//                    saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
+                    hotUpdateService.saveOrUpdateEquipmentDescBatch(equipmentIdList3, hotUpdateId);
                 }
+
                 break;
             case "3":
                 // 推送全球
-                List<TEquipmentDesc> equipmentDescAll = equipmentDescService.list();
-                for (TEquipmentDesc equipmentDesc : equipmentDescAll) {
-                    equipmentDesc.setPatchId(hotUpdateId);
-                    equipmentDescService.saveOrUpdate(equipmentDesc);
-                }
+//                List<TEquipmentDesc> equipmentDescAll = equipmentDescService.list();
+//                ArrayList<TEquipmentDesc> equipmentDescArrayList = new ArrayList<>();
+//
+//                for (TEquipmentDesc equipmentDesc : equipmentDescAll) {
+//                    equipmentDesc.setPatchId(hotUpdateId);
+//                    equipmentDescArrayList.add(equipmentDesc);
+////                    equipmentDescService.saveOrUpdate(equipmentDesc);
+//                }
+//                if (!equipmentDescArrayList.isEmpty()) {
+//                    equipmentDescService.saveOrUpdateBatch(equipmentDescArrayList);
+//                }
+
+                List<TEquipmentDesc> equipmentDescList = equipmentDescService.list();
+                equipmentDescList.forEach(d -> d.setPatchId(hotUpdateId));
+                equipmentDescService.saveOrUpdateBatch(equipmentDescList);
 
                 break;
             default:
@@ -190,15 +233,5 @@ public class THotUpdateController {
         return R.ok("录入成功");
     }
 
-
-    private void saveOrUpdateEquipmentDesc(Long equipmentId, Long hotUpdateId) {
-        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
-        if (Objects.isNull(equipmentDesc)) {
-            equipmentDesc = new TEquipmentDesc();
-            equipmentDesc.setEquipmentId(equipmentId);
-        }
-        equipmentDesc.setPatchId(hotUpdateId);
-        equipmentDescService.saveOrUpdate(equipmentDesc);
-    }
 }
 

+ 2 - 0
src/main/java/com/szwl/controller/TLogoController.java

@@ -80,6 +80,8 @@ public class TLogoController {
 //        return R.fail(P0001,"仅管理员可修改logo");
 //    }
 
+    // TODO: 2024-01-27
+
     @ApiOperation(value = "定制logo")
     @PostMapping("/customLogo")
     public JsonMessage customLogo(@RequestBody Map<String, Object> body) {

+ 28 - 0
src/main/java/com/szwl/controller/TParametersController.java

@@ -139,5 +139,33 @@ public class TParametersController {
         return R.ok(ResponseCodesEnum.ALL_OK,"开启物料监控功能成功SUCCESS");
     }
 
+    @ApiOperation(value = "关闭物料监控")
+    @PostMapping("/disableMaterial")
+    public ResponseModel<?> disableMaterial(@RequestBody TParameters parameters) {
+        Long equipmentId = parameters.getEquipmentId();
+        if (equipmentId == null) {
+            return R.fail(ResponseCodesEnum.A0001,"设备id不能为空");
+        }
+        TEquipmentDesc equipmentDesc = equipmentDescService.getById(equipmentId);
+        if (Objects.isNull(equipmentDesc)) {
+            TEquipmentDesc tEquipmentDesc = new TEquipmentDesc();
+            tEquipmentDesc.setEquipmentId(equipmentId);
+            tEquipmentDesc.setIsMaterialUse("0");
+            equipmentDescService.saveOrUpdate(tEquipmentDesc);
+        } else {
+            String isMaterialUse = equipmentDesc.getIsMaterialUse();
+            if (StringUtils.isNotEmpty(isMaterialUse) && "0".equals(isMaterialUse)) {
+                return R.ok(ResponseCodesEnum.ALL_OK,"已关闭CLOSED");
+            }
+            equipmentDesc.setIsMaterialUse("0");
+            equipmentDescService.saveOrUpdate(equipmentDesc);
+        }
+
+        TEquipment equipment = tEquipmentService.getById(equipmentId);
+        tEquipmentService.sentMessage(equipment.getClientId(), PushUtils.buildJson("Param", "M502" + ":" + "0").toString());
+
+        return R.ok(ResponseCodesEnum.ALL_OK,"物料监控已关闭CLOSED");
+    }
+
 }
 

+ 3 - 0
src/main/java/com/szwl/service/THotUpdateService.java

@@ -3,6 +3,8 @@ package com.szwl.service;
 import com.szwl.model.entity.THotUpdate;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -13,4 +15,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface THotUpdateService extends IService<THotUpdate> {
 
+    void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId);
 }

+ 19 - 0
src/main/java/com/szwl/service/impl/THotUpdateServiceImpl.java

@@ -1,11 +1,17 @@
 package com.szwl.service.impl;
 
+import com.szwl.model.entity.TEquipmentDesc;
 import com.szwl.model.entity.THotUpdate;
 import com.szwl.mapper.THotUpdateMapper;
+import com.szwl.service.TEquipmentDescService;
 import com.szwl.service.THotUpdateService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -17,4 +23,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class THotUpdateServiceImpl extends ServiceImpl<THotUpdateMapper, THotUpdate> implements THotUpdateService {
 
+    @Autowired
+    private TEquipmentDescService equipmentDescService;
+    @Override
+    public void saveOrUpdateEquipmentDescBatch(List<Long> equipmentIdList, Long hotUpdateId) {
+        ArrayList<TEquipmentDesc> descList = new ArrayList<>();
+        for (Long equipmentId : equipmentIdList) {
+            TEquipmentDesc equipmentDesc = new TEquipmentDesc();
+            equipmentDesc.setEquipmentId(equipmentId);
+            equipmentDesc.setPatchId(hotUpdateId);
+            descList.add(equipmentDesc);
+        }
+        equipmentDescService.saveOrUpdateBatch(descList);
+    }
 }