master
guochaojie 3 months ago
parent 915d0ee2fe
commit 11585da7f5

@ -615,9 +615,8 @@ public class DeviceController {
if (null == device1) { if (null == device1) {
return CommonResult.error(400, "设备编码编码不正确,命令不能下发!"); return CommonResult.error(400, "设备编码编码不正确,命令不能下发!");
} }
Object value = redisTool.getValue("online_" + deviceCode); boolean exist = redisTool.existsKey("online_" + deviceCode);
long expire = redisTool.getKeyExpire("online_" + deviceCode, TimeUnit.SECONDS); if (!exist) {
if (value == null || expire <= 0) {
return CommonResult.error(400, "设备不在线,命令不能下发!"); return CommonResult.error(400, "设备不在线,命令不能下发!");
} }
// Object value = redisTool.getValue(deviceCode); // Object value = redisTool.getValue(deviceCode);
@ -813,7 +812,7 @@ public class DeviceController {
// //
// } // }
String key = "weight_" + weight.getDeviceCode() + "_" + weight.getBucketCode(); String key = "weight_" + weight.getDeviceCode() + "_" + weight.getBucketCode();
redisTool.setValue(key, JSONUtil.toJsonStr(weight), 1000 * 60L);//一分钟过期 redisTool.setValue(key, JSONUtil.toJsonStr(weight), 1000L * 60 * 3);//3分钟过期
return CommonResult.success("success"); return CommonResult.success("success");
} }
@ -821,9 +820,8 @@ public class DeviceController {
@PostMapping("/getWeight") @PostMapping("/getWeight")
public CommonResult<WeightVO> getWeight(@RequestBody DeviceBucketVO deviceBucketVO) { public CommonResult<WeightVO> getWeight(@RequestBody DeviceBucketVO deviceBucketVO) {
String key = "weight_" + deviceBucketVO.getDeviceCode() + "_" + deviceBucketVO.getBucketCode(); String key = "weight_" + deviceBucketVO.getDeviceCode() + "_" + deviceBucketVO.getBucketCode();
long expire = redisTool.getKeyExpire(key, TimeUnit.SECONDS);
boolean exist = redisTool.existsKey(key); boolean exist = redisTool.existsKey(key);
if (!exist || expire <= 0) { if (!exist) {
return CommonResult.error(400, "获取实时重量失败"); return CommonResult.error(400, "获取实时重量失败");
} }
Object value = redisTool.getValue(key); Object value = redisTool.getValue(key);

@ -14,7 +14,7 @@ public enum CMDEnum {
apply("apply", "申请控制"), apply("apply", "申请控制"),
exit("exit", "结束控制"), exit("exit", "结束控制"),
weight("weight", "获取重量"), weight("weight", "获取重量"),
change("change", "配置更新"), refresh("refresh", "配置更新"),
reboot("reboot", "重启设备"), reboot("reboot", "重启设备"),
restart("restart", "重启应用"), restart("restart", "重启应用"),
update("update", "更新应用"), update("update", "更新应用"),

@ -9,7 +9,6 @@ import java.math.BigDecimal;
@Data @Data
@ApiModel("实时重量") @ApiModel("实时重量")
public class WeightVO { public class WeightVO {
@ApiModelProperty(value = "设备编码", required = true) @ApiModelProperty(value = "设备编码", required = true)
private String deviceCode; private String deviceCode;
@ApiModelProperty(value = "桶编码", required = true) @ApiModelProperty(value = "桶编码", required = true)

Loading…
Cancel
Save