Commit efecfd5344a62e07adda725290eb2f53667071fc
1 parent
883da593
.
Showing
4 changed files
with
270 additions
and
0 deletions
Show diff stats
src/main/java/com/batch/service/ThreadAiMatching.java
0 → 100644
1 | +package com.batch.service; | ||
2 | + | ||
3 | +import java.text.SimpleDateFormat; | ||
4 | +import java.util.Date; | ||
5 | +import java.util.HashMap; | ||
6 | +import java.util.Map; | ||
7 | +import java.util.UUID; | ||
8 | + | ||
9 | +import org.zeroturnaround.exec.ProcessExecutor; | ||
10 | +import org.zeroturnaround.exec.stream.LogOutputStream; | ||
11 | + | ||
12 | +import com.batch.mapper.primary.MatchingInnerDelingMapper; | ||
13 | + | ||
14 | +import lombok.extern.slf4j.Slf4j; | ||
15 | + | ||
16 | +@Slf4j | ||
17 | +public class ThreadAiMatching extends Thread { | ||
18 | + String jobGroupId; | ||
19 | + Map paramRec; | ||
20 | + MatchingInnerDelingMapper matchingInnerDelingMapper; | ||
21 | + String sPythonPrg; | ||
22 | + String sPythonAiTarget; | ||
23 | + | ||
24 | + public ThreadAiMatching( | ||
25 | + String pJobGroupId, | ||
26 | + Map pParamRec, | ||
27 | + MatchingInnerDelingMapper pMatchingInnerDelingMapper, | ||
28 | + String pPythonPrg, | ||
29 | + String pPythonAiTarget | ||
30 | + ) { | ||
31 | + this.jobGroupId = pJobGroupId; | ||
32 | + this.paramRec = pParamRec; | ||
33 | + this.matchingInnerDelingMapper = pMatchingInnerDelingMapper; | ||
34 | + this.sPythonPrg = pPythonPrg; | ||
35 | + this.sPythonAiTarget = pPythonAiTarget; | ||
36 | + } | ||
37 | + | ||
38 | + @Override | ||
39 | + public void run() { | ||
40 | + | ||
41 | + //Job Create Log | ||
42 | + UUID uuid = UUID.randomUUID(); | ||
43 | + HashMap<String, String> mt = new HashMap<String, String>(); | ||
44 | + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss"); | ||
45 | + String sDate = dateFormat.format(new Date()) + ":" + uuid.toString(); | ||
46 | + | ||
47 | + Map<String, Object> paramLog = new HashMap<String, Object>(); | ||
48 | + paramLog.put("user_job_group", jobGroupId); | ||
49 | + paramLog.put("user_job_id", sDate); | ||
50 | + paramLog.put("user_job_name", "AI매칭(" + paramRec.toString() + ")"); | ||
51 | + matchingInnerDelingMapper.createUserJob(paramLog); | ||
52 | + | ||
53 | + | ||
54 | + long startTime = System.currentTimeMillis(); | ||
55 | + log.info("ai Job Started : " + startTime); | ||
56 | + log.debug("ai Job params=" + paramRec.toString()); | ||
57 | + | ||
58 | + String sSysSe = (String) paramRec.get("sys_se"); | ||
59 | + String sAccnutYm = (String) paramRec.get("accnut_ym"); | ||
60 | + String sCprCode = (String) paramRec.get("cpr_code"); | ||
61 | + String sPartCpr = (String) paramRec.get("partn_cpr"); | ||
62 | + String sDelngCrncy = (String) paramRec.get("delng_crncy"); | ||
63 | + String sTbTy = (String) paramRec.get("tb_ty"); | ||
64 | + String sErrorRange = (String) paramRec.get("error_range"); | ||
65 | + | ||
66 | + String sThreadName = Thread.currentThread().getName(); | ||
67 | + | ||
68 | + log.debug("call python"); | ||
69 | + try { | ||
70 | + Thread.sleep(15000); | ||
71 | + | ||
72 | + new ProcessExecutor() | ||
73 | + .command(sPythonPrg, sPythonAiTarget, sDate, sSysSe, sAccnutYm, sCprCode, sPartCpr, sDelngCrncy, sErrorRange, sTbTy) | ||
74 | + .redirectOutput(new LogOutputStream() { | ||
75 | + @Override | ||
76 | + protected void processLine(String line) { | ||
77 | + log.info(line); | ||
78 | + } | ||
79 | + }) | ||
80 | + .execute(); | ||
81 | + | ||
82 | + long endTime = System.currentTimeMillis(); | ||
83 | + log.info("ai Job Ended: " + endTime); | ||
84 | + log.info("ai Job Running Time : " + (endTime - startTime) + "ms"); | ||
85 | + | ||
86 | + } catch(Exception e) { | ||
87 | + log.info("ai Job Start Fail : " + startTime); | ||
88 | + | ||
89 | + //작업종료에 대한 로그 업데이트(실패) | ||
90 | + paramLog.put("exit_code", "-1"); | ||
91 | + paramLog.put("exit_message", e.getMessage()); | ||
92 | + matchingInnerDelingMapper.finishUserJob(paramLog); | ||
93 | + } | ||
94 | + | ||
95 | + } | ||
96 | + | ||
97 | +} |
1 | +package com.batch.util; | ||
2 | + | ||
3 | +import org.springframework.stereotype.Component; | ||
4 | + | ||
5 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
6 | + | ||
7 | +@Component | ||
8 | +public class JsonUtil { | ||
9 | + | ||
10 | + public static String objectToString(Object object) { | ||
11 | + String rtnVal = ""; | ||
12 | + try { | ||
13 | + ObjectMapper objectMapper = new ObjectMapper(); | ||
14 | + rtnVal = objectMapper.writeValueAsString(object); | ||
15 | + } catch (Exception e) { | ||
16 | + e.printStackTrace(); | ||
17 | + rtnVal = "Error"; | ||
18 | + } | ||
19 | + return rtnVal; | ||
20 | + } | ||
21 | + | ||
22 | + public static Object stringToObject(String sJson, Class<?> objClass) { | ||
23 | + Object rtnVal; | ||
24 | + try { | ||
25 | + ObjectMapper objectMapper = new ObjectMapper(); | ||
26 | + rtnVal = objectMapper.readValue(sJson, objClass); | ||
27 | + } catch (Exception e) { | ||
28 | + e.printStackTrace(); | ||
29 | + rtnVal = "Error"; | ||
30 | + } | ||
31 | + return rtnVal; | ||
32 | + } | ||
33 | + | ||
34 | + public static Object objectToObject(Object object, Class<?> objClass) { | ||
35 | + return stringToObject(objectToString(object), objClass); | ||
36 | + } | ||
37 | + | ||
38 | +} | ||
0 | \ No newline at end of file | 39 | \ No newline at end of file |
1 | +package com.batch.util; | ||
2 | + | ||
3 | +import java.io.UnsupportedEncodingException; | ||
4 | +import java.net.URLDecoder; | ||
5 | +import java.net.URLEncoder; | ||
6 | +import java.util.ArrayList; | ||
7 | +import java.util.Arrays; | ||
8 | +import java.util.HashMap; | ||
9 | +import java.util.Iterator; | ||
10 | +import java.util.List; | ||
11 | +import java.util.Map; | ||
12 | +import java.util.StringTokenizer; | ||
13 | +import java.util.Vector; | ||
14 | + | ||
15 | +import org.apache.commons.lang3.StringUtils; | ||
16 | + | ||
17 | +/** | ||
18 | + * <p> | ||
19 | + * <code>StringUtil</code> 은 String의 handling과 관련된 class이다. | ||
20 | + * <p> | ||
21 | + */ | ||
22 | + | ||
23 | +public class StringUtil { | ||
24 | + /** | ||
25 | + * lPad(inStr, iSize, sPadStr) | ||
26 | + * | ||
27 | + * @param inStr | ||
28 | + * @param iSize | ||
29 | + * @param sPadStr | ||
30 | + * @return | ||
31 | + */ | ||
32 | + public static String leftPad(String inStr, int iSize, String sPadStr) { | ||
33 | + return StringUtils.leftPad(inStr, iSize, sPadStr); | ||
34 | + } | ||
35 | + | ||
36 | + /** | ||
37 | + * rPad(inStr, iSize, sPadStr) | ||
38 | + * | ||
39 | + * @param inStr | ||
40 | + * @param iSize | ||
41 | + * @param sPadStr | ||
42 | + * @return | ||
43 | + */ | ||
44 | + public static String rightPad(String inStr, int iSize, String sPadStr) { | ||
45 | + return StringUtils.rightPad(inStr, iSize, sPadStr); | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * inStr이 null/""/"공백문자" 이면 default | ||
50 | + * | ||
51 | + * @param inStr | ||
52 | + * @param sDefault | ||
53 | + * @return | ||
54 | + */ | ||
55 | + public static String defaultIfBlank(String inStr, String sDefault) { | ||
56 | + return StringUtils.defaultIfBlank(inStr, sDefault); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * inStr이 null/"" 이면 default | ||
61 | + * | ||
62 | + * @param inStr | ||
63 | + * @param sDefault | ||
64 | + * @return | ||
65 | + */ | ||
66 | + public static String defaultIfEmpty(String inStr, String sDefault) { | ||
67 | + return StringUtils.defaultIfEmpty(inStr, sDefault); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Strip 결과가 Null이나 ""이면 "" | ||
72 | + * | ||
73 | + * @param inStr | ||
74 | + * @param sDefault | ||
75 | + * @return | ||
76 | + */ | ||
77 | + public static String stripToEmpty(String inStr) { | ||
78 | + return StringUtils.stripToEmpty(inStr); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Strip 결과가 "" 이면 NULL | ||
83 | + * | ||
84 | + * @param inStr | ||
85 | + * @param sDefault | ||
86 | + * @return | ||
87 | + */ | ||
88 | + public static String stripToNull(String inStr) { | ||
89 | + return StringUtils.stripToNull(inStr); | ||
90 | + } | ||
91 | + | ||
92 | + public static String remove(String inStr, String sRemoveStr) { | ||
93 | + return StringUtils.remove(inStr, sRemoveStr); | ||
94 | + } | ||
95 | + | ||
96 | + public static String replace(String inStr, String sTargetStr, String sReplaceStr) { | ||
97 | + return StringUtils.replace(sTargetStr, inStr, sReplaceStr); | ||
98 | + } | ||
99 | + | ||
100 | + public static String trimToEmpty(String inStr) { | ||
101 | + return StringUtils.trimToEmpty(inStr); | ||
102 | + } | ||
103 | + | ||
104 | + public static String trimToNull(String inStr) { | ||
105 | + return StringUtils.trimToNull(inStr); | ||
106 | + } | ||
107 | + | ||
108 | + public static List<String> StringToArrayList(String inStr) { | ||
109 | + return StringToArrayList(inStr, null); | ||
110 | + } | ||
111 | + | ||
112 | + public static List<String> StringToArrayList(String inStr, String inSplit) { | ||
113 | + List<String> lRtn = new ArrayList<String>(); | ||
114 | + if (inSplit == null) inSplit = ","; | ||
115 | + if (inStr != null) { | ||
116 | + String[] slVal = inStr.split(inSplit); | ||
117 | + lRtn = new ArrayList<String>(Arrays.asList(slVal)); | ||
118 | + } | ||
119 | + return lRtn; | ||
120 | + } | ||
121 | + | ||
122 | +} | ||
0 | \ No newline at end of file | 123 | \ No newline at end of file |
1 | +import sys | ||
2 | + | ||
3 | +# PARAMITER | ||
4 | +JOB_ID = sys.argv[1] | ||
5 | +SYS_SE = sys.argv[2] | ||
6 | +FCST_YM = sys.argv[3] | ||
7 | +SELF_CD = sys.argv[4] | ||
8 | +OTHER_CD = sys.argv[5] | ||
9 | +CUR = sys.argv[6] | ||
10 | +TT_SUM = sys.argv[7] # 합산차액 허용오차값 | ||
11 | +DTA_TY = sys.argv[8] # T : 트랜잭션 , B : 발란스 | ||
12 | + | ||
13 | +print(sys.argv) | ||
0 | \ No newline at end of file | 14 | \ No newline at end of file |