提交
This commit is contained in:
parent
35faad32fa
commit
949111d420
|
@ -44,6 +44,11 @@ public class IotConstants {
|
||||||
*/
|
*/
|
||||||
public static final String ADDS_DEVICE_DETAIL = "/device/detail";
|
public static final String ADDS_DEVICE_DETAIL = "/device/detail";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备列表
|
||||||
|
*/
|
||||||
|
public static final String ADDS_DEVICE_LIST = "/device/list";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加设备
|
* 添加设备
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package com.ruoyi.iot.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wjh
|
||||||
|
* 2024/12/25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ListData {
|
||||||
|
|
||||||
|
Integer limit;
|
||||||
|
|
||||||
|
Integer offset;
|
||||||
|
|
||||||
|
List<IotDeviceDetail> list;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
package com.ruoyi.iot.domain.response;
|
||||||
|
|
||||||
|
import com.ruoyi.iot.domain.ListData;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wjh
|
||||||
|
* 2024/12/25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ListResponse extends BaseResponse{
|
||||||
|
|
||||||
|
private ListData data;
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wjh
|
* @author wjh
|
||||||
|
|
|
@ -13,18 +13,13 @@ import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
import com.ruoyi.common.utils.oneNet.Token;
|
import com.ruoyi.common.utils.oneNet.Token;
|
||||||
import com.ruoyi.iot.domain.*;
|
import com.ruoyi.iot.domain.*;
|
||||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
import com.ruoyi.iot.domain.response.*;
|
||||||
import com.ruoyi.iot.domain.response.CurrentDataPointResponse;
|
|
||||||
import com.ruoyi.iot.domain.response.DetailResponse;
|
|
||||||
import com.ruoyi.iot.domain.response.HistoryDataPointResponse;
|
|
||||||
import com.ruoyi.iot.enums.IotHttpStatus;
|
import com.ruoyi.iot.enums.IotHttpStatus;
|
||||||
import com.ruoyi.iot.interfaces.IotDevice;
|
import com.ruoyi.iot.interfaces.IotDevice;
|
||||||
import com.ruoyi.iot.service.IotConverter;
|
import com.ruoyi.iot.service.IotConverter;
|
||||||
import com.ruoyi.iot.service.IotService;
|
import com.ruoyi.iot.service.IotService;
|
||||||
import com.ruoyi.ss.commandLog.service.ICommandLogService;
|
import com.ruoyi.ss.commandLog.service.ICommandLogService;
|
||||||
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
import com.ruoyi.ss.device.domain.enums.DeviceOnlineStatus;
|
||||||
import com.ruoyi.ss.device.service.DeviceService;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
@ -33,10 +28,13 @@ import org.springframework.stereotype.Service;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author wjh
|
* @author wjh
|
||||||
|
@ -75,8 +73,6 @@ public class IotServiceImpl implements IotService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ICommandLogService commandLogService;
|
private ICommandLogService commandLogService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DeviceService deviceService;
|
|
||||||
|
|
||||||
// 查询OneNet设备在线状态
|
// 查询OneNet设备在线状态
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,14 +98,14 @@ public class IotServiceImpl implements IotService {
|
||||||
if (device == null || StringUtils.isBlank(device.getProductId())) {
|
if (device == null || StringUtils.isBlank(device.getProductId())) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
// 优先使用mac1判断
|
// 优先使用mac2判断
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
status = this.getOnlineStatus(device.iotMac1(), device.getProductId());
|
|
||||||
}
|
|
||||||
// 若还是离线,则判断mac2是否在线
|
|
||||||
if (status == DeviceOnlineStatus.OFFLINE && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
status = this.getOnlineStatus(device.iotMac2(), device.getProductId());
|
status = this.getOnlineStatus(device.iotMac2(), device.getProductId());
|
||||||
}
|
}
|
||||||
|
// 若还是离线,则判断mac1是否在线
|
||||||
|
if (status == DeviceOnlineStatus.OFFLINE && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
status = this.getOnlineStatus(device.iotMac1(), device.getProductId());
|
||||||
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,17 +130,17 @@ public class IotServiceImpl implements IotService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试用mac1通电
|
// 尝试用mac2通电
|
||||||
try {
|
try {
|
||||||
result = this.open(device.iotMac1(), device.getProductId(), reason);
|
result = this.open(device.iotMac2(), device.getProductId(), reason);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
log.error("mac1通电失败:{}", device.iotMac1());
|
log.error("mac2通电失败:{}", device.iotMac2());
|
||||||
throw new ServiceException("mac1通电失败");
|
throw new ServiceException("mac2通电失败");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("mac1通电失败,尝试用mac2通电");
|
log.info("mac2通电失败,尝试用mac1通电");
|
||||||
if (!StringUtils.isAnyBlank(device.iotMac2(), device.getProductId())) {
|
if (!StringUtils.isAnyBlank(device.iotMac1(), device.getProductId())) {
|
||||||
result = this.open(device.iotMac2(), device.getProductId(), reason);
|
result = this.open(device.iotMac1(), device.getProductId(), reason);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -174,16 +170,16 @@ public class IotServiceImpl implements IotService {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试用mac1断电
|
// 尝试用mac2断电
|
||||||
try {
|
try {
|
||||||
result = this.close(device.iotMac1(), device.getProductId(), reason);
|
result = this.close(device.iotMac2(), device.getProductId(), reason);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throw new ServiceException("mac1断电失败");
|
throw new ServiceException("mac2断电失败");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("mac1断电失败:{},尝试用mac2断电", e.getMessage());
|
log.info("mac2断电失败:{},尝试用mac1断电", e.getMessage());
|
||||||
if (!StringUtils.isAnyBlank(device.iotMac2(), device.getProductId())) {
|
if (!StringUtils.isAnyBlank(device.iotMac1(), device.getProductId())) {
|
||||||
result = this.close(device.iotMac2(), device.getProductId(), reason);
|
result = this.close(device.iotMac1(), device.getProductId(), reason);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -218,12 +214,12 @@ public class IotServiceImpl implements IotService {
|
||||||
ServiceUtil.assertion(device == null || vxs == null, "设备或参数为空");
|
ServiceUtil.assertion(device == null || vxs == null, "设备或参数为空");
|
||||||
|
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.setVxs(device.iotMac1(), vxs, device.getProductId(), reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.setVxs(device.iotMac2(), vxs, device.getProductId(), reason);
|
res = this.setVxs(device.iotMac2(), vxs, device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.setVxs(device.iotMac1(), vxs, device.getProductId(), reason);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -232,12 +228,12 @@ public class IotServiceImpl implements IotService {
|
||||||
public CommandResponse uploadData(IotDevice device, String reason) {
|
public CommandResponse uploadData(IotDevice device, String reason) {
|
||||||
ServiceUtil.assertion(device == null || StringUtils.isBlank(device.getProductId()), "设备为空");
|
ServiceUtil.assertion(device == null || StringUtils.isBlank(device.getProductId()), "设备为空");
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.uploadData(device.iotMac1(), device.getProductId(), reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.uploadData(device.iotMac2(), device.getProductId(), reason);
|
res = this.uploadData(device.iotMac2(), device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.uploadData(device.iotMac1(), device.getProductId(), reason);
|
||||||
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +254,10 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 获取当前设备数据点信息
|
// 获取当前设备数据点信息
|
||||||
public List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames, String productId) {
|
public List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames, String productId) {
|
||||||
|
deviceNames = deviceNames.stream().filter(StringUtils::hasText).collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmptyElement(deviceNames)) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
String param = "device_name=" + String.join(",", deviceNames) + "&product_id=" + productId;
|
String param = "device_name=" + String.join(",", deviceNames) + "&product_id=" + productId;
|
||||||
String sendUrl = iotHost+ IotConstants.ADDS_CURRENT_DATAPOINTS + "?" + param;
|
String sendUrl = iotHost+ IotConstants.ADDS_CURRENT_DATAPOINTS + "?" + param;
|
||||||
|
|
||||||
|
@ -291,7 +291,6 @@ public class IotServiceImpl implements IotService {
|
||||||
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
||||||
|
|
||||||
String token = Token.getToken();
|
String token = Token.getToken();
|
||||||
// log.info("IOT获取到Authorization:【{}】",token);
|
|
||||||
String result = HttpUtils.sendGetWithToken(sendUrl, param, token);
|
String result = HttpUtils.sendGetWithToken(sendUrl, param, token);
|
||||||
|
|
||||||
if (!StringUtils.hasText(result)) {
|
if (!StringUtils.hasText(result)) {
|
||||||
|
@ -307,6 +306,33 @@ public class IotServiceImpl implements IotService {
|
||||||
return response.getData();
|
return response.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备列表
|
||||||
|
*
|
||||||
|
* @param deviceName 设备名称过滤
|
||||||
|
* @param productId 产品ID
|
||||||
|
* @return 设备列表
|
||||||
|
*/
|
||||||
|
private List<IotDeviceDetail> getDeviceList(String deviceName, String productId) {
|
||||||
|
String sendUrl = iotHost + IotConstants.ADDS_DEVICE_LIST;
|
||||||
|
String param = "device_name=" + deviceName + "&product_id=" + productId + "&offset=0&limit=100";
|
||||||
|
String token = Token.getToken();
|
||||||
|
String res = HttpUtils.sendGetWithToken(sendUrl, param, token);
|
||||||
|
if (!StringUtils.hasText(res)) {
|
||||||
|
log.error("与OneNet通信异常");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
ListResponse response = JSONObject.parseObject(res, ListResponse.class);
|
||||||
|
if (!IotHttpStatus.SUCCESS.getCode().equals(response.getCode())) {
|
||||||
|
log.error("获取当前设备数据点信息出错:{}", response.getMsg());
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
if (response.getData() == null) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
return response.getData().getList();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置剩余时长
|
* 设置剩余时长
|
||||||
*
|
*
|
||||||
|
@ -330,12 +356,12 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.setTime(device.iotMac1(), seconds, device.getProductId(), reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.setTime(device.iotMac2(), seconds, device.getProductId(), reason);
|
res = this.setTime(device.iotMac2(), seconds, device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.setTime(device.iotMac1(), seconds, device.getProductId(), reason);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -354,12 +380,12 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.addEle(device.iotMac1(), ele, device.getProductId(), reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.addEle(device.iotMac2(), ele, device.getProductId(), reason);
|
res = this.addEle(device.iotMac2(), ele, device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.addEle(device.iotMac1(), ele, device.getProductId(), reason);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -378,12 +404,12 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.setEle(device.iotMac1(), ele, device.getProductId(), reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.setEle(device.iotMac2(), ele, device.getProductId(), reason);
|
res = this.setEle(device.iotMac2(), ele, device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.setEle(device.iotMac1(), ele, device.getProductId(), reason);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -537,12 +563,12 @@ public class IotServiceImpl implements IotService {
|
||||||
public CommandResponse setWifi(IotDevice device, String wifiName, String wifiPwd, String reason) {
|
public CommandResponse setWifi(IotDevice device, String wifiName, String wifiPwd, String reason) {
|
||||||
|
|
||||||
CommandResponse res = null;
|
CommandResponse res = null;
|
||||||
if (StringUtils.hasText(device.iotMac1())) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
res = this.setWifi(device.iotMac1(), device.getProductId(), wifiName, wifiPwd, reason);
|
|
||||||
}
|
|
||||||
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac2())) {
|
|
||||||
res = this.setWifi(device.iotMac2(), device.getProductId(), wifiName, wifiPwd, reason);
|
res = this.setWifi(device.iotMac2(), device.getProductId(), wifiName, wifiPwd, reason);
|
||||||
}
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = this.setWifi(device.iotMac1(), device.getProductId(), wifiName, wifiPwd, reason);
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -615,9 +641,12 @@ public class IotServiceImpl implements IotService {
|
||||||
if (device == null || StringUtils.isBlank(device.getProductId())) {
|
if (device == null || StringUtils.isBlank(device.getProductId())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CommandResponse res = reboot(device.iotMac1(), device.getProductId(), reason);
|
CommandResponse res = null;
|
||||||
if (res == null || !res.isSuccess()) {
|
if (StringUtils.hasText(device.iotMac2())) {
|
||||||
return reboot(device.iotMac2(), device.getProductId(), reason);
|
res = reboot(device.iotMac2(), device.getProductId(), reason);
|
||||||
|
}
|
||||||
|
if ((res == null || !res.isSuccess()) && StringUtils.hasText(device.iotMac1())) {
|
||||||
|
res = reboot(device.iotMac1(), device.getProductId(), reason);
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -122,7 +124,7 @@ public class DeviceVO extends Device implements IotDevice {
|
||||||
return getModelProductId();
|
return getModelProductId();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取数据库剩余电量
|
// 获取数据库剩余电量(度)
|
||||||
public BigDecimal getSurplusEleDb() {
|
public BigDecimal getSurplusEleDb() {
|
||||||
if (getExpireEle() == null) {
|
if (getExpireEle() == null) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
|
@ -132,4 +134,13 @@ public class DeviceVO extends Device implements IotDevice {
|
||||||
}
|
}
|
||||||
return getExpireEle().subtract(getTotalElectriQuantity());
|
return getExpireEle().subtract(getTotalElectriQuantity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取数据库剩余时长(秒)
|
||||||
|
public long getSurplusSecondsDb() {
|
||||||
|
if (getExpireTime() == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Duration between = Duration.between(LocalDateTime.now(), getExpireTime());
|
||||||
|
return between.getSeconds();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,4 +434,6 @@ public interface DeviceService
|
||||||
* 同步电量
|
* 同步电量
|
||||||
*/
|
*/
|
||||||
CommandResponse syncEle(Long deviceId, String reason);
|
CommandResponse syncEle(Long deviceId, String reason);
|
||||||
|
|
||||||
|
void monitor(List<Long> deviceIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -790,16 +790,10 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
|
||||||
for (DeviceVO device : list) {
|
for (DeviceVO device : list) {
|
||||||
if (StringUtils.hasText(device.getMac())) {
|
String status = iotService.getOnlineStatus(device).getStatus();
|
||||||
String status = iotService.getOnlineStatus(device).getStatus();
|
device.setOnlineStatus(status);
|
||||||
// log.info("device: {} {} online status is {}", device.getDeviceId(), device.getMac(), status);
|
if (DeviceOnlineStatus.ONLINE.getStatus().equals(status)) {
|
||||||
device.setOnlineStatus(status);
|
device.setLastOnlineTime(now);
|
||||||
if (DeviceOnlineStatus.ONLINE.getStatus().equals(status)) {
|
|
||||||
device.setLastOnlineTime(now);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
|
||||||
log.info("device {} mac is empty", device.getDeviceId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int i = deviceMapper.batchUpdateOnlineStatus(list);
|
int i = deviceMapper.batchUpdateOnlineStatus(list);
|
||||||
|
@ -937,90 +931,90 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
|
|
||||||
for (Map.Entry<String, List<DeviceVO>> entry : group.entrySet()) {
|
for (Map.Entry<String, List<DeviceVO>> entry : group.entrySet()) {
|
||||||
|
|
||||||
List<IotDeviceInfo> iotList = iotService.getDeviceInfo(entry.getValue(), entry.getKey());
|
// 批量获取设备信息
|
||||||
|
List<DeviceVO> groupDeviceList = entry.getValue();
|
||||||
|
String productId = entry.getKey();
|
||||||
|
List<IotDeviceInfo> iotList = iotService.getDeviceInfo(groupDeviceList, productId);
|
||||||
|
|
||||||
for (DeviceVO device : list) {
|
// 构造更新设备信息
|
||||||
try {
|
for (DeviceVO device : groupDeviceList) {
|
||||||
if (StringUtils.isAnyBlank(device.getMac(), device.getModelProductId())) {
|
// 获取数据点信息
|
||||||
continue;
|
IotDeviceInfo deviceInfo = iotList.stream()
|
||||||
}
|
.filter(item -> Objects.equals(device.getMac(), item.getMac()) || Objects.equals(device.getMac2(), item.getMac()))
|
||||||
// 获取数据点信息
|
.findFirst().orElse(null);
|
||||||
IotDeviceInfo deviceInfo = iotList.stream()
|
|
||||||
.filter(item -> Objects.equals(device.getMac(), item.getMac()) || Objects.equals(device.getMac2(), item.getMac()))
|
|
||||||
.findFirst().orElse(null);
|
|
||||||
|
|
||||||
// 更新设备信息
|
// 更新设备信息
|
||||||
device.setDeviceId(device.getDeviceId());
|
device.setDeviceId(device.getDeviceId());
|
||||||
if (deviceInfo != null) {
|
if (deviceInfo != null) {
|
||||||
device.setLastPullTime(deviceInfo.getAt());
|
device.setLastPullTime(deviceInfo.getAt());
|
||||||
device.setPowerStatus(deviceInfo.getS());
|
device.setPowerStatus(deviceInfo.getS());
|
||||||
device.setRemainTime(deviceInfo.getTime());
|
device.setRemainTime(deviceInfo.getTime());
|
||||||
device.setRealTimePower(deviceInfo.getP());
|
device.setRealTimePower(deviceInfo.getP());
|
||||||
device.setVoltage(deviceInfo.getV());
|
device.setVoltage(deviceInfo.getV());
|
||||||
device.setElectricity(deviceInfo.getA());
|
device.setElectricity(deviceInfo.getA());
|
||||||
device.setVersion(deviceInfo.getVersion());
|
device.setVersion(deviceInfo.getVersion());
|
||||||
device.setVxs(deviceInfo.getVxs());
|
device.setVxs(deviceInfo.getVxs());
|
||||||
|
|
||||||
// 总用电量
|
// 判断是否支持WIFI,支持则更新
|
||||||
if (deviceInfo.getW() != null) {
|
if (ModelTag.hasTag(device.getModelTags(), ModelTag.WIFI)) {
|
||||||
// 若有数据点中的值大于数据库中的值,则更新
|
device.setWifi(deviceInfo.getWifi());
|
||||||
if (deviceInfo.getW().compareTo(device.getTotalElectriQuantity()) >= 0) {
|
|
||||||
device.setTotalElectriQuantity(deviceInfo.getW());
|
|
||||||
}
|
|
||||||
// 若数据点小于数据库中的值,则发命令恢复物联网设备的总用电量
|
|
||||||
else {
|
|
||||||
scheduledExecutorService.schedule(() -> {
|
|
||||||
String reason = "拉取设备信息时,恢复总用电量,数据库值:" + device.getTotalElectriQuantity() + ",OneNet值:" + deviceInfo.getW();
|
|
||||||
iotService.setTotalEle(device, device.getTotalElectriQuantity().multiply(new BigDecimal(1000)), reason);
|
|
||||||
}, 0, TimeUnit.SECONDS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否有WIFI
|
|
||||||
if (ModelTag.hasTag(device.getModelTags(), ModelTag.WIFI)) {
|
|
||||||
device.setWifi(deviceInfo.getWifi());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 是否有电量
|
|
||||||
if (ModelTag.hasTag(device.getModelTags(), ModelTag.ELE)) {
|
|
||||||
device.setSurplusEle(deviceInfo.getM());
|
|
||||||
} else {
|
|
||||||
device.setSurplusEle(BigDecimal.ZERO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断设备是否正在使用
|
// 判断是否支持电量,支持则更新
|
||||||
// 若开关开启,则正在使用
|
if (ModelTag.hasTag(device.getModelTags(), ModelTag.ELE)) {
|
||||||
boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(device.getPowerStatus());
|
device.setSurplusEle(deviceInfo.getM());
|
||||||
// 若设备有正在使用中的订单,则正在使用
|
|
||||||
boolean hasUsingBill = device.getUsingBillCount() != null && device.getUsingBillCount() > 0;
|
|
||||||
if (hasOpen || hasUsingBill) {
|
|
||||||
device.setStatus(DeviceStatus.USING.getStatus());
|
|
||||||
} else {
|
} else {
|
||||||
device.setStatus(DeviceStatus.NORMAL.getStatus());
|
device.setSurplusEle(BigDecimal.ZERO);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否在线
|
// 总用电量
|
||||||
String onlineStatus1 = iotService.getOnlineStatus(device.getMac(), device.getProductId(), onlineType).getStatus();
|
if (deviceInfo.getW() != null) {
|
||||||
String onlineStatus2 = iotService.getOnlineStatus(device.getMac2(), device.getProductId(), onlineType).getStatus();
|
// 若有数据点中的值大于数据库中的值,则更新
|
||||||
device.setOnlineStatus1(onlineStatus1);
|
if (deviceInfo.getW().compareTo(device.getTotalElectriQuantity()) >= 0) {
|
||||||
device.setOnlineStatus2(onlineStatus2);
|
device.setTotalElectriQuantity(deviceInfo.getW());
|
||||||
if (DeviceOnlineStatus.ONLINE.getStatus().equals(onlineStatus1) || DeviceOnlineStatus.ONLINE.getStatus().equals(onlineStatus2)) {
|
}
|
||||||
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
// 若数据点小于数据库中的值,则发命令恢复物联网设备的总用电量
|
||||||
device.setLastOnlineTime(now);
|
else {
|
||||||
} else {
|
scheduledExecutorService.schedule(() -> {
|
||||||
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
String reason = "拉取设备信息时,恢复总用电量,数据库值:" + device.getTotalElectriQuantity() + ",OneNet值:" + deviceInfo.getW();
|
||||||
|
iotService.setTotalEle(device, device.getTotalElectriQuantity().multiply(new BigDecimal(1000)), reason);
|
||||||
|
}, 0, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 异步更新
|
|
||||||
scheduledExecutorService.schedule(() -> {
|
|
||||||
this.updateIotInfo(device);
|
|
||||||
}, 0, TimeUnit.SECONDS);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("更新设备信息失败,deviceId:{}, {}", device.getDeviceId(), e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 判断设备是否正在使用
|
||||||
|
// 若开关开启,则正在使用
|
||||||
|
boolean hasOpen = DevicePowerStatus.ON.getStatus().equals(device.getPowerStatus());
|
||||||
|
// 若设备有正在使用中的订单,则正在使用
|
||||||
|
boolean hasUsingBill = device.getUsingBillCount() != null && device.getUsingBillCount() > 0;
|
||||||
|
if (hasOpen || hasUsingBill) {
|
||||||
|
device.setStatus(DeviceStatus.USING.getStatus());
|
||||||
|
} else {
|
||||||
|
device.setStatus(DeviceStatus.NORMAL.getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 异步更新设备信息
|
||||||
|
for (DeviceVO device : list) {
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
// 是否在线
|
||||||
|
String onlineStatus1 = iotService.getOnlineStatus(device.getMac(), device.getProductId(), onlineType).getStatus();
|
||||||
|
String onlineStatus2 = iotService.getOnlineStatus(device.getMac2(), device.getProductId(), onlineType).getStatus();
|
||||||
|
device.setOnlineStatus1(onlineStatus1);
|
||||||
|
device.setOnlineStatus2(onlineStatus2);
|
||||||
|
if (DeviceOnlineStatus.ONLINE.getStatus().equals(onlineStatus1) || DeviceOnlineStatus.ONLINE.getStatus().equals(onlineStatus2)) {
|
||||||
|
device.setOnlineStatus(DeviceOnlineStatus.ONLINE.getStatus());
|
||||||
|
device.setLastOnlineTime(now);
|
||||||
|
} else {
|
||||||
|
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
||||||
|
}
|
||||||
|
// 更新数据库
|
||||||
|
this.updateIotInfo(device);
|
||||||
|
}, 0, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1314,6 +1308,48 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
return iotService.setEle(device, device.getSurplusEleDb(), reason);
|
return iotService.setEle(device, device.getSurplusEleDb(), reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监控设备信息,并对设备进行校准
|
||||||
|
@Override
|
||||||
|
public void monitor(List<Long> deviceIds) {
|
||||||
|
DeviceQuery query = new DeviceQuery();
|
||||||
|
query.setDeviceIds(deviceIds);
|
||||||
|
List<DeviceVO> deviceList = this.selectSmDeviceList(query);
|
||||||
|
if (CollectionUtils.isEmptyElement(deviceList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.pullDeviceInfoList(deviceList, IotConstants.ONLINE_TYPE_GET);
|
||||||
|
|
||||||
|
for (DeviceVO device : deviceList) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
scheduledExecutorService.schedule(() -> {
|
||||||
|
// 若物联网设备的时长或者电量小于当前设备数据库的值,则执行一次同步(开启)
|
||||||
|
// 一般情况下,物联网设备的值会大于或等于当前数据库的值
|
||||||
|
long deviceSeconds = device.getRemainTime() == null ? 0 : device.getRemainTime().longValue();
|
||||||
|
if (device.getSurplusSecondsDb() > deviceSeconds) {
|
||||||
|
this.syncTime(device.getDeviceId(), LocalDateTime.now(), "设备监控-同步时长");
|
||||||
|
}
|
||||||
|
if (device.getSurplusEleDb().compareTo(device.getSurplusEle()) > 0) {
|
||||||
|
this.syncEle(device.getDeviceId(), "设备监控-同步电量");
|
||||||
|
}
|
||||||
|
// TODO 若当前设备数据库的时长或者电量<=0,且在这之后用户没有发open命令,则执行一次同步(关闭)
|
||||||
|
if (device.getSurplusSecondsDb() <= 0) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
if (device.getSurplusEle().compareTo(device.getSurplusEleDb()) <= 0) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
},0, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("监控设备{}出错:{}", device.getDeviceNo(), e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备是否已经被绑定
|
* 设备是否已经被绑定
|
||||||
*
|
*
|
||||||
|
|
|
@ -107,7 +107,7 @@ public class UserValidatorImpl extends BaseValidator implements UserValidator {
|
||||||
query.setEqPhonenumber(mobile);
|
query.setEqPhonenumber(mobile);
|
||||||
query.setExcludeUserId(userId);
|
query.setExcludeUserId(userId);
|
||||||
int repeatCount = userService.selectCount(query);
|
int repeatCount = userService.selectCount(query);
|
||||||
ServiceUtil.assertion(repeatCount > 0, "当前手机号已被绑定");
|
ServiceUtil.assertion(repeatCount > 0, "当前手机号已被其他用户绑定,请尝试使用其他手机号");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.stereotype.Component;
|
||||||
public class DeviceTask {
|
public class DeviceTask {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DeviceService smDeviceService;
|
private DeviceService deviceService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ISmMeterReadingRecordService smMeterReadingRecordService;
|
private ISmMeterReadingRecordService smMeterReadingRecordService;
|
||||||
|
@ -30,4 +30,9 @@ public class DeviceTask {
|
||||||
Thread.sleep(3000); // 睡眠3秒,防止quartz重复调度
|
Thread.sleep(3000); // 睡眠3秒,防止quartz重复调度
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设备监控
|
||||||
|
public void monitor() {
|
||||||
|
deviceService.monitor(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ public class SmDeviceController extends BaseController
|
||||||
{
|
{
|
||||||
startPage();
|
startPage();
|
||||||
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
|
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
|
||||||
|
deviceService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_GET);
|
||||||
deviceAssembler.assembleRealServiceRate(list);
|
deviceAssembler.assembleRealServiceRate(list);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user