|
@@ -5,6 +5,7 @@ import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.github.yitter.idgen.YitIdHelper;
|
|
import com.github.yitter.idgen.YitIdHelper;
|
|
|
|
+import com.xy.annotate.Timer;
|
|
import com.xy.collections.map.JConcurrentHashMap;
|
|
import com.xy.collections.map.JConcurrentHashMap;
|
|
import com.xy.collections.map.JMap;
|
|
import com.xy.collections.map.JMap;
|
|
import com.xy.config.ThreadPoolConfig;
|
|
import com.xy.config.ThreadPoolConfig;
|
|
@@ -15,6 +16,7 @@ import com.xy.entity.MqttCommand;
|
|
import com.xy.mapper.MqttCommandMapper;
|
|
import com.xy.mapper.MqttCommandMapper;
|
|
import com.xy.producer.MqttProducer;
|
|
import com.xy.producer.MqttProducer;
|
|
import com.xy.utils.*;
|
|
import com.xy.utils.*;
|
|
|
|
+import com.xy.utils.consts.CommConsts;
|
|
import com.xy.utils.enums.MqttCommandStatusEnum;
|
|
import com.xy.utils.enums.MqttCommandStatusEnum;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
@@ -40,31 +42,32 @@ public class MqttServiceImpl implements MqttService {
|
|
|
|
|
|
private MqttCommandMapper mqttCommandMapper;
|
|
private MqttCommandMapper mqttCommandMapper;
|
|
|
|
|
|
|
|
+ @Timer
|
|
@Override
|
|
@Override
|
|
@ApiOperation("指令发布")
|
|
@ApiOperation("指令发布")
|
|
public Map<String, Boolean> sendMqtt(List<MqttDto> mqttDtos) {
|
|
public Map<String, Boolean> sendMqtt(List<MqttDto> mqttDtos) {
|
|
|
|
+ String time = DataTime.getSring();
|
|
JMap<String, Boolean> map = new JConcurrentHashMap<>(mqttDtos.size());
|
|
JMap<String, Boolean> map = new JConcurrentHashMap<>(mqttDtos.size());
|
|
ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(ThreadPoolConfig.SEND_MQTT_POLL, mqttDtos.size());
|
|
ThreadPoolUtils.Execute execute = ThreadPoolUtils.excPoll(ThreadPoolConfig.SEND_MQTT_POLL, mqttDtos.size());
|
|
mqttDtos.forEach(mqttDto -> execute.execute(() -> {
|
|
mqttDtos.forEach(mqttDto -> execute.execute(() -> {
|
|
//给予默认值
|
|
//给予默认值
|
|
PaterDto pater = mqttDto.getPater()
|
|
PaterDto pater = mqttDto.getPater()
|
|
.setSn(String.valueOf(YitIdHelper.nextId()))
|
|
.setSn(String.valueOf(YitIdHelper.nextId()))
|
|
- .setTime(DataTime.getSring());
|
|
|
|
|
|
+ .setTime(time)
|
|
|
|
+ .setDeviceId(mqttDto.getDeviceId());
|
|
//延迟发布处理
|
|
//延迟发布处理
|
|
String delayTime = mqttDto.getDelayTime();
|
|
String delayTime = mqttDto.getDelayTime();
|
|
- String topic = mqttDto.getTopic();
|
|
|
|
|
|
+ String topic = mqttDto.getDeviceId().toString(); //+ CommConsts.DEVICE_MQTT_TOPIC_SUFFIX;
|
|
if (!StringUtils.isEmpty(delayTime)) {
|
|
if (!StringUtils.isEmpty(delayTime)) {
|
|
//消息消费时间 - 发布时间的差值 = 距今被消费的秒数
|
|
//消息消费时间 - 发布时间的差值 = 距今被消费的秒数
|
|
long m = DataTime.diff(DataTime.toLocal(pater.getTime()), DataTime.toLocal(delayTime), "s");
|
|
long m = DataTime.diff(DataTime.toLocal(pater.getTime()), DataTime.toLocal(delayTime), "s");
|
|
- topic = String.format("$delayed/%d/%s", m, mqttDto.getTopic());
|
|
|
|
|
|
+ topic = String.format("$delayed/%d/%s", m, topic);
|
|
mqttDto.setTimeout(mqttDto.getTimeout() + (int) m);
|
|
mqttDto.setTimeout(mqttDto.getTimeout() + (int) m);
|
|
}
|
|
}
|
|
- //处理消息过期时间
|
|
|
|
- pater.setTimeout(DataTime.getStringAround(0, 0, 0, 0, 0, mqttDto.getTimeout()));
|
|
|
|
|
|
+ //消息过期时间
|
|
|
|
+ pater.setTimeout(mqttDto.getTimeout());
|
|
//翻译枚举
|
|
//翻译枚举
|
|
- JSONObject value = JSONUtil.parseObj(pater)
|
|
|
|
- .set(LambdaUtils.getProperty(PaterDto::getType1), pater.getType1().getKey())
|
|
|
|
- .set(LambdaUtils.getProperty(PaterDto::getType2), pater.getType2().getKey());
|
|
|
|
|
|
+ JSONObject value = JSONUtil.parseObj(pater);
|
|
String wkSn = pater.getWkSn();
|
|
String wkSn = pater.getWkSn();
|
|
try {
|
|
try {
|
|
//发送消息
|
|
//发送消息
|
|
@@ -133,8 +136,6 @@ public class MqttServiceImpl implements MqttService {
|
|
PaterDto pater = mqttDto.getPater();
|
|
PaterDto pater = mqttDto.getPater();
|
|
MqttCommand mqttCommand = Beans.copy(Beans.copy(MqttCommand.class, mqttDto), pater)
|
|
MqttCommand mqttCommand = Beans.copy(Beans.copy(MqttCommand.class, mqttDto), pater)
|
|
.setId(pater.getSn())
|
|
.setId(pater.getSn())
|
|
- .setType1(pater.getType1().getKey())
|
|
|
|
- .setType2(pater.getType2().getKey())
|
|
|
|
.setStatus(Integer.parseInt(status.getKey()))
|
|
.setStatus(Integer.parseInt(status.getKey()))
|
|
.setValue(value.toString())
|
|
.setValue(value.toString())
|
|
.setSendTime(pater.getTime())
|
|
.setSendTime(pater.getTime())
|