package com.changhong.epc.parsing.service.transition.billInfo; import com.changhong.epc.bean.tenant.master.MasterValue; import com.changhong.epc.constter.parsing.bill.ConstBill; import com.changhong.epc.constter.parsing.subassembly.billinfo.TransverterConstKey; import com.changhong.epc.constter.system.SystemClients; import com.changhong.epc.constter.tenant.TenantUrlConst; import com.changhong.epc.parsing.mapper.tenant.MasterValueMapper; import com.changhong.epc.parsing.mapper.tenant.master.MasterDefineMapper; import com.changhong.epc.parsing.service.transition.Transverter; import com.changhong.epc.parsing.service.transition.billInfo.models.BillTransitionData; import com.changhong.epc.parsing.service.transition.billInfo.models.GroupKey; import com.changhong.epc.parsing.service.transition.billInfo.util.IGainValCodeTranche; import com.changhong.epc.parsing.service.transition.billInfo.util.impl.GainValCodeTranche; import com.iemsoft.framework.cloud.core.tools.JSONTool; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import com.iemsoft.framework.cloud.core.tools.StringUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.ui.ModelMap; import javax.annotation.Resource; import java.util.*; @Slf4j public abstract class AbstractTransverterBillInfo implements Transverter, ConstBill, TransverterConstKey, SystemClients { /* 加载配置表数据 */ @Resource(name="billTransitionData") protected BillTransitionData billTransitionData; protected IGainValCodeTranche gainValCodeTranche; @Resource protected MasterValueMapper masterValueMapper; @Resource protected MasterDefineMapper masterDefineMapper; protected Map mdCodeMaping; protected List billFatchValFormula; protected List billFatchVal; protected Map> billFatcs; protected String costTypeMdCode; void init (){ billTransitionData.initData(); billFatcs = billTransitionData.getBillFatcs(); mdCodeMaping = billTransitionData.getMdCodeMaping(); String defineCode=mdCodeMaping.get(TB_BILLFATCHVALFORMULA); // System.out.println("主数据code为:"+defineCode); billFatchValFormula = getMasterValue(defineCode); String defineCode2=mdCodeMaping.get(TB_BILLFATCHVAL); billFatchVal = getMasterValue(defineCode2); costTypeMdCode = mdCodeMaping.get(COST_TYPE); this.gainValCodeTranche = SpringUtil.getBean(GainValCodeTranche.class); /** * 初始化 默认不缺失主数据 */ gainValCodeTranche.initData(); } protected List>> findMasterValueByOMCode(String code, String formId){ List> r = new ArrayList<>(); List> r2 = new ArrayList<>(); List>> rs = new ArrayList<>(); List> transverterData = transverterData(billFatchValFormula , mdCodeMaping.get(TB_BILLFATCHVALFORMULA) , line -> line.get(BILL_FATC_FORMID) == null ? false : formId.matches( StringUtil.trim(Objects.toString(line.get(BILL_FATC_FORMID)).replace("*", ".*"))) ); for (Map map : transverterData) { if(Objects.equals(code, map.get(BILL_FATC_CCODE))){ r.add(map); } } List> transverterData2 = transverterData(billFatchVal , mdCodeMaping.get(TB_BILLFATCHVAL) , line -> line.get(BILL_FATC_VAL_FORMID) == null ? false : formId.matches( StringUtil.trim(Objects.toString(line.get(BILL_FATC_VAL_FORMID)).replace("*", ".*"))) ); for (Map map : transverterData2) { if(Objects.equals(code, map.get(BILL_FATC_VAL_CODE))){ r2.add(map); } } rs.add(r); rs.add(r2); return rs; } /** * 对查询出的数据进行 * [ * {"key":"value"}, * {"key":"value"} * ] * @Title: transverterData * @param @param billFatch * @param @return 设定文件 * @return List> 返回类型 * @throws */ public List> transverterData(List billFatch,String mdCode, LineFilter lineFilter){ List> dimensionality = new ArrayList<>(); Integer temp = -1; Map map = null; if(ObjectUtil.notEmpty(billFatch)) { for (MasterValue val : billFatch) { if (temp == -1) { temp = val.getRowNo(); map = new HashMap<>(); } if (!Objects.equals(temp, val.getRowNo())) { if (map != null && lineFilter.filter(map)) { dimensionality.add(map); } map = null; temp = val.getRowNo(); map = new HashMap<>(); } if (Objects.equals(temp, val.getRowNo())) { try { Map tempLog = billFatcs.get(new GroupKey(mdCode, val.getEleCode())); // System.out.println(tempLog.get(BUS_CODE)); // System.out.println(val.getEleValue()); map.put( String.valueOf(tempLog.get(BUS_CODE)), val.getEleValue() == null ? "" : val.getEleValue() ); } catch (Exception e) { log.debug("配置表没有对应的" + val); } } temp = val.getRowNo(); } } if(map != null && lineFilter.filter(map)) { dimensionality.add(map); } return dimensionality; } /** * 查询可编辑主数据值 * */ public List getMasterValue(String defineCode){ //获取主数据值 List mList = new ArrayList(); Object data= billTransitionData.getTenantPostRest(TenantUrlConst.REST_TENANT_MASTERVALUE_SELECTLIST,new ModelMap("defineCode",defineCode)); if(Objects.isNull(data)){ return mList; } List resList = JSONTool.toList(JSONTool.toJson(data),Map.class); //转换 resList.stream().forEach(c->{ Integer id = Integer.parseInt(Objects.toString(c.get("id"))); c.remove("id"); c.keySet().stream().forEach(j->{ MasterValue mv = new MasterValue(); mv.setDefineCode(defineCode); mv.setEleCode(Objects.toString(j,"")); mv.setEleValue(Objects.toString(c.get(j),"")); mv.setRowNo(id); mList.add(mv); }); }); // System.out.println("最终数据----------------------》"+ JSONTool.toJson(mList)); return mList; } public interface LineFilter{ boolean filter(Map line); } }