배치 모니터링 커밋

This commit is contained in:
Leeminha
2022-11-03 17:47:49 +09:00
parent 46bd508b8e
commit e2fd670cfc
19 changed files with 817 additions and 56 deletions

View File

@@ -10,13 +10,17 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import kr.co.uplus.ez.api.sysMgt.dto.*;
import kr.co.uplus.ez.common.components.ValidComponents;
import kr.co.uplus.ez.common.components.WebClientRequestService;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import kr.co.uplus.ez.common.data.Const;
import org.apache.http.HttpStatus;
import org.apache.http.protocol.HTTP;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.validation.BindingResult;
@@ -24,6 +28,10 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
@@ -37,12 +45,23 @@ import java.util.Map;
public class SysMgtController {
private static final Logger logger = LoggerFactory.getLogger(SysMgtController.class);
@Autowired
private WebClientRequestService clientRequestService;
@Autowired
SysMgtService sysService;
@Autowired
ValidComponents validComponents;
@Value("${msghubez.batch-url:http://localhost:7070}")
private String batchDomain;
@Value("${msghubez.uri.batchExecuteJob:/executeJob}")
private String executeJob;
/**
* date : 2022. 4. 25. auth : ckr desc : HUBEZ_BO_API_4001 - 관리자 목록 조회.
@@ -250,10 +269,138 @@ public class SysMgtController {
}
/**
* data: 2022. 10.24.
* auth: Lee minha
* desc: 배치 리스트 조회
* @return
*/
@ApiOperation(value = "batchList", notes = "배치 리스트 조회")
@RequestMapping(value = "/batchList", method = {RequestMethod.POST})
@ResponseBody
public Object batchList() {
public BatchListResDto batchList() {
return sysService.batchList();
}
/**
* data : 2022. 10. 26
* auth : Lee minha
* desc : 배치 상세내용
* @return
*/
@ApiOperation(value = "batchDetail", notes = "배치 상세내용")
@ApiResponses({ @ApiResponse(code = HttpServletResponse.SC_OK, message = "SUCESS") })
@RequestMapping(value = "batchDetail", method = {RequestMethod.POST})
@ResponseBody
public BatchDetailResDto batchDetail(@RequestBody @Valid BatchDetailReqDto batchDetailReqDto,
BindingResult bindingResult) {
if (validComponents.validParameter(bindingResult)) {
return new BatchDetailResDto(ApiResponseCode.CM_PARAMETER_ERROR);
}
// batchDetailReqDto.setBatchId("BATCH_010");
logger.debug("param 확인 : "+ batchDetailReqDto);
return sysService.batchDetail(batchDetailReqDto);
}
@RequestMapping(value = "batchExecuteJob", method = {RequestMethod.POST})
@ResponseBody
public BatchExeLogResDto batchExecuteJob(@RequestBody @Valid Map<Object, Object> batchReqMap) {
logger.info("batchReqMap={}",batchReqMap);
Map<Object, Object> batchResultMap = new HashMap<Object, Object>();
Map<Object, Object> resultMap = new HashMap<Object, Object>();
JSONObject jsonObject = new JSONObject();
String callUrl = batchDomain + executeJob;
String monthBatch = "yyyyMM";
String dayBatch = "yyyyMMdd";
String timeBatch = "yyyyMMddHHmmss";
SimpleDateFormat monthDateFormat = new SimpleDateFormat(monthBatch);
SimpleDateFormat dayDateFormat = new SimpleDateFormat(dayBatch);
SimpleDateFormat timeDateFormat = new SimpleDateFormat(timeBatch);
logger.info("callUrl={}",callUrl);
String jobId = (String) batchReqMap.get("batchId");
String strDate = (String) batchReqMap.get("strDate");
if(
//월배치일 경우 날짜
jobId.equals("BATCH_001")||
jobId.equals("BATCH_002")||
jobId.equals("BATCH_004")||
jobId.equals("BATCH_005")||
jobId.equals("BATCH_006")||
jobId.equals("BATCH_009")||
jobId.equals("BATCH_011")||
jobId.equals("BATCH_020")) {
strDate = monthDateFormat.format(new Date());
logger.info("strDate={}",strDate);
} else if (
//일배치일 경우 날짜
jobId.equals("BATCH_003")||
jobId.equals("BATCH_008")||
jobId.equals("BATCH_010")||
jobId.equals("BATCH_012")||
jobId.equals("BATCH_013")||
jobId.equals("BATCH_014")||
jobId.equals("BATCH_015")||
jobId.equals("BATCH_018")||
jobId.equals("BATCH_019")){
strDate = dayDateFormat.format(new Date());
logger.info("strDate={}",strDate);
} else {
strDate = timeDateFormat.format(new Date());
logger.info("strDate={}",strDate);
}
try {
logger.info("batchReqMap={}",batchReqMap);
jsonObject.put("strDate", strDate);
jsonObject.put("jobId", jobId);
logger.info("jsonObject={}",jsonObject);
batchResultMap = (Map<Object, Object>) clientRequestService.callBySyncPost(callUrl, jsonObject);
Map<Object, Object> returnMsg = new HashMap<Object, Object>();
returnMsg = (Map<Object, Object>) batchResultMap.get("returnMsg");
logger.info("batchResultMap={}",batchResultMap);
if(batchResultMap == null) {
resultMap.put("BATCH_RSLT", Const.BATCH_RESULT_FAIL);
resultMap.put("BATCH_RSLT_MSG", "BATCH Result Recive null error");
} else {
if("02".equals(returnMsg.get("code"))) {
resultMap.put("BATCH_RSLT", Const.BATCH_RESULT_SUCCESS);
resultMap.put("BATCH_RSLT_MSG", returnMsg.get("msg"));
} else {
resultMap.put("BATCH_RSLT", Const.BATCH_RESULT_FAIL);
resultMap.put("BATCH_RSLT_MSG", returnMsg.get("msg"));
}
resultMap.putAll(batchResultMap);
}
} catch (Exception e) {
logger.error("mhez-batch fail : {}", e.getMessage(),e);
resultMap.put("BATCH_RSLT", Const.BATCH_RESULT_FAIL);
resultMap.put("BATCH_RSLT_MSG", e.getMessage());
}
logger.info("getChannel start : {}", callUrl);
logger.info("jsonObject: {}",jsonObject);
logger.info("resultMap: {}",resultMap);
return new BatchExeLogResDto(ApiResponseCode.SUCCESS,resultMap);
}
}

View File

@@ -46,7 +46,9 @@ public interface SysMgtMapper {
int checkAdmin(Map<String, Object> paramMap);
public List<BatchList> batchListSelect();
public List<BatchList> batchListSelect(); //배치 리스트 조회
public List<BatchChkDto> batchDetailSelect();
public List<BatchDetail> batchDetailSelect(BatchDetailReqDto batchDetailReqDto); //배치 상세내용
int batchDetailCnt(BatchDetailReqDto batchDetailReqDto);
}

View File

@@ -1,9 +1,12 @@
package kr.co.uplus.ez.api.sysMgt;
import kr.co.uplus.ez.api.calculate.dto.CalcListResDto;
import kr.co.uplus.ez.api.sysMgt.dto.*;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import kr.co.uplus.ez.common.data.Paging;
import kr.co.uplus.ez.common.utils.EncryptionUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.mybatis.spring.SqlSessionTemplate;
import org.slf4j.Logger;
@@ -18,6 +21,7 @@ import java.util.List;
import java.util.Map;
@Service
@Slf4j
public class SysMgtService {
private static final Logger logger = LoggerFactory.getLogger(SysMgtService.class);
@@ -404,18 +408,69 @@ public class SysMgtService {
return new UpdateAuthResDto(ApiResponseCode.SUCCESS);
}
/**
* data : 2022. 10. 25.
* auth : Lee minha
* desc : 배치 리스트 조회
* @return
*/
public BatchListResDto batchList() {
SysMgtMapper sysmgtmapper = sqlSessionSlave.getMapper(SysMgtMapper.class);
List<BatchList> batchLists = sysmgtmapper.batchListSelect();
BatchListRes batchListRes = new BatchListRes();
batchListRes.setList(batchLists);
return new BatchListResDto(ApiResponseCode.SUCCESS, batchListRes);
}
/**
* data : 2022. 10. 26.
* auth : Lee minha
* desc : 배치 상세내용 조회
* @param batchDetailReqDto
* @return
*/
public BatchDetailResDto batchDetail(BatchDetailReqDto batchDetailReqDto) {
SysMgtMapper sysMgtMapper = sqlSessionSlave.getMapper(SysMgtMapper.class);
BatchDetailRes batchDetailRes = new BatchDetailRes();
String nowPage = String.valueOf(batchDetailReqDto.getPage());
int totalCnt = sysMgtMapper.batchDetailCnt(batchDetailReqDto);
if (totalCnt == 0) {
batchDetailRes.setList(new ArrayList<>());
Paging paging = new Paging();
paging.setPage(nowPage);
paging.setTotalCnt(String.valueOf(totalCnt));
batchDetailRes.setPaging(paging);
return new BatchDetailResDto(ApiResponseCode.CM_NOT_FOUND, batchDetailRes);
}
int page = batchDetailReqDto.getPage();
int pagePerRows = batchDetailReqDto.getPagePerRows();
page = (page - 1) * pagePerRows;
batchDetailReqDto.setPage(page);
List<BatchDetail> batchDetail = sysMgtMapper.batchDetailSelect(batchDetailReqDto);
batchDetailRes.setList(batchDetail);
Paging paging = new Paging();
paging.setPage(nowPage);
paging.setTotalCnt(String.valueOf(totalCnt));
batchDetailRes.setPaging(paging);
return new BatchDetailResDto(ApiResponseCode.SUCCESS, batchDetailRes);
}
}

View File

@@ -0,0 +1,48 @@
package kr.co.uplus.ez.api.sysMgt.dto;
import lombok.Data;
/**
* 배치 상세조회 DTO
* @author Lee Minha
*
*/
@Data
public class BatchDetail {
//일련번호
private String seqNo;
//등록 일시
private String regDt;
//배치 아이디
private String batchId;
//배치 명
private String batchNm;
//상태코드
private String sttusCd;
//시작 일시
private String stDt;
//종료 일시
private String fnsDt;
//오류 메시지
private String errMsg;
//등록 ID
private String regId;
//변경 ID
private String chgId;
//변경 일시
private String chgDt;
}

View File

@@ -0,0 +1,40 @@
package kr.co.uplus.ez.api.sysMgt.dto;
import java.io.Serializable;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@SuppressWarnings("serial")
@Data
public class BatchDetailReqDto implements Serializable{
//배치 아이디
private String batchId;
//검색 시작일
private String startDt;
//검색 종료일
private String endDt;
//수동 실행 일자
private String strDate;
//상태코드
private String sttusCd;
@NotNull
@ApiModelProperty(example = "50", name = "페이지당 조회할 목록 수", dataType = "String")
private int pagePerRows;
@NotNull
@ApiModelProperty(example = "1", name = "현재 페이지", dataType = "int")
private int page;
}

View File

@@ -0,0 +1,15 @@
package kr.co.uplus.ez.api.sysMgt.dto;
import java.io.Serializable;
import java.util.List;
import kr.co.uplus.ez.common.data.Paging;
import lombok.Data;
@SuppressWarnings("serial")
@Data
public class BatchDetailRes implements Serializable {
private Paging paging;
private List<BatchDetail> list;
}

View File

@@ -0,0 +1,31 @@
package kr.co.uplus.ez.api.sysMgt.dto;
import java.io.Serializable;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import kr.co.uplus.ez.common.data.ResponseMessage;
import lombok.Data;
@SuppressWarnings("serial")
@Data
public class BatchDetailResDto extends ResponseMessage implements Serializable{
private BatchDetailRes data;
public BatchDetailResDto() {
this.retCode = ApiResponseCode.SUCCESS.getResultCode();
this.retMsg = ApiResponseCode.SUCCESS.getResultMsg();
}
public BatchDetailResDto(ApiResponseCode returnStr) {
this.retCode = returnStr.getResultCode();
this.retMsg = returnStr.getResultMsg();
}
public BatchDetailResDto(ApiResponseCode returnStr, BatchDetailRes data) {
this.retCode = returnStr.getResultCode();
this.retMsg = returnStr.getResultMsg();
this.data = data;
}
}

View File

@@ -0,0 +1,31 @@
package kr.co.uplus.ez.api.sysMgt.dto;
import java.io.Serializable;
import kr.co.uplus.ez.common.data.ApiResponseCode;
import kr.co.uplus.ez.common.data.ResponseMessage;
import lombok.Data;
@SuppressWarnings("serial")
@Data
public class BatchExeLogResDto extends ResponseMessage implements Serializable{
// 데이터.
private Object data;
public BatchExeLogResDto() {
this.retCode = ApiResponseCode.SUCCESS.getResultCode();
this.retMsg = ApiResponseCode.SUCCESS.getResultMsg();
}
public BatchExeLogResDto(ApiResponseCode returnStr) {
this.retCode = returnStr.getResultCode();
this.retMsg = returnStr.getResultMsg();
}
public BatchExeLogResDto(ApiResponseCode returnStr, Object data) {
this.retCode = returnStr.getResultCode();
this.retMsg = returnStr.getResultMsg();
this.data = data;
}
}

View File

@@ -6,7 +6,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 배치 모니터링 DTO
* 배치 리스트 조회 DTO
* @author Lee Minha
*/
@Data
@@ -24,6 +24,7 @@ public class BatchList {
//배치 아이디
private String batchId;
//배치 명
private String batchNm;
//상태코드
@@ -53,14 +54,5 @@ public class BatchList {
//배치 주기
private String batchCycle;
//검색 시작 일자
private String searchSt;
//검색 종료 일자
private String searchFns;
private Object batchList;
private String batchTime;
}

View File

@@ -143,4 +143,10 @@ public class Const {
/** 한도 차감 상세 - 차감 유형 코드 (01:차감, 02:소멸, 03:복원, 04:충전) */
public static final String LMTDCT_DTL_DDCT_TYPE_CD_04 = "04";
/** 배치 결과 */
public static final String BATCH_MSG_SUCCESS = "SUCCESS";
public static final String BATCH_RESULT_SUCCESS = "S";
public static final String BATCH_RESULT_FAIL = "F";
}

View File

@@ -48,10 +48,12 @@ mail:
msghubez:
homepage-url: https://mhez-dev.uplus.co.kr
api-url: https://api-int.mhez-dev.uplus.co.kr
batch-url: https://batch-int.mhez-dev.uplus.co.kr
applicationId: EZ_ADMIN
uri:
sendTemplateMail: /api/v1/fo/sendTemplateMail
notice: /api/v1/fo/notice
batchExecuteJob: /executeJob
homepageLogin: /auth/bo
authKey: "bohubez!@#$%"

View File

@@ -47,11 +47,13 @@ mail:
msghubez:
homepage-url: https://mhez.uplus.co.kr
batch-url: https://batch-int.mhez.uplus.co.kr
api-url: https://api-int.mhez.uplus.co.kr
applicationId: EZ_ADMIN
uri:
sendTemplateMail: /api/v1/fo/sendTemplateMail
notice: /api/v1/fo/notice
batchExecuteJob: /executeJob
homepageLogin: /auth/bo
authKey: "bohubez!@#$%"

View File

@@ -48,10 +48,12 @@ mail:
msghubez:
homepage-url: https://mhez-qa.uplus.co.kr
api-url: https://api-int.mhez-qa.uplus.co.kr
batch-url: https://batch-int.mhez-qa.uplus.co.kr
applicationId: EZ_ADMIN
uri:
sendTemplateMail: /api/v1/fo/sendTemplateMail
notice: /api/v1/fo/notice
batchExecuteJob: /executeJob
homepageLogin: /auth/bo
authKey: "bohubez!@#$%"

View File

@@ -458,31 +458,56 @@
</select>
<select id="batchDetailSelect" resultType="kr.co.uplus.ez.api.sysMgt.dto.BatchList">
<select id="batchDetailSelect" parameterType="kr.co.uplus.ez.api.sysMgt.dto.BatchDetailReqDto" resultType="kr.co.uplus.ez.api.sysMgt.dto.BatchDetail">
/* sysMgt-mapper.xml(batchDetailSelect) 배치 상세 조회*/
SELECT
ebl.BATCH_ID,
ebl.ST_DT,
ebl.FNS_DT,
ebl.STTUS_CD,
ebl.ERR_MSG
ebl.BATCH_ID AS batchId,
ebl.ST_DT AS stDt,
ebl.FNS_DT AS fnsDt,
CASE
WHEN ebl.STTUS_CD = '01' THEN '시작'
WHEN ebl.STTUS_CD = '02' THEN '성공'
WHEN ebl.STTUS_CD = '03' THEN '실패'
ELSE ebl.STTUS_CD
END STTUS_CD,
ebl.ERR_MSG AS errMsg
FROM
hubez_admin.EZ_BTEXE_LOG ebl
WHERE
ebl.BATCH_ID =#{batchId}
<if test= "searchSt != null and searchSt !=''">
<![CDATA[
AND ST_DT > DATE_FORMAT(#{searchSt},'%Y-%m-%d %h:%m:%s')
]]>
</if>
<if test= "searchFns != null and searchFns !=''">
AND FNS_DT <![CDATA[ < ]]> DATE_FORMAT(#{searchFns},'%Y-%m-%d %h:%m:%s')
<if test= "startDt != null and endDt !=null">
AND DATE_FORMAT(ebl.ST_DT,'%Y-%m-%d') BETWEEN DATE_FORMAT(#{startDt},'%Y-%m-%d') AND DATE_FORMAT(#{endDt},'%Y-%m-%d')
</if>
<if test ="sttusCd != null and sttusCd !=''">
AND ebl.STTUS_CD = #{sttusCd}
</if>
ORDER BY
ebl.REG_DT desc
LIMIT #{page}, #{pagePerRows}
</select>
<select id="batchDetailCnt" parameterType="kr.co.uplus.ez.api.sysMgt.dto.BatchDetailReqDto" resultType="int">
/* sysMgt-mapper.xml(batchDetailCnt) 배치 상세 조회 카운트*/
SELECT
COUNT(1)
FROM
hubez_admin.EZ_BTEXE_LOG ebl
WHERE
ebl.BATCH_ID =#{batchId}
<if test= "startDt != null and startDt !=''">
<![CDATA[
AND ST_DT > DATE_FORMAT(#{startDt},'%Y-%m-%d %h:%m:%s')
]]>
</if>
<if test= "endDt != null and endDt !=''">
<![CDATA[
AND FNS_DT < DATE_FORMAT(#{endDt},'%Y-%m-%d %h:%m:%s')
]]>
</if>
<if test ="sttusCd != null and sttusCd !=''">
AND ebl.STTUS_CD = #{sttusCd}
</if>
</select>