From 646ec3901cba867fd539146b26980c2ad510560c Mon Sep 17 00:00:00 2001
From: wuzeyu <1223318623@qq.com>
Date: 星期五, 31 五月 2024 15:28:35 +0800
Subject: [PATCH] 田间灌溉项目管理  新增 修改轮罐组绑定的灌溉单元接口

---
 pipIrr-platform/pipIrr-web/pipIrr-web-irrigate/src/main/java/com/dy/pipIrrIrrigate/irrigateGroup/IrrigateGroupCtrl.java |   61 ++++++++++++++++++++++++++++++
 1 files changed, 61 insertions(+), 0 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 7694fbb..afb4ec0 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
@@ -350,4 +350,65 @@
             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<Long> newUnitIds = (List<Long>) po.get("unitIds");
+
+        List<Long> oldUnitIds = irrigateGroupSv.getGroupBindUnits(groupId);
+
+        try {
+            for (int j = 0; j < oldUnitIds.size(); j++) {
+                Long oldUnitId = oldUnitIds.get(j);
+                IrGroupUnit irGroupUnit1 = new IrGroupUnit();
+                irGroupUnit1.setGroupId(groupId);
+                irGroupUnit1.setUnitId(oldUnitId);
+                irGroupUnit1.setOperator(operator);
+                Integer rec = Optional.ofNullable(irrigateGroupSv.deleteGroupUnit(irGroupUnit1)).orElse(0);
+                if (rec == 0) {
+                    return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_PROJECT_FAIL.getMessage());
+                }
+            }
+            for (int i = 0; i < newUnitIds.size(); i++) {
+                Long newUnitId = newUnitIds.get(i);
+                IrGroupUnit irGroupUnit2 = new IrGroupUnit();
+                irGroupUnit2.setGroupId(groupId);
+                irGroupUnit2.setUnitId(newUnitId);
+                irGroupUnit2.setOperator(operator);
+                Integer rec = Optional.ofNullable(irrigateGroupSv.addGroupUnit(irGroupUnit2)).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);
+    }
 }

--
Gitblit v1.8.0