package com.kingdee.shr.compensation.web.handler.integrate;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.util.EASResource;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.exception.ShrWebBizException;
import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
import com.kingdee.shr.base.syssetting.sensitive.ShrSensitiveServiceUtil;
import com.kingdee.shr.base.syssetting.web.util.WebUtil;
import com.kingdee.shr.compensation.app.formula.common.FunctionTools;
import com.kingdee.shr.compensation.exception.CmpBasicException;
import com.kingdee.shr.compensation.util.BaseUtils;
import com.kingdee.shr.compensation.util.report.CmpReportHelper;
import com.kingdee.shr.compensation.util.report.CommonSQLUtil;
import com.kingdee.shr.compensation.util.report.DataCacheManager;
import com.kingdee.shr.compensation.util.report.FileConventHelper;
import com.kingdee.util.StringUtils;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode;
import org.apache.poi.poifs.crypt.Encryptor;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.streaming.SXSSFSheet;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.ui.ModelMap;

public class FileExportHelper {
    private static Logger logger = Logger.getLogger(FileExportHelper.class);
    private static final int MAX_COLUMN_COUNT = 200;


    public FileExportHelper() {
    }

    public String assembleExportDataSql(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String sql = session.getAttribute("exportDataSql").toString();
        return sql;
    }

    public String[] assembleQueryMode(HttpServletRequest request) throws SHRWebException {
        HttpSession session = request.getSession();
        List<Map<String, Object>> colModel = (List)session.getAttribute("colModel");
        return this.doAssembleQueryMode(request, colModel);
    }

    public String[] doAssembleQueryMode(HttpServletRequest request, List<Map<String, Object>> colModel) throws SHRWebException {
        String[] queryMode = new String[colModel.size()];
        Map<String, Object> col = null;
        long startTime = System.currentTimeMillis();
        Integer[] numberTypeItemPrefxArr = CmpReportHelper.getNumberTypeItemFieldSnArray(request);
        Map<String, Object> numberTypeCmpItemMap = DataCacheManager.getNumberTypeCmpItemMapInSession(request);
        int i = 0;

        for(int size = colModel.size(); i < size; ++i) {
            col = (Map)colModel.get(i);
            String index = col.get("index").toString();
            boolean hidden = false;
            if (col.get("hidden") != null) {
                hidden = Boolean.valueOf(col.get("hidden").toString());
            }

            String label = col.get("label") == null ? col.get("name").toString() : col.get("label").toString();
            StringBuffer buffer = new StringBuffer();
            buffer.append(index).append(",").append(hidden).append(",").append(label);
            String name = col.get("name").toString();
            boolean numItem = CmpReportHelper.isNumberTypeSN(numberTypeItemPrefxArr, name);
            buffer.append(",").append(numItem);
            String type;
            if (numItem) {
                type = name.toUpperCase(Locale.ENGLISH);
                type = type.contains(".") ? type.substring(type.indexOf(".") + 1) : type;
                int precision = Integer.valueOf(numberTypeCmpItemMap.get(type).toString());
                buffer.append(",").append(precision);
            } else {
                buffer.append(",").append(0);
            }

            type = col.containsKey("type") ? col.get("type").toString() : "String";
            if (!"IntEnum".equalsIgnoreCase(type) && !"StringEnum".equalsIgnoreCase(type) && !"Enum".equalsIgnoreCase(type)) {
                buffer.append(",").append(false);
            } else {
                buffer.append(",").append(true);
            }

            queryMode[i] = buffer.toString();
        }

        long endTime = System.currentTimeMillis();
        logger.info("assembleQueryMode cost time : " + (endTime - startTime));
        logger.info("export total count  " + queryMode.length);
        return queryMode;
    }

    public void checkMaxExportColumnCount(String[] queryMode) throws SHRWebException {
        if (queryMode.length > 200) {
            throw new ShrWebBizException(new CmpBasicException(CmpBasicException.EXPORTFAIL, new Object[]{200}));
        }
    }

    public String exportToExcel(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        String sql = this.assembleExportDataSql(request);
        IRowSet rowSet = CommonSQLUtil.executeQuery(sql);
        String[] queryMode = this.assembleQueryMode(request);
        List<Map<String, Object>> datas = this.transferRowSetToList(rowSet, queryMode);
        return this.doExportToExcel(request, response, datas, queryMode);
    }

