package com.changhong.epc.form.service.budget.tool.impl;
|
|
import com.changhong.epc.bean.form.FormType;
|
import com.changhong.epc.bean.tenant.system.SystemConfig;
|
import com.changhong.epc.bean.tenant.system.SystemForm;
|
import com.changhong.epc.form.service.budget.CheckFormDataServes;
|
import com.changhong.epc.form.service.budget.department.model.BudgetExtend;
|
import com.changhong.epc.form.service.budget.impl.GetConstant;
|
import com.changhong.epc.form.service.budget.tool.UpdateBudgetFactory;
|
import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity;
|
import com.changhong.epc.rely.api.epc.tenant.SystemConfigApi;
|
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 javax.annotation.Resource;
|
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Objects;
|
|
@Service(UpdateBudgetFactory.CONTRACT_INFO_TYPE)
|
@Slf4j
|
@Scope("prototype")
|
public class ContractInfoUpdate extends AbstractUpdateBudget{
|
|
private Map<String, Object> contractInfo;
|
|
private Map<String, Object> budgetChildInfo;
|
|
@Resource
|
private CheckFormDataServes checkFormDataServes;
|
|
@Resource
|
private SystemConfigApi systemConfigApi;
|
|
@Override
|
public void checkBudget(UpdateBudgetEntity updateBudgetEntity) {
|
this.contractInfo = getFormInfo(updateBudgetEntity);
|
Integer budgetId = getParentId(contractInfo);
|
if(budgetId == null){
|
return;
|
}
|
this.budgetChildInfo = getFormInfo(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, budgetId);
|
Assert.condition(budgetChildInfo == null, BUDGET_INVALID);
|
if(contractInfo.get(CONTRACT_MONEY) == null || getBudgetBalance(budgetChildInfo) == null){
|
return;
|
}
|
// addLock(budgetId);
|
// 验证预算
|
Assert.condition(
|
toDouble(contractInfo.get(CONTRACT_MONEY)) > toDouble(getBudgetBalance(budgetChildInfo))
|
, BUDGET_MONEY_NOT_ENOUGH);
|
}
|
|
@Override
|
@TxTransaction
|
@Transactional
|
public void updateBudget(UpdateBudgetEntity updateBudgetEntity) {
|
super.updateBudget(updateBudgetEntity);
|
checkBudget(updateBudgetEntity);
|
if(ObjectUtil.empty(this.budgetChildInfo) || contractInfo.get(CONTRACT_MONEY) == null){
|
account(updateBudgetEntity.getFormId(),ThreadData.get(Keys.TENANT_ID), Objects.toString(updateBudgetEntity.getDataRowNum(),""));
|
return;
|
}
|
double money = toDouble(getBudgetBalance(budgetChildInfo)) - toDouble(contractInfo.get(CONTRACT_MONEY));
|
checkMoney(money);
|
|
addBudgetLogMoney(
|
this.budgetChildInfo
|
, money
|
, updateBudgetEntity.getFormId()
|
, this.contractInfo
|
, toDouble(contractInfo.get(CONTRACT_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)));
|
}
|
|
|
/**
|
* 预算回写
|
*/
|
public Integer budgetWirteBack(BudgetExtend budgetExtend){
|
this.contractInfo = getFormInfo(new UpdateBudgetEntity(budgetExtend.getFormId(),budgetExtend.getDatarowNum()));
|
log.debug("当前执行状态:"+contractInfo.get(STATE_EXECUTION));
|
Assert.condition(contractInfo.get(STATE_EXECUTION)!=null&& !Objects.equals("",contractInfo.get(STATE_EXECUTION)), CONTRACT_OVER);
|
log.debug("开始合同信息预算回写");
|
//判断合同执行状态,修改控件值
|
log.debug("当前合同执行状态:"+budgetExtend.getData());
|
if(ObjectUtil.notEmpty(budgetExtend.getData())
|
&& !Objects.equals(Objects.toString(budgetExtend.getData().get(STATE_EXECUTION),null)
|
, GetConstant.getConstant(STATE_EXECUTION))) {
|
updateData(budgetExtend.getFormId(), null
|
, budgetExtend.getDatarowNum()
|
, budgetExtend.getData());
|
//取出实时已付金额
|
Double sum = 0d;
|
for(Map<String,Object> map:checkFormDataServes.getSumAlreadyPaid(budgetExtend)){
|
if(map.get(ALREADYPAID)!=null){
|
sum+=toDouble(map.get(ALREADYPAID));
|
}
|
}
|
log.debug("当前合同已付金额为:"+sum);
|
//回写预算
|
Assert.condition((toDouble(this.contractInfo.get(CONTRACT_MONEY))-sum)<0, OVERTOP_CONTRACT_MONEY);
|
Integer budgetId = getParentId(contractInfo);
|
if(budgetId == null){
|
return 0;
|
}
|
this.budgetChildInfo = getFormInfo(this.getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, budgetId);
|
Assert.condition(budgetChildInfo == null, BUDGET_INVALID);
|
if(contractInfo.get(CONTRACT_MONEY) == null || getBudgetBalance(budgetChildInfo) == null){
|
return 0;
|
}
|
log.debug("当前预算余额:"+this.budgetChildInfo.get(BUDGET_ITEM_BALANCE));
|
Double budgetbl = toDouble(this.budgetChildInfo.get(BUDGET_ITEM_BALANCE))+(toDouble(this.contractInfo.get(CONTRACT_MONEY))-sum);
|
log.debug("预算回写后余额:"+budgetbl);
|
//回写预算
|
updateData(this.getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, getDataRowNum(this.budgetChildInfo),
|
new ModelMap(BUDGET_ITEM_BALANCE, format(budgetbl,getFormBase(budgetExtend.getFormId()),BUDGET_ITEM_BALANCE)));
|
}
|
return 1;
|
}
|
|
@Override
|
public void flowAfterCall(UpdateBudgetEntity updateBudgetEntity) {
|
account(updateBudgetEntity.getFormId(),ThreadData.get(Keys.TENANT_ID), Objects.toString(updateBudgetEntity.getDataRowNum(),""));
|
}
|
|
@Override
|
public void rollback(UpdateBudgetEntity updateBudgetEntity) {
|
super.rollback(updateBudgetEntity);
|
this.contractInfo = getFormInfo(updateBudgetEntity);
|
Integer budgetId = getParentId(contractInfo);
|
if(budgetId == null){
|
return;
|
}
|
this.budgetChildInfo = getFormInfo(getFormId(SystemForm.BUDGET_FORM_ID), BUDGET_SUB_FROM, budgetId);
|
Assert.condition(budgetChildInfo == null, BUDGET_INVALID);
|
if(contractInfo.get(CONTRACT_MONEY) == null || getBudgetBalance(budgetChildInfo) == null){
|
return;
|
}
|
double money = toDouble(getBudgetBalance(budgetChildInfo)) + toDouble(contractInfo.get(CONTRACT_MONEY));
|
|
addBudgetLogMoney(
|
this.budgetChildInfo
|
, money
|
, updateBudgetEntity.getFormId()
|
, this.contractInfo
|
, toDouble(contractInfo.get(CONTRACT_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.HTXX;
|
}
|
List<SystemConfig> config = null;
|
public String getFormId(SystemForm systemForm){
|
if(this.config == null){
|
this.config = systemConfigApi.getSystemConfigs(new SystemConfig("formInfo"));
|
}
|
SystemConfig sys = config.stream().filter(fi->Objects.equals(fi.getCkey(),systemForm.toString())).findFirst().orElse(null);
|
return sys!=null?sys.getCvalue():null;
|
}
|
|
}
|