Blame view

src/main/java/com/batch/controller/JobController.java 8.74 KB
8dc487b1   함상기   Init Version - 20...
1
2
3
4
5
6
  package com.batch.controller;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
78928007   함상기   20240305
7
  import java.util.UUID;
8dc487b1   함상기   Init Version - 20...
8
9
10
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.GetMapping;
78928007   함상기   20240305
11
  import org.springframework.web.bind.annotation.PathVariable;
8dc487b1   함상기   Init Version - 20...
12
13
14
15
16
17
18
19
20
21
22
23
24
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.batch.config.MatchingSetup;
  import com.batch.config.MatchingSetup.Matching;
  import com.batch.mapper.primary.MatchingInnerDelingMapper;
  import com.batch.mapper.secondary.OracleMapper;
  import com.batch.service.JobService;
  import com.batch.util.FileUtil;
  import com.google.gson.JsonObject;
  
78928007   함상기   20240305
25
  import com.batch.controller.JobController;
8dc487b1   함상기   Init Version - 20...
26
27
28
29
30
31
32
33
34
35
36
37
  import lombok.extern.slf4j.Slf4j;
  
  @RestController
  @RequestMapping("/api/job")
  @Slf4j
  public class JobController {
  
      @Autowired
      private JobService jobService;
      @Autowired
      private MatchingInnerDelingMapper matchingInnerDelingMapper;
      
9c28833f   ggun12   aiJobSub : 작업종료 처...
38
39
40
41
42
43
      
      
      
      /**
       * TODO : AI 서버에 특정 경로에 생성되는 파일을 읽는(끝에 50 정도) API 
       * */
8dc487b1   함상기   Init Version - 20...
44
45
  
      @PostMapping("/create")
78928007   함상기   20240305
46
      public Map<String, String> createJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
47
48
49
50
51
52
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
53
54
55
56
57
      	 */            
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
58
      	log.debug("Start Create Job");
78928007   함상기   20240305
59
      	jobService.createData(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
60
61
      	log.debug("End Create Job");
      	
78928007   함상기   20240305
62
63
64
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "신규 작업데이타를 생성합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
65
      	
78928007   함상기   20240305
66
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
67
68
69
70
      }
      
      
      @PostMapping("/matching")
78928007   함상기   20240305
71
      public Map<String, String> matchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
72
73
74
75
76
77
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
78
79
80
81
82
      	 */                           
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
83
      	log.debug("Start Matching Job");
78928007   함상기   20240305
84
      	jobService.matchingJob(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
85
86
      	log.debug("End Matching Job");
      	
78928007   함상기   20240305
87
88
89
90
91
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
      	    	
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
92
93
94
      }
      
      @PostMapping("/extramatching")
78928007   함상기   20240305
95
      public Map<String, String> extraMatchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
96
97
98
99
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
78928007   함상기   20240305
100
101
102
      	 *   "accnutYm": "202306",    
      	 *   "searchOne": "dta_ty in ('11','21','31','33','35','37','41')",
      	 *   "searchTwo": "dta_ty in ('11','21','31','33','35','37','41')"      
8dc487b1   함상기   Init Version - 20...
103
      	 * }  
78928007   함상기   20240305
104
105
106
107
108
      	 */                       
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
109
110
111
112
113
114
115
      	log.debug("Start Extra Matching Job");
      	List<Map> retData = matchingInnerDelingMapper.getCustomItemReadData(params);
  //    	List<Map> retData = new ArrayList<Map>();
  //    	Map m = new HashMap();
  //    	m.put("sys_se", "LS_ALL"); 
  //    	m.put("accnut_ym", "202311"); 
  //    	m.put("cpr_code", "A15300"); 
78928007   함상기   20240305
116
117
118
  //    	m.put("partn_cpr", "A01100");
  //    	m.put("searchOne", "dta_ty in ('11','21','41')");
  //    	m.put("searchTwo", "dta_ty in ('12','22','42')");
8dc487b1   함상기   Init Version - 20...
119
  //    	retData.add(m);
