package com.engine.workflow.cmd.codeMaintenance;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.company.SubCompanyComInfo;
import weaver.system.code.CodeBuild;
import weaver.system.code.CoderBean;
import weaver.systeminfo.SystemEnv;

import com.api.browser.bean.SearchConditionItem;
import com.api.browser.bean.SearchConditionOption;
import com.api.browser.util.ConditionFactory;
import com.api.browser.util.ConditionType;
import com.engine.core.interceptor.Command;
import com.engine.core.interceptor.CommandContext;

/**
 * 预留编号新建页面信息
 * @author longxx
 * */
public class GetReserveCodeNewInfosCmd implements Command<Map<String,Object>>{

    private Map<String,Object> params;
    private User user;
    protected String formId;
    protected String isBill;
    protected ConditionFactory conditionFactory;

    public GetReserveCodeNewInfosCmd(Map<String,Object> params,User user) {
        this.params = params;
        this.user = user;
        conditionFactory = new ConditionFactory(user);
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        return getReserveCodeNewInfos();
    }

    /**
     * 获取预留编号新建页面信息
     * */
    public Map<String,Object> getReserveCodeNewInfos(){
        Map<String,Object> finalReturnMap = new HashMap<String, Object>();
        Map<String,Object> conditionInfos = new HashMap<String,Object>();

        String workflowId = Util.null2String(params.get("workflowid"));
        boolean isFromForm = "1".equals(Util.null2String(params.get("isFromForm")));//是否由表单中进来

        if(!isFromForm) {
            int subCompanyId = Util.getIntValue(Util.null2String(params.get("subCompanyId")),-1);
            subCompanyId = WorkflowCodeUtil.getSubComIdByWfId(workflowId,subCompanyId);
            String isFromPathSet = Util.null2String(params.get("isFromPathSet"));
            String codeType = "1";
            //编号设置进来，校验流程编号权限
            if ("1".equals(isFromPathSet)) {
                codeType = "2";
            }
            int operateLevel = WorkflowCodeUtil.getCodeOperateLevel(user, subCompanyId, codeType);
            if (operateLevel < 0) {
                conditionInfos.put("newInfo_state", "noright");
                return conditionInfos;
            }
        }

        //从表单过来的参数
        String form_yearId = Util.null2String(params.get("yearId"));
        String form_monthId = Util.null2String(params.get("monthId"));
        String form_dateId = Util.null2String(params.get("dateId"));
        String form_fieldId = Util.null2String(params.get("fieldId"));
        String form_fieldValue = Util.null2String(params.get("fieldValue"));
        String form_supSubCompanyId = Util.null2String(params.get("supSubCompanyId"));
        String form_subCompanyId = Util.null2String(params.get("subCompanyId"));
        String form_departmentId = Util.null2String(params.get("departmentId"));
        List<String> formYearIdList = Util.splitString2List(form_yearId, ",");
        List<String> formMonthIdList = Util.splitString2List(form_monthId, ",");
        List<String> formDateIdList = Util.splitString2List(form_dateId, ",");
        List<String> formFieldIdList = Util.splitString2List(form_fieldId, ",");
        List<String> formFieldValueList = Util.splitString2List(form_fieldValue, ",");
        List<String> formSupSubcompanyIdList = Util.splitString2List(form_supSubCompanyId, ",");
        List<String> formSubcompanyIdList = Util.splitString2List(form_subCompanyId, ",");
        List<String> formDepartmentIdList = Util.splitString2List(form_departmentId, ",");
        int yearIndex = 0;
        int monthIndex = 0;
        int dateIndex = 0;
        int supSubCompanyIndex = 0;
        int subCompanyIndex = 0;
        int departmentIndex = 0;

        Map<String, String> formInfo = WorkflowCodeUtil.getFormInfo(workflowId);
        isBill = Util.null2String(formInfo.get("isbill"));
        formId = Util.null2String(formInfo.get("formid"));
        Map<String,List<String>> codeInfos = getCodeRegulateInfo(workflowId);
        List<String> conCreteFieldList = codeInfos.get("concreteFields");
        List<String> codeValueList = codeInfos.get("codeValues");

        List<Map<String,Object>> groupList = new ArrayList<Map<String,Object>>();

        Map<String,Object> codeSetGroupItem = new HashMap<String,Object>();
        Map<String,Object> seqSetGroupItem = new HashMap<String,Object>();
        List<SearchConditionItem> codeSetItemList = new ArrayList<SearchConditionItem>();
        List<SearchConditionItem> seqSetItemList = new ArrayList<SearchConditionItem>();

        codeSetGroupItem.put("defaultshow", true);
        codeSetGroupItem.put("items", codeSetItemList);
        codeSetGroupItem.put("title", SystemEnv.getHtmlLabelName(83549, user.getLanguage()));

        seqSetGroupItem.put("defaultshow", true);
        seqSetGroupItem.put("items", seqSetItemList);
        seqSetGroupItem.put("title", SystemEnv.getHtmlLabelName(10000891, Util.getIntValue(user.getLanguage())));

        groupList.add(codeSetGroupItem);
        groupList.add(seqSetGroupItem);

        //当前流水号
        SearchConditionItem currentSeqId = conditionFactory.createCondition(ConditionType.INPUT, 125356, "currentSeqId");
        currentSeqId.setViewAttr(1);
        currentSeqId.setFieldcol(16);
        currentSeqId.setLabelcol(6);
        Map<String, Object> cruuentSeqIdOtherParams = new HashMap<String, Object>();
        cruuentSeqIdOtherParams.put("hasBorder", true);
        currentSeqId.setOtherParams(cruuentSeqIdOtherParams);
        seqSetItemList.add(currentSeqId);

        int strNum = 0;//记录字符串个数
        int selectedMonthId = 0;
        int selectedYearId = 0;

        CodeBuild cbuild = new CodeBuild(Util.getIntValue(formId),isBill,Util.getIntValue(workflowId));
        CoderBean cbean = cbuild.getFlowCBuild();
        String dateSeqAlone = cbean.getDateSeqAlone();//1:日期单独流水
        String dateSeqSelect = cbean.getDateSeqSelect();//获取日期单独流水方式
        String dateSeqFieldId = cbean.getCorrespondDate();//获取日期单独流水字段

        boolean seqYearExists = false;
        boolean seqMonthExists = false;
        //先遍历一遍，查看日期单独流水字段年月日，是否都存在编号组成中
        for(int i = 0;i < conCreteFieldList.size();i++) {
            String conCreteField = conCreteFieldList.get(i);
            String codeValue = codeValueList.get(i);
            if(Util.null2String(dateSeqFieldId).equals(codeValue)) {
                if(conCreteField.equals("4")) {
                    seqYearExists = true;
                }else if(conCreteField.equals("5")) {
                    seqMonthExists = true;
                }
            }
        }

        for(int i = 0;i < conCreteFieldList.size();i++){
            String conCreteField = conCreteFieldList.get(i);
            String codeValue = codeValueList.get(i);//codevalue存放的是字段的id,如果是文本类型，就是字符串或者流水号位数,如果是选择框，则为value

            Calendar today = Calendar.getInstance();
            int yearIdToday = today.get(Calendar.YEAR);
            int monthIdToday = today.get(Calendar.MONTH) + 1;
            int dateIdToday = today.get(Calendar.DAY_OF_MONTH);

            if(conCreteField.equals("0")){//选择框
                Map<String,List<String>> selectInfos = getSelectInfos(codeValue, isBill);//这里的codevalue为字段id
                String selectItemName = "selectValue" + codeValue;//前端name组成为selectValue+字段id
                String selectValue = "";
                if(isFromForm) {
                    int index = formFieldIdList.indexOf(codeValue);
                    if(index != -1) {
                        selectValue = formFieldValueList.get(index);
                    }
                }
                if(selectValue.equals("")){
                    selectValue = "0";
                }
                SearchConditionItem selectItem = conditionFactory.createCondition(ConditionType.SELECT, 22755, selectItemName,getSelectOptions(selectInfos,selectValue));
                Map<String, Object> otherParams = new HashMap<String, Object>();
                otherParams.put("hasBorder", true);
                selectItem.setFieldcol(16);
                selectItem.setLabelcol(6);
                selectItem.setOtherParams(otherParams);
                if(isFromForm) selectItem.setViewAttr(1);
                codeSetItemList.add(selectItem);
            }else if(conCreteField.equals("1")){//部门
                String deptItemName = "deptId";
                if(codeValue.equals("-2"))
                    deptItemName += "_2";//创建人部门
                else
                    deptItemName += codeValue;//来自表单字段,codeValue为deptid

                String deptId = "";
                if(isFromForm) {
                    deptId = formDepartmentIdList.get(departmentIndex);
                    departmentIndex++;
                }

                SearchConditionItem deptItem = conditionFactory.createCondition(ConditionType.BROWSER, 124, deptItemName,"4");
                deptItem.setViewAttr(isFromForm ? 1 : 3);
                deptItem.setRules("required|string");
                deptItem.setFieldcol(16);
                deptItem.setLabelcol(6);
                if(!deptId.equals("")){
                    List<Map<String,Object>> replaceDatas = new ArrayList<Map<String,Object>>();
                    Map<String,Object> datas = getDefaultDept(deptId);
                    replaceDatas.add(datas);//用于页面浏览框默认显示
                    deptItem.getBrowserConditionParam().setReplaceDatas(replaceDatas);
                }
                deptItem.getBrowserConditionParam().setHasBorder(true);
                codeSetItemList.add(deptItem);
            }else if(conCreteField.equals("2")){//分部
                String subComItemName = "subComId";
                if(codeValue.equals("-2"))
                    subComItemName += "_2";//创建人分部
                else
                    subComItemName += codeValue;//来自表单字段

                String subComId = "";
                if(isFromForm) {
                    subComId = formSubcompanyIdList.get(subCompanyIndex);
                    subCompanyIndex++;
                }

                SearchConditionItem subComItem = conditionFactory.createCondition(ConditionType.BROWSER, 141, subComItemName,"164");
                subComItem.setViewAttr(isFromForm ? 1 : 3);
                subComItem.setFieldcol(16);
                subComItem.setLabelcol(6);
                subComItem.setRules("required|string");
                if(!subComId.equals("")){
                    List<Map<String,Object>> replaceDatas = new ArrayList<Map<String,Object>>();
                    Map<String,Object> datas = getDefaultSubCom(subComId);
                    replaceDatas.add(datas);
                    subComItem.getBrowserConditionParam().setReplaceDatas(replaceDatas);
                }
                subComItem.getBrowserConditionParam().setHasBorder(true);
                codeSetItemList.add(subComItem);
            }else if(conCreteField.equals("3")){//上级分部
                String supSubComItemName = "supSubComId";
                if(codeValue.equals("-2"))
                    supSubComItemName += "_2";//创建人分部
                else
                    supSubComItemName += codeValue;//来自表单字段

                String supSubComId = "";
                if(isFromForm) {
                    supSubComId = formSupSubcompanyIdList.get(supSubCompanyIndex);
                    supSubCompanyIndex++;
                }

                SearchConditionItem supSubComItem = conditionFactory.createCondition(ConditionType.BROWSER, 22753, supSubComItemName,"164");
                supSubComItem.setViewAttr(isFromForm ? 1 : 3);
                supSubComItem.setFieldcol(16);
                supSubComItem.setLabelcol(6);
                supSubComItem.setRules("required|string");
                if(!supSubComId.equals("")){
                    List<Map<String,Object>> replaceDatas = new ArrayList<Map<String,Object>>();
                    Map<String,Object> datas = getDefaultSubCom(supSubComId);
                    replaceDatas.add(datas);
                    supSubComItem.getBrowserConditionParam().setReplaceDatas(replaceDatas);
                }
                supSubComItem.getBrowserConditionParam().setHasBorder(true);
                codeSetItemList.add(supSubComItem);
            }else if(conCreteField.equals("4")){//年

                String yearItemName = getFieldMark("yearId", codeValue);

                String yearId = "";
                if(isFromForm) {
                    if(codeValue.equals("-2")) {
                        yearId = yearIdToday + "";
                    } else {
                        String fieldValue = Util.null2String(params.get("field" + codeValue));
                        yearId = fieldValue.split("-").length > 1 ? fieldValue.split("-")[0] : fieldValue;
                    }
                }

                //获取默认选中值
                String yearValue = getYearDefaultValue(yearId);
                selectedYearId = Util.getIntValue(yearValue);
                codeSetItemList.add(getYearItem(yearItemName, yearValue, isFromForm));
            }
            if(conCreteField.equals("5")){//月

                String yearItemName = getFieldMark("yearId", codeValue);
                String monthItemName = getFieldMark("monthId", codeValue);

                String yearId = "";
                String monthId = "";
                if(isFromForm) {
                    if(codeValue.equals("-2")) {
                        yearId = yearIdToday + "";
                        monthId = monthIdToday + "";
                    } else {
                        String fieldValue = Util.null2String(params.get("field" + codeValue));
                        yearId = fieldValue.split("-").length > 1 ? fieldValue.split("-")[0] : fieldValue;
                        monthId = fieldValue.split("-").length > 1 ? fieldValue.split("-")[1] : fieldValue;
                    }
                }


                //获取默认选中月
                String defaultSelectMonth = getMonthDefaultValue(monthId);

                //按月单独流水，当前字段为单独流水字段，且未设置年编号组成，补充一个年选择框，让用户选择年份
                if("1".equals(dateSeqAlone) && dateSeqSelect.equals("2") && codeValue.equals(dateSeqFieldId) && !seqYearExists) {
                    codeSetItemList.add(getYearItem(yearItemName, getYearDefaultValue(yearId), isFromForm));
                }

                selectedMonthId = Util.getIntValue(defaultSelectMonth);//用户选中的月份
                codeSetItemList.add(getMonthItem(monthItemName, defaultSelectMonth, isFromForm));
            }
            if(conCreteField.equals("6")){//日

                String yearItemName = getFieldMark("yearId", codeValue);
                String monthItemName = getFieldMark("monthId", codeValue);
                String dateItemName = getFieldMark("dateId", codeValue);

                String yearId = "";
                String monthId = "";
                String dateId = "";
                if(isFromForm) {
                    if(codeValue.equals("-2")) {
                        yearId = yearIdToday + "";
                        monthId = monthIdToday + "";
                        dateId = dateIdToday + "";
                    } else {
                        String fieldValue = Util.null2String(params.get("field" + codeValue));
                        yearId = fieldValue.split("-").length == 3 ? fieldValue.split("-")[0] : fieldValue;
                        monthId = fieldValue.split("-").length == 3 ? fieldValue.split("-")[1] : fieldValue;
                        dateId = fieldValue.split("-").length == 3 ? fieldValue.split("-")[2] : fieldValue;
                    }
                }

                String defaultSelectDate = "";
                if(!dateId.equals("")){
                    defaultSelectDate = dateId;
                }else{
                    String dateIdStr = "";
                    if(dateIdToday < 10)
                        dateIdStr = "0" + dateIdToday;
                    else
                        dateIdStr = "" + dateIdToday;
                    defaultSelectDate = dateIdStr;
                }

                //按日单独流水，当前字段为单独流水字段
                if("1".equals(dateSeqAlone) && dateSeqSelect.equals("3") && codeValue.equals(dateSeqFieldId)) {
                    //未设置年编号组成，补充一个年选择框，让用户选择年份
                    if(!seqYearExists) {
                        codeSetItemList.add(getYearItem(yearItemName, getYearDefaultValue(yearId), isFromForm));
                    }

                    if (!seqMonthExists) {
                        codeSetItemList.add(getMonthItem(monthItemName, getMonthDefaultValue(monthId), isFromForm));
                    }
                }

                codeSetItemList.add(getDateItem(dateItemName, selectedYearId, selectedMonthId, defaultSelectDate, isFromForm));
            }else if(conCreteField.equals("7")){//字符串
                strNum++;
                Map<String,Object> otherParams = new HashMap<String, Object>();
                String strItemName = "str_" + strNum;
                String labelName = SystemEnv.getHtmlLabelName(27903, user.getLanguage()) + strNum;
                otherParams.put("hasBorder", true);
                SearchConditionItem strItem = conditionFactory.createCondition(ConditionType.INPUT, 0, strItemName);
                strItem.setValue(codeValue);
                strItem.setLabel(labelName);
                strItem.setViewAttr(1);
                strItem.setOtherParams(otherParams);
                strItem.setFieldcol(16);
                strItem.setLabelcol(6);
                codeSetItemList.add(strItem);
            }else if(conCreteField.equals("8")){//这里获取流水号
                //流水号
                SearchConditionItem codeItem = conditionFactory.createCondition(ConditionType.INPUT, 383362, "flowcode");
                codeItem.setViewAttr(3);
                codeItem.setFieldcol(16);
                codeItem.setLabelcol(6);
                codeItem.setRules("required|string");
                seqSetItemList.add(codeItem);
            }else if(conCreteField.equals("9")){//字母
                SearchConditionItem strItem = conditionFactory.createCondition(ConditionType.INPUT, 27903, "letter");
                strItem.setValue(codeValue);
                strItem.setViewAttr(1);
                strItem.setFieldcol(16);
                strItem.setLabelcol(6);
                codeSetItemList.add(strItem);
            }
        }


        //描述,可编辑
        SearchConditionItem descItem = conditionFactory.createCondition(ConditionType.TEXTAREA, 433, "desc");
        descItem.setFieldcol(16);
        descItem.setLabelcol(6);
        seqSetItemList.add(descItem);

        conditionInfos.put("conditioninfo", groupList);


        finalReturnMap = conditionInfos;
        return finalReturnMap;
    }


