package com.ruoyi.project.sems.service.impl;

import java.io.*;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.config.RuoYiConfig;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.project.plant.domain.TStaffmgr;
import com.ruoyi.project.sems.domain.*;
import com.ruoyi.project.sems.mapper.*;
import com.ruoyi.project.sems.service.*;
import com.ruoyi.project.system.domain.SysDictData;
import com.ruoyi.project.training.domain.TTraining;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * 特种设备报告Service业务层处理
 *
 * @author Ly
 * @date 2024-07-17
 */
@Service
public class TSpecReportServiceImpl implements ITSpecReportService {
    @Resource
    private TSpecReportMapper tSpecReportMapper;
    @Autowired
    private ITSpecdevDtService tSpecdevDtService;
    @Autowired
    private ITSpecdevDzsbService tSpecdevDzsbService;
    @Autowired
    private ITSpecdevGlService tSpecdevGlService;
    @Autowired
    private ITSpecdevYlgdService tSpecdevYlgdService;
    @Autowired
    private ITSpecdevYlrqService tSpecdevYlrqService;
    @Autowired
    private ITSpecdevCcService tSpecdevCcService;
    @Resource
    private TSpecdevCcMapper tSpecdevCcMapper;
    @Resource
    private TSpecdevYlrqMapper tSpecdevYlrqMapper;
    @Resource
    private TSpecdevYlgdMapper tSpecdevYlgdMapper;
    @Resource
    private TSpecdevGlMapper tSpecdevGlMapper;
    @Resource
    private TSpecdevDzsbMapper tSpecdevDzsbMapper;
    @Resource
    private TSpecdevDtMapper tSpecdevDtMapper;

    protected final Logger logger = LoggerFactory.getLogger(BaseController.class);

    /**
     * 查询特种设备报告
     *
     * @param id 特种设备报告ID
     * @return 特种设备报告
     */
    @Override
    public TSpecReport selectTSpecReportById(Long id) {
        return tSpecReportMapper.selectTSpecReportById(id);
    }

    /**
     * 查询特种设备报告列表
     *
     * @param tSpecReport 特种设备报告
     * @return 特种设备报告
     */
    @Override
    public List<TSpecReport> selectTSpecReportList(TSpecReport tSpecReport) {
        return tSpecReportMapper.selectTSpecReportList(tSpecReport);
    }

