Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
800fc68cb9 | ||
|
|
d4f20f7a67 | ||
|
|
17eb0c69ff | ||
|
|
985ec252c6 | ||
|
|
7871c2ac70 |
@@ -3,10 +3,7 @@ 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.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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
|
||||||
@@ -52,4 +49,53 @@ 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,4 +47,14 @@ 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,8 +5,6 @@ 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;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ 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;
|
||||||
@@ -30,6 +31,7 @@ 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;
|
||||||
|
|
||||||
@@ -57,6 +59,10 @@ public class CarMessageListener {
|
|||||||
@Autowired
|
@Autowired
|
||||||
ICarPassGatherService carPassGatherService;
|
ICarPassGatherService carPassGatherService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerService service;
|
||||||
|
|
||||||
|
|
||||||
private static String key = "1234567898765432";
|
private static String key = "1234567898765432";
|
||||||
|
|
||||||
//xa、jl、td、xj
|
//xa、jl、td、xj
|
||||||
@@ -117,7 +123,16 @@ 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);
|
||||||
|
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);
|
String data = new String(message, StandardCharsets.UTF_8);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||||
@@ -172,7 +187,7 @@ public class CarMessageListener {
|
|||||||
carPassRecordService.save(record);
|
carPassRecordService.save(record);
|
||||||
|
|
||||||
//保存/删除在场数据
|
//保存/删除在场数据
|
||||||
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license));
|
boolean isExist = carPassGatherService.exists(new QueryWrapper<CarPassGather>().eq("license", license).eq("park_id", carParkItem.getParkId()));
|
||||||
//入场新增数据
|
//入场新增数据
|
||||||
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
if (StrUtil.equals(carParkItem.getWay(), "0") && !isExist) {
|
||||||
CarPassGather carPassGather = new CarPassGather();
|
CarPassGather carPassGather = new CarPassGather();
|
||||||
@@ -182,8 +197,23 @@ public class CarMessageListener {
|
|||||||
carPassGather.setJoinTime(record.getPassTime());
|
carPassGather.setJoinTime(record.getPassTime());
|
||||||
carPassGather.setSn(sn);
|
carPassGather.setSn(sn);
|
||||||
carPassGatherService.save(carPassGather);
|
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) {//出场删除数据
|
} else if (StrUtil.equals(carParkItem.getWay(), "1") && isExist) {//出场删除数据
|
||||||
carPassGatherService.deleteByLicense(license);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,9 +304,23 @@ 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);
|
||||||
log.info("IO锁定事件监听:{}", data);
|
JSONObject jsonObject = JSONObject.parseObject(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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 订阅离线数据数量
|
* 订阅离线数据数量
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ 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,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")
|
@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")
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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,7 +3,11 @@ 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,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -8,6 +7,8 @@ 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 {
|
||||||
|
|
||||||
@@ -18,4 +19,9 @@ 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
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
|
||||||
@@ -55,4 +61,108 @@ 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,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/xa_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
|
username: root
|
||||||
password: root
|
password: root
|
||||||
# Druid 连接池配置
|
# Druid 连接池配置
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ spring:
|
|||||||
redis:
|
redis:
|
||||||
#zr
|
#zr
|
||||||
# host: 192.168.155.42
|
# host: 192.168.155.42
|
||||||
#xa、jl、td、xj
|
# xa、jl、td、xj
|
||||||
host: 127.0.0.1
|
host: 127.0.0.1
|
||||||
port: 6379
|
port: 6379
|
||||||
password:
|
password:
|
||||||
|
|||||||
Reference in New Issue
Block a user