package com.changhong.epc.form.service.budget.tool.impl; import com.changhong.epc.bean.form.FormType; import com.changhong.epc.bean.tenant.system.SystemForm; import com.changhong.epc.form.service.budget.tool.UpdateBudgetFactory; import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity; import com.codingapi.tx.annotation.TxTransaction; import com.iemsoft.framework.cloud.core.tools.Assert; import lombok.extern.slf4j.Slf4j; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.ModelMap; import java.util.Map; /** * 扩展预算 */ @Service(UpdateBudgetFactory.YS_ADD_TYPE) @Slf4j @Scope("prototype") public class ExtendBudgetUpdate extends AbstractOccupyUpdateBudget { @Override public void checkBudget(UpdateBudgetEntity updateBudgetEntity) { forEach(false,updateBudgetEntity, getFormId(SystemForm.BUDGET_FORM_ID), (toolInfo, childInfo, parentChildInfo)->{ addLock(getDataRowNum(childInfo)); if(parentChildInfo != null) { addLock(getDataRowNum(parentChildInfo)); } if(parentChildInfo == null){ return; } double parentChildMoney = toDouble(parentChildInfo.get(BUDGET_ITEM_BALANCE)); double toolMoney = toDouble(toolInfo.get(BUDGET_ADDITIONALMONEY)); // 扩展金额 不能大于 上级预算余额 Assert.condition(toolMoney > parentChildMoney, EXTEND_BUDGET_MONEY_NOT_ENOUGH); }); } @Override @TxTransaction @Transactional public void updateBudget(UpdateBudgetEntity updateBudgetEntity) { super.updateBudget(updateBudgetEntity); forEach(false,updateBudgetEntity, getFormId(SystemForm.BUDGET_FORM_ID), (toolInfo, childInfo, parentChildInfo)->{ double childMoney = toDouble(childInfo.get(BUDGET_ITEM_BALANCE)); double toolMoney = toDouble(toolInfo.get(BUDGET_ADDITIONALMONEY)); Double parentMoney = null; if(parentChildInfo != null) { parentMoney = toDouble(parentChildInfo.get(BUDGET_ITEM_BALANCE)); Assert.condition(toolMoney > parentMoney, EXTEND_BUDGET_MONEY_NOT_ENOUGH); } Double parentResidueMoney = parentMoney == null ? null : parentMoney - toolMoney; double childResidueMoney = childMoney + toolMoney; double childBudgetMoney = toDouble(childInfo.get(BUDGET_ITEM_MONEY)) + toolMoney; if(parentResidueMoney != null) { checkMoney(parentResidueMoney); addParentBudgetLogMoney( parentChildInfo , parentResidueMoney , updateBudgetEntity.getFormId() , childInfo , toolMoney ); // 上级预算金额-扩展预算金额 updateData(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM , getDataRowNum(parentChildInfo) , new ModelMap(BUDGET_ITEM_BALANCE, format(parentResidueMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_BALANCE))); } checkMoney(childResidueMoney); String val3=format(childBudgetMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_MONEY); String val2=format(childResidueMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_BALANCE); Map val = new ModelMap(BUDGET_ITEM_BALANCE, val2) .addAttribute(BUDGET_ITEM_MONEY, val3); if(parentResidueMoney != null) { String val4=format(parentResidueMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_SUPER_MONEY); val.put(BUDGET_SUPER_MONEY,val4); } // 预算金额+扩展预算金额 updateData(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM , getDataRowNum(childInfo) , val); addParentBudgetLogMoney( childInfo , childResidueMoney , updateBudgetEntity.getFormId() , toolInfo , toolMoney ); // 预算余额 回写 updateData(updateBudgetEntity.getFormId(), BUDGET_SUB_FROM , getDataRowNum(toolInfo) , new ModelMap(BUDGET_ITEM_BALANCE, format(childResidueMoney,getFormBase(updateBudgetEntity.getFormId()),BUDGET_ITEM_BALANCE)) .addAttribute(BUDGET_ITEM_MONEY, format(childBudgetMoney,getFormBase(updateBudgetEntity.getFormId()),BUDGET_ITEM_MONEY))); }); } @Override public void flowAfterCall(UpdateBudgetEntity updateBudgetEntity) { forEach(false,updateBudgetEntity, getFormId(SystemForm.BUDGET_FORM_ID), (toolInfo, childInfo, parentChildInfo)-> { delLock(getDataRowNum(childInfo)); if(parentChildInfo != null) { delLock(getDataRowNum(parentChildInfo)); } }); } @Override public FormType getFormType() { return FormType.ZJ_YS; } }