package com.kingdee.shr.customer.gtiit.rpt;


import com.cloudera.impala.jdbc4.internal.apache.log4j.Logger;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;

import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemCollection;
import com.kingdee.bos.metadata.entity.FilterItemInfo;

import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.sql.ParserException;

import com.kingdee.eas.framework.util.FilterUtility;
import com.kingdee.eas.util.app.DbUtil;
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.json.GridDataEntity;
import com.kingdee.shr.base.syssetting.ml.SHRWebResource;
import com.kingdee.shr.base.syssetting.sensitive.DataSensitiveEngineService;
import com.kingdee.shr.base.syssetting.sensitive.IDataSensitiveEngineService;
import com.kingdee.shr.base.syssetting.util.MetaDataUtil;
import com.kingdee.shr.base.syssetting.util.SysSettingSHRBaseItemUtil;

import com.kingdee.shr.base.syssetting.web.dynamic.util.ExportHelper;
import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.shr.base.syssetting.web.util.FastFilterUtil;
import com.kingdee.util.StringUtils;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/**人员花名册
 * description: PersonRosterAListHandler <br>
 * date: 2025/3/12 16:46 <br>
 * author: lhbj <br>
 * version: 1.0 <br>
 */
public class PersonRosterAListHandler extends ListHandler {
    private static Logger logger = Logger.getLogger("com.kingdee.shr.customer.gtiit.rpt.PersonRosterAListHandler");

    protected Object getParameter(HttpServletRequest request, String key) {
        Object value = request.getAttribute(key);
        if (null == value) {
            value = request.getParameter(key);
        }
        return value;
    }

    /**
     * {
     *     "person": {
     *         "values": "",
     *         "isSaveToScheme": true,
     *         "dataType": "F7",
     *         "uipk": "com.kingdee.eas.basedata.person.app.Person.CMP",
     *         "dataItem": []
     *     },
     *     "personType": {
     *         "values": "",
     *         "isSaveToScheme": true,
     *         "dataType": "F7",
     *         "uipk": "com.kingdee.eas.hr.emp.emp_page.app.WorkerCategory.maintain.list",
     *         "dataItem": []
     *     },
     *     "status": {
     *         "values": "1",
     *         "isSaveToScheme": true,
     *         "dataType": "Enum",
     *         "enumSource": "status",
     *         "isCustomDefine": true,
     *         "enumOptionsType": "int"
     *     },
     *     "periodEmployment": {
     *         "values": {
     *             "startDate": "2025-03-01",
     *             "endDate": "2025-03-31",
     *             "selectDate": "custom"
     *         },
     *         "isSaveToScheme": true,
     *         "dataType": "Date",
     *         "dataItem": "custom",
     *         "queryDateType": ""
     *     },
     *     "periodResignation": {
     *         "values": {
     *             "startDate": "2025-03-01",
     *             "endDate": "2025-03-31",
     *             "selectDate": "custom"
     *         },
     *         "isSaveToScheme": true,
     *         "dataType": "Date",
     *         "dataItem": "custom",
     *         "queryDateType": ""
     *     },
     *     "deadline": {
     *         "values": "",
     *         "isSaveToScheme": true,
     *         "dataType": "Date",
     *         "queryDateType": ""
     *     }
     * }
     * @param request
     * @return
     * @throws SHRWebException
     */
    protected FilterInfo getFastFilter(HttpServletRequest request) throws SHRWebException {
        String fastFilterItems = request.getParameter("fastFilterItems");
        if (StringUtils.isEmpty(fastFilterItems)) {
            return SysSettingSHRBaseItemUtil.isSHRBaseItem(MetaDataUtil.getEntityObjectByEntityName(this.getUIViewInfo(request).getEntityName()).getBaseEntity()) ? this.getBaseItemFastFilter(request) : null;
        } else {
            Map map = JSONUtils.convertJsonToObject(SHRContext.getInstance().getContext(), fastFilterItems);
            Map<String,Object> deadline =  (Map<String, Object>) map.get("deadline");
            if (null != deadline.get("values")
                    && (!String.class.equals(deadline.get("values").getClass())
                    || !org.apache.commons.lang3.StringUtils.isEmpty(String.valueOf(deadline.get("values"))))){
                Map<String,Object> subMap = (Map<String, Object>) deadline.get("values");
                String date = String.valueOf(subMap.get("date"));
                //endDate<=date
                Map<String,Object> deadline1 = Maps.newHashMap();
                Map<String,Object> values1 = Maps.newHashMap();
                deadline1.put("isSaveToScheme",true);
                deadline1.put("dataType","Date");
                deadline1.put("queryDateType","");
                values1.put("endDate",date);
                deadline1.put("values",values1);
                //startDate>=date
                Map<String,Object> deadline2 = Maps.newHashMap();
                Map<String,Object> values2 = Maps.newHashMap();
                deadline2.put("isSaveToScheme",true);
                deadline2.put("dataType","Date");
                deadline2.put("queryDateType","");
                values2.put("startDate",date);
                deadline2.put("values",values2);

                map.put("deadline1",deadline1);
                map.put("deadline2",deadline2);
            }
            map.remove("deadline");

            if (null != map && map.size() > 0) {
                FilterInfo filter = null;
                Iterator var5 = map.keySet().iterator();

                while(var5.hasNext()) {
                    Object key = var5.next();
                    if (map.get(key) instanceof Map) {
                        Map subMap = (Map)map.get(key);
                        request.setAttribute((String)key, subMap.get("values"));
                    }
                }
                if (SysSettingSHRBaseItemUtil.isSHRBaseItem(MetaDataUtil.getEntityObjectByEntityName(this.getUIViewInfo(request).getEntityName()).getBaseEntity())) {
                    filter = this.getBaseItemFastFilter(request);
                } else {
                    filter = FastFilterUtil.generateBizFastFilterInfo((JSONUtils.convertObjectToJson(SHRContext.getInstance().getContext(),map)));
                }
                return filter;
            } else {
                return SysSettingSHRBaseItemUtil.isSHRBaseItem(MetaDataUtil.getEntityObjectByEntityName(this.getUIViewInfo(request).getEntityName()).getBaseEntity()) ? this.getBaseItemFastFilter(request) : null;
            }
        }
    }


