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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.changhong.epc.count.service.count.performer.impl;
 
import com.alibaba.fastjson.JSON;
import com.changhong.epc.bean.tenant.norm.extend.AppStanderExtend;
import com.changhong.epc.bean.tenant.norm.extend.SuppStanderExtend;
import com.changhong.epc.constter.parsing.bill.ConstBill;
import com.changhong.epc.count.service.count.data.condition.ICountConditionIter;
import com.changhong.epc.count.service.count.data.paramiter.IParamIter;
import com.changhong.epc.count.service.count.logic.ICountLogic;
import com.changhong.epc.count.service.count.logic.ILastMoneyCount;
import com.changhong.epc.count.service.count.logic.impl.CountLogicImpl;
import com.changhong.epc.count.service.count.model.CountResult;
import com.changhong.epc.count.service.count.model.CountResultExtend;
import com.changhong.epc.count.service.count.model.CountResultLast;
import com.changhong.epc.count.service.count.model.UnitInfo;
import com.changhong.epc.count.service.count.performer.ICountPerformer;
import com.iemsoft.framework.cloud.core.tools.JSONTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
 
/**
 * 计算费用执行器
 */
@Slf4j
@Service("countPerformer")
@Scope("prototype")
public class CountPerformer implements ICountPerformer<CountResultLast, AppStanderExtend, SuppStanderExtend, UnitInfo>,ConstBill {
 
    private IParamIter<UnitInfo> paramIter;
    private ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> countConditionIter;
 
    private Map<String,List<CountResult>> countResult;
    
    @Resource
    private ILastMoneyCount lastMoneyCount;
    
    private List<CountResultExtend> eachMoney;
    
 
    /**
     * 计算结果
     */
    public CountResultLast resultMoney;
    
    @Override
    public CountResultLast execute() {
        resultMoney = new CountResultLast();
        countResult = new LinkedHashMap<>(); // 使用有序map集合,否则顺序会混乱
        // 一、迭代单元 
        while(getIParamIter().hasNext()){
            
            UnitInfo unitinfo = getIParamIter().next();
 
            /**
             * 将行程进行分组
             */
            List<CountResult> unitResult = countResult.get(unitinfo.getUuid());
            if(countResult.get(unitinfo.getUuid()) == null){
                countResult.put(unitinfo.getUuid(), unitResult = new ArrayList<>());
            }
            
            while(getICountConditionIter().hasGropNext()){
                getICountConditionIter().groupNext();
                CountResult countResult = getICountLogic().countLogic(getIParamIter(), getICountConditionIter());
                if(countResult == null){
                    continue;
                }
                countResult.setFormDay(unitinfo.getVal(FROM_DATE));
                unitResult.add(countResult);
            }
 
            //补助标准从新遍历
            getICountConditionIter().gropReset();
        }
        
        // 分组
        resultGroup();
        return getOtherMoney();
    }
    
    protected ICountLogic getICountLogic(){
        return new CountLogicImpl();
    }
    
    @Override
    public void setIParamIter(IParamIter<UnitInfo> inters) {
        this.paramIter = inters;
    }
 
    @Override
    public IParamIter<UnitInfo> getIParamIter() {
        return paramIter;
    }
 
    /**
     * 对结果进行打包分组
     */
    public void resultGroup(){
        eachMoney = new ArrayList<>();
        for(Entry<String, List<CountResult>> group: countResult.entrySet()){
            
            CountResultExtend eachGrolup =  new CountResultExtend();
            eachGrolup.setCountResults(group.getValue());
            eachGrolup.setOtherMoney(0D);
            eachMoney.add(eachGrolup);
        }
        log.warn("计算后数据:{}", JSONTool.toJson(eachMoney));
        try{
            eachMoney  = lastMoneyCount.count(getICountConditionIter().getRecord(), eachMoney);
        }catch (Exception e) {
            log.error("对结果进行封装。。。。。。。。。。。。");
        }
    }
    
    
    private CountResultLast getOtherMoney() {
        CountResultLast countResultLast = new CountResultLast();
        countResultLast.setEachMoney(eachMoney);
        countResultLast.setNoJoinBillMoney(getNoJoinBill());
        countResultLast.setIParamIter(this.paramIter);
        countResultLast.setNoJoinBill(getIParamIter().getNoJoinAllBillInfo());
        return countResultLast;
    }
 
    /**
     * 返回无行程票据
     * @return
     */
    private Double getNoJoinBill() {
        return getIParamIter().getNoJoinAllBillTotalMoney();
    }
 
    @Override
    public void setICountConditionIter(ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> countConditionIter) {
        this.countConditionIter = countConditionIter;
    }
 
    @Override
    public ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo> getICountConditionIter() {
        return countConditionIter;
    }
 
 
 
    @Override
    public CountResultLast  getResture() {
        return resultMoney;
    }
 
    /**
     * @param s
     * @param c
     * @return
     * 字符串转化为对象
     */
    @SuppressWarnings("unchecked")
    public static <T>T convertJson2Class(String s,Class<T> c){
        Object obj = null;
        try {
            obj = JSON.parseObject(s, c);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
        return (T)obj;
    }                
}