liuxm
2024-05-21 55cb4daf506ad8f3c637f6e3d9bc7df41e538b2e
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);
        }
    }
}