    public String getFieldMark(String typeMark, String codeValue) {
        if(codeValue.equals("-2"))
            typeMark += "_2";
        else
            typeMark += codeValue;//来自表单字段
        return typeMark;
    }

    /**
     * 获取年默认选中值，未设置则选中当前日期
     * @param yearId
     * @return
     */
    public String getYearDefaultValue(String yearId) {
        Calendar today = Calendar.getInstance();
        int yearIdToday = today.get(Calendar.YEAR);

        String yearValue = "";
        if(!yearId.equals("")){
            yearValue = yearId;
        }else{
            yearValue = yearIdToday + "";
        }
        return yearValue;
    }

    /**
     * 获取年组件
     */
    public SearchConditionItem getYearItem(String yearItemName, String yearValue, boolean isFromForm) {
        Map<String,Object> otherParamMap = new HashMap<>();
        otherParamMap.put("format", "yyyy");
        otherParamMap.put("hasBorder", true);
        SearchConditionItem yearItem = conditionFactory.createCondition(ConditionType.DATEPICKER, 445, yearItemName);
        yearItem.setValue(yearValue);
        yearItem.setFieldcol(10);
        yearItem.setLabelcol(6);
        yearItem.setOtherParams(otherParamMap);
        //if(isFromForm) yearItem.setViewAttr(1);
        return yearItem;
    }

    /**
     * 获取月默认选中值，未设置则选中当前月
     * @param monthId
     * @return
     */
    public String getMonthDefaultValue(String monthId) {

        Calendar today = Calendar.getInstance();
        int monthIdToday = today.get(Calendar.MONTH) + 1;

        String defaultSelectMonth = "";
        if(!monthId.equals("")){
            defaultSelectMonth = monthId;
        }else{
            defaultSelectMonth = monthIdToday + "";
        }

        if (defaultSelectMonth.length() == 1) {
            defaultSelectMonth = "0" + defaultSelectMonth;
        }
        return defaultSelectMonth;
    }

    /**
     * 获取月组件
     */
    public SearchConditionItem getMonthItem(String monthItemName, String defaultSelectMonth, boolean isFromForm) {
        SearchConditionItem monthItem = conditionFactory.createCondition(ConditionType.SELECT, 6076, monthItemName,WorkflowCodeUtil.getMonthOptions(defaultSelectMonth));
        monthItem.setFieldcol(8);
        monthItem.setLabelcol(6);
        Map<String, Object> otherParams = new HashMap<String, Object>();
        otherParams.put("hasBorder", true);
        monthItem.setOtherParams(otherParams);
        monthItem.setValue(defaultSelectMonth);
        if(isFromForm) monthItem.setViewAttr(1);
        return monthItem;
    }

    /**
     * 获取日组件
     * @param dateItemName
     * @param selectedYearId
     * @param selectedMonthId
     * @param defaultSelectDate
     * @param isFromForm
     * @return
     */
    public SearchConditionItem getDateItem(String dateItemName, int selectedYearId, int selectedMonthId, String defaultSelectDate, boolean isFromForm) {

        if (selectedYearId <= 0) {
            selectedYearId = Util.getIntValue(getYearDefaultValue(""));
        }

        //月份未设置，取为31天的月
        if (selectedMonthId <= 0) {
            selectedMonthId = 1;
        }


        SearchConditionItem dateItem = conditionFactory.createCondition(ConditionType.SELECT, 390, dateItemName,WorkflowCodeUtil.getDateOptions(defaultSelectDate,selectedYearId,selectedMonthId));
        dateItem.setFieldcol(8);
        dateItem.setLabelcol(6);
        Map<String, Object> otherParams = new HashMap<String, Object>();
        otherParams.put("hasBorder", true);
        dateItem.setOtherParams(otherParams);

        //只有一位，前面添加一个0
        if (Util.null2String(defaultSelectDate).length() == 1) {
            defaultSelectDate = "0" + defaultSelectDate;
        }

        dateItem.setValue(defaultSelectDate);
        //if(isFromForm) dateItem.setViewAttr(1);
        return dateItem;
    }

