|  |  |  | 
|---|
|  |  |  | 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.VoGroupOne; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoUnit; | 
|---|
|  |  |  | import com.dy.pipIrrGlobal.voIr.VoUnitOne; | 
|---|
|  |  |  | 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.result.IrrigateResultCode; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.Operation; | 
|---|
|  |  |  | import io.swagger.v3.oas.annotations.media.Content; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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 | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 逻辑删除灌溉单元 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 批量删除 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param groupIds | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | 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); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 修改灌溉单元 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 分页查询 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "add_unit", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> addGroupUnit(@RequestBody @Valid IrGroupUnit 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()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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.addGroupUnit(po)).orElse(0); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.ADD_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.addGroupUnit(irGroupUnit)).orElse(0); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(IrrigateResultCode.GROUP_ADD_UNIT_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("轮灌组添加灌溉单元异常", e); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 逻辑删除 轮灌组移除灌溉单元 | 
|---|
|  |  |  | * 轮灌组移除灌溉单元 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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()); | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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("获取未绑定轮灌组的灌溉单元id记录异常", e); | 
|---|
|  |  |  | 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<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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|