新增 车位相机信息表以及相机解析信息逻辑

This commit is contained in:
Lemon
2023-12-11 09:00:58 +08:00
parent 5e4c8c7f84
commit a98a36f04f
10 changed files with 995 additions and 147 deletions

View File

@@ -1,16 +1,20 @@
package com.jsowell.thirdparty.camera.service;
import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.DateUtils;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.PileCameraInfo;
import com.jsowell.pile.dto.camera.CameraIdentifyResultsDTO;
import com.jsowell.pile.service.IPileCameraInfoService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 相机管理系统 Service
@@ -24,22 +28,120 @@ public class CameraService {
@Autowired
private RedisCache redisCache;
@Autowired
private IPileCameraInfoService pileCameraInfoService;
public void receiveIdentifyResults(JSONObject jsonObject) {
// 区分入场和出场
// Integer parking_state = jsonObject.getJSONObject("parking").getInteger("parking_state");
// if (parking_state == 1) {
// // 入场
// String parkingState = "ENTRY";
// vehicleEntry(jsonObject, parkingState);
// }
// if (parking_state == 2) {
// // 在场
// }
// if (parking_state == 4) {
// // 出场
// }
saveInfo2DataBase(jsonObject);
}
/**
* 车辆入场
* @param jsonObject
*/
private void vehicleEntry(JSONObject jsonObject, String parkingState) {
// 先将车牌图片信息存入缓存
// boolean result = saveCarPicture2Redis(jsonObject, parkingState);
// 将信息存数据库
saveInfo2DataBase(jsonObject);
}
private boolean saveInfo2DataBase(JSONObject jsonObject) {
// 车牌信息
CameraIdentifyResultsDTO.ProductH.Plate plate = JSONObject.parseObject(jsonObject.getJSONObject("product_h").getJSONObject("plate").toJSONString(),
CameraIdentifyResultsDTO.ProductH.Plate.class);
if (plate == null) {
return false;
}
// 停车位信息
CameraIdentifyResultsDTO.ProductH.Parking parking = JSONObject.parseObject(jsonObject.getJSONObject("product_h").getJSONObject("parking").toJSONString(),
CameraIdentifyResultsDTO.ProductH.Parking.class);
if (parking == null) {
return false;
}
// 设备信息
CameraIdentifyResultsDTO.DeviceInfo deviceInfo = JSONObject.parseObject(jsonObject.getJSONObject("device_info").toJSONString(),
CameraIdentifyResultsDTO.DeviceInfo.class);
if (deviceInfo == null) {
return false;
}
// 获取背景图片
JSONArray bgImgs = jsonObject.getJSONArray("bg_img");
List<CameraIdentifyResultsDTO.BgImg> bgImgList = bgImgs.toList(CameraIdentifyResultsDTO.BgImg.class);
if (CollectionUtils.isEmpty(bgImgList)) {
return;
return false;
}
// Base64解密
String plateNumber = Base64.decodeStr(plate.getPlate());
String zoneName = Base64.decodeStr(parking.getZoneName());
for (CameraIdentifyResultsDTO.BgImg bgImg : bgImgList) {
PileCameraInfo pileCameraInfo = PileCameraInfo.builder()
.deviceName(deviceInfo.getDevName())
.deviceIp(deviceInfo.getIp())
.deviceSn(deviceInfo.getSn())
.plateNumber(plateNumber)
.parkingState(String.valueOf(parking.getParkingState()))
.zoneId(parking.getZoneId())
.zoneName(zoneName)
.color(plate.getColor())
.plateType(plate.getType())
.image(bgImg.getImage())
.build();
// 插入数据库
pileCameraInfoService.insertPileCameraInfo(pileCameraInfo);
}
return true;
}
/**
* 将车辆图片信息存入缓存
* @param jsonObject
*/
private boolean saveCarPicture2Redis(JSONObject jsonObject, String parkingState) {
// 获取车牌号
String plateNumber = jsonObject.getJSONObject("plate").getString("plate");
if (StringUtils.isBlank(plateNumber)) {
return false;
}
// 获取背景图片
JSONArray bgImgs = jsonObject.getJSONArray("bg_img");
List<CameraIdentifyResultsDTO.BgImg> bgImgList = bgImgs.toList(CameraIdentifyResultsDTO.BgImg.class);
if (CollectionUtils.isEmpty(bgImgList)) {
return false;
}
for (CameraIdentifyResultsDTO.BgImg bgImg : bgImgList) {
String image = bgImg.getImage(); // 图片的 base64 编码
String key = bgImg.getKey(); // 索引id
String redisKey = "receiveCameraImageByKey_" + key;
// 根据索引id存入缓存
redisCache.setCacheObject(redisKey, image, 10, TimeUnit.HOURS);
// String key = bgImg.getKey(); // 索引id
// key: 前缀 + 车牌号 + 日期 + 入场/出场状态
String redisKey = CacheConstants.CAMERA_IMAGE_BY_PLATE_NUMBER + plateNumber + "_" + DateUtils.getDate() + "_" + parkingState;
// 存入缓存
// TODO 暂时永久保存
redisCache.setCacheObject(redisKey, image);
}
return true;
}
}