From e8937f27fce194d015ce6c27d286e7fc89f5e580 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期三, 23 四月 2025 17:29:47 +0800
Subject: [PATCH] 查询开关阀记录相关修改

---
 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java |  293 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 267 insertions(+), 26 deletions(-)

diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java
index f592fca..77706f0 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java
@@ -5,16 +5,17 @@
 import com.dy.common.webUtil.BaseResponseUtils;
 import com.dy.common.webUtil.QueryResultVo;
 import com.dy.common.webUtil.ResultCodeMsg;
+import com.dy.pipIrrGlobal.pojoIr.IrGroupClient;
 import com.dy.pipIrrGlobal.pojoIr.IrGroupUnit;
 import com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup;
-import com.dy.pipIrrGlobal.pojoIr.IrIrrigateUnit;
 import com.dy.pipIrrGlobal.voIr.VoGroup;
+import com.dy.pipIrrGlobal.voIr.VoGroupDetail;
 import com.dy.pipIrrGlobal.voIr.VoGroupOne;
-import com.dy.pipIrrGlobal.voIr.VoUnit;
-import com.dy.pipIrrGlobal.voIr.VoUnitOne;
+import com.dy.pipIrrGlobal.voIr.VoGroupSimple;
 import com.dy.pipIrrGlobal.voSe.VoActiveCard;
-import com.dy.pipIrrIrrigate.irrigateUnit.IrrigateUnitSv;
-import com.dy.pipIrrIrrigate.irrigateGroup.QueryVo;
+import com.dy.pipIrrIrrigate.irrigateGroup.dto.GroupClient;
+import com.dy.pipIrrIrrigate.irrigateGroup.dto.IrrigateGroup;
+import com.dy.pipIrrIrrigate.irrigateGroup.qo.QoGroup;
 import com.dy.pipIrrIrrigate.result.IrrigateResultCode;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.media.Content;
@@ -31,10 +32,7 @@
 import org.springframework.validation.BindingResult;
 import org.springframework.web.bind.annotation.*;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
+import java.util.*;
 
 /**
  * @author :WuZeYu
@@ -77,7 +75,7 @@
         try {
             Integer rec = Optional.ofNullable(irrigateGroupSv.addIrrigateGroup(po)).orElse(0);
             if (rec == 0) {
-                return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+                return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_GROUP_FAIL.getMessage());
             }
         } catch (Exception e) {
             log.error("鍒涘缓杞亴缁勫紓甯�", e);
@@ -88,6 +86,7 @@
 
     /**
      * 閫昏緫鍒犻櫎鐏屾簤鍗曞厓
+     *
      * @param
      * @return
      */
