Compare commits
2 Commits
e9a698c728
...
dev_zc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
056671d690 | ||
|
|
52c092cde7 |
@@ -3,7 +3,10 @@ package org.dromara.mica.mqtt.server.controller;
|
|||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import org.dromara.mica.mqtt.server.service.impl.ServerService;
|
import org.dromara.mica.mqtt.server.service.impl.ServerService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RequestMapping("/mqtt/server")
|
@RequestMapping("/mqtt/server")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -49,53 +52,4 @@ public class ServerController {
|
|||||||
return service.set_time(body);
|
return service.set_time(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
//手动触发抬杆
|
|
||||||
@PostMapping("/openFloodgate")
|
|
||||||
public boolean openFloodgate(@RequestBody JSONObject js) {
|
|
||||||
String sn = js.getString("sn");
|
|
||||||
return service.openFloodgate(sn);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/set_io_lock_status")
|
|
||||||
public JSONObject lock(@RequestBody JSONObject js) {
|
|
||||||
String sn = js.getString("sn");
|
|
||||||
Integer status = js.getInteger("status");
|
|
||||||
Integer ioout = js.getInteger("ioout");
|
|
||||||
boolean publish = service.locked(sn, status,ioout);
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
if (publish) {
|
|
||||||
jsonObject.put("code", 200);
|
|
||||||
} else {
|
|
||||||
jsonObject.put("code", 500);
|
|
||||||
}
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
//常开
|
|
||||||
@PostMapping("/set_io_lock_open")
|
|
||||||
public JSONObject lockOpen(@RequestBody JSONObject js) {
|
|
||||||
String sn = js.getString("sn");
|
|
||||||
boolean publish = service.lockOpen(sn);
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
if (publish) {
|
|
||||||
jsonObject.put("code", 200);
|
|
||||||
} else {
|
|
||||||
jsonObject.put("code", 500);
|
|
||||||
}
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
//常关
|
|
||||||
@PostMapping("/set_io_lock_close")
|
|
||||||
public JSONObject lockClose(@RequestBody JSONObject js) {
|
|
||||||
String sn = js.getString("sn");
|
|
||||||
boolean publish = service.lockClose(sn);
|
|
||||||
JSONObject jsonObject = new JSONObject();
|
|
||||||
if (publish) {
|
|
||||||
jsonObject.put("code", 200);
|
|
||||||
} else {
|
|
||||||
jsonObject.put("code", 500);
|
|
||||||
}
|
|
||||||
return jsonObject;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,14 +47,4 @@ public class CarParkItem implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String area;
|
private String area;
|
||||||
|
|
||||||
/**
|
|
||||||
* 车位数量
|
|
||||||
*/
|
|
||||||
private Integer carsNum;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 满车位自动锁杆:0:不锁,1:锁
|
|
||||||
*/
|
|
||||||
private Integer autoLock;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class CarPassGather implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* id
|
* id
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.AUTO )
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.TableId;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import java.io.Serial;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@TableName("sys_io_lock_equipment")
|
@TableName("sys_equipment")
|
||||||
public class IoLockEquipment implements Serializable {
|
public class Equipment implements Serializable {
|
||||||
|
|
||||||
@Serial
|
@Serial
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -21,6 +21,9 @@ public class IoLockEquipment implements Serializable {
|
|||||||
@TableId(type = IdType.AUTO)
|
@TableId(type = IdType.AUTO)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
|
/** 所属产品Id */
|
||||||
|
private Long productId;
|
||||||
|
|
||||||
/** 设备名称 */
|
/** 设备名称 */
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@@ -33,6 +36,15 @@ public class IoLockEquipment implements Serializable {
|
|||||||
/** 设备密码 */
|
/** 设备密码 */
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
/** 设备区域 */
|
||||||
|
private Long spaceId;
|
||||||
|
|
||||||
|
/** 设备位置 */
|
||||||
|
private Long pointId;
|
||||||
|
|
||||||
|
/** 对接状态(0未对接 1对接成功) */
|
||||||
|
private Long state;
|
||||||
|
|
||||||
/** 设备状态(0在线 1离线) */
|
/** 设备状态(0在线 1离线) */
|
||||||
private String flag;
|
private String flag;
|
||||||
|
|
||||||
@@ -21,7 +21,6 @@ import org.dromara.mica.mqtt.server.service.ICarParkItemService;
|
|||||||
import org.dromara.mica.mqtt.server.service.ICarParkRecordService;
|
import org.dromara.mica.mqtt.server.service.ICarParkRecordService;
|
||||||
import org.dromara.mica.mqtt.server.service.ICarPassGatherService;
|
import org.dromara.mica.mqtt.server.service.ICarPassGatherService;
|
||||||
import org.dromara.mica.mqtt.server.service.ICarPassRecordService;
|
import org.dromara.mica.mqtt.server.service.ICarPassRecordService;
|
||||||
import org.dromara.mica.mqtt.server.service.impl.ServerService;
|
|
||||||
import org.dromara.mica.mqtt.server.utils.AESUtil;
|
import org.dromara.mica.mqtt.server.utils.AESUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -31,7 +30,6 @@ import org.tio.utils.hutool.StrUtil;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -47,21 +45,24 @@ public class CarMessageListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
RedisService redisService;
|
RedisService redisService;
|
||||||
|
|
||||||
// @Autowired
|
@Autowired
|
||||||
// ICarParkRecordService carParkRecordService;
|
ICarParkRecordService carParkRecordService;
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// ICarPassRecordService carPassRecordService;
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// ICarParkItemService carParkItemService;
|
|
||||||
//
|
|
||||||
// @Autowired
|
|
||||||
// ICarPassGatherService carPassGatherService;
|
|
||||||
|
|
||||||
// private static String key = "1234567898765432";
|
@Autowired
|
||||||
|
ICarPassRecordService carPassRecordService;
|
||||||
|
|
||||||
// private String jinjiangUrl = "http://127.0.0.1:6609/";
|
@Autowired
|
||||||
|
ICarParkItemService carParkItemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
ICarPassGatherService carPassGatherService;
|
||||||
|
|
||||||
|
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/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 心跳
|
* 心跳
|
||||||
@@ -74,7 +75,7 @@ public class CarMessageListener {
|
|||||||
String sn = topicVars.get("sn");
|
String sn = topicVars.get("sn");
|
||||||
log.info("接收到来自客户端 [{}] 的心跳消息 -> Topic: {}", sn, topic);
|
log.info("接收到来自客户端 [{}] 的心跳消息 -> Topic: {}", sn, topic);
|
||||||
|
|
||||||
// 更新客户端的最后心跳
|
// 更新客户端的最后心跳
|
||||||
redisService.setCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + sn, FlagEnums.ONLINE.getCode(), CacheConstants.OFFLINE_THRESHOLD, TimeUnit.MILLISECONDS);
|
redisService.setCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + sn, FlagEnums.ONLINE.getCode(), CacheConstants.OFFLINE_THRESHOLD, TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ public class CarMessageListener {
|
|||||||
* @param topic
|
* @param topic
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
/*@MqttServerFunction("device/${sn}/message/down/white_list_operator/reply")
|
@MqttServerFunction("device/${sn}/message/down/white_list_operator/reply")
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void white_list_operator_reply(String topic, byte[] message) {
|
public void white_list_operator_reply(String topic, byte[] message) {
|
||||||
log.info("接收到车牌下发消息 -> Topic: {}, message: {}", topic, new String(message));
|
log.info("接收到车牌下发消息 -> Topic: {}, message: {}", topic, new String(message));
|
||||||
@@ -104,7 +105,7 @@ public class CarMessageListener {
|
|||||||
carParkRecord.setSync("1");
|
carParkRecord.setSync("1");
|
||||||
}
|
}
|
||||||
carParkRecordService.updateByClientId(carParkRecord);
|
carParkRecordService.updateByClientId(carParkRecord);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车牌入场出场识别监听
|
* 车牌入场出场识别监听
|
||||||
@@ -116,98 +117,74 @@ public class CarMessageListener {
|
|||||||
public void ivs_result(String topic, Map<String, String> topicVars, byte[] message) throws Exception {
|
public void ivs_result(String topic, Map<String, String> topicVars, byte[] message) throws Exception {
|
||||||
String sn = topicVars.get("sn");
|
String sn = topicVars.get("sn");
|
||||||
log.info("接收到车辆识别消息 -> Topic: {}", topic);
|
log.info("接收到车辆识别消息 -> Topic: {}", topic);
|
||||||
//
|
CarParkItem carParkItem = carParkItemService.selectBySn(sn);
|
||||||
// //如果开启了锁杆,且车位满了
|
|
||||||
// CarParkItem carParkItem = carParkItemService.selectBySn(sn);
|
String data = new String(message, StandardCharsets.UTF_8);
|
||||||
// long count = carPassGatherService.count(new QueryWrapper<CarPassGather>().eq("park_id", carParkItem.getParkId()));
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
// if (StrUtil.equals(carParkItem.getWay(), "0") //入场
|
JSONObject payload = jsonObject.getJSONObject("payload");
|
||||||
// && carParkItem.getAutoLock() == 1 //开启了锁杆
|
String id = jsonObject.getString("id");
|
||||||
// && count >= carParkItem.getCarsNum()) { //车位满了
|
JSONObject alarmInfoPlate = payload.getJSONObject("AlarmInfoPlate");
|
||||||
// log.info("车位满了,不记录入场数据");
|
JSONObject result = alarmInfoPlate.getJSONObject("result");
|
||||||
// return;
|
JSONObject plateResult = result.getJSONObject("PlateResult");
|
||||||
// }
|
JSONObject carBrand = plateResult.getJSONObject("car_brand");
|
||||||
//
|
String license = plateResult.getString("license");
|
||||||
// String data = new String(message, StandardCharsets.UTF_8);
|
String colorType = plateResult.getString("colorType");
|
||||||
// JSONObject jsonObject = JSONObject.parseObject(data);
|
String str = "";
|
||||||
// JSONObject payload = jsonObject.getJSONObject("payload");
|
if ("5".equals(colorType)) {
|
||||||
// String id = jsonObject.getString("id");
|
str = AESUtil.decrptyAES_ECB(license, key).substring(0, 20);
|
||||||
// JSONObject alarmInfoPlate = payload.getJSONObject("AlarmInfoPlate");
|
} else {
|
||||||
// JSONObject result = alarmInfoPlate.getJSONObject("result");
|
str = AESUtil.decrptyAES_ECB(license, key).substring(0, 18);
|
||||||
// JSONObject plateResult = result.getJSONObject("PlateResult");
|
}
|
||||||
// JSONObject carBrand = plateResult.getJSONObject("car_brand");
|
|
||||||
// String license = plateResult.getString("license");
|
license = AESUtil.UTF8decode(str);
|
||||||
// String colorType = plateResult.getString("colorType");
|
log.info("解密前车牌:{},解谜后的车牌:{}", plateResult.getString("license"), license);
|
||||||
// String str = "";
|
|
||||||
// if ("5".equals(colorType)) {
|
//保存通行记录
|
||||||
// str = AESUtil.decrptyAES_ECB(license, key).substring(0, 20);
|
CarPassRecord record = new CarPassRecord();
|
||||||
// } else {
|
record.setCarColor(plateResult.getString("carColor"));
|
||||||
// str = AESUtil.decrptyAES_ECB(license, key).substring(0, 18);
|
record.setColorType(colorType);
|
||||||
// }
|
record.setDirection(plateResult.getString("direction"));
|
||||||
//
|
record.setLicense(license);
|
||||||
// license = AESUtil.UTF8decode(str);
|
record.setDataType("0");
|
||||||
// log.info("解密前车牌:{},解谜后的车牌:{}", plateResult.getString("license"), license);
|
Map<String, Object> paramMap = new HashMap<>();
|
||||||
//
|
paramMap.put("url", plateResult.getString("full_image_content"));
|
||||||
// //保存通行记录
|
String repose = HttpUtil.createPost(jinjiangUrl + "file/uploadMinioCarBase64")
|
||||||
// CarPassRecord record = new CarPassRecord();
|
.body(JSON.toJSONString(paramMap))
|
||||||
// record.setCarColor(plateResult.getString("carColor"));
|
.execute()
|
||||||
// record.setColorType(colorType);
|
.body();
|
||||||
// record.setDirection(plateResult.getString("direction"));
|
log.info("imgRsp:{}", repose);
|
||||||
// record.setLicense(license);
|
JSONObject imgRsp = JSONObject.parseObject(repose);
|
||||||
// record.setDataType("0");
|
if (null != imgRsp && imgRsp.getInteger("code") == 200) {
|
||||||
// Map<String, Object> paramMap = new HashMap<>();
|
record.setUrl(imgRsp.getJSONObject("data").getString("url"));
|
||||||
// paramMap.put("url", plateResult.getString("full_image_content"));
|
}
|
||||||
// String repose = HttpUtil.createPost(jinjiangUrl + "file/uploadMinioCarBase64")
|
if (plateResult.containsKey("start_time")) {
|
||||||
// .body(JSON.toJSONString(paramMap))
|
log.info("拿到了时间:{}", plateResult.getLong("start_time"));
|
||||||
// .execute()
|
record.setPassTime(DateUtil.date(plateResult.getLong("start_time")));
|
||||||
// .body();
|
} else {
|
||||||
// log.info("imgRsp:{}", repose);
|
log.info("没有拿到时间,默认当前时间");
|
||||||
// JSONObject imgRsp = JSONObject.parseObject(repose);
|
record.setPassTime(DateUtil.date(new Date()));
|
||||||
// if (null != imgRsp && imgRsp.getInteger("code") == 200) {
|
}
|
||||||
// record.setUrl(imgRsp.getJSONObject("data").getString("url"));
|
record.setSn(sn);
|
||||||
// }
|
record.setUniqueNo(id);
|
||||||
// if (plateResult.containsKey("start_time")) {
|
record.setParkId(carParkItem.getParkId());
|
||||||
// log.info("拿到了时间:{}", plateResult.getLong("start_time"));
|
record.setTriggerType(plateResult.getString("triggerType"));
|
||||||
// record.setPassTime(DateUtil.date(plateResult.getLong("start_time")));
|
record.setType(carBrand.getString("type"));
|
||||||
// } else {
|
carPassRecordService.save(record);
|
||||||
// log.info("没有拿到时间,默认当前时间");
|
|
||||||
// record.setPassTime(DateUtil.date(new Date()));
|
//保存/删除在场数据
|
||||||
// }
|
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license));
|
||||||
// record.setSn(sn);
|
//入场新增数据
|
||||||
// record.setUniqueNo(id);
|
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
||||||
// record.setParkId(carParkItem.getParkId());
|
CarPassGather carPassGather = new CarPassGather();
|
||||||
// record.setTriggerType(plateResult.getString("triggerType"));
|
carPassGather.setLicense(license);
|
||||||
// record.setType(carBrand.getString("type"));
|
carPassGather.setParkId(carParkItem.getParkId());
|
||||||
// carPassRecordService.save(record);
|
carPassGather.setArea(carParkItem.getArea());
|
||||||
//
|
carPassGather.setJoinTime(record.getPassTime());
|
||||||
// //保存/删除在场数据
|
carPassGather.setSn(sn);
|
||||||
// boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license).eq("park_id", carParkItem.getParkId()));
|
carPassGatherService.save(carPassGather);
|
||||||
// //入场新增数据
|
} else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
|
||||||
// if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
carPassGatherService.deleteByLicense(license);
|
||||||
// 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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,7 +193,7 @@ public class CarMessageListener {
|
|||||||
* @param topic
|
* @param topic
|
||||||
* @param message
|
* @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 {
|
public void ivs_result_offline(String topic, Map<String, String> topicVars, byte[] message) throws Exception {
|
||||||
String sn = topicVars.get("sn");
|
String sn = topicVars.get("sn");
|
||||||
log.info("接收到车辆离线识别消息 -> Topic: {}", topic);
|
log.info("接收到车辆离线识别消息 -> Topic: {}", topic);
|
||||||
@@ -271,7 +248,7 @@ public class CarMessageListener {
|
|||||||
record.setTriggerType(plateResult.getString("triggerType"));
|
record.setTriggerType(plateResult.getString("triggerType"));
|
||||||
record.setType(carBrand.getString("type"));
|
record.setType(carBrand.getString("type"));
|
||||||
carPassRecordService.save(record);
|
carPassRecordService.save(record);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IO输出事件监听
|
* IO输出事件监听
|
||||||
@@ -297,23 +274,9 @@ public class CarMessageListener {
|
|||||||
public void set_io_lock_status(String topic, byte[] message) {
|
public void set_io_lock_status(String topic, byte[] message) {
|
||||||
log.info("IO锁定事件监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
log.info("IO锁定事件监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
||||||
String data = new String(message, StandardCharsets.UTF_8);
|
String data = new String(message, StandardCharsets.UTF_8);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
log.info("IO锁定事件监听:{}", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发布获取IO锁定状态监听
|
|
||||||
*
|
|
||||||
* @param topic
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
@MqttServerFunction("device/${sn}/message/down/get_io_lock_status/reply")
|
|
||||||
public void get_io_lock_status(String topic, byte[] message) {
|
|
||||||
log.info("发布获取IO锁定状态监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
|
||||||
String data = new String(message, StandardCharsets.UTF_8);
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订阅离线数据数量
|
* 订阅离线数据数量
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -16,10 +16,13 @@
|
|||||||
|
|
||||||
package org.dromara.mica.mqtt.server.listener;
|
package org.dromara.mica.mqtt.server.listener;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.mica.mqtt.core.server.event.IMqttConnectStatusListener;
|
import org.dromara.mica.mqtt.core.server.event.IMqttConnectStatusListener;
|
||||||
import org.dromara.mica.mqtt.server.constant.CacheConstants;
|
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.enums.FlagEnums;
|
||||||
|
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
|
||||||
import org.dromara.mica.mqtt.server.redis.RedisService;
|
import org.dromara.mica.mqtt.server.redis.RedisService;
|
||||||
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -27,6 +30,8 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.tio.core.ChannelContext;
|
import org.tio.core.ChannelContext;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mqtt 连接状态
|
* mqtt 连接状态
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ import java.util.List;
|
|||||||
@Mapper
|
@Mapper
|
||||||
public interface CarParkItemMapper extends BaseMapper<CarParkItem> {
|
public interface CarParkItemMapper extends BaseMapper<CarParkItem> {
|
||||||
|
|
||||||
@Select("SELECT p.id,p.park_id parkId,k.auto_lock autoLock,k.cars_num carsNum,p.way,p.equipment_id equipmentId,p.area FROM car_park_item p left join sys_equipment e on p.equipment_id = e.id LEFT JOIN car_park k on p.park_id = k.id where e.sequence = #{sn} and e.product_id = 4 limit 1")
|
@Select("SELECT p.id,p.park_id parkId,p.way,p.equipment_id equipmentId,p.area FROM car_park_item p left join sys_equipment e on p.equipment_id = e.id where e.sequence = #{sn} and e.product_id = 4 limit 1")
|
||||||
CarParkItem selectBySn(@Param("sn") String sn);
|
CarParkItem selectBySn(@Param("sn") String sn);
|
||||||
|
|
||||||
@Select("SELECT e.sequence FROM car_park_item p left join sys_equipment e on p.equipment_id = e.id where p.park_id = #{parkId} and p.way = 0 and e.product_id = 4")
|
|
||||||
List<String> selectSnByParkId(@Param("parkId") String parkId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package org.dromara.mica.mqtt.server.mapper;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
|
import org.dromara.mica.mqtt.server.entity.CarInfo;
|
||||||
|
import org.dromara.mica.mqtt.server.entity.Equipment;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EquipmentMapper extends BaseMapper<IoLockEquipment> {
|
public interface EquipmentMapper extends BaseMapper<Equipment> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
package org.dromara.mica.mqtt.server.pojo;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class DeviceIOLockRequestPO {
|
|
||||||
/**
|
|
||||||
* 消息ID,用于关联具体消息
|
|
||||||
*/
|
|
||||||
@JsonProperty("id")
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备序列号
|
|
||||||
*/
|
|
||||||
@JsonProperty("sn")
|
|
||||||
private String sn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息名称
|
|
||||||
*/
|
|
||||||
@JsonProperty("name")
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息版本,目前都填1.0
|
|
||||||
*/
|
|
||||||
@JsonProperty("version")
|
|
||||||
private String version = "1.0";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间戳
|
|
||||||
*/
|
|
||||||
@JsonProperty("timestamp")
|
|
||||||
private long timestamp = System.currentTimeMillis() / 1000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息负载
|
|
||||||
*/
|
|
||||||
@JsonProperty("payload")
|
|
||||||
private JSONObject payload;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
package org.dromara.mica.mqtt.server.pojo;
|
|
||||||
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
public class OpenFloodgatePO {
|
|
||||||
/**
|
|
||||||
* 消息ID,用于关联具体消息
|
|
||||||
*/
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设备序列号
|
|
||||||
*/
|
|
||||||
private String sn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息名称(固定为gpio_out)
|
|
||||||
*/
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息版本(目前都填1.0)
|
|
||||||
*/
|
|
||||||
private String version = "1.0";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 时间戳
|
|
||||||
*/
|
|
||||||
private Long timestamp = System.currentTimeMillis() / 1000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 消息负载
|
|
||||||
*/
|
|
||||||
private JSONObject payload;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,11 +3,7 @@ package org.dromara.mica.mqtt.server.service;
|
|||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.dromara.mica.mqtt.server.entity.CarParkItem;
|
import org.dromara.mica.mqtt.server.entity.CarParkItem;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ICarParkItemService extends IService<CarParkItem> {
|
public interface ICarParkItemService extends IService<CarParkItem> {
|
||||||
|
|
||||||
CarParkItem selectBySn(String sn);
|
CarParkItem selectBySn(String sn);
|
||||||
|
|
||||||
List<String> selectSnByParkId(String parkId);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package org.dromara.mica.mqtt.server.service;
|
package org.dromara.mica.mqtt.server.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
|
import org.dromara.mica.mqtt.server.entity.Equipment;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IEquipmentService extends IService<IoLockEquipment> {
|
public interface IEquipmentService extends IService<Equipment> {
|
||||||
|
|
||||||
IoLockEquipment selectEquipmentBySn(String sn);
|
Equipment selectEquipmentBySn(String sn);
|
||||||
|
|
||||||
List<IoLockEquipment> selectAllSnFlag();
|
List<Equipment> selectAllSnFlag();
|
||||||
|
|
||||||
void updateFlag(String sn, String flag);
|
void updateFlag(String sn, String flag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.dromara.mica.mqtt.server.service.impl;
|
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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.dromara.mica.mqtt.server.entity.CarParkItem;
|
import org.dromara.mica.mqtt.server.entity.CarParkItem;
|
||||||
import org.dromara.mica.mqtt.server.mapper.CarParkItemMapper;
|
import org.dromara.mica.mqtt.server.mapper.CarParkItemMapper;
|
||||||
@@ -7,8 +8,6 @@ import org.dromara.mica.mqtt.server.service.ICarParkItemService;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CarParkItemServiceImpl extends ServiceImpl<CarParkItemMapper, CarParkItem> implements ICarParkItemService {
|
public class CarParkItemServiceImpl extends ServiceImpl<CarParkItemMapper, CarParkItem> implements ICarParkItemService {
|
||||||
|
|
||||||
@@ -19,9 +18,4 @@ public class CarParkItemServiceImpl extends ServiceImpl<CarParkItemMapper, CarPa
|
|||||||
public CarParkItem selectBySn(String sn) {
|
public CarParkItem selectBySn(String sn) {
|
||||||
return carParkItemMapper.selectBySn(sn);
|
return carParkItemMapper.selectBySn(sn);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> selectSnByParkId(String parkId) {
|
|
||||||
return carParkItemMapper.selectSnByParkId(parkId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package org.dromara.mica.mqtt.server.service.impl;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
|
import org.dromara.mica.mqtt.server.entity.Equipment;
|
||||||
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
|
import org.dromara.mica.mqtt.server.mapper.EquipmentMapper;
|
||||||
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -11,25 +11,25 @@ import org.springframework.stereotype.Service;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, IoLockEquipment> implements IEquipmentService {
|
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment> implements IEquipmentService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
EquipmentMapper equipmentMapper;
|
EquipmentMapper equipmentMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IoLockEquipment selectEquipmentBySn(String sn) {
|
public Equipment selectEquipmentBySn(String sn) {
|
||||||
return equipmentMapper.selectOne(new QueryWrapper<IoLockEquipment>().eq("sequence", sn).last("limit 1"));
|
return equipmentMapper.selectOne(new QueryWrapper<Equipment>().eq("sequence", sn).eq("product_id", 4L).last("limit 1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IoLockEquipment> selectAllSnFlag() {
|
public List<Equipment> selectAllSnFlag() {
|
||||||
return equipmentMapper.selectList(new QueryWrapper<IoLockEquipment>().select("sequence", "flag"));
|
return equipmentMapper.selectList(new QueryWrapper<Equipment>().eq("product_id", 4L).select("sequence", "flag"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateFlag(String sn, String flag) {
|
public void updateFlag(String sn, String flag) {
|
||||||
IoLockEquipment equipment = new IoLockEquipment();
|
Equipment equipment = new Equipment();
|
||||||
equipment.setFlag(flag);
|
equipment.setFlag(flag);
|
||||||
equipmentMapper.update(equipment, new QueryWrapper<IoLockEquipment>().eq("sequence", sn));
|
equipmentMapper.update(equipment, new QueryWrapper<Equipment>().eq("sequence", sn).eq("product_id", 4L));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
package org.dromara.mica.mqtt.server.service.impl;
|
package org.dromara.mica.mqtt.server.service.impl;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.mica.mqtt.server.pojo.DeviceIOLockRequestPO;
|
|
||||||
import org.dromara.mica.mqtt.server.pojo.OpenFloodgatePO;
|
|
||||||
import org.dromara.mica.mqtt.server.utils.UuidUtil;
|
|
||||||
import org.dromara.mica.mqtt.spring.server.MqttServerTemplate;
|
import org.dromara.mica.mqtt.spring.server.MqttServerTemplate;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wsq
|
* @author wsq
|
||||||
@@ -61,108 +55,4 @@ public class ServerService {
|
|||||||
log.info("发布离线数据数量body:{},result:{}", body, result);
|
log.info("发布离线数据数量body:{},result:{}", body, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean openFloodgate(String sn) {
|
|
||||||
String operUrl = "device/%s/message/down/gpio_out";
|
|
||||||
String topic = String.format(operUrl, sn);
|
|
||||||
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
|
||||||
String uuid = "open_" + UuidUtil.getUuid();
|
|
||||||
openFloodgatePO.setId(uuid);
|
|
||||||
openFloodgatePO.setSn(sn);
|
|
||||||
openFloodgatePO.setName("gpio_out");
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
long timestamp = now.atZone(ZoneId.systemDefault()).toEpochSecond();
|
|
||||||
openFloodgatePO.setTimestamp(timestamp);
|
|
||||||
openFloodgatePO.setPayload(this.buildPayloadOpen());
|
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
|
||||||
log.info("抬杠设备编码:{},result:{},请求体{}", sn,result,openFloodgatePO);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean locked(String sn, Integer status, Integer ioout) {
|
|
||||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
|
||||||
String topic = String.format(operUrl, sn);
|
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
|
||||||
String uuid = "locked_" + UuidUtil.getUuid();
|
|
||||||
deviceIOLockRequestPO.setId(uuid);
|
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status, ioout));
|
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject buildPayloadOpen() {
|
|
||||||
JSONObject body = new JSONObject();
|
|
||||||
body.put("delay", 10000);
|
|
||||||
body.put("io", 0);
|
|
||||||
body.put("value",2);
|
|
||||||
JSONObject payload = new JSONObject();
|
|
||||||
payload.put("type", "gpio_out");
|
|
||||||
payload.put("body", body);
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
private JSONObject buildPayloadLocked(Integer status, Integer ioout) {
|
|
||||||
JSONObject payload = new JSONObject();
|
|
||||||
payload.put("type", "set_io_lock_status");
|
|
||||||
JSONObject body = new JSONObject();
|
|
||||||
//io口,摄像头接线口
|
|
||||||
body.put("ioout", ioout);
|
|
||||||
//0解锁 1高电平锁定(保持常抬) 2低电平锁定(保持常关)
|
|
||||||
body.put("status", status);
|
|
||||||
payload.put("body", body);
|
|
||||||
return payload;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean lockOpen(String sn) {
|
|
||||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
|
||||||
String topic = String.format(operUrl, sn);
|
|
||||||
|
|
||||||
//通道1解锁
|
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
|
||||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
|
||||||
deviceIOLockRequestPO.setId(uuid);
|
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 1));
|
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
//通道0 锁定
|
|
||||||
|
|
||||||
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
|
||||||
po.setId("lockOpen_" + UuidUtil.getUuid());
|
|
||||||
po.setSn(sn);
|
|
||||||
po.setName("set_io_lock_status");
|
|
||||||
po.setPayload(this.buildPayloadLocked(1, 0));
|
|
||||||
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
return (result && result2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean lockClose(String sn) {
|
|
||||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
|
||||||
String topic = String.format(operUrl, sn);
|
|
||||||
|
|
||||||
//通道0解锁
|
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
|
||||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
|
||||||
deviceIOLockRequestPO.setId(uuid);
|
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 0));
|
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
//通道1 锁定
|
|
||||||
|
|
||||||
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
|
||||||
po.setId("lockOpen_" + UuidUtil.getUuid());
|
|
||||||
po.setSn(sn);
|
|
||||||
po.setName("set_io_lock_status");
|
|
||||||
po.setPayload(this.buildPayloadLocked(1, 1));
|
|
||||||
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
return (result && result2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package org.dromara.mica.mqtt.server.task;
|
package org.dromara.mica.mqtt.server.task;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.mica.mqtt.server.constant.CacheConstants;
|
import org.dromara.mica.mqtt.server.constant.CacheConstants;
|
||||||
import org.dromara.mica.mqtt.server.entity.IoLockEquipment;
|
import org.dromara.mica.mqtt.server.entity.Equipment;
|
||||||
import org.dromara.mica.mqtt.server.enums.FlagEnums;
|
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.redis.RedisService;
|
||||||
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
import org.dromara.mica.mqtt.server.service.IEquipmentService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -28,28 +30,32 @@ public class HeartbeatOnLineTask {
|
|||||||
|
|
||||||
@Scheduled(fixedRate = 15 * 1000)
|
@Scheduled(fixedRate = 15 * 1000)
|
||||||
public void run() {
|
public void run() {
|
||||||
log.info("===========心跳检测=============");
|
// 添加异常捕获,防止单个任务异常导致定时任务线程阻塞
|
||||||
//查询车辆摄像头的编码和在线状态
|
try {
|
||||||
List<IoLockEquipment> equipment = equipmentService.selectAllSnFlag();
|
log.info("===========心跳检测=============");
|
||||||
|
//查询车辆摄像头的编码和在线状态
|
||||||
|
List<Equipment> equipment = equipmentService.selectAllSnFlag();
|
||||||
|
|
||||||
for (IoLockEquipment equip : equipment) {
|
for (Equipment equip : equipment) {
|
||||||
//缓存中有该设备心跳key
|
//缓存中有该设备心跳key
|
||||||
if (redisService.hasKey(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence())) {
|
if (redisService.hasKey(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence())) {
|
||||||
String flag = redisService.getCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence());
|
String flag = redisService.getCacheObject(CacheConstants.EQUIPMENT_HEARTBEAT + equip.getSequence());
|
||||||
//有心跳,但是和数据库设备在线状态不一致
|
//有心跳,但是和数据库设备在线状态不一致
|
||||||
if (!StrUtil.equals(flag, equip.getFlag())) {
|
if (!StrUtil.equals(flag, equip.getFlag())) {
|
||||||
log.info("设备:{},flag:{}", equip.getSequence(), flag);
|
log.info("设备:{},flag:{}", equip.getSequence(), flag);
|
||||||
equipmentService.updateFlag(equip.getSequence(), flag);
|
equipmentService.updateFlag(equip.getSequence(), flag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//没有心跳上传,且设备在线,将设备置为离线
|
//没有心跳上传,且设备在线,将设备置为离线
|
||||||
if (StrUtil.equals(FlagEnums.ONLINE.getCode(), equip.getFlag())) {
|
if (StrUtil.equals(FlagEnums.ONLINE.getCode(), equip.getFlag())) {
|
||||||
log.info("设备:{},无心跳离线", equip.getSequence());
|
log.info("设备:{},无心跳离线", equip.getSequence());
|
||||||
equipmentService.updateFlag(equip.getSequence(), FlagEnums.OFFLINE.getCode());
|
equipmentService.updateFlag(equip.getSequence(), FlagEnums.OFFLINE.getCode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
// 捕获所有异常并记录日志,确保定时任务能继续执行
|
||||||
|
log.error("HeartbeatOnLineTask 定时任务执行异常", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class PlatePublishTask {
|
|||||||
/**
|
/**
|
||||||
* 定时查询数据库需要下发的车辆进行下发
|
* 定时查询数据库需要下发的车辆进行下发
|
||||||
*/
|
*/
|
||||||
// @Scheduled(fixedDelay = 8 * 1000)
|
@Scheduled(fixedDelay = 8 * 1000)
|
||||||
public void run() {
|
public void run() {
|
||||||
// 添加异常捕获,防止单个任务异常导致定时任务线程阻塞
|
// 添加异常捕获,防止单个任务异常导致定时任务线程阻塞
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
url: jdbc:mysql://127.0.0.1:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&connectTimeout=5000&socketTimeout=30000
|
url: jdbc:mysql://127.0.0.1:3306/xa_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&connectTimeout=5000&socketTimeout=30000
|
||||||
username: root
|
username: root
|
||||||
password: root
|
password: root
|
||||||
# Druid 连接池配置
|
# Druid 连接池配置
|
||||||
|
|||||||
@@ -1,10 +1,26 @@
|
|||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
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&connectTimeout=5000&socketTimeout=30000
|
||||||
|
# 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&connectTimeout=5000&socketTimeout=30000
|
||||||
|
# username: root
|
||||||
|
# password: JL202509jj
|
||||||
#td
|
#td
|
||||||
url: jdbc:mysql://192.168.251.16:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&connectTimeout=5000&socketTimeout=30000
|
# url: jdbc:mysql://127.0.0.1:3306/td_cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&connectTimeout=5000&socketTimeout=30000
|
||||||
|
# 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&connectTimeout=5000&socketTimeout=30000
|
||||||
|
# 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&connectTimeout=5000&socketTimeout=30000
|
||||||
username: root
|
username: root
|
||||||
password: td@JJ2024
|
password: XjJN2024!
|
||||||
# Druid 连接池配置
|
# Druid 连接池配置
|
||||||
druid:
|
druid:
|
||||||
max-active: 20
|
max-active: 20
|
||||||
@@ -19,10 +35,13 @@ spring:
|
|||||||
min-evictable-idle-time-millis: 300000
|
min-evictable-idle-time-millis: 300000
|
||||||
data:
|
data:
|
||||||
redis:
|
redis:
|
||||||
host: 192.168.251.16
|
#zr
|
||||||
|
# host: 192.168.155.42
|
||||||
|
#xa、jl、td、xj
|
||||||
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
password:
|
password:
|
||||||
database: 2
|
database: 1
|
||||||
# Redis 超时配置,防止连接阻塞
|
# Redis 超时配置,防止连接阻塞
|
||||||
timeout: 5000ms
|
timeout: 5000ms
|
||||||
lettuce:
|
lettuce:
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ spring:
|
|||||||
name: mica-mqtt-server
|
name: mica-mqtt-server
|
||||||
# 环境 dev|test|prod
|
# 环境 dev|test|prod
|
||||||
profiles:
|
profiles:
|
||||||
active: dev
|
# active: dev
|
||||||
# active: prod
|
active: prod
|
||||||
messages:
|
messages:
|
||||||
encoding: UTF-8
|
encoding: UTF-8
|
||||||
basename: i18n/messages
|
basename: i18n/messages
|
||||||
|
|||||||
@@ -71,6 +71,7 @@
|
|||||||
<if test="sn != null "> and se.sequence = #{sn}</if>
|
<if test="sn != null "> and se.sequence = #{sn}</if>
|
||||||
<if test="delFlag != null "> and ci.del_flag = #{delFlag}</if>
|
<if test="delFlag != null "> and ci.del_flag = #{delFlag}</if>
|
||||||
<if test="sync != null "> and cpr.sync = #{sync}</if>
|
<if test="sync != null "> and cpr.sync = #{sync}</if>
|
||||||
|
and se.flag = 0
|
||||||
limit 10
|
limit 10
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user