package com.nantian.cloud.jljc.controller;

import org.apache.commons.lang.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nantian.cloud.jljc.entity.*;
import com.nantian.cloud.jljc.mapper.DictRegionMapper;
import com.nantian.cloud.jljc.service.DischargeEnergyProductMonthService;
import com.nantian.cloud.jljc.service.DischargeEnergyStockMonthService;
import com.nantian.cloud.jljc.service.UseEngergyService;
import com.nantian.cloud.jljc.tools.LpExcelUtil;
import com.nantian.cloud.jljc.vo.dischargeEnergy.DischargeEnergyStockMonthVo;
import com.nantian.cloud.jljc.vo.dischargeEnergy.DischargeEnergyStockVo;
import com.nantian.sc.cloud.common.core.util.R;
import com.nantian.sc.cloud.common.log.annotation.SysLog;
import com.nantian.sc.cloud.common.minio.service.MinioTemplate;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.xmlbeans.impl.piccolo.io.FileFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.*;

@CrossOrigin
@RestController
@AllArgsConstructor
@RequestMapping("/dischargeEnergyStockMonth")
public class DischargeEnergyStockMonthController {
    @Autowired
    private DischargeEnergyStockMonthService dischargeEnergyStockMonthService;

    @Autowired
    private DischargeEnergyProductMonthService dischargeEnergyProductMonthService;

    @Autowired
    private UseEngergyService useEngergyService;

    @Autowired
    private MinioTemplate minioTemplate;

    @Autowired
    private DictRegionMapper regionMapper;

    @PostMapping("/save")
    @SysLog("新增两高项目月报")
    public R save(@RequestBody String s) {
        return R.ok(dischargeEnergyStockMonthService.addStock(s, null, new ArrayList<>()));
    }


    @SysLog("批量新增两高项目月报(提取历史数据新增)")
    @ApiOperation(value = "批量新增两高项目月报(提取历史数据新增)", notes = "批量新增两高项目月报(提取历史数据新增)")
    @PostMapping("/renewBatch")
    public R saveOrUpdateBatch(@RequestBody String str) {
        return R.ok(dischargeEnergyStockMonthService.renewStockBatch(str));
    }

    //查询
    @GetMapping("/getStockProductIndex")
    @SysLog("查询两高项目月报")
    public R getStockProductIndex(Page page, DischargeEnergyStockMonth dischargeEnergyStock) {
        dischargeEnergyStock.setDelFlag("1");  //筛选未删除项
        IPage<DischargeEnergyStockMonth> monthVoIPage = new Page<>();
        ScUser u = SecurityUtils.getUser();
        String deptId = u.getDeptId().toString();
        if (("530000").equals(deptId)) {
            dischargeEnergyStock.setReportStatus("\"city\":\"1\"");
            monthVoIPage = dischargeEnergyStockMonthService.getStockProductIndex(page, dischargeEnergyStock);
            List<DischargeEnergyStockMonth> records = monthVoIPage.getRecords();
            records.forEach(dischargeEnergyStockMonthVo -> {
                Long id = dischargeEnergyStockMonthVo.getId();
                List<DischargeEnergyProductMonth> list = dischargeEnergyProductMonthService.list(new QueryWrapper<DischargeEnergyProductMonth>().eq("del_flag", "1")
                        .eq("item_id", id));
                dischargeEnergyStockMonthVo.setProduceList(list);
            });
            monthVoIPage.setRecords(records);
        } else if (("00").equals(deptId.substring(deptId.length() - 2))) {
            dischargeEnergyStock.setReportStatus("\"country\":\"1\"");
            monthVoIPage = dischargeEnergyStockMonthService.getStockProductIndex(page, dischargeEnergyStock);
            List<DischargeEnergyStockMonth> records = monthVoIPage.getRecords();
            Comparator<DischargeEnergyStockMonth> reversed = Comparator.comparing(DischargeEnergyStockMonth::getAdminisFlag).reversed();
            Comparator<DischargeEnergyStockMonth> comparing = Comparator.comparing(DischargeEnergyStockMonth::getAuditorFlag);
            if (records.size() > 0) {
                records.sort(reversed.thenComparing(comparing));
            }
            records.forEach(dischargeEnergyStockMonthVo -> {
                Long id = dischargeEnergyStockMonthVo.getId();
                List<DischargeEnergyProductMonth> list = dischargeEnergyProductMonthService.list(new QueryWrapper<DischargeEnergyProductMonth>().eq("del_flag", "1")
                        .eq("item_id", id));
                dischargeEnergyStockMonthVo.setProduceList(list);
            });
            monthVoIPage.setRecords(records);
        } else {
            monthVoIPage = dischargeEnergyStockMonthService.getStockProductIndex(page, dischargeEnergyStock);
            List<DischargeEnergyStockMonth> records = monthVoIPage.getRecords();
            if (records.size() > 0) {
                records.sort(Comparator.comparing(DischargeEnergyStockMonth::getAuditorFlag));
            }
            records.forEach(dischargeEnergyStockMonthVo -> {
                Long id = dischargeEnergyStockMonthVo.getId();
                List<DischargeEnergyProductMonth> list = dischargeEnergyProductMonthService.list(new QueryWrapper<DischargeEnergyProductMonth>().eq("del_flag", "1")
                        .eq("item_id", id));
                dischargeEnergyStockMonthVo.setProduceList(list);
            });
            monthVoIPage.setRecords(records);
        }

        if (!"3".equals(dischargeEnergyStock.getItemType())) { //存量与在建项目需要判断项目转态是否改变
            List<DischargeEnergyStockMonth> list = monthVoIPage.getRecords();
            /*List<Map<String, String>> changes =dischargeEnergyStockMonthService.getChanges(dischargeEnergyStock);
            list.forEach(l ->{
                changes.forEach(c ->{
                    if ( !StringUtils.isEmpty(l.getItemName())
                            && l.getItemName().equals(c.get("itemName"))
                            && l.getYear().equals(c.get("year"))
                            && l.getQuarter().equals(c.get("quarter"))) {
                        l.setFlag("1");
                    }
                });

            });*/
            for (DischargeEnergyStockMonth item : list) {
                if (StringUtils.isNotBlank(item.getItemName())) { //项目名称不为空，判断是否为历史项目状态变更
                    DischargeEnergyStockMonth itemChange = dischargeEnergyStockMonthService.getItemChange(item);
                    if (itemChange != null) {
                        item.setFlag("1");
                    }
                }
            }
            monthVoIPage.setRecords(list);
        }

        return R.ok(monthVoIPage);
    }

    @ApiOperation(value = "获取汇总数据", notes = "获取汇总数据")
    @SysLog("查询两高项目月报汇总数据")
    @GetMapping("/getStockTotal")
    public R getStockTotal(DischargeEnergyStockMonth stockMonth) {
        return R.ok(dischargeEnergyStockMonthService.getStockTotal(stockMonth));
    }

