package com.changhong.epc.form.service.budget.department.impl; import com.alibaba.fastjson.annotation.JSONField; import com.changhong.autoform.entity.ProcessBudget; import com.changhong.epc.bean.form.budget.BudgetUserDefined; import com.changhong.epc.bean.form.budget.BudgetUserDefined.Dimension; import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyKey; import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyValue; import com.changhong.epc.form.execute.IFormOthersOperation; import com.changhong.epc.form.service.budget.department.SuperBudgt; import com.changhong.epc.form.service.budget.department.model.BudgetRow; import com.changhong.epc.form.service.budget.department.model.BudgetRowUpdateRecord; import com.changhong.epc.form.service.budget.impl.GetConstant; import com.iemsoft.framework.cloud.core.exception.IEMRestException; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; import com.iemsoft.framework.cloud.core.tools.SpringUtil; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; /** * 部门预算 * @author wangZX * */ public class DepartmentBudgt extends SuperBudgt{ //@Resource private IFormOthersOperation formOthersOperation = SpringUtil.getBean(IFormOthersOperation.class); @Override @JSONField(serialize=false) public List> getUsableBudgetList() { List> datas = new ArrayList<>(); Collection values = data.values(); values.forEach(o->datas.addAll(o.dispose())); return datas; } @Override public boolean executeWriteBack(Map fromInfo, ProcessBudget processBudget,String formID) { List> subData = (List>) fromInfo.get(BUDGET_SUB_FROM); List budgetRows = new ArrayList<>(); subData.forEach(o->budgetRows.add(new BudgetRow(o))); verify(budgetRows).forEach(o->{ formOthersOperation.updateFormFieldProperty(o.getProcessBudget(), o.getData() ,o.getFormType(),o.getIBillCostLog()); }); return true; } public List verify(List budgetRows){ List budgetRowRecord = new ArrayList<>(); if(ObjectUtil.empty(budgetRows)){ return budgetRowRecord; } for (BudgetRow budgetRow : budgetRows) { Double applyMoney = Double.valueOf(budgetRow.getMoney()); for(BudgetRow supperbudgetRow : budgetRow.getSupperBudgetRows()){ Double balance = Double.valueOf(supperbudgetRow.getBalance()); Double money = balance - applyMoney; if(money < 0){ applyMoney -= balance; budgetRowRecord.add(new BudgetRowUpdateRecord( new ProcessBudget(GetConstant.getFormIdGetConstant(YS_FORMID) , supperbudgetRow.getDataRowNumber(), BUDGET_SUB_FROM) , BUDGET_ITEM_BALANCE, "0" ,budgetRow.getTenantId())); }else{ budgetRowRecord.add(new BudgetRowUpdateRecord( new ProcessBudget(GetConstant.getFormIdGetConstant(YS_FORMID) , supperbudgetRow.getDataRowNumber(), BUDGET_SUB_FROM) , BUDGET_ITEM_BALANCE, money+"" ,budgetRow.getTenantId())); applyMoney = 0D; } } if(applyMoney < 0){ throw new IEMRestException("预算不足"); } } return budgetRowRecord; } @Override public void setDataSource(BudgetUserDefined budgetUserDefined, Map data) { this.budgetUserDefined = budgetUserDefined; this.data = data; } @Override public boolean isMereg() { return false; } @Override public boolean isFilter(Map data) { return true; } @Override public BudgetUserDefined getBudgetUserDefined() { BudgetUserDefined budgetUserDefined = new BudgetUserDefined(); budgetUserDefined.setFilterSubForm(true); budgetUserDefined.setMergeSubForm(true); budgetUserDefined.setKey("DepartmentBudgt"); budgetUserDefined.setVal("部门预算"); List mainDimension = new ArrayList<>(); List subDimension = new ArrayList<>(); mainDimension.add(new Dimension(BUDGET_START_DATE)); mainDimension.add(new Dimension(BUDGET_END_DATE)); mainDimension.add(new Dimension(CURRENCY)); subDimension.add(new Dimension(BUDGET_ITEM_COST_TYPE)); subDimension.add(new Dimension(BUDGET_ITEM_DEPARTMENT)); budgetUserDefined.setMainDimension(mainDimension); budgetUserDefined.setSubDimension(subDimension); return budgetUserDefined; } @Override public Boolean excuteRefunds(Map formInfo) { // TODO Auto-generated method stub return null; } public BudgetUserDefined getBudgetUserDefined(String fun) { BudgetUserDefined budgetUserDefined = new BudgetUserDefined(); budgetUserDefined.setFilterSubForm(true); budgetUserDefined.setMergeSubForm(true); budgetUserDefined.setKey("DepartmentBudgt"); budgetUserDefined.setVal("部门预算"); List mainDimension = new ArrayList<>(); List subDimension = new ArrayList<>(); mainDimension.add(new Dimension(BUDGET_START_DATE)); mainDimension.add(new Dimension(BUDGET_END_DATE)); mainDimension.add(new Dimension(CURRENCY)); subDimension.add(new Dimension(BUDGET_ITEM_COST_TYPE)); subDimension.add(new Dimension(BUDGET_ITEM_DEPARTMENT)); budgetUserDefined.setMainDimension(mainDimension); budgetUserDefined.setSubDimension(subDimension); return budgetUserDefined; } }