    /**
     * 新增特种设备报告
     *
     * @param tSpecReport 特种设备报告
     * @return 结果
     */
    @Override
    @Transactional
    public int insertTSpecReport(TSpecReport tSpecReport, HttpServletResponse response) {
        tSpecReportMapper.insertTSpecReport(tSpecReport);
        try {
            String tempUrl = "static/word/sems/report/sems-report.xlsx"; // 模板文件
            // 生成的路径
            String fileDir = RuoYiConfig.getProfile() + "/" + "sems/spec-report";
            InputStream is = null;
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(tempUrl);
            XSSFWorkbook wb1 = new XSSFWorkbook(is);
            SXSSFWorkbook wb = new SXSSFWorkbook(wb1, 1000);
            // 替换excel模板数据
            replaceExcel(wb);
            //从下往上渲染
            replaceExcelByHi(wb,tSpecReport);
            replaceExcelExpireByThreeMonth(wb);
            replaceExcelExpire(wb);
            //创建明细excel
            String detailUrl = createDetailExcel(tSpecReport, false);
            //创建3个月明细excel
            String detail3Url = createDetailExcel(tSpecReport, true);

            // Save the generated file
            File dir = new File(fileDir);
            if (!dir.exists()) {
                logger.info("目录不存在，创建文件夹{}!", fileDir);
                dir.mkdirs();
            }
            FileOutputStream fos = null;
            LocalDate currentDate = LocalDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
            String dateStr = currentDate.format(formatter);
            String startDateStr = tSpecReport.getStartDate().toInstant().atZone(ZoneId.systemDefault()).format(formatter);
            String filePath = fileDir + "/" + dateStr + "Report" + tSpecReport.getId() + ".xlsx";
            fos = new FileOutputStream(filePath);
            wb.write(fos);
            //
            int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
            String currentDir = StringUtils.substring(filePath, dirLastIndex);
            String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir;
            tSpecReport.setReportUrl(pathFileName);
            tSpecReport.setReportName(startDateStr + "_" +dateStr + "报告");
            tSpecReport.setDetailUrl(detailUrl);
            tSpecReport.setDetail3Url(detail3Url);
            tSpecReportMapper.updateTSpecReport(tSpecReport);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return 1;
    }

    //数量变更说明（基于与上一个月数据对比）渲染
    private void replaceExcelByHi(SXSSFWorkbook wb, TSpecReport tSpecReport) {
        Sheet sheet;
        if (wb instanceof SXSSFWorkbook) {
            SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
            sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
        } else {
            sheet = wb.getSheetAt(0);
        }
        List<Integer> numArr = new ArrayList<>();
        List<TSpecReport> ylrqList = tSpecReportMapper.selectExpriedYlrqHi(tSpecReport);
        numArr.add(ylrqList.size());
        logger.info(JSON.toJSONString(ylrqList));
        Row row = sheet.getRow(13);
        Cell cell = row.getCell(1);
        // 获取单元格样式
        CellStyle originalStyle = cell.getCellStyle();
        cell.setCellStyle(originalStyle);
        cell.setCellValue(getDevTotal(ylrqList));

        List<TSpecReport> ylgdList = tSpecReportMapper.selectExpriedYlgdHi(tSpecReport);
        numArr.add(ylgdList.size());
        logger.info(JSON.toJSONString(ylgdList));
        Row row2 = sheet.getRow(13);
        Cell cell2 = row2.getCell(4);
        cell2.setCellValue(getDevTotal(ylgdList));

        List<TSpecReport> glList = tSpecReportMapper.selectExpriedGlHi(tSpecReport);
        numArr.add(glList.size());
        logger.info(JSON.toJSONString(glList));
        Row row3 = sheet.getRow(13);
        Cell cell3 = row3.getCell(7);
        cell3.setCellValue(getDevTotal(glList));

        List<TSpecReport> dtList = tSpecReportMapper.selectExpriedDtHi(tSpecReport);
        numArr.add(dtList.size());
        logger.info(JSON.toJSONString(dtList));
        Row row4 = sheet.getRow(13);
        Cell cell4 = row4.getCell(10);
        cell4.setCellValue(getDevTotal(dtList));

        List<TSpecReport> dzsbList = tSpecReportMapper.selectExpriedDzsbHi(tSpecReport);
        numArr.add(dzsbList.size());
        logger.info(JSON.toJSONString(dzsbList));
        Row row5 = sheet.getRow(13);
        Cell cell5 = row5.getCell(13);
        cell5.setCellValue(getDevTotal(dzsbList));

        List<TSpecReport> ccList = tSpecReportMapper.selectExpriedCcHi(tSpecReport);
        numArr.add(ccList.size());
        logger.info(JSON.toJSONString(ccList));
        Row row6 = sheet.getRow(8);
        Cell cell6 = row6.getCell(16);
        cell6.setCellValue(getDevTotal(ccList));

        int maxNum = findMaxValue(numArr);
        int needNum = maxNum - 3 > 0 ? maxNum - 3 : 0;
        for (int i = 0; i < needNum; i++) {
            sheet.shiftRows(16, sheet.getLastRowNum(), 1);
            cpoyRow(16, sheet);
        }
        // 合并区域从第0行第0列到第0行第3列
        CellRangeAddress mergedRegion = new CellRangeAddress(
                13, // 起始行
                needNum + 17, // 结束行
                0, // 起始列
                0  // 结束列
        );
        sheet.addMergedRegion(mergedRegion);

        renderCell(wb, sheet, ylrqList, 15, 1);
        renderCell(wb, sheet, ylgdList, 15, 4);
        renderCell(wb, sheet, glList, 15, 7);
        renderCell(wb, sheet, dtList, 15, 10);
        renderCell(wb, sheet, dzsbList, 15, 13);
        renderCell(wb, sheet, ccList, 15, 16);
    }

    //三个月到期渲染
    private void replaceExcelExpireByThreeMonth(SXSSFWorkbook wb) {
        Sheet sheet;
        if (wb instanceof SXSSFWorkbook) {
            SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
            sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
        } else {
            sheet = wb.getSheetAt(0);
        }
        List<Integer> numArr = new ArrayList<>();
        List<TSpecReport> ylrqList = tSpecReportMapper.selectExpriedYlrq3(new TSpecReport());
        numArr.add(ylrqList.size());
        logger.info(JSON.toJSONString(ylrqList));
        Row row = sheet.getRow(8);
        Cell cell = row.getCell(1);
        // 获取单元格样式
        CellStyle originalStyle = cell.getCellStyle();
        cell.setCellStyle(originalStyle);
        cell.setCellValue(getDevTotal(ylrqList));

        List<TSpecReport> ylgdList = tSpecReportMapper.selectExpriedYlgd3(new TSpecReport());
        numArr.add(ylgdList.size());
        logger.info(JSON.toJSONString(ylgdList));
        Row row2 = sheet.getRow(8);
        Cell cell2 = row2.getCell(4);
        cell2.setCellValue(getDevTotal(ylgdList));

        List<TSpecReport> glList = tSpecReportMapper.selectExpriedGl3(new TSpecReport());
        numArr.add(glList.size());
        logger.info(JSON.toJSONString(glList));
        Row row3 = sheet.getRow(8);
        Cell cell3 = row3.getCell(7);
        cell3.setCellValue(getDevTotal(glList));

        List<TSpecReport> dtList = tSpecReportMapper.selectExpriedDt3(new TSpecReport());
        numArr.add(dtList.size());
        logger.info(JSON.toJSONString(dtList));
        Row row4 = sheet.getRow(8);
        Cell cell4 = row4.getCell(10);
        cell4.setCellValue(getDevTotal(dtList));

        List<TSpecReport> dzsbList = tSpecReportMapper.selectExpriedDzsb3(new TSpecReport());
        numArr.add(dzsbList.size());
        logger.info(JSON.toJSONString(dzsbList));
        Row row5 = sheet.getRow(8);
        Cell cell5 = row5.getCell(13);
        cell5.setCellValue(getDevTotal(dzsbList));

        List<TSpecReport> ccList = tSpecReportMapper.selectExpriedCc3(new TSpecReport());
        numArr.add(ccList.size());
        logger.info(JSON.toJSONString(ccList));
        Row row6 = sheet.getRow(8);
        Cell cell6 = row6.getCell(16);
        cell6.setCellValue(getDevTotal(ccList));

        int maxNum = findMaxValue(numArr);
        int needNum = maxNum - 3 > 0 ? maxNum - 3 : 0;
        for (int i = 0; i < needNum; i++) {
            sheet.shiftRows(11, sheet.getLastRowNum(), 1);
            cpoyRow(11, sheet);
        }
        // 合并区域从第0行第0列到第0行第3列
        CellRangeAddress mergedRegion = new CellRangeAddress(
                8, // 起始行
                needNum + 12, // 结束行
                0, // 起始列
                0  // 结束列
        );
        sheet.addMergedRegion(mergedRegion);

        renderCell(wb, sheet, ylrqList, 10, 1);
        renderCell(wb, sheet, ylgdList, 10, 4);
        renderCell(wb, sheet, glList, 10, 7);
        renderCell(wb, sheet, dtList, 10, 10);
        renderCell(wb, sheet, dzsbList, 10, 13);
        renderCell(wb, sheet, ccList, 10, 16);
    }

    //过期渲染
    private void replaceExcelExpire(SXSSFWorkbook wb) {
        Sheet sheet;
        if (wb instanceof SXSSFWorkbook) {
            SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
            sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
        } else {
            sheet = wb.getSheetAt(0);
        }
        List<Integer> numArr = new ArrayList<>();
        List<TSpecReport> ylrqList = tSpecReportMapper.selectExpriedYlrq(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : ylrqList
        ) {
            TSpecdevYlrq d = tSpecdevYlrqMapper.selectTSpecdevYlrqById(t.getId());
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(ylrqList.size());
        logger.info(JSON.toJSONString(ylrqList));
        Row row = sheet.getRow(3);
        Cell cell = row.getCell(1);
        // 获取单元格样式
        CellStyle originalStyle = cell.getCellStyle();
        cell.setCellStyle(originalStyle);
        cell.setCellValue(getDevTotal(ylrqList));

        List<TSpecReport> ylgdList = tSpecReportMapper.selectExpriedYlgd(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : ylgdList
        ) {
            TSpecdevYlgd d = tSpecdevYlgdMapper.selectTSpecdevYlgdById(t.getId());
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(ylgdList.size());
        logger.info(JSON.toJSONString(ylgdList));
        Row row2 = sheet.getRow(3);
        Cell cell2 = row2.getCell(4);
        cell2.setCellValue(getDevTotal(ylgdList));

        List<TSpecReport> glList = tSpecReportMapper.selectExpriedGl(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : glList
        ) {
            TSpecdevGl d = tSpecdevGlMapper.selectTSpecdevGlById(t.getId());
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(glList.size());
        logger.info(JSON.toJSONString(glList));
        Row row3 = sheet.getRow(3);
        Cell cell3 = row3.getCell(7);
        cell3.setCellValue(getDevTotal(glList));

        List<TSpecReport> dtList = tSpecReportMapper.selectExpriedDt(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : dtList
        ) {
            TSpecdevDt d = tSpecdevDtMapper.selectTSpecdevDtById(t.getId());
            logger.info(JSON.toJSONString(d));
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(dtList.size());
        logger.info(JSON.toJSONString(dtList));
        Row row4 = sheet.getRow(3);
        Cell cell4 = row4.getCell(10);
        cell4.setCellValue(getDevTotal(dtList));

        List<TSpecReport> dzsbList = tSpecReportMapper.selectExpriedDzsb(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : dzsbList
        ) {
            TSpecdevDzsb d = tSpecdevDzsbMapper.selectTSpecdevDzsbById(t.getId());
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(dzsbList.size());
        logger.info(JSON.toJSONString(dzsbList));
        Row row5 = sheet.getRow(3);
        Cell cell5 = row5.getCell(13);
        cell5.setCellValue(getDevTotal(dzsbList));

        List<TSpecReport> ccList = tSpecReportMapper.selectExpriedCc(new TSpecReport());
        // 判断超期原因
        for (TSpecReport t : ccList
        ) {
            TSpecdevCc d = tSpecdevCcMapper.selectTSpecdevCcById(t.getId());
            String re = checkApproveStatus(d.getApproveStatus()); //申请中超期
            if (re == null) {
                re = checkRemarks(d.getRemarks() + d.getRemarks2());//备注超期
            }
            t.setRemarks(re);
        }
        numArr.add(ccList.size());
        logger.info(JSON.toJSONString(ccList));
        Row row6 = sheet.getRow(3);
        Cell cell6 = row6.getCell(16);
        cell6.setCellValue(getDevTotal(ccList));

        int maxNum = findMaxValue(numArr);
        int needNum = maxNum - 3 > 0 ? maxNum - 3 : 0;
        for (int i = 0; i < needNum; i++) {
            sheet.shiftRows(6, sheet.getLastRowNum(), 1);
            cpoyRow(6, sheet);
        }
        // 合并区域从第0行第0列到第0行第3列
        CellRangeAddress mergedRegion = new CellRangeAddress(
                3, // 起始行
                needNum + 7, // 结束行
                0, // 起始列
                0  // 结束列
        );
        sheet.addMergedRegion(mergedRegion);

        renderCell(wb, sheet, ylrqList, 5, 1);
        renderCell(wb, sheet, ylgdList, 5, 4);
        renderCell(wb, sheet, glList, 5, 7);
        renderCell(wb, sheet, dtList, 5, 10);
        renderCell(wb, sheet, dzsbList, 5, 13);
        renderCell(wb, sheet, ccList, 5, 16);
    }

    private String checkRemarks(String input) {
        logger.info("checkRemarks包含 '" + input + "'================");
        String[] keywords = {"报告未到", "已检等待报告", "等待报告", "已检"};
        for (String keyword : keywords) {
            if (input.contains(keyword)) {
                System.out.println("包含 '" + keyword + "'");
                return "报告未到";
            }
        }
        return null;
    }

    private String checkApproveStatus(Long approveStatus) {
        if (approveStatus == 2l) {
            return "停用申请中";
        }
        if (approveStatus == 3l) {
            return "报废申请中";
        }
        if (approveStatus == -1l) {
            return "注销申请中";
        }
        return null;
    }

    // Excel 渲染
    private void replaceExcel(SXSSFWorkbook wb) {
        Sheet sheet;
        if (wb instanceof SXSSFWorkbook) {
            SXSSFWorkbook sxssfWorkbook = (SXSSFWorkbook) wb;
            sheet = sxssfWorkbook.getXSSFWorkbook().getSheetAt(0);
        } else {
            sheet = wb.getSheetAt(0);
        }
        //压力容器
        int ylrqAll = tSpecdevYlrqService.count(new QueryWrapper<TSpecdevYlrq>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row = sheet.getRow(2);
        Cell cell = row.getCell(1);
        // 获取单元格样式
        CellStyle originalStyle = cell.getCellStyle();
        cell.setCellStyle(originalStyle);
        cell.setCellValue(ylrqAll + "(台)");

        //压力管道
        int ylgdAll = tSpecdevYlgdService.count(new QueryWrapper<TSpecdevYlgd>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row2 = sheet.getRow(2);
        Cell cell2 = row2.getCell(4);
        // 获取单元格样式
        cell2.setCellValue(ylgdAll + "(条)");
        //锅炉
        int glAll = tSpecdevGlService.count(new QueryWrapper<TSpecdevGl>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row3 = sheet.getRow(2);
        Cell cell3 = row3.getCell(7);
        // 获取单元格样式
        cell3.setCellValue(glAll + "(套)");
        //电梯
        int dtAll = tSpecdevDtService.count(new QueryWrapper<TSpecdevDt>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row4 = sheet.getRow(2);
        Cell cell4 = row4.getCell(10);
        // 获取单元格样式
        cell4.setCellValue(dtAll + "(台)");
        //吊装设备
        int dzsbAll = tSpecdevDzsbService.count(new QueryWrapper<TSpecdevDzsb>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row5 = sheet.getRow(2);
        Cell cell5 = row5.getCell(13);
        // 获取单元格样式
        cell5.setCellValue(dzsbAll + "(条)");
        //叉车
        int ccAll = tSpecdevCcService.count(new QueryWrapper<TSpecdevCc>()
                .eq("STATUS", 1)
                .eq("del_flag", 0)
        );
        Row row6 = sheet.getRow(2);
        Cell cell6 = row6.getCell(16);
        // 获取单元格样式
        cell6.setCellValue(ccAll + "(辆)");

    }

    private int getDevTotal(List<TSpecReport> list) {
        int num = 0;
        for (TSpecReport t : list
        ) {
            num = num + t.getDevNum();
        }
        return num;
    }

    void cpoyRow(int rowNum, Sheet sheet) {
        Row newRow = sheet.createRow(rowNum);
        Row oldRow = sheet.getRow(rowNum + 1);
        for (int i = 0; i < 22; i++) {
            Cell newCell = newRow.createCell(i);
            Cell oldCell = oldRow.getCell(i);
            CellStyle originalStyle = oldCell.getCellStyle();
            newCell.setCellStyle(originalStyle);
        }
    }

    public int findMaxValue(List<Integer> list) {
        // Assume the first element is the largest
        int max = list.get(0);

        // Loop through the list starting from the second element
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i) > max) {
                max = list.get(i);
            }
        }

        return max;
    }

    public void renderCell(SXSSFWorkbook wb, Sheet sheet, List<TSpecReport> list, int startRow, int startCol) {
        int num = 0;
        Font font = wb.createFont();
        font.setFontHeightInPoints((short) 9); // 设置字体大小为12
        font.setBold(false);
        for (TSpecReport t : list
        ) {
            //装置
            logger.info("开始渲染行：" + startRow + "开始渲染列：" + (startCol + num));
            Row row = sheet.getRow(startRow + num);
            Cell cell = row.getCell(startCol);
            // 获取单元格样式
            CellStyle originalStyle = cell.getCellStyle();
            originalStyle.setFont(font);
            cell.setCellStyle(originalStyle);
            cell.setCellValue(t.getPlantCode());

            //数量
            logger.info("开始渲染行：" + startRow + num + "开始渲染列：" + startCol + 1);
            Row row2 = sheet.getRow(startRow + num);
            Cell cell2 = row2.getCell(startCol + 1);
            // 获取单元格样式
            originalStyle = cell2.getCellStyle();
            originalStyle.setFont(font);
            cell2.setCellStyle(originalStyle);
            cell2.setCellValue(t.getDevNum());

            //备注
            logger.info("开始渲染行：" + startRow + num + "开始渲染列：" + startCol + 2);
            Row row3 = sheet.getRow(startRow + num);
            Cell cell3 = row3.getCell(startCol + 2);
            // 获取单元格样式
            originalStyle = cell3.getCellStyle();
            originalStyle.setFont(font);
            cell3.setCellStyle(originalStyle);
            if (t.getRemarks() != null) {
                cell3.setCellValue(t.getRemarks().replace("-通过", "").replace("批准", ""));
            }
            num++;
        }

    }

    ;

    /**
     * 修改特种设备报告
     *
     * @param tSpecReport 特种设备报告
     * @return 结果
     */
    @Override
    public int updateTSpecReport(TSpecReport tSpecReport) {
        return tSpecReportMapper.updateTSpecReport(tSpecReport);
    }

    /**
     * 批量删除特种设备报告
     *
     * @param ids 需要删除的特种设备报告ID
     * @return 结果
     */
    @Override
    public int deleteTSpecReportByIds(Long[] ids) {
        return tSpecReportMapper.deleteTSpecReportByIds(ids);
    }

    /**
     * 删除特种设备报告信息
     *
     * @param id 特种设备报告ID
     * @return 结果
     */
    @Override
    public int deleteTSpecReportById(Long id) {
        return tSpecReportMapper.deleteTSpecReportById(id);
    }

    private String createDetailExcel(TSpecReport tSpecReport, boolean isThree) {
        SXSSFWorkbook wb = new SXSSFWorkbook(1000);
        CellStyle wrapStyle = wb.createCellStyle();
        wrapStyle.setWrapText(true);    //设置自动换行
        //
        replaceDetailYrlq(wb, isThree);
        replaceDetailYrgd(wb, isThree);
        replaceDetailGl(wb, isThree);
        replaceDetailDt(wb, isThree);
        replaceDetailDzsb(wb, isThree);
        replaceDetailCc(wb, isThree);


        try {
            String fileDir = "";
            if (isThree) {
                fileDir = RuoYiConfig.getProfile() + "/" + "sems/spec-report-detail3";
            } else {
                fileDir = RuoYiConfig.getProfile() + "/" + "sems/spec-report-detail";
            }
            // Save the generated file
            File dir = new File(fileDir);
            if (!dir.exists()) {
                logger.info("目录不存在，创建文件夹{}!", fileDir);
                dir.mkdirs();
            }
            FileOutputStream fos = null;
            LocalDate currentDate = LocalDate.now();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
            String dateStr = currentDate.format(formatter);
            String filePath = fileDir + "/" + dateStr + "ReportDetail" + tSpecReport.getId() + ".xlsx";
            if (isThree) {
                filePath = fileDir + "/" + dateStr + "Report3MonthDetail" + tSpecReport.getId() + ".xlsx";
            }

            fos = new FileOutputStream(filePath);

            wb.write(fos);
            //
            int dirLastIndex = RuoYiConfig.getProfile().length() + 1;
            String currentDir = StringUtils.substring(filePath, dirLastIndex);
            String pathFileName = Constants.RESOURCE_PREFIX + "/" + currentDir;
            return pathFileName;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    private void replaceDetailYrlq(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevYlrq> list;
        if (isThree) {
             list = tSpecdevYlrqMapper.selectExpiredYlrq(3);
        }else {
             list = tSpecdevYlrqMapper.selectExpiredYlrq(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("压力容器");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        sheet.setColumnWidth(10, 26 * 256);
        sheet.setColumnWidth(11, 26 * 256);
        sheet.setColumnWidth(12, 40 * 256);
        sheet.setColumnWidth(13, 40 * 256);
        sheet.setColumnWidth(14, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();
        style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//        Font headerFont = wb.createFont();
//        headerFont.setFontName("Arial");
//        headerFont.setFontHeightInPoints((short) 12);
//        headerFont.setBold(false);
//        headerFont.setColor(IndexedColors.BLACK.getIndex());
//        style.setFont(headerFont);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("位号");
        row0.createCell(3).setCellValue("设备名称");
        row0.createCell(4).setCellValue("使用证号码");
        row0.createCell(5).setCellValue("检验单位");
        row0.createCell(6).setCellValue("定期检验日期");
        row0.createCell(7).setCellValue("安全状况等级");
        row0.createCell(8).setCellValue("下次定期检验日期");
        row0.createCell(9).setCellValue("定期检验报告编号");

        row0.createCell(10).setCellValue("年度检查日期");
        row0.createCell(11).setCellValue("年度检查结论");
        row0.createCell(12).setCellValue("下次年度检查日期");
        row0.createCell(13).setCellValue("年度检查报告编号");
        row0.createCell(14).setCellValue("备注");
        row0.createCell(15).setCellValue("备注2");
        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevYlrq t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getDevno());
            row.createCell(3).setCellValue(t.getDevname());
            row.createCell(4).setCellValue(t.getUseno());
            row.createCell(5).setCellValue(t.getCheckUnit());
            if (t.getWarnDate() != null) {
                row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }
            row.createCell(7).setCellValue(t.getSafeClass());
            if (t.getNextWarnDate() != null) {
                row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            row.createCell(9).setCellValue(t.getReportNo());
            if (t.getYearWarnDate() != null) {
                row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearWarnDate()));
            }
            row.createCell(11).setCellValue(t.getCheckConclusion());
            if (t.getYearNextWarnDate() != null) {
                row.createCell(12).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearNextWarnDate()));
            }
            row.createCell(13).setCellValue(t.getYearReportNo());
            row.createCell(14).setCellValue(t.getRemarks());
            row.createCell(15).setCellValue(t.getRemarks2());
            rowIndex++;
        }
    }

    private void replaceDetailYrgd(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevYlgd> list;
        if (isThree) {
            list = tSpecdevYlgdMapper.selectExpiredYlgd(3);
        }else {
            list = tSpecdevYlgdMapper.selectExpiredYlgd(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("压力管道");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        sheet.setColumnWidth(10, 26 * 256);
        sheet.setColumnWidth(11, 26 * 256);
        sheet.setColumnWidth(12, 40 * 256);
        sheet.setColumnWidth(13, 40 * 256);
        sheet.setColumnWidth(14, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();

//        Font headerFont = wb.createFont();
//        headerFont.setFontName("Arial");
//        headerFont.setFontHeightInPoints((short) 12);
//        headerFont.setBold(false);
//        headerFont.setColor(IndexedColors.BLACK.getIndex());
//        style.setFont(headerFont);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("管道名称");
        row0.createCell(3).setCellValue("管道编号");
        row0.createCell(4).setCellValue("使用登记表编号");
        row0.createCell(5).setCellValue("检验单位");
        row0.getCell(5).setCellStyle(style);
        row0.createCell(6).setCellValue("定期检验日期");
        row0.getCell(6).setCellStyle(style);
        row0.createCell(7).setCellValue("安全状况等级");
        row0.getCell(7).setCellStyle(style);
        row0.createCell(8).setCellValue("定期检验报告编号");
        row0.getCell(8).setCellStyle(style);
        row0.createCell(9).setCellValue("下次定期检验日期");
        row0.getCell(9).setCellStyle(style);

        row0.createCell(10).setCellValue("年度检查日期");
        row0.getCell(10).setCellStyle(style);
        row0.createCell(11).setCellValue("年度检查结论");
        row0.getCell(11).setCellStyle(style);
        row0.createCell(12).setCellValue("下次年度检查日期");
        row0.getCell(12).setCellStyle(style);
        row0.createCell(13).setCellValue("年度检查报告编号");
        row0.getCell(13).setCellStyle(style);
        row0.createCell(14).setCellValue("备注");
        row0.getCell(14).setCellStyle(style);
        row0.createCell(15).setCellValue("备注2");
        row0.getCell(15).setCellStyle(style);
        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevYlgd t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getDevname());
            row.createCell(3).setCellValue(t.getDevno());
            row.createCell(4).setCellValue(t.getUseno());
            row.createCell(5).setCellValue(t.getCheckUnit());
            if (t.getWarnDate() != null) {
                row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }
            row.createCell(7).setCellValue(t.getSafeClass());
            row.createCell(8).setCellValue(t.getReportNo());
            if (t.getNextWarnDate() != null) {
                row.createCell(9).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            if (t.getYearWarnDate() != null) {
                row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearWarnDate()));
            }
            row.createCell(11).setCellValue(t.getCheckConclusion());
            if (t.getYearNextWarnDate() != null) {
                row.createCell(12).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getYearNextWarnDate()));
            }
            row.createCell(13).setCellValue(t.getYearReportNo());
            row.createCell(14).setCellValue(t.getRemarks());
            row.createCell(15).setCellValue(t.getRemarks2());
            rowIndex++;
        }

    }

    private void replaceDetailGl(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevGl> list;
        if (isThree) {
            list = tSpecdevGlMapper.selectExpiredGl(3);
        }else {
            list = tSpecdevGlMapper.selectExpiredGl(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("锅炉");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        sheet.setColumnWidth(10, 26 * 256);
        sheet.setColumnWidth(11, 26 * 256);
        sheet.setColumnWidth(12, 40 * 256);
        sheet.setColumnWidth(13, 40 * 256);
        sheet.setColumnWidth(14, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();

//        Font headerFont = wb.createFont();
//        headerFont.setFontName("Arial");
//        headerFont.setFontHeightInPoints((short) 12);
//        headerFont.setBold(false);
//        headerFont.setColor(IndexedColors.BLACK.getIndex());
//        style.setFont(headerFont);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("设备位号");
        row0.createCell(3).setCellValue("设备名称");
        row0.createCell(4).setCellValue("使用证号码");
        row0.createCell(5).setCellValue("检验单位");
        row0.getCell(5).setCellStyle(style);
        row0.createCell(6).setCellValue("本次内部检验日期");
        row0.getCell(6).setCellStyle(style);
        row0.createCell(7).setCellValue("内部检验结论");
        row0.getCell(7).setCellStyle(style);
        row0.createCell(8).setCellValue("内部检验报告编号");
        row0.getCell(8).setCellStyle(style);
        row0.createCell(9).setCellValue("下次内部检验日期");
        row0.getCell(9).setCellStyle(style);

        row0.createCell(10).setCellValue("本次外部检验日期");
        row0.getCell(10).setCellStyle(style);
        row0.createCell(11).setCellValue("外部检验结论");
        row0.getCell(11).setCellStyle(style);
        row0.createCell(12).setCellValue("外部检验报告编号");
        row0.getCell(12).setCellStyle(style);
        row0.createCell(13).setCellValue("下次外部检验日期");
        row0.getCell(13).setCellStyle(style);
        row0.createCell(14).setCellValue("备注");
        row0.getCell(14).setCellStyle(style);
        row0.createCell(15).setCellValue("备注2");
        row0.getCell(15).setCellStyle(style);

        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevGl t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getDevno());
            row.createCell(3).setCellValue(t.getDevname());
            row.createCell(4).setCellValue(t.getUseno());
            row.createCell(5).setCellValue(t.getCheckUnit());
            if (t.getWarnDate() != null) {
                row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }

            row.createCell(7).setCellValue(t.getCheckConclusion());
            row.createCell(8).setCellValue(t.getReportNo());
            if (t.getNextWarnDate() != null) {
                row.createCell(9).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            if (t.getOutWarnDate() != null) {
                row.createCell(10).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getOutWarnDate()));
            }
            row.createCell(11).setCellValue(t.getOutCheckConclusion());
            row.createCell(12).setCellValue(t.getOutReportNo());
            if (t.getOutNextWarnDate() != null) {
                row.createCell(13).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getOutNextWarnDate()));
            }
            row.createCell(14).setCellValue(t.getRemarks());
            row.createCell(15).setCellValue(t.getRemarks2());
            rowIndex++;
        }
    }

    private void replaceDetailDt(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevDt> list;
        if (isThree) {
            list = tSpecdevDtMapper.selectExpiredDt(3);
        }else {
            list = tSpecdevDtMapper.selectExpiredDt(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("电梯");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        sheet.setColumnWidth(10, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();

//        Font headerFont = wb.createFont();
//        headerFont.setFontName("Arial");
//        headerFont.setFontHeightInPoints((short) 12);
//        headerFont.setBold(false);
//        headerFont.setColor(IndexedColors.BLACK.getIndex());
//        style.setFont(headerFont);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("档案号");
        row0.createCell(3).setCellValue("型号");
        row0.createCell(4).setCellValue("使用地点");
        row0.createCell(5).setCellValue("检验日期");
        row0.getCell(5).setCellStyle(style);
        row0.createCell(6).setCellValue("检验单位");
        row0.getCell(6).setCellStyle(style);
        row0.createCell(7).setCellValue("报告编号");
        row0.getCell(7).setCellStyle(style);
        row0.createCell(8).setCellValue("下次检验日期");
        row0.getCell(8).setCellStyle(style);
        row0.createCell(9).setCellValue("定期检验结论");
        row0.getCell(9).setCellStyle(style);
        row0.createCell(10).setCellValue("备注");
        row0.getCell(10).setCellStyle(style);
        row0.createCell(11).setCellValue("备注2");
        row0.getCell(11).setCellStyle(style);
        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevDt t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getDocno());
            row.createCell(3).setCellValue(t.getModel());
            row.createCell(4).setCellValue(t.getLocation());
            if (t.getWarnDate() != null) {
                row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }
            row.createCell(6).setCellValue(t.getCheckUnit());
            row.createCell(7).setCellValue(t.getReportNo());
            if (t.getNextWarnDate() != null) {
                row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            row.createCell(9).setCellValue(t.getPerTestConclusion());
            row.createCell(10).setCellValue(t.getRemarks());
            row.createCell(11).setCellValue(t.getRemarks2());
            rowIndex++;
        }
    }

    private void replaceDetailDzsb(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevDzsb> list;
        if (isThree) {
            list = tSpecdevDzsbMapper.selectExpiredDzsb(3);
        }else {
            list = tSpecdevDzsbMapper.selectExpiredDzsb(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("起重机械");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        sheet.setColumnWidth(10, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();
//        Font headerFont = wb.createFont();
//        headerFont.setFontName("Arial");
//        headerFont.setFontHeightInPoints((short) 12);
//        headerFont.setBold(false);
//        headerFont.setColor(IndexedColors.BLACK.getIndex());
//        style.setFont(headerFont);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("设备位号");
        row0.createCell(3).setCellValue("档案号");
        row0.createCell(4).setCellValue("设备名称");
        row0.createCell(5).setCellValue("检验单位");
        row0.getCell(5).setCellStyle(style);
        row0.createCell(6).setCellValue("检验日期");
        row0.getCell(6).setCellStyle(style);
        row0.createCell(7).setCellValue("报告编号");
        row0.getCell(7).setCellStyle(style);
        row0.createCell(8).setCellValue("下次检验日期");
        row0.getCell(8).setCellStyle(style);
        row0.createCell(9).setCellValue("定期检验结论");
        row0.getCell(9).setCellStyle(style);
        row0.createCell(10).setCellValue("备注");
        row0.getCell(10).setCellStyle(style);
        row0.createCell(11).setCellValue("备注2");
        row0.getCell(11).setCellStyle(style);
        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevDzsb t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getDevno());
            row.createCell(3).setCellValue(t.getDocno());
            row.createCell(4).setCellValue(t.getDevname());
            row.createCell(5).setCellValue(t.getCheckUnit());
            if (t.getWarnDate() != null) {
                row.createCell(6).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }
            row.createCell(7).setCellValue(t.getReportNo());
            if (t.getNextWarnDate() != null) {
                row.createCell(8).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            row.createCell(9).setCellValue(t.getPerTestConclusion());
            row.createCell(10).setCellValue(t.getRemarks());
            row.createCell(11).setCellValue(t.getRemarks2());
            rowIndex++;
        }
    }

    private void replaceDetailCc(SXSSFWorkbook wb, boolean isThree) {
        List<TSpecdevCc> list;
        if (isThree) {
            list = tSpecdevCcMapper.selectExpiredCc(3);
        }else {
            list = tSpecdevCcMapper.selectExpiredCc(0);
        }
        //创建sheet页
        Sheet sheet = wb.createSheet("叉车");
        //设置列的宽度，第一个参数为列的序号，从0开始，第二参数为列宽，单位1/256个字节
        sheet.setColumnWidth(0, 12 * 256);
        sheet.setColumnWidth(1, 26 * 256);
        sheet.setColumnWidth(2, 26 * 256);
        sheet.setColumnWidth(3, 26 * 256);
        sheet.setColumnWidth(4, 26 * 256);
        sheet.setColumnWidth(5, 26 * 256);
        sheet.setColumnWidth(6, 26 * 256);
        sheet.setColumnWidth(7, 26 * 256);
        sheet.setColumnWidth(8, 40 * 256);
        sheet.setColumnWidth(9, 40 * 256);
        //设置开始行和开始列

        Row row0 = sheet.createRow(0);
        CellStyle style = wb.createCellStyle();
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        Cell cell0 = row0.createCell(0);
        row0.createCell(0).setCellValue("序号");
        row0.createCell(1).setCellValue("装置");
        row0.createCell(2).setCellValue("车牌号");
        row0.createCell(3).setCellValue("档案号");
        row0.createCell(4).setCellValue("检验日期");
        row0.createCell(5).setCellValue("下次检验日期");
        row0.createCell(6).setCellValue("报告编号");
        row0.createCell(7).setCellValue("定期检验结论");
        row0.createCell(8).setCellValue("备注");
        row0.createCell(9).setCellValue("备注2");
        //填充数据
        int rowIndex = 1;
        int columnIndex = 1;
        for (TSpecdevCc t : list
        ) {
            Row row = sheet.createRow(rowIndex);
            row.createCell(0).setCellValue(t.getId());
            row.createCell(1).setCellValue(t.getPlantCode());
            row.createCell(2).setCellValue(t.getCarNo());
            row.createCell(3).setCellValue(t.getDocno());
            if (t.getWarnDate() != null) {
                row.createCell(4).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getWarnDate()));
            }
            if (t.getNextWarnDate() != null) {
                row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(t.getNextWarnDate()));
            }
            row.createCell(6).setCellValue(t.getReportNo());
            row.createCell(7).setCellValue(t.getPerTestConclusion());
            row.createCell(8).setCellValue(t.getRemarks());
            row.createCell(9).setCellValue(t.getRemarks2());
            rowIndex++;
        }
    }


}
