package org.jeecg.modules.workorderTemplate.service.impl;

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.jeecg.common.api.vo.Result;
import org.jeecg.modules.workorderGeneralStepfour.entity.WorkorderGeneralStepfour;
import org.jeecg.modules.workorderGeneralStepfour.service.IWorkorderGeneralStepfourService;
import org.jeecg.modules.workorderGeneralStepone.entity.WorkorderGeneralStepone;
import org.jeecg.modules.workorderGeneralStepone.service.IWorkorderGeneralSteponeService;
import org.jeecg.modules.workorderGeneralStepthree.entity.WorkorderGeneralStepthree;
import org.jeecg.modules.workorderGeneralStepthree.service.IWorkorderGeneralStepthreeService;
import org.jeecg.modules.workorderGeneralSteptwo.entity.WorkorderGeneralSteptwo;
import org.jeecg.modules.workorderGeneralSteptwo.service.IWorkorderGeneralSteptwoService;
import org.jeecg.modules.workorderItemCheck.entity.WorkorderItemCheck;
import org.jeecg.modules.workorderItemCheck.service.IWorkorderItemCheckService;
import org.jeecg.modules.workorderParamStepfour.entity.WorkorderParamStepfour;
import org.jeecg.modules.workorderParamStepfour.service.IWorkorderParamStepfourService;
import org.jeecg.modules.workorderParamStepone.entity.WorkorderParamStepone;
import org.jeecg.modules.workorderParamStepone.service.IWorkorderParamSteponeService;
import org.jeecg.modules.workorderParamStepthree.entity.WorkorderParamStepthree;
import org.jeecg.modules.workorderParamStepthree.service.IWorkorderParamStepthreeService;
import org.jeecg.modules.workorderParamSteptwo.entity.WorkorderParamSteptwo;
import org.jeecg.modules.workorderParamSteptwo.service.IWorkorderParamSteptwoService;
import org.jeecg.modules.workorderProcess.entity.WorkorderProcess;
import org.jeecg.modules.workorderProcess.service.IWorkorderProcessService;
import org.jeecg.modules.workorderStep.entity.WorkorderStep;
import org.jeecg.modules.workorderStep.service.IWorkorderStepService;
import org.jeecg.modules.workorderTemplate.entity.ImportBean;
import org.jeecg.modules.workorderTemplate.entity.WorkorderTemplate;
import org.jeecg.modules.workorderTemplate.service.IWorkorderTemplateService;
import org.jeecg.modules.workorderTemplate.service.WorkorderExcelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

@Service
public class WorkorderExcelServiceImpl implements WorkorderExcelService {



    //工单信息
    @Resource
    private IWorkorderTemplateService workorderTemplateService;

    //工序卡信息
    @Resource
    private IWorkorderStepService workorderStepService;

    //工序流程信息
    @Resource
    private IWorkorderProcessService workorderProcessService;

    //检查项目信息
    @Resource
    private IWorkorderItemCheckService workorderItemCheckService;

    //工序卡常规参数
    @Resource
    private IWorkorderGeneralSteponeService workorderGeneralSteponeService;
    @Resource
    private IWorkorderGeneralSteptwoService workorderGeneralSteptwoService;
    @Resource
    private IWorkorderGeneralStepthreeService workorderGeneralStepthreeService;
    @Resource
    private IWorkorderGeneralStepfourService workorderGeneralStepfourService;

