package com.changhong.epc.admin.service.site.impl;
|
|
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.admin.MasterValueToCode;
|
import com.changhong.epc.bean.tenant.master.CodeAndAlias;
|
import com.changhong.epc.bean.tenant.master.MasterDefine;
|
import com.changhong.epc.bean.tenant.master.MasterValue;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.tenant.TenantUrlConst;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
@Service("masterDefaultMappingServiceImpl")
|
public class MasterDefaultMappingServiceImpl implements MasterDefaultMappingService, TenantUrlConst, SystemClients{
|
|
@Resource
|
private MasterElementMappingMapper masterElement;
|
|
@Resource
|
private MasterDefaultMappingMapper masterDefault;
|
|
@Override
|
public List<Map<String,String>> selectCode(MasterDefine master) {
|
List<CodeAndAlias> param = master.getParams();
|
MasterDefaultMapping mdm = masterDefault.selectMaster(master.getCode());
|
if(mdm!=null){
|
String code = null;
|
String value = null;
|
List<String> list1 = null;
|
if(!ObjectUtil.empty(master.getDef2())){
|
list1 = JSONTool.toList(master.getDef2(),String.class);
|
}
|
List<MasterElementMapping> list = masterElement.getField(mdm.getId(), param);
|
for(MasterElementMapping o:list){
|
if(Objects.equals(o.getMeCode(),master.getDef4())){
|
code = o.getMeCode();
|
}else if(Objects.equals(o.getMeCode(),master.getDef5())){
|
value = o.getMeCode();
|
}
|
}
|
return masterDefault.selectValue(mdm.getTableName(), list,master.getDef1(),list1,code,value,master.getDef4(),master.getDef5());
|
}
|
return Collections.EMPTY_LIST;
|
}
|
|
@Override
|
public MasterDefaultMapping selectMasterDefault(String code) {
|
return masterDefault.selectMaster(code);
|
}
|
|
@Override
|
public List<MasterElementMapping> selectMasterElement(MasterDefaultMapping mdm ) {
|
List<MasterElementMapping> list = new ArrayList<>();
|
if(mdm!=null){
|
list = masterElement.getField(mdm.getId(),mdm.getParams());
|
}
|
return list;
|
}
|
|
|
/**
|
* value转code
|
*/
|
@Override
|
public MasterValue ValueConCode(MasterValueToCode con) {
|
MasterValue mv = new MasterValue();
|
con.setCodeFlied(masterElement.getFieldOne(con.getEleCode(), con.getMId()));
|
con.setValueFlied(masterElement.getFieldOne(con.getEleValue(), con.getMId()));
|
mv.setEleValue(masterDefault.ValueConCode(con));
|
return mv;
|
}
|
|
@Override
|
public MasterValue CodeConValue(MasterValueToCode con) {
|
MasterValue mv = new MasterValue();
|
con.setCodeFlied(masterElement.getFieldOne(con.getEleCode(), con.getMId()));
|
con.setValueFlied(masterElement.getFieldOne(con.getEleValue(), con.getMId()));
|
mv.setEleValue(masterDefault.CodeConValue(con));
|
return mv;
|
}
|
|
@Override
|
public Map<String,String> getFieldOrCode(String code) {
|
MasterDefaultMapping master = masterDefault.selectMaster(code);
|
List<MasterElementMapping> list = masterElement.getField(master.getId(),null);
|
Map<String,String> map = new HashMap<>();
|
list.stream().forEach(o->
|
map.put(o.getMeCode(),o.getTableField()));
|
return map;
|
}
|
|
@Override
|
public int insertMasterDefault(MasterDefaultMapping mdm) {
|
mdm.initParam();
|
if(Objects.isNull(mdm.getId())){
|
return masterDefault.insert(mdm);
|
}else{
|
MasterDefaultMapping old=masterDefault.selectMasterById(mdm.getId());
|
if(!Objects.equals(old.getId(), mdm.getId())){
|
return masterDefault.insert(mdm);
|
}
|
return 0;
|
}
|
}
|
|
@Override
|
public int updateMasterDefault(MasterDefaultMapping mdm) {
|
mdm.initParam();
|
return masterDefault.updateMasterDefaultMapping(mdm);
|
}
|
|
@Override
|
public int insertMasterElement(List<MasterElementMapping> masterElementMapping) {
|
int count=0;
|
if(ObjectUtil.empty(masterElementMapping)){
|
return count;
|
}
|
for (MasterElementMapping ele : masterElementMapping){
|
ele.initParam();
|
count+=masterElement.insert(ele);
|
}
|
return count;
|
}
|
|
@Override
|
public int updateMasterElement(MasterElementMapping masterElementMapping) {
|
masterElementMapping.initParam();
|
return masterElement.updateMasterElementMapping(masterElementMapping);
|
}
|
|
@Override
|
public List<MasterDefaultMapping> selectMasterDefMappingList() {
|
return masterDefault.selectAllDefAndEle();
|
}
|
|
|
}
|