//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

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

import com.google.common.collect.Maps;
import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.privacy.ParamData;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.bos.util.EASResource;
import com.kingdee.eas.basedata.assistant.CurrencyInfo;
import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.PositionInfo;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.permission.field.UserFieldPermInfoHelper;
import com.kingdee.shr.base.permission.field.form.ShrFieldPermForm;
import com.kingdee.shr.base.syssetting.app.filter.HRFilterUtils;
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.permission.data.ShrCheckDataPermissionUtil;
import com.kingdee.shr.base.syssetting.util.SHRPermissionWebUtils;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;
import com.kingdee.shr.base.syssetting.web.util.UrlParamEncryptHelper;
import com.kingdee.shr.compensation.CmpEmpORelationInfo;
import com.kingdee.shr.compensation.app.integrate.SubmitElementInfo;
import com.kingdee.shr.compensation.util.CmpStrUtil;
import com.kingdee.shr.compensation.util.SqlUtil;
import com.kingdee.shr.compensation.util.columnModel.CmpColumnModels;
import com.kingdee.shr.compensation.util.filter.CmpPermFilter;
import com.kingdee.shr.compensation.util.filter.CmpSchemeFilter;
import com.kingdee.shr.compensation.util.integrate.CmpIntegrateUtils;
import com.kingdee.shr.compensation.util.report.CommonSQLUtil;
import com.kingdee.shr.compensation.web.handler.CmpWorkFlowBaseHandler;
import com.kingdee.shr.compensation.web.handler.integrate.entry.BaseSubmitBillEntryGenerator;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;

public class BatchSubmitBillEntryGridHandler extends CmpWorkFlowBaseHandler {
    protected static Logger logger = Logger.getLogger(BatchSubmitBillEntryGridHandler.class);
    private String entityName = "com.kingdee.eas.basedata.org.app.Position";

    public BatchSubmitBillEntryGridHandler() {
    }

    public String getGridDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        return super.getGridDataAction(request, response, modelMap);
    }

    public Map<String, Object> getGridDataMap(HttpServletRequest request) throws SHRWebException {
        String[] dateFieldMap = new String[]{"enterDate"};
        String submitSchemeId = request.getParameter("submitSchemeId");
        String billId = request.getParameter("billId");
        String querySql = "";
        Object resultMap = Maps.newHashMap();

        try {
            resultMap = CmpIntegrateUtils.getBillColumnListAndQuerySql(this.ctx, submitSchemeId, billId);
        } catch (Exception var20) {
            logger.error("getBillColumnListAndQuerySql error: ", var20);
            this.handleException(var20);
        }

        try {
            querySql = ((Map)resultMap).get("querySql").toString();
            querySql = this.addPermSql(request, querySql);
        } catch (Exception var19) {
            logger.error("addPermSql error: ", var19);
            this.handleException(var19);
        }

        int totalCount = 0;
        IRowSet rowSet = null;

        Map gridDataMap;
        try {
            gridDataMap = this.doExecuteQuery(request, querySql);
            String sql = String.valueOf(gridDataMap.get("afterPagingSql"));
            ParamData param = (ParamData)gridDataMap.get("afterPagingHelperParamData");
            rowSet = SqlUtil.executeQuery(this.ctx, sql, param);
            totalCount = Integer.parseInt(String.valueOf(gridDataMap.get("totalCount")));
        } catch (Exception var18) {
            logger.error("getGridDataMap doExecuteQuery error: ", var18);
            this.handleException(var18);
        }

        try {
            gridDataMap = this.assembleGridData(request, (List)((Map)resultMap).get("colNames"), rowSet, totalCount);
            List<Map<String, Object>> rowDataList = (List)gridDataMap.get("rows");
            if (rowDataList != null && rowDataList.size() > 0) {
                for(int i = 0; i < rowDataList.size(); ++i) {
                    Map<String, Object> rowDataMap = (Map)rowDataList.get(i);
                    String[] var13 = dateFieldMap;
                    int var14 = dateFieldMap.length;

                    for(int var15 = 0; var15 < var14; ++var15) {
                        String keyItem = var13[var15];
                        if (rowDataMap.containsKey(keyItem)) {
                            String val = (String)rowDataMap.get(keyItem);
                            if (!StringUtils.isEmpty(val)) {
                                rowDataMap.put(keyItem, val.substring(0, 10));
                            }
                        }
                    }
                }
            }

            this.fieldPerm(this.ctx, rowDataList);
            return gridDataMap;
        } catch (Exception var21) {
            logger.error("getGridDataMap assembleGridData error: ", var21);
            this.handleException(var21);
            return null;
        }
    }

    protected void fieldPerm(Context ctx, List<Map<String, Object>> rowDataList) throws EASBizException, BOSException {
        Locale locale = ctx.getLocale();
        if (rowDataList != null && !rowDataList.isEmpty()) {
            String userId = HRFilterUtils.getCurrentUserId(ctx);
            Set<String> fieldPermSet = UserFieldPermInfoHelper.getUserEntityFields(ctx, userId, this.entityName);
            ShrFieldPermForm shrFieldPermForm = new ShrFieldPermForm(ctx, (SelectorItemCollection)null, this.entityName);
            if (fieldPermSet != null && fieldPermSet.size() >= 1) {
                for(int i = 0; i < rowDataList.size(); ++i) {
                    Map<String, Object> rowDataMap = (Map)rowDataList.get(i);
                    if (rowDataMap.containsKey("position")) {
                        Map<String, Object> permMap = new HashMap();
                        PositionInfo posInfo = (PositionInfo)rowDataMap.get("position");
                        Iterator var11 = fieldPermSet.iterator();

                        while(var11.hasNext()) {
                            String permField = (String)var11.next();
                            if (permField.contains("name")) {
                                permMap.put("name", posInfo.getName(locale));
                                if (!shrFieldPermForm.isAllowView(this.entityName, permField, permMap)) {
                                    posInfo.setName("***");
                                    rowDataMap.put("position", posInfo);
                                }
                            }
                        }
                    }
                }
            }
        }

    }

    protected void addEntryFastFilterItem(HttpServletRequest request, StringBuilder result) throws SHRWebException {
        String filterItems = request.getParameter("filterItems");
        if (!StringUtils.isEmpty(filterItems)) {
            filterItems = UrlParamEncryptHelper.decodeValue(filterItems);
            result.append(" and " + filterItems);
        }

    }

    public String addPermSql(HttpServletRequest request, String executeSql) throws SHRWebException {
        StringBuilder result = new StringBuilder(executeSql);
        this.addEntryFastFilterItem(request, result);
        if (this.checkIsShrWfButNoPermitemPermissionCtx(this.ctx, request)) {
            return result.toString();
        } 
        String uipk = request.getParameter("uipk");
        //员工自助提报单不根据后面的条件过滤
        if ("com.kingdee.shr.compensation.app.integrate.BatchSubmitShemeBillMySubmission.form".equals(uipk)) {
//            permItemId = HRFilterUtils.getCurrentPersonId(this.ctx);
//            result.append(" and fPersonId ='").append(permItemId).append("'");
            return result.toString();
        } 
        String permItemId = this.getCurrentRequestPermItemId(request);
        String hrOrgSql = CmpSchemeFilter.getHrOrgUnitRangeSQL(this.ctx, permItemId);
        String adminOrgSql = this.getAdminOrgSql(this.ctx, permItemId);
        result.append(" and (exists (");
        result.append(" select 1 from T_HR_SCmpEmpORelation cmpOrel where t.FCmpEmpORelationID = cmpOrel.fid ");
        result.append(" and (");
        result.append(" (t.FAdminOrgUnitID in (").append(adminOrgSql).append(") ");
        if (CmpStrUtil.isNotEmpty(hrOrgSql)) {
            result.append(" and t.FHrOrgUnitID in (").append(hrOrgSql).append(") ");
        }

        result.append(" )");
        if (CmpStrUtil.isNotEmpty(hrOrgSql)) {
            result.append(" or (t.FHrOrgUnitID in (").append(hrOrgSql).append(") and cmpOrel.FUseDefault = 0 ").append(") ");
        } else {
            result.append(" or (cmpOrel.FUseDefault = 0 ").append(") ");
        }

        result.append(" )) ");
        result.append(" or not exists (");
        result.append(" select 1 from T_HR_SCmpEmpORelation cmpOrel where t.FCmpEmpORelationID = cmpOrel.fid ");
        result.append(" ))");
        String permSql = CmpPermFilter.getCmpPersonPermFilter(this.ctx, "t.FHrOrgUnitID", "t.FPersonID", permItemId, true);
        if (CmpStrUtil.isNotEmpty(permSql)) {
            result.append(" and ").append(permSql);
        }
        return result.toString();
    }

    protected String getAdminOrgSql(Context ctx, String permItemId) {
        return CmpSchemeFilter.getAdminOrgUnitRangeSQL(ctx, permItemId);
    }

    public String getSumRowDataAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws SHRWebException {
        try {
            String submitSchemeId = request.getParameter("submitSchemeId");
            String billId = request.getParameter("billId");
            Map<String, Object> resultMap = CmpIntegrateUtils.getBillColumnListAndQuerySql(SHRContext.getInstance().getContext(), submitSchemeId, billId);
            String querySql = resultMap.get("querySql").toString();
            querySql = this.addPermSql(request, querySql);
            IRowSet rowSet = CommonSQLUtil.executeQuery(this.ctx, querySql);
            Map<String, Integer> columnMap = (HashMap)resultMap.get("columnMap");
            Map<String, String> sumItemMap = new HashMap();
            Set<String> columnList = columnMap.keySet();
            Object value = null;
            BigDecimal columnValue = null;
            if (columnList.size() > 0) {
                while(rowSet.next()) {
                    Iterator var14 = columnList.iterator();

                    while(var14.hasNext()) {
                        String columnName = (String)var14.next();
                        value = rowSet.getObject(columnName);
                        if (value instanceof BigDecimal) {
                            Integer dot = (Integer)columnMap.get(columnName);
                            if (dot != null) {
                                BigDecimal bigValue = (new BigDecimal(value.toString())).setScale(dot, RoundingMode.HALF_UP);
                                if (sumItemMap.get(columnName) != null) {
                                    columnValue = new BigDecimal((String)sumItemMap.get(columnName));
                                } else {
                                    columnValue = BigDecimal.ZERO;
                                }

                                sumItemMap.put(columnName, columnValue.add(bigValue).toString());
                            }
                        }
                    }
                }
            }

            JSONUtils.SUCCESS(sumItemMap);
        } catch (Exception var18) {
            var18.printStackTrace();
            this.handleException(var18);
        }

        return null;
    }

    public Map<String, Object> doExecuteQuery(HttpServletRequest request, String executeSql) throws SHRWebException {
        int rows = Integer.parseInt(request.getParameter("rows"));
        int page = Integer.parseInt(request.getParameter("page"));
        this.getSortData(request);
        String sord = request.getAttribute("sord").toString();
        String sidx = request.getAttribute("sidx").toString();
        return CommonSQLUtil.processGridDataPaging(this.ctx, executeSql, rows, page, sidx, sord);
    }

    public void getSortData(HttpServletRequest request) {
        String sidx = request.getParameter("sidx");
        String sord = request.getParameter("sord");
        if (StringUtils.isEmpty(sidx) || "orgUnit".equals(sidx) || "person".equals(sidx)) {
            sidx = "number,ADMORGNAME,POSITIONNAME";
        }

        if ("adminOrgUnit".equals(sidx)) {
            sidx = "ADMORGNAME";
        }

        if ("position".equals(sidx)) {
            sidx = "POSITIONNAME";
        }

        if (!"dealStatus".equals(sidx)) {
            sidx = "DEALSTATUS," + sidx;
        }

        request.setAttribute("sidx", sidx);
        request.setAttribute("sord", sord);
    }

    public String addSortSql(String sourceSql, HttpServletRequest request) {
        this.getSortData(request);
        String sidx = "";
        String sord = "";
        if (request.getAttribute("sidx") != null) {
            sidx = request.getAttribute("sidx").toString();
        }

        if (request.getAttribute("sord") != null) {
            sord = request.getAttribute("sord").toString();
        }

        String sorterItems = null;
        if (!StringUtils.isEmpty(sidx) && !"null".equals(sidx)) {
            StringBuilder buffer = new StringBuilder();
            String[] tempSidxs = sidx.split(",");
            String[] var8 = tempSidxs;
            int var9 = tempSidxs.length;

            for(int var10 = 0; var10 < var9; ++var10) {
                String tempSidx = var8[var10];
                tempSidx = tempSidx.trim();
                if (tempSidx.contains(" ")) {
                    String[] strArr = tempSidx.split(" ");
                    buffer.append(",").append(strArr[0]).append(" ").append(strArr[1]);
                } else {
                    buffer.append(",").append(tempSidx).append(" ").append(sord);
                }
            }

            sorterItems = buffer.toString().replaceFirst(",", "");
        }

        if (!StringUtils.isEmpty(sorterItems)) {
            sourceSql = sourceSql + " order by " + sorterItems;
        }

        return sourceSql;
    }

    public Map<String, Object> assembleGridData(HttpServletRequest request, List<String> columnList, IRowSet rowSet, int totalCount) throws SHRWebException {
        List<Map<String, Object>> rowDataList = this.assembleGridDataList(request, columnList, rowSet);
        Map<String, Object> resultMap = new HashMap();
        int rows = Integer.parseInt(request.getParameter("rows"));
        int page = Integer.parseInt(request.getParameter("page"));
        if (totalCount % rows == 0) {
            resultMap.put("total", totalCount / rows);
        } else {
            resultMap.put("total", totalCount / rows + 1);
        }

        resultMap.put("page", page);
        resultMap.put("records", totalCount);
        resultMap.put("rows", rowDataList);
        return resultMap;
    }

    public List<Map<String, Object>> assembleGridDataList(HttpServletRequest request, List<String> columnList, IRowSet rowSet) throws SHRWebException {
        Map<String, Object> rowDataMap = null;
        List<Map<String, Object>> rowDataList = new ArrayList();
        if (rowSet.size() == 0) {
            return rowDataList;
        } else {
            try {
                String submitSchemeId = request.getParameter("submitSchemeId");
                StringBuilder sql = new StringBuilder();
                sql.append(" SELECT  ");
                sql.append(" item.fieldSn FIELDSN ");
                sql.append(" FROM T_HR_SCalSubmitScheme scheme ");
                sql.append(" inner join T_HR_SCalSubmitSchemeItem schemeItem on scheme.fid = schemeItem.FCalSubmitSchemeID ");
                sql.append(" inner join T_HR_SCalSubmitItem item on item.fid = schemeItem.FCalSubmitItemID ");
                sql.append(" where scheme.fid =  '").append(submitSchemeId).append("' and item.FDataType = '").append("3").append("'");
                sql.append(" order by  FSortSn");
                IRowSet rs = DbUtil.executeQuery(this.ctx, sql.toString());
                String fieldSn = "";
                String s = "S";
                HashSet f7TypeFieldSet = new HashSet();

                while(rs.next()) {
                    fieldSn = s + rs.getString("FIELDSN");
                    f7TypeFieldSet.add(fieldSn);
                }

                String column = "";

                while(rowSet.next()) {
                    rowDataMap = new HashMap();
                    Iterator iter = columnList.iterator();

                    while(iter.hasNext()) {
                        column = (String)iter.next();
                        String value;
                        String name;
                        if ("personId".equals(column)) {
                            value = rowSet.getString(column);
                            name = rowSet.getString("name");
                            PersonInfo info = new PersonInfo();
                            info.setName(name);
                            info.setId(BOSUuid.read(value));
                            rowDataMap.put("tempId", value);
                            rowDataMap.put("person", info);
                        } else {
                            AdminOrgUnitInfo orgInfo;
                            if ("orgId".equals(column)) {
                                orgInfo = new AdminOrgUnitInfo();
                                value = rowSet.getString(column);
                                name = rowSet.getString("name");
                                rowDataMap.put("tempId", value);
                                orgInfo.setName(name);
                                orgInfo.setId(BOSUuid.read(value));
                                rowDataMap.put("orgUnit", orgInfo);
                            } else if ("admOrgId".equals(column)) {
                                orgInfo = new AdminOrgUnitInfo();
                                value = rowSet.getString(column);
                                if (!StringUtils.isEmpty(value)) {
                                    name = rowSet.getString("admOrgName");
                                    rowDataMap.put("tempId", value);
                                    orgInfo.setName(name);
                                    orgInfo.setId(BOSUuid.read(value));
                                    rowDataMap.put("adminOrgUnit", orgInfo);
                                }
                            } else if ("positionId".equals(column)) {
                                PositionInfo positionInfo = new PositionInfo();
                                value = rowSet.getString(column);
                                if (!StringUtils.isEmpty(value)) {
                                    name = rowSet.getString("positionName");
                                    rowDataMap.put("tempId", value);
                                    positionInfo.setName(name);
                                    positionInfo.setId(BOSUuid.read(value));
                                    rowDataMap.put("position", positionInfo);
                                }
                            } else if ("cmpEmpORelation".equals(column)) {
                                CmpEmpORelationInfo cmpEmpORelation = new CmpEmpORelationInfo();
                                value = rowSet.getString(column);
                                if (!StringUtils.isEmpty(value)) {
                                    cmpEmpORelation.setId(BOSUuid.read(value));
                                    cmpEmpORelation.put("name", value);
                                    rowDataMap.put("cmpEmpORelation", cmpEmpORelation);
                                }
                            } else if ("submitElement".equals(column)) {
                                SubmitElementInfo submitElementInfo = new SubmitElementInfo();
                                value = rowSet.getString(column);
                                if (!StringUtils.isEmpty(value)) {
                                    name = rowSet.getString("submitElementName");
                                    submitElementInfo.setId(BOSUuid.read(value));
                                    submitElementInfo.setName(name);
                                    rowDataMap.put("submitElement", submitElementInfo);
                                }
                            } else if ("currency".equals(column)) {
                                CurrencyInfo currencyInfo = new CurrencyInfo();
                                value = rowSet.getString(column);
                                if (!StringUtils.isEmpty(value)) {
                                    name = rowSet.getString("currencyName");
                                    currencyInfo.setId(BOSUuid.read(value));
                                    currencyInfo.setName(name);
                                    rowDataMap.put("currency", currencyInfo);
                                }
                            } else {
                                HashMap f7TypeValue;
                                if (f7TypeFieldSet.contains(column)) {
                                    value = rowSet.getString(column + "id");
                                    if (StringUtils.isEmpty(value)) {
                                        rowDataMap.put(column, (Object)null);
                                    } else {
                                        f7TypeValue = new HashMap();
                                        f7TypeValue.put("id", value);
                                        f7TypeValue.put("name", rowSet.getString(column));
                                        f7TypeValue.put("number", rowSet.getString(column + "number"));
                                        rowDataMap.put(column, f7TypeValue);
                                    }
                                } else if ("description".equals(column)) {
                                    f7TypeValue = new HashMap();
                                    f7TypeValue.put("l1", rowSet.getString("description_l1"));
                                    f7TypeValue.put("l2", rowSet.getString("description_l2"));
                                    f7TypeValue.put("l3", rowSet.getString("description_l3"));
                                    rowDataMap.put(column, f7TypeValue);
                                } else {
                                    value = rowSet.getString(column);
                                    rowDataMap.put(column, value);
                                }
                            }
                        }
                    }

                    rowDataList.add(rowDataMap);
                }

                return rowDataList;
            } catch (Exception var18) {
                throw new SHRWebException(var18);
            }
        }
    }

    public String exportAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws Exception {
        try {
        	logger.error("进入提报导出方法"); 
            request.setAttribute("title", this.getExportTitle(request));
            String submitSchemeId = request.getParameter("submitSchemeId");
            String billId = request.getParameter("billId");
            Context ctx = SHRContext.getInstance().getContext();
            Map<String, Object> resultMap = CmpIntegrateUtils.getBillColumnListAndQuerySql(ctx, submitSchemeId, billId);
            Map<String, Object> params = Maps.newHashMap();
            params.put("datasource", Integer.valueOf(request.getParameter("datasource")));
            CmpColumnModels cmpColumnModels = null;
            if(Integer.valueOf(request.getParameter("datasource")) == 1) {
                cmpColumnModels = new com.kingdee.shr.customer.gtiit.handler.BaseSubmitBillEntryGenerator().getEntryColumnModels(ctx, submitSchemeId, params);
            }else {
                cmpColumnModels = new BaseSubmitBillEntryGenerator().getEntryColumnModels(ctx, submitSchemeId, params);
            }
            FileExportHelper excel = new FileExportHelper();
            String querySql = resultMap.get("querySql").toString();
            querySql = this.addPermSql(request, querySql);
            String exportSql = this.addSortSql(querySql, request);
            String[] queryMode = this.assembleQueryMode(request, cmpColumnModels.getColModel());
            logger.error("提报导出字段信息："+queryMode);
            IRowSet rowSet = CommonSQLUtil.executeQuery(exportSql);
            List<Map<String, Object>> results = new ArrayList();
            if (rowSet != null && rowSet.size() > 0) {
                String userId = HRFilterUtils.getCurrentUserId(ctx);
                Set<String> fieldPermSet = UserFieldPermInfoHelper.getUserEntityFields(ctx, userId, this.entityName);
                ShrFieldPermForm shrFieldPermForm = new ShrFieldPermForm(ctx, (SelectorItemCollection)null, this.entityName);

                while(rowSet.next()) {
                    Map<String, Object> map = new HashMap();

                    for(int i = 0; i < queryMode.length; ++i) {
                        String[] column = queryMode[i].split(",");
                        if (StringUtils.isEmpty(column[1]) || !Boolean.valueOf(column[1])) {
                            if ("positionName".equals(column[0]) && fieldPermSet != null && !fieldPermSet.isEmpty()) {
                                Map<String, Object> permMap = new HashMap();
                                Iterator var23 = fieldPermSet.iterator();

                                while(var23.hasNext()) {
                                    String permField = (String)var23.next();
                                    if (permField.contains("name")) {
                                        permMap.put("name", rowSet.getObject(column[0]));
                                        if (!shrFieldPermForm.isAllowView(this.entityName, permField, permMap)) {
                                            map.put(column[0], "****");
                                        }
                                    }
                                }
                            } else {
                                map.put(column[0], rowSet.getObject(column[0]));
                            }
                        }
                    }

                    results.add(map);
                }
            }

            excel.exportToExcel(request, response, results, queryMode);
        } catch (Exception var25) {
            this.handleException(var25);
        }

        return null;
    }

    public BaseSubmitBillEntryGenerator getEntryGenerator() {
        return new BaseSubmitBillEntryGenerator();
    }

    protected String getExportTitle(HttpServletRequest request) throws SHRWebException {
        String billNumber = request.getParameter("billNumber");
        Context ctx = SHRContext.getInstance().getContext();
        String isMultiInspire = request.getParameter("isMultiInspire");
        return ("1".equals(isMultiInspire) ? EASResource.getString("com.kingdee.shr.compensation.resource.SubmitShemeBillResource", "label30", ctx.getLocale()) : EASResource.getString("com.kingdee.shr.compensation.resource.SubmitShemeBillResource", "label31", ctx.getLocale())) + billNumber.trim();
    }

    protected String[] assembleQueryMode(HttpServletRequest request, List<Map<String, Object>> colModel) {
        String[] queryMode = new String[colModel.size()];
        Map<String, Object> col = null;
        Context ctx = SHRContext.getInstance().getContext();
        String language = ctx.getLocale().getLanguage();
        Map<String, String> convert2NameMap = new HashMap();
        convert2NameMap.put("orgUnit", "name");
        convert2NameMap.put("person", "name");
        convert2NameMap.put("adminOrgUnit", "admOrgName");
        convert2NameMap.put("position", "positionName");
        convert2NameMap.put("submitElement", "submitElementName");
        convert2NameMap.put("currency", "currencyName");
        convert2NameMap.put("description", "description_" + language);
        int i = 0;

        for(int size = colModel.size(); i < size; ++i) {
            col = (Map)colModel.get(i);
            StringBuilder buffer = new StringBuilder();
            String index = col.get("name").toString();
            if (convert2NameMap.containsKey(index)) {
                index = (String)convert2NameMap.get(index);
            }

            buffer.append(index).append(",");
            boolean hidden = false;
            if (col.get("hidden") != null) {
                hidden = Boolean.parseBoolean(col.get("hidden").toString());
            }

            String label = col.get("label") == null ? col.get("name").toString() : col.get("label").toString();
            buffer.append(hidden).append(",").append(label);
            String name = col.get("name").toString();
            boolean numItem = false;
            int precision = 0;
            if (name.matches("[sS]\\d+") && col.containsKey("editoptions") && "numberfield".equals(col.get("edittype"))) {
                Map editoptions = (Map)col.get("editoptions");
                if (null != editoptions && editoptions.containsKey("inputJson")) {
                    Map inputJson = (Map)editoptions.get("inputJson");
                    if (null != inputJson && inputJson.containsKey("decimalPrecision")) {
                        precision = Integer.parseInt(inputJson.get("decimalPrecision").toString());
                        numItem = true;
                    }
                }
            }

            buffer.append(",").append(numItem);
            if (numItem) {
                buffer.append(",").append(precision);
            } else {
                buffer.append(",").append(0);
            }

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

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

        return queryMode;
    }

    public boolean checkIsShrWfButNoPermitemPermissionCtx(Context ctx, HttpServletRequest request) throws ShrWebBizException {
        System.out.println("checkIsShrWfButNoPermitemPermissionCtx: " + request.getMethod() + "_" + "POST".equals(request.getMethod()));
        logger.error("checkIsShrWfButNoPermitemPermissionCtx: " + request.getMethod() + "_" + "POST".equals(request.getMethod()));
        if ("POST".equals(request.getMethod())) {
            return true;
        } else {
            String uipk = request.getParameter("uipk");
            uipk = SHRPermissionWebUtils.getRealUipk(uipk);
            String billId = this.getBillId(request);
            String msgId = request.getParameter("msgId");
            Map<String, Set<String>> shrWfInProcess = (Map)request.getSession().getAttribute("SHR_WF_IN_PROCESS");
            Map<String, Set<String>> shrWfFinished = (Map)request.getSession().getAttribute("SHR_WF_FINISHED");
            Map<String, Set<String>> shrWfCirculation = (Map)request.getSession().getAttribute("SHR_WF_CIRCULATION");
            Map<String, Set<String>> myShrWfInOrFinished = (Map)request.getSession().getAttribute("MY_SHR_WF_INORFINISHED");
            if (ShrCheckDataPermissionUtil.sessionDataCheckHandler(ctx, shrWfInProcess, uipk, billId, "shrWfInProcess")) {
                return true;
            } else if (ShrCheckDataPermissionUtil.sessionDataCheckHandler(ctx, shrWfFinished, uipk, billId, "shrWfFinished")) {
                return true;
            } else {
                return ShrCheckDataPermissionUtil.sessionDataCheckHandler(ctx, shrWfCirculation, uipk, msgId, "shrWfCirculation") ? true : ShrCheckDataPermissionUtil.sessionDataCheckHandler(ctx, myShrWfInOrFinished, uipk, billId, "myShrWfInOrFinished");
            }
        }
    }
}