    //工序卡列表参数
    @Resource
    private IWorkorderParamSteponeService workorderParamSteponeService;
    @Resource
    private IWorkorderParamSteptwoService workorderParamSteptwoService;
    @Resource
    private IWorkorderParamStepthreeService workorderParamStepthreeService;
    @Resource
    private IWorkorderParamStepfourService workorderParamStepfourService;
    /******************************************************************************************************************/
    @Override
    public Result<?> templateImport1(List<ImportBean> importBeanList) {
        List<WorkorderTemplate> templateList = new ArrayList<>();

        try {
            //1、获取excel数据
            for (ImportBean importBean : importBeanList) {
                WorkorderTemplate workorderTemplate = new WorkorderTemplate();
                workorderTemplate.setTaskNo(importBean.getTaskNo());
                workorderTemplate.setResponsibler(importBean.getResponsibler());
                workorderTemplate.setModel(importBean.getModel());
                workorderTemplate.setNumber(importBean.getNumber());
                templateList.add(workorderTemplate);
            }

            //2、将数据录入到数据库
            Boolean result = workorderTemplateService.saveBatch(templateList);
            if(result){
                return Result.OK("数据导入成功！");
            }else {
                return Result.error("数据导入失败！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("数据导入失败！");
        }
    }

    /**********************************************主体入口************************************************************/
    //工单导入
    @Override
    public Result<?> templateImport(String path) {
        try {
            //1、获取excel数据
            List<WorkorderTemplate> templateList = getImportData(path);

            //2、将数据录入到数据库
            Boolean result = workorderTemplateService.saveBatch(templateList);
            if(result){
                return Result.OK("数据导入成功！");
            }else {
                return Result.error("数据导入失败！");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("数据导入失败！");
        }
    }

    //工单导出
    @Override
    public Result<?> templateExport(String path, String templateId) {
        try {
            template(path, templateId);
            System.out.println("test over!");
            return Result.OK(templateId+"导出成功！");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.OK("导出失败！");
        }
    }

    /******************************************************************************************************************/
    /**********************************************工单导入************************************************************/
    //获取导入工单数据
    public List<WorkorderTemplate> getImportData(String path) throws Exception{
        path = "F:\\temp\\工单导入测试数据.xlsx";
        //工单列表
        List<WorkorderTemplate> templateList = new ArrayList<>();

        //创建文件流
        InputStream fileInputStream = null;
        try{
            //获取文件流
            fileInputStream = new FileInputStream(path);

            //1、创建一个工作簿
            Workbook workbook = new XSSFWorkbook(fileInputStream);
            //2、得到一个工作表
            Sheet sheet = workbook.getSheetAt(0);

            //3、获取表中内容
            //3.1、获取表中有多少行数据
            int rowCount = sheet.getPhysicalNumberOfRows();
            for (int rowNum = 1; rowNum < rowCount; rowNum++) {
                WorkorderTemplate template = new WorkorderTemplate();
                Row rowData = sheet.getRow(rowNum);
                if(rowData != null){
                    template.setTaskNo(rowData.getCell(0).getStringCellValue());
                    template.setResponsibler(rowData.getCell(1).getStringCellValue());
                    template.setModel(rowData.getCell(2).getStringCellValue());
                    template.setNumber((int)rowData.getCell(3).getNumericCellValue());
                }
                templateList.add(template);
            }

            return templateList;

        }catch (Exception e){
            e.printStackTrace();
            return null;
        }finally {
            if(null != fileInputStream){
                //操作结束，关闭文件
                fileInputStream.close();
            }
        }
    }





    /******************************************************************************************************************/
    /**********************************************工单导出************************************************************/
    //创建工作表
    public void template(String path, String templateId) throws Exception{
        //创建一个工作表
        Workbook workbook = new SXSSFWorkbook();

        //编辑工作表内容
        sheet(workbook, templateId);

        //导出工作表
        FileOutputStream out = new FileOutputStream(path+templateId+".xlsx");
        workbook.write(out);

        //操作结束，关闭文件流
        out.close();

        //清除临时文件
        ((SXSSFWorkbook) workbook).dispose();

    }

    //常规参数-工序卡1
    public int generalParamOne(Sheet sheet, WorkorderTemplate template, int stepNum, int generalNum, CellStyle cellStyle){
        //常规参数信息
        WorkorderGeneralStepone generalStepone = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteponeList().get(generalNum);
        //设置跨行跨列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));
        sheet.addMergedRegion(new CellRangeAddress(2, 3, 6, 6));
        sheet.addMergedRegion(new CellRangeAddress(2, 3, 7, 7));

        //第一行
        Row row1 = sheet.createRow(0);
        //第一行第一列
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("中试压缩机试作工序卡1（选配）");
        cell11.setCellStyle(cellStyle);

        //第二行
        Row row2 = sheet.createRow(1);
        //第二行第n列
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("委托担当");
        Cell cell22 = row2.createCell(1);
        cell22.setCellValue(template.getResponsibler());
        Cell cell23 = row2.createCell(2);
        cell23.setCellValue("指示书/流程编号：");
        Cell cell24 = row2.createCell(3);
        cell24.setCellValue(template.getTaskNo());
        Cell cell25 = row2.createCell(4);
        cell25.setCellValue("机种名");
        Cell cell26 = row2.createCell(5);
        cell26.setCellValue(template.getModel());
        Cell cell27 = row2.createCell(6);
        cell27.setCellValue("数量");
        Cell cell28 = row2.createCell(7);
        cell28.setCellValue(template.getNumber());
        Cell cell29 = row2.createCell(8);
        cell29.setCellValue("页数");
        Cell cell210 = row2.createCell(9);
        cell210.setCellValue("1/4");

        //第三行
        Row row3 = sheet.createRow(2);
        //第三行第n列
        Cell cell31 = row3.createCell(0);
        cell31.setCellValue("气缸料号1");
        Cell cell32 = row3.createCell(1);
        cell32.setCellValue(generalStepone.getCylinder1());
        Cell cell33 = row3.createCell(2);
        cell33.setCellValue("活塞料号1");
        Cell cell34 = row3.createCell(3);
        cell34.setCellValue(generalStepone.getPiston1());
        Cell cell35 = row3.createCell(4);
        cell35.setCellValue("划片料号1");
        Cell cell36 = row3.createCell(5);
        cell36.setCellValue(generalStepone.getScribing1());
        Cell cell37 = row3.createCell(6);
        cell37.setCellValue("中试作业员");
        Cell cell38 = row3.createCell(7);
        cell38.setCellValue(generalStepone.getOperator());

        //第四行
        Row row4 = sheet.createRow(3);
        //第四行第n列
        Cell cell41 = row4.createCell(0);
        cell41.setCellValue("气缸料号2");
        Cell cell42 = row4.createCell(1);
        cell42.setCellValue(generalStepone.getCylinder2());
        Cell cell43 = row4.createCell(2);
        cell43.setCellValue("活塞料号2");
        Cell cell44 = row4.createCell(3);
        cell44.setCellValue(generalStepone.getPiston2());
        Cell cell45 = row4.createCell(4);
        cell45.setCellValue("划片料号2");
        Cell cell46 = row4.createCell(5);
        cell46.setCellValue(generalStepone.getScribing2());
        Cell cell47 = row4.createCell(6);
        cell47.setCellValue("中试作业员");
        Cell cell48 = row4.createCell(7);
        cell48.setCellValue(generalStepone.getOperator());
        return sheet.getLastRowNum();
    }

    //常规参数-工序卡2
    public int generalParamTwo(Sheet sheet, WorkorderTemplate template, int stepNum, int generalNum, CellStyle cellStyle){
        //常规参数信息
        WorkorderGeneralSteptwo generalSteptwo = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteptwoList().get(generalNum);
        //设置跨行跨列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        //第一行
        Row row1 = sheet.createRow(0);
        //第一行第一列
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("中试压缩机试作工序卡2");
        cell11.setCellStyle(cellStyle);

        //第二行
        Row row2 = sheet.createRow(1);
        //第二行第n列
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("委托担当");
        Cell cell22 = row2.createCell(1);
        cell22.setCellValue(template.getResponsibler());
        Cell cell23 = row2.createCell(2);
        cell23.setCellValue("指示书/流程编号：");
        Cell cell24 = row2.createCell(3);
        cell24.setCellValue(template.getTaskNo());
        Cell cell25 = row2.createCell(4);
        cell25.setCellValue("机种名");
        Cell cell26 = row2.createCell(5);
        cell26.setCellValue(template.getModel());
        Cell cell27 = row2.createCell(6);
        cell27.setCellValue("数量");
        Cell cell28 = row2.createCell(7);
        cell28.setCellValue(template.getNumber());
        Cell cell29 = row2.createCell(8);
        cell29.setCellValue("页数");
        Cell cell210 = row2.createCell(9);
        cell210.setCellValue("2/4");

        //第三行
        Row row3 = sheet.createRow(2);
        //第三行第n列
        Cell cell31 = row3.createCell(0);
        cell31.setCellValue("部件名");
        Cell cell32 = row3.createCell(1);
        cell32.setCellValue(generalSteptwo.getComponent());
        Cell cell33 = row3.createCell(2);
        cell33.setCellValue("日期");
        Cell cell34 = row3.createCell(3);
        cell34.setCellValue(generalSteptwo.getCurrentdate());
        Cell cell35 = row3.createCell(4);
        cell35.setCellValue("中试确认");
        Cell cell36 = row3.createCell(5);
        cell36.setCellValue(generalSteptwo.getCreateBy());
        Cell cell37 = row3.createCell(6);
        cell37.setCellValue("品质确认");
        Cell cell38 = row3.createCell(7);
        cell38.setCellValue(generalSteptwo.getConfirmQuality());
        Cell cell39 = row3.createCell(8);
        cell39.setCellValue("研发确认");
        Cell cell310 = row3.createCell(9);
        cell310.setCellValue(generalSteptwo.getConfirmDevelop());

        //第四行
        Row row4 = sheet.createRow(3);
        //第四行第n列
        Cell cell41 = row4.createCell(0);
        cell41.setCellValue("工序");
        Cell cell42 = row4.createCell(1);
        cell42.setCellValue("检查项目");
        Cell cell43 = row4.createCell(2);
        cell43.setCellValue("规格");
        Cell cell44 = row4.createCell(3);
        cell44.setCellValue("1");
        Cell cell45 = row4.createCell(4);
        cell45.setCellValue("2");
        Cell cell46 = row4.createCell(5);
        cell46.setCellValue("3");
        Cell cell47 = row4.createCell(6);
        cell47.setCellValue("4");
        Cell cell48 = row4.createCell(7);
        cell48.setCellValue("5");
        Cell cell49 = row4.createCell(8);
        cell49.setCellValue("6");
        Cell cell410 = row4.createCell(9);
        cell410.setCellValue("7");
        Cell cell411 = row4.createCell(10);
        cell411.setCellValue("8");
        Cell cell412 = row4.createCell(11);
        cell412.setCellValue("9");
        Cell cell413 = row4.createCell(12);
        cell413.setCellValue("10");
        Cell cell414 = row4.createCell(13);
        cell414.setCellValue("作业员");

        return sheet.getLastRowNum();
    }

    //常规参数-工序卡3
    public int generalParamThree(Sheet sheet, WorkorderTemplate template, int stepNum, int generalNum, CellStyle cellStyle){
        //常规参数信息
        WorkorderGeneralStepthree generalStepthree = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepthreeList().get(generalNum);
        //设置跨行跨列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        //第一行
        Row row1 = sheet.createRow(0);
        //第一行第一列
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("中试压缩机试作工序卡3");
        cell11.setCellStyle(cellStyle);


        //第二行
        Row row2 = sheet.createRow(1);
        //第二行第n列
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("委托担当");
        Cell cell22 = row2.createCell(1);
        cell22.setCellValue(template.getResponsibler());
        Cell cell23 = row2.createCell(2);
        cell23.setCellValue("指示书/流程编号：");
        Cell cell24 = row2.createCell(3);
        cell24.setCellValue(template.getTaskNo());
        Cell cell25 = row2.createCell(4);
        cell25.setCellValue("机种名");
        Cell cell26 = row2.createCell(5);
        cell26.setCellValue(template.getModel());
        Cell cell27 = row2.createCell(6);
        cell27.setCellValue("数量");
        Cell cell28 = row2.createCell(7);
        cell28.setCellValue(template.getNumber());
        Cell cell29 = row2.createCell(8);
        cell29.setCellValue("页数");
        Cell cell210 = row2.createCell(9);
        cell210.setCellValue("3/4");

        //第三行
        Row row3 = sheet.createRow(2);
        //第三行第n列
        Cell cell31 = row3.createCell(0);
        cell31.setCellValue("部件名");
        Cell cell32 = row3.createCell(1);
        cell32.setCellValue(generalStepthree.getComponent());
        Cell cell33 = row3.createCell(2);
        cell33.setCellValue("日期");
        Cell cell34 = row3.createCell(3);
        cell34.setCellValue(generalStepthree.getCurrentdate());
        Cell cell35 = row3.createCell(4);
        cell35.setCellValue("中试确认");
        Cell cell36 = row3.createCell(5);
        cell36.setCellValue(generalStepthree.getCreateBy());
        Cell cell37 = row3.createCell(6);
        cell37.setCellValue("品质确认");
        Cell cell38 = row3.createCell(7);
        cell38.setCellValue(generalStepthree.getConfirmQuality());
        Cell cell39 = row3.createCell(8);
        cell39.setCellValue("研发确认");
        Cell cell310 = row3.createCell(9);
        cell310.setCellValue(generalStepthree.getComfirmDevelop());

        //第四行
        Row row4 = sheet.createRow(3);
        //第四行第n列
        Cell cell41 = row4.createCell(0);
        cell41.setCellValue("工序");
        Cell cell42 = row4.createCell(1);
        cell42.setCellValue("检查项目");
        Cell cell43 = row4.createCell(2);
        cell43.setCellValue("规格");
        Cell cell44 = row4.createCell(3);
        cell44.setCellValue("1");
        Cell cell45 = row4.createCell(4);
        cell45.setCellValue("2");
        Cell cell46 = row4.createCell(5);
        cell46.setCellValue("3");
        Cell cell47 = row4.createCell(6);
        cell47.setCellValue("4");
        Cell cell48 = row4.createCell(7);
        cell48.setCellValue("5");
        Cell cell49 = row4.createCell(8);
        cell49.setCellValue("6");
        Cell cell410 = row4.createCell(9);
        cell410.setCellValue("7");
        Cell cell411 = row4.createCell(10);
        cell411.setCellValue("8");
        Cell cell412 = row4.createCell(11);
        cell412.setCellValue("9");
        Cell cell413 = row4.createCell(12);
        cell413.setCellValue("10");
        Cell cell414 = row4.createCell(13);
        cell414.setCellValue("作业员");

        return sheet.getLastRowNum();
    }

    //常规参数-工序卡4
    public int generalParamFour(Sheet sheet, WorkorderTemplate template, int stepNum, int generalNum, CellStyle cellStyle){
        //常规参数信息
        WorkorderGeneralStepfour generalStepfour = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepfourList().get(generalNum);
        //设置跨行跨列
        sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 9));

        //第一行
        Row row1 = sheet.createRow(0);
        //第一行第一列
        Cell cell11 = row1.createCell(0);
        cell11.setCellValue("中试压缩机试作工序卡4（总成）");
        cell11.setCellStyle(cellStyle);

        //第二行
        Row row2 = sheet.createRow(1);
        //第二行第n列
        Cell cell21 = row2.createCell(0);
        cell21.setCellValue("委托担当");
        Cell cell22 = row2.createCell(1);
        cell22.setCellValue(template.getResponsibler());
        Cell cell23 = row2.createCell(2);
        cell23.setCellValue("指示书/流程编号：");
        Cell cell24 = row2.createCell(3);
        cell24.setCellValue(template.getTaskNo());
        Cell cell25 = row2.createCell(4);
        cell25.setCellValue("机种名");
        Cell cell26 = row2.createCell(5);
        cell26.setCellValue(template.getModel());
        Cell cell27 = row2.createCell(6);
        cell27.setCellValue("数量");
        Cell cell28 = row2.createCell(7);
        cell28.setCellValue(template.getNumber());
        Cell cell29 = row2.createCell(8);
        cell29.setCellValue("页数");
        Cell cell210 = row2.createCell(9);
        cell210.setCellValue("4/4");

        //第三行
        Row row3 = sheet.createRow(2);
        //第三行第n列
        Cell cell31 = row3.createCell(0);
        cell31.setCellValue("部件名");
        Cell cell32 = row3.createCell(1);
        cell32.setCellValue(generalStepfour.getComponent());
        Cell cell33 = row3.createCell(2);
        cell33.setCellValue("日期");
        Cell cell34 = row3.createCell(3);
        cell34.setCellValue(generalStepfour.getCurrentdate());
        Cell cell35 = row3.createCell(4);
        cell35.setCellValue("中试确认");
        Cell cell36 = row3.createCell(5);
        cell36.setCellValue(generalStepfour.getCreateBy());
        Cell cell37 = row3.createCell(6);
        cell37.setCellValue("品质确认");
        Cell cell38 = row3.createCell(7);
        cell38.setCellValue(generalStepfour.getComfirmQuality());
        Cell cell39 = row3.createCell(8);
        cell39.setCellValue("研发确认");
        Cell cell310 = row3.createCell(9);
        cell310.setCellValue(generalStepfour.getComfirmDevelop());

        //第四行
        Row row4 = sheet.createRow(3);
        //第四行第n列
        Cell cell41 = row4.createCell(0);
        cell41.setCellValue("工序");
        Cell cell42 = row4.createCell(1);
        cell42.setCellValue("检查项目");
        Cell cell43 = row4.createCell(2);
        cell43.setCellValue("规格");
        Cell cell44 = row4.createCell(3);
        cell44.setCellValue("1");
        Cell cell45 = row4.createCell(4);
        cell45.setCellValue("2");
        Cell cell46 = row4.createCell(5);
        cell46.setCellValue("3");
        Cell cell47 = row4.createCell(6);
        cell47.setCellValue("4");
        Cell cell48 = row4.createCell(7);
        cell48.setCellValue("5");
        Cell cell49 = row4.createCell(8);
        cell49.setCellValue("6");
        Cell cell410 = row4.createCell(9);
        cell410.setCellValue("7");
        Cell cell411 = row4.createCell(10);
        cell411.setCellValue("8");
        Cell cell412 = row4.createCell(11);
        cell412.setCellValue("9");
        Cell cell413 = row4.createCell(12);
        cell413.setCellValue("10");
        Cell cell414 = row4.createCell(13);
        cell414.setCellValue("作业员");

        return sheet.getLastRowNum();
    }

    //工作簿
    public void sheet(Workbook workbook, String templateId) {
        //设置居中
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);//水平居中
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);//垂直居中

