|
@@ -1,20 +1,24 @@
|
|
|
package com.sig.api.controller.sig;
|
|
|
|
|
|
import com.sig.api.aspectj.SigOpenApiElapsed;
|
|
|
+import com.sig.api.dto.sig.ServiceHistDto;
|
|
|
import com.sig.api.dto.sig.SigOpenApiHeaderDto;
|
|
|
import com.sig.api.entity.sig.DataCount;
|
|
|
import com.sig.api.entity.sig.TbInt;
|
|
|
import com.sig.api.entity.sig.TbIntPhase;
|
|
|
import com.sig.api.service.sig.CrossRoadInfoService;
|
|
|
import com.sig.utils.ApiUtils;
|
|
|
-import com.sun.istack.Nullable;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang.time.StopWatch;
|
|
|
import org.jdom2.Element;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
+import org.springframework.core.io.InputStreamResource;
|
|
|
+import org.springframework.core.io.Resource;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.lang.Nullable;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
@@ -22,7 +26,11 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -34,6 +42,7 @@ import java.util.Map;
|
|
|
@Api(tags = "02.교차로기반정보서비스")
|
|
|
public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
|
|
|
+ private final String serviceName = "CrossRoadInfoService";
|
|
|
private final CrossRoadInfoService service;
|
|
|
|
|
|
@SigOpenApiElapsed
|
|
@@ -48,13 +57,12 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
@RequestParam(name="numOfRows", required = false) @Nullable Integer numOfRows,
|
|
|
@ApiParam(name = "pageNo", value = "페이지 번호", example = "1")
|
|
|
@RequestParam(name="pageNo", required = false) @Nullable Integer pageNo,
|
|
|
- @ApiParam(name = "srchCTId", value = "지역코드", example = "L01")
|
|
|
+ @ApiParam(name = "srchCTId", value = "지역코드", example = "L02")
|
|
|
@RequestParam(name="srchCTId", required = false) @Nullable String srchCTId,
|
|
|
- @ApiParam(name = "srchCRNm", value = "교차로명", example = "시청입구")
|
|
|
+ @ApiParam(name = "srchCRNm", value = "교차로명", example = "옥골4거리")
|
|
|
@RequestParam(name="srchCRNm", required = false) @Nullable String srchCRNm,
|
|
|
HttpServletRequest req, HttpServletResponse res
|
|
|
) throws IOException {
|
|
|
- final String serviceName = "CrossRoadInfoService";
|
|
|
final String remoteIP = ApiUtils.getRemoteIP(req);
|
|
|
|
|
|
String type_ = (type == null) ? "json" : type;
|
|
@@ -66,6 +74,20 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
numOfRows_ = 100;
|
|
|
}
|
|
|
|
|
|
+ ServiceHistDto hist = ServiceHistDto.builder()
|
|
|
+ .OPENAPI_ID(6)
|
|
|
+ .OPEN_DATA_KEY(serviceKey)
|
|
|
+ .HOST_IP(remoteIP)
|
|
|
+ .DATA_TYPE(type)
|
|
|
+ .EXECUTE_TIME(0)
|
|
|
+ .STATUS(0)
|
|
|
+ .REGION_CD("".equals(srchCTId_) ? "ALL" : srchCTId_)
|
|
|
+ .REGION_CD("".equals(srchCTId_) ? "ALL" : srchCTId_)
|
|
|
+ .startTime(System.currentTimeMillis())
|
|
|
+ .build();
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start();
|
|
|
+
|
|
|
Integer [] calcPageReturn = this.service.calcPageStartEndNo(pageNo_, numOfRows_);
|
|
|
log.info("getCrossRoadInfoList: type_:{}, numOfRows_:{}, pageNo_:{}, srchCTId_:{}, srchCRNm_:{}, startRow:{}, endRow:{}",
|
|
|
type_, numOfRows_, pageNo_, srchCTId_, srchCRNm_, calcPageReturn[0], calcPageReturn[1]);
|
|
@@ -81,6 +103,8 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
SigOpenApiHeaderDto headerVo = this.service.checkServiceKey("/CrossRoadInfoService/getCrossRoadInfoList", remoteIP, serviceKey);
|
|
|
if (!"0".equals(headerVo.getResultCode())) {
|
|
|
sendErrorResponse(type_, "CrossRoadInfoService", headerVo, res);
|
|
|
+ hist.setSTATUS("30".equals(headerVo.getResultCode()) ? 1 : 2);
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -135,6 +159,7 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
}
|
|
|
sendResponseJson(jsonList, res);
|
|
|
}
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
}
|
|
|
|
|
|
@SigOpenApiElapsed
|
|
@@ -149,13 +174,12 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
@RequestParam(name="numOfRows", required = false) @Nullable Integer numOfRows,
|
|
|
@ApiParam(name = "pageNo", value = "페이지 번호", example = "1")
|
|
|
@RequestParam(name="pageNo", required = false) @Nullable Integer pageNo,
|
|
|
- @ApiParam(name = "srchCTId", value = "지역코드", example = "L01")
|
|
|
+ @ApiParam(name = "srchCTId", value = "지역코드", example = "L02")
|
|
|
@RequestParam(name="srchCTId", required = false) @Nullable String srchCTId,
|
|
|
- @ApiParam(name = "srchCRNm", value = "교차로명", example = "시청입구")
|
|
|
+ @ApiParam(name = "srchCRNm", value = "교차로명", example = "옥골4거리")
|
|
|
@RequestParam(name="srchCRNm", required = false) @Nullable String srchCRNm,
|
|
|
HttpServletRequest req, HttpServletResponse res
|
|
|
) throws IOException {
|
|
|
- final String serviceName = "CrossRoadInfoService";
|
|
|
final String remoteIP = ApiUtils.getRemoteIP(req);
|
|
|
|
|
|
String type_ = (type == null) ? "json" : type;
|
|
@@ -167,6 +191,19 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
numOfRows_ = 100;
|
|
|
}
|
|
|
|
|
|
+ ServiceHistDto hist = ServiceHistDto.builder()
|
|
|
+ .OPENAPI_ID(7)
|
|
|
+ .OPEN_DATA_KEY(serviceKey)
|
|
|
+ .HOST_IP(remoteIP)
|
|
|
+ .DATA_TYPE(type)
|
|
|
+ .EXECUTE_TIME(0)
|
|
|
+ .STATUS(0)
|
|
|
+ .REGION_CD("".equals(srchCTId_) ? "ALL" : srchCTId_)
|
|
|
+ .startTime(System.currentTimeMillis())
|
|
|
+ .build();
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start();
|
|
|
+
|
|
|
Integer [] calcPageReturn = this.service.calcPageStartEndNo(pageNo_, numOfRows_);
|
|
|
log.info("getCrossRoadInfoDetail: type_:{}, numOfRows_:{}, pageNo_:{}, srchCTId_:{}, srchCRNm_:{}, startRow:{}, endRow:{}",
|
|
|
type_, numOfRows_, pageNo_, srchCTId_, srchCRNm_, calcPageReturn[0], calcPageReturn[1]);
|
|
@@ -182,6 +219,8 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
SigOpenApiHeaderDto headerVo = this.service.checkServiceKey("/CrossRoadInfoService/getCrossRoadInfoDetail", remoteIP, serviceKey);
|
|
|
if (!"0".equals(headerVo.getResultCode())) {
|
|
|
sendErrorResponse(type_, "CrossRoadInfoService", headerVo, res);
|
|
|
+ hist.setSTATUS("30".equals(headerVo.getResultCode()) ? 1 : 2);
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -298,6 +337,120 @@ public class CrossRoadInfoController extends SigOpenApiCommonController {
|
|
|
}
|
|
|
sendResponseJson(jsonList, res);
|
|
|
}
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
+ }
|
|
|
+
|
|
|
+ @SigOpenApiElapsed
|
|
|
+ @ApiOperation(value = "3.교차로정보-다운로드")
|
|
|
+ @GetMapping(value = "/download/crossInfo", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
|
|
|
+ public ResponseEntity<Object> getCrossRoadInfoListDownload(
|
|
|
+ @ApiParam(name = "serviceKey", value = "인증키", example = "A515753C425C4B579BCC1F2E0ED50374", required = true)
|
|
|
+ @RequestParam final String serviceKey,
|
|
|
+ @ApiParam(name = "srchCTId", value = "지역코드", example = "L02")
|
|
|
+ @RequestParam(name="srchCTId", required = false) @Nullable String srchCTId,
|
|
|
+ HttpServletRequest req, HttpServletResponse res
|
|
|
+ ) throws IOException {
|
|
|
+ final String remoteIP = ApiUtils.getRemoteIP(req);
|
|
|
+ String srchCTId_ = (srchCTId == null) ? "" : srchCTId;
|
|
|
+ ServiceHistDto hist = ServiceHistDto.builder()
|
|
|
+ .OPENAPI_ID(8)
|
|
|
+ .OPEN_DATA_KEY(serviceKey)
|
|
|
+ .HOST_IP(remoteIP)
|
|
|
+ .DATA_TYPE("file")
|
|
|
+ .EXECUTE_TIME(0)
|
|
|
+ .STATUS(0)
|
|
|
+ .REGION_CD("".equals(srchCTId_) ? "ALL" : srchCTId_)
|
|
|
+ .startTime(System.currentTimeMillis())
|
|
|
+ .build();
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start();
|
|
|
+
|
|
|
+ SigOpenApiHeaderDto headerVo = this.service.checkServiceKey("/CrossRoadInfoService/download/crossInfo", remoteIP, serviceKey);
|
|
|
+ if (!"0".equals(headerVo.getResultCode())) {
|
|
|
+ sendErrorResponse(null, serviceName, headerVo, res);
|
|
|
+ hist.setSTATUS("30".equals(headerVo.getResultCode()) ? 1 : 2);
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
+ return new ResponseEntity<Object>(null, HttpStatus.CONFLICT);
|
|
|
+ }
|
|
|
+ // 여기서 파일 다운로드....
|
|
|
+ String dataFileName = "".equals(srchCTId_) ? "crossInfo.zip" : srchCTId_ + "_crossInfo.xlsx";
|
|
|
+ String separator = System.getProperty("file.separator");
|
|
|
+ String fileFullName = System.getProperty("user.dir")+separator+"download"+separator+dataFileName;
|
|
|
+
|
|
|
+ try {
|
|
|
+ Path filePath = Paths.get(fileFullName);
|
|
|
+ File file = new File(fileFullName);
|
|
|
+ String fileName = file.getName();
|
|
|
+ Resource resource = new InputStreamResource(Files.newInputStream(filePath));
|
|
|
+ String header = req.getHeader("User-Agent");
|
|
|
+ String encodeFileName = service.fileNameEncoder(fileName, header);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ // 다운로드 되거나 로컬에 저장되는 용도로 쓰이는지를 알려주는 헤더
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment").filename(encodeFileName).build());
|
|
|
+
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
+ return new ResponseEntity<Object>(resource, headers, HttpStatus.OK);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ sendErrorResponse(null, serviceName, headerVo, res);
|
|
|
+ return new ResponseEntity<Object>(null, HttpStatus.CONFLICT);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @SigOpenApiElapsed
|
|
|
+ @ApiOperation(value = "4.교차로현시구성정보-다운로드")
|
|
|
+ @GetMapping(value = "/download/crossDetailInfo", produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE})
|
|
|
+ public ResponseEntity<Object> getPlanCRWDInfoDownload(
|
|
|
+ @ApiParam(name = "serviceKey", value = "인증키", example = "A515753C425C4B579BCC1F2E0ED50374", required = true)
|
|
|
+ @RequestParam final String serviceKey,
|
|
|
+ @ApiParam(name = "srchCTId", value = "지역코드", example = "L02")
|
|
|
+ @RequestParam(name="srchCTId", required = false) @Nullable String srchCTId,
|
|
|
+ HttpServletRequest req, HttpServletResponse res
|
|
|
+ ) throws IOException {
|
|
|
+ final String remoteIP = ApiUtils.getRemoteIP(req);
|
|
|
+ String srchCTId_ = (srchCTId == null) ? "" : srchCTId;
|
|
|
+ ServiceHistDto hist = ServiceHistDto.builder()
|
|
|
+ .OPENAPI_ID(9)
|
|
|
+ .OPEN_DATA_KEY(serviceKey)
|
|
|
+ .HOST_IP(remoteIP)
|
|
|
+ .DATA_TYPE("file")
|
|
|
+ .EXECUTE_TIME(0)
|
|
|
+ .STATUS(0)
|
|
|
+ .REGION_CD("".equals(srchCTId_) ? "ALL" : srchCTId_)
|
|
|
+ .startTime(System.currentTimeMillis())
|
|
|
+ .build();
|
|
|
+ StopWatch stopWatch = new StopWatch();
|
|
|
+ stopWatch.start();
|
|
|
+
|
|
|
+ SigOpenApiHeaderDto headerVo = this.service.checkServiceKey("/CrossRoadInfoService/download/crossDetailInfo", remoteIP, serviceKey);
|
|
|
+ if (!"0".equals(headerVo.getResultCode())) {
|
|
|
+ sendErrorResponse(null, serviceName, headerVo, res);
|
|
|
+ hist.setSTATUS("30".equals(headerVo.getResultCode()) ? 1 : 2);
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
+ return new ResponseEntity<Object>(null, HttpStatus.CONFLICT);
|
|
|
+ }
|
|
|
+ // 여기서 파일 다운로드....
|
|
|
+ String dataFileName = "".equals(srchCTId_) ? "crossDetailInfo.zip" : srchCTId_ + "_crossDetailInfo.xlsx";
|
|
|
+ String separator = System.getProperty("file.separator");
|
|
|
+ String fileFullName = System.getProperty("user.dir")+separator+"download"+separator+dataFileName;
|
|
|
+ try {
|
|
|
+ Path filePath = Paths.get(fileFullName);
|
|
|
+ File file = new File(fileFullName);
|
|
|
+ String fileName = file.getName();
|
|
|
+ Resource resource = new InputStreamResource(Files.newInputStream(filePath));
|
|
|
+ String header = req.getHeader("User-Agent");
|
|
|
+ String encodeFileName = this.service.fileNameEncoder(fileName, header);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ // 다운로드 되거나 로컬에 저장되는 용도로 쓰이는지를 알려주는 헤더
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment").filename(encodeFileName).build());
|
|
|
+
|
|
|
+ this.service.saveServiceHistory(hist);
|
|
|
+ return new ResponseEntity<Object>(resource, headers, HttpStatus.OK);
|
|
|
+ }
|
|
|
+ catch (Exception e) {
|
|
|
+ sendErrorResponse(null, serviceName, headerVo, res);
|
|
|
+ return new ResponseEntity<Object>(null, HttpStatus.CONFLICT);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|