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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.changhong.epc.form.service.budget.tool;
 
import com.changhong.epc.bean.form.FormType;
import com.changhong.epc.bean.tenant.cost.CostFromMapping;
import com.changhong.epc.bean.tenant.system.SystemConfig;
import com.changhong.epc.bean.tenant.system.SystemForm;
import com.changhong.epc.constter.form.budget.BudgetMsg;
import com.changhong.epc.form.service.budget.tool.entity.UpdateBudgetEntity;
import com.changhong.epc.form.service.budget.tool.impl.ApplyBudgetUpdate;
import com.changhong.epc.form.service.budget.tool.impl.AssetBudgetUpdate;
import com.changhong.epc.form.service.budget.tool.impl.ContractInfoUpdate;
import com.changhong.epc.form.service.budget.tool.impl.ExpendBudgetUpdate;
import com.changhong.epc.rely.api.epc.tenant.CostFromMappingApi;
import com.changhong.epc.rely.api.epc.tenant.SystemConfigApi;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * 预算修改执行器
 */
@Service
@Slf4j
public class UpdateBudgetFactory implements BudgetMsg {
 
    // 申请类型回写
    public static final String SQ_TYPE          = "applyDelBudget";
    // 报销类型回写
    public static final String BX_TYPE          = "expendDelBudget";
    // 预算类型扩展
    public static final String YS_ADD_TYPE      = "extendBudget";
    // 预算类型回收
    public static final String YS_DEL_TYPE      = "recoveryBudget";
    // 预算类型占用上级预算
    public static final String YS_PARENT_TYPE   = "parentBudget";
    // 固定资产
    public static final String ASSET_TYPE       = "assetBudget";
    // 合同报销
    public static final String CONTRACT_TYPE    = "contractBudget";
    //合同信息
    public static final String CONTRACT_INFO_TYPE = "contractInfo";
    // 还款
    public static final String AMOUNT_TYPE = "Amount";
    //借款
    public static final String BORROW_MONEY = "borrowMoney";
 
 
    private static final Map<Object, String> FORM_MAPPING_BEANNAME = new HashMap<>();
 
    static {
        FORM_MAPPING_BEANNAME.put(SystemForm.BUDGET_FORM_ID         , YS_PARENT_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.EXTEND_BUDGET_FORM_ID  , YS_ADD_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.RECOVERY_BUDGET_FORM_ID, YS_DEL_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.ASSET_EXPEND_FORM_ID   , ASSET_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.CONTRACT_EXPEND_FORM_ID, CONTRACT_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.REPAYMENT_FORM_ID, AMOUNT_TYPE);
        FORM_MAPPING_BEANNAME.put(SystemForm.LOAN_FORM_ID,BORROW_MONEY);
        FORM_MAPPING_BEANNAME.put(SystemForm.CONTRACT_FORM_ID,CONTRACT_INFO_TYPE);
        
        FORM_MAPPING_BEANNAME.put(FormType.SQ                       , SQ_TYPE);
        FORM_MAPPING_BEANNAME.put(FormType.BX                       , BX_TYPE);
    }
 
    @Resource
    private SystemConfigApi systemConfigApi;
 
    @Resource
    private CostFromMappingApi costFromMappingApi;
 
    public boolean isAutoBudgetUpdate(IUpdateBudget iUpdateBudget){
        return iUpdateBudget instanceof ApplyBudgetUpdate
                || iUpdateBudget instanceof AssetBudgetUpdate
                || iUpdateBudget instanceof ContractInfoUpdate
                || iUpdateBudget instanceof ExpendBudgetUpdate;
    }
 
    /**
     * 获得扣减预算类型
     * @param updateBudgetEntity
     * @return
     */
    public IUpdateBudget getIUpdateBudget(UpdateBudgetEntity updateBudgetEntity){
 
        List<SystemConfig> systemConfigs = systemConfigApi.getSystemConfigs(new SystemConfig("formInfo"));
 
        for(SystemConfig systemConfig : systemConfigs){
            if(Objects.equals(systemConfig.getCvalue(), updateBudgetEntity.getFormId())){
                String beanName = FORM_MAPPING_BEANNAME.get(SystemForm.valueOf(systemConfig.getCkey()));
                if(ObjectUtil.notEmpty(beanName)){
                    IUpdateBudget iUpdateBudget =  SpringUtil.getBean(beanName, IUpdateBudget.class);
                    iUpdateBudget.setSystemFormInfo(systemConfigs);
                    return iUpdateBudget;
                }
            }
        }
 
        List<CostFromMapping> costFromMappings = getCostFromMappings(updateBudgetEntity);
        if(ObjectUtil.empty(costFromMappings)){
            log.debug("未找到对应费用类型,formId={}, datarownum={}", updateBudgetEntity.getFormId(), updateBudgetEntity.getDataRowNum());
            return null;
        }
        for (CostFromMapping cost: costFromMappings) {
            if(Objects.equals(cost.getFId(), updateBudgetEntity.getFormId())){
                IUpdateBudget iUpdateBudget = SpringUtil.getBean(
                        FORM_MAPPING_BEANNAME.get(FormType.valueOf(cost.getType()))
                        , IUpdateBudget.class);
                iUpdateBudget.setCostFromMappings(costFromMappings);
                iUpdateBudget.setSystemFormInfo(systemConfigs);
                return iUpdateBudget;
            }
        }
        return null;
    }
 
    protected List<CostFromMapping> getCostFromMappings(UpdateBudgetEntity updateBudgetEntity){
        return costFromMappingApi.getConstFromMappings(updateBudgetEntity.getFormId());
    }
}