        WorkorderTemplate template = getExportData(templateId);

        int stepCount = template.getWorkorderStepList().size();//工序卡数量
        for (int stepNum = 0; stepNum < stepCount; stepNum++) {

            int lineNum = 0;//写入单元行
            int firstLine= 0;//合并单元起始行
            String stepName = template.getWorkorderStepList().get(stepNum).getName();//工序卡名称
            Sheet sheet = workbook.createSheet(stepName);//创建工序卡
            int processCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().size();//工序数量
            //工序卡1
            String stepId = template.getWorkorderStepList().get(stepNum).getId();//工序卡id

            //常规参数-工序卡1
            int generalOneCount = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteponeList().size();//常规参数数量
            for (int generalNum = 0; generalNum < generalOneCount; generalNum++) {
                String g_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteponeList().get(generalNum).getStepId();
                if(g_stepId.equals(stepId)){
                    lineNum = generalParamOne(sheet, template, stepNum, generalNum, cellStyle) + 1;
                    firstLine = lineNum;
                }
            }

            //常规参数-工序卡2
            int generalTwoCount = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteptwoList().size();//常规参数数量
            for (int generalNum = 0; generalNum < generalTwoCount; generalNum++) {
                String g_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralSteptwoList().get(generalNum).getStepId();
                if(g_stepId.equals(stepId)){
                    lineNum = generalParamTwo(sheet, template, stepNum, generalNum, cellStyle) + 1;
                    firstLine = lineNum;
                }
            }

            //常规参数-工序卡3
            int generalThreeCount = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepthreeList().size();//常规参数数量
            for (int generalNum = 0; generalNum < generalThreeCount; generalNum++) {
                String g_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepthreeList().get(generalNum).getStepId();
                if(g_stepId.equals(stepId)){
                    lineNum = generalParamThree(sheet, template, stepNum, generalNum, cellStyle) + 1;
                    firstLine = lineNum;
                }
            }

            //常规参数-工序卡3
            int generalFourCount = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepfourList().size();//常规参数数量
            for (int generalNum = 0; generalNum < generalFourCount; generalNum++) {
                String g_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderGeneralStepfourList().get(generalNum).getStepId();
                if(g_stepId.equals(stepId)){
                    lineNum = generalParamFour(sheet, template, stepNum, generalNum, cellStyle) + 1;
                    firstLine = lineNum;
                }
            }

            //检查项目参数
            for (int processNum = 0; processNum < processCount; processNum++) {
                //工序
                String p_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getStepId();//关联工序卡id
                if(p_stepId.equals(stepId)){
                    String processId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getId();//工序id
                    String processName = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getName();//工序名称
                    int itemCheckCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().size();//检查项目数量
                    int lastLine = firstLine + itemCheckCount-1;//合并单元结束行
                    if(firstLine != lastLine){
                        sheet.addMergedRegion(new CellRangeAddress(firstLine,lastLine,0,0));//合并单元格
                    }
                    for (int itemNum = 0; itemNum < itemCheckCount; itemNum++) {
                        //检查项目
                        String i_processId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getProcessId();//关联工序id
                        if(i_processId.equals(processId)){
                            String itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getId();//检查项目id
                            String itemCheckName = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getName();//检查项目名称

                            Row row = sheet.createRow(lineNum);
                            Cell cell1 = row.createCell(0);
                            cell1.setCellValue(processName);
                            Cell cell2 = row.createCell(1);
                            cell2.setCellValue(itemCheckName);

                            int paramOneCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().size();
                            for (int paramNum = 0; paramNum < paramOneCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)) {

                                    //检查项目参数-工序卡1
                                    WorkorderParamStepone paramStepone = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().get(paramNum);
                                    if (null != paramStepone) {
                                        //第n行第n列
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepone.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepone.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepone.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepone.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepone.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepone.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepone.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepone.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepone.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepone.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepone.getParam10());
                                        Cell param11 = row.createCell(13);
                                        param11.setCellValue(paramStepone.getParam11());
                                        Cell param12 = row.createCell(14);
                                        param12.setCellValue(paramStepone.getParam12());
                                        Cell param13 = row.createCell(15);
                                        param13.setCellValue(paramStepone.getParam13());
                                        Cell param14 = row.createCell(16);
                                        param14.setCellValue(paramStepone.getParam14());
                                        Cell param15 = row.createCell(17);
                                        param15.setCellValue(paramStepone.getParam15());
                                        Cell param16 = row.createCell(18);
                                        param16.setCellValue(paramStepone.getParam16());
                                        Cell param17 = row.createCell(19);
                                        param17.setCellValue(paramStepone.getParam17());
                                        Cell param18 = row.createCell(20);
                                        param18.setCellValue(paramStepone.getParam18());
                                        Cell param19 = row.createCell(21);
                                        param19.setCellValue(paramStepone.getParam19());
                                        Cell param20 = row.createCell(22);
                                        param20.setCellValue(paramStepone.getParam20());
                                        Cell remark = row.createCell(23);
                                        remark.setCellValue(paramStepone.getRemark());
                                    } else {
                                        break;
                                    }
                                }
                            }

                            //检查项目参数-工序卡2
                            int paramTwoCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().size();
                            for (int paramNum = 0; paramNum < paramTwoCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamSteptwo paramSteptwo = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().get(paramNum);
                                    if (null != paramSteptwo) {
                                        //第n行第n列
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramSteptwo.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramSteptwo.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramSteptwo.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramSteptwo.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramSteptwo.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramSteptwo.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramSteptwo.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramSteptwo.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramSteptwo.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramSteptwo.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramSteptwo.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramSteptwo.getOperator());
                                    } else {
                                        break;
                                    }
                                }
                            }