    /**
     * 数据查询
     *
     * @param request
     * @param response
     * @param modelMap
     * @return
     * @throws SHRWebException
     */
    protected GridDataEntity getGridRequestData(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        GridDataEntity gridDataEntity = new GridDataEntity();
        try {
            SHRContext shrContext = SHRContext.getInstance();
            Context ctx = shrContext.getContext();
            EntityViewInfo entityViewInfo = (EntityViewInfo) modelMap.get("DataGridEntityView");
            String columnModel = request.getParameter("columnModel");
            List<String> columnModels = Lists.newArrayList();
            columnModels.addAll(Arrays.asList(columnModel.split(",")));
            int rows = Integer.parseInt(this.getParameter(request, "rows").toString());
            int page = Integer.parseInt(this.getParameter(request, "page").toString());
            Map<String, Object> custom_params = (Map<String, Object>) request.getAttribute("custom_params");
            String clear = (String) custom_params.get("clear");
            String sorterItems = request.getParameter("sorterItems");
            if (!org.apache.commons.lang3.StringUtils.isEmpty(request.getParameter("sidx"))) {
                if (sorterItems != null && !"".equals(sorterItems)) {
                    String sordsidx = request.getParameter("sidx");
                    String tempSort = ("," + sorterItems).toLowerCase();
                    if (tempSort.contains("," + sordsidx.toLowerCase())) {
                        int startIndex = tempSort.indexOf("," + sordsidx.toLowerCase());
                        int endIndex = tempSort.indexOf(",", startIndex + 1);
                        if (endIndex < startIndex) {
                            endIndex = tempSort.length();
                        }
                        String repStr = tempSort.substring(startIndex, endIndex);
                        tempSort = tempSort.replace(repStr, "");
                        if (tempSort.replace(" ", "").length() > 0) {
                            sorterItems = tempSort.replaceFirst(",", request.getParameter("sidx") + " " + request.getParameter("sord") + ",");
                        } else {
                            sorterItems = request.getParameter("sidx") + " " + request.getParameter("sord");
                        }
                    } else {
                        sorterItems = request.getParameter("sidx") + " " + request.getParameter("sord") + "," + sorterItems;
                    }
                } else {
                    sorterItems = request.getParameter("sidx") + " " + request.getParameter("sord");
                }
            } else if (org.apache.commons.lang3.StringUtils.isEmpty(sorterItems)) {
                sorterItems = "pNumber desc";
            }

            String filterItems = (String) modelMap.get("filterItems");
            if (org.apache.commons.lang3.StringUtils.isEmpty(filterItems)) {
                filterItems = request.getParameter("filterItems");
            }

            String filter = (String) modelMap.get("filter");
            if (org.apache.commons.lang3.StringUtils.isEmpty(filter)) {
                filter = request.getParameter("filter");
            }

            FilterInfo filterInfo;
            if (filter != null && filter.length() > 0) {

                filterInfo = new FilterInfo(filter);
                if (FilterUtility.hasFilterItem(entityViewInfo.getFilter())) {
                    entityViewInfo.getFilter().mergeFilter(filterInfo, "AND");
                } else {
                    entityViewInfo.setFilter(new FilterInfo(filter));
                }

            }

            if (filterItems != null && filterItems.length() > 0) {

                filterInfo = new FilterInfo(filterItems);
                if (FilterUtility.hasFilterItem(entityViewInfo.getFilter())) {
                    entityViewInfo.getFilter().mergeFilter(filterInfo, "AND");
                } else {
                    entityViewInfo.setFilter(new FilterInfo(filterItems));
                }
            }
            boolean preEntry = true;
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
            System.out.println("entityViewInfo:" + entityViewInfo.getFilter().toSql());
            Long start = System.currentTimeMillis();
            StringBuilder sel = new StringBuilder();
            sel.append(" SELECT rownum as rownumber,temp.* from ( ");
            sel.append(" SELECT * from ( ");
            sel.append(" SELECT DISTINCT 'person' billType, ");
            sel.append(" person.fnumber as PersonNumber, ");
            sel.append(" person.CFSurname as LastName, ");
            sel.append(" person.CFMiddleNames as MiddleName, ");
            sel.append(" person.CFGivenName as FirstName, ");
            sel.append(" person.CFLocalName as LocalName, ");
            sel.append(" person.fname_l1 as DisplayName, ");
            sel.append(" c.fname_l1 as Department, ");
            sel.append(" c.fsimplename as Dept, ");
            sel.append(" e.fname_l1 as Job, ");
            //sel.append(" f.jobLevel as JobLevel, ");

            sel.append(" ( ");
            sel.append("  SELECT top 1  ");
            sel.append("   jg.FNAME_l1 as jobLevel ");
            sel.append("   FROM T_HR_EmpPostRank epr ");
            sel.append("   left join t_hr_jobgrade jg on epr.FJOBGRADEID = jg.FID    ");
            sel.append(" where epr.FPERSONID = person.fid ");
            sel.append(" and epr.feffdt <= b.eorLeffdt ");
            sel.append(" and epr.fleffdt >= b.eorEffdt ");
            sel.append(" order by epr.fleffdt desc ");
            sel.append(" ) JobLevel, ");

            sel.append(" d.CFLongname_l1 as Position, ");
            sel.append(" d.fnumber as PositionCode, ");
            sel.append(" personType.fname_l1 as WorkCategory, ");
            sel.append(" case ");
            sel.append("  when blx.fname_l1 is not null then blx.fname_l1 ");
            sel.append("  else lsx.fname_l1 ");
            sel.append(" end as PersonType, ");
            sel.append(" case ");
            sel.append("  when qzjz.fname_l1 is not null then qzjz.fname_l1 ");
            sel.append("  else lsqzjz.fname_l1 ");
            sel.append(" end as FullTimeorPartTime, ");
            sel.append(" j.fnumber as LineManager, ");
            sel.append(" j.fname_l1 as LineManagerName, ");
            sel.append(" to_char(b.eorEffdt, 'yyyy-MM-dd') as StartTime, ");
            sel.append(" to_char(b.eorLeffdt, 'yyyy-MM-dd') as EndTime, ");
            sel.append(" b.eorLeffdt as eorEndDate, ");
            sel.append(" to_char(b.FEnterDate, 'yyyy-MM-dd') as HireDate, ");
            sel.append(" b.FTryoutMonth as ProbationPeriod, ");
            sel.append(" 'months' as ProbationPeriodUnit, ");
            sel.append(" to_char(b.FPlanFormalDate, 'yyyy-MM-dd') as ProbationEndDate, ");
            sel.append(" l.FOfficePhone as WorkPhone, ");
            sel.append(" l.FMobile as CellPhone, ");
            sel.append(" l.FEmail as PrimaryEmail, ");
            sel.append(" l.CFPrivateemail as Email, ");
            sel.append(" m.fname_l1 as Nationality, ");
            sel.append(" to_char(v.FIssueDate, 'yyyy-MM-dd') as WorkPermitIssueDate, ");
            sel.append(" to_char(v.CFExpirationDate, 'yyyy-MM-dd') as WorkPermitExpirationDate, ");
            sel.append(" to_char(w.FIssueDate, 'yyyy-MM-dd') as ResidencePermitIssueDate, ");
            sel.append(" to_char(w.CFExpirationDate, 'yyyy-MM-dd') as ResidencePermitExpirationDate, ");
            sel.append(" case ");
            sel.append("  when person.FIDCardNO is not null then person.FIDCardNO ");
            sel.append("  when person.FPassportNO is not null then person.FPassportNO ");
            sel.append(" end as IDcardnoorPassportno, ");
            sel.append(" to_char(person.FIdCardBeginDate, 'yyyy-MM-dd') as IDcardcommencingdate, ");
            sel.append(" to_char(person.FIdCardEndDate, 'yyyy-MM-dd') as IDcardexpireddate, ");
            sel.append(" person.FIDCardAddress IDCardAddress, ");
            sel.append(" l.FWORKPLACE as CurrentAddress, ");
            sel.append(" to_char( ");
            sel.append("  case ");
            sel.append("   when person.FGender = 1 then 'male' ");
            sel.append("   when person.FGender = 2 then 'female' ");
            sel.append("   else '' ");
            sel.append("  end ");
            sel.append(" ) as Sex, ");
            sel.append(" to_char(person.FBirthday, 'yyyy-MM-dd') as BirthDate, ");
            sel.append(" mz.FName_L1 as Ethnicity, ");
            sel.append(" hj.FName_L1 as HukouType, ");
            sel.append(" to_char(person.cfhrd, 'yyyy-MM-dd') as HouseholdRegisteredDate, ");
            sel.append(" person.FNativePlace_L1 as Nativeplace, ");
            sel.append(" zm.FName_L1 as PoliticaStatus, ");
            sel.append(" hy.FName_L1 as MaritalStatus, ");
            sel.append(" l.FPostalcode as Zipcode, ");
            sel.append(" qrz.CFSchool as GraduatedSchoolofHighestAcademicDegree, ");
            sel.append(" qxl.FName_L1 as HighestAcademicDegree, ");
            sel.append(" qxw.FName_L1 as HighestQualificationOfFulltimeEducation, ");
            sel.append(" qrz.CFMajor as Majoroffulltimeeducation, ");
            sel.append(" qrz.CFGraduation as GraduatedDate, ");
            sel.append(" fqrz.CFSchool as GraduateSchoolofHighestDegreeofParttimeEducation, ");
            sel.append(" fqxl.FName_L1 as HighestDegreeofParttimeEducation, ");
            sel.append(" fqxw.FName_L1 as HighestQualificationofParttimeeducation, ");
            sel.append(" fqrz.CFMajor as MajorofParttimeeducation, ");
            sel.append(" l.FLinkName as emergencyContact, ");
            sel.append(" l.FLinkTelNum as telephoneofemergency, ");
            sel.append(" l.CFRelationship as relationship, ");
            //sel.append(" to_char(isnull(b.bizDate,rEntry2.bizDate), 'yyyy-MM-dd') as TerminationDate, ");
            sel.append(" case ");
            sel.append("  b.finservice ");
            sel.append("  when 1 then to_char((b.bizDate), 'yyyy-MM-dd') ");
            sel.append("  when 4 then to_char((b.bizDate), 'yyyy-MM-dd') ");
            sel.append("  else to_char(isnull(isnull(rEntry2.bizDate,b.bizDate),b.eorEffdt), 'yyyy-MM-dd')  ");
            sel.append(" end as TerminationDate, ");
            sel.append(" b.TerminationReason as TerminationReason, ");
            sel.append(" b.EmployeeType as EmployeeType, ");
            sel.append(" case ");
            sel.append("  b.finservice ");
            sel.append("  when 1 then 'active' ");
            sel.append("  when 4 then 'active' ");
            sel.append("  else 'inactive' ");
            sel.append(" end as InService, ");
            sel.append(" person.fid personId, ");
            sel.append(" personType.fId as personTypeId, ");
            sel.append(" b.FEnterDate as enterDate, ");

            sel.append(" case ");
            sel.append("  b.finservice ");
            sel.append("  when 1 then (b.bizDate) ");
            sel.append("  when 4 then (b.bizDate) ");
            sel.append("  else (isnull(isnull(rEntry2.bizDate,b.bizDate),b.eorEffdt))  ");
            sel.append(" end as leftDate, ");
//            sel.append("  isnull(pePos.fleftdate, { ts '2199-12-31' }) ");
//            sel.append("  as leftDate, ");
            sel.append(" (b.eorEffdt) as deadline1, ");
            sel.append(" (b.eorLeffdt) as deadline2, ");
//            sel.append(" b.fleffdt as deadline2, ");
//            sel.append(" b.feffdt as deadline1, ");
            sel.append(" case ");
            sel.append("  b.finservice ");
            sel.append("  when 1 then 1 ");
            sel.append("  when 4 then 1 ");
            sel.append("  else 2 ");
            sel.append(" end as \"status\", ");
            sel.append(" b.fid as id, ");
            sel.append(" b.flaborrelationstateid as laborrelationstateId ");
            sel.append("   FROM ( ");

            sel.append(" SELECT ehis.fid, ");
            sel.append(" ehis.feffdt, ");
            sel.append(" ehis.fleffdt, ");
            sel.append(" eor.feffdt as eorEffdt, ");
            sel.append(" isnull(rEntry.bizdate,eor.fleffdt) as eorLeffdt, ");
            sel.append(" rEntry.bizdate as bizdate, ");
            sel.append(" ehis.FPERSONID, ");
            sel.append(" eor.FAdminOrgID, ");
            sel.append(" eor.CFWorkercategoryID, ");
            sel.append(" eor.fpositionid, ");
            sel.append(" eor.CFLineManagerNameI, ");
            sel.append(" eor.CFFtorptID, ");
            sel.append(" eor.CFPersontypeID, ");
            sel.append(" ehis.FEnterDate, ");
            sel.append(" ehis.FTryoutMonth, ");
            sel.append(" ehis.FPlanFormalDate, ");
            sel.append(" '' TerminationReason, ");
            sel.append(" bt.fname_l1 EmployeeType, ");
            sel.append(" bt.finservice finservice, ");
            sel.append(" ehis.flaborrelationstateid ");
            sel.append(" from t_hr_emplaborrelationhis ehis ");
            sel.append(" left join T_HR_BDEmployeeType bt on bt.fid = ehis.flaborrelationstateid ");
            sel.append(" left join T_HR_EMPORGRELATION eor on eor.fpersonid = ehis.fpersonid ");
            sel.append(" and eor.feffdt >= ehis.feffdt ");
            sel.append(" and eor.fleffdt <= ehis.fleffdt ");

            sel.append(" left join ( ");
            sel.append("    select max(e.fbizdate) bizdate, e.fpersonid ");
            sel.append("    from T_HR_RESIGNBIZBILLENTRY e ");
            sel.append("    left join  T_HR_RESIGNBIZBILL b on e.fbillid=b.fid where b.FBILLSTATE = 3 ");
            sel.append("    group by e.fpersonid ) rEntry ");

            sel.append(" on rEntry.fpersonid = ehis.FPERSONID and eor.feffdt < rEntry.bizdate and eor.fleffdt='2199-12-31' ");
            sel.append(" where eor.fassigntype=1 ");
           // sel.append(" and ehis.fpersonid='Qn6sVXVHSoGPDxwLt7t3u4Dvfe0=' ");
            if (null != entityViewInfo && entityViewInfo.getFilter() != null) {
                boolean isREntry = true;
                FilterItemCollection fc = entityViewInfo.getFilter().getFilterItems();
                Integer status = 0;
                for (int i = 0; i < fc.size(); i++) {
                    FilterItemInfo itemInfo = fc.get(i);
                    if ("status".equals(itemInfo.getPropertyName())) {
                        HashSet<Integer> statusSet  = ((HashSet ) itemInfo.getCompareValue());
                        for(Integer iu:statusSet){
                            status=iu;
                        }
                        break;
                    }
                }

                for (int i = 0; i < fc.size(); i++) {
                    FilterItemInfo itemInfo = (FilterItemInfo) fc.get(i).clone();
                    if (itemInfo.getPropertyName().startsWith("deadline")) {
                        preEntry=false;
                    }
                }
//                String andSql = filterInfo1.toSql();
//                if (org.apache.commons.lang3.StringUtils.isNotBlank(andSql)) {
//                    andSql = andSql.replaceAll("deadline1", "eor.feffdt");
//                    andSql = andSql.replaceAll("deadline2", "eor.fleffdt");
//                    sel.append(" and " + andSql + " ");
//                }
                if(1==status){
                    sel.append(" and ehis.flaborrelationstateid in(select fid from T_HR_BDEmployeeType where finservice in(1,4)) ");
                }else  if(2==status){
                    sel.append(" and ehis.flaborrelationstateid not in(select fid from T_HR_BDEmployeeType where finservice in(1,4)) ");
                }
            }
            sel.append(" UNION all ");
            sel.append(" SELECT ehis.fid, ");
            sel.append(" ehis.feffdt, ");
            sel.append(" ehis.fleffdt, ");
            sel.append(" (rEntry.fbizdate + 1) as eorEffdt, ");
            sel.append(" ehis.fleffdt as eorLeffdt, ");
            sel.append(" rEntry.FBIZDATE as bizdate, ");
            sel.append(" ehis.FPERSONID, ");
            sel.append(" rEntry.fadminorgid, ");
            sel.append(" p.CFWorkercategoryID, ");
            sel.append(" '', ");
            sel.append(" rEntry.fpositionid, ");
            sel.append(" p.CFFtorptID, ");
            sel.append(" p.CFPersontypeID, ");
            sel.append(" ehis.FEnterDate, ");
            sel.append(" ehis.FTryoutMonth, ");
            sel.append(" ehis.FPlanFormalDate, ");
            sel.append(" isnull(rEntry.fdescription,vr.fname_l1) TerminationReason, ");
            sel.append(" bt.fname_l1 EmployeeType, ");
            sel.append(" bt.finservice finservice, ");
            sel.append(" rEntry.femptypeid ");
            sel.append(" from T_HR_RESIGNBIZBILLENTRY rEntry ");
            sel.append(" left join  T_HR_RESIGNBIZBILL rbill on rEntry.fbillid=rbill.fid ");
            sel.append(" left join T_HR_BDEmployeeType bt on bt.fid = rEntry.femptypeid ");
            sel.append(" left join T_HR_VariationReason vr on vr.fid = rEntry.fvariationreasonid ");
            sel.append(" left join t_hr_emplaborrelationhis ehis on rEntry.FPERSONID = ehis.fpersonid ");
            sel.append(" and rEntry.femptypeid!=ehis.flaborrelationstateid ");
            sel.append(" left join T_HR_EMPORGRELATION eor on eor.fpersonid = ehis.fpersonid ");
            sel.append(" and eor.feffdt >= ehis.feffdt ");
            sel.append(" and eor.fleffdt <= ehis.fleffdt ");
            sel.append(" left join t_bd_person p on p.fid = ehis.fpersonid ");
            sel.append(" where eor.fassigntype=1 ");
            sel.append(" and ehis.fleffdt='2199-12-31' ");
            sel.append(" and (rEntry.fbizdate+1) >= ehis.feffdt and rbill.FBILLSTATE = 3 ");
            sel.append(" ) b ");
            sel.append(" left join t_bd_person person on person.fid = b.FPERSONID ");

            sel.append(" left join ( ");
            sel.append("    select max(e.fbizdate) bizdate, e.fpersonid ");
            sel.append("    from T_HR_RESIGNBIZBILLENTRY e ");
            sel.append("    left join  T_HR_RESIGNBIZBILL b on e.fbillid=b.fid where b.FBILLSTATE = 3 ");
            sel.append("    group by e.fpersonid ) rEntry2 ");
            sel.append(" on rEntry2.fpersonid = person.fid ");

            sel.append(" left join T_HR_personPosition pePos on pePos.fpersonid = person.FID ");
            sel.append(" left join t_org_admin c on b.FAdminOrgID = c.FID ");
            sel.append(" left join t_org_position d on b.fpositionid = d.FID ");
            sel.append(" left join t_org_job e on d.FJOBID = e.fid ");
            sel.append(" left join CT_MP_WorkerCategory personType on b.CFWorkercategoryID = personType.fid ");
            sel.append(" left join CT_MP_Fullorpart h on person.CFFtorptID = h.fid ");
            sel.append(" left join T_HR_EmployeeClassify i on person.CFPersontypeID = i.FID ");
            sel.append(" left join t_bd_person j on b.CFLineManagerNameI = j.fid ");
            sel.append(" left join T_BD_HRFolk mz on mz.fid = person.FFOLKID ");
            sel.append(" left join T_BD_HRPolitical zm on zm.fid = person.FPoliticalFaceID ");
            sel.append(" left join T_BD_HRWed hy on hy.fid = person.FWedID ");
            sel.append(" left join T_BD_Regpermresidence hj on hj.fid = person.FREGRESIDENCEID ");
//            sel.append(" left join ( ");
//            sel.append("  SELECT epr.FPERSONID, ");
//            sel.append("   jg.FNAME_l1 as jobLevel, ");
//            sel.append("   epr.frankenddate,epr.feffdt,epr.fleffdt ");
//            sel.append("  FROM T_HR_EmpPostRank epr ");
//            sel.append("   left join t_hr_jobgrade jg on epr.FJOBGRADEID = jg.FID ");
//            sel.append(" ) f on person.fid = f.FPERSONID ");
//            sel.append(" and f.feffdt <= b.eorLeffdt ");
//            sel.append(" and f.fleffdt >= b.eorEffdt ");
            sel.append(" left join T_HR_PersonContactMethod l on person.fid = l.FPERSONID ");
            sel.append(" left join T_BD_Nationality m on person.FNationalityID = m.fid ");
            sel.append(" left join CT_MP_Fullperson qrz on qrz.FPersonID = person.fid ");
            sel.append(" left join T_BD_HRDiploma qxl on qrz.CFBackgroundID = qxl.fid ");
            sel.append(" left join T_BD_HRDegree qxw on qxw.fid = qrz.CFDegreeID ");
            sel.append(" left join CT_MP_Partperson fqrz on fqrz.FPersonID = person.fid ");
            sel.append(" left join T_BD_HRDiploma fqxl on fqrz.CFBackgroundID = fqxl.fid ");
            sel.append(" left join T_BD_HRDegree fqxw on fqxw.fid = fqrz.CFDegreeID ");
            sel.append(" left join ( ");
            sel.append("  select pct.FCredentialsTypeNO, ");
            sel.append("   pct.fid, ");
            sel.append("   pct.fpersonid ");
            sel.append("  from T_HR_PersonCredentialsType pct ");
            sel.append("   left join T_HR_CredentialsType ct on pct.FCredentialsTypeID = ct.fid ");
            sel.append("  where ct.FNUMBER = 'CN01' ");
            sel.append(" ) r on person.fid = r.fpersonid ");
            sel.append(" left join( ");
            sel.append("  SELECT pct.CFExpirationDate, ");
            sel.append("   pct.FCredentialsTypeNO, ");
            sel.append("   pct.fpersonid, ");
            sel.append("   pct.FIssueDate ");
            sel.append("  FROM T_HR_PersonCredentialsType pct ");
            sel.append("   INNER join( ");
            sel.append(" select max(pcta.CFExpirationDate) CFExpirationDate, ");
            sel.append("  pcta.fpersonid ");
            sel.append(" from T_HR_PersonCredentialsType pcta ");
            sel.append("  left join T_HR_CredentialsType ctb on pcta.FCredentialsTypeID = ctb.fid ");
            sel.append(" where ctb.FNUMBER = 'CWP' ");
            sel.append(" group by pcta.fpersonid ");
            sel.append("   ) pctMax on pct.fpersonid = pctMax.fpersonid ");
            sel.append("   and pct.CFExpirationDate = pctMax.CFExpirationDate ");
            sel.append("   inner join T_HR_CredentialsType ct on pct.FCredentialsTypeID = ct.fid ");
            sel.append("  where ct.FNUMBER = 'CWP' ");
            sel.append(" ) v on person.fid = v.FPersonID ");
            sel.append(" left join( ");
            sel.append("  SELECT pct.CFExpirationDate, ");
            sel.append("   pct.FCredentialsTypeNO, ");
            sel.append("   pct.fpersonid, ");
            sel.append("   pct.FIssueDate ");
            sel.append("  FROM T_HR_PersonCredentialsType pct ");
            sel.append("   INNER join( ");
            sel.append(" select max(pcta.CFExpirationDate) CFExpirationDate, ");
            sel.append("  pcta.fpersonid ");
            sel.append(" from T_HR_PersonCredentialsType pcta ");
            sel.append("  left join T_HR_CredentialsType b on pcta.FCredentialsTypeID = b.fid ");
            sel.append(" where b.FNUMBER = 'CFRP' ");
            sel.append(" group by pcta.fpersonid ");
            sel.append("   ) pctMax on pct.fpersonid = pctMax.fpersonid ");
            sel.append("   and pct.CFExpirationDate = pctMax.CFExpirationDate ");
            sel.append("   inner join T_HR_CredentialsType ct on pct.FCredentialsTypeID = ct.fid ");
            sel.append("  where ct.FNUMBER = 'CFRP' ");
            sel.append(" ) w on person.fid = w.FPersonID ");
            sel.append(" left join T_HR_EmployeeClassify blx on b.CFPersontypeID = blx.fid ");
            sel.append(" left join T_HR_EmployeeClassify lsx on lsx.fid = person.CFPersontypeID ");
            sel.append(" left join CT_MP_Fullorpart qzjz on b.CFFtorptID = qzjz.fid ");
            sel.append(" left join CT_MP_Fullorpart lsqzjz on lsqzjz.fid = person.CFFtorptID ");
            sel.append("  ) person ");
            if (null != entityViewInfo && entityViewInfo.getFilter() != null) {
                FilterInfo ffc= (FilterInfo) entityViewInfo.getFilter().clone();
                FilterItemCollection fc = ffc.getFilterItems();
//                for (int i = 0; i < fc.size(); i++) {
//                    FilterItemInfo itemInfo = fc.get(i);
//                    if ("deadline2".equals(itemInfo.getPropertyName())) {
//                        itemInfo.setCompareValue("1");
//                        itemInfo.setCompareType(CompareType.EQUALS);
//                        itemInfo.setPropertyName("1");
//                        preEntry=false;
//                    }
//                    if ("deadline1".equals(itemInfo.getPropertyName())) {
//                        itemInfo.setCompareValue("1");
//                        itemInfo.setCompareType(CompareType.EQUALS);
//                        itemInfo.setPropertyName("1");
//                        preEntry=false;
//                    }
//                }
                String andSql=ffc.toSql();
                if (org.apache.commons.lang3.StringUtils.isNotBlank(andSql)) {
                    andSql = andSql.replaceAll("personType.id", "personTypeId");
                    andSql = andSql.replaceAll("person.id", "personId");
                    andSql = andSql.replaceAll("periodEmployment", "enterDate");
                    andSql = andSql.replaceAll("periodResignation", "leftDate");
                    sel.append(" where " + andSql + " ");
                }
            }
//            if (null != entityViewInfo && entityViewInfo.getFilter() != null) {
//                FilterItemCollection fc = entityViewInfo.getFilter().getFilterItems();
//                FilterInfo fcf = new FilterInfo();
//                for (int i = 0; i < fc.size(); i++) {
//                    FilterItemInfo itemInfo = (FilterItemInfo) fc.get(i).clone();
//                    if ("deadline1".equals(itemInfo.getPropertyName())) {
//                        itemInfo.setCompareType(CompareType.GREATER_EQUALS);
//                        fcf.getFilterItems().add(itemInfo);
//                    }
//                }
//                String andSql=fcf.toSql();
//                if (org.apache.commons.lang3.StringUtils.isNotBlank(andSql)) {
//                    andSql = andSql.replaceAll("deadline1", "eorEndDate");
//                    sel.append(" and " + andSql + " ");
//                }
//            }
            sel.append(" UNION all ");
            //搜索“在职”：预入职人员都不出来，做了离职单的但是还没到离职日期的人需要搜索出来
            sel.append(" SELECT * ");
            sel.append(" from ( ");
            sel.append("   select 'preEntry' as billType, ");
            sel.append(" pEntry.cfempnumber as PersonNumber, ");
            sel.append(" pEntry.cfsurname_l1 as LastName, ");
            sel.append(" pEntry.cfmiddlenames_l1 as MiddleName, ");
            sel.append(" pEntry.cfgivenname_l1 as FirstName, ");
            sel.append(" pEntry.cflocalname_l1 as LocalName, ");
            sel.append(" pEntry.fname_l1 as DisplayName, ");
            sel.append(" c.fname_l1 as Department, ");
            sel.append(" c.fsimplename as Dept, ");
            sel.append(" e.fname_l1 as Job, ");
            sel.append(" jg.fname_l1 as JobLevel, ");
            sel.append(" d.CFLongname_l1 as Position, ");
            sel.append(" d.fnumber as PositionCode, ");
            sel.append(" personType.fname_l1 as WorkCategory, ");
            sel.append(" blx.fname_l1 as PersonType, ");
            sel.append(" lsqzjz.fname_l1 as FullTimeorPartTime, ");
            sel.append(" j.fnumber as LineManager, ");
            sel.append(" j.fname_l1 as LineManagerName, ");
            sel.append(" to_char(pEntry.fbizdate, 'yyyy-MM-dd') as StartTime, ");
            sel.append(" '2199-12-31' as EndTime, ");
            sel.append(" { ts '2199-12-31' } as eorEndDate, ");
            sel.append(" to_char(pEntry.fpreenterdate, 'yyyy-MM-dd') as HireDate, ");
            sel.append(" pEntry.cftrymonth as ProbationPeriod, ");
            sel.append(" 'months' as ProbationPeriodUnit, ");
            sel.append(" to_char(pEntry.cftransferdate, 'yyyy-MM-dd') as ProbationEndDate, ");
            sel.append(" l.FOfficePhone as WorkPhone, ");
            sel.append(" l.FMobile as CellPhone, ");
            sel.append(" l.FEmail as PrimaryEmail, ");
            sel.append(" l.CFPrivateemail as Email, ");
            sel.append(" m.fname_l1 as Nationality, ");
            sel.append(" to_char(v.FIssueDate, 'yyyy-MM-dd') as WorkPermitIssueDate, ");
            sel.append(" to_char(v.CFExpirationDate, 'yyyy-MM-dd') as WorkPermitExpirationDate, ");
            sel.append(" to_char(w.FIssueDate, 'yyyy-MM-dd') as ResidencePermitIssueDate, ");
            sel.append(" to_char(w.CFExpirationDate, 'yyyy-MM-dd') as ResidencePermitExpirationDate, ");
            sel.append(" case ");
            sel.append("  when person.FIDCardNO is not null then person.FIDCardNO ");
            sel.append("  when person.FPassportNO is not null then person.FPassportNO ");
            sel.append(" end as IDcardnoorPassportno, ");
            sel.append(" to_char(person.FIdCardBeginDate, 'yyyy-MM-dd') as IDcardcommencingdate, ");
            sel.append(" to_char(person.FIdCardEndDate, 'yyyy-MM-dd') as IDcardexpireddate, ");
            sel.append(" person.FIDCardAddress IDCardAddress, ");
            sel.append(" l.FWORKPLACE as CurrentAddress, ");
            sel.append(" to_char( ");
            sel.append("  case ");
            sel.append("   when person.FGender = 1 then 'male' ");
            sel.append("   when person.FGender = 2 then 'female' ");
            sel.append("   else '' ");
            sel.append("  end ");
            sel.append(" ) as Sex, ");
            sel.append(" to_char(person.FBirthday, 'yyyy-MM-dd') as BirthDate, ");
            sel.append(" mz.FName_L1 as Ethnicity, ");
            sel.append(" hj.FName_L1 as HukouType, ");
            sel.append(" to_char(person.cfhrd, 'yyyy-MM-dd') as HouseholdRegisteredDate, ");
            sel.append(" person.FNativePlace_L1 as Nativeplace, ");
            sel.append(" zm.FName_L1 as PoliticaStatus, ");
            sel.append(" hy.FName_L1 as MaritalStatus, ");
            sel.append(" l.FPostalcode as Zipcode, ");
            sel.append(" qrz.CFSchool as GraduatedSchoolofHighestAcademicDegree, ");
            sel.append(" qxl.FName_L1 as HighestAcademicDegree, ");
            sel.append(" qxw.FName_L1 as HighestQualificationOfFulltimeEducation, ");
            sel.append(" qrz.CFMajor as Majoroffulltimeeducation, ");
            sel.append(" qrz.CFGraduation as GraduatedDate, ");
            sel.append(" fqrz.CFSchool as GraduateSchoolofHighestDegreeofParttimeEducation, ");
            sel.append(" fqxl.FName_L1 as HighestDegreeofParttimeEducation, ");
            sel.append(" fqxw.FName_L1 as HighestQualificationofParttimeeducation, ");
            sel.append(" fqrz.CFMajor as MajorofParttimeeducation, ");
            sel.append(" l.FLinkName as emergencyContact, ");
            sel.append(" l.FLinkTelNum as telephoneofemergency, ");
            sel.append(" l.CFRelationship as relationship, ");
            sel.append(" '' as TerminationDate, ");
            sel.append(" '' as TerminationReason, ");
            sel.append(" bt.fname_l1 as EmployeeType, ");
            sel.append(" case ");
            sel.append("  bt.finservice ");
            sel.append("  when 1 then 'active' ");
            sel.append("  when 4 then 'active' ");
            sel.append("  else 'inactive' ");
            sel.append(" end as InService, ");
            sel.append(" person.fpersonid as personId, ");
            sel.append(" personType.fId as personTypeId, ");
            sel.append(" pEntry.fpreenterdate as enterDate, ");
            sel.append(" { ts '2199-12-31' } as leftDate, ");
            sel.append(" pEntry.fpreenterdate as deadline2, ");
            sel.append(" pEntry.fpreenterdate as deadline1, ");
           //没有截止日期时，只搜索“在职”：预入职人员都不出来
            //preEntry=true时表示没有截止日期
            if(preEntry) {
                sel.append(" 3 as \"status\", ");
            }else{
                sel.append(" case ");
                sel.append("  bt.finservice ");
                sel.append("  when 1 then 1 ");
                sel.append("  when 4 then 1 ");
                sel.append("  else 2 ");
                sel.append(" end as \"status\", ");
            }

            sel.append(" pEntry.fid as id, ");
            sel.append(" pEntry.cfemptypeid as laborrelationstateId ");
            sel.append("   from T_HR_PreEntry pEntry ");
            sel.append(" left join T_HR_PreEntryPerson person on person.fid = pEntry.ftalentid ");
            sel.append(" left join T_HR_BDEmployeeType bt on bt.fid = pEntry.cfemptypeid ");
            sel.append(" left join t_org_admin c on pEntry.fadminorgunitid = c.FID ");
            sel.append(" left join t_org_position d on pEntry.fpositionid = d.FID ");
            sel.append(" left join t_org_job e on d.FJOBID = e.fid ");
            sel.append(" left join CT_MP_WorkerCategory personType on pEntry.cfwcategoryid = personType.fid ");
            sel.append(" left join t_hr_jobgrade jg on pEntry.CFJOBGRADEID = jg.FID ");
            sel.append(" left join T_HR_EmployeeClassify blx on pEntry.CFPersontypeID = blx.fid ");
            sel.append(" left join CT_MP_Fullorpart lsqzjz on lsqzjz.fid = pEntry.cfftorptid ");
            sel.append(" left join t_bd_person j on pEntry.CFlmanagerID = j.fid ");
            sel.append(" left join T_HR_PEPersonContact l on l.ftalentid = pEntry.ftalentid ");
            sel.append(" left join T_BD_Nationality m on person.FNationalityID = m.fid ");
            sel.append(" left join( ");
            sel.append("  SELECT pct.CFExpirationDate, ");
            sel.append("   pct.FCredentialsTypeNO, ");
            sel.append("   pct.ftalentid, ");
            sel.append("   pct.FIssueDate ");
            sel.append("  FROM T_HR_PEPersonCredentialsType pct ");
            sel.append("   INNER join( ");
            sel.append(" select max(pcta.CFExpirationDate) CFExpirationDate, ");
            sel.append("  pcta.ftalentid ");
            sel.append(" from T_HR_PEPersonCredentialsType pcta ");
            sel.append("  left join T_HR_CredentialsType ctb on pcta.FCredentialsTypeID = ctb.fid ");
            sel.append(" where ctb.FNUMBER = 'CWP' ");
            sel.append(" group by pcta.ftalentid ");
            sel.append("   ) pctMax on pct.ftalentid = pctMax.ftalentid ");
            sel.append("   and pct.CFExpirationDate = pctMax.CFExpirationDate ");
            sel.append("   inner join T_HR_CredentialsType ct on pct.FCredentialsTypeID = ct.fid ");
            sel.append("  where ct.FNUMBER = 'CWP' ");
            sel.append(" ) v on person.fid = v.ftalentid ");
            sel.append(" left join( ");
            sel.append("  SELECT pct.CFExpirationDate, ");
            sel.append("   pct.FCredentialsTypeNO, ");
            sel.append("   pct.ftalentid, ");
            sel.append("   pct.FIssueDate ");
            sel.append("  FROM T_HR_PEPersonCredentialsType pct ");
            sel.append("   INNER join( ");
            sel.append(" select max(pcta.CFExpirationDate) CFExpirationDate, ");
            sel.append("  pcta.ftalentid ");
            sel.append(" from T_HR_PEPersonCredentialsType pcta ");
            sel.append("  left join T_HR_CredentialsType b on pcta.FCredentialsTypeID = b.fid ");
            sel.append(" where b.FNUMBER = 'CFRP' ");
            sel.append(" group by pcta.ftalentid ");
            sel.append("   ) pctMax on pct.ftalentid = pctMax.ftalentid ");
            sel.append("   and pct.CFExpirationDate = pctMax.CFExpirationDate ");
            sel.append("   inner join T_HR_CredentialsType ct on pct.FCredentialsTypeID = ct.fid ");
            sel.append("  where ct.FNUMBER = 'CFRP' ");
            sel.append(" ) w on person.fid = w.ftalentid ");
            sel.append(" left join T_BD_HRFolk mz on mz.fid = person.FFOLKID ");
            sel.append(" left join T_BD_HRPolitical zm on zm.fid = person.FPoliticalFaceID ");
            sel.append(" left join T_BD_HRWed hy on hy.fid = person.FWedID ");
            sel.append(" left join T_BD_Regpermresidence hj on hj.fid = person.FREGRESIDENCEID ");
            sel.append(" left join CT_MP_Fulleducation qrz on qrz.ftalentid = person.fid ");
            sel.append(" left join T_BD_HRDiploma qxl on qrz.CFBackgroundID = qxl.fid ");
            sel.append(" left join T_BD_HRDegree qxw on qxw.fid = qrz.CFDegreeID ");
            sel.append(" left join CT_MP_Parteducation fqrz on fqrz.ftalentid = person.fid ");
            sel.append(" left join T_BD_HRDiploma fqxl on fqrz.CFBackgroundID = fqxl.fid ");
            sel.append(" left join T_BD_HRDegree fqxw on fqxw.fid = fqrz.CFDegreeID ");
            sel.append("   where pEntry.fcheckinstate = 4 ");
            sel.append(" and pEntry.fbillstate = 3 ");
            sel.append("  ) preEntry ");

            if ((null != entityViewInfo) && (entityViewInfo.getFilter() != null)) {
                FilterItemCollection fc = entityViewInfo.getFilter().getFilterItems();
                for (int i = 0; i < fc.size(); i++) {
                    FilterItemInfo itemInfo = fc.get(i);
                    if ("deadline2".equals(itemInfo.getPropertyName())) {
                        itemInfo.setCompareValue("1");
                        itemInfo.setCompareType(CompareType.EQUALS);
                        itemInfo.setPropertyName("1");

                    }
                    if ("deadline1".equals(itemInfo.getPropertyName())) {
                        itemInfo.setCompareType(CompareType.LESS_EQUALS);

                    }

                }
                String andSql = entityViewInfo.getFilter().toSql();
                if (org.apache.commons.lang3.StringUtils.isNotBlank(andSql)) {
                    andSql = andSql.replaceAll("personType.id", "personTypeId");
                    andSql = andSql.replaceAll("person.id", "personId");
                    andSql = andSql.replaceAll("periodEmployment", "enterDate");
                    andSql = andSql.replaceAll("periodResignation", "leftDate");
                    sel.append(new StringBuilder().append(" where ").append(andSql).append(" ").toString());
                }
            }
//            if (null != entityViewInfo && entityViewInfo.getFilter() != null) {
//                String andSql=entityViewInfo.getFilter().toSql();
//                if (org.apache.commons.lang3.StringUtils.isNotBlank(andSql)) {
//                    andSql = andSql.replaceAll("personType.id", "personTypeId");
//                    andSql = andSql.replaceAll("person.id", "personId");
//                    andSql = andSql.replaceAll("periodEmployment", "enterDate");
//                    andSql = andSql.replaceAll("periodResignation", "leftDate");
//                    sel.append(" where " + andSql + " ");
//                }
//            }
            sel.append(" ) temp  ");
            sel.append(" order by " + sorterItems);
            //分页处理
            //获取总行数
            Long records = 0L;
            boolean isAll = Boolean.valueOf(request.getParameter("isAll"));
            if (!isAll) {
                StringBuffer countsb = new StringBuffer(sel);
                countsb.insert(0, "select count(1) records from ( ");
                countsb.append(") temp_row  ");
                int pageStart = ((Integer.valueOf(page) - 1) * Integer.valueOf(rows));
                int pageEnd = (pageStart + Integer.valueOf(rows));
                sel.insert(0, " select * from ( ");
                sel.append(" ) temp_row ");
                sel.append(" where rownumber > ").append(pageStart);
                sel.append(" and rownumber <= " + pageEnd);
                IRowSet countRs = DbUtil.executeQuery(ctx, countsb.toString());
                if (countRs.next()) {
                    records = countRs.getLong("records");
                }
                System.out.println("countsb:" + countsb.toString());
            }

            System.out.println("sqls:" + sel.toString());
            IRowSet rs = DbUtil.executeQuery(ctx, sel.toString());
            List<Map<String, Object>> rowList = Lists.newArrayList();
            while (rs.next()) {
                String pid = rs.getString("id");
                String billType = rs.getString("billType");
                Map<String, Object> row = Maps.newHashMap();
                //处理页面配置字段值
                for (int i = 0; i < columnModels.size(); i++) {
                    String key = columnModels.get(i);
                    row.put(key, rs.getString(key));
                }
                if (!StringUtils.isEmpty(billType)) {
                    row.put("billType", billType);
                }
                if (!StringUtils.isEmpty(pid)) {
                    row.put("id", pid);
                }
                rowList.add(row);
            }
            gridDataEntity.setRows(rowList);
            if (!isAll) {
                int total = 0;
                if (records % rows == 0) {
                    total = (int) (records / rows);
                } else {
                    total = (int) (records / rows + 1);
                }
                gridDataEntity.setTotal(total);
                gridDataEntity.setPage(page);
                gridDataEntity.setRecords(records);
            } else {
                gridDataEntity.setTotal(1);
                gridDataEntity.setPage(page);
                gridDataEntity.setRecords(rowList.size());
            }
            Map userData = Maps.newHashMap();
            userData.put("isExportAllToExcelCount", Boolean.valueOf(true));
            userData.put("rows", Integer.valueOf(rows));
            userData.put("page", Integer.valueOf(page));
            gridDataEntity.setUserdata(userData);
            Long end = System.currentTimeMillis();
            System.out.println(this.getClass().toString() + ":start-->" + start);
            System.out.println(this.getClass().toString() + ":end-->" + end);
            System.out.println(this.getClass().toString() + ":end-start-->" + (end - start));
        } catch (IllegalStateException var7) {
            if (!StringUtils.isEmpty(var7.getMessage()) && var7.getMessage().indexOf("Please process pk") > -1) {
                String message = var7.getMessage().replace("Please process pk", "").replace("at LocalBOSObjectFactory", "").replace("\\", ".");
                throw new ShrWebBizException(MessageFormat.format(SHRWebResource.getString("com.kingdee.shr.base.syssetting.SHRSyssettingResource", "metadata_not_exist"), message), var7);
            } else {
                throw var7;
            }
        } catch (BOSException var8) {
            logger.error(var8);
            throw new ShrWebBizException(var8);
        } catch (ParserException var9) {
            logger.error(var9);
            throw new ShrWebBizException(var9);
        } catch (SQLException throwables) {
            logger.error(throwables);
            throw new ShrWebBizException(throwables);
        }
        return gridDataEntity;
    }

