zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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;
    }
 
}