Blame view

src/main/java/com/batch/controller/JobController.java 8.55 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
  
  import org.springframework.beans.factory.annotation.Autowired;
8dc487b1   함상기   Init Version - 20...
10
  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
  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;
8dc487b1   함상기   Init Version - 20...
20
21
22
23
  import com.batch.service.JobService;
  import com.batch.util.FileUtil;
  import com.google.gson.JsonObject;
  
8dc487b1   함상기   Init Version - 20...
24
25
26
27
28
29
30
31
32
33
34
35
  import lombok.extern.slf4j.Slf4j;
  
  @RestController
  @RequestMapping("/api/job")
  @Slf4j
  public class JobController {
  
      @Autowired
      private JobService jobService;
      @Autowired
      private MatchingInnerDelingMapper matchingInnerDelingMapper;
      
31cbf4da   함상기   2024-04-02
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
      
      
      
      /**
       * TODO : AI 서버에 특정 경로에 생성되는 파일을 읽는(끝에 50 정도) API 
       * */
      @PostMapping("/readlogs")
      public StringBuffer readLogs( @RequestBody Map<String, String> params) throws Exception {
  		StringBuffer sb = new StringBuffer();
  		
  		String filePath  = params.get("filePath");
  		int readCnt  = Integer.parseInt(params.get("readCnt"));
  		
      	sb = FileUtil.readFileLastLines(filePath, readCnt, "ISO-8859-1", "UTF-8");
  
      	log.info("sb ===");
      	log.info(sb.toString());
  		return sb;
      }
8dc487b1   함상기   Init Version - 20...
55
56
  
      @PostMapping("/create")
78928007   함상기   20240305
57
      public Map<String, String> createJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
58
59
60
61
62
63
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
64
65
66
67
68
      	 */            
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
69
      	log.debug("Start Create Job");
78928007   함상기   20240305
70
      	jobService.createData(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
71
72
      	log.debug("End Create Job");
      	
78928007   함상기   20240305
73
74
75
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "신규 작업데이타를 생성합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
76
      	
78928007   함상기   20240305
77
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
78
79
80
81
      }
      
      
      @PostMapping("/matching")
78928007   함상기   20240305
82
      public Map<String, String> matchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
83
84
85
86
87
88
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
89
90
91
92
93
      	 */                           
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
94
      	log.debug("Start Matching Job");
78928007   함상기   20240305
95
      	jobService.matchingJob(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
96
97
      	log.debug("End Matching Job");
      	
78928007   함상기   20240305
98
99
100
101
102
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
      	    	
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
103
104
105
      }
      
      @PostMapping("/extramatching")
78928007   함상기   20240305
106
      public Map<String, String> extraMatchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
107
108
109
110
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
78928007   함상기   20240305
111
112
113
      	 *   "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...
114
      	 * }  
78928007   함상기   20240305
115
      	 */                       
78928007   함상기   20240305
116
117
118
119
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
d3e8a8a9   함상기   2024-04-01
120
121
      	log.debug("Start Extra Matching Job");
      	List<Map> retData = matchingInnerDelingMapper.getCustomItemReadData(params);
a45ecedc   ggun12   * EX 매칭은 순차 실행으로 처리
122
  
d3e8a8a9   함상기   2024-04-01
123
124
125
126
127
128
129
130
131
132
133
134
135
136
      	// 수익/비용
      	for(Map curMap : retData) {
      		Map<String, String> cParams = new HashMap<String, String>();
      		cParams.putAll(curMap);
      		cParams.put("conds", "T");
      		jobService.extraJobSub(sJobGroup, cParams);
      	}
      	//채권/채무
      	for(Map curMap : retData) {
      		Map<String, String> cParams = new HashMap<String, String>();
      		cParams.putAll(curMap);
      		cParams.put("conds", "B");
      		jobService.extraJobSub(sJobGroup, cParams);
      	}
a45ecedc   ggun12   * EX 매칭은 순차 실행으로 처리
137
  
d3e8a8a9   함상기   2024-04-01
138
      	log.debug("End Extra Matching Job");
8dc487b1   함상기   Init Version - 20...
139
      	
78928007   함상기   20240305
140
141
142
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "Extra 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
143
      	
78928007   함상기   20240305
144
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
145
146
147
148
      }      
      
      
      @PostMapping("/aimatching")
78928007   함상기   20240305
149
      public Map<String, String> aiMatchingJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
150
151
152
153
154
155
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
156
157
158
159
160
      	 */             
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
8dc487b1   함상기   Init Version - 20...
161
162
163
      	log.debug("Start AI Matching Job");
      	List<Map> retData = matchingInnerDelingMapper.getAiReadData(params);
      	for(Map curMap : retData) {
78928007   함상기   20240305
164
      		jobService.aiJobSub(sJobGroup, curMap);
8dc487b1   함상기   Init Version - 20...
165
166
167
      	}
      	log.debug("End AI Matching Job");
      	
78928007   함상기   20240305
168
169
170
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "AI 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
171
      	
78928007   함상기   20240305
172
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
173
174
175
      }    
  
      @PostMapping("/return")
78928007   함상기   20240305
176
      public Map<String, String> returnJob( @RequestBody Map<String, String> params) throws Exception {
8dc487b1   함상기   Init Version - 20...
177
178
179
180
181
182
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
78928007   함상기   20240305
183
184
185
186
      	 */        
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
  
8dc487b1   함상기   Init Version - 20...
187
      	log.debug("Start Return Job");
78928007   함상기   20240305
188
      	jobService.returnRwsultData(sJobGroup, params);
8dc487b1   함상기   Init Version - 20...
189
190
      	log.debug("End Return Job");
      	
78928007   함상기   20240305
191
192
193
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭결과 반영을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
8dc487b1   함상기   Init Version - 20...
194
      	
78928007   함상기   20240305
195
          return rtnMap;
8dc487b1   함상기   Init Version - 20...
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
241
242
243
      }
      
      
      @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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
      @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...
266
267
      
  }