package com.changhong.epc.config.service; 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.extend.MasterElementExtend; import com.google.common.base.Objects; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.StringUtil; import org.springframework.web.bind.annotation.RequestBody; import java.util.ArrayList; import java.util.Collections; import java.util.List; public abstract class MasterElementService { public static final String VALUE = "value"; public static final String CODE = "code"; public abstract List selectByCode(String defineCode); /** * 查询关联主数据 * @param master * @return */ public List selectCode(MasterEleValue master) { List masterList = new ArrayList(); this.getCode(masterList,this.selectByCode(master.getDefineCode()),master); return masterList; } /** * 递归查询 * @param masterList * @param master * @param elementList * @return */ public List getCode(List masterList,List elementList,MasterEleValue master){ MasterEleValue value = new MasterEleValue(); value.setDefineCode(master.getDefineCode()); value.setMvCode(master.getMvCode()); // System.out.println("当前关联主数据:"+ JSONTool.toJson(elementList)); if(ObjectUtil.empty(elementList) || !(VALUE.equals(elementList.get(0).getAlias()))){ // System.out.println("1------------------"); return null; } // System.out.println("for之前-----------------"); for(MasterElementExtend masters: elementList){ // System.out.println("第一次循环:"+ JSONTool.toJson(masters)); //判断一个字段是否包含两个主数据Code if(masters.getJoinMd()!=null){ String [] join = masters.getJoinMd().split(","); for(String jo : join){ // // System.out.println("进入分割"); if(jo!=null && jo.equals(master.getDefineCode())){ value.setInMeCode(masters.getCode()); } if (jo != null && !Objects.equal(jo, value.getDefineCode()) && !(CODE.equals(masters.getAlias()))) { value.setOutMeCode(masters.getCode()); MasterEleValue values = new MasterEleValue(); String s =this.getValFunc(value); // System.out.println(masters.getDefineCode()+"对应的值是:"+s); values.setMvCode(s); // System.out.println(JSONTool.toJson(values)); values.setDefineCode(jo); masterList.add(values); this.getCode(masterList, this.selectByCode(values.getDefineCode()), values); } } } //没有关联时跳出循环 if(masters.getJoinMd()==null && (StringUtil.isBlank(masters.getAlias()) || !(masters.getAlias().equals("value")))){ // System.out.println("2--------------------"); // System.out.println("masters------"+ JSONTool.toJson(masters)); break; } } return masterList; } //实现getval()函数调用 public abstract String getValFunc(MasterEleValue value); public abstract List elementInfos(MasterElement masterList); /** * * @param masterList * @return */ public List selectCodes(List 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; } /** * 制定code,value */ public abstract int updateAlias(@RequestBody MasterAlias alias); }