                            //检查项目参数-工序卡3
                            int paramThreeCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().size();
                            for (int paramNum = 0; paramNum < paramThreeCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamStepthree paramStepthree = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().get(paramNum);
                                    if (null != paramStepthree) {
                                        //第n行第n列
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepthree.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepthree.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepthree.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepthree.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepthree.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepthree.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepthree.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepthree.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepthree.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepthree.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepthree.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramStepthree.getOperator());
                                    } else {
                                        break;
                                    }
                                }
                            }

                            //检查项目参数-工序卡4
                            int paramFourCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().size();
                            for (int paramNum = 0; paramNum < paramFourCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamStepfour paramStepfour = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().get(paramNum);
                                    if (null != paramStepfour) {
                                        //第n行第n列
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepfour.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepfour.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepfour.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepfour.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepfour.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepfour.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepfour.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepfour.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepfour.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepfour.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepfour.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramStepfour.getOperator());
                                    } else {
                                        break;
                                    }
                                }
                            }

                            lineNum++;//行数增加

                        }
                    }
                    firstLine = lastLine+1;//改变下一个起始行位置
                }
            }
        }
    }

    //工作簿
    public void sheetTest(Workbook workbook, String templateId) {
        WorkorderTemplate template = getExportData(templateId);

        int stepCount = template.getWorkorderStepList().size();//工序卡数量
        for (int stepNum = 0; stepNum < stepCount; stepNum++) {
            int lineNum = 0;//写入单元行
            int firstLine= 0;//合并单元起始行
            String stepName = template.getWorkorderStepList().get(stepNum).getName();//工序卡名称
            Sheet sheet = workbook.createSheet(stepName);//创建工序卡
            int processCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().size();//工序数量
            //工序卡1
            String stepId = template.getWorkorderStepList().get(stepNum).getId();//工序卡id
            for (int processNum = 0; processNum < processCount; processNum++) {
                int line = 0;//合并行数(检查项目)
                //工序
                String p_stepId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getStepId();//关联工序卡id
                if(p_stepId.equals(stepId)){
                    String processId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getId();//工序id
                    String processName = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getName();//工序名称
                    int itemCheckCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().size();//检查项目数量

                    for (int itemNum = 0; itemNum < itemCheckCount; itemNum++) {
                        //检查项目
                        String i_processId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getProcessId();//关联工序id
                        if(i_processId.equals(processId)){
                            line++;
                            String itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getId();//检查项目id
                            String itemCheckName = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getName();//检查项目名称
                            int paramOneCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().size();
                            for (int paramNum = 0; paramNum < paramOneCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //检查项目参数-工序卡1
                                    WorkorderParamStepone paramStepone = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteponeList().get(paramNum);
                                    if (null != paramStepone) {
                                        //第n行
                                        //int lineNum = (stepNum * processCount * itemCheckCount) + (itemCheckCount * itemNum) + itemNum;
                                        Row row = sheet.createRow((lineNum));
                                        //第n行第n列
                                        Cell process = row.createCell(0);
                                        process.setCellValue(processName);
                                        Cell itemCheck = row.createCell(1);
                                        itemCheck.setCellValue(itemCheckName);
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepone.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepone.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepone.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepone.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepone.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepone.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepone.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepone.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepone.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepone.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepone.getParam10());
                                        Cell param11 = row.createCell(13);
                                        param11.setCellValue(paramStepone.getParam11());
                                        Cell param12 = row.createCell(14);
                                        param12.setCellValue(paramStepone.getParam12());
                                        Cell param13 = row.createCell(15);
                                        param13.setCellValue(paramStepone.getParam13());
                                        Cell param14 = row.createCell(16);
                                        param14.setCellValue(paramStepone.getParam14());
                                        Cell param15 = row.createCell(17);
                                        param15.setCellValue(paramStepone.getParam15());
                                        Cell param16 = row.createCell(18);
                                        param16.setCellValue(paramStepone.getParam16());
                                        Cell param17 = row.createCell(19);
                                        param17.setCellValue(paramStepone.getParam17());
                                        Cell param18 = row.createCell(20);
                                        param18.setCellValue(paramStepone.getParam18());
                                        Cell param19 = row.createCell(21);
                                        param19.setCellValue(paramStepone.getParam19());
                                        Cell param20 = row.createCell(22);
                                        param20.setCellValue(paramStepone.getParam20());
                                        Cell remark = row.createCell(23);
                                        remark.setCellValue(paramStepone.getRemark());
                                        lineNum++;
                                    } else {
                                        break;
                                    }

                                }
                            }

                            //检查项目参数-工序卡2
                            int paramTwoCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().size();
                            for (int paramNum = 0; paramNum < paramTwoCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamSteptwo paramSteptwo = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamSteptwoList().get(paramNum);
                                    if (null != paramSteptwo) {
                                        //第n行
                                        //int lineNum = (stepNum * processCount * itemCheckCount) + (itemCheckCount * itemNum) + itemNum;
                                        Row row = sheet.createRow((lineNum));
                                        //第n行第n列
                                        Cell process = row.createCell(0);
                                        process.setCellValue(processName);
                                        Cell itemCheck = row.createCell(1);
                                        itemCheck.setCellValue(itemCheckName);
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramSteptwo.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramSteptwo.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramSteptwo.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramSteptwo.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramSteptwo.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramSteptwo.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramSteptwo.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramSteptwo.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramSteptwo.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramSteptwo.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramSteptwo.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramSteptwo.getOperator());
                                        lineNum++;
                                    } else {
                                        break;
                                    }

                                }
                            }

                            //检查项目参数-工序卡3
                            int paramThreeCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().size();
                            for (int paramNum = 0; paramNum < paramThreeCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamStepthree paramStepthree = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepthreeList().get(paramNum);
                                    if (null != paramStepthree) {
                                        //第n行
                                        //int lineNum = (stepNum * processCount * itemCheckCount) + (itemCheckCount * itemNum) + itemNum;
                                        Row row = sheet.createRow((lineNum));
                                        //第n行第n列
                                        Cell process = row.createCell(0);
                                        process.setCellValue(processName);
                                        Cell itemCheck = row.createCell(1);
                                        itemCheck.setCellValue(itemCheckName);
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepthree.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepthree.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepthree.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepthree.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepthree.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepthree.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepthree.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepthree.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepthree.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepthree.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepthree.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramStepthree.getOperator());
                                        lineNum++;
                                    } else {
                                        break;
                                    }

                                }
                            }

                            //检查项目参数-工序卡4
                            int paramFourCount = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().size();
                            for (int paramNum = 0; paramNum < paramFourCount; paramNum++) {
                                String p_itemCheckId = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().get(paramNum).getProcessId();//关联检查项目id
                                if(p_itemCheckId.equals(itemCheckId)){
                                    //工序卡1
                                    WorkorderParamStepfour paramStepfour = template.getWorkorderStepList().get(stepNum).getWorkorderProcessList().get(processNum).getWorkorderItemCheckList().get(itemNum).getWorkorderParamStepfourList().get(paramNum);
                                    if (null != paramStepfour) {
                                        //第n行
                                        //int lineNum = (stepNum * processCount * itemCheckCount) + (itemCheckCount * itemNum) + itemNum;
                                        Row row = sheet.createRow((lineNum));
                                        //第n行第n列
                                        Cell process = row.createCell(0);
                                        process.setCellValue(processName);
                                        Cell itemCheck = row.createCell(1);
                                        itemCheck.setCellValue(itemCheckName);
                                        Cell specs = row.createCell(2);
                                        specs.setCellValue(paramStepfour.getSpecs());
                                        Cell param1 = row.createCell(3);
                                        param1.setCellValue(paramStepfour.getParam1());
                                        Cell param2 = row.createCell(4);
                                        param2.setCellValue(paramStepfour.getParam2());
                                        Cell param3 = row.createCell(5);
                                        param3.setCellValue(paramStepfour.getParam3());
                                        Cell param4 = row.createCell(6);
                                        param4.setCellValue(paramStepfour.getParam4());
                                        Cell param5 = row.createCell(7);
                                        param5.setCellValue(paramStepfour.getParam5());
                                        Cell param6 = row.createCell(8);
                                        param6.setCellValue(paramStepfour.getParam6());
                                        Cell param7 = row.createCell(9);
                                        param7.setCellValue(paramStepfour.getParam7());
                                        Cell param8 = row.createCell(10);
                                        param8.setCellValue(paramStepfour.getParam8());
                                        Cell param9 = row.createCell(11);
                                        param9.setCellValue(paramStepfour.getParam9());
                                        Cell param10 = row.createCell(12);
                                        param10.setCellValue(paramStepfour.getParam10());
                                        Cell operator = row.createCell(23);
                                        operator.setCellValue(paramStepfour.getOperator());
                                        lineNum++;
                                    } else {
                                        break;
                                    }

                                }
                            }

                        }
                    }
                }
                sheet.addMergedRegion(new CellRangeAddress(firstLine,firstLine+line,0,0));//合并单元格
                firstLine = firstLine+line+1;//改变下一个起始行位置
            }
        }
    }

    //获取数据
    public WorkorderTemplate getExportData(String templateId){
        //查询工单信息
        WorkorderTemplate workorderTemplate = workorderTemplateService
                .lambdaQuery()
                .eq(WorkorderTemplate::getId, templateId)
                .one();

        //查询工序卡信息
        List<WorkorderStep> stepList = workorderStepService
                .lambdaQuery()
                .list();

        //查询工序信息
        List<WorkorderProcess> processList = workorderProcessService
                .lambdaQuery()
                .list();

        //查询检查项目信息
        List<WorkorderItemCheck> itemCheckList = workorderItemCheckService
                .lambdaQuery()
                .list();

        //根据工单id查询常规参数
        List<WorkorderGeneralStepone> GeneralSteponeList = workorderGeneralSteponeService
                .lambdaQuery()
                .eq(WorkorderGeneralStepone::getTemplateId, templateId)
                .list();
        List<WorkorderGeneralSteptwo> GeneralSteptwoList = workorderGeneralSteptwoService
                .lambdaQuery()
                .eq(WorkorderGeneralSteptwo::getTemplateId, templateId)
                .list();
        List<WorkorderGeneralStepthree> GeneralStepthreeList = workorderGeneralStepthreeService
                .lambdaQuery()
                .eq(WorkorderGeneralStepthree::getTemplateId, templateId)
                .list();
        List<WorkorderGeneralStepfour> GeneralStepfourList = workorderGeneralStepfourService
                .lambdaQuery()
                .eq(WorkorderGeneralStepfour::getTemplateId, templateId)
                .list();

        //根据工单id查询检查项目参数
        List<WorkorderParamStepone> paramSteponeList = workorderParamSteponeService
                .lambdaQuery()
                .eq(WorkorderParamStepone::getTemplateId, templateId)
                .list();
        List<WorkorderParamSteptwo> paramSteptwoList = workorderParamSteptwoService
                .lambdaQuery()
                .eq(WorkorderParamSteptwo::getTemplateId, templateId)
                .list();
        List<WorkorderParamStepthree> paramStepthreeList = workorderParamStepthreeService
                .lambdaQuery()
                .eq(WorkorderParamStepthree::getTemplateId, templateId)
                .list();
        List<WorkorderParamStepfour> paramStepfourList = workorderParamStepfourService
                .lambdaQuery()
                .eq(WorkorderParamStepfour::getTemplateId, templateId)
                .list();

        //一、将检查项目参数对象放入对应检查项目对象下
        for (WorkorderItemCheck workorderItemCheck : itemCheckList) {
            //工序卡1
            List<WorkorderParamStepone> workorderParamSteponeList = new ArrayList<>();
            for (WorkorderParamStepone workorderParamStepone : paramSteponeList) {
                if(workorderParamStepone.getProcessId().equals(workorderItemCheck.getId()) ){
                    workorderParamSteponeList.add(workorderParamStepone);
                }
            }
            workorderItemCheck.setWorkorderParamSteponeList(workorderParamSteponeList);

            //工序卡2
            List<WorkorderParamSteptwo> workorderParamSteptwoList = new ArrayList<>();
            for (WorkorderParamSteptwo workorderParamSteptwo : paramSteptwoList) {
                if(workorderParamSteptwo.getProcessId().equals(workorderItemCheck.getId())){
                    workorderParamSteptwoList.add(workorderParamSteptwo);
                }
            }
            workorderItemCheck.setWorkorderParamSteptwoList(workorderParamSteptwoList);

            //工序卡3
            List<WorkorderParamStepthree> workorderParamStepthreeList = new ArrayList<>();
            for (WorkorderParamStepthree workorderParamStepthree : paramStepthreeList) {
                if(workorderParamStepthree.getProcessId().equals(workorderItemCheck.getId())){
                    workorderParamStepthreeList.add(workorderParamStepthree);
                }
            }
            workorderItemCheck.setWorkorderParamStepthreeList(workorderParamStepthreeList);

            //工序卡4
            List<WorkorderParamStepfour> workorderParamStepfourList = new ArrayList<>();
            for (WorkorderParamStepfour workorderParamStepfour : paramStepfourList) {
                if(workorderParamStepfour.getProcessId().equals(workorderItemCheck.getId())){
                    workorderParamStepfourList.add(workorderParamStepfour);
                }
            }
            workorderItemCheck.setWorkorderParamStepfourList(workorderParamStepfourList);

        }

        //二、将检查项目对象放入对应工序流程对象下
        for (WorkorderProcess workorderProcess : processList) {
            List<WorkorderItemCheck> workorderItemCheckList = new ArrayList<>();
            for (WorkorderItemCheck workorderItemCheck : itemCheckList) {
                if(workorderItemCheck.getProcessId().equals(workorderProcess.getId())){
                    workorderItemCheckList.add(workorderItemCheck);
                }
            }
            workorderProcess.setWorkorderItemCheckList(workorderItemCheckList);
        }

        //三、将工序流程对象放入对应工序卡对象下
        for (WorkorderStep workorderStep : stepList) {
            //工序参数
            List<WorkorderProcess> workorderProcessList = new ArrayList<>();
            for (WorkorderProcess workorderProcess : processList) {
                if (workorderProcess.getStepId().equals(workorderStep.getId())) {
                    workorderProcessList.add(workorderProcess);
                }
            }
            workorderStep.setWorkorderProcessList(workorderProcessList);

            //常规参数(待优化--冗余list)
            //工序卡1
            List<WorkorderGeneralStepone> workorderGeneralSteponeList = new ArrayList<>();
            for (WorkorderGeneralStepone generalStepone : GeneralSteponeList) {
                if (generalStepone.getStepId().equals(workorderStep.getId())) {
                    workorderGeneralSteponeList.add(generalStepone);
                }
            }
            workorderStep.setWorkorderGeneralSteponeList(workorderGeneralSteponeList);

            //工序卡2
            List<WorkorderGeneralSteptwo> workorderGeneralSteptwoList = new ArrayList<>();
            for (WorkorderGeneralSteptwo generalSteptwo : GeneralSteptwoList) {
                if (generalSteptwo.getStepId().equals(workorderStep.getId())) {
                    workorderGeneralSteptwoList.add(generalSteptwo);
                }
            }
            workorderStep.setWorkorderGeneralSteptwoList(workorderGeneralSteptwoList);

            //工序卡3
            List<WorkorderGeneralStepthree> workorderGeneralStepthreeList = new ArrayList<>();
            for (WorkorderGeneralStepthree generalStepthree : GeneralStepthreeList) {
                if (generalStepthree.getStepId().equals(workorderStep.getId())) {
                    workorderGeneralStepthreeList.add(generalStepthree);
                }
            }
            workorderStep.setWorkorderGeneralStepthreeList(workorderGeneralStepthreeList);

            //工序卡4
            List<WorkorderGeneralStepfour> workorderGeneralStepfourList = new ArrayList<>();
            for (WorkorderGeneralStepfour generalStepfour : GeneralStepfourList) {
                if (generalStepfour.getStepId().equals(workorderStep.getId())) {
                    workorderGeneralStepfourList.add(generalStepfour);
                }
            }
            workorderStep.setWorkorderGeneralStepfourList(workorderGeneralStepfourList);
        }

        //四、将工序卡对象放入对应工单对象下
        workorderTemplate.setWorkorderStepList(stepList);

        return workorderTemplate;
    }

}
