|
@@ -37,7 +37,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.Map;
|
|
|
|
|
|
|
|
import static com.xy.utils.PlusBeans.*;
|
|
import static com.xy.utils.PlusBeans.*;
|
|
|
|
|
|
@@ -53,8 +52,6 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
|
|
|
|
|
|
private final DeviceInfoServiceImpl deviceInfoService;
|
|
private final DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
|
|
- private String keyStr = "mqtt:cmd:result:%d";
|
|
|
|
-
|
|
|
|
private boolean snInit;
|
|
private boolean snInit;
|
|
|
|
|
|
public long getSn() {
|
|
public long getSn() {
|
|
@@ -144,27 +141,12 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
|
|
if (!Emptys.check(mqttCommand)) {
|
|
if (!Emptys.check(mqttCommand)) {
|
|
return R.fail("数据不存在");
|
|
return R.fail("数据不存在");
|
|
}
|
|
}
|
|
- //写入mysql
|
|
|
|
|
|
+ JSONObject result = ackMqttDto.getResult();
|
|
mqttCommand.setStatus(Integer.valueOf(ackMqttDto.getStatusEnum().getKey()))
|
|
mqttCommand.setStatus(Integer.valueOf(ackMqttDto.getStatusEnum().getKey()))
|
|
|
|
+ .setResult(result != null ? result.toString() : null)
|
|
.setBackClientTime(DataTime.toString(ackMqttDto.getBackClientTime()))
|
|
.setBackClientTime(DataTime.toString(ackMqttDto.getBackClientTime()))
|
|
.setBackServerTime(DataTime.getSring());
|
|
.setBackServerTime(DataTime.getSring());
|
|
updateById(mqttCommand);
|
|
updateById(mqttCommand);
|
|
- //写入redis
|
|
|
|
- String result = ackMqttDto.getResult().toString();
|
|
|
|
- if (Emptys.check(ackMqttDto.getResult())) {
|
|
|
|
- String key = String.format(keyStr, ackMqttDto.getSn());
|
|
|
|
- String backClientTime = DataTime.toString(ackMqttDto.getBackClientTime());
|
|
|
|
- Map<String, String> map = redisService.getMap(key);
|
|
|
|
- if (Emptys.check(map)) {
|
|
|
|
- String time = map.get("time");
|
|
|
|
- if (DataTime.stringContrast(time, backClientTime) >= 0) {
|
|
|
|
- return R.ok();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- JMap<String, String> jmap = new JHashMap<String, String>().set("time", backClientTime).set("result", result);
|
|
|
|
- redisService.setMap(key, jmap);
|
|
|
|
- redisService.timeout(key, 300);
|
|
|
|
- }
|
|
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -176,16 +158,10 @@ public class MqttServiceImpl extends ServiceImpl<MqttCommandMapper, MqttCommand>
|
|
|
|
|
|
@PostMapping("snByCmdAndResult")
|
|
@PostMapping("snByCmdAndResult")
|
|
@ApiOperation("sn查询指令和结果数据")
|
|
@ApiOperation("sn查询指令和结果数据")
|
|
- public R<MqttDto.Vo3> snByCmdAndResult(@RequestBody MqttDto.SnByCmdAndResult snByCmdAndResult) {
|
|
|
|
|
|
+ public R<MqttDto.Vo2> snByCmdAndResult(@RequestBody MqttDto.SnByCmdAndResult snByCmdAndResult) {
|
|
MqttCommand mqttCommand = getById(snByCmdAndResult.getSn());
|
|
MqttCommand mqttCommand = getById(snByCmdAndResult.getSn());
|
|
- String key = String.format(keyStr, snByCmdAndResult.getSn());
|
|
|
|
- Map<String, String> map = redisService.getMap(key);
|
|
|
|
- MqttDto.Vo3 vo3 = copy(MqttDto.Vo3.class, mqttCommand);
|
|
|
|
- if (Emptys.check(map)) {
|
|
|
|
- String result = map.get("result");
|
|
|
|
- vo3.setResult(JSONUtil.parseObj(result));
|
|
|
|
- }
|
|
|
|
- return R.ok(vo3);
|
|
|
|
|
|
+ MqttDto.Vo2 vo2 = copy(MqttDto.Vo2.class, mqttCommand);
|
|
|
|
+ return R.ok(vo2);
|
|
}
|
|
}
|
|
|
|
|
|
@PostMapping("page")
|
|
@PostMapping("page")
|