From b80b64f9c76c2358b339e6217070fbe87734e4be Mon Sep 17 00:00:00 2001
From: 18650502300 <18650502300@163.com>
Date: Thu, 20 Feb 2025 15:07:27 +0800
Subject: [PATCH] 111
---
.../web/controller/app/AppController.java | 14 +++++++++
.../app/AppDeviceAdminController.java | 15 +++++++++-
.../service/impl/CommandLogServiceImpl.java | 10 +++----
.../com/ruoyi/ss/device/domain/Device.java | 3 ++
.../ruoyi/ss/device/mapper/DeviceMapper.xml | 4 +++
.../ss/device/service/DeviceService.java | 5 ++++
.../service/impl/DeviceServiceImpl.java | 14 +++++++++
.../store/service/impl/StoreServiceImpl.java | 3 +-
.../system/iot/domain/IotDeviceInfo.java | 2 ++
.../ruoyi/system/iot/service/IotService.java | 9 +++---
.../iot/service/impl/IotServiceImpl.java | 29 +++++++++++++++++--
11 files changed, 95 insertions(+), 13 deletions(-)
diff --git a/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java
index 6f3e2d9..76d2a15 100644
--- a/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java
+++ b/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java
@@ -14,6 +14,7 @@ import com.ruoyi.common.core.domain.model.LoginBody;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServiceUtil;
+import com.ruoyi.common.utils.onenet.Token;
import com.ruoyi.framework.web.service.SysLoginService;
import com.ruoyi.ss.article.service.IArticleService;
import com.ruoyi.ss.articleClassify.service.IArticleClassifyService;
@@ -45,6 +46,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
+import java.io.UnsupportedEncodingException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
import java.util.List;
/**
@@ -294,4 +298,14 @@ public class AppController extends BaseController
}
}
+ /**
+ * 获取token
+ */
+ @GetMapping("/getToken")
+ public AjaxResult getToken()
+ {
+ return success(Token.getToken());
+ }
+
+
}
diff --git a/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppDeviceAdminController.java b/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppDeviceAdminController.java
index 16019fd..99d8c59 100644
--- a/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppDeviceAdminController.java
+++ b/share-space-admin/src/main/java/com/ruoyi/web/controller/app/AppDeviceAdminController.java
@@ -88,7 +88,20 @@ public class AppDeviceAdminController extends BaseController {
} else {
return error("请输入SN码");
}
- return toAjax(deviceService.reboot(device, "小程序管理员重启设备"));
+ return toAjax(deviceService.reboot(device, "小程序控制台重启设备"));
+ }
+
+ @ApiOperation("管理员开门")
+ @DeviceAdminRequired
+ @PutMapping("/openDoor")
+ public AjaxResult openDoor(@RequestParam String sn) {
+ DeviceVO device = null;
+ if (StringUtils.hasText(sn)) {
+ device = deviceService.selectBySn(sn);
+ } else {
+ return error("请输入SN码");
+ }
+ return toAjax(deviceService.openDoor(device, "小程序控制台开门"));
}
}
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java
index 93d716b..05429d3 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java
+++ b/share-space-system/src/main/java/com/ruoyi/ss/commandLog/service/impl/CommandLogServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.ss.commandLog.service.impl;
+import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.constant.CacheConstants;
@@ -126,11 +127,10 @@ public class CommandLogServiceImpl implements ICommandLogService
etCommandLog.setSn(deviceService.selectSnByMac(mac));
etCommandLog.setResult(result);
etCommandLog.setCreateTime(DateUtils.getNowDate());
- JSONObject paramsObj = JSON.parseObject(result);
- String code = paramsObj.getString("code");
- etCommandLog.setCallStatus(code);
- etCommandLog.setUserId(user.getUserId());
- etCommandLog.setUserName(user.getUsername());
+ if(ObjectUtil.isNotEmpty(user)){
+ etCommandLog.setUserId(user.getUserId());
+ etCommandLog.setUserName(user.getUsername());
+ }
etCommandLog.setReason(reason);
int i = commandLogMapper.insertEtCommandLog(etCommandLog);
if(i>0){
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/domain/Device.java b/share-space-system/src/main/java/com/ruoyi/ss/device/domain/Device.java
index a155ee4..00a7b90 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/device/domain/Device.java
+++ b/share-space-system/src/main/java/com/ruoyi/ss/device/domain/Device.java
@@ -253,4 +253,7 @@ public class Device extends BaseEntity
@ApiModelProperty("投放类型:1-房间门;2-麻将桌;3-台球桌;4-房间灯;5-卫生间门;6-大门")
private String placementType;
+
+ @ApiModelProperty("电压系数")
+ private BigDecimal vxs;
}
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml
index 6e4ec2e..ce89ee9 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml
+++ b/share-space-system/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml
@@ -56,6 +56,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
sd.over_price,
sd.rent_time,
sd.lock_user_id,
+ sd.vxs,
sd.surplus_ele,
sd.limit_recharge_time,
sd.limit_recharge_reason,
@@ -370,6 +371,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
online_status1,
online_status2,
version,
+ vxs,
#{storeId},
@@ -424,6 +426,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{onlineStatus1},
#{onlineStatus2},
#{version},
+ #{vxs},
@@ -497,6 +500,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
online_status1 = #{onlineStatus1},
online_status2 = #{onlineStatus2},
version = #{version},
+ vxs = #{vxs},
where device_id = #{deviceId}
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java b/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java
index e89cecf..52cc2d9 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java
+++ b/share-space-system/src/main/java/com/ruoyi/ss/device/service/DeviceService.java
@@ -276,6 +276,11 @@ public interface DeviceService
*/
int reboot(DeviceVO device,String reason);
+ /**
+ * 开门
+ */
+ int openDoor(DeviceVO device, String reason);
+
/**
* 开关设施
*/
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
index d4ccd72..054973c 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
+++ b/share-space-system/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.ss.device.service.impl;
+import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.redis.RedisLock;
import com.ruoyi.common.core.redis.enums.RedisLockKey;
@@ -415,6 +416,16 @@ public class DeviceServiceImpl implements DeviceService
return res != null && res.isSuccess() ? 1 : 0;
}
+ /**
+ * 开门
+ */
+ @Override
+ public int openDoor(DeviceVO device, String reason) {
+ ServiceUtil.assertion(device == null, "设备不存在");
+ CommandResponse res = iotService.openDoor(device, reason);
+ return res != null && res.isSuccess() ? 1 : 0;
+ }
+
/**
* 开关设施
*/
@@ -1218,6 +1229,7 @@ public class DeviceServiceImpl implements DeviceService
.filter(item -> Objects.equals(device.getMac(), item.getMac()) || Objects.equals(device.getMac2(), item.getMac()))
.findFirst().orElse(null);
+ log.info("拉取的deviceInfo: {}", JSON.toJSON(deviceInfo));
// 更新设备信息
device.setDeviceId(device.getDeviceId());
if (deviceInfo != null) {
@@ -1228,6 +1240,7 @@ public class DeviceServiceImpl implements DeviceService
device.setVoltage(deviceInfo.getV());
device.setElectricity(deviceInfo.getA());
device.setVersion(deviceInfo.getVersion());
+ device.setVxs(deviceInfo.getVxs());
// 判断是否支持WIFI,支持则更新
if (ModelTag.hasTag(device.getModelTags(), ModelTag.WIFI)) {
@@ -1274,6 +1287,7 @@ public class DeviceServiceImpl implements DeviceService
// 异步更新设备信息
for (DeviceVO device : list) {
scheduledExecutorService.schedule(() -> {
+ log.info("异步更新数据库的device: {}", device);
// if (StringUtils.hasText(onlineType)) {
// 获取并设置在线状态
this.setOnlineStatus(device);
diff --git a/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java
index a463cc5..ecac8b6 100644
--- a/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java
+++ b/share-space-system/src/main/java/com/ruoyi/ss/store/service/impl/StoreServiceImpl.java
@@ -1,5 +1,6 @@
package com.ruoyi.ss.store.service.impl;
+import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.exception.ServiceException;
@@ -234,7 +235,7 @@ public class StoreServiceImpl implements IStoreService
// 同步修改店铺名称,则修改房间、设施、卫生间中的店铺名称
StoreVO storeVO = storeMapper.selectEStoreByStoreId(eStore.getStoreId());
- if(!eStore.getName().equals(storeVO.getName())){
+ if(ObjectUtil.isNotNull(eStore.getName()) && !eStore.getName().equals(storeVO.getName())){
syncModifyStoreName(eStore.getStoreId(), eStore.getName());
}
return Boolean.TRUE;
diff --git a/share-space-system/src/main/java/com/ruoyi/system/iot/domain/IotDeviceInfo.java b/share-space-system/src/main/java/com/ruoyi/system/iot/domain/IotDeviceInfo.java
index 1e3e4e3..ac0d20b 100644
--- a/share-space-system/src/main/java/com/ruoyi/system/iot/domain/IotDeviceInfo.java
+++ b/share-space-system/src/main/java/com/ruoyi/system/iot/domain/IotDeviceInfo.java
@@ -32,6 +32,7 @@ public class IotDeviceInfo {
private String model; // 型号
private String wifi; // WIFI
private String version; // 版本号
+ private BigDecimal vxs; // 电压系数
public static IotDeviceInfo newDefaultInstance() {
return IotDeviceInfo.builder()
@@ -45,6 +46,7 @@ public class IotDeviceInfo {
.time(BigDecimal.ZERO)
.model(null)
.version(null)
+ .vxs(BigDecimal.ONE)
.build();
}
diff --git a/share-space-system/src/main/java/com/ruoyi/system/iot/service/IotService.java b/share-space-system/src/main/java/com/ruoyi/system/iot/service/IotService.java
index 39a6fe5..8e1275f 100644
--- a/share-space-system/src/main/java/com/ruoyi/system/iot/service/IotService.java
+++ b/share-space-system/src/main/java/com/ruoyi/system/iot/service/IotService.java
@@ -44,15 +44,16 @@ public interface IotService {
*/
boolean open(IotDevice device,boolean isIgnore,String reason);
-// /**
-// * 重启设备
-// */
-// boolean reboot(DeviceVO device,String reason);
/**
* 重启设备
*/
CommandResponse reboot(IotDevice device, String reason);
+ /**
+ * 开门
+ */
+ CommandResponse openDoor(IotDevice device, String reason);
+
/**
* 断电
*
diff --git a/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java b/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java
index f083502..bb56e9b 100644
--- a/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java
+++ b/share-space-system/src/main/java/com/ruoyi/system/iot/service/impl/IotServiceImpl.java
@@ -745,8 +745,7 @@ public class IotServiceImpl implements IotService {
return null;
}
String command = IotConstants.COMMAND_SET_VXS + vxs + IotConstants.COMMAND_SEPARATOR;
- sendCommand(deviceName, command, productId,reason);
- return null;
+ return sendCommand(deviceName, command, productId,reason);
}
/**
@@ -767,6 +766,24 @@ public class IotServiceImpl implements IotService {
return res;
}
+ /**
+ * 开门
+ */
+ @Override
+ public CommandResponse openDoor(IotDevice device, String reason) {
+ if (device == null || StringUtils.isBlank(device.getProductId())) {
+ return null;
+ }
+ CommandResponse res = null;
+ if (StringUtils.hasText(device.iotMac2())) {
+ res = openDoor(device.iotMac2(), device.getProductId(), reason);
+ }
+ if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
+ res = openDoor(device.iotMac1(), device.getProductId(), reason);
+ }
+ return res;
+ }
+
private CommandResponse reboot(String deviceName, String productId, String reason) {
if (StringUtils.isAnyBlank(deviceName, productId)) {
return null;
@@ -774,4 +791,12 @@ public class IotServiceImpl implements IotService {
String command = IotConstants.COMMAND_REBOOT;
return sendCommand(deviceName, command, productId, reason);
}
+
+ private CommandResponse openDoor(String deviceName, String productId, String reason) {
+ if (StringUtils.isAnyBlank(deviceName, productId)) {
+ return null;
+ }
+ String command = IotConstants.COMMAND_RECHARGE +"5";
+ return sendCommand(deviceName, command, productId, reason);
+ }
}