This commit is contained in:
zc
2026-05-12 10:49:59 +08:00
parent 17eb0c69ff
commit 2248060905
9 changed files with 133 additions and 178 deletions

View File

@@ -10,8 +10,8 @@ import java.io.Serial;
import java.io.Serializable;
@Data
@TableName("sys_equipment")
public class Equipment implements Serializable {
@TableName("sys_io_lock_equipment")
public class IoLockEquipment implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
@@ -21,9 +21,6 @@ public class Equipment implements Serializable {
@TableId(type = IdType.AUTO)
private Long id;
/** 所属产品Id */
private Long productId;
/** 设备名称 */
private String name;
@@ -36,15 +33,6 @@ public class Equipment implements Serializable {
/** 设备密码 */
private String password;
/** 设备区域 */
private Long spaceId;
/** 设备位置 */
private Long pointId;
/** 对接状态(0未对接 1对接成功) */
private Long state;
/** 设备状态(0在线 1离线) */
private String flag;

View File

@@ -47,28 +47,21 @@ public class CarMessageListener {
@Autowired
RedisService redisService;
@Autowired
ICarParkRecordService carParkRecordService;
// @Autowired
// ICarParkRecordService carParkRecordService;
//
// @Autowired
// ICarPassRecordService carPassRecordService;
//
// @Autowired
// ICarParkItemService carParkItemService;
//
// @Autowired
// ICarPassGatherService carPassGatherService;
@Autowired
ICarPassRecordService carPassRecordService;
// private static String key = "1234567898765432";
@Autowired
ICarParkItemService carParkItemService;
@Autowired
ICarPassGatherService carPassGatherService;
@Autowired
private ServerService service;
private static String key = "1234567898765432";
//xa、jl、td、xj
private String jinjiangUrl = "http://127.0.0.1:6609/";
//zr
// private String jinjiangUrl = "http://192.168.155.42:6609/";
// private String jinjiangUrl = "http://127.0.0.1:6609/";
/**
* 心跳
@@ -91,7 +84,7 @@ public class CarMessageListener {
* @param topic
* @param message
*/
@MqttServerFunction("device/${sn}/message/down/white_list_operator/reply")
/*@MqttServerFunction("device/${sn}/message/down/white_list_operator/reply")
@Transactional(rollbackFor = Exception.class)
public void white_list_operator_reply(String topic, byte[] message) {
log.info("接收到车牌下发消息 -> Topic: {}, message: {}", topic, new String(message));
@@ -111,7 +104,7 @@ public class CarMessageListener {
carParkRecord.setSync("1");
}
carParkRecordService.updateByClientId(carParkRecord);
}
}*/
/**
* 车牌入场出场识别监听
@@ -123,98 +116,98 @@ public class CarMessageListener {
public void ivs_result(String topic, Map<String, String> topicVars, byte[] message) throws Exception {
String sn = topicVars.get("sn");
log.info("接收到车辆识别消息 -> Topic: {}", topic);
//如果开启了锁杆,且车位满了
CarParkItem carParkItem = carParkItemService.selectBySn(sn);
long count = carPassGatherService.count(new QueryWrapper<CarPassGather>().eq("park_id", carParkItem.getParkId()));
if (StrUtil.equals(carParkItem.getWay(), "0") //入场
&& carParkItem.getAutoLock() == 1 //开启了锁杆
&& count >= carParkItem.getCarsNum()) { //车位满了
log.info("车位满了,不记录入场数据");
return;
}
String data = new String(message, StandardCharsets.UTF_8);
JSONObject jsonObject = JSONObject.parseObject(data);
JSONObject payload = jsonObject.getJSONObject("payload");
String id = jsonObject.getString("id");
JSONObject alarmInfoPlate = payload.getJSONObject("AlarmInfoPlate");
JSONObject result = alarmInfoPlate.getJSONObject("result");
JSONObject plateResult = result.getJSONObject("PlateResult");
JSONObject carBrand = plateResult.getJSONObject("car_brand");
String license = plateResult.getString("license");
String colorType = plateResult.getString("colorType");
String str = "";
if ("5".equals(colorType)) {
str = AESUtil.decrptyAES_ECB(license, key).substring(0, 20);
} else {
str = AESUtil.decrptyAES_ECB(license, key).substring(0, 18);
}
license = AESUtil.UTF8decode(str);
log.info("解密前车牌:{},解谜后的车牌:{}", plateResult.getString("license"), license);
//保存通行记录
CarPassRecord record = new CarPassRecord();
record.setCarColor(plateResult.getString("carColor"));
record.setColorType(colorType);
record.setDirection(plateResult.getString("direction"));
record.setLicense(license);
record.setDataType("0");
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("url", plateResult.getString("full_image_content"));
String repose = HttpUtil.createPost(jinjiangUrl + "file/uploadMinioCarBase64")
.body(JSON.toJSONString(paramMap))
.execute()
.body();
log.info("imgRsp:{}", repose);
JSONObject imgRsp = JSONObject.parseObject(repose);
if (null != imgRsp && imgRsp.getInteger("code") == 200) {
record.setUrl(imgRsp.getJSONObject("data").getString("url"));
}
if (plateResult.containsKey("start_time")) {
log.info("拿到了时间:{}", plateResult.getLong("start_time"));
record.setPassTime(DateUtil.date(plateResult.getLong("start_time")));
} else {
log.info("没有拿到时间,默认当前时间");
record.setPassTime(DateUtil.date(new Date()));
}
record.setSn(sn);
record.setUniqueNo(id);
record.setParkId(carParkItem.getParkId());
record.setTriggerType(plateResult.getString("triggerType"));
record.setType(carBrand.getString("type"));
carPassRecordService.save(record);
//保存/删除在场数据
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license).eq("park_id", carParkItem.getParkId()));
//入场新增数据
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
CarPassGather carPassGather = new CarPassGather();
carPassGather.setLicense(license);
carPassGather.setParkId(carParkItem.getParkId());
carPassGather.setArea(carParkItem.getArea());
carPassGather.setJoinTime(record.getPassTime());
carPassGather.setSn(sn);
carPassGatherService.save(carPassGather);
//最后一辆车进场
if (carParkItem.getAutoLock() == 1 && (count + 1) >= carParkItem.getCarsNum()) {
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
for (String s : snList) {
service.locked(s, 2, 0);
}
}
} else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
carPassGatherService.deleteByLicense(license);
//出去一辆车,有空位
if (carParkItem.getAutoLock() == 1 && count == carParkItem.getCarsNum()) {
List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
for (String s : snList) {
service.locked(s, 0, 0);
}
}
}
//
// //如果开启了锁杆,且车位满了
// CarParkItem carParkItem = carParkItemService.selectBySn(sn);
// long count = carPassGatherService.count(new QueryWrapper<CarPassGather>().eq("park_id", carParkItem.getParkId()));
// if (StrUtil.equals(carParkItem.getWay(), "0") //入场
// && carParkItem.getAutoLock() == 1 //开启了锁杆
// && count >= carParkItem.getCarsNum()) { //车位满了
// log.info("车位满了,不记录入场数据");
// return;
// }
//
// String data = new String(message, StandardCharsets.UTF_8);
// JSONObject jsonObject = JSONObject.parseObject(data);
// JSONObject payload = jsonObject.getJSONObject("payload");
// String id = jsonObject.getString("id");
// JSONObject alarmInfoPlate = payload.getJSONObject("AlarmInfoPlate");
// JSONObject result = alarmInfoPlate.getJSONObject("result");
// JSONObject plateResult = result.getJSONObject("PlateResult");
// JSONObject carBrand = plateResult.getJSONObject("car_brand");
// String license = plateResult.getString("license");
// String colorType = plateResult.getString("colorType");
// String str = "";
// if ("5".equals(colorType)) {
// str = AESUtil.decrptyAES_ECB(license, key).substring(0, 20);
// } else {
// str = AESUtil.decrptyAES_ECB(license, key).substring(0, 18);
// }
//
// license = AESUtil.UTF8decode(str);
// log.info("解密前车牌:{},解谜后的车牌:{}", plateResult.getString("license"), license);
//
// //保存通行记录
// CarPassRecord record = new CarPassRecord();
// record.setCarColor(plateResult.getString("carColor"));
// record.setColorType(colorType);
// record.setDirection(plateResult.getString("direction"));
// record.setLicense(license);
// record.setDataType("0");
// Map<String, Object> paramMap = new HashMap<>();
// paramMap.put("url", plateResult.getString("full_image_content"));
// String repose = HttpUtil.createPost(jinjiangUrl + "file/uploadMinioCarBase64")
// .body(JSON.toJSONString(paramMap))
// .execute()
// .body();
// log.info("imgRsp:{}", repose);
// JSONObject imgRsp = JSONObject.parseObject(repose);
// if (null != imgRsp && imgRsp.getInteger("code") == 200) {
// record.setUrl(imgRsp.getJSONObject("data").getString("url"));
// }
// if (plateResult.containsKey("start_time")) {
// log.info("拿到了时间:{}", plateResult.getLong("start_time"));
// record.setPassTime(DateUtil.date(plateResult.getLong("start_time")));
// } else {
// log.info("没有拿到时间,默认当前时间");
// record.setPassTime(DateUtil.date(new Date()));
// }
// record.setSn(sn);
// record.setUniqueNo(id);
// record.setParkId(carParkItem.getParkId());
// record.setTriggerType(plateResult.getString("triggerType"));
// record.setType(carBrand.getString("type"));
// carPassRecordService.save(record);
//
// //保存/删除在场数据
// boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license).eq("park_id", carParkItem.getParkId()));
// //入场新增数据
// if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
// CarPassGather carPassGather = new CarPassGather();
// carPassGather.setLicense(license);
// carPassGather.setParkId(carParkItem.getParkId());
// carPassGather.setArea(carParkItem.getArea());
// carPassGather.setJoinTime(record.getPassTime());
// carPassGather.setSn(sn);
// carPassGatherService.save(carPassGather);
//
// //最后一辆车进场
// if (carParkItem.getAutoLock() == 1 && (count + 1) >= carParkItem.getCarsNum()) {
// List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
// for (String s : snList) {
// service.locked(s, 2, 0);
// }
// }
// } else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
// carPassGatherService.deleteByLicense(license);
// //出去一辆车,有空位
// if (carParkItem.getAutoLock() == 1 && count == carParkItem.getCarsNum()) {
// List<String> snList = carParkItemService.selectSnByParkId(carParkItem.getParkId());
// for (String s : snList) {
// service.locked(s, 0, 0);
// }
// }
// }
}
/**
@@ -223,7 +216,7 @@ public class CarMessageListener {
* @param topic
* @param message
*/
@MqttServerFunction("device/${sn}/message/up/ivs_result_offline")
/*@MqttServerFunction("device/${sn}/message/up/ivs_result_offline")
public void ivs_result_offline(String topic, Map<String, String> topicVars, byte[] message) throws Exception {
String sn = topicVars.get("sn");
log.info("接收到车辆离线识别消息 -> Topic: {}", topic);
@@ -278,7 +271,7 @@ public class CarMessageListener {
record.setTriggerType(plateResult.getString("triggerType"));
record.setType(carBrand.getString("type"));
carPassRecordService.save(record);
}
}*/
/**
* IO输出事件监听

View File

@@ -16,13 +16,10 @@
package org.dromara.mica.mqtt.server.listener;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.dromara.mica.mqtt.core.server.event.IMqttConnectStatusListener;
import org.dromara.mica.mqtt.server.constant.CacheConstants;
import org.dromara.mica.mqtt.server.entity.Equipment;
import org.dromara.mica.mqtt.server.enums.FlagEnums;
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
import org.dromara.mica.mqtt.server.redis.RedisService;
import org.dromara.mica.mqtt.server.service.IEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -30,8 +27,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.tio.core.ChannelContext;
import java.util.concurrent.TimeUnit;
/**
* mqtt 连接状态
*

View File

@@ -2,10 +2,9 @@ package org.dromara.mica.mqtt.server.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.dromara.mica.mqtt.server.entity.CarInfo;
import org.dromara.mica.mqtt.server.entity.Equipment;
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
@Mapper
public interface EquipmentMapper extends BaseMapper<Equipment> {
public interface EquipmentMapper extends BaseMapper<IoLockEquipment> {
}

View File

@@ -1,15 +1,15 @@
package org.dromara.mica.mqtt.server.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.dromara.mica.mqtt.server.entity.Equipment;
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
import java.util.List;
public interface IEquipmentService extends IService<Equipment> {
public interface IEquipmentService extends IService<IoLockEquipment> {
Equipment selectEquipmentBySn(String sn);
IoLockEquipment selectEquipmentBySn(String sn);
List<Equipment> selectAllSnFlag();
List<IoLockEquipment> selectAllSnFlag();
void updateFlag(String sn, String flag);
}

View File

@@ -2,7 +2,7 @@ package org.dromara.mica.mqtt.server.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.mica.mqtt.server.entity.Equipment;
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
import org.dromara.mica.mqtt.server.service.IEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -11,25 +11,25 @@ import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, IoLockEquipment> implements IEquipmentService {
@Autowired
EquipmentMapper equipmentMapper;
@Override
public Equipment selectEquipmentBySn(String sn) {
return equipmentMapper.selectOne(new QueryWrapper<Equipment>().eq("sequence", sn).eq("product_id", 4L).last("limit 1"));
public IoLockEquipment selectEquipmentBySn(String sn) {
return equipmentMapper.selectOne(new QueryWrapper<IoLockEquipment>().eq("sequence", sn).last("limit 1"));
}
@Override
public List<Equipment> selectAllSnFlag() {
return equipmentMapper.selectList(new QueryWrapper<Equipment>().eq("product_id", 4L).select("sequence", "flag"));
public List<IoLockEquipment> selectAllSnFlag() {
return equipmentMapper.selectList(new QueryWrapper<IoLockEquipment>().select("sequence", "flag"));
}
@Override
public void updateFlag(String sn, String flag) {
Equipment equipment = new Equipment();
IoLockEquipment equipment = new IoLockEquipment();
equipment.setFlag(flag);
equipmentMapper.update(equipment, new QueryWrapper<Equipment>().eq("sequence", sn).eq("product_id", 4L));
equipmentMapper.update(equipment, new QueryWrapper<IoLockEquipment>().eq("sequence", sn));
}
}

View File

@@ -1,11 +1,9 @@
package org.dromara.mica.mqtt.server.task;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.dromara.mica.mqtt.server.constant.CacheConstants;
import org.dromara.mica.mqtt.server.entity.Equipment;
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
import org.dromara.mica.mqtt.server.enums.FlagEnums;
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
import org.dromara.mica.mqtt.server.redis.RedisService;
import org.dromara.mica.mqtt.server.service.IEquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -32,9 +30,9 @@ public class HeartbeatOnLineTask {
public void run() {
log.info("===========心跳检测=============");
//查询车辆摄像头的编码和在线状态
List<Equipment> equipment = equipmentService.selectAllSnFlag();
List<IoLockEquipment> equipment = equipmentService.selectAllSnFlag();
for (Equipment equip : equipment) {
for (IoLockEquipment equip : equipment) {
//缓存中有该设备心跳key
if (redisService.hasKey(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence())) {
String flag = redisService.getCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence());

View File

@@ -48,7 +48,7 @@ public class PlatePublishTask {
/**
* 定时查询数据库需要下发的车辆进行下发
*/
@Scheduled(fixedDelay = 8 * 1000)
// @Scheduled(fixedDelay = 8 * 1000)
public void run() {
String whiteUrl = "device/%s/message/down/white_list_operator";

View File

@@ -1,32 +1,14 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
#xa
# url: jdbc:mysql://127.0.0.1:3306/xa_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: Xahg2024.
#jl
# url: jdbc:mysql://127.0.0.1:3306/jl_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: JL202509jj
#td
url: jdbc:mysql://127.0.0.1:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://192.168.251.16:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: td@JJ2024
#zr
# url: jdbc:mysql://192.168.155.42:3306/zr_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: zr202407.J
#xj
# url: jdbc:mysql://127.0.0.1:3306/xj_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
# username: root
# password: XjJN2024!
data:
redis:
#zr
# host: 192.168.155.42
# xa、jl、td、xj
host: 127.0.0.1
host: 192.168.251.16
port: 6379
password:
database: 1
database: 2