main
MonHun 2023-10-10 11:42:11 +09:00
parent c11b6c8635
commit 8dd797edcf
24 changed files with 5003 additions and 4392 deletions

View File

@ -7,7 +7,9 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.ApplicationPidFileWriter;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableScheduling
@SpringBootApplication
public class DevApplication {
// implements CommandLineRunner

View File

@ -31,10 +31,10 @@ public class ServiceConfig {
// @Value("${tcpip.server.checksum}")
// private boolean serverReceiveChecksum;
private Charset clientReceiveCharset;
private Charset serverReceiveCharset;
private Charset clientSendCharset;
private Charset serverSendCharset;
// private Charset clientReceiveCharset;
// private Charset serverReceiveCharset;
// private Charset clientSendCharset;
// private Charset serverSendCharset;
@PostConstruct
private void initialize() {

View File

@ -27,7 +27,7 @@ import java.util.HashMap;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
@Component("controller")
//@Component("controller")
public class MainController implements ApplicationListener<ContextClosedEvent> {
@Value("${root}")

View File

@ -0,0 +1,53 @@
package kr.gmtc.gw.dev.restdev.config;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import kr.gmtc.gw.dev.asderecv.asde.rest.vo.ServiceAsdeData;
//@Configuration("restConfig")
public class RestConfig {
@Value("${root}")
private String root;
@Value("${request.url.recvTest}")
private String testReqTestUrl = "http://localhost:18080/test";
@PostConstruct
private void initialize() {
}
@Bean(name = "serviceRunnig")
public boolean serviceRunnig(){
return false;
}
@Bean(name = "packetQ")
public Queue<String> packetQ(){
return new LinkedBlockingQueue<String>();
}
@Bean(name = "sendQueue")
public HashMap<Integer, Queue<ServiceAsdeData>> sendQueue(){
return new LinkedHashMap<Integer, Queue<ServiceAsdeData>>();
}
}

View File

@ -0,0 +1,160 @@
package kr.gmtc.gw.dev.restdev.controller;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.ObjectMapper;
import kr.gmtc.gw.dev.restdev.service.StandMasterService;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO.Data;
import kr.gmtc.gw.dev.restdev.vo.AiMetaVideoStatusVO;
import kr.gmtc.gw.dev.restdev.vo.AiMetaVideoStatusVO.AiMetaVideoStatusVO_Data;
import kr.gmtc.gw.dev.restdev.vo.AiMetaVideoStatusVO.AiMetaVideoStatusVO_Sts;
import kr.gmtc.gw.dev.restdev.vo.StandMasterVO;
@Component("restReciveController")
public class RestReciveController {
private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;
private Queue<AImetaTestVO> recvQ;
private AiMetaVideoStatusVO mapStatus;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
@Autowired
private StandMasterService standService;
public RestReciveController() {
this.restTemplate = new RestTemplate();
this.objectMapper = new ObjectMapper();
this.recvQ = new LinkedBlockingQueue<AImetaTestVO>();
this.mapStatus = new AiMetaVideoStatusVO();
}
@Scheduled(fixedRate = 1000) // 1초마다 실행
public void requestJsonData() {
// JSON 데이터를 요청할 URL 설정
String apiUrl = "http://localhost";
String sPort = "18082";
String sReqMsg = "getVideoTest";
String sReqUrl = apiUrl + ":" +sPort + "/" + sReqMsg;
// 요청을 보내고 JSON 데이터를 받아옴
String jsonResponse = restTemplate.getForObject(sReqUrl, String.class);
// 받아온 JSON 데이터를 Message 객체로 변환
try {
AImetaTestVO message = objectMapper.readValue(jsonResponse, AImetaTestVO.class);
recvQ.offer(message);
// 변환된 Message 객체를 원하는 방식으로 처리
System.out.println("Received Message: " + message.toString());
} catch (Exception e) {
// JSON 파싱 오류 처리
e.printStackTrace();
}
splitData();
}
private void splitData(){
for(AImetaTestVO oneData : recvQ ){
List<Data> recvDatas = oneData.getData();
int iDataCnt = recvDatas.size();
for(int idx=0; idx<iDataCnt; idx++ ){
List<String> listCctvs = recvDatas.get(idx).getCc_id();
int iCctvCnt = listCctvs.size();
for(int idxC=0; idxC<iCctvCnt; idxC++){
// cctv_id <-> 주기장 번호 매핑
// MetaAIVideoStatus3 mapStatus3 = new MetaAIVideoStatus3();
String sCctvID = listCctvs.get(idxC);
String sStandNO = mappingStand(sCctvID);
String sSts = recvDatas.get(idx).getStts_cls();
AiMetaVideoStatusVO_Sts stsMap = mapStatus.getStsMap(sStandNO);
AiMetaVideoStatusVO_Data dataMap = mapStatus.getStsMap(sStandNO).getDataMap(sSts);
Map<String, AiMetaVideoStatusVO_Sts> standStsMap = new HashMap<String, AiMetaVideoStatusVO_Sts>();
Date now = new Date();
dataMap.setRecvTime( String.valueOf(sdf.format(now)));
dataMap.setStandNo(sStandNO);
dataMap.setSts(sSts);
standStsMap.put(sStandNO, stsMap);
mapStatus.setMapStandNoGroup(standStsMap);
}
}
}
}
private String mappingStand(String sCctvID){
String sRetStandNo = "";
List<StandMasterVO> standList = standService.getStandList();
for(StandMasterVO standMaster : standList){
if(standMaster.getCctvID().equals(sCctvID)){
sRetStandNo = standMaster.getStandNO();
return sRetStandNo;
}
}
return sRetStandNo;
}
// private boolean checkExistMap(String sKey){
// boolean isEx = false;
// if(mapStatus.get(sKey) != null){
// isEx = true;
// }
// return isEx;
// }
}

View File

@ -0,0 +1,83 @@
package kr.gmtc.gw.dev.restdev.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO.Data;
import kr.gmtc.gw.dev.restdev.vo.AImetaTestVO.Header;
@RestController
public class RestReqeustController {
@RequestMapping(value={"getTest/{param1}/{param2}"}, method=RequestMethod.GET)
public String getTest(@PathVariable String param1, @PathVariable String param2){
String sParam1, sParam2;
sParam1 = param1;
sParam2 = param2;
return "return :" + sParam1 + "/" + sParam2;
}
@RequestMapping(value={"getVideoTest"}, method=RequestMethod.GET)
public AImetaTestVO getMessage() {
// JSON 형식의 메시지를 생성
Header header = new Header("200", "OK");
List<Data> dataList = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < 2; i++) { // 두 개의 데이터 생성
String on_arcrft = random.nextBoolean() ? "true" : "false";
String stts_cls = getRandomStatusClass(random);
String arcrft_tp = "A380-800";
String zn_id = String.valueOf(106 + i);
List<String> bb_tlp = Arrays.asList("241", "489");
List<String> crd_frm = Arrays.asList("286", "500");
List<String> cc_id = Arrays.asList(String.valueOf(random.nextInt(4) + 102), String.valueOf(random.nextInt(4) + 102)); // 102부터 105까지의 랜덤값
List<String> crd_glb = Arrays.asList("37.344556", "127.422913");
List<String> bb_brp = Arrays.asList("331", "512");
String dtct_tm = "";
String arln = "KOR-001";
String trck_id = "";
Data data = new Data();
data.setOn_arcrft(on_arcrft);
data.setStts_cls(stts_cls);
data.setArcrft_tp(arcrft_tp);
data.setZn_id(zn_id);
data.setBb_brp(bb_brp);
data.setBb_tlp(bb_tlp);
data.setCrd_frm(crd_frm);
data.setCc_id(cc_id);
data.setCrd_glb(crd_glb);
data.setDtct_tm(dtct_tm);
data.setArln(arln);
data.setTrck_id(trck_id);
dataList.add(data);
}
return new AImetaTestVO(header, dataList);
}
private String getRandomStatusClass(Random random) {
String[] statusClasses = {"brdg_cnnctd", "crg_dr_opnd", "twng_cr_cnnctd"};
int randomIndex = random.nextInt(statusClasses.length);
return statusClasses[randomIndex];
}
}

View File

@ -0,0 +1,40 @@
package kr.gmtc.gw.dev.restdev.service;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import kr.gmtc.gw.dev.restdev.vo.StandMasterVO;
@Service("standMasterService")
public class StandMasterService {
private List<StandMasterVO> standList;
public StandMasterService(){
standList = new ArrayList<StandMasterVO>();
standList.add(new StandMasterVO("G101", "101"));
standList.add(new StandMasterVO("G102", "102"));
standList.add(new StandMasterVO("G103", "103"));
standList.add(new StandMasterVO("G104", "104"));
standList.add(new StandMasterVO("G105", "105"));
standList.add(new StandMasterVO("G106", "106"));
standList.add(new StandMasterVO("G107", "107"));
standList.add(new StandMasterVO("G108", "108"));
standList.add(new StandMasterVO("G109", "109"));
}
public List<StandMasterVO> getStandList(){
return this.standList;
}
}

View File

@ -0,0 +1,178 @@
package kr.gmtc.gw.dev.restdev.vo;
import java.util.List;
public class AImetaTestVO {
private Header header;
private List<Data> data;
public AImetaTestVO() {
}
public AImetaTestVO(Header header, List<Data> data){
this.header = header;
this.data = data;
}
public Header getHeader() {
return header;
}
public void setHeader(Header header) {
this.header = header;
}
public List<Data> getData() {
return data;
}
public void setData(List<Data> data) {
this.data = data;
}
public static class Header {
private String result_code;
private String result_msg;
public Header() {
}
public Header(String result_code, String result_msg) {
this.result_code = result_code;
this.result_msg = result_msg;
}
public String getResult_code() {
return result_code;
}
public void setResult_code(String result_code) {
this.result_code = result_code;
}
public String getResult_msg() {
return result_msg;
}
public void setResult_msg(String result_msg) {
this.result_msg = result_msg;
}
}
public static class Data {
private String on_arcrft;
private String stts_cls;
private String arcrft_tp;
private String zn_id;
private List<String> bb_tlp;
private List<String> crd_frm;
private List<String> cc_id;
private List<String> crd_glb;
private List<String> bb_brp;
private String dtct_tm;
private String arln;
private String trck_id;
public String getOn_arcrft() {
return on_arcrft;
}
public void setOn_arcrft(String on_arcrft) {
this.on_arcrft = on_arcrft;
}
public String getStts_cls() {
return stts_cls;
}
public void setStts_cls(String stts_cls) {
this.stts_cls = stts_cls;
}
public String getArcrft_tp() {
return arcrft_tp;
}
public void setArcrft_tp(String arcrft_tp) {
this.arcrft_tp = arcrft_tp;
}
public String getZn_id() {
return zn_id;
}
public void setZn_id(String zn_id) {
this.zn_id = zn_id;
}
public List<String> getBb_tlp() {
return bb_tlp;
}
public void setBb_tlp(List<String> bb_tlp) {
this.bb_tlp = bb_tlp;
}
public List<String> getCrd_frm() {
return crd_frm;
}
public void setCrd_frm(List<String> crd_frm) {
this.crd_frm = crd_frm;
}
public List<String> getCc_id() {
return cc_id;
}
public void setCc_id(List<String> cc_id) {
this.cc_id = cc_id;
}
public List<String> getCrd_glb() {
return crd_glb;
}
public void setCrd_glb(List<String> crd_glb) {
this.crd_glb = crd_glb;
}
public List<String> getBb_brp() {
return bb_brp;
}
public void setBb_brp(List<String> bb_brp) {
this.bb_brp = bb_brp;
}
public String getDtct_tm() {
return dtct_tm;
}
public void setDtct_tm(String dtct_tm) {
this.dtct_tm = dtct_tm;
}
public String getArln() {
return arln;
}
public void setArln(String arln) {
this.arln = arln;
}
public String getTrck_id() {
return trck_id;
}
public void setTrck_id(String trck_id) {
this.trck_id = trck_id;
}
}
}

View File

@ -0,0 +1,56 @@
package kr.gmtc.gw.dev.restdev.vo;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class AiMetaVideoStatusVO {
private Map<String, AiMetaVideoStatusVO_Sts> mapStandNoGroup;
public AiMetaVideoStatusVO(){
mapStandNoGroup = new HashMap<String, AiMetaVideoStatusVO_Sts>();
}
public AiMetaVideoStatusVO_Sts getStsMap(String sStandNo){
return mapStandNoGroup.get(sStandNo);
}
@Getter
@Setter
public static class AiMetaVideoStatusVO_Sts {
private Map<String, AiMetaVideoStatusVO_Data> mapStatusGroup;
public AiMetaVideoStatusVO_Sts(String sSts, AiMetaVideoStatusVO_Data map){
mapStatusGroup = new HashMap<String, AiMetaVideoStatusVO_Data>();
}
public AiMetaVideoStatusVO_Data getDataMap(String sSts){
return mapStatusGroup.get(sSts);
}
}
@Getter
@Setter
public static class AiMetaVideoStatusVO_Data {
private String standNo;
private String sts;
private String cctvID;
private String recvTime;
}
}

View File

@ -0,0 +1,35 @@
package kr.gmtc.gw.dev.restdev.vo;
public class StandMasterVO {
private String standNO;
private String cctvID;
public StandMasterVO(String standNO, String cctvID){
this.standNO = standNO;
this.cctvID = cctvID;
}
public String getStandNO() {
return standNO;
}
public void setStandNO(String standNo) {
this.standNO = standNo;
}
public String getCctvID() {
return cctvID;
}
public void setCctvID(String cctvID) {
this.cctvID = cctvID;
}
}

View File

@ -41,3 +41,7 @@ spring:
root: D:\Workspace\Odroid_repository\EyeGW_CompDev
request:
url:
recvTest: http://localhost:18082/getVideoTest