    //获取下拉框选项
    public static Map<String,List<String>> getSelectInfos(String fieldId,String isBill){
        Map<String,List<String>> selectInfos = new HashMap<String, List<String>>();
        List<String> selectNames = new ArrayList<String>();
        List<String> selectValues = new ArrayList<String>();
        String sql = "select selectvalue,selectname from workflow_selectitem where fieldid=? and isbill=? order by listorder";
        RecordSet rs = new RecordSet();
        rs.executeQuery(sql, fieldId, isBill);
        while(rs.next()){
            String selectValue = Util.null2String(rs.getString("selectvalue"));
            String selectName = Util.null2String(rs.getString("selectname"));
            selectNames.add(selectName);
            selectValues.add(selectValue);
        }
        selectInfos.put("selectNames", selectNames);
        selectInfos.put("selectValues", selectValues);
        return selectInfos;
    }
    //获取选择框流水的选项
    public List<SearchConditionOption> getSelectOptions(Map<String,List<String>> selectInfos,String defaultSelectValue){
        List<SearchConditionOption> options = new ArrayList<SearchConditionOption>();
        SearchConditionOption optionItem = null;
        List<String> selectNames = selectInfos.get("selectNames");
        List<String> selectValues = selectInfos.get("selectValues");
        String selectName = "";
        String selectValue = "";
        for(int i = 0;i < selectValues.size();i++){
            selectName = selectNames.get(i);
            selectValue = selectValues.get(i);
            optionItem = new SearchConditionOption(selectValue,selectName,(selectValue.equals(defaultSelectValue)) ? true : false );
            options.add(optionItem);
        }
        return options;
    }

    //得到编号组成
    public Map<String,List<String>> getCodeRegulateInfo(String workflowId){
        Map<String,List<String>> codeInfos = new HashMap<String, List<String>>();
        List<String> conCreteFieldList = new ArrayList<String>();
        List<String> codeValueList = new ArrayList<String>();
        List<String> enableCodeList = new ArrayList<String>();
        CodeBuild cb = new CodeBuild();
        boolean isWorkflowSeqAlone = cb.isWorkflowSeqAlone(new RecordSet(), Util.getIntValue(workflowId));
        RecordSet rs = new RecordSet();
        if(isWorkflowSeqAlone) {
            rs.executeQuery("select * from workflow_coderegulate  where workflowId = ? order by codeorder", workflowId);
        } else {
            rs.executeQuery("select * from workflow_coderegulate  where formid = ? and isbill = ? order by codeorder", formId, isBill);
        }
        while(rs.next()){
            conCreteFieldList.add(rs.getString("concreteField"));
            codeValueList.add(rs.getString("codeValue"));
            enableCodeList.add(rs.getString("enablecode"));
        }

        codeInfos.put("concreteFields", conCreteFieldList);
        codeInfos.put("codeValues", codeValueList);
        codeInfos.put("enableCodes", enableCodeList);
        return codeInfos;
    }

