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.thread.Keys; import com.iemsoft.framework.cloud.core.thread.ThreadData; import com.iemsoft.framework.cloud.core.tools.Assert; import com.iemsoft.framework.cloud.core.tools.ObjectUtil; 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; import java.util.Objects; /** * 固定资产扣减预算 */ @Service(UpdateBudgetFactory.ASSET_TYPE) @Slf4j @Scope("prototype") public class AssetBudgetUpdate extends AbstractUpdateBudget{ private Map assetInfo; private Map budgetChildInfo; private Map socmap; @Override public void checkBudget(UpdateBudgetEntity updateBudgetEntity) { this.assetInfo = getFormInfo(updateBudgetEntity); Integer budgetId = getParentId(assetInfo); if(budgetId == null){ return; } addLock(budgetId); this.budgetChildInfo = getFormInfo(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, budgetId); Assert.condition(budgetChildInfo == null, BUDGET_INVALID); if(assetInfo.get(EXPEND_USE_MONEY) == null || getBudgetBalance(budgetChildInfo) == null){ return; } Assert.condition( toDouble(assetInfo.get(EXPEND_USE_MONEY)) > toDouble(getBudgetBalance(budgetChildInfo)) , BUDGET_MONEY_NOT_ENOUGH); //检查固定资产是否被报销过 String fixed = Objects.toString(assetInfo.get(SELECT_FIXED_ASSETS)); if(fixed!= null && !"".equals(fixed)) { this.socmap = getFormInfo(getFormId(SystemForm.ASSET_FORM_ID), null, Integer.parseInt(fixed)); // System.out.println("当前固定资产:"+ JSONTool.toJson(socmap)); Assert.condition("1".equals(Objects.toString(socmap.get(PROCESS_FLAG),null)),ASSET_EXTEND_REPETITION); } } @Override @TxTransaction @Transactional public void updateBudget(UpdateBudgetEntity updateBudgetEntity) { super.updateBudget(updateBudgetEntity); checkBudget(updateBudgetEntity); if(ObjectUtil.empty(this.budgetChildInfo) || assetInfo.get(EXPEND_USE_MONEY) == null){ return; } double money = toDouble(getBudgetBalance(budgetChildInfo)) - toDouble(assetInfo.get(EXPEND_USE_MONEY)); checkMoney(money); addBudgetLogMoney( this.budgetChildInfo , money , updateBudgetEntity.getFormId() , this.assetInfo , toDouble(assetInfo.get(EXPEND_USE_MONEY)) ); updateData(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM , getDataRowNum(budgetChildInfo) , new ModelMap(BUDGET_ITEM_BALANCE, format(money,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_BALANCE))); if(this.socmap!=null){ updateData(getFormId(SystemForm.ASSET_FORM_ID), null , Integer.parseInt(Objects.toString(socmap.get(DATAROWNUMBER),"0")) , new ModelMap(PROCESS_FLAG, 1)); } } @Override public void flowAfterCall(UpdateBudgetEntity updateBudgetEntity) { this.assetInfo = getFormInfo(updateBudgetEntity); Integer budgetId = getParentId(assetInfo); if(budgetId == null){ return; } delLock(budgetId); account(updateBudgetEntity.getFormId(),ThreadData.get(Keys.TENANT_ID), Objects.toString(updateBudgetEntity.getDataRowNum(),"")); } @Override public void rollback(UpdateBudgetEntity updateBudgetEntity) { super.rollback(updateBudgetEntity); this.assetInfo = getFormInfo(updateBudgetEntity); Integer budgetId = getParentId(assetInfo); if(budgetId == null){ return; } addLock(budgetId); this.budgetChildInfo = getFormInfo(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, budgetId); Assert.condition(budgetChildInfo == null, BUDGET_INVALID); if(assetInfo.get(EXPEND_USE_MONEY) == null || getBudgetBalance(budgetChildInfo) == null){ return; } double money = toDouble(getBudgetBalance(budgetChildInfo)) + toDouble(assetInfo.get(EXPEND_USE_MONEY)); addBudgetLogMoney( this.budgetChildInfo , money , updateBudgetEntity.getFormId() , this.assetInfo , toDouble(assetInfo.get(EXPEND_USE_MONEY)) ); updateData(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM , getDataRowNum(budgetChildInfo) , new ModelMap(BUDGET_ITEM_BALANCE, format(money,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_BALANCE))); } @Override public FormType getFormType() { return FormType.GDZC; } }