package com.batch.controller; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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.service.JobService; import com.batch.util.FileUtil; import com.batch.util.JsonUtil; import com.google.gson.JsonObject; import lombok.extern.slf4j.Slf4j; @RestController @RequestMapping("/api/job") @Slf4j public class JobController { @Autowired private JobService jobService; @Autowired private MatchingInnerDelingMapper matchingInnerDelingMapper; /** * TODO : AI 서버에 특정 경로에 생성되는 파일을 읽는(끝에 50줄 정도) API * */ @PostMapping("/readlogs") public StringBuffer readLogs( @RequestBody Map 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; } @PostMapping("/create") public Map createJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * } */ //Job Create Log UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start Create Job"); jobService.createData(sJobGroup, params); log.info("End Create Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "신규 작업데이타를 생성합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @PostMapping("/matching") public Map matchingJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * "cpr_code": "xxxxx", * "partn_cpr": "xxxxx", * } */ //Job Create Log UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start Matching Job"); jobService.matchingJob(sJobGroup, params); log.info("End Matching Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @PostMapping("/extramatching") public Map extraMatchingJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * "cpr_code": "xxxxx", * "partn_cpr": "xxxxx", * "searchOne": "dta_ty in ('11','21','31','33','35','37','41')", * "searchTwo": "dta_ty in ('11','21','31','33','35','37','41')" * } */ //Job Create Log UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start Extra Matching Job"); params.put("asCurrency", "Y"); List retData = matchingInnerDelingMapper.getCustomItemReadData(params); // 수익/비용 for(Map curMap : retData) { Map cParams = new HashMap(); cParams.putAll(curMap); cParams.put("conds", "T"); jobService.extraJobSub(sJobGroup, cParams); } //채권/채무 for(Map curMap : retData) { Map cParams = new HashMap(); cParams.putAll(curMap); cParams.put("conds", "B"); jobService.extraJobSub(sJobGroup, cParams); } log.info("End Extra Matching Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "Extra 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @PostMapping("/aisubmatching") public Map aiSubMatchingJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * "mtch_ty": "AI_SLT" * "cpr_code": "xxxxx", * "partn_cpr": "xxxxx" * } */ //Job Create Log UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start AI Sub Matching Job"); List retData = matchingInnerDelingMapper.getAiSubReadData(params); //AI의 경우 수익비용만 매칭하고 있음 for(Map curMap : retData) { Map cParams = new HashMap(); cParams.putAll(params); cParams.putAll(curMap); cParams.put("conds", "T"); jobService.aiSubJobSub(sJobGroup, cParams); } log.info("End Extra Matching Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "Extra 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @PostMapping("/aimatching") public Map aiMatchingJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * "cpr_code": "xxxxx", * "partn_cpr": "xxxxx", * "error_range": "0" * } */ //Job Create LogmatchingInnerDelingMapper UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start AI Matching Job"); jobService.aiJobSub(sJobGroup, params); log.info("End AI Matching Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "AI 매칭작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @PostMapping("/return") public Map returnJob( @RequestBody Map params) throws Exception { /* * { * "sysSe": "LS_ALL", * "accnutYm": "202306", * } */ UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start Return Job"); jobService.returnRwsultData(sJobGroup, params); log.info("End Return Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "매칭결과 반영을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } @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 lJobList = new ArrayList(); for (Matching curMatching : matchingSetup.getMatchingSetup()) { lJobList.add(curMatching.getType() + ':' + curMatching.getTypeName()); } return lJobList; } @GetMapping("/userJobInfo/{userJobGroup}") public Object statusBatchJob(@PathVariable(name = "userJobGroup") String sUserJobGroup) throws Exception { Map rtnVal = new HashMap(); Map mParam = new HashMap(); mParam.put("userJobGroup", sUserJobGroup); List 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; } @PostMapping("/callAsyncJob") public Map callAsyncJob( @RequestBody Map params) throws Exception { /* * { * "PrgName": "cmd", * "PrgParams": "/C dir /w", * } */ //Job Create Log UUID uuid = UUID.randomUUID(); String sJobGroup = uuid.toString(); log.info("Start AI Sub Matching Job"); //OS Command Line 수행 jobService.callAsyncJobSub(sJobGroup, params); log.info("End Extra Matching Job"); Map rtnMap = new HashMap(); rtnMap.put("jobGroupId", sJobGroup); rtnMap.put("jobMessage", "OS Command 작업을 시작합니다. 작업이 끝난후 작업결과는 별도로 확인 바랍니다."); return rtnMap; } }