package com.changhong.epc.form.service.define.impl; import com.alibaba.fastjson.TypeReference; import com.changhong.autoform.entity.*; import com.changhong.autoform.mapper.define.impl.DefineMapperImpl; import com.changhong.epc.bean.tenant.master.CodeAndAlias; import com.changhong.epc.bean.tenant.master.MasterEleValue; import com.changhong.epc.bean.tenant.master.extend.MasterElementExtend; import com.changhong.epc.constter.admin.AdminUrlConst; import com.changhong.epc.constter.base.BaseConst; import com.changhong.epc.constter.cache.master.MasterCache; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.changhong.epc.constter.tenant.TenantUrlConst; import com.changhong.epc.form.service.define.MasterElementService; import com.iemsoft.framework.cloud.config.datasource.DynamicDataSource; import com.iemsoft.framework.cloud.core.base.ResMsg; import com.iemsoft.framework.cloud.core.exception.IEMRuntimeException; 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.Component; import org.springframework.ui.ModelMap; import java.sql.Connection; import java.sql.SQLException; import java.util.*; @Component("masterElementServiceImplExtend") @Slf4j public class MasterElementServiceImplExtend extends DefineMapperImpl implements SystemClients,MasterElementService ,BaseConst, MasterCache { @Override protected Connection getConnection() { // MybatisTool.initDataSource(); try { return SpringUtil.getBean(DynamicDataSource.class).getConnection(); } catch (SQLException e) { log.error(e.getMessage(), e); throw new IEMRuntimeException(e.getMessage()); } } /** * 重写查询主数据值方法 */ // @CacheSave(value = MASTER_VALUE, tenantAndCompany = true) public List selectCreateMainValue(MasterValue masterValue){ // // System.out.println("进入方法体了"); Map map = new HashMap<>(); map.put("defineCode", masterValue.getDefineCode()); map.put("def1", masterValue.getIsAll()); map.put("def2", masterValue.getCodes()); map.put("def3", masterValue.getValue()); List params = new ArrayList<>(); { if(masterValue.getEleName() != null){ params.add(new CodeAndAlias(masterValue.getEleName(), "value")); } } { if(masterValue.getParentCode() != null){ params.add(new CodeAndAlias(masterValue.getParentCode(), "pid")); } } { if(masterValue.getELE_CODE() != null){ params.add(new CodeAndAlias(masterValue.getELE_CODE(), "code")); } //如果name == code 在查询时候就把另一个值放到这个里面 if(Objects.equals(masterValue.getEleName(), masterValue.getELE_CODE())){ map.put("flag", "one"); } } map.put("eleCode", masterValue.getELE_CODE()); map.put("eleValue", masterValue.getEleName()); map.put("params", params); ResMsg> data = (ResMsg>)SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class) .post(TenantUrlConst.REST_TENANT_MASTERVALUE_SELECTLIST , map ,new TypeReference>>(){}.getType() , EpcRestInterface.getEpcHeads()); return data.getData(); } // @CacheSave(value = MASTER_VALUE, tenantAndCompany = true) public CodeAndValueBean masterValueCodeToName(MasterValue masterValue) { Map map = new HashMap<>(); map.put("defineCode", masterValue.getDefineCode()); map.put("masterCode", masterValue.getVariableField()); map.put("eleCode", masterValue.getELE_CODE()); map.put("eleValue", masterValue.getEleName()); map.put("tenantId", masterValue.getTenantID()); MasterEleValue masterEleValue = new MasterEleValue(); masterEleValue.setDefineCode(masterValue.getDefineCode()); masterEleValue.setMvCode(masterValue.getELE_CODE()); ResMsg data = (ResMsg) SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class) .post(TenantUrlConst.MASTER_TENANT_GETMASTERVAL , map , new TypeReference>(){}.getType() , EpcRestInterface.getEpcHeads()); return data.getData(); } /** * 查询所有主数据 */ public List selectAllMainDef(MasterData materData){ List list = super.selectAllMainDef(materData); Object o = this.masterRPC(AdminUrlConst.MASTER_SELECTALLMASTER,materData); if(o!=null){ if(list == null) { list = new ArrayList(); } List li = JSONTool.toList(JSONTool.toJson(o),MasterDefineEntity.class); if(li.size()>0) { list.addAll(li); } } return list; } public static Object masterRPC(String url,Object map){ RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class); Object data = restInterface.post(url, map, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } public List searchMainElement(MasterData materData) { List list = super.searchMainElement(materData); if(list == null || list.size()<=0){ List li = new ArrayList<>(); Object o = MasterElementServiceImplExtend.masterRPC(AdminUrlConst.ELEMENT_SELECTBYCODE, new ModelMap("defineCode",materData.getCode()).addAttribute("tenantId",materData.getTenantID() )); List l = JSONTool.toList(JSONTool.toJson(o),MasterElementExtend.class); if(l!=null){ l.stream().forEach(c->{ MasterElementEntity a = new MasterElementEntity(); a.setDefine_code(c.getDefineCode()); a.setAlias(c.getAlias()); a.setDel_flag(c.getDelFlag()); a.setName(c.getName()); a.setCode(c.getCode()); a.setMust_flag(c.getMustFlag()); a.setLen(c.getLen()); a.setType(c.getType()); a.setId(c.getId()); li.add(a); }); } return li; }else{ return list; } } }