From 9281643d18bc2e0aaffed3c5f216d1df12d68424 Mon Sep 17 00:00:00 2001 From: wuzeyu <1223318623@qq.com> Date: 星期四, 18 一月 2024 09:44:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java | 183 +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 175 insertions(+), 8 deletions(-) diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java index fe5f6b9..30a1954 100644 --- a/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java +++ b/pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java @@ -1,10 +1,17 @@ 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; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; +import com.dy.common.webUtil.QueryResultVo; import com.dy.common.webUtil.ResultCodeMsg; +import com.dy.pipIrrGlobal.pojoBa.BaClient; import com.dy.pipIrrGlobal.pojoPr.PrController; +import com.dy.pipIrrGlobal.voPr.VoController; +import com.dy.pipIrrGlobal.voSe.VoActiveCard; import com.dy.pipIrrProject.result.ProjectResultCode; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; @@ -12,20 +19,20 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; -import java.util.Date; -import java.util.Objects; -import java.util.Optional; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.*; /** * @author ZhuBaoMin @@ -42,6 +49,72 @@ public class ControllerCtrl { private final ControllerSv controllerSv; + /** + * 鏍规嵁鎸囧畾鏉′欢鑾峰彇鎺у埗鍣ㄥ垪琛� + * @param vo 鏌ヨ鏉′欢 + * @return 绗﹀悎鏉′欢鐨勬帶鍒跺櫒鍒楄〃 + */ + @Operation(summary = "鑾峰緱涓�椤垫帶鍒跺櫒璁板綍", description = "杩斿洖涓�椤垫帶鍒跺櫒鏁版嵁") + @ApiResponses(value = { + @ApiResponse( + responseCode = ResultCodeMsg.RsCode.SUCCESS_CODE, + description = "杩斿洖涓�椤垫帶鍒跺櫒鏁版嵁锛圔aseResponse.content:QueryResultVo[{}]锛�", + content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = VoActiveCard.class))} + ) + }) + @GetMapping(path = "/getControllers") + @SsoAop() + public BaseResponse<QueryResultVo<List<VoController>>> getControllers(QueryVo vo){ + try { + QueryResultVo<List<VoController>> res = controllerSv.getControllers(vo); + if(res.itemTotal != null && res.itemTotal > 0) { + return BaseResponseUtils.buildSuccess(res); + }else { + return BaseResponseUtils.buildFail(ProjectResultCode.NO_RECORDS.getMessage()); + } + //return BaseResponseUtils.buildSuccess(res); + } catch (Exception e) { + log.error("鑾峰彇寮�鍗¤褰曞紓甯�", e); + return BaseResponseUtils.buildException(e.getMessage()) ; + } + } + + /** + * 鏍规嵁鎺у埗鍣ㄧ紪鍙疯幏鍙栨帶鍒跺櫒鍒楄〃 + * @param rtuAddr 鎺у埗鍣ㄥ湴鍧� + * @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 = "controller_list") + @SsoAop() + public BaseResponse<List<Map<String, Object>>> getControllersByCode(String rtuAddr){ + try { + 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()) ; + } + } + + /** + * 娣诲姞鎺у埗鍣� + * @param po 鎺у埗鍣ㄥ疄浣撳璞� + * @param bindingResult + * @return 娣诲姞鏄惁鎴愬姛 + */ @Operation(summary = "娣诲姞鎺у埗鍣ㄨ褰�", description = "娣诲姞鎺у埗鍣ㄨ褰�") @ApiResponses(value = { @ApiResponse( @@ -54,18 +127,112 @@ @PostMapping(path = "add", consumes = MediaType.APPLICATION_JSON_VALUE) @Transactional(rollbackFor = Exception.class) @SsoAop() + //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); + //Date operateTime = new Date(); + //prController.setOperatedt(operateTime); + //prController.setDeleted((byte)0); + //prController.setReporttime(operateTime); + Date operateTime = new Date(); - po.setOperatedt(operateTime); + po.setOperateDt(operateTime); po.setDeleted((byte)0); + po.setFindDt(operateTime); Integer rec = Optional.ofNullable(controllerSv.addController(po)).orElse(0); if(rec == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.CONTROLLER_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true) ; } + + /** + * 鏍规嵁鎺у埗鍣ㄧ紪鍙峰垹闄ゆ帶鍒跺櫒 + * @param map + * @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 = "delete") + @SsoAop() + 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) { + return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_CONTROLLER_FAIL.getMessage()); + } + return BaseResponseUtils.buildSuccess(true) ; + } + + /** + * 鑾峰彇鏈粦鎺у埗鍣ㄧ殑鍙栨按鍙e垪琛� + * @return + */ + @Operation(summary = "鑾峰緱鏈粦鎺у埗鍣ㄧ殑鍙栨按鍙h褰�", description = "杩斿洖鏈粦鎺у埗鍣ㄧ殑鍙栨按鍙f暟鎹�") + @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 + */ + @SneakyThrows(IOException.class) + @RequestMapping(value = "/export", method = RequestMethod.GET) + public void export(HttpServletResponse response, QueryVo vo) { + setExcelRespProp(response, "鎺у埗鍣ㄥ垪琛�"); + //List<VoDivide> memberList = LocalJsonUtil.getListFromJson("json/members.json", VoDivide.class); + List<VoController> memberList = controllerSv.export(vo); + + EasyExcel.write(response.getOutputStream()) + .head(VoController.class) + .excelType(ExcelTypeEnum.XLSX) + .sheet("鎺у埗鍣ㄥ垪琛�") + .doWrite(memberList); + } + + /** + * 璁剧疆excel涓嬭浇鍝嶅簲澶村睘鎬� + */ + private void setExcelRespProp(HttpServletResponse response, String rawFileName) throws UnsupportedEncodingException { + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + String fileName = URLEncoder.encode(rawFileName, "UTF-8").replaceAll("\\+", "%20"); + response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); + } } -- Gitblit v1.8.0