package com.persagy.proxy.adm.constant;

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

import org.apache.commons.lang.StringUtils;

import cn.hutool.core.util.StrUtil;

/**
 * 对象类型的前缀与全名的来回映射，以及根据边类型获取对应的对象类型前缀
 * 
 * @version 1.0.0
 * @company persagy 
 * @author zhangqiankun
 * @date 2021年9月3日 下午9:16:10
 */
public class ObjTypeMapping {

	/** example: Sp -> space */
	public static final Map<String, String> PREFIX_FULLNAME = new HashMap<String, String>();
	
	/** example: space -> Sp */
	public static final Map<String, String> FULLNAME_PREFIX = new HashMap<String, String>();
	
	/** example: space -> 空间 */
	public static final Map<String, String> FULLNAME_NAME = new HashMap<String, String>();
	
	/** example: Sp -> 空间 */
	public static final Map<String, String> PREFIX_NAME = new HashMap<String, String>();
	/**楼层-对象类型*/
	public static final String FLOOR = "floor";
	
	static {
	    
		PREFIX_FULLNAME.put("Pj", "project");
		PREFIX_FULLNAME.put("Bd", "building");
		PREFIX_FULLNAME.put("Fl", "floor");
		PREFIX_FULLNAME.put("Sp", "space");
		PREFIX_FULLNAME.put("Sy", "system");
		PREFIX_FULLNAME.put("Eq", "equipment");
		PREFIX_FULLNAME.put("Sh", "shaft");
		PREFIX_FULLNAME.put("Ec", "component");
		PREFIX_FULLNAME.put("Pe", "property");
		
		FULLNAME_PREFIX.put("project", "Pj");
		FULLNAME_PREFIX.put("building", "Bd");
		FULLNAME_PREFIX.put("floor", "Fl");
		FULLNAME_PREFIX.put("space", "Sp");
		FULLNAME_PREFIX.put("system", "Sy");
		FULLNAME_PREFIX.put("equipment", "Eq");
		FULLNAME_PREFIX.put("shaft", "Sh");
		FULLNAME_PREFIX.put("component", "Ec");
		FULLNAME_PREFIX.put("property", "Pe");
		
		PREFIX_NAME.put("Pj", "项目");
		PREFIX_NAME.put("Bd", "建筑");
		PREFIX_NAME.put("Fl", "楼层");
		PREFIX_NAME.put("Sp", "空间");
		PREFIX_NAME.put("Sy", "系统");
		PREFIX_NAME.put("Eq", "设备");
		PREFIX_NAME.put("Sh", "竖井");
		PREFIX_NAME.put("Ec", "部件");
		PREFIX_NAME.put("Pe", "资产");
		
		FULLNAME_NAME.put("project", "项目");
		FULLNAME_NAME.put("building", "建筑");
		FULLNAME_NAME.put("floor", "楼层");
		FULLNAME_NAME.put("space", "空间");
		FULLNAME_NAME.put("system", "系统");
		FULLNAME_NAME.put("equipment", "设备");
		FULLNAME_NAME.put("shaft", "竖井");
		FULLNAME_NAME.put("component", "部件");
		FULLNAME_NAME.put("property", "资产");
		
	}
	
	/**
	 * 获取中台中，边类型编码的前两位
	 * 
	 * @param relCode 最低2位，不然抛异常
	 * @return 空字符串或者对应前缀
	 */
	public static String getRelCodePrefix(String relCode) {
		return StrUtil.isBlank(relCode) ? AdmCommonConstant.EMPTY : relCode.substring(0, 2);
	}
	
	/**
	 * 获取中台中对象类型的前两位
	 * 
	 * @param objType 最低5位，不然抛异常
	 * @return 空字符串或者对应后缀
	 */
	public static String getRelCodeSuffix(String relCode) {
		return StrUtil.isBlank(relCode) ? AdmCommonConstant.EMPTY : relCode.substring(3, 5);
	}
	
	/**
	 * 获取中台中边类型对应的描述
	 * 
	 * @param objType 最低5位，不然抛异常
	 * @return 空字符串或者对应后缀
	 */
	public static String getConneObject(String relCode) {
		if (StringUtils.isBlank(relCode) || relCode.length() < 5) {
			return AdmCommonConstant.EMPTY;
		}
		return PREFIX_NAME.get(relCode.substring(0, 2)) + AdmCommonConstant.RIGHT_ARROW +  PREFIX_NAME.get(relCode.substring(3, 5));
	}
	
}
