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 | 77 ++++++++++++++++++++++++++++++++++---- 1 files changed, 69 insertions(+), 8 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 6a6ce00..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 @@ -319,15 +319,15 @@ @GetMapping(path = "bind_units") @SsoAop() - public BaseResponse<Map> getGroupBindUnits(Long id) { + public BaseResponse<List<String>> getGroupBindUnits(Long id) { try { List<Long> res = irrigateGroupSv.getGroupBindUnits(id); - HashMap<Integer, String> map = new HashMap<>(); + ArrayList<Object> list = new ArrayList<>(); for (int i = 0; i < res.size(); i++) { String aLong = res.get(i).toString(); - map.put(i,aLong); + list.add(aLong); } - return BaseResponseUtils.buildSuccess(map); + return BaseResponseUtils.buildSuccess(list); } catch (Exception e) { log.error("鑾峰彇涓�涓疆鐏岀粍缁戝畾鐏屾簤鍗曞厓璁板綍寮傚父", e); return BaseResponseUtils.buildException(e.getMessage()); @@ -336,18 +336,79 @@ @GetMapping(path = "notBind_units") @SsoAop() - public BaseResponse<Map> getNotBindUnits() { + public BaseResponse<List<String>> getNotBindUnits() { try { List<Long> res = irrigateGroupSv.getNotBindUnits(); - HashMap<Integer, String> map = new HashMap<>(); + ArrayList<Object> list = new ArrayList<>(); for (int i = 0; i < res.size(); i++) { String aLong = res.get(i).toString(); - map.put(i,aLong); + list.add(aLong); } - return BaseResponseUtils.buildSuccess(map); + 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<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