刘小明
2024-08-26 0c479f17e5f9ff3ad638f3af783cf22b0a77fbd0
pms-parent/pms-web-product/src/main/java/com/dy/pmsProduct/schedule/ScheduleCtrl.java
@@ -1,5 +1,6 @@
package com.dy.pmsProduct.schedule;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.converters.Converter;
import com.dy.common.aop.SsoPowerAop;
import com.dy.common.webUtil.BaseResponse;
@@ -14,6 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -25,8 +27,7 @@
@RestController
@RequestMapping(path="schedule")
public class ScheduleCtrl {
    private static final String fileName = "排班信息" ;
    private static final String sheetName = "排班信息" ;
    private ScheduleSv sv;
    @Autowired
    public void setScheduleSv(ScheduleSv scheduleSv) {
@@ -99,7 +100,8 @@
        return BaseResponseUtils.buildSuccess(list);
    }
    private String fileName = "排班信息" ;
    private String sheetName = "排班信息" ;
    @PostMapping(path="export")
    @SsoPowerAop(power = "-1")
    @Log("导出排班")
@@ -107,10 +109,10 @@
        List<Converter> list = new ArrayList<>() ;
        List<PrSchedule> schList = sv.selectAll(queryVo);
        // 使用并行流提高性能
        schList.parallelStream().forEach(sch -> {
        schList.forEach(sch -> {
            sch.relList.forEach(rel -> {
                ExcelVo vo = new ExcelVo();
                vo.id = sch.id.toString();
                vo.userName = sch.userName;
                vo.scheduleDate = sch.scheduleDate;
                vo.dt = sch.dt;
@@ -121,6 +123,16 @@
                list.add(vo);
            });
        });
        QrCodeUtil.downloadExcel(response, fileName,sheetName,list);
        try{
            response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
            response.setCharacterEncoding("utf-8");
            fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
            response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
            EasyExcel.write(response.getOutputStream(), list.get(0).getClass()).sheet(sheetName)
                    .registerWriteHandler(new CustomCellWriteHandler()).doWrite(list);
        }catch (Exception e){
            log.error("导出排班信息异常", e);
        }
    }
}