MatchingItemProcessorAuto.java
9.61 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.batch.config;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;
import com.batch.config.MatchingSetup.Cond;
import com.batch.config.MatchingSetup.Matching;
import com.batch.mapper.primary.MatchingInnerDelingMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@StepScope
@Component
@RequiredArgsConstructor
public class MatchingItemProcessorAuto implements ItemProcessor<Map, Map> {
MatchingInnerDelingMapper matchingInnerDelingMapper;
public void setMapper(MatchingInnerDelingMapper matchingInnerDelingMapper) {
this.matchingInnerDelingMapper = matchingInnerDelingMapper;
}
@SuppressWarnings("unchecked")
public Map process(Map item) throws Exception {
Map<String, Object> params = new HashMap<String, Object>((Map<String, String>) item.get("jobParameters"));
Matching matching = (Matching) item.get("matchingType");
Cond condOne = matching.getCondOne();
Cond condTwo = matching.getCondTwo();
List<String> lCompareField = matching.getCompareField();
String mtchType = matching.getType();
String mtchTypeName = matching.getTypeName();
int mtchNumber = 0;
int iUpdated = 0;
log.debug("CustomItemProcessorA.params : " + params.toString());
log.debug("CustomItemProcessorA.item : " + item.get("cpr_code") + "," + item.get("partn_cpr"));
//----------------------------------------------------------------------------
//자기법인 업데이트
params.put("cprCode", item.get("cpr_code"));
params.put("partnCpr", item.get("partn_cpr"));
params.put("cond", condOne.getCond() ); //조건리스트
params.put("compareKey", matching.getCompareKey() );
params.put("makeCompareKey", "'" + mtchType + ":' || " + condOne.getMakeCompareKey() );
iUpdated = matchingInnerDelingMapper.setDataMakeCompareKy(params);
log.debug("matchingInnerDelingMapper.setDataMakeCompareKy ; " + iUpdated);
//상대법인업데이트
params.put("cprCode", item.get("partn_cpr"));
params.put("partnCpr", item.get("cpr_code"));
params.put("cond", condTwo.getCond() ); //조건리스트
params.put("compareKey", matching.getCompareKey() );
params.put("makeCompareKey", "'" + mtchType + ":' || " + condTwo.getMakeCompareKey() );
iUpdated = matchingInnerDelingMapper.setDataMakeCompareKy(params);
log.debug("matchingInnerDelingMapper.setDataMakeCompareKy ; " + iUpdated);
//----------------------------------------------------------------------------
//자기법인 데이타 가져오기
params.put("cprCode", item.get("cpr_code"));
params.put("partnCpr", item.get("partn_cpr"));
params.put("amtField", matching.getAmtField());
params.put("currencyField", matching.getCurrencyField());
params.put("cond", condOne.getCond() ); //조건리스트
List<Map> lMatchingDataOne = matchingInnerDelingMapper.getMatchingData(params);
//상대법인 데이타 가져오기
params.put("cprCode", item.get("partn_cpr"));
params.put("partnCpr", item.get("cpr_code"));
params.put("currencyField", matching.getCurrencyField());
params.put("amtField", matching.getAmtField());
params.put("cond", condTwo.getCond() ); //조건리스트
List<Map> lMatchingDataTwo = matchingInnerDelingMapper.getMatchingData(params);
//----------------------------------------------------------------------------
//자기법인 데이타를 맵으로 처리한다.
Map<String, List<Map>> mMatchingDataOne = new HashMap<String, List<Map>>();
for (Map curMap : lMatchingDataOne) {
StringBuffer sbKey = new StringBuffer();
for (String curField : lCompareField) {
if (sbKey.length() > 0) sbKey.append(":");
sbKey.append(curMap.get(curField).toString());
}
List<Map> curlMap = new ArrayList<Map>();
String sKey = sbKey.toString();
if (mMatchingDataOne.containsKey(sKey)) curlMap = mMatchingDataOne.get(sKey);
curlMap.add(curMap);
mMatchingDataOne.put(sKey, curlMap);
}
//상대법인 데이타를 맵으로 처리한다.
Map<String, List<Map>> mMatchingDataTwo = new HashMap<String, List<Map>>();
for (Map curMap : lMatchingDataTwo) {
StringBuffer sbKey = new StringBuffer();
for (String curField : lCompareField) {
if (sbKey.length() > 0) sbKey.append(":");
sbKey.append(curMap.get(curField).toString());
}
List<Map> curlMap = new ArrayList<Map>();
String sKey = sbKey.toString();
if (mMatchingDataTwo.containsKey(sKey)) curlMap = mMatchingDataTwo.get(sKey);
curlMap.add(curMap);
mMatchingDataTwo.put(sKey, curlMap);
}
//여기서 매칭 비교
//비교 lMatchingDataOne vs mMatchingDataTwo
for (String curKey : mMatchingDataOne.keySet()) {
if (mMatchingDataTwo.containsKey(curKey)) {
List<Map> lMapOne = mMatchingDataOne.get(curKey);
List<Map> lMapTwo = mMatchingDataTwo.get(curKey);
int iMin = Math.min(lMapOne.size(), lMapTwo.size());
if (iMin > 0) mtchNumber++;
for (int i=0; i<iMin; i++) {
lMapOne.get(i).put("mtchType", mtchType);
lMapOne.get(i).put("mtchTypeName", mtchTypeName);
lMapOne.get(i).put("mtchNumber", mtchNumber);
lMapTwo.get(i).put("mtchType", mtchType);
lMapTwo.get(i).put("mtchTypeName", mtchTypeName);
lMapTwo.get(i).put("mtchNumber", mtchNumber);
}
}
}
//----------------------------------------------------------------------------
//여기서 결과 업데이트
List<Map> lMatchingResultUpdate = new ArrayList<Map>(); //업데이트할 대상
String sCompareKey = matching.getCompareKey();
//자기법인 데이타 가져오기
params.put("cprCode", item.get("cpr_code"));
params.put("partnCpr", item.get("partn_cpr"));
params.put("cond", condOne.getCond() ); //조건리스트
List<Map> lMatchingResultOne = matchingInnerDelingMapper.getMatchingResult(params);
Map<String, Map> mMatchingResultOne = new HashMap<String, Map>();
for (Map curMap : lMatchingDataOne) {
String curComapreKeyVal = (String)curMap.get(sCompareKey);
boolean curBlnMatching = curMap.get("mtchType")!=null && curMap.get("mtchNumber")!=null;
if (curBlnMatching) mMatchingResultOne.put(curComapreKeyVal, curMap);
}
for (Map curMap : lMatchingResultOne) {
String curComapreKeyVal = (String)curMap.get(sCompareKey);
if ( mMatchingResultOne.containsKey(curComapreKeyVal) ) {
Map mResult = mMatchingResultOne.get(curComapreKeyVal);
curMap.put(matching.getMatchingType() , mResult.get("mtchType"));
curMap.put(matching.getMatchingTypeName(), mResult.get("mtchTypeName"));
curMap.put(matching.getMatchingNumber(), mResult.get("mtchNumber"));
lMatchingResultUpdate.add(curMap);
}
}
//상대법인 데이타 가져오기
params.put("cprCode", item.get("partn_cpr"));
params.put("partnCpr", item.get("cpr_code"));
params.put("cond", condTwo.getCond() ); //조건리스트
List<Map> lMatchingResultTwo = matchingInnerDelingMapper.getMatchingResult(params);
Map<String, Map> mMatchingResultTwo = new HashMap<String, Map>();
for (Map curMap : lMatchingDataTwo) {
String curComapreKeyVal = (String)curMap.get(sCompareKey);
boolean curBlnMatching = curMap.get("mtchType")!=null && curMap.get("mtchNumber")!=null;
if (curBlnMatching) mMatchingResultTwo.put(curComapreKeyVal, curMap);
}
for (Map curMap : lMatchingResultTwo) {
String curComapreKeyVal = (String)curMap.get(sCompareKey);
if ( mMatchingResultTwo.containsKey(curComapreKeyVal) ) {
Map mResult = mMatchingResultTwo.get(curComapreKeyVal);
curMap.put(matching.getMatchingType() , mResult.get("mtchType"));
curMap.put(matching.getMatchingTypeName(), mResult.get("mtchTypeName"));
curMap.put(matching.getMatchingNumber(), mResult.get("mtchNumber"));
lMatchingResultUpdate.add(curMap);
}
}
iUpdated = 0;
int limit = 1000; //1000건씩 batch
List<Map> lUpdated = new ArrayList<Map>();
for (Map curMap : lMatchingResultUpdate) {
curMap.put("matchingType", matching.getMatchingType());
curMap.put("matchingTypeVal", curMap.get(matching.getMatchingType()));
curMap.put("matchingTypeName", matching.getMatchingTypeName());
curMap.put("matchingTypeNameVal", curMap.get(matching.getMatchingTypeName()));
curMap.put("matchingNumber", matching.getMatchingNumber());
curMap.put("matchingNumberVal", curMap.get(matching.getMatchingNumber()));
lUpdated.add(curMap);
if (lUpdated.size() == limit) {
matchingInnerDelingMapper.setResult(Map.of("itemList", lUpdated));
iUpdated = iUpdated + lUpdated.size();
lUpdated.clear();
}
}
if (lUpdated.size() > 0) {
matchingInnerDelingMapper.setResult(Map.of("itemList", lUpdated));
iUpdated = iUpdated + lUpdated.size();
}
log.debug("Updated OrgData : " + iUpdated + "건");
//작업이 정상적으로 작동 되었을 경우 현재 처리하고 있는 데이타 그대로 넘겨준다.
return item;
}
}