package com.changhong.epc.form.service.budget.tool.impl;
|
|
import com.changhong.epc.bean.form.FormType;
|
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;
|
|
/**
|
* 占用上级预算
|
*/
|
@Service(UpdateBudgetFactory.YS_PARENT_TYPE)
|
@Slf4j
|
@Scope("prototype")
|
public class ParentBudgetUpdate extends AbstractGrepUpdateBudget {
|
|
|
@Override
|
public void checkBudget(UpdateBudgetEntity updateBudgetEntity) {
|
forEach(updateBudgetEntity, updateBudgetEntity.getFormId(), (childInfo, parentChildInfo)->{
|
Assert.condition(
|
toDouble(parentChildInfo.get(BUDGET_ITEM_BALANCE))
|
< toDouble(childInfo.get(BUDGET_ITEM_BALANCE))
|
, BUDGET_MONEY_NOT_ENOUGH);
|
});
|
}
|
|
|
@Override
|
@TxTransaction
|
@Transactional
|
public void updateBudget(UpdateBudgetEntity updateBudgetEntity) {
|
super.updateBudget(updateBudgetEntity);
|
forEach(updateBudgetEntity, updateBudgetEntity.getFormId(), (childInfo, parentChildInfo)->{
|
double parentMoney = toDouble(parentChildInfo.get(BUDGET_ITEM_BALANCE));
|
double childMoney = toDouble(getBudgetBalance(childInfo));
|
Assert.condition(parentMoney < childMoney, BUDGET_MONEY_NOT_ENOUGH);
|
double parentResidueMoney = parentMoney - childMoney;
|
checkMoney(parentResidueMoney);
|
log.debug("添加log");
|
addParentBudgetLogMoney(
|
parentChildInfo
|
, parentResidueMoney
|
, updateBudgetEntity.getFormId()
|
, childInfo
|
, childMoney
|
);
|
log.debug("上级dataRowNum:"+getDataRowNum(parentChildInfo));
|
updateData(updateBudgetEntity.getFormId(), BUDGET_SUB_FROM, getDataRowNum(parentChildInfo) , new ModelMap(BUDGET_ITEM_BALANCE, format(parentResidueMoney,getFormBase(updateBudgetEntity.getFormId()),BUDGET_ITEM_BALANCE)));
|
updateData(updateBudgetEntity.getFormId(), BUDGET_SUB_FROM, getDataRowNum(childInfo) , new ModelMap(BUDGET_SUPER_MONEY, format(parentResidueMoney,getFormBase(updateBudgetEntity.getFormId()),BUDGET_SUPER_MONEY)));
|
});
|
}
|
|
@Override
|
public void flowAfterCall(UpdateBudgetEntity updateBudgetEntity) {
|
forEach(updateBudgetEntity, updateBudgetEntity.getFormId(), (childInfo, parentChildInfo)->{
|
delLock(getDataRowNum(childInfo));
|
delLock(getDataRowNum(parentChildInfo));
|
});
|
}
|
|
@Override
|
public FormType getFormType() {
|
return FormType.YS;
|
}
|
|
}
|