package com.changhong.epc.parsing.service.transition.billInfo.models; import com.changhong.epc.bean.admin.CorresElField; import com.changhong.epc.bean.admin.extend.CorresElFieldExtendFind; import com.changhong.epc.constter.admin.AdminUrlConst; import com.changhong.epc.constter.parsing.subassembly.billinfo.TransverterConstKey; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.iemsoft.framework.cloud.core.base.ResMsg; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.ribbon.RestInterface; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import java.util.HashMap; import java.util.Map; import java.util.Objects; /** * 加载 转换billInfo需要的数据 * @ClassName: InitBillTransitionData * @author [九鼎联合科技] * @date 2017年7月23日 下午7:26:46 */ @Slf4j @Component("billTransitionData") public class BillTransitionData implements TransverterConstKey, SystemClients { /* 对应字段缓存信息 */ //@Resource(name="corresFieldCache") // 字段对应常量表 private CorresElFieldExtendFind cores; private Map> billFatcs; private Map mdCodeMaping; public BillTransitionData() { } @Autowired(required=false) private RestTemplate restTemplate; public Object getPostRest(String url,Map parm){ RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class); Object data = restInterface.post(url, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } public Object getTenantPostRest(String url,Map parm){ RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class); Object data = restInterface.post(url, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } public Object getConstEl(){ Object postRest = getPostRest(AdminUrlConst.REST_ADMIN_CORRESELFIELD_SELECT, new HashMap<>()); return JSONTool.toObj(JSONTool.toJson(postRest), CorresElFieldExtendFind.class); } //@PostConstruct public void initData(){ cores = (CorresElFieldExtendFind) getConstEl(); try{ billFatcs = new HashMap>(); // 映射MdCode mdCodeMaping = new HashMap<>(); mdCodeMaping.put(COST_TYPE,cores.findCode(COST_TYPE).getMdCode()); mdCodeMaping.put(TB_BILLFATCHVALFORMULA, cores.findCode(TB_BILLFATCHVALFORMULA).getMdCode()); mdCodeMaping.put(TB_BILLFATCHVAL, cores.findCode(TB_BILLFATCHVAL).getMdCode() ); /* * 公式取值 */ //票据模板编码 Map billFatcCcode = getCostToMapp(BILL_FATC_CCODE);//cores.findCode(BILL_FATC_CCODE); // corresFieldCache.getFirstData(BILL_FATC_CCODE); //对照业务代码 Map billFatcMeanigKey = getCostToMapp(BILL_FATC_MEANIG_KEY ); //corresFieldCache.getFirstData( BILL_FATC_MEANIG_KEY); //主数据定义 Map billFatcMdCod = getCostToMapp(BILL_FATC_MDCODE ); //corresFieldCache.getFirstData( BILL_FATC_MDCODE ); //主数据值 Map billFatcValue = getCostToMapp(BILL_FATC_VALUE ); //corresFieldCache.getFirstData( BILL_FATC_VALUE ); Map billFatcValueCode = getCostToMapp(BILL_FATC_VALUE_CODE ); //corresFieldCache.getFirstData( BILL_FATC_VALUE ); //条件关系 Map billFatcCount = getCostToMapp(BILL_FATC_COUNT ); //corresFieldCache.getFirstData( BILL_FATC_COUNT ); //票据元素 Map billFatcElemet = getCostToMapp(BILL_FATC_ELEMENT ); //corresFieldCache.getFirstData( BILL_FATC_ELEMENT ); //formId Map billFatcFormId = getCostToMapp(BILL_FATC_FORMID ); billFatcs.put( getNewGroupKey(billFatcCcode) , billFatcCcode ); billFatcs.put( getNewGroupKey(billFatcMeanigKey) , billFatcMeanigKey); billFatcs.put( getNewGroupKey(billFatcMdCod) , billFatcMdCod ); billFatcs.put( getNewGroupKey(billFatcValue) , billFatcValue ); billFatcs.put( getNewGroupKey(billFatcValueCode) , billFatcValueCode); billFatcs.put( getNewGroupKey(billFatcCount) , billFatcCount ); billFatcs.put( getNewGroupKey(billFatcElemet) , billFatcElemet ); billFatcs.put( getNewGroupKey(billFatcFormId) , billFatcFormId ); /* * 取值表 */ Map billFatcValKey = getCostToMapp(BILL_FATC_VAL_KEY); // corresFieldCache.getFirstData(BILL_FATC_VAL_KEY ); Map billFatcValMdCode = getCostToMapp(BILL_FATC_VAL_MDCODE); // corresFieldCache.getFirstData(BILL_FATC_VAL_MDCODE ); Map billFatcValElement = getCostToMapp(BILL_FATC_VAL_ELEMENT); // corresFieldCache.getFirstData(BILL_FATC_VAL_ELEMENT); Map billFatcValCode = getCostToMapp(BILL_FATC_VAL_CODE); // corresFieldCache.getFirstData(BILL_FATC_VAL_CODE ); Map billFatcValFormId = getCostToMapp(BILL_FATC_VAL_FORMID); // corresFieldCache.getFirstData(BILL_FATC_VAL_CODE ); billFatcs.put(getNewGroupKey(billFatcValKey) ,billFatcValKey ); billFatcs.put(getNewGroupKey(billFatcValMdCode),billFatcValMdCode ); billFatcs.put(getNewGroupKey(billFatcValElement),billFatcValElement); billFatcs.put(getNewGroupKey(billFatcValCode) ,billFatcValCode ); billFatcs.put(getNewGroupKey(billFatcValFormId) ,billFatcValFormId ); }catch(Exception e){ log.error("加载配置信息失败!->"+e.getMessage(), e); } } private Map getCostToMapp(String codeMap){ CorresElField findCode = cores.findCode(codeMap); // System.out.println("选用取值公式:"+JSONTool.toJson(findCode)); Map obj = JSONTool.toObj(JSONTool.toJson(findCode), Map.class); return obj; } private GroupKey getNewGroupKey(Map map){ return new GroupKey( String.valueOf(map.get(MD_CODE)), String.valueOf(map.get(ME_CODE)) ); } /** * 获得通用配置实体 * @param bmCode * @return */ public CorresElField getCorresElField(String bmCode){ for(CorresElField corresElField : cores.getCorresElFieldList()){ if(Objects.equals(corresElField.getBusinessMeaningCode(), bmCode)){ return corresElField; } } return null; } public Map> getBillFatcs() { return billFatcs; } public Map getMdCodeMaping() { return mdCodeMaping; } }