|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrProject.controller; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONArray; | 
|---|
|  |  |  | import com.alibaba.excel.EasyExcel; | 
|---|
|  |  |  | import com.alibaba.excel.support.ExcelTypeEnum; | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | @Tag(name = "控制器管理", description = "控制器操作") | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping(path="controller") | 
|---|
|  |  |  | @RequestMapping(path = "controller") | 
|---|
|  |  |  | @RequiredArgsConstructor | 
|---|
|  |  |  | public class ControllerCtrl { | 
|---|
|  |  |  | private final ControllerSv controllerSv; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据指定条件获取控制器列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param vo 查询条件 | 
|---|
|  |  |  | * @return 符合条件的控制器列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "/getControllers") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoController>>> getControllers(QueryVo vo){ | 
|---|
|  |  |  | public BaseResponse<QueryResultVo<List<VoController>>> getControllers(QueryVo vo) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | QueryResultVo<List<VoController>> res = controllerSv.getControllers(vo); | 
|---|
|  |  |  | if(res.itemTotal != null && res.itemTotal > 0) { | 
|---|
|  |  |  | if (res.itemTotal != null && res.itemTotal > 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.NO_RECORDS.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //return BaseResponseUtils.buildSuccess(res); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("获取开卡记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | log.error("获取控制器记录异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据控制器编号获取控制器列表 | 
|---|
|  |  |  | * @param controllerCode 控制器编号 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param rtuAddr 控制器地址 | 
|---|
|  |  |  | * @return 符合条件的控制器列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得控制器记录", description = "返回取控制器数据") | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "controller_list") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<List<Map<String, Object>>> getControllersByCode(String controllerCode){ | 
|---|
|  |  |  | public BaseResponse<List<Map<String, Object>>> getControllersByCode(String rtuAddr) { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | List<Map<String, Object>> list = Optional.ofNullable(controllerSv.getControllersByCode(controllerCode)).orElse(new ArrayList<>()); | 
|---|
|  |  |  | if(list.size() <= 0) { | 
|---|
|  |  |  | List<Map<String, Object>> list = Optional.ofNullable(controllerSv.getControllersByAddr(rtuAddr)).orElse(new ArrayList<>()); | 
|---|
|  |  |  | if (list.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.NO_RECORDS.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(list); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询控制器异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 添加控制器 | 
|---|
|  |  |  | * @param po 控制器实体对象 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param po            控制器实体对象 | 
|---|
|  |  |  | * @param bindingResult | 
|---|
|  |  |  | * @return 添加是否成功 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> add(@RequestBody @Valid DtoController po, BindingResult bindingResult){ | 
|---|
|  |  |  | if(bindingResult != null && bindingResult.hasErrors()){ | 
|---|
|  |  |  | //public BaseResponse<Boolean> add(@RequestBody @Valid DtoController po, BindingResult bindingResult){ | 
|---|
|  |  |  | public BaseResponse<Boolean> add(@RequestBody @Valid PrController po, BindingResult bindingResult) { | 
|---|
|  |  |  | if (bindingResult != null && bindingResult.hasErrors()) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | PrController prController = DtoToPojo.INSTANCT.po2vo(po); | 
|---|
|  |  |  | //PrController prController = DtoToPojo.INSTANCT.po2vo(po); | 
|---|
|  |  |  | //Date operateTime = new Date(); | 
|---|
|  |  |  | //prController.setOperatedt(operateTime); | 
|---|
|  |  |  | //prController.setDeleted((byte)0); | 
|---|
|  |  |  | //prController.setReporttime(operateTime); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Date operateTime = new Date(); | 
|---|
|  |  |  | prController.setOperatedt(operateTime); | 
|---|
|  |  |  | prController.setDeleted((byte)0); | 
|---|
|  |  |  | prController.setReporttime(operateTime); | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(controllerSv.addController(prController)).orElse(0); | 
|---|
|  |  |  | if(rec == 0) { | 
|---|
|  |  |  | po.setOperateDt(operateTime); | 
|---|
|  |  |  | po.setDeleted((byte) 0); | 
|---|
|  |  |  | po.setFindDt(operateTime); | 
|---|
|  |  |  | if (po.getAddWays() == null) { | 
|---|
|  |  |  | po.setAddWays((byte) 1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Integer rec = Optional.ofNullable(controllerSv.addController(po)).orElse(0); | 
|---|
|  |  |  | if (rec == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.CONTROLLER_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 根据控制器编号删除控制器 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param map | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @PostMapping(path = "delete") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@RequestBody Map map){ | 
|---|
|  |  |  | if(map == null || map.size() <=0) { | 
|---|
|  |  |  | public BaseResponse<Boolean> delete(@RequestBody Map map) { | 
|---|
|  |  |  | if (map == null || map.size() <= 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.PLEASE_INPUT_CONTROLLER_ID.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Long controllerId = Long.parseLong(map.get("controllerId").toString()); | 
|---|
|  |  |  | Integer recordCount = Optional.ofNullable(controllerSv.deleteControllerById(controllerId)).orElse(0); | 
|---|
|  |  |  | if(recordCount == 0) { | 
|---|
|  |  |  | if (recordCount == 0) { | 
|---|
|  |  |  | return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_CONTROLLER_FAIL.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true) ; | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 获取未绑控制器的取水口列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @return | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Operation(summary = "获得未绑控制器的取水口记录", description = "返回未绑控制器的取水口数据") | 
|---|
|  |  |  | @ApiResponses(value = { | 
|---|
|  |  |  | @ApiResponse( | 
|---|
|  |  |  | responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, | 
|---|
|  |  |  | description = "返回控制器数据(BaseResponse.content:QueryResultVo[{}])", | 
|---|
|  |  |  | content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, | 
|---|
|  |  |  | schema = @Schema(implementation = BaClient.class))} | 
|---|
|  |  |  | ) | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | @GetMapping(path = "nobinding_intakes") | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<JSONArray> getNoBindingIntakes() { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | JSONArray array = controllerSv.getNoBindingIntakes(); | 
|---|
|  |  |  | //            if (array.size() <= 0) { | 
|---|
|  |  |  | //                return BaseResponseUtils.buildFail(ProjectResultCode.NO_BINDING_INTAKE.getMessage()); | 
|---|
|  |  |  | //            } | 
|---|
|  |  |  | return BaseResponseUtils.buildSuccess(array); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | log.error("查询控制器异常", e); | 
|---|
|  |  |  | return BaseResponseUtils.buildException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 导出控制器列表 | 
|---|
|  |  |  | * | 
|---|
|  |  |  | * @param response | 
|---|
|  |  |  | * @param vo | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | 
|---|
|  |  |  | String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); | 
|---|
|  |  |  | response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|