fo bo 머지작업
This commit is contained in:
@@ -1,10 +1,17 @@
|
||||
package com.wb.domainserver.domain.mngr.api.controller;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.wb.domainserver.domain.gcone.api.service.BOApiService;
|
||||
import com.wb.domainserver.domain.gcone.common.service.BOCommonService;
|
||||
import com.wb.domainserver.domain.mngr.api.service.ApiService;
|
||||
import com.wb.domainserver.response.ApiResponse;
|
||||
import com.wb.domainserver.response.WnbtResponse;
|
||||
import com.wb.domainserver.response.WnbtResponseBody;
|
||||
import com.wb.domainserver.response.WnbtWebClientResponseHandler;
|
||||
import com.wb.domainserver.security.authentication.AnonymousUser;
|
||||
import com.wb.domainserver.security.authentication.MemberJwtContextHolder;
|
||||
import com.wb.domainserver.security.authorization.annotation.AuthPolicy;
|
||||
import com.wb.domainserver.security.authorization.annotation.Policy;
|
||||
import com.wb.domainserver.util.communicate.RESRC;
|
||||
@@ -16,12 +23,18 @@ import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
@@ -39,6 +52,18 @@ public class ApiController {
|
||||
@Autowired
|
||||
private ApiService service;
|
||||
|
||||
@Autowired
|
||||
private BOApiService boservice;
|
||||
|
||||
@Autowired
|
||||
private BOCommonService commonService;
|
||||
|
||||
@Value("${api.AES_KEY}")
|
||||
private String AES_KEY;
|
||||
|
||||
@Value("${api.DATA_ENCRYPT_AES_KEY}")
|
||||
private String DATA_ENCRYPT_AES_KEY;
|
||||
|
||||
/**
|
||||
* Order Api
|
||||
* 주문내역 api
|
||||
@@ -70,13 +95,14 @@ public class ApiController {
|
||||
requestBody.put("authSopmalCd", authSopmalCd);
|
||||
String listStr = "";
|
||||
String clearDataStr = "";
|
||||
ResponseEntity<WnbtResponse> boResponse = responseHandler.handleResponse(
|
||||
sendToResrc.ofPost(RESRC.GCONEBO, "/gcone/api/select/selectOrderList", requestBody),
|
||||
ReplyFromResrc::getReply
|
||||
);
|
||||
|
||||
// CSV 추출
|
||||
Object resultObj = boResponse.getBody().getResBody().getResult();
|
||||
Object resultObj = selectOrdrList(requestBody, response, request);
|
||||
// ResponseEntity<WnbtResponse> boResponse = responseHandler.handleResponse(
|
||||
// sendToResrc.ofPost(RESRC.GCONEBO, "/gcone/api/select/selectOrderList", requestBody),
|
||||
// ReplyFromResrc::getReply
|
||||
// );
|
||||
|
||||
if (resultObj instanceof String) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode outerJson = mapper.readTree((String) resultObj);
|
||||
@@ -102,4 +128,134 @@ public class ApiController {
|
||||
service.insertMngrApiAccessLog(request,response,"Y","",responseData);
|
||||
return listStr;
|
||||
}
|
||||
|
||||
private WnbtResponseBody selectOrdrList(Map<String, Object> requestBody, HttpServletResponse response, HttpServletRequest request){
|
||||
|
||||
// 1. 작성자 정보 할당
|
||||
AnonymousUser user = MemberJwtContextHolder.getMemberInfo();
|
||||
if ("01".equals(user.getSysDvCd())) {
|
||||
requestBody.put("sopmalCd", user.getSopmalCd());
|
||||
}
|
||||
|
||||
String hashEqual = "";
|
||||
String csvString = "";
|
||||
String clearData = "";
|
||||
DataMap paramMap = new DataMap();
|
||||
paramMap.put("aesKey", AES_KEY);
|
||||
paramMap.put("timeStamp", requestBody.get("timeStamp"));
|
||||
paramMap.put("data", requestBody.get("data"));
|
||||
paramMap.put("hashData", requestBody.get("hash"));
|
||||
paramMap.put("dataAesKey", DATA_ENCRYPT_AES_KEY);
|
||||
|
||||
log.debug("파라미터 총 체크 : {}", paramMap);
|
||||
|
||||
DataMap content = new DataMap();
|
||||
List<DataMap> list = new ArrayList<>();
|
||||
|
||||
// 2. 타임스탬프 검증
|
||||
try {
|
||||
boservice.isValidTimestamp((String) requestBody.get("timeStamp"));
|
||||
} catch (RuntimeException e) {
|
||||
log.warn("⛔ 타임스탬프 검증 실패: {}", e.getMessage(), e);
|
||||
boservice.insertMngrApiAccessLog(request,response,"N",e.getMessage());
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "요청 시간이 유효하지 않습니다.", e);
|
||||
}
|
||||
|
||||
// 3. 파라미터 복호화
|
||||
String param = boservice.aesParamDecrypt(paramMap);
|
||||
log.debug("📦 디코딩된 API 파라미터: {}", param);
|
||||
|
||||
// 4. 해시값 검증
|
||||
try {
|
||||
hashEqual = boservice.isValidHash(paramMap);
|
||||
log.debug("✅ 해쉬코드 검증 완료: {}", hashEqual);
|
||||
} catch (RuntimeException e) {
|
||||
log.debug("client hash: {}", paramMap.get("hashData"));
|
||||
log.debug("server hash: {}", e.getMessage());
|
||||
log.warn("⛔ 해쉬 코드 검증 실패: {}", e.getMessage(), e);
|
||||
boservice.insertMngrApiAccessLog(request,response,"N",e.getMessage());
|
||||
|
||||
content.put("result", "FAIL");
|
||||
content.put("message", "해쉬값 불일치");
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "해쉬값 불일치", e);
|
||||
}
|
||||
|
||||
// 5. 복호화된 파라미터 파싱 및 리스트 조회
|
||||
int totalSize = 0;
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
map = objectMapper.readValue(param, new TypeReference<Map<String, Object>>() {});
|
||||
|
||||
} catch (Exception e) {
|
||||
boservice.insertMngrApiAccessLog(request,response,"N",e.getMessage());
|
||||
log.warn("⛔ 파라미터 파싱 또는 리스트 조회 중 오류 발생", e);
|
||||
map = new HashMap<>();
|
||||
}
|
||||
log.debug("복호화 파라미터 : " + map);
|
||||
map.put("secretkey",commonService.selectSecretkey());
|
||||
// total 사이즈
|
||||
totalSize = boservice.selectTableTotalSize(map);
|
||||
|
||||
int pageSize = 10000;
|
||||
int pageIndex = 1;
|
||||
try {
|
||||
pageIndex = Integer.parseInt((String) map.get("pageIndex"));
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("pageIndex 파싱 실패, 기본값 사용: {}", pageIndex);
|
||||
pageIndex = 1;
|
||||
}
|
||||
|
||||
int offset = (pageIndex - 1) * pageSize;
|
||||
int lastPageIndex = (int) Math.ceil((double) totalSize / pageSize);
|
||||
lastPageIndex = Math.max(1, lastPageIndex);
|
||||
|
||||
if (offset >= totalSize) {
|
||||
pageIndex = lastPageIndex;
|
||||
offset = (pageIndex - 1) * pageSize;
|
||||
}
|
||||
|
||||
if (totalSize <= pageSize) {
|
||||
offset = 0;
|
||||
map.put("limit", pageSize);
|
||||
}
|
||||
map.put("limit", pageSize);
|
||||
map.put("offset", offset);
|
||||
map.put("totalSize", totalSize);
|
||||
long queryStart = System.currentTimeMillis();
|
||||
list = boservice.selectTableList(map);
|
||||
long queryEnd = System.currentTimeMillis();
|
||||
System.out.println("쿼리 실행 시간(ms): " + (queryEnd - queryStart)/ 1000.0 + "초");
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("list", list);
|
||||
result.put("pageIndex", pageIndex);
|
||||
result.put("lastPageIndex", lastPageIndex);
|
||||
result.put("totalSize", totalSize);
|
||||
long start = System.currentTimeMillis();
|
||||
clearData = list.toString();
|
||||
// 6. 응답 구성
|
||||
csvString = boservice.convertCsv(result);
|
||||
long afterConvert = System.currentTimeMillis();
|
||||
log.debug("CSV 변환 시간: " + (afterConvert - start)/ 1000.0 + "초");
|
||||
paramMap.put("csvString", csvString);
|
||||
|
||||
// csv text -> AES 암호화 전송
|
||||
csvString = boservice.encryptCsv(paramMap);
|
||||
long afterEncrypt = System.currentTimeMillis();
|
||||
log.debug("CSV 암호화 시간: " + (afterEncrypt - afterConvert)/ 1000.0 + "초");
|
||||
|
||||
|
||||
/*content.put("totalSize", totalSize);
|
||||
content.put("pageIndex", pageIndex);
|
||||
content.put("lastPageIndex", lastPageIndex);*/
|
||||
log.debug("총 후처리 시간: " + (afterEncrypt - start)/ 1000.0 + "초");
|
||||
|
||||
content.put("list", csvString);
|
||||
content.put("clearData", clearData);
|
||||
|
||||
return new WnbtResponseBody(content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user