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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.changhong.epc.form.service.budget.department;
 
import com.changhong.autoform.entity.BudgetData;
import com.changhong.autoform.entity.BudgetTitle;
import com.changhong.epc.bean.form.FormType;
import com.changhong.epc.bean.form.budget.BudgetUserDefined;
import com.changhong.epc.bean.form.budget.BudgetUserDefined.Dimension;
import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyKey;
import com.changhong.epc.bean.form.budget.filtrate.BudgetclassifyValue;
import com.changhong.epc.bean.tenant.cost.budgetlog.IBillCostLog;
import com.changhong.epc.bean.tenant.cost.budgetlog.MoneyApplyLog;
import com.changhong.epc.bean.tenant.cost.budgetlog.MoneyBudgetLog;
import com.changhong.epc.bean.tenant.cost.budgetlog.MoneyExpendLog;
import com.changhong.epc.constter.system.SystemClients;
import com.changhong.epc.constter.system.businesscode.BudgetBusinessMeaningCode;
import com.changhong.epc.constter.system.run.EpcRestInterface;
import com.changhong.epc.constter.tenant.TenantUrlConst;
import com.changhong.epc.form.service.budget.department.util.TitletTool;
import com.iemsoft.framework.cloud.core.base.ResMsg;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import com.iemsoft.framework.cloud.ribbon.RestInterface;
 
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
public abstract class SuperBudgt  implements IDepartment, BudgetBusinessMeaningCode, SystemClients{
    
    protected BudgetUserDefined budgetUserDefined;
    protected Map<BudgetclassifyKey, BudgetclassifyValue> data;
    
    private Object iBillCostLog;
    
    //预算余额是否含有小数位数
    protected Integer budgetItemBalanceType;
    //预算单id
    protected String superFormId = "";
    
    public void setBudgetItemBalanceType(Integer budgetItemBalanceType){
        this.budgetItemBalanceType = budgetItemBalanceType;
    }
    
//    protected void setIBillCostLog(IBillCostLog iBillCostLog){
//        this.iBillCostLog =  iBillCostLog;
//    }
//    
//    protected Object getIBillCostLog(){
//        return  this.iBillCostLog;
//    }
    
    @Override
    public boolean isFilter(Map<String, Object> data) {
        Double balance= 0D;
        try {
            balance = Double.valueOf(Objects.toString(data.get(BudgetBusinessMeaningCode.BUDGET_ITEM_BALANCE), "0"));
        } catch (NumberFormatException e) {
        }
        if(balance <= 0){
            return false;
        }
        if(!budgetUserDefined.isFilterSubForm()){
            return true;
        }
        
        for(List<Dimension> dimensionRow : budgetUserDefined.getSubDimensions()){
            boolean folg = true;
            for(Dimension dimension: dimensionRow){
                folg = Objects.equals(data.get(dimension.getName()),dimension.getValue());
                if(!folg){
                    break;
                }
            }
            if(folg){
                return true;
            }
        }
        
        return false;
    }
    
    protected Object getValueByBalanceType(BigDecimal money){
        Object value = budgetItemBalanceType == 0 ? money.intValue() : money.setScale(budgetItemBalanceType, BigDecimal.ROUND_HALF_UP);
        return value;
    }
 
    
    /**
     * 将数据封装成 BudgetData
     * @param datas
     * @return
     */
    protected List<BudgetData> envelopedBudgetData(List<Map<String,Object>> datas){
        
        List<BudgetData>  budgetDatas = new ArrayList<>();
        datas.forEach(o->{
            BudgetData budgetData = new BudgetData();
            budgetData.setFormData(o);
            budgetDatas.add(budgetData);
        });
        
        return budgetDatas;
        
    } 
    
    @Override
    public List<BudgetTitle> getTitles(){
        return TitletTool.getDefTitlet();
    }
    
    public Object getPostRest(String url,Object parm){
        
        RestInterface restInterface = SpringUtil.getBean(SERVER_TENANT.getBeanName(), RestInterface.class);
        Object data = restInterface.post(url, parm, ResMsg.class, EpcRestInterface.getEpcHeads()).getData();
        return data;
    }
    
    
    
    /**
     * 记录费用类型变更日志
     * @param billCostLog
     */
    public void recordLog(IBillCostLog billCostLog){
        if(billCostLog instanceof MoneyBudgetLog){
            
        }else if(billCostLog instanceof MoneyApplyLog){
            
        }else if(billCostLog instanceof MoneyExpendLog){
            
        }
    } 
    
    public void recordLog(FormType formType, IBillCostLog billCostLog){
        switch (formType) {
        case YS:
            getPostRest(TenantUrlConst.REST_TENANT_COST_RECORDLOG_YS, billCostLog);
            break;
        case SQ:
            getPostRest(TenantUrlConst.REST_TENANT_COST_RECORDLOG_SQ, billCostLog);
            break;
        case BX:
            getPostRest(TenantUrlConst.REST_TENANT_COST_RECORDLOG_BX, billCostLog);
            break;
        
        default:
            break;
        }
    }
    
}