    /**
     * 导出处理
     *
     * @param request
     * @param response
     * @param modelMap
     * @param helper
     * @param excelConfig
     * @throws SHRWebException
     */
    protected void exportAllToExcel(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap, ExportHelper helper, Map<String, Object> excelConfig) throws SHRWebException {
        long start = 0L;
        long end = 0L;
        List listData = null;
        if (logger.isDebugEnabled()) {
            start = System.currentTimeMillis();
        }
        Context ctx = SHRContext.getInstance().getContext();
        GridDataEntity gridDataEntity = this.getGridRequestData(request, response, modelMap);
        request.setAttribute("_userData_", gridDataEntity.getUserdata());
        this.doFieldPermFilter(gridDataEntity);
        if (logger.isDebugEnabled()) {
            end = System.currentTimeMillis();
            logger.debug(MessageFormat.format("handler: {0}, get list data, cost: {1}", this.getClass().getName(), end - start));
        }
        listData = gridDataEntity.getRows();
        this.afterGetExportData(request, response, listData);
        String isSensitive = request.getParameter("isSensitive");
        if ("true".equals(isSensitive)) {
            IDataSensitiveEngineService iDataSensitiveEngineService = new DataSensitiveEngineService(ctx);
            iDataSensitiveEngineService.convertSensitiveData(listData, this.getUipk(request));
        }
        helper.fillData0(excelConfig, listData);
        listData = null;
        gridDataEntity = null;
    }
}
