| | |
| | | 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 |
| | |
| | | schema = @Schema(implementation = Boolean.class))} |
| | | ) |
| | | }) |
| | | @GetMapping(path = "delete") |
| | | @PostMapping(path = "delete") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @SsoAop() |
| | | public BaseResponse<Boolean> delete( Long id) { |
| | | if (id == null ) { |
| | | public BaseResponse<Boolean> delete(@RequestBody Map map) { |
| | | if (map == null || map.size() <= 0) { |
| | | BaseResponseUtils.buildFail(IrrigateResultCode.PLEASE_INPUT_PROJECT_ID.getMessage()); |
| | | } |
| | | // Long groupId = Long.parseLong(map.get("id").toString()); |
| | | Long groupId = Long.parseLong(map.get("id").toString()); |
| | | try { |
| | | Integer rows = irrigateGroupSv.deleteIrrigateGroup(id); |
| | | Integer rows = irrigateGroupSv.deleteIrrigateGroup(groupId); |
| | | if (rows == 0) { |
| | | return BaseResponseUtils.buildFail(IrrigateResultCode.DELETE_PROJECT_FAIL.getMessage()); |
| | | } |
| | |
| | | @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.ADD_PROJECT_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()); |
| | | } |
| | | return BaseResponseUtils.buildSuccess(true); |
| | | } |
| | | |
| | | @GetMapping(path = "bind_units") |
| | | @SsoAop() |
| | | public BaseResponse<List<String>> getGroupBindUnits(Long id) { |
| | | try { |
| | | List<Long> res = irrigateGroupSv.getGroupBindUnits(id); |
| | | 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<String>> getNotBindUnits() { |
| | | try { |
| | | List<Long> res = irrigateGroupSv.getNotBindUnits(); |
| | | 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()); |
| | | } |
| | | } |
| | | } |