    /**
     * 数据审核，审核通过后数据自动上报至省级部门
     *
     * @param dischargeEnergyStockMonth
     * @return
     */
    @PutMapping("/auditData")
    @SysLog("两高项目月报数据审核")
    public R auditData(@RequestBody String dischargeEnergyStockMonth) {
        JSONObject jsonObject = JSONObject.parseObject(dischargeEnergyStockMonth);
        String data = jsonObject.getString("auditorFlag");
        DischargeEnergyStockMonth s = JSONArray.parseObject(data, DischargeEnergyStockMonth.class);
        ScUser u = SecurityUtils.getUser();
        String deptId = u.getDeptId().toString();
        DischargeEnergyStockMonth info = dischargeEnergyStockMonthService.getById(s.getId());
        String auditUser = info.getAuditUser();
        JSONObject object = JSONObject.parseObject(auditUser);
        if (("530000").equals(deptId)) { //省级审核
            object.replace("province", u.getUserRealName());
            s.setAuditUser(JSONObject.toJSONString(object));
        } else if (deptId.substring(deptId.length() - 2).equals("00")) { //州市审核
            object.replace("city", u.getUserRealName());
            s.setAuditUser(JSONObject.toJSONString(object));
        } else {
            return R.failed("区县用户不能审核数据！");
        }
        s.setDelFlag("1");
        s.setUpdateTime(new Date());
        dischargeEnergyStockMonthService.updateById(s);
        return R.ok();
    }

    @PutMapping("/reportData")
    @SysLog("上报两高项目月报")
    public R reportData(@RequestBody String dischargeEnergyStockMonth) {
        JSONObject jsonObject = JSONObject.parseObject(dischargeEnergyStockMonth);
        String data = jsonObject.getString("dischargeEnergyStockMonth");
        List<DischargeEnergyStockMonth> s = (List<DischargeEnergyStockMonth>) JSONArray.parseArray(data, DischargeEnergyStockMonth.class);
        ScUser u = SecurityUtils.getUser();
        String deptId = u.getDeptId().toString();
        if (deptId.equals("530000")) {
            return R.failed("省级用户不需要进行数据上报操作！");
        } else if (deptId.substring(deptId.length() - 2).equals("00")) { //州市数据上报
            s.forEach(dischargeEnergyStockMonth1 -> {
                DischargeEnergyStockMonth info = dischargeEnergyStockMonthService.getById(dischargeEnergyStockMonth1.getId());
                String reportUser = info.getReportUser();
                String reportStatus = info.getReportStatus();
                JSONObject reportUserJson = JSONObject.parseObject(reportUser);
                JSONObject reportStatusJson = JSONObject.parseObject(reportStatus);
                reportUserJson.replace("city", u.getUserRealName());
                reportStatusJson.replace("city", "1");
                dischargeEnergyStockMonth1.setReportUser(JSONObject.toJSONString(reportUserJson));
                dischargeEnergyStockMonth1.setReportStatus(JSONObject.toJSONString(reportStatusJson));
            });
            dischargeEnergyStockMonthService.updateBatchById(s);
            return R.ok();
        } else { //区县数据上报
            s.forEach(dischargeEnergyStockMonth1 -> {
                DischargeEnergyStockMonth info = dischargeEnergyStockMonthService.getById(dischargeEnergyStockMonth1.getId());
                String reportUser = info.getReportUser();
                String reportStatus = info.getReportStatus();
                JSONObject reportUserJson = JSONObject.parseObject(reportUser);
                JSONObject reportStatusJson = JSONObject.parseObject(reportStatus);
                reportUserJson.replace("country", u.getUserRealName());
                reportStatusJson.replace("country", "1");
                dischargeEnergyStockMonth1.setReportUser(JSONObject.toJSONString(reportUserJson));
                dischargeEnergyStockMonth1.setReportStatus(JSONObject.toJSONString(reportStatusJson));
            });
            dischargeEnergyStockMonthService.updateBatchById(s);
            return R.ok();
        }
    }

    @GetMapping("/getById")
    @SysLog("通过id获取两高项目月报")
    public R getById(String id) {
        DischargeEnergyStockMonth byId = dischargeEnergyStockMonthService.getById(id);
        QueryWrapper<DischargeEnergyProductMonth> query = new QueryWrapper<>();
        query.eq("item_id", byId.getId());
        query.eq("del_flag", "1");
        List<DischargeEnergyProductMonth> list = dischargeEnergyProductMonthService.list(query);
        byId.setProduceList(list);
        byId.setItemLocationTmp(regionMapper.getAreaTmp(byId.getItemLocation()));
        return R.ok(byId);
    }