@@ -105,13 +104,13 @@
     @SsoAop()
     public BaseResponse<Boolean> delete(@RequestBody Map map) {
         if (map == null || map.size() <= 0) {
-            BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage());
+            BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_GROUP_ID.getMessage());
         }
         Long groupId = Long.parseLong(map.get("id").toString());
         try {
             Integer rows = irrigateGroupSv.deleteIrrigateGroup(groupId);
             if (rows == 0) {
-                return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+                return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_GROUP_FAIL.getMessage());
             }
         } catch (Exception e) {
             log.error("鍒犻櫎杞亴缁勫紓甯�", e);
@@ -122,6 +121,7 @@
 
     /**
      * 鎵归噺鍒犻櫎
+     *
      * @param groupIds
      * @return
      */
@@ -138,7 +138,7 @@
             try {
                 Integer rows = irrigateGroupSv.deleteIrrigateGroup(groupId);
                 if (rows == 0) {
-                    return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+                    return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_GROUP_FAIL.getMessage());
                 }
             } catch (Exception e) {
                 log.error("鍒犻櫎杞亴缁勫紓甯�", e);
@@ -150,6 +150,7 @@
 
     /**
      * 淇敼鐏屾簤鍗曞厓
+     *
      * @param po
      * @param bindingResult
      * @return
@@ -166,14 +167,14 @@
     @PostMapping(path = "update", consumes = MediaType.APPLICATION_JSON_VALUE)
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> update(@RequestBody @Valid IrIrrigateGroup po, BindingResult bindingResult){
+    public BaseResponse<Boolean> update(@RequestBody @Valid IrIrrigateGroup po, BindingResult bindingResult) {
         if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
         try {
             Integer rec = Optional.ofNullable(irrigateGroupSv.updateIrrigateGroup(po)).orElse(0);
             if (rec == 0) {
-                return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_PROJECT_FAIL.getMessage());
+                return BaseResponseUtils.buildFail(IrrigateResultCode.UPDATE_GROUP_FAIL.getMessage());
             }
         } catch (Exception e) {
             log.error("淇敼杞亴缁勫紓甯�", e);
@@ -207,6 +208,7 @@
 
     /**
      * 鍒嗛〉鏌ヨ
+     *
      * @param vo
      * @return
      */
@@ -250,7 +252,7 @@
     @PostMapping(path = "add_unit", consumes = MediaType.APPLICATION_JSON_VALUE)
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> addGroupUnit(@RequestBody @Valid Map<String,Object> po, BindingResult bindingResult) {
+    public BaseResponse<Boolean> addGroupUnit(@RequestBody @Valid Map<String, Object> po, BindingResult bindingResult) {
         if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
@@ -266,7 +268,7 @@
                 irGroupUnit.setOperator(operator);
                 Integer rec = Optional.ofNullable(irrigateGroupSv.addGroupUnit(irGroupUnit)).orElse(0);
                 if (rec == 0) {
-                    return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+                    return BaseResponseUtils.buildFail(IrrigateResultCode.GROUP_ADD_UNIT_FAIL.getMessage());
                 }
             }
         } catch (Exception e) {
@@ -277,7 +279,8 @@
     }
 
     /**
-     *  杞亴缁勭Щ闄ょ亴婧夊崟鍏�
+     * 杞亴缁勭Щ闄ょ亴婧夊崟鍏�
+     *
      * @param
      * @return
      */
@@ -293,15 +296,26 @@
     @PostMapping(path = "remove_unit")
     @Transactional(rollbackFor = Exception.class)
     @SsoAop()
-    public BaseResponse<Boolean> deleteGroupUnit(@RequestBody @Valid IrGroupUnit po, BindingResult bindingResult) {
+    public BaseResponse<Boolean> deleteGroupUnit(@RequestBody @Valid Map<String, Object> po, BindingResult bindingResult) {
         if (bindingResult != null && bindingResult.hasErrors()) {
             return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
         }
+        Long groupId = Long.parseLong(po.get("groupId").toString());
+        Long operator = Long.parseLong(po.get("operator").toString());
+        List<Long> unitIds = (List<Long>) po.get("unitIds");
         try {
-            Integer rec = Optional.ofNullable(irrigateGroupSv.deleteGroupUnit(po)).orElse(0);
-            if (rec == 0) {
-                return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+            for (int i = 0; i < unitIds.size(); i++) {
+                Long unitId = unitIds.get(i);
+                IrGroupUnit irGroupUnit = new IrGroupUnit();
+                irGroupUnit.setGroupId(groupId);
+                irGroupUnit.setUnitId(unitId);
+                irGroupUnit.setOperator(operator);
+                Integer rec = Optional.ofNullable(irrigateGroupSv.deleteGroupUnit(irGroupUnit)).orElse(0);
+                if (rec == 0) {
+                    return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage());
+                }
             }
+
         } catch (Exception e) {
             log.error("杞亴缁勭Щ闄ょ亴婧夊崟鍏冨紓甯�", e);
             return BaseResponseUtils.buildException(e.getMessage());
@@ -311,10 +325,15 @@
 
     @GetMapping(path = "bind_units")
     @SsoAop()
-    public BaseResponse<List<Long>> getGroupBindUnits(Long id) {
+    public BaseResponse<List<String>> getGroupBindUnits(Long id) {
         try {
             List<Long> res = irrigateGroupSv.getGroupBindUnits(id);
-            return BaseResponseUtils.buildSuccess(res);
+            ArrayList<Object> list = new ArrayList<>();
+            for (int i = 0; i < res.size(); i++) {
+                String aLong = res.get(i).toString();
+                list.add(aLong);
+            }
+            return BaseResponseUtils.buildSuccess(list);
         } catch (Exception e) {
             log.error("鑾峰彇涓�涓疆鐏岀粍缁戝畾鐏屾簤鍗曞厓璁板綍寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage());
@@ -323,13 +342,235 @@
 
     @GetMapping(path = "notBind_units")
     @SsoAop()
-    public BaseResponse<List<Long>> getNotBindUnits() {
+    public BaseResponse<List<String>> getNotBindUnits() {
         try {
             List<Long> res = irrigateGroupSv.getNotBindUnits();
-            return BaseResponseUtils.buildSuccess(res);
+            ArrayList<Object> list = new ArrayList<>();
+            for (int i = 0; i < res.size(); i++) {
+                String aLong = res.get(i).toString();
+                list.add(aLong);
+            }
+            return BaseResponseUtils.buildSuccess(list);
         } catch (Exception e) {
             log.error("鑾峰彇鏈粦瀹氳疆鐏岀粍鐨勭亴婧夊崟鍏僫d璁板綍寮傚父", e);
             return BaseResponseUtils.buildException(e.getMessage());
         }
     }
+
+
+    /**
+     * 淇敼杞亴缁勭粦瀹氱殑鐏屾簤鍗曞厓
+     *
+     * @param po            杞亴缁勭亴婧夊崟鍏冧腑闂磋〃
+     * @param bindingResult
+     * @return 娣诲姞鏄惁鎴愬姛
+     */
+    @Operation(summary = "淇敼杞亴缁勭粦瀹氱殑鐏屾簤鍗曞厓", description = "淇敼杞亴缁勭粦瀹氱殑鐏屾簤鍗曞厓")
+    @ApiResponses(value = {
+            @ApiResponse(
+                    responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE,
+                    description = "鎿嶄綔缁撴灉锛歵rue锛氭垚鍔燂紝false锛氬け璐ワ紙BaseResponse.content锛�",
+                    content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE,
+                            schema = @Schema(implementation = Boolean.class))}
+            )
+    })
+    @PostMapping(path = "updateBindUnits", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> updateBindUnits(@RequestBody @Valid Map<String, Object> po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        Long groupId = Long.parseLong(po.get("groupId").toString());
+        Long operator = Long.parseLong(po.get("operator").toString());
+        List<String> newUnitIds = (List<String>) po.get("unitIds");
+        List<Long> oldUnitIds = irrigateGroupSv.getGroupBindUnits(groupId);
+
+        IrGroupUnit irGroupUnit = new IrGroupUnit();
+        irGroupUnit.setGroupId(groupId);
+        irGroupUnit.setOperator(operator);
+        try {
+            for (int j = 0; j < oldUnitIds.size(); j++) {
+                Long oldUnitId = oldUnitIds.get(j);
+                if (!newUnitIds.toString().contains(oldUnitId.toString())) {
+                    irGroupUnit.setUnitId(oldUnitId);
+                    Integer rec = Optional.ofNullable(irrigateGroupSv.deleteGroupUnit(irGroupUnit)).orElse(0);
+                    if (rec == 0) {
+                        return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+                    }
+                }
+            }
+            for (int i = 0; i < newUnitIds.size(); i++) {
+                Long newUnitId = Long.parseLong(newUnitIds.get(i));
+                if (!oldUnitIds.toString().contains(newUnitId.toString())) {
+                    irGroupUnit.setUnitId(newUnitId);
+                    Integer rec = Optional.ofNullable(irrigateGroupSv.addGroupUnit(irGroupUnit)).orElse(0);
+                    if (rec == 0) {
+                        return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("淇敼杞亴缁勭粦瀹氱殑鐏屾簤鍗曞厓寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 杞亴缁勫叧鑱斿啘鎴�
+     * @param po
+     * @param bindingResult
+     * @return
+     */
+    @PostMapping(path = "add_group_client", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> addGroupClient(@RequestBody @Valid GroupClient po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        IrGroupClient irGroupClient = new IrGroupClient();
+        irGroupClient.setGroupId(po.getGroupId());
+        irGroupClient.setClientId(po.getClientId());
+        irGroupClient.setOperator(po.getOperator());
+        irGroupClient.setOperateTime(new Date());
+
+        try {
+            Long rec = Optional.ofNullable(irrigateGroupSv.addGroupClient(irGroupClient)).orElse(0L);
+            if (rec == 0) {
+                return BaseResponseUtils.buildErrorMsg(IrrigateResultCode.GRPUP_ASSOCIATE_CLIENT_FAIL.getMessage());
+            }
+        } catch (Exception e) {
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+        return BaseResponseUtils.buildSuccess(true);
+    }
+
+    /**
+     * 鏂板杞亴缁勶紝鏂颁唬鐮�
+     * @param po
+     * @param bindingResult
+     * @return
+     */
+    @PostMapping(path = "addIrrigateGroup", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> addIrrigateGroup(@RequestBody @Valid IrrigateGroup po, BindingResult bindingResult) {
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+        
+        // 鍏堝垽鏂〃鍐呮槸鍚﹀瓨鍦ㄧ浉鍚岀殑 groupCode
+        if (irrigateGroupSv.existsByGroupCode(po.getGroupCode())) {
+            return BaseResponseUtils.buildFail(IrrigateResultCode.GROUP_CODE_ALREADY_EXISTS.getMessage());
+        }
+
+        Map map_result = irrigateGroupSv.addIrrigateGroup(po);
+        if(map_result.get("success").equals(false)) {
+            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
+        }
+        return BaseResponseUtils.buildSuccess() ;
+    }
+
+    /**
+     * 鍒犻櫎杞亴缁勶紝鏂颁唬鐮�
+     * @param groupId
+     * @return
+     */
+    @PostMapping(path = "deleteIrrigateGroup")
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> deleteIrrigateGroup(@RequestParam(required = false) Long groupId) {
+        if(groupId == null) {
+            return BaseResponseUtils.buildErrorMsg("杞亴缁処D涓嶈兘涓虹┖");
+        }
+
+        Map map_result = irrigateGroupSv.deleteGroup(groupId);
+        if(map_result.get("success").equals(false)) {
+            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
+        }
+        return BaseResponseUtils.buildSuccess() ;
+    }
+
+    /**
+     * 淇敼杞亴缁勶紝鏂颁唬鐮�
+     * @param po
+     * @param bindingResult
+     * @return
+     */
+    @PostMapping(path = "updateIrrigateGroup", consumes = MediaType.APPLICATION_JSON_VALUE)
+    @Transactional(rollbackFor = Exception.class)
+    @SsoAop()
+    public BaseResponse<Boolean> updateIrrigateGroup(@RequestBody @Valid IrrigateGroup po, BindingResult bindingResult){
+        if (bindingResult != null && bindingResult.hasErrors()) {
+            return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage());
+        }
+
+        if(po.getGroupId() == null) {
+            return BaseResponseUtils.buildErrorMsg("杞亴缁処D涓嶈兘涓虹┖");
+        }
+        
+        // 鍏堝垽鏂〃鍐呮槸鍚﹀瓨鍦ㄧ浉鍚岀殑 groupCode锛堟帓闄ゅ綋鍓嶆鍦ㄤ慨鏀圭殑璁板綍锛�
+        if (irrigateGroupSv.existsByGroupCodeExcludeId(po.getGroupCode(), po.getGroupId())) {
+            return BaseResponseUtils.buildFail(IrrigateResultCode.GROUP_CODE_ALREADY_EXISTS.getMessage());
+        }
+
+        Map map_result = irrigateGroupSv.updateIrrigateGroup(po);
+        if(map_result.get("success").equals(false)) {
+            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
+        }
+        return BaseResponseUtils.buildSuccess() ;
+    }
+
+    /**
+     * 鑾峰彇杞亴缁勫垪琛紝鏂颁唬鐮�
+     * @param qo
+     * @return
+     */
+    @GetMapping(path = "/getSimpleGroups")
+    @SsoAop()
+    public BaseResponse<QueryResultVo<List<VoGroupSimple>>> getSimpleGroups(QoGroup qo) {
+        try {
+            QueryResultVo<List<VoGroupSimple>> res = irrigateGroupSv.getSimpleGroups(qo);
+            return BaseResponseUtils.buildSuccess(res);
+        } catch (Exception e) {
+            log.error("鑾峰彇椤圭洰璁板綍寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+
+    /**
+     * 鑾峰彇鍏ㄩ儴杞亴缁勶紝鏂颁唬鐮�
+     * @return
+     */
+    @GetMapping(path = "/getAllGroups")
+    @SsoAop()
+    public BaseResponse<List<VoGroupSimple>> getAllGroups() {
+        try {
+            return BaseResponseUtils.buildSuccess(irrigateGroupSv.getAllGroups());
+        } catch (Exception e) {
+            log.error("鑾峰彇椤圭洰璁板綍寮傚父", e);
+            return BaseResponseUtils.buildException(e.getMessage());
+        }
+    }
+
+    /**
+     * 鑾峰彇杞亴缁勮鎯咃紝鏂颁唬鐮�
+     * @param groupId
+     * @return
+     */
+    @GetMapping(path = "getGroupDetail")
+    @SsoAop()
+    public BaseResponse<VoGroupDetail> getGroupDetail(@RequestParam Long groupId) {
+        if(groupId == null) {
+            return BaseResponseUtils.buildErrorMsg("杞亴缁処D涓嶈兘涓虹┖");
+        }
+
+        Map map_result = irrigateGroupSv.getGroupDetail(groupId);
+        if(map_result.get("success").equals(false)) {
+            return BaseResponseUtils.buildErrorMsg(map_result.get("msg").toString());
+        }
+        return BaseResponseUtils.buildSuccess(map_result.get("content")) ;
+    }
 }

--
Gitblit v1.8.0