package com.changhong.epc.form.execute.impl; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import com.changhong.autoform.entity.ProcessBudget; import com.changhong.epc.bean.form.CpnVal; import com.changhong.epc.bean.form.Fieldsets; import com.changhong.epc.bean.form.FormType; import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode; import com.changhong.epc.form.execute.BudgetRecord; import com.changhong.epc.form.execute.IFormOthersOperation; import com.changhong.epc.form.execute.IProcessBudgetBack; 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 lombok.extern.slf4j.Slf4j; /** * * 一个预算单 1000元 * 1. 申请100元 —— 回写预算 900 * 2. 报销200元 __ 加会报销单对应的申请单 900+100 - 200 = 800元 为负数 抛异常 * 3. 报销单直接选择预算 直接扣除预算 * * 每一次操作都要记录log * @param processBudget */ @Slf4j public class ProcessBudgetBack implements IProcessBudgetBack, BudgetBusinessMeaningCode { private MainLogic mainLogic; // @Resource private IFormOthersOperation formOthersOperation = SpringUtil.getBean(IFormOthersOperation.class); // = new FormOthersOperationImpl(); /** * 子表单 中间结构 对应自定义表单 */ private Fieldsets fieldsets = new Fieldsets(); private String costType; private Boolean sjys = true; public ProcessBudgetBack(MainLogic mainLogic) { this.mainLogic = mainLogic; } @Override public BudgetRecord exeBudget(List budgetRecords, ProcessBudget processBudget) { BudgetRecord exeBasic = exeBasic(budgetRecords,processBudget); if(sjys && ( exeBasic.getProcessBudget() !=null && exeBasic.getProcessBudget().getFormId() != null)) { sjys = false; // System.out.println("exeBasic.getProcessBudget(): "+exeBasic.getProcessBudget()); exeBudget(budgetRecords, exeBasic.getProcessBudget()); } return null; } @Override public BudgetRecord exeExpense(List budgetRecords, ProcessBudget processBudget) { BudgetRecord exeBasic = exeBasic(budgetRecords,processBudget); this.sjys = false; if(formOthersOperation.getBillType(exeBasic.getProcessBudget()) == FormType.YS){ exeBudget(budgetRecords, exeBasic.getProcessBudget()); } else{ exeApply(budgetRecords, exeBasic.getProcessBudget()); } return null; } private BudgetRecord exeBasic1(List budgetRecords, ProcessBudget processBudget){ return null; } private BudgetRecord exeBasic(List budgetRecords, ProcessBudget processBudget){ Fieldsets formFieldProperty = formOthersOperation.getFormFieldProperty(processBudget); List mainCpn = formFieldProperty.getMainCpn(); List subCpn = new ArrayList<>(); for(CpnVal subCpnValKey : formFieldProperty.getSubform().keySet()){ if(Objects.equals(subCpnValKey.getAlias(), BUDGET_SUB_FROM)){ subCpn = formFieldProperty.getSubform().get(subCpnValKey); } } BudgetRecord budgetRecord = new BudgetRecord(); // budgetRecord.setType(FormType.SQ); /** * defeated */ FormType billType = FormType.YS; //formOthersOperation.getBillType(budgetRecord.getProcessBudget()); processBudget.setCostType(billType.toString()); budgetRecord.setAtProcessBudget(processBudget); /* * 当前详细 */ Map fromInfo = formOthersOperation.getFromInfo(processBudget); boolean flg = false; for (CpnVal cpnVal : mainCpn) { // 引用上级表单 if(Objects.equals(cpnVal.getTagType(), "mytext")){ try { if(Objects.equals(processBudget.getCostType(),costType)){ List map = null; map = JSONTool.toList(findFormCpnInfo(fromInfo,cpnVal.getAlias()), Map.class); budgetRecord.setProcessBudget(cpnVal.getChooseForm()); budgetRecord.getProcessBudget().setAlias(cpnVal.getAlias()); flg = formOthersOperation.getBillType(budgetRecord.getProcessBudget()) == FormType.YS ? true : false; if(flg){ List dataRowNumbers = new ArrayList<>(); map.forEach(s->{ dataRowNumbers.add(Integer.parseInt(s.get(DATAROWNUMBER).toString())); }); boolean addOfType = mainLogic.addOfType(FormType.YS, dataRowNumbers); if(!addOfType){ Integer dataRow = mainLogic.findOfTypeEques(FormType.YS); budgetRecord.getProcessBudget().setDataRowNUm( dataRow ); // break outer; } }else{ budgetRecord.getProcessBudget().setDataRowNUm( Integer.valueOf(map.get(0).get(DATAROWNUMBER).toString()) ); } budgetRecord.setCpnVal(cpnVal); // 查询表单数据信息 budgetRecord.setValue(formOthersOperation.getFromInfo(budgetRecord.getProcessBudget())); } } catch (Exception e) { } } // 报销金额 if(Objects.equals(cpnVal.getAlias(), EXPEND_USE_MONEY)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; mainLogic.setXyMoney(budgetRecord.getMoney().money); } // 获得申请金额 if(Objects.equals(cpnVal.getAlias(), APPLY_USE_MONEY)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; mainLogic.setXyMoney(budgetRecord.getMoney().money); } // 获得预算余额 if(Objects.equals(cpnVal.getAlias(), BUDGET_ITEM_BALANCE)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; mainLogic.setXyMoney(budgetRecord.getMoney().money); } // 获得预算总额 if(Objects.equals(cpnVal.getAlias(), BUDGET_ITEM_MONEY)){ budgetRecord.getSumMoney().alias = cpnVal.getAlias(); budgetRecord.getSumMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; } if(flg){ if(!mainLogic.getFlog()){ budgetRecord.getMoney().money = mainLogic.getEachMoney(); log.debug("当前金额: "+budgetRecord.getMoney().money); break; } } if(flg){ if(!mainLogic.getFlog()){ //budgetRecord.getMoney().money = mainLogic.getEachMoney(); //log.debug("当前金额: "+mainLogic.getEachMoney()); }else{ //Object obj = fromInfo.get("ysfp"); //String[] split = Objects.toString(obj, "").split(","); List split = new ArrayList<>(); split.add(budgetRecord.getMoney().money.toString()); mainLogic.setXyMoney(budgetRecord.getMoney().money); //mainLogic.setPzMoney(Arrays.asList(split)); mainLogic.setPzMoney(split); } } } budgetRecords.add(budgetRecord); return budgetRecord; } @Override public BudgetRecord exeApply(List budgetRecords, ProcessBudget processBudget) { this.sjys = false; BudgetRecord budgetRecord = exeBasic(budgetRecords,processBudget); exeBudget(budgetRecords, budgetRecord.getProcessBudget()); return null; } public String findFormCpnInfo(Map fromInfo,String alias){ if(fromInfo == null){ return "0"; } return Objects.toString(fromInfo.get(alias), "0"); } /** * */ @Override public BudgetRecord exeBasics(List budgetRecords, ProcessBudget processBudget){ List mainCpn = formOthersOperation.getFormFieldProperty(processBudget).getMainCpn(); BudgetRecord budgetRecord = new BudgetRecord(); FormType billType = formOthersOperation.getBillType(budgetRecord.getProcessBudget()); processBudget.setCostType(billType.toString()); // budgetRecord.setType(FormType.SQ); budgetRecord.setAtProcessBudget(processBudget); /* * 当前详细 */ Map fromInfo = formOthersOperation.getFromInfo(processBudget); if(ObjectUtil.empty(mainCpn)){ mainCpn = new ArrayList<>(); } for (CpnVal cpnVal : mainCpn) { // 引用上级表单 if(Objects.equals(cpnVal.getTagType(), "mytext")){ try { if(Objects.equals(processBudget.getCostType(),costType)){ budgetRecord.setProcessBudget(cpnVal.getChooseForm()); budgetRecord.getProcessBudget().setDataRowNUm(null); budgetRecord.getProcessBudget().setAlias(cpnVal.getAlias()); } budgetRecord.setCpnVal(cpnVal); // 查询表单数据信息 // budgetRecord.setValue(formOthersOperation.getFromInfo(budgetRecord.getProcessBudget())); } catch (Exception e) { } } // 报销金额 if(Objects.equals(cpnVal.getAlias(), EXPEND_USE_MONEY)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; } // 获得申请金额 if(Objects.equals(cpnVal.getAlias(), APPLY_USE_MONEY)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; } // 获得预算余额 if(Objects.equals(cpnVal.getAlias(), BUDGET_ITEM_BALANCE)){ budgetRecord.getMoney().alias = cpnVal.getAlias(); budgetRecord.getMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; } // 获得预算总额 if(Objects.equals(cpnVal.getAlias(), BUDGET_ITEM_MONEY)){ budgetRecord.getSumMoney().alias = cpnVal.getAlias(); budgetRecord.getSumMoney().money = Double.valueOf( findFormCpnInfo(fromInfo, cpnVal.getAlias()) ); budgetRecord.getSumMoney().oldMoney = budgetRecord.getSumMoney().money; } } budgetRecords.add(budgetRecord); return budgetRecord; } }