package weaver.interfaces.htsc.payment;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 流程中英文名称转换
 */
public class WorkFlowNameConvertor {

    public final static Map<String,String> CN2ENMap;
    static {
        CN2ENMap = new HashMap<>();
        CN2ENMap.put("总部通用付款","ZBTYFK");
        CN2ENMap.put("总部IT付款","ZBITFK");
        CN2ENMap.put("总部工会付款","ZBGHFK");
        CN2ENMap.put("总部差旅报销","ZBCLBX");
        CN2ENMap.put("总部差旅报销【测试中】","ZBCLBX");
        CN2ENMap.put("总部通用报销","ZBTYBX");
        CN2ENMap.put("总部通用报销【测试中】","ZBTYBX");
        CN2ENMap.put("分支机构差旅报销","FZJGCLBX");
        CN2ENMap.put("分支机构通用报销","FZJGTYBX");
        CN2ENMap.put("分支机构通用付款","FZJGTYFK");
        CN2ENMap.put("预付款费用确认","YFKFYQR");
        CN2ENMap.put("总部商旅结算付款","ZBSLJSFK");
        CN2ENMap.put("资金业务付款","ZJYWFK");
        CN2ENMap.put("分支机构商旅结算付款","FZJGSLJSFK");
        CN2ENMap.put("子公司通用报销","ZGSTYBX");
        CN2ENMap.put("资管差旅报销","ZGCLBX");
        CN2ENMap.put("香港通用付款","XGTYBX");
        CN2ENMap.put("资管通用报销","ZGTYBX");
        CN2ENMap.put("紫金通用报销","ZJTYBX");
        CN2ENMap.put("香港通用报销","XGTYBX");
        CN2ENMap.put("联合通用报销","LHTYBX");
        CN2ENMap.put("差旅报销","LHCLBX");
    }

    /**
     * 获取流程编号的英文展示
     * @param lcbh
     */
    public static String getEN_Lcbh(String lcbh) {
        String CN_prefix = splitNotNumber(lcbh);
        String EN_prefix = CN2ENMap.get(CN_prefix);
        if(null!=EN_prefix) {
            return lcbh.replaceFirst(CN_prefix,EN_prefix);
        }
        return lcbh;
    }

    /**
     * 截取非数字部分
     * @param content
     * @return
     */
    public static String splitNotNumber(String content) {
        Pattern pattern = Pattern.compile("\\D+");
        Matcher matcher = pattern.matcher(content);
        while (matcher.find()) {
            return matcher.group(0);
        }
        return "";
    }

    public static void main(String[] args) {
        String s = "总部IT付款202105000115";
        String t = getEN_Lcbh(s);
        System.out.println(s);
        System.out.println(t);
        System.out.println("---"+getEN_Lcbh(s));
        System.out.println(s);
    }

}
