设备监控debug
This commit is contained in:
parent
870e1ac431
commit
7c9acf2c54
|
@ -1,5 +1,5 @@
|
|||
package com.ruoyi.iot.service.impl;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
|
||||
import com.ruoyi.common.core.redis.RedisLock;
|
||||
import com.ruoyi.common.core.redis.enums.RedisLockKey;
|
||||
import com.ruoyi.common.utils.NumberUtils;
|
||||
|
@ -7,7 +7,10 @@ import com.ruoyi.common.utils.ServiceUtil;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.constants.ReceiveConstants;
|
||||
import com.ruoyi.iot.domain.*;
|
||||
import com.ruoyi.iot.domain.Datapoint;
|
||||
import com.ruoyi.iot.domain.HistoryDatastream;
|
||||
import com.ruoyi.iot.domain.HistoryDeviceData;
|
||||
import com.ruoyi.iot.domain.ReceiveMsg;
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.iot.enums.ReceiveType;
|
||||
import com.ruoyi.iot.service.IotReceiveService;
|
||||
|
@ -96,7 +99,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
|
|||
return;
|
||||
}
|
||||
// 拉取一下设备信息
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
// 查询
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
|||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -224,4 +223,8 @@ public interface DeviceMapper
|
|||
*/
|
||||
int initTotalEle(@Param("deviceId") Long deviceId);
|
||||
|
||||
/**
|
||||
* 查询ID列表
|
||||
*/
|
||||
List<Long> selectIds(@Param("query") DeviceQuery query);
|
||||
}
|
||||
|
|
|
@ -341,6 +341,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectIds" resultType="java.lang.Long">
|
||||
select device_id
|
||||
from sm_device sd
|
||||
<where>
|
||||
<include refid="searchCondition"/>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertSmDevice" parameterType="Device" useGeneratedKeys="true" keyProperty="deviceId">
|
||||
<selectKey resultType="Long" order="AFTER" keyProperty="deviceId">
|
||||
select LAST_INSERT_ID()
|
||||
|
@ -631,6 +639,26 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
<foreach open="online_status1 = CASE device_id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.onlineStatus1 != null">
|
||||
WHEN #{item.deviceId} THEN #{item.onlineStatus1}
|
||||
</when>
|
||||
<otherwise>
|
||||
WHEN #{item.deviceId} THEN `online_status1`
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
<foreach open="online_status2 = CASE device_id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.onlineStatus2 != null">
|
||||
WHEN #{item.deviceId} THEN #{item.onlineStatus2}
|
||||
</when>
|
||||
<otherwise>
|
||||
WHEN #{item.deviceId} THEN `online_status2`
|
||||
</otherwise>
|
||||
</choose>
|
||||
</foreach>
|
||||
<foreach open="last_online_time = CASE device_id" collection="list" item="item" close="END,">
|
||||
<choose>
|
||||
<when test="item.lastOnlineTime != null">
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package com.ruoyi.ss.device.service;
|
||||
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.ss.device.domain.*;
|
||||
import com.ruoyi.ss.device.domain.Device;
|
||||
import com.ruoyi.ss.device.domain.DeviceBO;
|
||||
import com.ruoyi.ss.device.domain.DeviceCountVO;
|
||||
import com.ruoyi.ss.device.domain.DeviceQuery;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
|
||||
|
@ -112,16 +115,15 @@ public interface DeviceService
|
|||
/**
|
||||
* 拉取设备信息,并保存到数据库
|
||||
*
|
||||
* @param deviceIds 设备id列表(为空则查询所有)
|
||||
* @param onlineType
|
||||
* @param deviceIds 设备id列表(为空则查询所有)
|
||||
*/
|
||||
void pullDeviceInfo(List<Long> deviceIds, String onlineType);
|
||||
void pullDeviceInfo(List<Long> deviceIds);
|
||||
|
||||
|
||||
/**
|
||||
* 拉取设备信息,并保存到数据库
|
||||
*/
|
||||
void pullDeviceInfoList(List<DeviceVO> list, String onlineType);
|
||||
void pullDeviceInfoList(List<DeviceVO> list);
|
||||
|
||||
/**
|
||||
* 通过SN绑定设备
|
||||
|
@ -290,7 +292,7 @@ public interface DeviceService
|
|||
/**
|
||||
* 刷新设备数据
|
||||
*/
|
||||
void pullDeviceInfo(Long deviceId, String onlineType);
|
||||
void pullDeviceInfo(Long deviceId);
|
||||
|
||||
/**
|
||||
* 设备归零时长
|
||||
|
@ -338,7 +340,7 @@ public interface DeviceService
|
|||
/**
|
||||
* 拉取最新设备数据
|
||||
*/
|
||||
void pullDeviceInfo(DeviceVO device, String onlineType);
|
||||
void pullDeviceInfo(DeviceVO device);
|
||||
|
||||
/**
|
||||
* 解绑代理商
|
||||
|
|
|
@ -7,7 +7,10 @@ import com.ruoyi.common.core.redis.enums.RedisLockKey;
|
|||
import com.ruoyi.common.enums.LoginType;
|
||||
import com.ruoyi.common.enums.UserType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
|
@ -45,7 +48,6 @@ import com.ruoyi.ss.store.service.StoreService;
|
|||
import com.ruoyi.ss.storeStaff.service.StoreStaffValidator;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillStatus;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.TransactionBillType;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillService;
|
||||
import com.ruoyi.ss.user.domain.SmUserVO;
|
||||
|
@ -366,7 +368,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
@Override
|
||||
public int switchDevice(Long deviceId, boolean open, String reason) {
|
||||
DeviceVO device = selectById(deviceId);
|
||||
this.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
this.pullDeviceInfo(device);
|
||||
return this.switchDevice(device, open ? DevicePowerStatus.ON : DevicePowerStatus.OFF, reason);
|
||||
}
|
||||
|
||||
|
@ -387,8 +389,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
|
||||
@Override
|
||||
public void pullDeviceInfo(Long deviceId, String onlineType) {
|
||||
pullDeviceInfo(Collections.singletonList(deviceId), onlineType);
|
||||
public void pullDeviceInfo(Long deviceId) {
|
||||
pullDeviceInfo(Collections.singletonList(deviceId));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -587,8 +589,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
}
|
||||
|
||||
@Override
|
||||
public void pullDeviceInfo(DeviceVO device, String onlineType) {
|
||||
this.pullDeviceInfoList(Collections.singletonList(device), onlineType);
|
||||
public void pullDeviceInfo(DeviceVO device) {
|
||||
this.pullDeviceInfoList(Collections.singletonList(device));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -777,14 +779,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
log.info("device list is empty");
|
||||
return;
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
for (DeviceVO device : list) {
|
||||
String status = iotService.getOnlineStatus(device).getStatus();
|
||||
device.setOnlineStatus(status);
|
||||
if (DeviceOnlineStatus.ONLINE.getStatus().equals(status)) {
|
||||
device.setLastOnlineTime(now);
|
||||
}
|
||||
this.setOnlineStatus(device, IotConstants.ONLINE_TYPE_COMMAND);
|
||||
}
|
||||
int i = deviceMapper.batchUpdateOnlineStatus(list);
|
||||
log.info("update count: {}", i);
|
||||
|
@ -806,7 +802,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
// 查询设备列表
|
||||
List<DeviceVO> deviceList = this.selectByIds(deviceIds);
|
||||
// 拉取最新数据
|
||||
this.pullDeviceInfoList(deviceList, IotConstants.ONLINE_TYPE_GET);
|
||||
this.pullDeviceInfoList(deviceList);
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 关闭设备订单
|
||||
|
@ -895,25 +891,23 @@ public class DeviceServiceImpl implements DeviceService
|
|||
/**
|
||||
* 拉取设备信息,并保存到数据库
|
||||
*
|
||||
* @param deviceIds 设备id列表(为空则查询所有)
|
||||
* @param onlineType
|
||||
* @param deviceIds 设备id列表(为空则查询所有)
|
||||
*/
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void pullDeviceInfo(List<Long> deviceIds, String onlineType) {
|
||||
public void pullDeviceInfo(List<Long> deviceIds) {
|
||||
// 查询设备列表
|
||||
DeviceQuery dto = new DeviceQuery();
|
||||
dto.setDeviceIds(deviceIds);
|
||||
List<DeviceVO> list = deviceMapper.selectSmDeviceList(dto);
|
||||
this.pullDeviceInfoList(list, onlineType);
|
||||
this.pullDeviceInfoList(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pullDeviceInfoList(List<DeviceVO> list, String onlineType) {
|
||||
public void pullDeviceInfoList(List<DeviceVO> list) {
|
||||
if (CollectionUtils.isEmptyElement(list)) {
|
||||
return;
|
||||
}
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 拼接正在使用中的订单数量
|
||||
deviceAssembler.assembleUsingBillCount(list);
|
||||
|
@ -992,23 +986,28 @@ public class DeviceServiceImpl implements DeviceService
|
|||
// 异步更新设备信息
|
||||
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.setOnlineStatus(device, IotConstants.ONLINE_TYPE_COMMAND);
|
||||
// 更新数据库
|
||||
this.updateIotInfo(device);
|
||||
}, 0, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
private void setOnlineStatus(DeviceVO device, String onlineType) {
|
||||
// 是否在线
|
||||
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(LocalDateTime.now());
|
||||
} else {
|
||||
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新物联网信息
|
||||
*/
|
||||
|
@ -1026,6 +1025,8 @@ public class DeviceServiceImpl implements DeviceService
|
|||
data.setSurplusEle(device.getSurplusEle());
|
||||
data.setStatus(device.getStatus());
|
||||
data.setOnlineStatus(device.getOnlineStatus());
|
||||
data.setOnlineStatus1(device.getOnlineStatus1());
|
||||
data.setOnlineStatus2(device.getOnlineStatus2());
|
||||
data.setLastOnlineTime(device.getLastOnlineTime());
|
||||
return deviceMapper.updateSmDevice(data);
|
||||
}
|
||||
|
@ -1039,7 +1040,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
private void pullDeviceInfoAsync(List<Long> deviceIds, long delay, TimeUnit unit) {
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
log.info("异步拉取设备信息 start");
|
||||
this.pullDeviceInfo(deviceIds, IotConstants.ONLINE_TYPE_GET);
|
||||
this.pullDeviceInfo(deviceIds);
|
||||
log.info("异步拉取设备信息 end");
|
||||
}, delay, unit);
|
||||
}
|
||||
|
@ -1137,7 +1138,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
DeviceVO device = deviceMapper.selectSmDeviceByDeviceId(deviceId);
|
||||
ServiceUtil.assertion(device == null || device.getDeleted(), "设备不存在");
|
||||
// 拉取最新设备信息
|
||||
pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
pullDeviceInfo(device);
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改设备信息
|
||||
|
@ -1226,7 +1227,7 @@ public class DeviceServiceImpl implements DeviceService
|
|||
return 0;
|
||||
}
|
||||
// 拉取设备信息
|
||||
this.pullDeviceInfo(deviceId, IotConstants.ONLINE_TYPE_GET);
|
||||
this.pullDeviceInfo(deviceId);
|
||||
return deviceMapper.initTotalEle(deviceId);
|
||||
}
|
||||
|
||||
|
@ -1314,51 +1315,58 @@ public class DeviceServiceImpl implements DeviceService
|
|||
|
||||
/**
|
||||
* 监控设备信息,并对设备进行校准
|
||||
* FIXME 存在问题:数据量大时,处理较慢,会造成数据不一致,导致频繁关闭设备
|
||||
* 应该考虑实时获取设备数据,采用同步方式进行校准
|
||||
* 或者考虑有针对性的对设备进行校准
|
||||
*/
|
||||
@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(), "设备监控-同步电量");
|
||||
// }
|
||||
//
|
||||
// // 若当前设备数据库的时长并且电量<=0,且在这之后用户没有发open命令,则执行一次同步(关闭)
|
||||
// boolean hasOpen = DeviceUserOperaType.OPEN.getType().equals(device.getUserOperaType()); // 是否开启过
|
||||
// LocalDateTime lastOperaTime = device.getUserOperaTime(); // 上次开启的时间
|
||||
// BigDecimal lastOperaEle = device.getUserOperaEle(); // 上次开启的总用电量
|
||||
//
|
||||
// boolean hasOpenAfterExpireTime = hasOpen && lastOperaTime != null && lastOperaTime.isAfter(device.getExpireTime()); // 是否在时间结束后开启
|
||||
// boolean hasTime = device.getSurplusSecondsDb() > 0; // 剩余时间
|
||||
// boolean hasOpenAfterExpireEle = hasOpen && lastOperaEle != null && lastOperaEle.compareTo(device.getExpireEle()) > 0; // 是否在结束电量后开启
|
||||
// boolean hasEle = device.getSurplusEleDb().compareTo(BigDecimal.ZERO) > 0; // 剩余电量
|
||||
// if (!hasTime && !hasEle && !hasOpenAfterExpireTime && !hasOpenAfterExpireEle) {
|
||||
// this.switchDevice(device, DevicePowerStatus.OFF, "设备监控-发现异常未关闭设备");
|
||||
// }
|
||||
// },0, TimeUnit.SECONDS);
|
||||
//
|
||||
// } catch (Exception e) {
|
||||
// log.error("监控设备{}出错:{}", device.getDeviceNo(), e.getMessage());
|
||||
// }
|
||||
// }
|
||||
// 若不为空,则查询所有设备
|
||||
if (CollectionUtils.isEmpty(deviceIds)) {
|
||||
DeviceQuery query = new DeviceQuery();
|
||||
query.setDeviceIds(deviceIds);
|
||||
deviceIds = this.selectIds(query);
|
||||
}
|
||||
if (CollectionUtils.isEmptyElement(deviceIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Long deviceId : deviceIds) {
|
||||
try {
|
||||
scheduledExecutorService.schedule(() -> {
|
||||
// 获取设备最新信息
|
||||
DeviceVO device = selectById(deviceId);
|
||||
pullDeviceInfo(device);
|
||||
|
||||
// 若物联网设备的时长或者电量小于当前设备数据库的值,则执行一次同步(开启)
|
||||
// 一般情况下,物联网设备的值会大于或等于当前数据库的值
|
||||
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(), "设备监控-同步电量");
|
||||
}
|
||||
|
||||
// 若当前设备数据库的时长并且电量<=0,且在这之后用户没有发open命令,则执行一次同步(关闭)
|
||||
boolean hasOpen = DeviceUserOperaType.OPEN.getType().equals(device.getUserOperaType()); // 是否开启过
|
||||
LocalDateTime lastOperaTime = device.getUserOperaTime(); // 上次开启的时间
|
||||
BigDecimal lastOperaEle = device.getUserOperaEle(); // 上次开启的总用电量
|
||||
|
||||
boolean hasOpenAfterExpireTime = hasOpen && lastOperaTime != null && lastOperaTime.isAfter(device.getExpireTime()); // 是否在时间结束后开启
|
||||
boolean hasTime = device.getSurplusSecondsDb() > 0; // 剩余时间
|
||||
boolean hasOpenAfterExpireEle = hasOpen && lastOperaEle != null && lastOperaEle.compareTo(device.getExpireEle()) > 0; // 是否在结束电量后开启
|
||||
boolean hasEle = device.getSurplusEleDb().compareTo(BigDecimal.ZERO) > 0; // 剩余电量
|
||||
if (!hasTime && !hasEle && !hasOpenAfterExpireTime && !hasOpenAfterExpireEle) {
|
||||
this.switchDevice(device, DevicePowerStatus.OFF, "设备监控-发现异常未关闭设备");
|
||||
}
|
||||
},0, TimeUnit.SECONDS);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("监控设备id={}出错:{}", deviceId, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<Long> selectIds(DeviceQuery query) {
|
||||
return deviceMapper.selectIds(query);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ruoyi.ss.transactionBill.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
|
@ -50,7 +49,7 @@ public class RechargeDepositAfterPay implements AfterPay {
|
|||
|
||||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
ServiceUtil.assertion(device == null, "设备不存在");
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
Integer result = transactionTemplate.execute(status -> {
|
||||
// 修改订单信息
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package com.ruoyi.ss.transactionBill.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.ss.bonus.domain.BonusVO;
|
||||
import com.ruoyi.ss.bonus.domain.enums.BonusArrivalType;
|
||||
import com.ruoyi.ss.bonus.service.BonusService;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceIotResultVO;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
import com.ruoyi.ss.payBill.domain.PayBillVO;
|
||||
|
@ -101,7 +98,7 @@ public class RechargePayHandler implements AfterPay, AfterRefund {
|
|||
|
||||
// 设备信息
|
||||
DeviceVO device = bo.getDevice();
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
List<BonusVO> bonusList = bill.getBonusList();
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.ruoyi.ss.transactionBill.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
@ -19,7 +18,10 @@ import com.ruoyi.ss.store.service.StoreService;
|
|||
import com.ruoyi.ss.suit.domain.SuitVO;
|
||||
import com.ruoyi.ss.suit.service.SuitAssembler;
|
||||
import com.ruoyi.ss.suit.service.SuitService;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.EndUseBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargeBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargePayDepositBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.WithdrawBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.service.TransactionBillConverter;
|
||||
|
@ -192,7 +194,7 @@ public class TransactionBillConverterImpl implements TransactionBillConverter {
|
|||
bo.setTotalEle(dto.getTotalEle());
|
||||
if (order != null) {
|
||||
DeviceVO device = deviceService.selectById(order.getDeviceId());
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
bo.setDevice(device);
|
||||
}
|
||||
return bo;
|
||||
|
|
|
@ -3,14 +3,18 @@ package com.ruoyi.ss.transactionBill.service.impl;
|
|||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.core.redis.RedisLock;
|
||||
import com.ruoyi.common.core.redis.enums.RedisLockKey;
|
||||
import com.ruoyi.common.enums.ServiceCode;
|
||||
import com.ruoyi.common.enums.WithdrawServiceType;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.*;
|
||||
import com.ruoyi.common.pay.wx.service.WxPayService;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.SnowFlakeUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.dashboard.domain.vo.BillCountVo;
|
||||
import com.ruoyi.iot.domain.response.CommandResponse;
|
||||
import com.ruoyi.iot.service.IotService;
|
||||
import com.ruoyi.ss.account.domain.AccountVO;
|
||||
|
@ -23,7 +27,6 @@ import com.ruoyi.ss.bonus.service.BonusConverter;
|
|||
import com.ruoyi.ss.bonus.service.BonusService;
|
||||
import com.ruoyi.ss.channelWithdraw.domain.ChannelWithdrawVO;
|
||||
import com.ruoyi.ss.channelWithdraw.service.ChannelWithdrawService;
|
||||
import com.ruoyi.dashboard.domain.vo.BillCountVo;
|
||||
import com.ruoyi.ss.device.domain.enums.DevicePowerStatus;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
|
@ -49,10 +52,16 @@ import com.ruoyi.ss.suit.domain.enums.SuitFeeType;
|
|||
import com.ruoyi.ss.suit.domain.enums.SuitTimeUnit;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBill;
|
||||
import com.ruoyi.ss.transactionBill.domain.TransactionBillQuery;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.EndUseBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargeBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.RechargePayDepositBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.bo.WithdrawBO;
|
||||
import com.ruoyi.ss.transactionBill.domain.dto.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.enums.*;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionAmountVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionBillVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.TransactionDailyAmountVO;
|
||||
import com.ruoyi.ss.transactionBill.domain.vo.UserWithdrawServiceVO;
|
||||
import com.ruoyi.ss.transactionBill.mapper.TransactionBillMapper;
|
||||
import com.ruoyi.ss.transactionBill.service.*;
|
||||
import com.ruoyi.ss.transfer.domain.TransferVO;
|
||||
|
@ -61,7 +70,6 @@ import com.ruoyi.ss.transfer.service.TransferConverter;
|
|||
import com.ruoyi.ss.transfer.service.TransferService;
|
||||
import com.ruoyi.ss.user.domain.SmUserVO;
|
||||
import com.ruoyi.ss.user.service.ISmUserService;
|
||||
import com.ruoyi.common.pay.wx.service.WxPayService;
|
||||
import com.ruoyi.system.domain.enums.config.ConfigKey;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.task.bill.BillDelayedManager;
|
||||
|
@ -261,7 +269,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
ServiceUtil.assertion(!redisLock.lock(RedisLockKey.ADD_RECHARGE_ORDER, deviceId), "当前使用该设备人数较多,请稍后再试");
|
||||
try {
|
||||
// 拉取设备信息
|
||||
deviceService.pullDeviceInfo(bo.getDevice().getDeviceId(), IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(bo.getDevice().getDeviceId());
|
||||
|
||||
// 生成订单
|
||||
TransactionBill order = parseToOrder(bo);
|
||||
|
@ -865,7 +873,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
|
||||
// 获取最新设备信息
|
||||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
// 充值设备
|
||||
Boolean iotResult = transactionTemplate.execute(status -> {
|
||||
|
@ -1138,7 +1146,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
// 计量收费,则获取最新的设备信息
|
||||
if(SuitFeeType.COUNT.getType().equals(bill.getSuitFeeType()) || SuitFeeType.TIMING_COUNT.getType().equals(bill.getSuitFeeType())) {
|
||||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
totalEle = this.calcTotalEle(device, totalEle);
|
||||
}
|
||||
|
||||
|
@ -1539,7 +1547,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
ServiceUtil.assertion(!TransactionBillStatus.SUCCESS.getStatus().equals(bill.getStatus()), "订单尚未充值成功", 10004);
|
||||
|
||||
// 拉取设备信息
|
||||
deviceService.pullDeviceInfo(bill.getDeviceId(), IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(bill.getDeviceId());
|
||||
|
||||
Integer execute = transactionTemplate.execute(status -> {
|
||||
// 更新设备充值状态
|
||||
|
@ -1823,7 +1831,7 @@ public class TransactionBillServiceImpl implements TransactionBillService, After
|
|||
DeviceVO device = deviceService.selectById(bill.getDeviceId());
|
||||
ServiceUtil.assertion(device == null, "设备不存在");
|
||||
ServiceUtil.assertion(StringUtils.isAllBlank(device.getMac(), device.getMac2()), "设备MAC为空,请联系管理员处理");
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
|
||||
// 开启
|
||||
if (open) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ruoyi.web.controller.app;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
@ -75,7 +74,7 @@ public class AppDeviceAdminController extends BaseController {
|
|||
return error("上报数据失败");
|
||||
}
|
||||
Threads.sleep(3000);
|
||||
deviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfo(device);
|
||||
return success(device);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.ruoyi.web.controller.app;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonView;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.JsonViewProfile;
|
||||
|
@ -13,18 +12,18 @@ import com.ruoyi.common.enums.OperatorType;
|
|||
import com.ruoyi.common.utils.ServiceUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.collection.CollectionUtils;
|
||||
import com.ruoyi.ss.device.domain.DeviceView;
|
||||
import com.ruoyi.ss.device.domain.Device;
|
||||
import com.ruoyi.ss.device.domain.DeviceBO;
|
||||
import com.ruoyi.ss.device.domain.DeviceQuery;
|
||||
import com.ruoyi.ss.device.domain.DeviceView;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceRegisterDTO;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
|
||||
import com.ruoyi.ss.device.domain.enums.DevicePowerStatus;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
import com.ruoyi.ss.device.service.DeviceAssembler;
|
||||
import com.ruoyi.ss.device.service.DeviceConverter;
|
||||
import com.ruoyi.ss.device.service.DeviceValidator;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
import com.ruoyi.ss.device.service.DeviceValidator;
|
||||
import com.ruoyi.ss.meterReadingRecord.domain.SmMeterReadingRecordQuery;
|
||||
import com.ruoyi.ss.meterReadingRecord.service.ISmMeterReadingRecordService;
|
||||
import com.ruoyi.ss.suit.domain.enums.SuitTimeUnit;
|
||||
|
@ -97,7 +96,7 @@ public class AppDeviceController extends BaseController {
|
|||
startOrderBy();
|
||||
smDevice.setUserId(getUserId());
|
||||
List<DeviceVO> list = smDeviceService.selectSmDeviceList(smDevice);
|
||||
smDeviceService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_GET);
|
||||
smDeviceService.pullDeviceInfoList(list);
|
||||
deviceAssembler.assembleRealServiceRate(list);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
@ -109,7 +108,7 @@ public class AppDeviceController extends BaseController {
|
|||
startPage();
|
||||
query.setStoreId(storeId);
|
||||
List<DeviceVO> list = smDeviceService.selectSmDeviceList(query);
|
||||
smDeviceService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_GET);
|
||||
smDeviceService.pullDeviceInfoList(list);
|
||||
deviceAssembler.assembleBusinessTime(list); // 店铺营业时间
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
@ -140,7 +139,7 @@ public class AppDeviceController extends BaseController {
|
|||
ServiceUtil.assertion(!device.getAllowSwitch(), "您无权操作此设备");
|
||||
|
||||
// 获取最新数据
|
||||
smDeviceService.pullDeviceInfo(device, IotConstants.ONLINE_TYPE_GET);
|
||||
smDeviceService.pullDeviceInfo(device);
|
||||
|
||||
DevicePowerStatus powerStatus = DevicePowerStatus.parse(status);
|
||||
return toAjax(smDeviceService.switchDevice(device, powerStatus, "商户开关设备"));
|
||||
|
@ -216,9 +215,8 @@ public class AppDeviceController extends BaseController {
|
|||
|
||||
@ApiOperation("刷新设备信息")
|
||||
@GetMapping("/{deviceId}/refreshIot")
|
||||
public AjaxResult syncIot(@PathVariable @ApiParam("设备id") Long deviceId,
|
||||
@RequestParam(required = false, defaultValue = IotConstants.ONLINE_TYPE_GET) String onlineType) {
|
||||
smDeviceService.pullDeviceInfo(deviceId, onlineType);
|
||||
public AjaxResult syncIot(@PathVariable @ApiParam("设备id") Long deviceId) {
|
||||
smDeviceService.pullDeviceInfo(deviceId);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
@ -226,8 +224,7 @@ public class AppDeviceController extends BaseController {
|
|||
@GetMapping("/v2/refreshIot")
|
||||
public AjaxResult syncIotBySn(@RequestParam(required = false) Long deviceId,
|
||||
@RequestParam(required = false) String deviceNo,
|
||||
@RequestParam(required = false) String mac,
|
||||
@RequestParam(required = false, defaultValue = IotConstants.ONLINE_TYPE_GET) String onlineType) {
|
||||
@RequestParam(required = false) String mac) {
|
||||
DeviceVO device = null;
|
||||
if (deviceId != null) {
|
||||
device = smDeviceService.selectById(deviceId);
|
||||
|
@ -238,7 +235,7 @@ public class AppDeviceController extends BaseController {
|
|||
} else {
|
||||
return error("设备ID、SN、MAC必须传入其中一个");
|
||||
}
|
||||
smDeviceService.pullDeviceInfo(device, onlineType);
|
||||
smDeviceService.pullDeviceInfo(device);
|
||||
return success(device);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
package com.ruoyi.web.controller.ss;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.ValidGroup;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.ss.device.domain.DeviceBO;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
|
||||
import com.ruoyi.ss.device.domain.DeviceQuery;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceBatchUpdateModelDTO;
|
||||
import com.ruoyi.ss.device.domain.dto.DeviceWifiDTO;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceIotResultVO;
|
||||
import com.ruoyi.ss.device.domain.vo.DeviceVO;
|
||||
import com.ruoyi.ss.device.service.DeviceAssembler;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
import com.ruoyi.ss.suit.domain.enums.SuitTimeUnit;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.ss.device.service.DeviceService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备Controller
|
||||
|
@ -53,7 +51,7 @@ public class SmDeviceController extends BaseController
|
|||
{
|
||||
startPage();
|
||||
List<DeviceVO> list = deviceService.selectSmDeviceList(smDevice);
|
||||
deviceService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfoList(list);
|
||||
deviceAssembler.assembleRealServiceRate(list);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
@ -144,7 +142,7 @@ public class SmDeviceController extends BaseController
|
|||
@GetMapping("/{deviceId}/refreshIot")
|
||||
public AjaxResult syncIot(@PathVariable @ApiParam("设备id") Long deviceId,
|
||||
@RequestParam(required = false, defaultValue = IotConstants.ONLINE_TYPE_GET) String onlineType) {
|
||||
deviceService.pullDeviceInfo(deviceId, onlineType);
|
||||
deviceService.pullDeviceInfo(deviceId);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.ruoyi.web.controller.staff;
|
||||
|
||||
import com.ruoyi.common.constant.IotConstants;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.ss.device.domain.DeviceQuery;
|
||||
|
@ -38,7 +37,7 @@ public class StaffDeviceController extends BaseController {
|
|||
query.setStaffUserId(getUserId());
|
||||
query.setStaffPermission(StoreStaffPermissions.DEVICE_VIEW.getCode());
|
||||
List<DeviceVO> list = deviceService.selectStaffDeviceList(query);
|
||||
deviceService.pullDeviceInfoList(list, IotConstants.ONLINE_TYPE_GET);
|
||||
deviceService.pullDeviceInfoList(list);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user