    @PostMapping("/del")
    @SysLog("删除两高项目月报")
    @ApiOperation(value = "删除两高项目", notes = "删除两高项目")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "int", paramType = "path")
    public R removeById(@RequestBody DischargeEnergyStockMonth dischargeEnergyStock) {
        return R.ok(dischargeEnergyStockMonthService.delStock(dischargeEnergyStock));
    }

    @PostMapping("/update")
    @SysLog("修改两高项目月报")
    public R update(@RequestBody String s) {
        return R.ok(dischargeEnergyStockMonthService.updateStock(s));
    }

    @ApiOperation(value = "下载模板", notes = "下载模板")
    @SysLog("下载两高项目月报模板")
    @RequestMapping(value = {"/template"}, produces = {"application/json;charset=UTF-8"})
    public void template(HttpServletRequest request, HttpServletResponse response, String type) {
        try {
            InputStream is = null;
            String name = null;
            if (Objects.equals("1", type)) {
                is = minioTemplate.getObject("jljc", "云南省存量“两高”清单模板.xlsx");
                name = "云南省存量“两高”清单模板.xlsx";
            }
            if (Objects.equals("2", type)) {
                is = minioTemplate.getObject("jljc", "云南省在建“两高”清单模板.xlsx");
                name = "云南省在建“两高”清单模板.xlsx";
            }
            if (Objects.equals("3", type)) {
                is = minioTemplate.getObject("jljc", "云南省拟建“两高”清单模板.xlsx");
                name = "云南省拟建“两高”清单模板.xlsx";
            }
            XSSFWorkbook xSSFWorkbook = new XSSFWorkbook(is);
            OutputStream output = response.getOutputStream(); // 读取的文件路径
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8"));
            response.setCharacterEncoding("UTF-8");
            response.setContentType("charset=GBK");
            xSSFWorkbook.write(output);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Excel数据导入
     *
     * @param file
     * @return
     * @throws
     */
    @RequestMapping("/excelImport")
    @SysLog("导入两高项目月报")
    @ApiOperation(value = "导入excel", notes = "导入excel")
    @ApiImplicitParam(name = "file", value = "文件", required = true, dataType = "file", paramType = "path")
    public R excelImport(@RequestParam MultipartFile file, String datel, String type) {
        try {
            /*if (file.getOriginalFilename().indexOf("xlsx")==-1){
                return R.failed("上传文件格式错误！需要为xlsx");
            }*/
            if (!(file.getOriginalFilename().endsWith("xlsx") || file.getOriginalFilename().endsWith("xls"))) {
                return R.failed("传入文件不是excel格式!");
            }
            List<DischargeEnergyStockMonth> list = dischargeEnergyStockMonthService.excelImport(file, type);
            if (list.size() == 1 && list.get(0).getItemName().contains("导入失败")) {
                return R.failed(list.get(0).getItemName());
            }
//            dischargeEnergyStockMonthService.saveBatch(list);
            list.forEach(item -> {
                ScUser u = SecurityUtils.getUser();
                item.setDeptId(u.getDeptId());
                item.setDelFlag("1");
                item.setYear(datel.split("-")[0]);
                item.setQuarter(Integer.parseInt(datel.split("-")[1]) + "");
                item.setItemType(type);
                item.setUpdateTime(new Date());
                Map<String, String> json = new HashMap<>();
                json.put("country", "");
                json.put("city", "");
                Map<String, String> jsonObject = new HashMap<>();
                jsonObject.put("city", "");
                jsonObject.put("province", "");
                if (u.getDeptId().toString().equals("530000")) {
                    item.setAdminisFlag("");
                    item.setReportUser(JSONObject.toJSONString(json));
                    json.replace("country", "1");
                    json.replace("city", "1");
                    item.setReportStatus(JSONObject.toJSONString(json));
                    item.setUpdateUser(JSONObject.toJSONString(jsonObject));
                    item.setAuditUser(JSONObject.toJSONString(jsonObject));
                    item.setCause(JSONObject.toJSONString(jsonObject));
                    jsonObject.replace("city", "1");
                    jsonObject.replace("province", "1");
                    item.setAuditorFlag(JSONObject.toJSONString(jsonObject));
                } else if (u.getDeptId().toString().substring(u.getDeptId().toString().length() - 2).equals("00")) {
                    item.setAdminisFlag("2");
                    item.setReportUser(JSONObject.toJSONString(json));
                    json.replace("country", "1");
                    json.replace("city", "0");
                    item.setReportStatus(JSONObject.toJSONString(json));
                    item.setUpdateUser(JSONObject.toJSONString(jsonObject));
                    item.setAuditUser(JSONObject.toJSONString(jsonObject));
                    item.setCause(JSONObject.toJSONString(jsonObject));
                    jsonObject.replace("city", "1");
                    jsonObject.replace("province", "0");
                    item.setAuditorFlag(JSONObject.toJSONString(jsonObject));
                } else {
                    item.setAdminisFlag("1");
                    item.setReportUser(JSONObject.toJSONString(json));
                    json.replace("country", "0");
                    json.replace("city", "0");
                    item.setReportStatus(JSONObject.toJSONString(json));
                    item.setUpdateUser(JSONObject.toJSONString(jsonObject));
                    item.setAuditUser(JSONObject.toJSONString(jsonObject));
                    item.setCause(JSONObject.toJSONString(jsonObject));
                    jsonObject.replace("city", "0");
                    jsonObject.replace("province", "0");
                    item.setAuditorFlag(JSONObject.toJSONString(jsonObject));
                }
                item.setUpdateUser(u.getUserRealName());
                dischargeEnergyStockMonthService.save(item);
                List<DischargeEnergyProductMonth> ps = item.getProduceList();
                ps.forEach(p -> {
                    p.setItemId(item.getId());
                    p.setDeptId(u.getDeptId());
                    p.setItemType(type);
                    p.setDelFlag("1");
                    if (!StringUtils.isEmpty(p.getProductName())) dischargeEnergyProductMonthService.save(p);
                });
                //dischargeEnergyProductMonthService.saveBatch(item.getProduceList());
            });
            return R.ok("导入成功");
        } catch (Exception e) {
            return R.failed("程序出错 " + e.getMessage(), "导入失败");
        }
    }

    @ApiOperation(value = "数据导出", notes = "数据导出")
    @SysLog("导出两高项目月报")
    @RequestMapping(value = {"/export"}, produces = {"application/json;charset=UTF-8"})
    public void export(HttpServletRequest request, HttpServletResponse response, String year, String month, String type) {
        try {
            QueryWrapper<DischargeEnergyStockMonth> query = new QueryWrapper<>();
            query.eq("year", year);
            query.eq("quarter", month);
            query.eq("del_flag", '1');
            query.eq("item_type", type);
//            query.like("area",area=="undefined"?"":area);

            ScUser u = SecurityUtils.getUser();
            String deptId = u.getDeptId().toString();
            if (deptId.equals("530000")) {
                query.like("report_status", "\"city\":\"1\"");
            } else if (deptId.contains("00")) {
                query.like("report_status", "\"country\":\"1\"");
                query.like("dept_id", deptId.substring(0,4));
            } else {
                query.like("dept_id", deptId);
            }

            List<DischargeEnergyStockMonth> list = dischargeEnergyStockMonthService.list(query);
//            // 子表
            if (list.size() != 0) {
                list.forEach(item -> {
                    QueryWrapper<DischargeEnergyProductMonth> query2 = new QueryWrapper<>();
                    query2.eq("item_id", item.getId());
                    query2.eq("del_flag", "1");
                    List<DischargeEnergyProductMonth> produces = dischargeEnergyProductMonthService.list(query2);
                    item.setProduceList(produces);
                });
            }
//            LpExcelUtil.StockExcel(response, list,type);
            writeExcel(response, list, type);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void writeExcel(HttpServletResponse response, List<DischargeEnergyStockMonth> data1, String type) throws Exception {
        InputStream is = minioTemplate.getObject("jljc", "云南省存量“两高”清单模板.xlsx");
        String name = null;
        if (Objects.equals("1", type)) {
            is = minioTemplate.getObject("jljc", "云南省存量“两高”清单导出模板.xlsx");
            name = "云南省存量“两高”清单.xlsx";
        }
        if (Objects.equals("2", type)) {
            is = minioTemplate.getObject("jljc", "云南省在建“两高”清单导出模板.xlsx");
            name = "云南省在建“两高”清单.xlsx";
        }
        if (Objects.equals("3", type)) {
            is = minioTemplate.getObject("jljc", "云南省拟建“两高”清单导出模板.xlsx");
            name = "云南省拟建“两高”清单.xlsx";
        }
        XSSFWorkbook xSSFWorkbook = null;
        XSSFSheet xSSFSheet = null;
        //组装合并单元格数据
        List<Integer> list1 = new ArrayList<Integer>();
        int pos = 0;
        for (int i = 0; i < data1.size(); i++) {
            for (int j = 0; j < data1.get(i).getProduceList().size(); j++) {
                if (j == 0) {
                    list1.add(data1.get(i).getProduceList().size());
                } else {
                    list1.add(0);
                }
            }
        }
        xSSFWorkbook = new XSSFWorkbook(is);
        //获取第一个sheet
        xSSFSheet = xSSFWorkbook.getSheetAt(0);
        XSSFFont font = xSSFWorkbook.createFont();
        XSSFFont font1 = xSSFWorkbook.createFont();
        CellStyle style = xSSFWorkbook.createCellStyle();
        CellStyle style1 = xSSFWorkbook.createCellStyle();
        font.setFontName("方正仿宋_GBK");
        font1.setFontName("Times New Roman");
        style.setFont(font);
        style1.setFont(font1);
        style.setWrapText(true);//自動換行
        style1.setWrapText(true);//自動換行
        style.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);//设置居中
        style.setAlignment(HorizontalAlignment.CENTER);
        style1.setVerticalAlignment(style.getVerticalAlignmentEnum().CENTER);//设置居中
        style1.setAlignment(HorizontalAlignment.CENTER);
        style.setBorderBottom(BorderStyle.THIN);//边框
        style.setBorderLeft(BorderStyle.THIN);
        style.setBorderRight(BorderStyle.THIN);
        style.setBorderTop(BorderStyle.THIN);
        style1.setBorderBottom(BorderStyle.THIN);
        style1.setBorderLeft(BorderStyle.THIN);
        style1.setBorderRight(BorderStyle.THIN);
        style1.setBorderTop(BorderStyle.THIN);

        //构建每行的数据内容
        int rowNum;
        int index = 0;
        if (type.equals("1")) {
            //存量
            rowNum = 6;
            for (DischargeEnergyStockMonth data : data1) {
                if (data == null) {
                    continue;
                }
                for (int i = 0; i < data.getProduceList().size(); i++) {
                    //输出行数据
                    Row row = xSSFSheet.createRow(rowNum++);
                    int cellNum = 0;
                    Cell cell;

                    if (list1.get(rowNum - 7) > 1) {
                        index = index + 1;
                        int a = (rowNum - 2 + list1.get(rowNum - 7));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 0, 0));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 1, 1));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 2, 2));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 3, 3));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 4, 4));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 5, 5));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 6, 6));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 7, 7));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 8, 8));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 9, 9));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 10, 10));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 11, 11));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 12, 12));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 13, 13));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 14, 14));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 15, 15));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 22, 22));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 23, 23));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 29, 29));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 30, 30));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 31, 31));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 32, 32));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 33, 33));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 35, 35));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 36, 36));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 37, 37));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 38, 38));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 39, 39));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 40, 40));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 41, 41));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 42, 42));

                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 组织机构代码
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getOrganizationCode() ? "" : data.getOrganizationCode());
                        cell.setCellStyle(style1);
                    } else if (list1.get(rowNum - 7) == 1) {
                        index = index + 1;
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 组织机构代码
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getOrganizationCode() ? "" : data.getOrganizationCode());
                        cell.setCellStyle(style1);
                    } else {
                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style1);

                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style1);
                    }
                    // 序号
