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

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;

import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.compensation.web.handler.CmpWorkFlowPersonalDetailHandler;

public class CmpWorkFlowPersonalDetailHandlerEx extends CmpWorkFlowPersonalDetailHandler{


	private static Logger logger = Logger.getLogger(CmpWorkFlowPersonalDetailHandler.class);
	@Override
	public String exportAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)
			throws Exception {
		try {
			logger.error("进入二开导出方法");
            request.setAttribute("title", this.getExportTitle(request));
            List<Map<String, Object>> colModel = this.getGirdColModel(request);
            FileExportHelper excel = new FileExportHelper();
            String exportSql = this.getExportSql(request);
            String[] queryMode = excel.doAssembleQueryMode(request, colModel);
            boolean isPdfExport = this.isPdfExport(request);
            if (isPdfExport) {
                excel.exportToPDF(request, response, exportSql, queryMode);
            } else {
                excel.exportToExcel(request, response, exportSql, queryMode);
            }
        } catch (Exception var9) {
            this.handleException(var9);
        }

        return null;
	}

	private List<Map<String, Object>> getGirdColModel(HttpServletRequest request) throws SHRWebException {
        HttpSession session = request.getSession();
        List<Map<String, Object>> colModel = (List)session.getAttribute(this.getModelCacheKey());
        if (null == colModel) {
            String cmpSchemeId = this.getCmpSchemeId(request);
            colModel = this.assembleModel(cmpSchemeId, request);
        }

        return colModel;
    }

	private String getModelCacheKey() throws SHRWebException {
        return this.getExprotSqlCacheKey() + "grid_model";
    }

	private String getExprotSqlCacheKey() throws SHRWebException {
        return this.getCacheKeyPrefix() + "export_sql";
    }

	private String getExportSql(HttpServletRequest request) throws SHRWebException {
        return this.getExportSqlCache(request);
    }

	private boolean isPdfExport(HttpServletRequest request) {
        String suffix = request.getParameter("suffix");
        return "pdf".equalsIgnoreCase(suffix);
    }
}
