| | |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 修改轮灌组绑定的灌溉单元 |
| | | * |
| | | * @param po 轮灌组灌溉单元中间表 |
| | | * @param bindingResult |
| | | * @return 添加是否成功 |
| | | */ |
| | | @Operation(summary = "修改轮灌组绑定的灌溉单元", description = "修改轮灌组绑定的灌溉单元") |
| | | @ApiResponses(value = { |
| | | @ApiResponse( |
| | | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, |
| | | description = "操作结果:true:成功,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); |
| | | } |
| | | } |