//                cell.setCellValue(null == data.getIndex() ? "" : data.getIndex());
//                cell.setCellStyle(style1);
                    // 组织机构代码
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getOrganizationCode() ? "" : data.getOrganizationCode());
//                    cell.setCellStyle(style1);
                    //企业社会信用代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseCode() ? "" : data.getEnterpriseCode());
                    cell.setCellStyle(style1);
                    // 企业名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseName() ? "" : data.getEnterpriseName());
                    cell.setCellStyle(style);
//                    //项目名称
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getItemName() ? "" : data.getItemName());
//                    cell.setCellStyle(style);
                    // 所在州市
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
                    cell.setCellStyle(style);
                    // 产业类别
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryClassName() ? "" : data.getProduceList().get(i).getIndustryClassName());
                    cell.setCellStyle(style);
                    // 大类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryTypeCode() ? "" : data.getProduceList().get(i).getIndustryTypeCode());
                    cell.setCellStyle(style1);
                    // 小类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustrySubclassCode() ? "" : data.getProduceList().get(i).getIndustrySubclassCode());
                    cell.setCellStyle(style1);
                    //项目名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemName() ? "" : data.getItemName());
                    cell.setCellStyle(style);
                    // 企业运行状态
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseState() ? "" : data.getEnterpriseState());
                    cell.setCellStyle(style);
                    //节能审查机关及批复文号
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyOfficeAndNumber() ? "" : data.getEnergyOfficeAndNumber());
                    cell.setCellStyle(style);
//                    // 节能审查机关
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyOffice() ? "" : data.getEnergyOffice());
//                    cell.setCellStyle(style);
                    // 审查完成时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyTime() ? "" : data.getEnergyTime());
                    cell.setCellStyle(style);
//                    // 节能审查批复文号
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyNumber() ? "" : data.getEnergyNumber());
//                    cell.setCellStyle(style);
                    // 工业总产值(当年价)(万元)
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProductionTotal() ? "" : data.getProductionTotal());
                    cell.setCellStyle(style1);
                    // 是否存在原料用能（是/否）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyRaw() ? "" : data.getEnergyRaw());
                    cell.setCellStyle(style1);
//                    // 原料用能（万吨标准煤）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyRawValue() ? "" : data.getEnergyRawValue());
//                    cell.setCellStyle(style1);
                    // 原料用能消费量-实物量（万吨）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getActualQuantity() ? "" : data.getActualQuantity());
                    cell.setCellStyle(style1);
                    // 原料用能消费量-折标量（万吨标准煤）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getReducedScalar() ? "" : data.getReducedScalar());
                    cell.setCellStyle(style1);
                    // 产品
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductName() ? "" : data.getProduceList().get(i).getProductName());
                    cell.setCellStyle(style);
                    // 产品单耗指标名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndicatorName() ? "" : data.getProduceList().get(i).getIndicatorName());
                    cell.setCellStyle(style);
                    // 产品单耗指标单位
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductUnit() ? "" : data.getProduceList().get(i).getProductUnit());
                    cell.setCellStyle(style);
                    // 产品单耗指标
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductUnitConsumption() ? "" : data.getProduceList().get(i).getProductUnitConsumption());
                    cell.setCellStyle(style);
                    // 国家能耗限额标准
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getLimitStandard() ? "" : data.getProduceList().get(i).getLimitStandard());
                    cell.setCellStyle(style);
                    // 能效水平
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getEnergyEfficiencyLevel() ? "" : data.getProduceList().get(i).getEnergyEfficiencyLevel());
                    cell.setCellStyle(style);
                    // 产值能耗（吨标准煤/万元）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyOutputValue() ? "" : data.getEnergyOutputValue());
                    cell.setCellStyle(style1);
                    // 增加值能耗（吨标准煤/万元）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyAddedValue() ? "" : data.getEnergyAddedValue());
                    cell.setCellStyle(style1);
                    // 设计产能（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getCapacityDesign() ? "" : data.getProduceList().get(i).getCapacityDesign());
                    cell.setCellStyle(style1);
                    // 2021年实际产量（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput1() ? "" : data.getProduceList().get(i).getProductOutput1());
                    cell.setCellStyle(style1);
                    // 2022年实际产量（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput2() ? "" : data.getProduceList().get(i).getProductOutput2());
                    cell.setCellStyle(style1);
