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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
package com.changhong.epc.count.service.count.data.condition.impl;
 
import com.changhong.epc.bean.tenant.norm.extend.AppStanderExtend;
import com.changhong.epc.bean.tenant.norm.extend.SuppStanderExtend;
import com.changhong.epc.count.service.count.data.condition.ICountConditionIter;
import com.changhong.epc.count.service.count.execution.ICounter;
import com.changhong.epc.count.service.count.execution.impl.FuncCountImpl;
import com.changhong.epc.count.service.count.execution.impl.SimpleCounterImpl;
import com.changhong.epc.count.service.count.model.AmountKey;
import com.changhong.epc.count.service.count.model.UnitInfo;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
import com.iemsoft.framework.cloud.core.tools.SpringUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * 补助标准 数据迭代器
 * @author wangZX
 *
 */
@Service("countConditionIter")
@Scope("prototype")
public class CountConditionIterImpl implements ICountConditionIter<AppStanderExtend, SuppStanderExtend, UnitInfo>{
 
    private List<SuppStanderExtend> suppStanderExtend;
 
    private Iterator<SuppStanderExtend> groupIterator;
 
    @Override
    public CountConditionIterImpl setDataSource(List<SuppStanderExtend> data) {
        if(data == null) return this;
        suppStanderExtend = data;
        
        init( data);
        groupIterator = suppStanderExtend.iterator();
        return this;
    }
 
    /**
     * 将原始数据转换为可用数据
     * @param data
     */
    private void init(List<SuppStanderExtend> data) {
        if(ObjectUtil.empty(data)){
            return;
        }
        // 迭代每一大块 
        for (SuppStanderExtend supp : data) {
            // 按照行号,分为补助,标准,金额,转换为二维矩阵
            // System.err.println(JSONTool.toJson(supp));
            Map<Integer,List<AppStanderExtend>> matrix = new HashMap<>();
            for (AppStanderExtend appslist : supp.getAppStanderDefs()) {
                // System.err.println(JSONTool.toJson(appslist));
                if( matrix.get(appslist.getRowNo()) ==  null){
                    List<AppStanderExtend> temp = new ArrayList<>();
                    matrix.put(appslist.getRowNo(), temp);
                }
                matrix.get(appslist.getRowNo()).add(appslist);
            }
            MapToMatrix(supp,matrix);
        }
        // System.out.println(JSONTool.toJson(suppStanderExtend));
        // System.out.println("将原始数据转换为可用数据");
    }
 
    private void MapToMatrix(SuppStanderExtend supp, Map<Integer, List<AppStanderExtend>> matrix) {
        // System.out.println(JSONTool.toJson(supp));
        List<List<AppStanderExtend>> matrixList = new ArrayList<>();
        for (Integer colKey : matrix.keySet()) {
            matrixList.add(matrix.get(colKey));
        }
        supp.setAppStanderDefMatrix(matrixList);
        // System.out.println(JSONTool.toJson(supp));
    }
 
    @Override
    public Boolean hasGropNext() {
        return groupIterator !=null && groupIterator.hasNext();
    }
    private SuppStanderExtend currGroup;
    List<List<AppStanderExtend>> appStanderDefTwe;
    Iterator<List<AppStanderExtend>> rowIterator;
 
    @Override
    public void initGroup(){
        appStanderDefTwe = currGroup.getAppStanderDefMatrix();
        initRow();
    }
 
    @Override
    public void groupNext() {
        currGroup = groupIterator.next();
        initGroup();
        return ;
    }
 
    @Override
    public SuppStanderExtend getCurrGroup() {
        countEachSuppStanderCount(currGroup);
        
        
        return currGroup;
    }
    
    
    @Override
    public void gropReset() {
        if(suppStanderExtend == null)
                return ;
        groupIterator = suppStanderExtend.iterator();
    }
 
    /***********************************************************************/
 
    @Override
    public void initRow(){
        rowIterator = appStanderDefTwe.iterator();
    }
 
    @Override
    public Boolean hasRowNext() {
        return rowIterator.hasNext();
    }
    
    List<AppStanderExtend> currRow;
    Iterator<AppStanderExtend> elem;
    @Override
    public void rowNext() {
        currRow = rowIterator.next();
        initCol();
        return ;
    }
 
    @Override
    public List<AppStanderExtend> cruuRow() {
        return currRow;
    }
 
    @Override
    public void initCol(){
        elem = currRow.iterator();
    }
 
    @Override
    public Boolean hasColNext() {
        return elem.hasNext();
    }
 
    private AppStanderExtend currElem;
    
    @Override
    public AppStanderExtend colNext() {
        currElem = elem.next();
        return currElem;
    }
 
    @Override
    public AppStanderExtend cruuCol() {
        return currElem;
    }
 
    @Override
    public ICounter<AppStanderExtend, UnitInfo> getExeCounter() {
        return getExeCounter(this.cruuCol());
    }
 
    @Override
    public ICounter<AppStanderExtend, UnitInfo> getExeCounter(AppStanderExtend appStanderExtend){
        if(appStanderExtend.getDefType() == 5){
            return SpringUtil.getBean(FuncCountImpl.class);
        }else{
            return SpringUtil.getBean(SimpleCounterImpl.class);
        }
    }
    
    private Map<AmountKey, String> amountLastCount = new HashMap<>();
 
    private void countEachSuppStanderCount(SuppStanderExtend guoup) {
         if(guoup.getRule() != null 
                && !Objects.equals(guoup.getRule(), "0")){
            AmountKey k = new AmountKey();
            // System.out.println("取值规则是:"+guoup.getRule());
            k.fylx = guoup.getType(); // mdCode
            // System.out.println("选择的补助类型:"+guoup.getType());
            k.bxfs = guoup.getName(); // 报销方式
            // System.out.println("报销方式是:"+guoup.getName());
            k.id = String.valueOf(guoup.getId());//表中数据ID
            // System.out.println("表单ID是:"+guoup.getId());
            amountLastCount.put(k, guoup.getRule());
            
        }
    }
 
    public Map<AmountKey, String> getRecord(){
        return amountLastCount;
    }
}