package com.changhong.epc.tenant.service.norm.impl;
|
|
import com.changhong.epc.bean.admin.MasterDefaultMapping;
|
import com.changhong.epc.bean.admin.MasterElementMapping;
|
import com.changhong.epc.bean.tenant.master.MasterDefine;
|
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.config.service.MasterDefineService;
|
import com.changhong.epc.constter.admin.AdminUrlConst;
|
import com.changhong.epc.constter.system.SystemClients;
|
import com.changhong.epc.constter.system.run.EpcRestInterface;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterDefineMapper;
|
import com.changhong.epc.tenant.mapper.tenant.norm.MasterValueMapper;
|
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 org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
@Service("masterDefineServiceImpl")
|
public class MasterDefineServiceImpl extends MasterDefineService implements SystemClients {
|
|
@Resource
|
private MasterDefineMapper masterDefineMapper;
|
|
@Resource
|
private MasterValueMapper masterValueMapper;
|
|
/**
|
* 查询通用和租户主数据
|
* @param masterDefine
|
* @return
|
*/
|
public List<MasterDefine> selectByQuery(MasterDefine masterDefine) {
|
List<MasterDefine> masterDefines = masterDefineMapper.selectByQuery(null);
|
Object o = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTBYQUERY,masterDefine);
|
if(masterDefines == null) {
|
masterDefines = new ArrayList<MasterDefine>();
|
}
|
if(o!= null){
|
List<MasterDefine> list = JSONTool.toList(JSONTool.toJson(o),MasterDefine.class);
|
if(list.size()>0) {
|
masterDefines.addAll(list);
|
}
|
}
|
return masterDefines;
|
}
|
|
public List<MasterDefine> selectAllMaster() {
|
Object o = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTALLMASTER,new HashMap<String,String>());
|
// System.out.println("通用主数据:"+JSONTool.toJson(o));
|
List<MasterDefine> masterDefines = masterDefineMapper.selectAll();
|
//添加通用主数据
|
if(o!=null){
|
if(masterDefines == null) {
|
masterDefines = new ArrayList<MasterDefine>();
|
}
|
|
List<MasterDefine> list = JSONTool.toList(JSONTool.toJson(o),MasterDefine.class);
|
if(list.size()>0) {
|
masterDefines.addAll(list);
|
}
|
}
|
return masterDefines;
|
}
|
|
/**
|
* 按名称或者code查询数据定义
|
* @param masterDefine
|
* @return
|
*/
|
@Override
|
public List<MasterDefinesExtend> selectEle(MasterDefine masterDefine) {
|
List<MasterDefinesExtend> masterDefinesExtends = masterDefineMapper.selectEle(masterDefine);
|
Object o = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTELE, masterDefine);
|
if(masterDefinesExtends == null) {
|
masterDefinesExtends = new ArrayList<MasterDefinesExtend>();
|
}
|
//按条件去查询通用
|
if(o!= null){
|
List<MasterDefinesExtend> list = JSONTool.toList(JSONTool.toJson(o),MasterDefinesExtend.class);
|
if(list.size()>0) {
|
masterDefinesExtends.addAll(list);
|
}
|
}
|
return masterDefinesExtends;
|
}
|
|
@Override
|
public List<MasterDefinesExtend> selectName(MasterDefine master) {
|
List<MasterDefinesExtend> masterDefinesExtends = masterDefineMapper.selectName(master);
|
Object o = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTNAME, master);
|
if(masterDefinesExtends == null) {
|
masterDefinesExtends = new ArrayList<MasterDefinesExtend>();
|
}
|
//按条件去查询通用
|
if(o!= null){
|
List<MasterDefinesExtend> list = JSONTool.toList(JSONTool.toJson(o),MasterDefinesExtend.class);
|
if(list.size()>0) {
|
masterDefinesExtends.addAll(list);
|
}
|
}
|
return masterDefinesExtends;
|
}
|
|
public Integer queryMaster(String defineCode) {
|
return masterDefineMapper.queryMaster(defineCode);
|
}
|
|
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;
|
}
|
|
@Transactional
|
public int synMaster(MasterDefine master) {
|
Object data = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTMASTERDEFAULT,master);
|
MasterDefaultMapping mdm = JSONTool.toObj(JSONTool.toJson(data),MasterDefaultMapping.class);
|
int count = -1;
|
if(mdm ==null){
|
return -1;
|
}
|
mdm.setParams(null);
|
Object data2 = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTMASTERELEMENT,mdm);
|
List<MasterElementMapping> lists = JSONTool.toList(JSONTool.toJson(data2), MasterElementMapping.class);
|
Map<String,String> map = new HashMap<>();
|
lists.stream().forEach(o->map.put(o.getMeCode(),o.getTableField()));
|
List<MasterValue> list = masterValueMapper.selectValue1(master.getCode());
|
int rowN = 0;
|
int flag = 0;
|
List<Map<String,String>> billList = new ArrayList<>();
|
Map<String,String> m = new HashMap<String,String>();
|
billList.add(m);
|
for(MasterValue mv:list){
|
rowN = mv.getRowNo();
|
m.put(map.get(mv.getEleCode()),mv.getEleValue());
|
if(rowN!=flag && flag!=0){
|
billList.add(m);
|
m = new HashMap<String,String>();
|
}
|
flag = mv.getRowNo();
|
}
|
billList.stream().forEach(o->masterDefineMapper.addMasterValue(o,mdm.getTableName()));
|
return 1;
|
}
|
|
public List<MasterDefine> selectAllConfigM(MasterDefine ma) {
|
Object o = MasterDefineServiceImpl.masterRPC(AdminUrlConst.MASTER_SELECTALLMASTER,ma);
|
// System.out.println("通用主数据:"+JSONTool.toJson(o));
|
List<MasterDefine> masterDefines = masterDefineMapper.select(ma);
|
//添加通用主数据
|
if(o!=null){
|
if(masterDefines == null) {
|
masterDefines = new ArrayList<MasterDefine>();
|
}
|
|
List<MasterDefine> list = JSONTool.toList(JSONTool.toJson(o),MasterDefine.class);
|
if(list.size()>0) {
|
masterDefines.addAll(list);
|
}
|
}
|
return masterDefines;
|
}
|
|
|
|
}
|