Blame view

src/main/java/daeucna/batch/controller/JobController.java 8.7 KB
2034b5b1   함상기   Init Version 2024...
1
2
  package daeucna.batch.controller;
  
5b5ab7e5   함상기   20240409
3
  import java.text.SimpleDateFormat;
2034b5b1   함상기   Init Version 2024...
4
  import java.util.ArrayList;
5b5ab7e5   함상기   20240409
5
6
  import java.util.Date;
  import java.util.HashMap;
2034b5b1   함상기   Init Version 2024...
7
8
  import java.util.List;
  import java.util.Map;
5b5ab7e5   함상기   20240409
9
  import java.util.UUID;
2034b5b1   함상기   Init Version 2024...
10
11
12
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.web.bind.annotation.GetMapping;
5b5ab7e5   함상기   20240409
13
  import org.springframework.web.bind.annotation.PathVariable;
2034b5b1   함상기   Init Version 2024...
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
  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.google.gson.JsonObject;
  
  import daeucna.batch.service.JobService;
  import daeucna.batch.util.FileUtil;
  import daeucna.config.batch.MatchingSetup;
  import daeucna.config.batch.MatchingSetup.Matching;
  import daeucna.mapper.primary.batch.MatchingInnerDelingMapper;
  import lombok.extern.slf4j.Slf4j;
  
  @RestController
  @RequestMapping("/api/job")
  @Slf4j
  public class JobController {
  
      @Autowired
      private JobService jobService;
      @Autowired
      private MatchingInnerDelingMapper matchingInnerDelingMapper;
      
  
      @PostMapping("/create")
5b5ab7e5   함상기   20240409
40
      public Map<String, String> createJob( @RequestBody Map<String, String> params) throws Exception {
2034b5b1   함상기   Init Version 2024...
41
42
43
44
45
46
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
5b5ab7e5   함상기   20240409
47
48
49
50
51
      	 */            
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
2034b5b1   함상기   Init Version 2024...
52
      	log.debug("Start Create Job");
5b5ab7e5   함상기   20240409
53
      	jobService.createData(sJobGroup, params);
2034b5b1   함상기   Init Version 2024...
54
55
      	log.debug("End Create Job");
      	
5b5ab7e5   함상기   20240409
56
57
58
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "신규 작업데이타를 생성합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
2034b5b1   함상기   Init Version 2024...
59
      	
5b5ab7e5   함상기   20240409
60
          return rtnMap;
2034b5b1   함상기   Init Version 2024...
61
62
63
64
65
66
67
68
69
70
71
      }
      
      
      @PostMapping("/matching")
      public String matchingJob( @RequestBody Map<String, String> params) throws Exception {
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
5b5ab7e5   함상기   20240409
72
73
74
75
76
      	 */                           
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
2034b5b1   함상기   Init Version 2024...
77
      	log.debug("Start Matching Job");
5b5ab7e5   함상기   20240409
78
      	jobService.matchingJob(sJobGroup, params);
2034b5b1   함상기   Init Version 2024...
79
80
      	log.debug("End Matching Job");
      	
5b5ab7e5   함상기   20240409
81
82
83
84
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
      	    	
2034b5b1   함상기   Init Version 2024...
85
86
87
88
          return "매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.";
      }
      
      @PostMapping("/extramatching")
5b5ab7e5   함상기   20240409
89
      public Map<String, String> extraMatchingJob( @RequestBody Map<String, String> params) throws Exception {
2034b5b1   함상기   Init Version 2024...
90
91
92
93
94
95
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
5b5ab7e5   함상기   20240409
96
97
98
99
100
      	 */                       
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
2034b5b1   함상기   Init Version 2024...
101
102
103
104
105
106
107
108
109
110
      	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"); 
  //    	m.put("partn_cpr", "A01100"); 
  //    	retData.add(m);
      	for(Map curMap : retData) {
5b5ab7e5   함상기   20240409
111
      		jobService.extraJobSub(sJobGroup, curMap);
2034b5b1   함상기   Init Version 2024...
112
113
114
      	}
      	log.debug("End Extra Matching Job");
      	
5b5ab7e5   함상기   20240409
115
116
117
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "Extra 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
2034b5b1   함상기   Init Version 2024...
118
      	
5b5ab7e5   함상기   20240409
119
          return rtnMap;
2034b5b1   함상기   Init Version 2024...
120
121
122
123
      }      
      
      
      @PostMapping("/aimatching")
5b5ab7e5   함상기   20240409
124
      public Map<String, String> aiMatchingJob( @RequestBody Map<String, String> params) throws Exception {
2034b5b1   함상기   Init Version 2024...
125
126
127
128
129
130
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
5b5ab7e5   함상기   20240409
131
132
133
134
135
      	 */             
      	//Job Create Log
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
      	
2034b5b1   함상기   Init Version 2024...
136
137
138
      	log.debug("Start AI Matching Job");
      	List<Map> retData = matchingInnerDelingMapper.getAiReadData(params);
      	for(Map curMap : retData) {
5b5ab7e5   함상기   20240409
139
      		jobService.aiJobSub(sJobGroup, curMap);
2034b5b1   함상기   Init Version 2024...
140
141
142
      	}
      	log.debug("End AI Matching Job");
      	
5b5ab7e5   함상기   20240409
143
144
145
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "AI 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
2034b5b1   함상기   Init Version 2024...
146
      	
5b5ab7e5   함상기   20240409
147
          return rtnMap;
2034b5b1   함상기   Init Version 2024...
148
149
150
      }    
  
      @PostMapping("/return")
5b5ab7e5   함상기   20240409
151
      public Map<String, String> returnJob( @RequestBody Map<String, String> params) throws Exception {
2034b5b1   함상기   Init Version 2024...
152
153
154
155
156
157
      	
      	/*
      	 * {                                
      	 *   "sysSe": "LS_ALL",             
      	 *   "accnutYm": "202306",          
      	 * }  
5b5ab7e5   함상기   20240409
158
159
160
161
      	 */        
      	UUID uuid = UUID.randomUUID();
      	String sJobGroup = uuid.toString();
  
2034b5b1   함상기   Init Version 2024...
162
      	log.debug("Start Return Job");
5b5ab7e5   함상기   20240409
163
      	jobService.returnRwsultData(sJobGroup, params);
2034b5b1   함상기   Init Version 2024...
164
165
      	log.debug("End Return Job");
      	
5b5ab7e5   함상기   20240409
166
167
168
      	Map<String, String> rtnMap = new HashMap<String, String>();
      	rtnMap.put("jobGroupId", sJobGroup);
      	rtnMap.put("jobMessage", "매칭결과 반영을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다.");
2034b5b1   함상기   Init Version 2024...
169
      	
5b5ab7e5   함상기   20240409
170
          return rtnMap;
2034b5b1   함상기   Init Version 2024...
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
218
      }
      
      
      @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;
      }
  
5b5ab7e5   함상기   20240409
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
      @GetMapping("/batchJobInfo/{jobExecutionId}")
      public Object statusBatchJob(@PathVariable(name = "jobExecutionId") Integer iJobExecutionId) throws Exception {
      	Map<String, Object> rtnVal = new HashMap<String, Object>();
      	
      	Map<String, Object> mParam = new HashMap<String, Object>();
      	mParam.put("jobExecutionId", iJobExecutionId);
      	List<Map> lmJob = matchingInnerDelingMapper.getJobStatus(mParam);
      	if (lmJob.size() > 0) rtnVal.put("JobStatus", lmJob.get(0));
      	    	
      	List<Map> lmParameter = matchingInnerDelingMapper.getJobParameter(mParam);
      	if (lmParameter.size() > 0) lmJob.get(0).put("Parameter", lmParameter.get(0));
  
      	List<Map> lmStep = matchingInnerDelingMapper.getStepStatus(mParam);
      	if (lmStep.size() > 0) lmJob.get(0).put("StepsStatus", lmStep);
      	
      	
      	return rtnVal;
      }
  
      @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;
      }
2034b5b1   함상기   Init Version 2024...
259
260
      
  }