    public String exportToExcel(HttpServletRequest request, HttpServletResponse response, String sql, String[] queryMode) throws SHRWebException {
        IRowSet rowSet = CommonSQLUtil.executeQuery(sql);
        List<Map<String, Object>> datas = this.transferRowSetToList(rowSet, queryMode);
        return this.doExportToExcel(request, response, datas, queryMode);
    }

    public String exportToPDF(HttpServletRequest request, HttpServletResponse response, String sql, String[] queryMode) throws SHRWebException, EASBizException, BOSException {
        Context ctx = SHRContext.getInstance().getContext();
        String psw = request.getParameter("psw");
        boolean isPswNeeded = ShrSensitiveServiceUtil.isExportInProtected(ctx, request);
        if (isPswNeeded && StringUtils.isEmpty(psw)) {
            throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "exportPrivteProtected", ctx));
        } else {
            IRowSet rowSet = CommonSQLUtil.executeQuery(sql);
            List<Map<String, Object>> datas = this.transferRowSetToList(rowSet, queryMode);
            return this.doExportToPDF(request, response, datas, queryMode);
        }
    }

    public String exportToPDF(HttpServletRequest request, HttpServletResponse response, List<Map<String, Object>> datas, String[] queryMode) throws SHRWebException, EASBizException, BOSException {
        Context ctx = SHRContext.getInstance().getContext();
        String psw = request.getParameter("psw");
        boolean isPswNeeded = ShrSensitiveServiceUtil.isExportInProtected(ctx, request);
        if (isPswNeeded && StringUtils.isEmpty(psw)) {
            throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "exportPrivteProtected", ctx));
        } else {
            return this.doExportToPDF(request, response, datas, queryMode);
        }
    }

    protected String doExportToPDF(HttpServletRequest request, HttpServletResponse response, List<Map<String, Object>> datas, String[] queryMode) throws ShrWebBizException {
        OutputStream os = null;
        BufferedInputStream in = null;
        FileOutputStream outputStream = null;

        try {
            long stime = System.currentTimeMillis();
            String title = this.assembleExprotTitile(request);
            String datetime = this.assembleExportDateTimeStr();
            String sheetTitle = title + "_" + datetime;
            SXSSFWorkbook wb = this.generateWorkBookData(datas, queryMode, sheetTitle, true);
            String dfileName = this.assembleExportFileName(request, sheetTitle);
            outputStream = FileConventHelper.getExcelFileOutputStream(dfileName);
            wb.write(outputStream);
            String pdfFileName = FileConventHelper.convertExcelToPdf(request, dfileName);
            os = response.getOutputStream();
            response.reset();
            response.setHeader("Content-Disposition", "attachment; filename=" + pdfFileName);
            response.setContentType("application/pdf");
            in = new BufferedInputStream(FileConventHelper.getPdfFileInputStream(dfileName));
            byte[] data = new byte[1024];

            int length;
            while((length = in.read(data)) != -1) {
                os.write(data, 0, length);
            }

            long etime = System.currentTimeMillis();
            logger.info(" do execute export pdf cost time: " + (etime - stime));
            return null;
        } catch (Exception var23) {
            throw new ShrWebBizException(var23.getMessage());
        } finally {
            BaseUtils.closeResource(new Closeable[]{outputStream, os, in});
        }
    }

    protected String assembleExprotTitile(HttpServletRequest request) {
        String title = request.getParameter("title");
        if (StringUtils.isEmpty(title)) {
            title = (String)request.getAttribute("title");
        }

        return title;
    }

    protected String doExportToExcel(HttpServletRequest request, HttpServletResponse response, List<Map<String, Object>> datas, String[] queryMode) throws SHRWebException {
        Context ctx = SHRContext.getInstance().getContext();
        String psw = request.getParameter("psw");

        boolean isPswNeeded;
        try {
            isPswNeeded = ShrSensitiveServiceUtil.isExportInProtected(ctx, request);
        } catch (EASBizException var377) {
            throw new ShrWebBizException(var377.getMessage(), var377);
        } catch (BOSException var378) {
            throw new SHRWebException(var378.getMessage(), var378);
        }

        if (isPswNeeded && StringUtils.isEmpty(psw)) {
            throw new ShrWebBizException(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "exportPrivteProtected", ctx));
        } else {
            long stime = System.currentTimeMillis();
            response.reset();
            response.setHeader("Content-disposition", "attachment; filename=" + this.getExportFileName(request));
            response.setContentType("application/msexcel");
            String sheetTitle = this.getSheetTitle(request);
            SXSSFWorkbook wb;
            Throwable var12;
            ServletOutputStream responseOutputStream;
            Throwable var14;
            EncryptionInfo info;
            if (StringUtils.isEmpty(psw)) {
                try {
                    wb = this.generateWorkBookData(datas, queryMode, sheetTitle, false);
                    var12 = null;

                    try {
                        responseOutputStream = response.getOutputStream();
                        var14 = null;

                        try {
                            wb.write(responseOutputStream);
                            long etime = System.currentTimeMillis();
                            logger.info("do execute export cost time: " + (etime - stime));
                            info = null;
                        } catch (Throwable var375) {
                            var14 = var375;
                            throw var375;
                        } finally {
                            if (responseOutputStream != null) {
                                if (var14 != null) {
                                    try {
                                        responseOutputStream.close();
                                    } catch (Throwable var368) {
                                        var14.addSuppressed(var368);
                                    }
                                } else {
                                    responseOutputStream.close();
                                }
                            }

                        }
                    } catch (Throwable var380) {
                        var12 = var380;
                        throw var380;
                    } finally {
                        if (wb != null) {
                            if (var12 != null) {
                                try {
                                    wb.close();
                                } catch (Throwable var366) {
                                    var12.addSuppressed(var366);
                                }
                            } else {
                                wb.close();
                            }
                        }

                    }

                    return null;
                } catch (SQLException | IOException var382) {
                    throw new SHRWebException(var382.getMessage(), var382);
                }
            } else {
                try {
                    wb = this.generateWorkBookData(datas, queryMode, sheetTitle, false);
                    var12 = null;

                    try {
                        responseOutputStream = response.getOutputStream();
                        var14 = null;

                        try {
                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                            Throwable var16 = null;

                            try {
                                wb.write(baos);
                                info = new EncryptionInfo(EncryptionMode.agile);
                                Encryptor encryptor = info.getEncryptor();
                                encryptor.confirmPassword(psw);
                                ByteArrayInputStream workbookInput = new ByteArrayInputStream(baos.toByteArray());
                                Throwable var20 = null;

                                try {
                                    OPCPackage opc = OPCPackage.open(workbookInput);
                                    Throwable var22 = null;

                                    try {
                                        POIFSFileSystem fs = new POIFSFileSystem();
                                        Throwable var24 = null;

                                        try {
                                            OutputStream encOs = encryptor.getDataStream(fs);
                                            Throwable var26 = null;

                                            try {
                                                opc.save(encOs);
                                            } catch (Throwable var376) {
                                                var26 = var376;
                                                throw var376;
                                            } finally {
                                                if (encOs != null) {
                                                    if (var26 != null) {
                                                        try {
                                                            encOs.close();
                                                        } catch (Throwable var374) {
                                                            var26.addSuppressed(var374);
                                                        }
                                                    } else {
                                                        encOs.close();
                                                    }
                                                }

                                            }

                                            fs.writeFilesystem(responseOutputStream);
                                        } catch (Throwable var384) {
                                            var24 = var384;
                                            throw var384;
                                        } finally {
                                            if (fs != null) {
                                                if (var24 != null) {
                                                    try {
                                                        fs.close();
                                                    } catch (Throwable var373) {
                                                        var24.addSuppressed(var373);
                                                    }
                                                } else {
                                                    fs.close();
                                                }
                                            }

                                        }
                                    } catch (Throwable var386) {
                                        var22 = var386;
                                        throw var386;
                                    } finally {
                                        if (opc != null) {
                                            if (var22 != null) {
                                                try {
                                                    opc.close();
                                                } catch (Throwable var372) {
                                                    var22.addSuppressed(var372);
                                                }
                                            } else {
                                                opc.close();
                                            }
                                        }

                                    }
                                } catch (Throwable var388) {
                                    var20 = var388;
                                    throw var388;
                                } finally {
                                    if (workbookInput != null) {
                                        if (var20 != null) {
                                            try {
                                                workbookInput.close();
                                            } catch (Throwable var371) {
                                                var20.addSuppressed(var371);
                                            }
                                        } else {
                                            workbookInput.close();
                                        }
                                    }

                                }
                            } catch (Throwable var390) {
                                var16 = var390;
                                throw var390;
                            } finally {
                                if (baos != null) {
                                    if (var16 != null) {
                                        try {
                                            baos.close();
                                        } catch (Throwable var370) {
                                            var16.addSuppressed(var370);
                                        }
                                    } else {
                                        baos.close();
                                    }
                                }

                            }
                        } catch (Throwable var392) {
                            var14 = var392;
                            throw var392;
                        } finally {
                            if (responseOutputStream != null) {
                                if (var14 != null) {
                                    try {
                                        responseOutputStream.close();
                                    } catch (Throwable var369) {
                                        var14.addSuppressed(var369);
                                    }
                                } else {
                                    responseOutputStream.close();
                                }
                            }

                        }
                    } catch (Throwable var394) {
                        var12 = var394;
                        throw var394;
                    } finally {
                        if (wb != null) {
                            if (var12 != null) {
                                try {
                                    wb.close();
                                } catch (Throwable var367) {
                                    var12.addSuppressed(var367);
                                }
                            } else {
                                wb.close();
                            }
                        }

                    }
                } catch (Exception var396) {
                    throw new ShrWebBizException(var396.getMessage(), var396);
                }

                long etime = System.currentTimeMillis();
                logger.info(" do execute export cost time: " + (etime - stime));
                return null;
            }
        }
    }

    protected String getSheetTitle(HttpServletRequest request) {
        String title = this.assembleExprotTitile(request);
        String datetime = this.assembleExportDateTimeStr();
        return title + "_" + datetime;
    }

    protected String getExportFileName(HttpServletRequest request) throws SHRWebException {
        String sheetTitle = this.getSheetTitle(request);

        try {
            return this.assembleExportFileName(request, sheetTitle);
        } catch (UnsupportedEncodingException var4) {
            throw new SHRWebException(var4.getMessage(), var4);
        }
    }

    public List<Map<String, Object>> transferRowSetToList(IRowSet rowSet, String[] queryMode) throws SHRWebException {
        List<Map<String, Object>> datas = new ArrayList();
        if (rowSet != null && rowSet.size() >= 1 && queryMode != null && queryMode.length >= 1) {
            try {
                while(rowSet.next()) {
                    Map<String, Object> dataMap = new HashMap();

                    for(int i = 0; i < queryMode.length; ++i) {
                        String[] column = queryMode[i].split(",");
                        if (StringUtils.isEmpty(column[1]) || !Boolean.valueOf(column[1])) {
                            dataMap.put(column[0], rowSet.getObject(column[0]));
                        }
                    }

                    datas.add(dataMap);
                }

                return datas;
            } catch (SQLException var7) {
                throw new SHRWebException(var7.getMessage(), var7);
            }
        } else {
            return datas;
        }
    }

    protected SXSSFWorkbook generateWorkBookData(List<Map<String, Object>> datas, String[] queryMode, String sheetTitle, Boolean isPdf) throws SHRWebException, SQLException, IOException {
        if (datas == null) {
            datas = new ArrayList();
        }

        SXSSFWorkbook wb = new SXSSFWorkbook();
        CellStyle headCellStyle = wb.createCellStyle();
        Font fontStyle = wb.createFont();
        fontStyle.setFontName("Arial");
        fontStyle.setFontHeightInPoints((short)10);
        headCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
        headCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        headCellStyle.setBorderTop(BorderStyle.THIN);
        headCellStyle.setBorderLeft(BorderStyle.THIN);
        headCellStyle.setBorderBottom(BorderStyle.THIN);
        headCellStyle.setBorderRight(BorderStyle.THIN);
        headCellStyle.setFont(fontStyle);
        Row row = null;
        Cell cell = null;
        CellStyle cellStyleString = wb.createCellStyle();
        cellStyleString.setFont(fontStyle);
        Sheet sheet = wb.createSheet(sheetTitle);
        int hCol = 0;
        row = sheet.createRow(0);
        Set<String> dotNumSet = new HashSet();

        for(int i = 0; i < queryMode.length; ++i) {
            String[] column = queryMode[i].split(",");
            boolean isHidden = Boolean.valueOf(column[1]);
            if (!isHidden) {
                cell = row.createCell(hCol);
                cell.setCellValue(column[2]);
                cell.setCellStyle(headCellStyle);
                ++hCol;
            }

            dotNumSet.add(column[4]);
        }

        Map<String, CellStyle> cellStyleMap = this.getCellStyleByDotNumber(dotNumSet, wb, fontStyle);
        int rowIndex = 0;
        Map<String, Object> sumDataMap = new HashMap();
        int rowSetSize = ((List)datas).size();
        BaseUtils utils = new BaseUtils();
        Map<String, String> enumSourceMap = new HashMap();
        DataFormat format = wb.createDataFormat();
        Iterator var21 = ((List)datas).iterator();

        while(var21.hasNext()) {
            Map<String, Object> data = (Map)var21.next();
            row = sheet.createRow(rowIndex + 1);
            int colIndex = 0;

            for(int i = 0; i < queryMode.length; ++i) {
                String[] column = queryMode[i].split(",");
                boolean isHidden = Boolean.valueOf(column[1]);
                if (!isHidden) {
                    String colOne = column[0];
                    Object valueObj = data.get(colOne);
                    String value;
                    if (!Boolean.valueOf(column[5])) {
                        value = this.processCellValue(valueObj, column[3], column[4]);
                    } else if (enumSourceMap.containsKey(colOne)) {
                        String enumSource = (String)enumSourceMap.get(colOne);
                        Object obj = utils.getStructColumnsPupolateValueByType("002", colOne, valueObj, enumSource);
                        if (obj == null) {
                            value = null;
                        } else {
                            value = obj.toString();
                        }
                    } else {
                        Map<String, Map<String, Object>> structColumnsPupolateValue = utils.getStructColumnsPupolateValue("002", colOne, valueObj);
                        enumSourceMap.put(colOne, ((Map)structColumnsPupolateValue.get(colOne)).get("type").toString());
                        if (((Map)structColumnsPupolateValue.get(colOne)).get("value") == null) {
                            value = null;
                        } else {
                            value = ((Map)structColumnsPupolateValue.get(colOne)).get("value").toString();
                        }
                    }
                    
                    //start xiaoxin 开始时间、结束时间、休息开始时间、休息结束时间只显示时分
                    if(("startTime".equals(colOne) || "endTime".equals(colOne) || "restStartTime".equals(colOne) || "restEndTime".equals(colOne)) && valueObj instanceof Timestamp) {
                    	SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
                    	SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        try {
                        	value = dateFormat.format(timeFormat.parse(valueObj.toString()));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                    //end xiaoxin

                    boolean isNumType = Boolean.valueOf(column[3]);
                    cell = row.createCell(colIndex);
                    colOne = colOne.contains(".") ? colOne.substring(colOne.indexOf(".") + 1) : colOne;
                    if ((!colOne.toUpperCase(Locale.ENGLISH).startsWith("S") || !isNumType) && !colOne.equalsIgnoreCase("personCounts")) {
                        if (StringUtils.isEmpty(value)) {
                            cell.setCellType(CellType.BLANK);
                        } else {
                            cell.setCellValue(value);
                            cell.setCellStyle(cellStyleString);
                        }

                        cellStyleString.setDataFormat(format.getFormat("@"));
                    } else {
                        CellStyle cellStyleNumber = (CellStyle)cellStyleMap.get(column[4]);
                        cell.setCellStyle(cellStyleNumber);
                        if (null != value && !isPdf) {
                            cell.setCellValue(Double.valueOf(value));
                        } else {
                            cell.setCellValue(value);
                        }

                        if (sumDataMap.get(colOne) == null) {
                            sumDataMap.put(colOne, value);
                        } else {
                            Object tmp = sumDataMap.get(colOne);
                            BigDecimal tmpV = tmp == null ? BigDecimal.ZERO : new BigDecimal(tmp.toString());
                            if (!StringUtils.isEmpty(value)) {
                                sumDataMap.put(colOne, tmpV.add(new BigDecimal(value)));
                            }
                        }
                    }

                    ++colIndex;
                }
            }

            ++rowIndex;
            //this.addSumRowData(wb, sheet, rowIndex, queryMode, sumDataMap, rowSetSize, cellStyleMap, isPdf);
            if (rowIndex % 100 == 0) {
                ((SXSSFSheet)sheet).flushRows();
            }
        }

        return wb;
    }

    protected void addSumRowData(SXSSFWorkbook wb, Sheet sheet, int rowIndex, String[] queryMode, Map<String, Object> sumDataMap, int rowSetSize, Map<String, CellStyle> cellStyleMap, Boolean isPdf) {
    	if (rowSetSize == rowIndex) {
            Font fontStyle = wb.createFont();
            fontStyle.setFontName("Arial");
            fontStyle.setFontHeightInPoints((short)10);
            CellStyle cellStyleNumber = wb.createCellStyle();
            CellStyle cellStyleString = wb.createCellStyle();
            cellStyleString.setFont(fontStyle);
            String getSum = EASResource.getString("com.kingdee.shr.compensation.resource.CalPersonResource", "sumAll", SHRContext.getInstance().getContext().getLocale());
            int FIRSTCOLINDEX = 0;
            Row row = sheet.createRow(rowIndex + 1);
            int colIndex = 0;

            for(int i = 0; i < queryMode.length; ++i) {
                String[] column = queryMode[i].split(",");
                boolean isHidden = Boolean.valueOf(column[1]);
                if (!isHidden) {
                    String colOne = column[0];
                    boolean isNumType = Boolean.valueOf(column[3]);
                    Cell cell = row.createCell(colIndex);
                    colOne = colOne.contains(".") ? colOne.substring(colOne.indexOf(".") + 1) : colOne;
                    String value = this.processCellValue(sumDataMap.get(colOne), column[3], column[4]);
                    if (FIRSTCOLINDEX == colIndex) {
                        value = getSum;
                    }

                    if ((!colOne.toUpperCase(Locale.ENGLISH).startsWith("S") || !isNumType) && !colOne.equalsIgnoreCase("personCounts")) {
                        cell.setCellValue(value);
                        cell.setCellStyle(cellStyleString);
                    } else {
                        cellStyleNumber = (CellStyle)cellStyleMap.get(column[4]);
                        if (null != value && !isPdf) {
                            cell.setCellValue(Double.valueOf(value));
                        } else {
                            cell.setCellValue(value);
                        }

                        cell.setCellStyle(cellStyleNumber);
                    }

                    ++colIndex;
                }
            }
        }

    }

    protected String assembleExportFileName(HttpServletRequest request, String sheetTitle) throws UnsupportedEncodingException {
        String dfileName = "";
        dfileName = WebUtil.convertFileNameForDownload(request, sheetTitle) + ".xlsx";
        return dfileName;
    }

    protected String assembleExportDateTimeStr() {
        Date currdate = new Date();
        Calendar c = Calendar.getInstance();
        c.setTime(currdate);
        String datetime = c.get(1) + "" + (c.get(2) + 1) + "" + c.get(5) + "";
        return datetime;
    }

    protected String processCellValue(Object value, Object fieldType, Object precision) {
        boolean isNumType = Boolean.valueOf(fieldType.toString());
        if (isNumType) {
            if (null == value) {
                return (String)value;
            } else {
                int pre = Integer.parseInt(precision.toString());
                return value == null ? null : FunctionTools.getRound(pre, (new BigDecimal(value == null ? "0" : value.toString())).doubleValue());
            }
        } else {
            if (value instanceof Timestamp) {
                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

                try {
                    return dateFormat.format(dateFormat.parse(value.toString()));
                } catch (ParseException var7) {
                    var7.printStackTrace();
                }
            }

            return value == null ? null : value.toString();
        }
    }

    protected Map<String, CellStyle> getCellStyleByDotNumber(Set<String> dotNumSet, SXSSFWorkbook wb, Font fontStyle) {
        Map<String, CellStyle> map = new HashMap();
        DataFormat format = wb.createDataFormat();
        Iterator var6 = dotNumSet.iterator();

        while(true) {
            String value;
            CellStyle cellStyleNumber;
            boolean flag;
            do {
                if (!var6.hasNext()) {
                    return map;
                }

                value = (String)var6.next();
                cellStyleNumber = wb.createCellStyle();
                cellStyleNumber.setFont(fontStyle);
                flag = org.apache.commons.lang3.StringUtils.isNumeric(value);
            } while(!flag);

            int num = Integer.valueOf(value);
            if (num == 0) {
                cellStyleNumber.setDataFormat(format.getFormat("###0"));
            } else {
                StringBuilder builder = new StringBuilder("###0.");

                for(int i = 0; i < num; ++i) {
                    builder.append("0");
                }

                cellStyleNumber.setDataFormat(format.getFormat(builder.toString()));
            }

            map.put(value, cellStyleNumber);
        }
    }

    public String exportToExcel(HttpServletRequest request, HttpServletResponse response, List<Map<String, Object>> datas, String[] queryMode) throws SHRWebException {
        return this.doExportToExcel(request, response, datas, queryMode);
    }
}
