package com.changhong.epc.parsing.service.master.impl; 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.MasterList; import com.changhong.epc.bean.tenant.sunCloud.MasterFtp; import com.changhong.epc.constter.admin.AdminUrlConst; import com.changhong.epc.constter.base.loop.LoopBaseService; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.system.run.EpcRestInterface; import com.changhong.epc.parsing.mapper.tenant.MasterValueMapper; import com.changhong.epc.parsing.mapper.tenant.master.MasterDefineMapper; import com.changhong.epc.parsing.mapper.tenant.master.MasterElementMapper; import com.changhong.epc.parsing.service.master.MasterFtpService; import com.esotericsoftware.minlog.Log; 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.redis.annotation.CacheRm; import com.iemsoft.framework.cloud.ribbon.RestInterface; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service("masterFtpServiceImpl") public class MasterFtpServiceImpl implements MasterFtpService,SystemClients, LoopBaseService { @Resource private MasterDefineMapper masterDefineMapper; @Resource private MasterElementMapper masterElementMapper; @Resource private MasterValueMapper masterValueMapper; private static final String MASTER_VALUE = "MASTER_VALUE"; @Override public int updateMasterFtp(MasterFtp ftp) { //暂时不需要返回 RPC(AdminUrlConst.REST_ADMIN_JSON_UPDATEFTPPATH,ftp); Log.debug("清空主数据缓存"); this.removeMasterValue(); return 1; } @Override public List selectMasterFtp() { Object o = RPC(AdminUrlConst.REST_ADMIN_JSON_FINDFTPPATH,null); return o!=null?JSONTool.toList(JSONTool.toJson(o),MasterFtp.class):new ArrayList(); } public static Object RPC(String url,Object o){ RestInterface restInterface = SpringUtil.getBean(SERVER_ADMIN.getBeanName(), RestInterface.class); Object data = restInterface.post(url, o, ResMsg.class, EpcRestInterface.getEpcHeads()).getData(); return data; } @Override public Integer synMaster(MasterList master) { Object o = RPC(AdminUrlConst.REST_ADMIN_ADDMASTERLIST,master); return o!=null?Integer.parseInt(o.toString()):-1; } /** * 同步主数据定义 * @param master * @return */ @Override public int checkMasterDefine(MasterDefine master) { //判断主数据是否存在,不存在添加 if(masterDefineMapper.queryMaster(master.getCode())<=0){ master.setId(null); return masterDefineMapper.insertSelective(master); } return -1; } /** * 同步主数据元素 * @param eleList * @return */ @Override public int checkMasterElement(List eleList,String code) { Map map = new HashMap(); Log.debug("元素集合:"+ JSONTool.toJson(eleList)); eleList.stream().forEach(o->map.put(o.getCode(),o.getName())); List list = masterElementMapper.selectEle(code); //首先update list.stream().filter(li->map.get(li.getCode())!=null && !"".equals(map.get(li.getCode()))) .forEach(o->{ o.setName(map.get(o.getCode())); o.setDataStart(0); masterElementMapper.updateByPrimaryKey(o); map.remove(o.getCode()); }); //新增 eleList.stream().filter(li->map.get(li.getCode())!=null && !"".equals(map.get(li.getCode()))) .forEach( o->masterElementMapper.insert(o) ); return 1; } /** * 同步主数据value * @param valList * @return */ @Override public int checkMasterValue(List valList) { valList.stream().forEach(o->{ switch(o.getFlag()){ case "1": masterValueMapper.insert(o); break; case "2": if(masterValueMapper.selectByCode(o.getDefineCode(),o.getEleCode(),o.getRowNo())>0){ masterValueMapper.updateMasterVal(o); }else{ masterValueMapper.insert(o); } break; case "3": masterValueMapper.delMasterValue(o); break; } }); return 1; } @Override @CacheRm(value = MASTER_VALUE, company = false) public void removeMasterValue() { Log.debug("清空主数据缓存成功"); } @Override public int update(MasterFtp masterFtp) { return updateMasterFtp(masterFtp); } @Override public List list() { return selectMasterFtp(); } }