|
@@ -2,7 +2,6 @@ package com.its.pis.websocket;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
-import com.its.app.utils.ItsUtils;
|
|
|
import com.its.pis.entity.TbPisInfr;
|
|
|
import com.its.pis.process.DbmsData;
|
|
|
import com.its.pis.websocket.common.SubscribeIdentifier;
|
|
@@ -10,15 +9,11 @@ import com.its.pis.websocket.common.SubscribeRequest;
|
|
|
import com.its.pis.websocket.common.SubscribeResponseAccept;
|
|
|
import com.its.pis.websocket.message.c2f.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.socket.TextMessage;
|
|
|
import org.springframework.web.socket.WebSocketSession;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.util.Base64;
|
|
|
-
|
|
|
@Slf4j
|
|
|
@Controller
|
|
|
@RequestMapping(PisWebSocketConfig.WS_C2F_ENDPOINT)
|
|
@@ -38,7 +33,7 @@ public class PisWebSocketHandlerC2F extends PisWebSocketHandler {
|
|
|
log.error("C2F: Payload data is empty");
|
|
|
return;
|
|
|
}
|
|
|
- log.info("C2F: Payload, RX] {}", payloadMessage);
|
|
|
+ //log.info("C2F: Payload, RX] {}", payloadMessage);
|
|
|
|
|
|
PisWebSocketSession sessionClient = PisWebSocketSessionManager.getInstance().getSession(session);
|
|
|
if (sessionClient == null) {
|
|
@@ -54,20 +49,20 @@ public class PisWebSocketHandlerC2F extends PisWebSocketHandler {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ pis.setLastRecvTime(System.currentTimeMillis());
|
|
|
C2FMessage<C2FMessagePayload> c2fMessage = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<C2FMessagePayload>>(){});
|
|
|
if (c2fMessage.getCommand() == null) {
|
|
|
- log.error("C2F: C2FMessage NULL, {}", c2fMessage);
|
|
|
- log.error("C2F: C2FMessage NULL, command data not found, session will be closed {}", session);
|
|
|
+ log.error("{}, C2F: C2FMessage NULL, {}", pis.getPIS_ID(), c2fMessage);
|
|
|
+ log.error("{}, C2F: C2FMessage NULL, command data not found, session will be closed {}", pis.getPIS_ID(), session);
|
|
|
session.close();
|
|
|
return;
|
|
|
}
|
|
|
if (C2FConstants.subscribe.equals(c2fMessage.getCommand())) {
|
|
|
- log.info("C2F: RX] subscribe");
|
|
|
-
|
|
|
+ log.info("{}, C2F: RX] subscribe", pis.getPIS_ID());
|
|
|
try {
|
|
|
SubscribeRequest subscribe = this.mapper.readValue(payloadMessage, SubscribeRequest.class);
|
|
|
//log.info("C2F: RX] {}", subscribe);
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(subscribe));
|
|
|
+ //log.info("RX] {}", this.mapper.writeValueAsString(subscribe));
|
|
|
pis.channelLogin(pis.getSession());
|
|
|
updatePisStts(pis, true);
|
|
|
|
|
@@ -79,9 +74,10 @@ public class PisWebSocketHandlerC2F extends PisWebSocketHandler {
|
|
|
.build();
|
|
|
String strMessage = this.mapper.writeValueAsString(response);
|
|
|
sessionClient.sendMessage(response.getType(), new TextMessage(strMessage));
|
|
|
- log.info("TX] {}", strMessage);
|
|
|
+ log.info("{}, C2F: TX]", pis.getPIS_ID());
|
|
|
+ //log.info("TX] {}", strMessage);
|
|
|
} catch (JsonProcessingException e) {
|
|
|
- log.error("TX] Exception: {}", e.getMessage());
|
|
|
+ log.error("{}, C2F: TX] Exception: JsonProcessingException", pis.getPIS_ID());
|
|
|
session.close();
|
|
|
}
|
|
|
return;
|
|
@@ -91,27 +87,27 @@ public class PisWebSocketHandlerC2F extends PisWebSocketHandler {
|
|
|
String eventName = c2fMessage.getData().getPayload().getEvent_name();
|
|
|
if (C2FConstants.prk_plce_sttus_info.equals(eventName)) {
|
|
|
C2FMessage<PrkPlceSttusInfo> sttusInfo = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<PrkPlceSttusInfo>>(){});
|
|
|
- C2FMessage<PrkPlceSttusInfo> sttusTemp = sttusInfo;
|
|
|
- sttusTemp.getData().getPayload().getPrk_place_image().setPrk_plce_image_data("base64 image data string");
|
|
|
- log.info("C2F: RX] prk_plce_sttus_info");
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(sttusTemp));
|
|
|
-
|
|
|
- if (sttusInfo.getData().getPayload().getPrk_place_image() != null) {
|
|
|
- int imageType = sttusInfo.getData().getPayload().getPrk_place_image().getPrk_plce_image_type();
|
|
|
- String imageStringData = sttusInfo.getData().getPayload().getPrk_place_image().getPrk_plce_image_data();
|
|
|
- byte[] decodedBytes = Base64.getDecoder().decode(imageStringData);
|
|
|
- String saveDir = ItsUtils.createUserDir("/images/");
|
|
|
- String outputFileName = saveDir + sttusInfo.getData().getPayload().getPrk_plce_manage_no();
|
|
|
- switch(imageType) {
|
|
|
- case 0: outputFileName += ".bmp"; break;
|
|
|
- case 1: outputFileName += ".gif"; break;
|
|
|
- case 2: outputFileName += ".jpg"; break;
|
|
|
- case 3: outputFileName += ".png"; break;
|
|
|
- default: outputFileName += ""; break;
|
|
|
- }
|
|
|
-
|
|
|
- FileUtils.writeByteArrayToFile(new File(outputFileName), decodedBytes);
|
|
|
- }
|
|
|
+// C2FMessage<PrkPlceSttusInfo> sttusTemp = sttusInfo;
|
|
|
+// sttusTemp.getData().getPayload().getPrk_place_image().setPrk_plce_image_data("base64 image data string");
|
|
|
+ log.info("{}, C2F: RX] prk_plce_sttus_info", pis.getPIS_ID());
|
|
|
+// log.info("RX] {}", this.mapper.writeValueAsString(sttusTemp));
|
|
|
+
|
|
|
+// if (sttusInfo.getData().getPayload().getPrk_place_image() != null) {
|
|
|
+// int imageType = sttusInfo.getData().getPayload().getPrk_place_image().getPrk_plce_image_type();
|
|
|
+// String imageStringData = sttusInfo.getData().getPayload().getPrk_place_image().getPrk_plce_image_data();
|
|
|
+// byte[] decodedBytes = Base64.getDecoder().decode(imageStringData);
|
|
|
+// String saveDir = ItsUtils.createUserDir("/images/");
|
|
|
+// String outputFileName = saveDir + sttusInfo.getData().getPayload().getPrk_plce_manage_no();
|
|
|
+// switch(imageType) {
|
|
|
+// case 0: outputFileName += ".bmp"; break;
|
|
|
+// case 1: outputFileName += ".gif"; break;
|
|
|
+// case 2: outputFileName += ".jpg"; break;
|
|
|
+// case 3: outputFileName += ".png"; break;
|
|
|
+// default: outputFileName += ""; break;
|
|
|
+// }
|
|
|
+//
|
|
|
+// FileUtils.writeByteArrayToFile(new File(outputFileName), decodedBytes);
|
|
|
+// }
|
|
|
// byte[] decodedBytes = Base64.getDecoder().decode(encodedString);
|
|
|
// FileUtils.writeByteArrayToFile(new File(outputFileName), decodedBytes);
|
|
|
// byte[] fileContent = FileUtils.readFileToByteArray(new File(filePath));
|
|
@@ -119,28 +115,28 @@ public class PisWebSocketHandlerC2F extends PisWebSocketHandler {
|
|
|
|
|
|
} else if (C2FConstants.prk_plce_opr_info.equals(eventName)) {
|
|
|
C2FMessage<PrkPlceOprInfo> oprInfo = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<PrkPlceOprInfo>>(){});
|
|
|
- log.info("C2F: RX] prk_plce_opr_info");
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(oprInfo));
|
|
|
+ log.info("{}, C2F: RX] prk_plce_opr_info", pis.getPIS_ID());
|
|
|
+ //log.info("RX] {}", this.mapper.writeValueAsString(oprInfo));
|
|
|
} else if (C2FConstants.prk_plce_rl_time_info.equals(eventName) || C2FConstants.prk_plce_rl_time_info_cycle.equals(eventName)) {
|
|
|
C2FMessage<PrkPlceRlTimeResponseInfo> rlTimeInfo = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<PrkPlceRlTimeResponseInfo>>(){});
|
|
|
pis.setRlTimeInfo(rlTimeInfo);
|
|
|
dbmsDataProcess.add(new DbmsData(DbmsData.DBMS_DATA_RL_TIME, false, rlTimeInfo, pis));
|
|
|
- log.info("C2F: RX] prk_plce_rl_time_info");
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(rlTimeInfo));
|
|
|
+ log.info("{}, C2F: RX] prk_plce_rl_time_info", pis.getPIS_ID());
|
|
|
+ //log.info("RX] {}", this.mapper.writeValueAsString(rlTimeInfo));
|
|
|
} else if (C2FConstants.prk_plce_reservation_response_info.equals(eventName)) {
|
|
|
C2FMessage<PrkPlceReservationResponseInfo> reservationInfo = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<PrkPlceReservationResponseInfo>>(){});
|
|
|
- log.info("C2F: RX] prk_plce_reservation_response_info");
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(reservationInfo));
|
|
|
+ log.info("{}, C2F: RX] prk_plce_reservation_response_info", pis.getPIS_ID());
|
|
|
+ //log.info("RX] {}", this.mapper.writeValueAsString(reservationInfo));
|
|
|
} else if (C2FConstants.prk_plce_vhcl_location_response_info.equals(eventName)) {
|
|
|
C2FMessage<PrkPlceVhclLocationResponseInfo> locationInfo = this.mapper.readValue(payloadMessage, new TypeReference<C2FMessage<PrkPlceVhclLocationResponseInfo>>(){});
|
|
|
log.info("C2F: RX] prk_plce_vhcl_location_response_info");
|
|
|
- log.info("RX] {}", this.mapper.writeValueAsString(locationInfo));
|
|
|
+ //log.info("RX] {}", this.mapper.writeValueAsString(locationInfo));
|
|
|
} else {
|
|
|
- log.error("C2F: RX] Unknown event name, {}", eventName);
|
|
|
+ log.error("{}, C2F: RX] Unknown event name, {}", pis.getPIS_ID(), eventName);
|
|
|
log.error("RX] Payload, {}", payloadMessage);
|
|
|
}
|
|
|
} catch(NullPointerException e) {
|
|
|
- log.error("C2F: RX] NullPointerException, Payload data null, {}", payloadMessage);
|
|
|
+ log.error("{}, C2F: RX] NullPointerException, Payload NullPointerException, {}", pis.getPIS_ID(), payloadMessage);
|
|
|
}
|
|
|
}
|
|
|
|