package com.changhong.epc.admin.service.master.impl; import com.changhong.epc.admin.mapper.centen.corres.CorresElFieldMapper; import com.changhong.epc.admin.mapper.centen.master.MasterDefineMapper; import com.changhong.epc.admin.mapper.centen.master.MasterElementMapper; import com.changhong.epc.admin.mapper.centen.master.MasterValueMapper; import com.changhong.epc.admin.mapper.centen.site.MasterDefaultMappingMapper; import com.changhong.epc.admin.mapper.centen.site.MasterElementMappingMapper; import com.changhong.epc.admin.service.site.MasterDefaultMappingService; import com.changhong.epc.bean.admin.MasterDefaultMapping; import com.changhong.epc.bean.admin.MasterElementMapping; import com.changhong.epc.bean.count.MeInfo; 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.MasterValueListExtend; import com.changhong.epc.config.service.MasterValueService; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import org.springframework.stereotype.Service; import org.springframework.ui.ModelMap; import javax.annotation.Resource; import java.io.InputStream; import java.io.OutputStream; import java.util.*; @Service public class MasterValueServiceImpl implements MasterValueService { @Resource private MasterValueMapper masterValueMapper; @Resource private MasterElementMapper masterElementMapper; @Resource private MasterDefineMapper masterDefineMapper; @Resource private CorresElFieldMapper corresElFieldMapper; @Resource private MasterDefaultMappingMapper masterDefaultMappingMapper; @Resource private MasterElementMappingMapper memm; @Resource(name="masterDefaultMappingServiceImpl") private MasterDefaultMappingService masterDefault; @Override public List selectMasterValueListExtend(MasterValue masterValue) { List codes = null; if (!ObjectUtil.empty(masterValue.getDef2())) { codes = JSONTool.toList(masterValue.getDef2(), String.class); if (ObjectUtil.empty(codes)) { codes = null; } } MasterValueListExtend masterValueListExtend1 = masterValueMapper.selectMasterValueListExtend(masterValue.getDefineCode(), masterValue.getParams(), masterValue.getDef1(), codes, masterValue.getDef3()); List> list = masterValueListExtend1 != null ? masterValueListExtend1.getValues().getList() : Collections.EMPTY_LIST; if ("one".equals(masterValue.getFlag())) { list.stream().forEach(map -> { if (map.get(VALUE) != null && map.get(CODE) == null) { map.put(CODE, map.get(VALUE)); } if (map.get(VALUE) == null && map.get(CODE) != null) { map.put(VALUE, map.get(CODE)); } }); return list; } return list; } @Override public MasterValue CodeConVal(MasterEleValue masterEleValue) { MasterValue master = new MasterValue(); for (MasterElement met : masterValueMapper.selectCode(masterEleValue.getDefineCode())) { if (isCode(met.getAlias())) { masterEleValue.setInMeCode(met.getCode()); } else if (isValue(met.getAlias())) { masterEleValue.setOutMeCode(met.getCode()); } } master.setEleValue(masterValueMapper.getVal(masterEleValue).toString()); return master; } @Override public MasterValue ValConCode(MasterEleValue masterEleValue) { MasterValue master = new MasterValue(); String code = masterElementMapper.geteleCode(masterEleValue.getDefineCode(), CODE); String value = masterElementMapper.geteleCode(masterEleValue.getDefineCode(), VALUE); if (ObjectUtil.empty(code) || ObjectUtil.empty(value)) { master.setCodeFlag(false); return master; } for (MasterElement met : masterValueMapper.selectCode(masterEleValue.getDefineCode())) { if (met.getAlias().equals(VALUE)) { masterEleValue.setInMeCode(met.getCode()); } else if (met.getAlias().equals(CODE)) { masterEleValue.setOutMeCode(met.getCode()); } } master.setEleValue(masterValueMapper.getVal(masterEleValue).toString()); return master; } @Override public String getValString(String mdCode, String mecode, List params) { return masterValueMapper.getValString(mdCode, mecode, params); } @Override public String getMasterCode(MasterValue masterValue) { return masterValueMapper.getMasterCode(masterValue); } @Override public Object selectValueSeache(MasterValue masterValue) { Map map = new HashMap<>(); List list = masterValueMapper.selectValueSeache(masterValue.getDefineCode(), null, masterValue.getValue()); map.put("values", getMasterValue(list)); if (!ObjectUtil.empty(masterValue.getCodes()) && masterValue.getCodes().size() > 0) { List list1 = masterValueMapper.selectValueSeache(masterValue.getDefineCode(), masterValue.getCodes(), null); map.put("selectSeache", getMasterValue(list1)); } return map; } @Override public List getSelectValue(String defineCode) { return masterValueMapper.selectValue(defineCode); } @Override public Map getMasterValString(Map parm) { return new ModelMap(CODE, parm.get("masterCode")) .addAttribute(VALUE, masterValueMapper.getMasterValString(parm)); } @Override public String getValTwoDimensional(String defMapTableName, String defMapTalbeField, List params) { return masterValueMapper.getValTwoDimensional(defMapTableName, defMapTalbeField, params); } @Override public Object seacheValues(MasterValue m) { Map map = new HashMap<>(); map.put("values", masterValueMapper.seacherValues( m.getEleCode(),m.getEleValue(), m.getTableName(),null,m.getValue())); map.put("selectSeache", masterValueMapper.seacherValues( m.getEleCode(),m.getEleValue(), m.getTableName(),m.getCodes()!=null && m.getCodes().size()>0?m.getCodes():null,null)); return map; } @Override public int importExcel(InputStream inputStream, String name, String defineCode) { return 0; } @Override public void outTemplate(String defineCode, OutputStream os) { } @Override public Object selectValue(MasterValue masterValue) { return getSelectValue(masterValue.getDefineCode()); } public List selectMasterValueList(MasterValue masterValue){ MasterDefaultMapping masterDefaultMapping=masterDefaultMappingMapper.selectMaster(masterValue.getDefineCode()); if(Objects.isNull(masterDefaultMapping)){ return masterValueMapper.selectMasterValueList(masterValue); }else{ //映射表字段id List mvs=new ArrayList<>(); Integer eleMappingId=masterDefaultMapping.getId(); //二维表字段名字 List eleMap=memm.getFieldByMid(eleMappingId); List> masterVal=masterValueMapper.selectMaster2(masterDefaultMapping.getTableName(),eleMap); for(int i=0;i