package com.chinaweal.aiccs.common.util;

import com.chinaweal.aiccs.common.constant.BaseDataConstant;
import org.apache.commons.lang.StringUtils;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by nieqiurong on 15-1-13.
 */
public class CreditUtil {
    private CreditUtil() {
    }

    public final static String WORK = "creditWorkFlow";  //信用分类管理工作流名称
    public final static String FLAGE = "1";              //不需要签署意见
    public final static String STATUS_START = "0";     //历史表业务启动状态
    public final static String STATUS_END = "1";       //历史表业务结束状态
    public final static String CREDITINFO = "collectionWorkFlow";  //外部信用信息工作流程
    public final static String CREDITINFO_STATUS = "0";  //外部信用信息状态 未通过
    public final static String CREDITINFO_STATUS_NORMAL = "1"; //外部信用信息状态正常
    public final static String BUS_ADD = "DJ03";
    public final static String BUS_UPDATE = "DJ04";
    public final static String BUS_DELTE = "DJ05";
    public final static String BUS_SEARCH = "DJ00";
    /**
     * 信用分类信息 业务环节
     */
    public final static String CREDITENTER = "creditEnter";    //呈报审批
    public final static String HANDLECREDIT = "handleCredit"; //审批中
    public final static String CREDIT = "handleCrediting";//办结中
    public final static String EXIT = "exitEnter";//撤销
    public final static String END = "end";//办结

    /**
     * 外部信用信息 业务环节
     */
    public final static String COLLECTIONENTER = "collectionEnter"; //呈报审批
    public final static String HANDLECOLLECTION = "handleCollection";  //审批中
    public final static String COLLECTIONREFUSE = "refuse";  //不予审核
    public final static String COLLECTIONEND = "end";//办结
    public final static String ADD = "add";
    public final static String UPDATR = "update";
    // 0:未生效 1:生效 2:增加业务 3:修改业务 4:删除业务  8:已删除  9:未通过
    public final static String CREDITINFO_ADD_STATUS = "2";   //外部信用信息增加业务中
    public final static String CREDITINFO_ADD_DELETE = "8";   //已删除
    public final static String CREDITINFO_UPDATA_STATUS = "3";//外部信用信息修改业务中
    public final static String CREDITINFO_DELETE_STATUS = "4";//外部信用信息删除业务中
    public final static String CREDITINFO_DELETE_REFUSE = "9";//外部信用信息业务审核未通过

    /**
     * 内部信用优良企业称号管理
     */
    public final static String INFOINVALID = "0"; //未生效
    public final static String INURE = "1";//生效
    public final static String INFOBASECODE = "LN00001";

    public static boolean isExitEnd(String nodeid, String nextId) {
        return (EXIT + "_" + END).equals(nodeid + "_" + nextId);
    }

    public static boolean isEnd(String nodeid, String nextId) {
        return (CREDIT + "_" + END).equals(nodeid + "_" + nextId);
    }

    /**
     * 主表字段等级为int  历史表为char
     */
    private static Map<String, Integer> MAP = new HashMap<String, Integer>();

    private static Map<String, String> GET_LEVEL = new HashMap<String, String>();

    private static Map<String, String> GET_OPTION_TYPE = new HashMap<String, String>();

    private static Map<String, String> GET_OPERATE_TYPE = new HashMap<String, String>();

    static {
        MAP.put("0", 0);
        MAP.put("1", 1);
        MAP.put("2", 2);
        MAP.put("3", 3);
        MAP = Collections.unmodifiableMap(MAP);
        GET_LEVEL.put("0", "A");
        GET_LEVEL.put("1", "B");
        GET_LEVEL.put("2", "C");
        GET_LEVEL.put("3", "D");
        GET_LEVEL = Collections.unmodifiableMap(GET_LEVEL);
        GET_OPTION_TYPE.put("0", "审查");
        GET_OPTION_TYPE.put("1", "核准");
        GET_OPTION_TYPE = Collections.unmodifiableMap(GET_OPERATE_TYPE);
        GET_OPERATE_TYPE.put(BaseDataConstant.BUSTNESS_TYPE_CREDITINFO_ADD, "新增");
        GET_OPERATE_TYPE.put(BaseDataConstant.BUSTNESS_TYPE_CREDITINFO_UPDATA, "修改");
        GET_OPERATE_TYPE.put(BaseDataConstant.BUSTNESS_TYPE_CREDITINFO_DELETE, "删除");
        GET_OPERATE_TYPE = Collections.unmodifiableMap(GET_OPERATE_TYPE);
    }

    /**
     * 获取手动标志
     *
     * @param level
     * @return
     */
    public static int getLevelarttag(String level) {
        int i = 0;
        try {
            i = Integer.parseInt(level);
        } catch (Exception e) {
            i = -1;
        }
        return i;
    }

    /**
     * 获取等级对应的字母
     */
    public static String getLevelStr(Object o) {
        if(o ==null) return null;
        String str = String.valueOf(o);
        return GET_LEVEL.get(str);
    }

    /**
     * 是否手动标志
     */
    public static String getTagStr(String tag) {
        String str = "";
        if (StringUtils.isNotBlank(tag)) str = tag.equals("1") ? "是" : "否";
        return str;
    }

    /**
     * 获取意见类型
     */
    public static String getOptionType(String type) {
        if (StringUtils.isBlank(type)) return "";
        return GET_OPTION_TYPE.get(type);
    }

    /**
     * 获取审核类型
     */
    public static String getOperateType(String type) {
        if (StringUtils.isBlank(type)) return "";
        return GET_OPERATE_TYPE.get(type.trim());
    }

    public static Map<String, Integer> getMap() {
        return MAP;
    }
}
