lkd9125(이경도)
11 months ago
5 changed files with 401 additions and 244 deletions
@ -0,0 +1,148 @@ |
|||||||
|
package com.palnet.biz.api.main.statistics.controller; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.springframework.http.HttpStatus; |
||||||
|
import org.springframework.http.MediaType; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.GetMapping; |
||||||
|
import org.springframework.web.bind.annotation.PathVariable; |
||||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.bind.annotation.RestController; |
||||||
|
|
||||||
|
import com.palnet.biz.api.comn.response.BasicResponse; |
||||||
|
import com.palnet.biz.api.comn.response.ErrorResponse; |
||||||
|
import com.palnet.biz.api.comn.response.SuccessResponse; |
||||||
|
import com.palnet.biz.api.main.dash.model.FlightStaticStcsModel; |
||||||
|
import com.palnet.biz.api.main.dash.model.FlightStcsModel; |
||||||
|
import com.palnet.biz.api.main.statistics.service.MainStatisticsService; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiImplicitParam; |
||||||
|
import io.swagger.annotations.ApiImplicitParams; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.log4j.Log4j2; |
||||||
|
|
||||||
|
@Log4j2 |
||||||
|
@RestController |
||||||
|
@RequiredArgsConstructor |
||||||
|
@RequestMapping(value = "/api/main/statistics", produces = {MediaType.APPLICATION_JSON_VALUE}) |
||||||
|
@Tag(name = "메인화면 컨트롤러", description = "메인화면 관련 API") |
||||||
|
public class MainStatisticsController { |
||||||
|
|
||||||
|
private final MainStatisticsService service; |
||||||
|
|
||||||
|
@GetMapping("/stcs/flight-static") |
||||||
|
@ApiOperation(value = "비행통계 상단 데이터[DB전체 통계데이터]") |
||||||
|
@Tag(name = "메인화면 컨트롤러", description = "메인화면 관련 API") |
||||||
|
public ResponseEntity<? extends BasicResponse> fltStcsStatic(){ |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> result = null; |
||||||
|
|
||||||
|
try { |
||||||
|
result = service.getFlightStaticStcs(); |
||||||
|
|
||||||
|
log.warn("result => {}", result); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("IGNORE : {}", e); |
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) |
||||||
|
.body(new ErrorResponse("Server Error", "-1")); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseEntity.ok().body(new SuccessResponse<List<FlightStaticStcsModel>>(result)); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/stcs/flight/{type}") |
||||||
|
@ApiOperation(value = "비행통계 cate = ['TIME', 'DISTANCE','FLT_COUNT'], type=['year','month','day','one-day']") |
||||||
|
@Tag(name = "메인화면 컨트롤러", description = "메인화면 관련 API") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "date",value = "날짜[2023]", dataTypeClass = String.class), |
||||||
|
@ApiImplicitParam(name = "cate",value = "비행시간,거리,횟수[TIME]", dataTypeClass = String.class), |
||||||
|
@ApiImplicitParam(name = "type",value = "날짜형식[month]", dataTypeClass = String.class) |
||||||
|
}) |
||||||
|
public ResponseEntity<? extends BasicResponse> fltStcs(@RequestParam String cate, String date, @PathVariable String type){ |
||||||
|
log.warn("cate => {}, date => {}, type => {}", cate, date, type); |
||||||
|
|
||||||
|
FlightStcsModel result = new FlightStcsModel(); |
||||||
|
|
||||||
|
try { |
||||||
|
String[] formatParam = null; |
||||||
|
|
||||||
|
if(date == null) date = ""; |
||||||
|
formatParam = service.paramCheck(date,type); |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> graphData = service.fltStatics(cate, date, formatParam); |
||||||
|
List<FlightStaticStcsModel> topData = service.fltTopStatics(cate, date, formatParam); |
||||||
|
|
||||||
|
result.setGraphData(graphData); |
||||||
|
result.setTopData(topData); |
||||||
|
|
||||||
|
log.warn("result => {}", result); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("IGNORE : {}", e); |
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) |
||||||
|
.body(new ErrorResponse("Server Error", "-1")); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseEntity.ok().body(new SuccessResponse<FlightStcsModel>(result)); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/stcs/warn-static") |
||||||
|
@ApiOperation(value = "비정상 상황 상단 데이터[DB전체 통계데이터]") |
||||||
|
@Tag(name = "메인화면 컨트롤러", description = "메인화면 관련 API") |
||||||
|
public ResponseEntity<? extends BasicResponse> warnStcsStatic(){ |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> result = null; |
||||||
|
|
||||||
|
try { |
||||||
|
result = service.getWarnStaticStcs(); |
||||||
|
|
||||||
|
log.warn("result => {}", result); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("IGNORE : {}", e); |
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) |
||||||
|
.body(new ErrorResponse("Server Error", "-1")); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseEntity.ok().body(new SuccessResponse<List<FlightStaticStcsModel>>(result)); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/stcs/warn/{type}") |
||||||
|
@ApiOperation(value = "비정상상황 cate = ['PLAN' ,'ALTITUDE', 'CRASH'], type=['year','month','day','one-day']") |
||||||
|
@Tag(name = "메인화면 컨트롤러", description = "메인화면 관련 API") |
||||||
|
@ApiImplicitParams({ |
||||||
|
@ApiImplicitParam(name = "date",value = "날짜[2023]", dataTypeClass = String.class), |
||||||
|
@ApiImplicitParam(name = "cate",value = "비행시간,거리,횟수[TIME]", dataTypeClass = String.class), |
||||||
|
@ApiImplicitParam(name = "type",value = "날짜형식[month]", dataTypeClass = String.class) |
||||||
|
}) |
||||||
|
public ResponseEntity<? extends BasicResponse> warnStcs(@RequestParam String cate, String date, @PathVariable String type){ |
||||||
|
log.warn("cate => {}, date => {}, type => {}", cate, date, type); |
||||||
|
|
||||||
|
FlightStcsModel result = new FlightStcsModel(); |
||||||
|
|
||||||
|
try { |
||||||
|
String[] formatParam = null; |
||||||
|
|
||||||
|
if(date == null) date = ""; |
||||||
|
formatParam = service.paramCheck(date,type); |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> graphData = service.warnStatics(cate, date, formatParam); |
||||||
|
List<FlightStaticStcsModel> topData = service.warnTopStatics(cate, date, formatParam); |
||||||
|
|
||||||
|
result.setGraphData(graphData); |
||||||
|
result.setTopData(topData); |
||||||
|
|
||||||
|
log.warn("result => {}", result); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("IGNORE : {}", e); |
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) |
||||||
|
.body(new ErrorResponse("Server Error", "-1")); |
||||||
|
} |
||||||
|
|
||||||
|
return ResponseEntity.ok().body(new SuccessResponse<FlightStcsModel>(result)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,209 @@ |
|||||||
|
package com.palnet.biz.api.main.statistics.service; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.Arrays; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import com.palnet.biz.api.main.dash.model.FlightStaticStcsModel; |
||||||
|
import com.palnet.biz.jpa.repository.ctr.CtrCntrlQueryRepository; |
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
@RequiredArgsConstructor |
||||||
|
public class MainStatisticsService { |
||||||
|
|
||||||
|
|
||||||
|
private final CtrCntrlQueryRepository query; |
||||||
|
|
||||||
|
/** |
||||||
|
* 파라미터 체크 |
||||||
|
* 1. 연단위 검색 -> Parameter Null일 경우 |
||||||
|
* 2. 월단위 검색 -> Parameter 2023등 연도만 있는경우 |
||||||
|
* 3. 일단위 검색 -> Parameter 2023-09 등 월까지 있는경우 |
||||||
|
* 4. 일일단위 검색 -> Parameter 2023-09-01 등 한 날짜에 대한 검색 |
||||||
|
* 이하 모든 데이터는 Exception 발생 |
||||||
|
* @param date |
||||||
|
* @throws NumberFormatException |
||||||
|
*/ |
||||||
|
public String[] paramCheck(String date, String type) throws NumberFormatException{ |
||||||
|
|
||||||
|
String[] result = new String[2]; |
||||||
|
|
||||||
|
date = date.trim(); |
||||||
|
|
||||||
|
String[] paramStrings = date.split("-"); |
||||||
|
|
||||||
|
switch (type) { |
||||||
|
case "month": // 2. 월단위 검색 -> Parameter 2023등 연도만 있는경우
|
||||||
|
Integer.parseInt(date.trim()); |
||||||
|
|
||||||
|
result[0] = "%Y"; |
||||||
|
result[1] = "%m"; |
||||||
|
break; |
||||||
|
case "day": // 3. 일단위 검색 -> Parameter 2023-09 등 월까지 있는경우
|
||||||
|
|
||||||
|
if(paramStrings.length == 2){ |
||||||
|
for(String param : paramStrings){ |
||||||
|
Integer.parseInt(param.trim()); |
||||||
|
} |
||||||
|
|
||||||
|
result[0] = "%Y-%m"; |
||||||
|
result[1] = "%d"; |
||||||
|
} else { |
||||||
|
throw new NumberFormatException(); |
||||||
|
} |
||||||
|
|
||||||
|
break; |
||||||
|
case "one-day": // 4. 일일단위 검색 -> Parameter 2023-09-01 등 한 날짜에 대한 검색
|
||||||
|
|
||||||
|
if(paramStrings.length == 3){ |
||||||
|
for(String param : paramStrings){ |
||||||
|
|
||||||
|
Integer.parseInt(param.trim()); |
||||||
|
} |
||||||
|
|
||||||
|
result[0] = "%Y-%m-%d"; |
||||||
|
result[1] = "%d"; |
||||||
|
} else { |
||||||
|
throw new NumberFormatException(); |
||||||
|
} |
||||||
|
break; |
||||||
|
case "year" : // 1. 연단위 검색 -> Parameter Null일 경우
|
||||||
|
if(paramStrings.length > 1) throw new NumberFormatException(); |
||||||
|
|
||||||
|
result[0] = ""; |
||||||
|
result[1] = "%y"; |
||||||
|
|
||||||
|
break; |
||||||
|
default: |
||||||
|
throw new NumberFormatException(); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비행관련 고정 통계, 항상 DB 전체값에서 통계진행할것임 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> getFlightStaticStcs(){ |
||||||
|
|
||||||
|
FlightStaticStcsModel time = query.getFlightTimeStcs(); |
||||||
|
FlightStaticStcsModel distance = query.getFlightDistanceStcs(); |
||||||
|
FlightStaticStcsModel fltCount = query.getFlightCountStcs(); |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> result = Arrays.asList(time, distance, fltCount); |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비행통계 |
||||||
|
* @param idntfNum |
||||||
|
* @param date |
||||||
|
* @param formatParam |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> fltStatics(String cate, String date, String[] formatParam){ |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> resultList = null; |
||||||
|
|
||||||
|
switch (cate) { |
||||||
|
case "TIME": |
||||||
|
resultList = query.fltTimeStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
case "DISTANCE": |
||||||
|
resultList = query.fltDistanceStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
case "FLT_COUNT": |
||||||
|
resultList = query.fltCountStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
return resultList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비행통계 카테고리 별 Top 5 데이터 가져오기 |
||||||
|
* @param cate |
||||||
|
* @param date |
||||||
|
* @param formatParam |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> fltTopStatics(String cate, String date, String[] formatParam){ |
||||||
|
List<FlightStaticStcsModel> resultList = null; |
||||||
|
|
||||||
|
switch (cate) { |
||||||
|
case "TIME": |
||||||
|
resultList = query.fltTopTimeStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
case "DISTANCE": |
||||||
|
resultList = query.fltTopDistanceStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
case "FLT_COUNT": |
||||||
|
resultList = query.fltTopCountStcs(date, formatParam); |
||||||
|
|
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
return resultList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비행관련 고정 통계, 항상 DB 전체값에서 통계진행할것임 |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> getWarnStaticStcs(){ |
||||||
|
|
||||||
|
// TODO:: 비행경로이탈, 고도이탈, 충돌위험 임시코드
|
||||||
|
String[] cate = {"PLAN" ,"ALTITUDE", "CRASH"}; |
||||||
|
// String[] cate = {WarnType.PLAN.getValue() ,WarnType.ALTITUDE.getValue(), WarnType.CRASH.getValue()};
|
||||||
|
|
||||||
|
List<FlightStaticStcsModel> result = new ArrayList<>(); |
||||||
|
|
||||||
|
for(int i = 0; i < cate.length; i ++){ |
||||||
|
FlightStaticStcsModel node = query.getWarnStaticStcs(cate[i]); |
||||||
|
result.add(node); |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비정상상황 그래프 데이터 |
||||||
|
* @param cate |
||||||
|
* @param date |
||||||
|
* @param formatParam |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> warnStatics(String cate, String date, String[] formatParam){ |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> resultList = query.warnStcs(cate, date, formatParam); |
||||||
|
|
||||||
|
return resultList; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 비정상상황 카테고리별 Top5 데이터 |
||||||
|
* @param cate |
||||||
|
* @param date |
||||||
|
* @param formatParam |
||||||
|
* @return |
||||||
|
*/ |
||||||
|
public List<FlightStaticStcsModel> warnTopStatics(String cate, String date, String[] formatParam){ |
||||||
|
|
||||||
|
List<FlightStaticStcsModel> resultList = query.warnTopStcs(cate, date, formatParam); |
||||||
|
|
||||||
|
return resultList; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue