From ebae0c1137ba96d38e5b2323577129d2c9ff2e6e Mon Sep 17 00:00:00 2001 From: liurunyu <lry9898@163.com> Date: 星期四, 22 五月 2025 09:45:59 +0800 Subject: [PATCH] 1、优化配置文件; 2、优化ID生成器代码; 3、修改注释; 4、修改权限初始化时算法; 5、导出Excel文件功能归为一个新类; 6、工站数据库存入验空修改; --- pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java | 136 ++++++++++++++++++++++++++------------------ 1 files changed, 80 insertions(+), 56 deletions(-) diff --git a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java index 2e191f5..00c1890 100644 --- a/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java +++ b/pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java @@ -1,5 +1,7 @@ package com.dy.pmsPlatform.station; +import cn.hutool.json.JSONArray; +import com.alibaba.excel.converters.Converter; import com.alibaba.fastjson2.JSON; import com.dy.common.aop.SsoPowerAop; import com.dy.common.webUtil.BaseResponse; @@ -7,14 +9,19 @@ import com.dy.common.webUtil.QueryResultVo; import com.dy.pmsGlobal.aop.Log; import com.dy.pmsGlobal.pojoPlt.PltStation; +import com.dy.pmsGlobal.util.ExportExcelUtil; +import com.dy.pmsGlobal.util.QrCodeConstant; +import com.dy.pmsGlobal.util.QrCodeUtil; +import com.google.zxing.WriterException; +import jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; +import java.io.IOException; +import java.util.ArrayList; import java.util.List; -import java.util.Objects; /** * 宸ョ珯 @@ -24,6 +31,8 @@ @RequestMapping(path="station") @SuppressWarnings("unchecked") public class StationCtrl { + private static final String fileName = "宸ョ珯淇℃伅" ; + private static final String sheetName = "宸ョ珯淇℃伅" ; private StationSv sv; @Autowired public StationCtrl(StationSv sv){ @@ -33,24 +42,14 @@ /** * 淇濆瓨 * @param station - * @param bindingResult * @return */ @PostMapping(path="save") @SsoPowerAop(power = "10300007") @Log("淇濆瓨宸ョ珯") - public BaseResponse<Boolean> save(@RequestBody @Valid PltStation station,BindingResult bindingResult){ - if (bindingResult != null && bindingResult.hasErrors()) { - return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); - } - int count; - try { - station.deleted = false; - count = sv.save(station); - }catch (Exception e){ - log.error("淇濆瓨宸ョ珯寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + public BaseResponse<Boolean> save(@RequestBody @Valid PltStation station){ + station.deleted = false; + int count = sv.save(station); if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); @@ -63,23 +62,14 @@ /** * 鏇存柊 * @param station - * @param bindingResult * @return */ @PostMapping(path="update") @SsoPowerAop(power = "10300007") @Log("鏇存柊宸ョ珯") - public BaseResponse<Boolean> update(@RequestBody @Valid PltStation station,BindingResult bindingResult){ - int count; - try { - if (bindingResult != null && bindingResult.hasErrors()) { - return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); - } - count = sv.update(station); - }catch (Exception e){ - log.error("鏇存柊宸ョ珯寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + public BaseResponse<Boolean> update(@RequestBody @Valid PltStation station){ + int count = sv.update(station); + if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { @@ -96,13 +86,8 @@ @SsoPowerAop(power = "10300007") @Log("鍒犻櫎宸ョ珯") public BaseResponse<Boolean> delete(String id){ - int count; - try { - count = sv.delete(Long.parseLong(id)); - }catch (Exception e){ - log.error("鍒犻櫎宸ョ珯寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + int count = sv.delete(Long.parseLong(id)); + if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { @@ -117,13 +102,8 @@ @SsoPowerAop(power = "10300006") //鐧诲綍涓庢潈闄愬悓鏃堕獙璇� @Log("鏍规嵁ID鏌ヨ宸ョ珯") public BaseResponse<PltStation> one(String id){ - try{ - PltStation param=sv.selectById(id); - return BaseResponseUtils.buildSuccess(JSON.toJSON(param)); - }catch (Exception e){ - log.error("鏍规嵁ID鏌ヨ宸ョ珯寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + PltStation param=sv.selectById(id); + return BaseResponseUtils.buildSuccess(JSON.toJSON(param)); } /** @@ -135,31 +115,75 @@ @SsoPowerAop(power = "10300006") @Log("鍒嗛〉鏌ヨ宸ョ珯") public BaseResponse<QueryResultVo<List<PltStation>>> some(@RequestBody QueryVo vo){ - try { - QueryResultVo<List<PltStation>> list = sv.selectSome(vo) ; - return BaseResponseUtils.buildSuccess(list); - }catch (Exception e){ - log.error("鍒嗛〉鏌ヨ宸ョ珯寮傚父", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + QueryResultVo<List<PltStation>> list = sv.selectSome(vo) ; + return BaseResponseUtils.buildSuccess(list); + } + + /** + * 鏌ヨ鎵�鏈夊伐绔� + * @return + */ + @GetMapping(path="all") + @SsoPowerAop(power = "10300006") + @Log("鏌ヨ鎵�鏈夊伐绔�") + public BaseResponse<JSONArray> all(){ + JSONArray array = sv.selectAllIdAndName() ; + return BaseResponseUtils.buildSuccess(array); } @PostMapping(path="disabled") - @SsoPowerAop(power = "10100011") + @SsoPowerAop(power = "10300007") @Log("绂佺敤鎴栧惎鐢ㄥ伐绔�") public BaseResponse<Boolean> disabled(@RequestBody PltStation station){ - int count; - try { - count = sv.disabled(station.id,station.disabled); - }catch (Exception e){ - log.error("绂佺敤鎴栧惎鐢ㄥ伐绔欏紓甯�", e); - return BaseResponseUtils.buildException(e.getMessage()); - } + int count = sv.disabled(station.id,station.disabled); + if (count <= 0) { return BaseResponseUtils.buildFail("鏁版嵁搴撳瓨鍌ㄥけ璐�"); } else { return BaseResponseUtils.buildSuccess(true); } } + @PostMapping(path="export") + @SsoPowerAop(power = "10300007") + @Log("瀵煎嚭宸ョ珯淇℃伅") + public void export(HttpServletResponse response){ + List<Converter> list = new ArrayList<>() ; + + List<PltStation> stations = sv.selectAll(); + if(stations != null){ + for(PltStation station : stations){ + ExcelVo vo = new ExcelVo(); + vo.name = station.name; + //vo.code = "103"+station.id; + vo.lineName = station.lineName; + try { + vo.qrCode = QrCodeUtil.genQrCode(QrCodeConstant.TypeStation+station.id); + } catch (IOException e) { + e.printStackTrace(); + } catch (WriterException e) { + e.printStackTrace(); + } + list.add(vo); + } + } + // 浣跨敤骞惰娴佹彁楂樻�ц兘锛屼絾鐢熸垚鐨勭粨鏋滃彉鎴愭棤搴忕殑浜� + /* + stations.parallelStream().forEach(station -> { + ExcelVo vo = new ExcelVo(); + vo.name = station.name; + //vo.code = "103"+station.id; + vo.lineName = station.lineName; + try { + vo.qrCode = QrCodeUtil.genQrCode(QrCodeConstant.TypeStation+station.id); + } catch (IOException e) { + e.printStackTrace(); + } catch (WriterException e) { + e.printStackTrace(); + } + list.add(vo); + }); + */ + ExportExcelUtil.downloadExcel(response, fileName, sheetName, list); + } } -- Gitblit v1.8.0