    //获取选中选择框预览选项
    public static String getSelectDefaultPreView(Map<String,List<String>> selectInfos,String selectValue){
        String returnStr = "";
        List<String> selectValues = selectInfos.get("selectValues");
        List<String> selectNames = selectInfos.get("selectNames");
        for(int i = 0;i < selectValues.size();i++){
            if(selectValues.get(i).equals(selectValue)){
                returnStr = selectNames.get(i);
            }
        }
        return returnStr;
    }

    //用于默认显示部门
    public Map<String,Object> getDefaultDept(String deptId){
        Map<String,Object> deptInfoMap = new HashMap<String, Object>();
        DepartmentComInfo depCom = new DepartmentComInfo();
        String deptName = depCom.getDepartmentname(deptId);
        deptInfoMap.put("id", deptId);
        deptInfoMap.put("name", deptName);
        return deptInfoMap;
    }

    //获取默认分部,用于默认显示
    public Map<String,Object> getDefaultSubCom(String subComId){
        Map<String,Object> subComInfoMap = new HashMap<String, Object>();
        SubCompanyComInfo subCom = new SubCompanyComInfo();
        String subName = subCom.getSubCompanyname(subComId);
        subComInfoMap.put("id", subComId);
        subComInfoMap.put("name", subName);
        return subComInfoMap;
    }

    /**
     * 校验流水号,只能输入数字和-范围分隔符
     * */
    public String validateFlowCode(String flowCode){
        String returnCode = "";

        //1 判断有没有-字符
        if(flowCode.indexOf("-") == -1){//没有
            //判断字符串里面是否有非数字
            int flowCodeNum = Util.getIntValue(flowCode,-1);
            if(flowCodeNum != -1){
                if(flowCodeNum !=0 && flowCode.matches("^[0-9]+")){
                    returnCode = flowCodeNum + "";
                }
            }
        }else{//有
            String[] values = flowCode.split("-");// -5这样的解析成["","5"],也存在05-06这样的情况啊,这个时候需要解析
            if(values.length == 2){
                if(values[0].trim().matches("^[0-9]+")){
                    if(values[1].trim().matches("^[0-9]+")){
                        returnCode = Util.getIntValue(values[0].trim()) + "-" + Util.getIntValue(values[1].trim());
                    }

                }
            }
            if(values.length == 1){
                if(values[0].trim().matches("^[0-9]+")){
                    returnCode = Util.getIntValue(values[0].trim()) + "-";
                }
            }
        }
        return returnCode;
    }

    public Map<String, Object> getParams() {
        return params;
    }

    public void setParams(Map<String, Object> params) {
        this.params = params;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

}