//                    // 2023年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput3() ? "" : data.getProduceList().get(i).getProductOutput3());
//                    cell.setCellStyle(style1);
//                    // 2024年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput4() ? "" : data.getProduceList().get(i).getProductOutput4());
//                    cell.setCellStyle(style1);
//                    // 2025年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput5() ? "" : data.getProduceList().get(i).getProductOutput5());
//                    cell.setCellStyle(style1);
                    //本年度本月产量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getThisMonthThisYear() ? "" : data.getProduceList().get(i).getThisMonthThisYear());
                    cell.setCellStyle(style1);
                    //本年度1-本月产量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getJanuaryToThisMonth() ? "" : data.getProduceList().get(i).getJanuaryToThisMonth());
                    cell.setCellStyle(style1);
                    //本年度本月综合能源消费量（万吨标准煤）-当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyThisMonth() ? "" : data.getEnergyThisMonth());
                    cell.setCellStyle(style1);
                    //本年度1－本月综合能源消费量（万吨标准煤）-当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyJanuaryToThisMonth() ? "" : data.getEnergyJanuaryToThisMonth());
                    cell.setCellStyle(style1);
                    //本年度本月耗电量（万千瓦时）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getElectricThisMonth() ? "" : data.getElectricThisMonth());
                    cell.setCellStyle(style1);
                    //本年度1-本月耗电量（万千瓦时）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getElectricJanuaryToThisMonth() ? "" : data.getElectricJanuaryToThisMonth());
                    cell.setCellStyle(style1);
                    //度电增加值(元)
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getElectricityPrice() ? "" : data.getElectricityPrice());
                    cell.setCellStyle(style1);
                    //本年度预计产量（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput() ? "" : data.getProduceList().get(i).getProductOutput());
                    cell.setCellStyle(style1);
                    // 2020年综合能源消费量当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDl() ? "" : data.getEnergyConsumptionLastTwoDl());
                    cell.setCellStyle(style1);
                    // 2020年综合能源消费量等价值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDj() ? "" : data.getEnergyConsumptionLastTwoDj());
                    cell.setCellStyle(style1);
                    // 2021年综合能源消费量当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionLastDl() ? "" : data.getEnergyConsumptionLastDl());
                    cell.setCellStyle(style1);
                    // 2021年综合能源消费量等价值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionLastDj() ? "" : data.getEnergyConsumptionLastDj());
                    cell.setCellStyle(style1);
                    // 2022年综合能源消费量当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionDl() ? "" : data.getEnergyConsumptionDl());
                    cell.setCellStyle(style1);
                    // 2022年综合能源消费量等价值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyConsumptionDj() ? "" : data.getEnergyConsumptionDj());
                    cell.setCellStyle(style1);
                    // 工业和信息化厅确认是/否属于高耗能项目
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getMinistryState() ? "" : data.getMinistryState());
                    cell.setCellStyle(style);
                    // 生态环境厅确认是/否属于高排放项目
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEcologyState() ? "" : data.getEcologyState());
                    cell.setCellStyle(style);
                    // 备注
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getRemark() ? "" : data.getProduceList().get(i).getRemark());
                    cell.setCellStyle(style);

                }
            }
        } else if (type.equals("2")) {
            //在建
            rowNum = 5;
            for (DischargeEnergyStockMonth data : data1) {
                if (data == null) {
                    continue;
                }
                for (int i = 0; i < data.getProduceList().size(); i++) {
                    //输出行数据
                    Row row = xSSFSheet.createRow(rowNum++);
                    int cellNum = 0;
                    Cell cell;
                    if (list1.get(rowNum - 6) > 1) {
                        index = index + 1;
                        int a = (rowNum - 2 + list1.get(rowNum - 6));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 0, 0));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 1, 1));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 2, 2));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 3, 3));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 4, 4));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 5, 5));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 6, 6));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 7, 7));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 8, 8));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 9, 9));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 10, 10));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 11, 11));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 12, 12));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 13, 13));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 14, 14));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 15, 15));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 16, 16));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 17, 17));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 18, 18));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 19, 19));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 22, 22));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 23, 23));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 24, 24));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 25, 25));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 27, 27));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 28, 28));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 29, 29));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 32, 32));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 33, 33));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 34, 34));
                        //xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 30, 30));
                        // 序号
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 所在州市
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
                        cell.setCellStyle(style);
                    } else if (list1.get(rowNum - 6) == 1) {
                        index = index + 1;
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 所在州市
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
                        cell.setCellStyle(style);
                    } else {
                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style1);

                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style);
                    }
                    // 所在州市
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
//                    cell.setCellStyle(style);
                    // 产业类别
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryClassName() ? "" : data.getProduceList().get(i).getIndustryClassName());
                    cell.setCellStyle(style);
                    // 大类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryTypeCode() ? "" : data.getProduceList().get(i).getIndustryTypeCode());
                    cell.setCellStyle(style1);
                    // 小类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustrySubclassCode() ? "" : data.getProduceList().get(i).getIndustrySubclassCode());
                    cell.setCellStyle(style1);
                    //项目名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemName() ? "" : data.getItemName());
                    cell.setCellStyle(style);
                    //统一社会信用代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseCode() ? "" : data.getEnterpriseCode());
                    cell.setCellStyle(style);
                    // 企业名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseName() ? "" : data.getEnterpriseName());
                    cell.setCellStyle(style);
                    // 项目状态
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseState() ? "" : data.getEnterpriseState());
                    cell.setCellStyle(style);
                    //节能审查机关及批复文号
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyOfficeAndNumber() ? "" : data.getEnergyOfficeAndNumber());
                    cell.setCellStyle(style);
//                    // 节能审查机关
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyOffice() ? "" : data.getEnergyOffice());
//                    cell.setCellStyle(style);
                    // 审查完成时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyTime() ? "" : data.getEnergyTime());
                    cell.setCellStyle(style);
//                    // 节能审查批复文号
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyNumber() ? "" : data.getEnergyNumber());
//                    cell.setCellStyle(style);
                    // 工业总产值(当年价)(万元)
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProductionTotal() ? "" : data.getProductionTotal());
                    cell.setCellStyle(style1);
                    //开工时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getStartTime() ? "" : data.getStartTime());
                    cell.setCellStyle(style1);
                    //投产时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProductionTime() ? "" : data.getProductionTime());
                    cell.setCellStyle(style1);
                    //项目总投资
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemInvest() ? "" : data.getItemInvest());
                    cell.setCellStyle(style1);
                    //已完成投资
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getCompletedInvestment() ? "" : data.getCompletedInvestment());
                    cell.setCellStyle(style1);
                    // 是否存在原料用能（是/否）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyRaw() ? "" : data.getEnergyRaw());
                    cell.setCellStyle(style1);
//                    // 原料用能（万吨标准煤）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyRawValue() ? "" : data.getEnergyRawValue());
//                    cell.setCellStyle(style1);
                    // 原料用能消费量-实物量（万吨）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getActualQuantity() ? "" : data.getActualQuantity());
                    cell.setCellStyle(style1);
                    // 原料用能消费量-折标量（万吨标准煤）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getReducedScalar() ? "" : data.getReducedScalar());
                    cell.setCellStyle(style1);
                    //“十四五”期间新增原料用能消费量（万吨标准煤）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getIncrement() ? "" : data.getIncrement());
                    cell.setCellStyle(style1);
                    // 产品
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductName() ? "" : data.getProduceList().get(i).getProductName());
                    cell.setCellStyle(style);
//                    // 产品单位
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductUnit() ? "" : data.getProduceList().get(i).getProductUnit());
//                    cell.setCellStyle(style);
                    // 设计产能（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getCapacityDesign() ? "" : data.getProduceList().get(i).getCapacityDesign());
                    cell.setCellStyle(style1);
