From 432a1b0c4dd251f686e9bb7950c4868aaf3e4ed7 Mon Sep 17 00:00:00 2001 From: liuxm <liuxm_a@163.com> Date: 星期四, 06 六月 2024 09:55:57 +0800 Subject: [PATCH] 添加验证和异常处理 --- pms-parent/pms-web-platform/src/main/java/com/dy/pmsPlatform/station/StationCtrl.java | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 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..e081b49 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,6 @@ package com.dy.pmsPlatform.station; +import com.alibaba.excel.converters.Converter; import com.alibaba.fastjson2.JSON; import com.dy.common.aop.SsoPowerAop; import com.dy.common.webUtil.BaseResponse; @@ -7,12 +8,17 @@ import com.dy.common.webUtil.QueryResultVo; import com.dy.pmsGlobal.aop.Log; import com.dy.pmsGlobal.pojoPlt.PltStation; +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 +30,9 @@ @RequestMapping(path="station") @SuppressWarnings("unchecked") public class StationCtrl { + private static final String fileName = "宸ョ珯淇℃伅" ; + private static final String sheetName = "宸ョ珯淇℃伅" ; + private static final String stationPrefix = "103" ; private StationSv sv; @Autowired public StationCtrl(StationSv sv){ @@ -161,5 +170,33 @@ return BaseResponseUtils.buildSuccess(true); } } + @PostMapping(path="export") + @SsoPowerAop(power = "10300000") + @Log("瀵煎嚭宸ョ珯淇℃伅") + public void export(HttpServletResponse response){ + try{ + List<Converter> list = new ArrayList<>() ; + + List<PltStation> stations = sv.selectAll(); + // 浣跨敤骞惰娴佹彁楂樻�ц兘 + 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(stationPrefix+station.id); + } catch (IOException e) { + e.printStackTrace(); + } catch (WriterException e) { + e.printStackTrace(); + } + list.add(vo); + }); + QrCodeUtil.downloadExcel(response, fileName,sheetName,list); + }catch (Exception e){ + log.error("瀵煎嚭浜у搧淇℃伅寮傚父", e); + } + } } -- Gitblit v1.8.0