|
@@ -3,11 +3,8 @@ package com.xy.service;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.xy.annotate.Runners;
|
|
|
-import com.xy.annotate.Timer;
|
|
|
import com.xy.collections.list.JArrayList;
|
|
|
import com.xy.collections.list.JList;
|
|
|
import com.xy.collections.map.JHashMap;
|
|
@@ -15,7 +12,6 @@ import com.xy.collections.map.JMap;
|
|
|
import com.xy.dto.*;
|
|
|
import com.xy.entity.DeviceInfo;
|
|
|
import com.xy.entity.MqttCommand;
|
|
|
-import com.xy.error.CommRuntimeException;
|
|
|
import com.xy.mapper.MqttCommandMapper;
|
|
|
import com.xy.service.factory.cmd.CmdService;
|
|
|
import com.xy.service.factory.device.DeviceFactory;
|
|
@@ -51,19 +47,11 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
|
|
|
|
|
|
private String keyStr = "mqtt:cmd:result:%d";
|
|
|
|
|
|
- private boolean snInit;
|
|
|
-
|
|
|
public long getSn() {
|
|
|
- if (!snInit) {
|
|
|
- throw new CommRuntimeException("sn号未初始化");
|
|
|
- }
|
|
|
return redisService.atomicIncrease(CommConsts.CMD_ATOM_SN);
|
|
|
}
|
|
|
|
|
|
public long getWkSn() {
|
|
|
- if (!snInit) {
|
|
|
- throw new CommRuntimeException("sn号未初始化");
|
|
|
- }
|
|
|
return redisService.atomicIncrease(CommConsts.CMD_ATOM_WK_SN);
|
|
|
}
|
|
|
|
|
@@ -230,22 +218,4 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
|
|
|
save(mqttCommand);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- @Timer
|
|
|
- @Runners
|
|
|
- @PostMapping("sysnAtoms")
|
|
|
- @ApiOperation("同步sn号redis原子变量")
|
|
|
- public void sysnAtoms() {
|
|
|
- //todo 集群有问题,暂不处理
|
|
|
- String sn = LambdaUtils.getProperty(MqttCommand::getSn);
|
|
|
- QueryWrapper<MqttCommand> wrapper = new QueryWrapper<MqttCommand>()
|
|
|
- .select(String.format("max(%s) as %s", sn, sn));
|
|
|
- MqttCommand mqttCommand = getOne(wrapper);
|
|
|
- if (mqttCommand != null) {
|
|
|
- redisService.setAtomic(CommConsts.CMD_ATOM_SN, mqttCommand.getSn() + 1);
|
|
|
- MqttCommand byId = getById(mqttCommand.getSn());
|
|
|
- redisService.setAtomic(CommConsts.CMD_ATOM_WK_SN, byId.getWkSn() + 1);
|
|
|
- }
|
|
|
- snInit = true;
|
|
|
- }
|
|
|
}
|