package com.changhong.epc.tenant.service.norm.impl.value; import com.alibaba.fastjson.TypeReference; import com.changhong.epc.bean.tenant.master.MasterEleValue; import com.changhong.epc.bean.tenant.master.MasterElement; import com.changhong.epc.bean.tenant.master.MasterValue; import com.changhong.epc.bean.tenant.master.extend.MasterDefinesExtend; import com.changhong.epc.constter.admin.AdminUrlConst; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper; import com.changhong.epc.tenant.service.norm.impl.SimplAbstractMasterTools; 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.stereotype.Service; import javax.annotation.Resource; import java.util.Objects; import java.util.Optional; /** * code,value互转方法 * @author DELL * */ @Service @Slf4j public class CodeConValue extends SimplAbstractMasterTools implements SystemClients, BaseConst { @Resource private MasterValueMapper masterValueMapper; //一维通用 @Override protected MasterValue adminOneDimensional(MasterDefinesExtend masterDefine, MasterEleValue p) { MasterValue master = new MasterValue(); String url = null; if(Objects.equals("code", p.getAlias())){ url = AdminUrlConst.VALUE_CODECONVAL; }else{ url = AdminUrlConst.VALUE_VALCONCODE; } RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class); Object data = restInterface.post(url, p, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); MasterValue masterValueAdmin = JSONTool.toObj(JSONTool.toJson(data), MasterValue.class); master.setEleValue(masterValueAdmin.getEleValue()); return master; } //二维通用 @Override protected MasterValue adminTwoDimensional(MasterDefinesExtend masterDefine, MasterEleValue p) { // this.setCodeValue(p); String code = masterDefine.getEleList().stream() .filter(me->Objects.equals(me.getAlias(), "code")) .findFirst() .map(MasterElement::getDefMapTalbeField) .orElse(null); String val = masterDefine.getEleList().stream() .filter(me->Objects.equals(me.getAlias(), "value")) .findFirst() .map(MasterElement::getDefMapTalbeField) .orElse(null); if(Objects.equals(p.getAlias(), "value")){ p.setInMeCode(code); p.setOutMeCode(val); }else{ p.setInMeCode(val); p.setOutMeCode(code); } p.setTableName(masterDefine.getDefMapTableName()); RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class); ResMsg data = (ResMsg) restInterface.post(AdminUrlConst.ADMIN_MASTER_CODECONVALUE , p , new TypeReference>(){}.getType() , EpcRestInterface.getEpcHeads()); return Optional.ofNullable(data).map(ResMsg::getData).orElse(null); } //租户一维 @Override protected MasterValue tenantOneDimensional(MasterDefinesExtend masterDefine, MasterEleValue p) { this.setCodeValue(p); MasterValue master = new MasterValue(); master.setEleValue(masterValueMapper.getVal(p).toString()); return master; } //租户二维 @Override protected MasterValue tenantTwoDimensional(MasterDefinesExtend masterDefine, MasterEleValue p) { String field = null; String conditionField = null; this.setCodeValue(p); for(MasterElement m:masterDefine.getEleList()){ if(Objects.equals(p.getInMeCode(), m.getCode())){ conditionField = m.getDefMapTalbeField(); }else if(Objects.equals(p.getOutMeCode(), m.getCode())){ field = m.getDefMapTalbeField(); } } MasterValue master = new MasterValue(); master.setEleValue(masterValueMapper.twoCodeValue(field, masterDefine.getDefMapTableName(), conditionField, p.getMvCode())); return master; } public void setCodeValue(MasterEleValue p){ masterValueMapper.selectCode(p.getDefineCode()) .stream() .filter(fi->!Objects.equals("", fi.getAlias()) && fi.getAlias()!=null) .forEach(o->{ if(Objects.equals("code", p.getAlias())){ if (o.getAlias().equals("code")) { p.setInMeCode(o.getCode()); } else if (o.getAlias().equals("value")) { p.setOutMeCode(o.getCode()); } }else{ if (o.getAlias().equals("value")) { p.setInMeCode(o.getCode()); } else if (o.getAlias().equals("code")) { p.setOutMeCode(o.getCode()); } } }); } }