//                    // 2021年实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput1() ? "" : data.getProduceList().get(i).getProductOutput1());
//                    cell.setCellStyle(style1);
//                    // 2022年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput2() ? "" : data.getProduceList().get(i).getProductOutput2());
//                    cell.setCellStyle(style1);
//                    // 2023年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput3() ? "" : data.getProduceList().get(i).getProductOutput3());
//                    cell.setCellStyle(style1);
//                    // 2024年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput4() ? "" : data.getProduceList().get(i).getProductOutput4());
//                    cell.setCellStyle(style1);
//                    // 2025年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput5() ? "" : data.getProduceList().get(i).getProductOutput5());
//                    cell.setCellStyle(style1);
//                    // 2020年综合能源消费量当量值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDl() ? "" : data.getEnergyConsumptionLastTwoDl());
//                    cell.setCellStyle(style1);
//                    // 2020年综合能源消费量等价值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDj() ? "" : data.getEnergyConsumptionLastTwoDj());
//                    cell.setCellStyle(style1);
//                    // 2021年综合能源消费量当量值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastDl() ? "" : data.getEnergyConsumptionLastDl());
//                    cell.setCellStyle(style1);
//                    // 2021年综合能源消费量等价值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastDj() ? "" : data.getEnergyConsumptionLastDj());
//                    cell.setCellStyle(style1);
                    //设计能耗当量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyDesignDl() ? "" : data.getEnergyDesignDl() + "");
                    cell.setCellStyle(style1);
                    //设计能耗等价
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyDesignDj() ? "" : data.getEnergyDesignDj() + "");
                    cell.setCellStyle(style1);
                    //新增能耗当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyNewPlanDl() ? "" : data.getEnergyNewPlanDl() + "");
                    cell.setCellStyle(style1);
                    //新增能耗等价值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyNewPlanDj() ? "" : data.getEnergyNewPlanDj() + "");
                    cell.setCellStyle(style1);
                    //单位产品能耗（千克标准煤/吨等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductEnergy() ? "" : data.getProduceList().get(i).getProductEnergy() + "");
                    cell.setCellStyle(style1);
                    //节能效果
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergySavingEffect() ? "" : data.getEnergySavingEffect());
                    cell.setCellStyle(style1);
                    //电力消耗量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyElectricity() ? "" : data.getEnergyElectricity());
                    cell.setCellStyle(style1);
                    //煤炭消耗量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyCoal() ? "" : data.getEnergyCoal());
                    cell.setCellStyle(style1);
                    //国家能耗限额标准
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getLimitStandard() ? "" : data.getProduceList().get(i).getLimitStandard());
                    cell.setCellStyle(style);
                    //能效水平
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getEnergyEfficiencyLevel() ? "" : data.getProduceList().get(i).getEnergyEfficiencyLevel());
                    cell.setCellStyle(style);
                    //环评审批机关及批复文号
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getDocumentNumber() ? "" : data.getDocumentNumber());
                    cell.setCellStyle(style);
                    //项目上马前期论证情况
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getPreviousSituation() ? "" : data.getPreviousSituation());
                    cell.setCellStyle(style);
                    //产能置换情况
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getCapacityReplacement() ? "" : data.getCapacityReplacement());
                    cell.setCellStyle(style);
                    // 备注
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getRemark() ? "" : data.getProduceList().get(i).getRemark());
                    cell.setCellStyle(style);

                }
            }
        } else if (type.equals("3")) {
            //拟建
            rowNum = 5;
            for (DischargeEnergyStockMonth data : data1) {
                if (data == null) {
                    continue;
                }
                for (int i = 0; i < data.getProduceList().size(); i++) {
                    //输出行数据
                    Row row = xSSFSheet.createRow(rowNum++);
                    int cellNum = 0;
                    Cell cell;
                    if (list1.get(rowNum - 6) > 1) {
                        index = index + 1;
                        int a = (rowNum - 2 + list1.get(rowNum - 6));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 0, 0));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 1, 1));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 2, 2));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 3, 3));
//                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 4, 4));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 5, 5));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 6, 6));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 7, 7));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 8, 8));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 9, 9));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 10, 10));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 11, 11));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 12, 12));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 13, 13));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 14, 14));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 15, 15));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 16, 16));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 17, 17));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 20, 20));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 21, 21));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 22, 22));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 23, 23));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 25, 25));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 26, 26));

                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 29, 29));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 30, 30));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 31, 31));
                        xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum - 1, a, 32, 32));
                        //xSSFSheet.addMergedRegion(new CellRangeAddress(rowNum-1, a, 30, 30));
                        // 序号
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 所在州市
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
                        cell.setCellStyle(style);
                    } else if (list1.get(rowNum - 6) == 1) {
                        index = index + 1;
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(index);
                        cell.setCellStyle(style1);

                        // 所在州市
                        cell = row.createCell(cellNum++);
                        cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
                        cell.setCellStyle(style);
                    } else {
                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style1);

                        cell = row.createCell(cellNum++);
                        cell.setCellStyle(style);
                    }
                    // 所在州市
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getItemLocation() ? "" : data.getItemLocation());
//                    cell.setCellStyle(style);
                    // 产业类别
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryClassName() ? "" : data.getProduceList().get(i).getIndustryClassName());
                    cell.setCellStyle(style);
                    // 大类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustryTypeCode() ? "" : data.getProduceList().get(i).getIndustryTypeCode());
                    cell.setCellStyle(style1);
                    // 小类代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getIndustrySubclassCode() ? "" : data.getProduceList().get(i).getIndustrySubclassCode());
                    cell.setCellStyle(style1);
                    //项目名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemName() ? "" : data.getItemName());
                    cell.setCellStyle(style);
                    // 统一社会信用代码
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseCode() ? "" : data.getEnterpriseCode());
                    cell.setCellStyle(style);
                    // 企业名称
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseName() ? "" : data.getEnterpriseName());
                    cell.setCellStyle(style);
                    // 项目状态
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnterpriseState() ? "" : data.getEnterpriseState());
                    cell.setCellStyle(style);
                    //节能审查机关及批复文号
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyOfficeAndNumber() ? "" : data.getEnergyOfficeAndNumber());
                    cell.setCellStyle(style);
//                    // 节能审查机关
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyOffice() ? "" : data.getEnergyOffice());
//                    cell.setCellStyle(style);
                    // 审查完成时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyTime() ? "" : data.getEnergyTime());
                    cell.setCellStyle(style);
//                    // 节能审查批复文号
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyNumber() ? "" : data.getEnergyNumber());
//                    cell.setCellStyle(style);
                    // 工业总产值(当年价)(万元)
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProductionTotal() ? "" : data.getProductionTotal());
                    cell.setCellStyle(style1);
                    //开工时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getStartTime() ? "" : data.getStartTime());
                    cell.setCellStyle(style1);
                    //投产时间
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProductionTime() ? "" : data.getProductionTime());
                    cell.setCellStyle(style1);
                    //项目总投资
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getItemInvest() ? "" : data.getItemInvest());
                    cell.setCellStyle(style1);
                    // 是否存在原料用能（是/否）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyRaw() ? "" : data.getEnergyRaw());
                    cell.setCellStyle(style1);
                    // 原料用能（万吨标准煤）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyRawValue() ? "" : data.getEnergyRawValue());
                    cell.setCellStyle(style1);
                    //“十四五”期间新增原料用能消费量（万吨标准煤）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getIncrement() ? "" : data.getIncrement());
                    cell.setCellStyle(style1);
                    // 产品
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductName() ? "" : data.getProduceList().get(i).getProductName());
                    cell.setCellStyle(style);