78928007   함상기   20240305
120
121
122
      	// 수익/비용
      	for(Map curMap : retData) {
      		curMap.put("conds", "T");
406c670d   ggun12   - 대상목록, 매칭목록 에 거래...
123
          	log.info("Start extraJobSub  Transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
78928007   함상기   20240305
124
      		jobService.extraJobSub(sJobGroup, curMap);
406c670d   ggun12   - 대상목록, 매칭목록 에 거래...
125
          	log.info("End   extraJobSub  Transaction !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
78928007   함상기   20240305
126
127
      	}
      	//채권/채무
8dc487b1   함상기   Init Version - 20...
128
      	for(Map curMap : retData) {
78928007   함상기   20240305
129
      		curMap.put("conds", "B");
406c670d   ggun12   - 대상목록, 매칭목록 에 거래...
130
          	log.info("Start extraJobSub  Balance !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
78928007   함상기   20240305
131
      		jobService.extraJobSub(sJobGroup, curMap);
406c670d   ggun12   - 대상목록, 매칭목록 에 거래...
132
          	log.info("End   extraJobSub  Balance !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
8dc487b1   함상기   Init Version - 20...
133
      	}
78928007   함상기   20240305
134
  
8dc487b1   함상기   Init Version - 20...
135
136
      	log.debug("End Extra Matching Job");
      	
78928007   함상기   20240305
137
138
139
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "Extra 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
140
      	
78928007   함상기   20240305
141
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
142
143
144
145
      }      
      
      
      @PostMapping("/aimatching")
78928007   함상기   20240305
146
      public Map<String, String> aiMatchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
147
148
149
150
151
152
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
153
154
155
156
157
      	 */             
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
158
159
160
      	log.debug("Start AI Matching Job");
      	List<Map> retData = matchingInnerDelingMapper.getAiReadData(params);
      	for(Map curMap : retData) {
78928007   함상기   20240305
161
      		jobService.aiJobSub(sJobGroup, curMap);
8dc487b1   함상기   Init Version - 20...
162
163
164
      	}
      	log.debug("End AI Matching Job");
      	
78928007   함상기   20240305
165
166
167
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "AI 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
168
      	
78928007   함상기   20240305
169
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
170
171
172
      }    
  
      @PostMapping("/return")
78928007   함상기   20240305
173
      public Map<String, String> returnJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
174
175
176
177
178
179
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
180
181
182
183
      	 */        
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
  
8dc487b1   함상기   Init Version - 20...
184
      	log.debug("Start Return Job");
78928007   함상기   20240305
185
      	jobService.returnRwsultData(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
186
187
      	log.debug("End Return Job");
      	
78928007   함상기   20240305
188
189
190
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭결과 반영을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
191
      	
78928007   함상기   20240305
192
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
      }
      
      
      @GetMapping("/configJobStr")
      public String configJobStr() throws Exception {
      	
      	StringBuffer sb = FileUtil.readFileToString("matchingSetup.json");
  
      	return sb.toString();
      }
  
      @GetMapping("/configJobJsonObj")
      public JsonObject configJobJsonObj() throws Exception {
      	
      	StringBuffer sb = FileUtil.readFileToString("matchingSetup.json");
      	JsonObject jobj = FileUtil.strToJsonObj(sb.toString());
  
      	return jobj;
      }
  
      @GetMapping("/configJobObj")
      public Object configJobObj() throws Exception {
      	
      	StringBuffer sb = FileUtil.readFileToString("matchingSetup.json");
      	MatchingSetup matchingSetup = (MatchingSetup) FileUtil.strToObj(sb.toString(), MatchingSetup.class);
  
      	return matchingSetup;
      }
  
      @GetMapping("/config")
      public Object config() throws Exception {
      	return configJobObj();
      }
  
      @GetMapping("/config/jobList")
      public Object configJobList() throws Exception {
      	
      	StringBuffer sb = FileUtil.readFileToString("matchingSetup.json");
      	MatchingSetup matchingSetup = (MatchingSetup) FileUtil.strToObj(sb.toString(), MatchingSetup.class);
  
      	List<String> lJobList = new ArrayList<String>();
      	for (Matching curMatching : matchingSetup.getMatchingSetup()) {
      		lJobList.add(curMatching.getType() + ':' + curMatching.getTypeName());
      	}
      	
      	return lJobList;
      }
  
78928007   함상기   20240305
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
      @GetMapping("/userJobInfo/{userJobGroup}")
      public Object statusBatchJob(@PathVariable(name = "userJobGroup") String sUserJobGroup) throws Exception {
      	Map<String, Object> rtnVal = new HashMap<String, Object>();
      	
      	Map<String, Object> mParam = new HashMap<String, Object>();
      	mParam.put("userJobGroup", sUserJobGroup);
      	List<Map> lmJob = matchingInnerDelingMapper.getUserJobStatus(mParam);
      	rtnVal.put("JobList", lmJob);
      	boolean blnStatus = true;
      	for (Map curMap : lmJob) {
      		String ScurStatus = (String) curMap.get("status"); 
      		if (!"Finished".equalsIgnoreCase(ScurStatus)) {
      			blnStatus = false;
      			break;
      		}
      	}
      	rtnVal.put("JobStatus", blnStatus);
      	
      	
      	return rtnVal;
      }
      
8dc487b1   함상기   Init Version - 20...
263
264
      
  }