|
|
@ -526,6 +526,8 @@ public class DeviceController {
|
|
|
|
UserDTO user = UserContext.getUser();
|
|
|
|
UserDTO user = UserContext.getUser();
|
|
|
|
String deviceCode = cmd.getDeviceCode();
|
|
|
|
String deviceCode = cmd.getDeviceCode();
|
|
|
|
Object value = redisTool.getValue(deviceCode);
|
|
|
|
Object value = redisTool.getValue(deviceCode);
|
|
|
|
|
|
|
|
Long expire = redisTool.getKeyExpire(deviceCode, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
log.info("@@@@@ 过期时间:{}", expire);
|
|
|
|
if (null == value) return CommonResult.error(400, "设备不在线");
|
|
|
|
if (null == value) return CommonResult.error(400, "设备不在线");
|
|
|
|
DeviceStatus status = JSONUtil.toBean(value.toString(), DeviceStatus.class);
|
|
|
|
DeviceStatus status = JSONUtil.toBean(value.toString(), DeviceStatus.class);
|
|
|
|
// 判断设备是否在线
|
|
|
|
// 判断设备是否在线
|
|
|
@ -542,14 +544,14 @@ public class DeviceController {
|
|
|
|
if (null != cmd.getData() && StrUtil.isNotEmpty(cmd.getData().toString())) {
|
|
|
|
if (null != cmd.getData() && StrUtil.isNotEmpty(cmd.getData().toString())) {
|
|
|
|
event.setBucketCode(cmd.getData().toString());//桶编码
|
|
|
|
event.setBucketCode(cmd.getData().toString());//桶编码
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RecycleDevice device = deviceService.getByDeviceCode(deviceCode);
|
|
|
|
event.setEventType(deviceCode);
|
|
|
|
event.setEventType(cmd.getCmd().getValue());
|
|
|
|
event.setEventDesc("设备命令下发");
|
|
|
|
event.setEventDesc("设备命令下发");
|
|
|
|
event.setEventTime(new Date());
|
|
|
|
event.setEventTime(new Date());
|
|
|
|
event.setIsLocal("0");//远程调用
|
|
|
|
event.setIsLocal("0");//远程调用
|
|
|
|
event.setCreateUserId(user.getId());
|
|
|
|
event.setCreateUserId(null != user ? user.getId() : null);
|
|
|
|
event.setCreateTime(new Date());
|
|
|
|
event.setCreateTime(new Date());
|
|
|
|
event.setCompanyId(user.getCompanyId());
|
|
|
|
event.setCompanyId(device.getBeLongCompanyId());
|
|
|
|
eventService.save(event);
|
|
|
|
eventService.save(event);
|
|
|
|
|
|
|
|
|
|
|
|
return CommonResult.success("指令下发成功");
|
|
|
|
return CommonResult.success("指令下发成功");
|
|
|
@ -582,8 +584,10 @@ public class DeviceController {
|
|
|
|
public CommonResult<String> getStatus(@RequestBody DeviceVO deviceVO) {
|
|
|
|
public CommonResult<String> getStatus(@RequestBody DeviceVO deviceVO) {
|
|
|
|
Object value = redisTool.getValue(deviceVO.getDeviceCode());
|
|
|
|
Object value = redisTool.getValue(deviceVO.getDeviceCode());
|
|
|
|
if (value == null) return CommonResult.error(400, "获取失败,设备不在线!");
|
|
|
|
if (value == null) return CommonResult.error(400, "获取失败,设备不在线!");
|
|
|
|
|
|
|
|
Long expire = redisTool.getKeyExpire(deviceVO.getDeviceCode(), TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
log.info("@@@@@ 过期时间:{}", expire);
|
|
|
|
DeviceStatus status = JSONUtil.toBean(value.toString(), DeviceStatus.class);
|
|
|
|
DeviceStatus status = JSONUtil.toBean(value.toString(), DeviceStatus.class);
|
|
|
|
if (status.isOnline()) return CommonResult.error(400, "获取失败,设备不在线!");
|
|
|
|
if (!status.isOnline()) return CommonResult.error(400, "获取失败,设备不在线!");
|
|
|
|
CommandVO command = new CommandVO();
|
|
|
|
CommandVO command = new CommandVO();
|
|
|
|
command.setCmd(CMDEnum.status);
|
|
|
|
command.setCmd(CMDEnum.status);
|
|
|
|
command.setDeviceCode(deviceVO.getDeviceCode());
|
|
|
|
command.setDeviceCode(deviceVO.getDeviceCode());
|
|
|
@ -600,7 +604,7 @@ public class DeviceController {
|
|
|
|
public CommonResult<String> receiveStatus(@RequestBody DeviceStatus des, HttpServletRequest request) {
|
|
|
|
public CommonResult<String> receiveStatus(@RequestBody DeviceStatus des, HttpServletRequest request) {
|
|
|
|
String deviceCode = des.getDeviceCode();
|
|
|
|
String deviceCode = des.getDeviceCode();
|
|
|
|
String host = request.getRemoteHost();
|
|
|
|
String host = request.getRemoteHost();
|
|
|
|
des.setIp(host);//ip
|
|
|
|
// des.setIp(host);//ip
|
|
|
|
des.setOnline(true);//在线
|
|
|
|
des.setOnline(true);//在线
|
|
|
|
log.info("设备编码:{},状态上报:{},host:{}", deviceCode, JSONUtil.toJsonStr(des), host);
|
|
|
|
log.info("设备编码:{},状态上报:{},host:{}", deviceCode, JSONUtil.toJsonStr(des), host);
|
|
|
|
Object value = redisTool.getValue(deviceCode);
|
|
|
|
Object value = redisTool.getValue(deviceCode);
|
|
|
@ -642,7 +646,7 @@ public class DeviceController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
redisTool.setValue(deviceCode, JSONUtil.toJsonStr(des), 1000 * 60 * 60L);
|
|
|
|
redisTool.setValue(deviceCode, JSONUtil.toJsonStr(des), 1000 * 60 * 5L);//5分钟
|
|
|
|
CommonResult<String> success = CommonResult.success(deviceCode);
|
|
|
|
CommonResult<String> success = CommonResult.success(deviceCode);
|
|
|
|
success.setMsg("success");
|
|
|
|
success.setMsg("success");
|
|
|
|
return success;
|
|
|
|
return success;
|
|
|
@ -688,6 +692,7 @@ public class DeviceController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("更换垃圾袋")
|
|
|
|
@PostMapping("/changeBag")
|
|
|
|
@PostMapping("/changeBag")
|
|
|
|
public CommonResult<String> changeBag(@RequestBody BagCodeReqVO bag) {
|
|
|
|
public CommonResult<String> changeBag(@RequestBody BagCodeReqVO bag) {
|
|
|
|
boolean b = bucketService.setBagNo(bag);
|
|
|
|
boolean b = bucketService.setBagNo(bag);
|
|
|
@ -695,6 +700,7 @@ public class DeviceController {
|
|
|
|
else return CommonResult.error(400, "error");
|
|
|
|
else return CommonResult.error(400, "error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("校验垃圾袋")
|
|
|
|
@PostMapping("/checkBag")
|
|
|
|
@PostMapping("/checkBag")
|
|
|
|
public CommonResult<String> checkBag(@RequestBody BagCodeReqVO bag) {
|
|
|
|
public CommonResult<String> checkBag(@RequestBody BagCodeReqVO bag) {
|
|
|
|
RecycleBucket bucket = bucketService.getByBag(bag);
|
|
|
|
RecycleBucket bucket = bucketService.getByBag(bag);
|
|
|
|