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.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 回收预算
|
*/
|
@Service(UpdateBudgetFactory.YS_DEL_TYPE)
|
@Slf4j
|
@Scope("prototype")
|
public class RecoveryBudgetUpdate extends AbstractOccupyUpdateBudget {
|
|
|
|
@Override
|
public void checkBudget(UpdateBudgetEntity updateBudgetEntity) {
|
forEach(true,updateBudgetEntity, getFormId(SystemForm.BUDGET_FORM_ID), (toolInfo, childInfo, parentChildInfo)->{
|
addLock(getDataRowNum(childInfo));
|
if(parentChildInfo != null) {
|
addLock(getDataRowNum(parentChildInfo));
|
}
|
double childMoney = toDouble(childInfo.get(BUDGET_ITEM_BALANCE));
|
double toolMoney = toDouble(toolInfo.get(BUDGET_ADDITIONALMONEY));
|
// 回收金额 不能大于 预算余额
|
Assert.condition(toolMoney > childMoney, RECOVERY_BUDGET_MONEY_NOT_ENOUGH);
|
});
|
}
|
|
@Override
|
@TxTransaction
|
@Transactional
|
public void updateBudget(UpdateBudgetEntity updateBudgetEntity) {
|
super.updateBudget(updateBudgetEntity);
|
forEach(true,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 > childMoney, RECOVERY_BUDGET_MONEY_NOT_ENOUGH);
|
Double parentResidueMoney = parentMoney == null ? null : parentMoney + 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)));
|
}
|
|
double childResidueMoney = childMoney - toolMoney;
|
double childBudgetMoney = toDouble(childInfo.get(BUDGET_ITEM_MONEY)) - toolMoney;
|
checkMoney(childResidueMoney);
|
Map<String, Object> val = new ModelMap(BUDGET_ITEM_BALANCE, format(childResidueMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_BALANCE))
|
.addAttribute(BUDGET_ITEM_MONEY, format(childBudgetMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_ITEM_MONEY));
|
if(parentResidueMoney != null) {
|
val.put(BUDGET_SUPER_MONEY, format(parentResidueMoney,getFormBase(getFormId(SystemForm.BUDGET_FORM_ID)),BUDGET_SUPER_MONEY));
|
}
|
// 预算金额-回收预算金额
|
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(true,updateBudgetEntity, getFormId(SystemForm.BUDGET_FORM_ID), (toolInfo, childInfo, parentChildInfo)-> {
|
delLock(getDataRowNum(childInfo));
|
if(parentChildInfo != null) {
|
delLock(getDataRowNum(parentChildInfo));
|
}
|
});
|
}
|
|
@Override
|
public FormType getFormType() {
|
return FormType.TH_YS;
|
}
|
}
|