//                    // 产品单位
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductUnit() ? "" : data.getProduceList().get(i).getProductUnit());
//                    cell.setCellStyle(style);
                    // 设计产能（吨/千瓦时/重量箱等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getCapacityDesign() ? "" : data.getProduceList().get(i).getCapacityDesign());
                    cell.setCellStyle(style1);
//                    // 2021年实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput1() ? "" : data.getProduceList().get(i).getProductOutput1());
//                    cell.setCellStyle(style1);
//                    // 2022年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput2() ? "" : data.getProduceList().get(i).getProductOutput2());
//                    cell.setCellStyle(style1);
//                    // 2023年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput3() ? "" : data.getProduceList().get(i).getProductOutput3());
//                    cell.setCellStyle(style1);
//                    // 2024年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput4() ? "" : data.getProduceList().get(i).getProductOutput4());
//                    cell.setCellStyle(style1);
//                    // 2025年预计实际产量（吨/千瓦时/重量箱等）
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getProduceList().get(i).getProductOutput5() ? "" : data.getProduceList().get(i).getProductOutput5());
//                    cell.setCellStyle(style1);
//                    // 2020年综合能源消费量当量值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDl() ? "" : data.getEnergyConsumptionLastTwoDl());
//                    cell.setCellStyle(style1);
//                    // 2020年综合能源消费量等价值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastTwoDj() ? "" : data.getEnergyConsumptionLastTwoDj());
//                    cell.setCellStyle(style1);
//                    // 2021年综合能源消费量当量值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastDl() ? "" : data.getEnergyConsumptionLastDl());
//                    cell.setCellStyle(style1);
//                    // 2021年综合能源消费量等价值
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergyConsumptionLastDj() ? "" : data.getEnergyConsumptionLastDj());
//                    cell.setCellStyle(style1);
                    //设计能耗当量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyDesignDl() ? "" : data.getEnergyDesignDl() + "");
                    cell.setCellStyle(style1);
                    //设计能耗等价
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyDesignDj() ? "" : data.getEnergyDesignDj() + "");
                    cell.setCellStyle(style1);
                    //新增能耗当量值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyNewPlanDl() ? "" : data.getEnergyNewPlanDl() + "");
                    cell.setCellStyle(style1);
                    //新增能耗等价值
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyNewPlanDj() ? "" : data.getEnergyNewPlanDj() + "");
                    cell.setCellStyle(style1);
                    //单位产品能耗（千克标准煤/吨等）
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getProductEnergy() ? "" : data.getProduceList().get(i).getProductEnergy() + "");
                    cell.setCellStyle(style1);
