package com.changhong.epc.tenant.service.norm.impl;
|
|
import com.changhong.epc.bean.tenant.master.MasterAlias;
|
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.MasterElementExtend;
|
import com.changhong.epc.config.service.MasterElementService;
|
import com.changhong.epc.constter.admin.AdminUrlConst;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterDefineMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterElementMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper;
|
import com.iemsoft.framework.cloud.core.tools.JSONTool;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.List;
|
import java.util.Objects;
|
@Service("masterElementServiceImpl")
|
public class MasterElementServiceImpl extends MasterElementService {
|
|
@Resource
|
private MasterElementMapper masterElementMapper;
|
|
@Resource
|
private MasterDefineMapper masterDefineMapper;
|
|
/**
|
* MasterValueMapper引用
|
*/
|
@Resource
|
private MasterValueMapper masterValueMapper;
|
|
public static final String VALUE = "value";
|
|
public static final String CODE = "code";
|
|
|
@Override
|
public List<MasterElementExtend> selectByCode(String defineCode) {
|
// int o = masterDefineMapper.queryMaster(defineCode);
|
// if(o>0){
|
return masterElementMapper.selectByCode(defineCode);
|
// }else{
|
// Object obj = MasterDefineServiceImpl.masterRPC(AdminUrlConst.ELEMENT_SELECTBYCODE,new ModelMap("defineCode",defineCode) );
|
// return obj!= null?JSONTool.toList(JSONTool.toJson(obj), MasterElementExtend.class):null;
|
// }
|
}
|
|
|
/**
|
* 查询所有主数据关联
|
*/
|
@Override
|
public List<MasterEleValue> selectCode(MasterEleValue master) {
|
List<MasterEleValue> masterList = new ArrayList<MasterEleValue>();
|
this.getCode(masterList,this.selectByCode(master.getDefineCode()),master);
|
|
return masterList;
|
}
|
|
@Override
|
public String getValFunc(MasterEleValue value) {
|
int o = masterDefineMapper.queryMaster(value.getDefineCode());
|
if(o>0){
|
return Objects.toString(masterValueMapper.getVal(value),"");
|
}else{
|
Object obj = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_VALUE_GETVAL,value );
|
return obj!=null?JSONTool.toObj(JSONTool.toJson(obj), MasterValue.class).getValue():"";
|
}
|
|
}
|
|
|
@Override
|
public List<MasterElement> elementInfos(MasterElement masterList) {
|
return masterElementMapper.elementInfos(masterList.getDefineCode());
|
}
|
|
|
@Override
|
public List<MasterEleValue> selectCodes(List<MasterEleValue> masterList) {
|
if(ObjectUtil.empty(masterList)){
|
return Collections.EMPTY_LIST;
|
}
|
for(MasterEleValue o : masterList){
|
if(o.getDefineCode().equals("") || o.getDefineCode() == null){
|
continue;
|
}else{
|
o.setJoinDefines(this.selectCode(o));
|
}
|
};
|
return masterList;
|
}
|
|
@Override
|
@Transactional
|
public int updateAlias(MasterAlias alias) {
|
String defCode = alias.getDefineCode();
|
int o = masterDefineMapper.queryMaster(defCode);
|
if(o>0){
|
int count = -1;
|
//清空原有alias
|
masterElementMapper.updateAlias(defCode, null, "");
|
//修改新得元素code
|
if(alias.getCode()!=null && !"".equals(alias.getCode())){
|
count += masterElementMapper.updateAlias(defCode, alias.getCode(), "code");
|
}
|
//修改新的得value
|
if(alias.getName()!=null && !"".equals(alias.getName())){
|
count += masterElementMapper.updateAlias(defCode, alias.getName(), "value");
|
}
|
return count;
|
}else{
|
Object ob = MasterDefineServiceImpl.masterRPC(AdminUrlConst.ELEMENT_UPDATEALIAS,alias);
|
return Integer.parseInt(Objects.toString(ob, "-1"));
|
}
|
}
|
|
}
|