//                    //节能效果
//                    cell = row.createCell(cellNum++);
//                    cell.setCellValue(null == data.getEnergySavingEffect() ? "" : data.getEnergySavingEffect());
//                    cell.setCellStyle(style1);
                    //电力消耗量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyElectricity() ? "" : data.getEnergyElectricity());
                    cell.setCellStyle(style1);
                    //煤炭消耗量
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getEnergyCoal() ? "" : data.getEnergyCoal());
                    cell.setCellStyle(style1);
                    //国家能耗限额标准
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getLimitStandard() ? "" : data.getProduceList().get(i).getLimitStandard());
                    cell.setCellStyle(style);
                    //能效水平
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getEnergyEfficiencyLevel() ? "" : data.getProduceList().get(i).getEnergyEfficiencyLevel());
                    cell.setCellStyle(style);
                    //项目是否位于大气污染防治重点区域内
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProjectLocated() ? "" : data.getProjectLocated());
                    cell.setCellStyle(style);
                    //环评审批机关及批复文号
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getDocumentNumber() ? "" : data.getDocumentNumber());
                    cell.setCellStyle(style);
                    //项目上马前期论证情况
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getPreviousSituation() ? "" : data.getPreviousSituation());
                    cell.setCellStyle(style);
                    //产能置换情况
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getCapacityReplacement() ? "" : data.getCapacityReplacement());
                    cell.setCellStyle(style);
                    // 备注
                    cell = row.createCell(cellNum++);
                    cell.setCellValue(null == data.getProduceList().get(i).getRemark() ? "" : data.getProduceList().get(i).getRemark());
                    cell.setCellStyle(style);

                }
            }
        }
        OutputStream output = response.getOutputStream(); // 读取的文件路径
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(name, "UTF-8"));
        response.setCharacterEncoding("UTF-8");
        response.setContentType("charset=GBK");
        xSSFWorkbook.write(output);
        output.close();
    }


    @GetMapping("/getSummaryTable1")
    @SysLog("获取汇总表1")
    public R getSummaryTable1(String year, String quarter) {
        return R.ok(dischargeEnergyStockMonthService.getSummaryTable1(year, quarter));
    }


    @GetMapping("/getSummaryTable1Excel")
    @SysLog("导出汇总表1")
    public R getSummaryTable1Excel(String year, String quarter, HttpServletResponse response) throws IOException {
//        try {
            List<String> code = new ArrayList<String>();
            code.add("25");
            code.add("26");
            code.add("30");
            code.add("31");
            code.add("32");
            code.add("44");
            List<List<Map<String, String>>> list = new ArrayList();
            List<Map<String, String>> summaryTable1 = dischargeEnergyStockMonthService.getSummaryTable1(year, quarter);
            List<Map<String, String>> summaryTableSum = dischargeEnergyStockMonthService.getSummaryTableSum(year, quarter);
            list.add(summaryTable1);
            list.add(summaryTableSum);
            code.forEach(r -> {
                List<Map<String, String>> data = dischargeEnergyStockMonthService.getSummaryTableData(year, quarter, r);
                list.add(data);
            });
            code.forEach(r -> {
                List<Map<String, String>> sum = dischargeEnergyStockMonthService.getSummaryTableDataSum(year, quarter, r);
                list.add(sum);
            });
            Table1Excel(response, list);
//        } catch (Exception e) {
//            System.out.println(e);
//        }
        return null;
    }

    @GetMapping("/getSummaryTable2Excel")
    @SysLog("导出汇总表2")
    public R getSummaryTable2Excel(String year, String quarter, HttpServletResponse response) throws IOException {
//        try {
            List<Map<String, String>> table = dischargeEnergyStockMonthService.getSummaryTable2(year, quarter);
            Table2Excel(response, table);
//        } catch (Exception e) {
//            System.out.println(e);
//        }
        return null;
    }

    private void Table1Excel(HttpServletResponse response, List<List<Map<String, String>>> list) throws IOException {
        InputStream is = minioTemplate.getObject("jljc", "全省“两高”行业能耗与经济指标.xlsx");
        XSSFWorkbook xSSFWorkbook = new XSSFWorkbook(is);
        XSSFSheet xSSFSheet = xSSFWorkbook.getSheetAt(0);
        if (xSSFSheet != null) {
            int i = 0;
            for (List<Map<String, String>> summaryTable1 : list) {
                int rowNum = 6;
                for (Map<String, String> data : summaryTable1) {
                    if (i == 0) { //16个地州存量企业数据
//                        String n1 =data.get("存量企业-2020年综合能源消费量当量值（万吨标准煤）");
                        if (data == null) {
                            continue;
                        }
                        //输出行数据
                        Row row = xSSFSheet.getRow(rowNum++);
                        XSSFCellStyle cellStyle = (XSSFCellStyle) row.getRowStyle();
                        row.setRowStyle(cellStyle);
                        int cellNum = 10;
                        Cell cell;
                        // 2020年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
//                        cell.setCellType(CellType.NUMERIC);
//                        cell.setCellValue(n1);
                        String str1 = String.valueOf(data.get("存量企业-2020年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2021年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2021年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2022年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2022年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2023年1-X月综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2023年1-X月综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2023年1-X月用电量（万千瓦时）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2023年1-X月用电量（万千瓦时）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("在建项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("拟建项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                    } else if (i == 1) {
                        if (data == null) {
                            continue;
                        }
                        //输出行数据
                        Row row = xSSFSheet.getRow(5);
                        XSSFCellStyle cellStyle = (XSSFCellStyle) row.getRowStyle();
                        row.setRowStyle(cellStyle);
                        int cellNum = 10;
                        Cell cell;
                        // 2020年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        String str1 = String.valueOf(data.get("存量企业-2020年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2021年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2021年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2022年综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2022年综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2023年1-X月综合能源消费量当量值（万吨标准煤）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2023年1-X月综合能源消费量当量值（万吨标准煤）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 存量企业-2023年1-X月用电量（万千瓦时）
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量企业-2023年1-X月用电量（万千瓦时）"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("存量项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("在建项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("拟建项目"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }

                    } else if (i > 1 && i < 8) { //16个地州两高行业数据
                        if (data == null) {
                            continue;
                        }
                        //输出行数据
                        Row row = xSSFSheet.getRow(rowNum++);
                        XSSFCellStyle cellStyle = (XSSFCellStyle) row.getRowStyle();
                        row.setRowStyle(cellStyle);
                        int cellNum = 18 + (i - 2) * 9;
                        Cell cell;
                        // 存量项目数量
                        cell = row.getCell(cellNum++);
                        String str1 = String.valueOf(data.get("存量项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-存量-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-存量-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 用电量（万千瓦时）-存量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("用电量（万千瓦时）-存量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 在建项目数量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("在建项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-在建-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-在建-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-在建-等价值
                        cell = row.getCell(cellNum++);
                        cell.setCellValue("");
                        // 拟建项目数量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("拟建项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-拟建-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-拟建-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-拟建-等价值
                        cell = row.getCell(cellNum++);
                        cell.setCellValue("");

                    } else { //云南省两高行业数据
                        if (data == null) {
                            continue;
                        }
                        //输出行数据
                        Row row = xSSFSheet.getRow(5);
                        XSSFCellStyle cellStyle = (XSSFCellStyle) row.getRowStyle();
                        row.setRowStyle(cellStyle);
                        int cellNum = 18 + (i - 8) * 9;
                        Cell cell;
                        // 存量项目数量
                        cell = row.getCell(cellNum++);
                        String str1 = String.valueOf(data.get("存量项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-存量-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-存量-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 用电量（万千瓦时）-存量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("用电量（万千瓦时）-存量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 在建项目数量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("在建项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-在建-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-在建-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-在建-等价值
                        cell = row.getCell(cellNum++);
                        cell.setCellValue("");
                        // 拟建项目数量
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("拟建项目数量"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-拟建-当量值
                        cell = row.getCell(cellNum++);
                        str1 = String.valueOf(data.get("能耗（万吨标准煤）-拟建-当量值"));
                        if(StringUtils.isNotBlank(str1)){
                            cell.setCellValue(Double.valueOf(str1));
                        }
                        // 能耗（万吨标准煤）-拟建-等价值
                        cell = row.getCell(cellNum++);
                        cell.setCellValue("");
                    }

//                XSSFCellStyle cellStyle = (XSSFCellStyle) row.getCell(cellNum++).getCellStyle();
//                cell.setCellStyle(cellStyle);

                }
                i++;

            }


            OutputStream output = response.getOutputStream(); // 读取的文件路径
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("全省“两高”行业能耗与经济指标.xlsx", "UTF-8"));
            response.setCharacterEncoding("UTF-8");
            response.setContentType("charset=GBK");
            xSSFWorkbook.write(output);
//            output.close();

        }

    }

    private void Table2Excel(HttpServletResponse response, List<Map<String, String>> list) throws IOException {
        InputStream is = minioTemplate.getObject("jljc", "全省六大高耗能行业能耗与经济指标.xlsx");
        XSSFWorkbook xSSFWorkbook = new XSSFWorkbook(is);
        XSSFSheet xSSFSheet = xSSFWorkbook.getSheetAt(0);
        if (xSSFSheet != null) {
            int rowNum = 6;
            for (Map<String, String> data : list) {
                if (data == null) {
                    continue;
                }
                //输出行数据
                Row row = xSSFSheet.getRow(rowNum++);
                XSSFCellStyle cellStyle = (XSSFCellStyle) row.getRowStyle();
                row.setRowStyle(cellStyle);
                int cellNum = 1;
                Cell cell;
                // 数量
                cell = row.getCell(cellNum++);
                String str1 = String.valueOf(data.get("数量"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 生产总值（亿元）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("生产总值（亿元）"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 同比增速（%）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("同比增速%"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 六大高耗能行业增加值占全省或规上工业增加值比重（%）
                cell = row.getCell(cellNum++);
                cell.setCellValue("");
                // 用电量（万千瓦时）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("用电量（万千瓦时）"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 六大高耗能行业用电量占全省或规上工业用电量比重（%）
                cell = row.getCell(cellNum++);
                cell.setCellValue("");
                // 用电量同比增速（%）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("用电量同比增速%"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 能源消费总量（万吨标准煤，等价值）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("1-x月能源消费总量（万吨标准煤，当量值）"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 六大高耗能行业能耗占全省或规上工业能耗比重（%）
                cell = row.getCell(cellNum++);
                cell.setCellValue("");
                // 能耗累计增速%
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("能耗累计增速%"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 环比增速（%）(单元格已隐藏)
                cell = row.getCell(cellNum++);
                cell.setCellValue("");
                // 能耗强度（吨标准煤/万元）
                cell = row.getCell(cellNum++);
                cell.setCellValue("");
                // 度电增加值（元）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("度电增加值（元）"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }
                // 度电产值（元/千瓦时）
                cell = row.getCell(cellNum++);
                str1 = String.valueOf(data.get("度电产值（元/千瓦时）"));
                if(StringUtils.isNotBlank(str1)){
                    cell.setCellValue(Double.valueOf(str1));
                }

            }
            OutputStream output = response.getOutputStream(); // 读取的文件路径
            response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("全省六大高耗能行业能耗与经济指标.xlsx", "UTF-8"));
            response.setCharacterEncoding("UTF-8");
            response.setContentType("charset=GBK");
            xSSFWorkbook.write(output);
//            output.close();

        }

    }
}
