设备型号配置产品ID
This commit is contained in:
parent
91c924d69b
commit
6ef84a9fe3
|
@ -18,12 +18,14 @@ import java.util.List;
|
||||||
public interface IotService {
|
public interface IotService {
|
||||||
/**
|
/**
|
||||||
* 向设备发送命令
|
* 向设备发送命令
|
||||||
|
*
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
* @param command 命令字符串
|
* @param command 命令字符串
|
||||||
|
* @param productId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default CommandResponse sendCommand(String deviceName, String command) {
|
default CommandResponse sendCommand(String deviceName, String command, String productId) {
|
||||||
return sendCommand(deviceName, command, null);
|
return sendCommand(deviceName, command, null, productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,84 +34,106 @@ public interface IotService {
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
* @param command 命令字符串
|
* @param command 命令字符串
|
||||||
* @param timeout
|
* @param timeout
|
||||||
|
* @param productId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
CommandResponse sendCommand(String deviceName, String command, Integer timeout);
|
CommandResponse sendCommand(String deviceName, String command, Integer timeout, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备在线状态
|
* 获取设备在线状态
|
||||||
|
*
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
DeviceOnlineStatus getOnlineStatus(String deviceName);
|
DeviceOnlineStatus getOnlineStatus(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通电
|
* 通电
|
||||||
|
*
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
|
* @param productId
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean open(String deviceName);
|
boolean open(String deviceName, String productId);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 断电
|
* 断电
|
||||||
|
*
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
|
* @param productId
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
boolean close(String deviceName);
|
boolean close(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取历史设备数据点信息
|
* 获取历史设备数据点信息
|
||||||
|
*
|
||||||
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
* @param deviceName OneNet设备名称(即设备表的MAC号)
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
HistoryDeviceData getHistoryDataPoint(String deviceName);
|
HistoryDeviceData getHistoryDataPoint(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量获取当前设备数据点信息
|
* 批量获取当前设备数据点信息
|
||||||
|
*
|
||||||
* @param deviceNames 设备名称列表
|
* @param deviceNames 设备名称列表
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames);
|
List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前设备数据点信息
|
* 获取当前设备数据点信息
|
||||||
|
*
|
||||||
* @param deviceName 设备名称
|
* @param deviceName 设备名称
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
CurrentDeviceData getCurrentDataPoint(String deviceName);
|
CurrentDeviceData getCurrentDataPoint(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备详情
|
* 获取设备详情
|
||||||
|
*
|
||||||
* @param deviceName 设备名称
|
* @param deviceName 设备名称
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
IotDeviceDetail getDeviceDetail(String deviceName);
|
IotDeviceDetail getDeviceDetail(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置剩余时长
|
* 设置剩余时长
|
||||||
*
|
*
|
||||||
* @param deviceName 设备名称
|
* @param deviceName 设备名称
|
||||||
* @param seconds 时长(秒)
|
* @param seconds 时长(秒)
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
CommandResponse setTime(String deviceName, long seconds);
|
CommandResponse setTime(String deviceName, long seconds, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备信息
|
* 更新设备信息
|
||||||
* @param device 设备信息
|
*
|
||||||
|
* @param device 设备信息
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
boolean updateDevice(Device device);
|
boolean updateDevice(Device device, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备信息,并转化为IotDeviceInfo
|
* 获取设备信息,并转化为IotDeviceInfo
|
||||||
|
*
|
||||||
* @param deviceName 设备名称
|
* @param deviceName 设备名称
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
IotDeviceInfo getDeviceInfo(String deviceName);
|
IotDeviceInfo getDeviceInfo(String deviceName, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备信息列表,并转换为IotDeviceInfo
|
* 获取设备信息列表,并转换为IotDeviceInfo
|
||||||
|
*
|
||||||
* @param deviceNames 设备名称列表
|
* @param deviceNames 设备名称列表
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
List<IotDeviceInfo> getDeviceInfo(List<String> deviceNames);
|
List<IotDeviceInfo> getDeviceInfo(List<String> deviceNames, String productId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册设备
|
* 注册设备
|
||||||
*/
|
*/
|
||||||
int create(String mac);
|
int create(String mac, String productId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,6 @@ public class IotServiceImpl implements IotService {
|
||||||
@Value("${sm.iotHost}")
|
@Value("${sm.iotHost}")
|
||||||
private String iotHost;
|
private String iotHost;
|
||||||
|
|
||||||
@Value(value = "${sm.productId}")
|
|
||||||
private String productId;
|
|
||||||
|
|
||||||
@Value(value = "${sm.version}")
|
@Value(value = "${sm.version}")
|
||||||
private String version;
|
private String version;
|
||||||
|
|
||||||
|
@ -63,14 +60,14 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 查询OneNet设备在线状态
|
// 查询OneNet设备在线状态
|
||||||
@Override
|
@Override
|
||||||
public DeviceOnlineStatus getOnlineStatus(String deviceName) {
|
public DeviceOnlineStatus getOnlineStatus(String deviceName, String productId) {
|
||||||
if (StringUtils.isBlank(deviceName)) {
|
if (StringUtils.isBlank(deviceName)) {
|
||||||
return DeviceOnlineStatus.OFFLINE;
|
return DeviceOnlineStatus.OFFLINE;
|
||||||
}
|
}
|
||||||
// CommandResponse response = sendCommand(deviceName, "111");
|
// CommandResponse response = sendCommand(deviceName, "111");
|
||||||
// return IotHttpStatus.SUCCESS.getCode().equals(response.getCode()) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
// return IotHttpStatus.SUCCESS.getCode().equals(response.getCode()) ? DeviceOnlineStatus.ONLINE : DeviceOnlineStatus.OFFLINE;
|
||||||
|
|
||||||
IotDeviceDetail detail = this.getDeviceDetail(deviceName);
|
IotDeviceDetail detail = this.getDeviceDetail(deviceName, productId);
|
||||||
if (detail == null) {
|
if (detail == null) {
|
||||||
return DeviceOnlineStatus.OFFLINE;
|
return DeviceOnlineStatus.OFFLINE;
|
||||||
}
|
}
|
||||||
|
@ -80,8 +77,8 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 通电
|
// 通电
|
||||||
@Override
|
@Override
|
||||||
public boolean open(String deviceName) {
|
public boolean open(String deviceName, String productId) {
|
||||||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN);
|
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN, productId);
|
||||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||||
throw new ServiceException("通电发生异常:" + status.getMsg());
|
throw new ServiceException("通电发生异常:" + status.getMsg());
|
||||||
|
@ -91,8 +88,8 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 断电
|
// 断电
|
||||||
@Override
|
@Override
|
||||||
public boolean close(String deviceName) {
|
public boolean close(String deviceName, String productId) {
|
||||||
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE);
|
CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE, productId);
|
||||||
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode());
|
||||||
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
if (!IotHttpStatus.SUCCESS.equals(status)) {
|
||||||
throw new ServiceException("断电发生异常:" + status.getMsg());
|
throw new ServiceException("断电发生异常:" + status.getMsg());
|
||||||
|
@ -102,7 +99,7 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 获取历史设备数据点信息
|
// 获取历史设备数据点信息
|
||||||
@Override
|
@Override
|
||||||
public HistoryDeviceData getHistoryDataPoint(String deviceName) {
|
public HistoryDeviceData getHistoryDataPoint(String deviceName, String productId) {
|
||||||
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
||||||
String sendUrl = iotHost + IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
String sendUrl = iotHost + IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param;
|
||||||
|
|
||||||
|
@ -125,7 +122,7 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 获取当前设备数据点信息
|
// 获取当前设备数据点信息
|
||||||
@Override
|
@Override
|
||||||
public List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames) {
|
public List<CurrentDeviceData> getCurrentDataPoint(List<String> deviceNames, String productId) {
|
||||||
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;
|
||||||
|
|
||||||
|
@ -147,8 +144,8 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 获取当前设备数据点信息
|
// 获取当前设备数据点信息
|
||||||
@Override
|
@Override
|
||||||
public CurrentDeviceData getCurrentDataPoint(String deviceName) {
|
public CurrentDeviceData getCurrentDataPoint(String deviceName, String productId) {
|
||||||
List<CurrentDeviceData> list = this.getCurrentDataPoint(Collections.singletonList(deviceName));
|
List<CurrentDeviceData> list = this.getCurrentDataPoint(Collections.singletonList(deviceName), productId);
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +153,7 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotDeviceDetail getDeviceDetail(String deviceName) {
|
public IotDeviceDetail getDeviceDetail(String deviceName, String productId) {
|
||||||
String sendUrl = iotHost + IotConstants.ADDS_DEVICE_DETAIL;
|
String sendUrl = iotHost + IotConstants.ADDS_DEVICE_DETAIL;
|
||||||
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
String param = "device_name=" + deviceName + "&product_id=" + productId;
|
||||||
|
|
||||||
|
@ -182,45 +179,44 @@ public class IotServiceImpl implements IotService {
|
||||||
*
|
*
|
||||||
* @param deviceName 设备名称
|
* @param deviceName 设备名称
|
||||||
* @param seconds 时长(秒)
|
* @param seconds 时长(秒)
|
||||||
|
* @param productId
|
||||||
* @return 是否成功
|
* @return 是否成功
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CommandResponse setTime(String deviceName, long seconds) {
|
public CommandResponse setTime(String deviceName, long seconds, String productId) {
|
||||||
if (seconds < 0) {
|
if (seconds < 0) {
|
||||||
throw new ServiceException("设置剩余时长参数错误:读数不允许小于0");
|
throw new ServiceException("设置剩余时长参数错误:读数不允许小于0");
|
||||||
}
|
}
|
||||||
return sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR, 5);
|
return sendCommand(deviceName, IotConstants.COMMAND_RECHARGE + seconds + IotConstants.COMMAND_SEPARATOR, 5, productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备信息
|
* 更新设备信息
|
||||||
* @param device 设备信息
|
*
|
||||||
|
* @param device 设备信息
|
||||||
|
* @param productId
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public boolean updateDevice(Device device) {
|
public boolean updateDevice(Device device, String productId) {
|
||||||
// DEBUG模式下直接返回true
|
|
||||||
if (debug) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
DeviceOutageWay deviceOutageWay = DeviceOutageWay.parse(device.getOutageWay());
|
DeviceOutageWay deviceOutageWay = DeviceOutageWay.parse(device.getOutageWay());
|
||||||
|
|
||||||
String command = CommandBuilder.builder()
|
String command = CommandBuilder.builder()
|
||||||
// 断电方式,若为空,则立即断电
|
// 断电方式,若为空,则立即断电
|
||||||
.setIfNull(IotConstants.COMMAND_OUTAGE_WAY, deviceOutageWay.getValue() , DeviceOutageWay.IMMEDIATE.getValue())
|
.setIfNull(IotConstants.COMMAND_OUTAGE_WAY, deviceOutageWay.getValue() , DeviceOutageWay.IMMEDIATE.getValue())
|
||||||
.build();
|
.build();
|
||||||
CommandResponse response = sendCommand(device.getMac(), command);
|
CommandResponse response = sendCommand(device.getMac(), command, productId);
|
||||||
ServiceUtil.assertion(!Objects.equals(IotHttpStatus.SUCCESS.getCode(), response.getCode()), "修改设备设置发生异常:" + response.getMsg());
|
ServiceUtil.assertion(!Objects.equals(IotHttpStatus.SUCCESS.getCode(), response.getCode()), "修改设备设置发生异常:" + response.getMsg());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IotDeviceInfo getDeviceInfo(String deviceName) {
|
public IotDeviceInfo getDeviceInfo(String deviceName, String productId) {
|
||||||
if (StringUtils.isBlank(deviceName)) {
|
if (StringUtils.isBlank(deviceName)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
CurrentDeviceData currentDataPoint = getCurrentDataPoint(deviceName);
|
CurrentDeviceData currentDataPoint = getCurrentDataPoint(deviceName, productId);
|
||||||
if (currentDataPoint == null) {
|
if (currentDataPoint == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -228,11 +224,11 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<IotDeviceInfo> getDeviceInfo(List<String> deviceNames) {
|
public List<IotDeviceInfo> getDeviceInfo(List<String> deviceNames, String productId) {
|
||||||
if (CollectionUtils.isEmpty(deviceNames)) {
|
if (CollectionUtils.isEmpty(deviceNames)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
List<CurrentDeviceData> dataList = getCurrentDataPoint(deviceNames);
|
List<CurrentDeviceData> dataList = getCurrentDataPoint(deviceNames, productId);
|
||||||
if (CollectionUtils.isEmpty(dataList)) {
|
if (CollectionUtils.isEmpty(dataList)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -240,7 +236,7 @@ public class IotServiceImpl implements IotService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int create(String mac) {
|
public int create(String mac, String productId) {
|
||||||
String sendUrl = iotHost + IotConstants.CREATE_DEVICE;
|
String sendUrl = iotHost + IotConstants.CREATE_DEVICE;
|
||||||
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
|
CreateDeviceVo createDeviceVo = new CreateDeviceVo();
|
||||||
createDeviceVo.setDevice_name(mac);
|
createDeviceVo.setDevice_name(mac);
|
||||||
|
@ -256,7 +252,7 @@ public class IotServiceImpl implements IotService {
|
||||||
|
|
||||||
// 发送MQTT命令
|
// 发送MQTT命令
|
||||||
@Override
|
@Override
|
||||||
public CommandResponse sendCommand(String deviceName, String command, Integer timeout) {
|
public CommandResponse sendCommand(String deviceName, String command, Integer timeout, String productId) {
|
||||||
if (timeout == null) {
|
if (timeout == null) {
|
||||||
timeout = this.timeout;
|
timeout = this.timeout;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,4 +71,6 @@ public class DeviceVO extends Device {
|
||||||
@JsonView(DeviceView.SuitList.class)
|
@JsonView(DeviceView.SuitList.class)
|
||||||
private String storeContactMobile;
|
private String storeContactMobile;
|
||||||
|
|
||||||
|
@ApiModelProperty("型号产品ID")
|
||||||
|
private String modelProductId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
sm.model_name as model,
|
sm.model_name as model,
|
||||||
sm.picture as picture,
|
sm.picture as picture,
|
||||||
sm.tags as model_tags,
|
sm.tags as model_tags,
|
||||||
|
sm.product_id as model_product_id,
|
||||||
ss.name as store_name,
|
ss.name as store_name,
|
||||||
ss.contact_name as store_contact_name,
|
ss.contact_name as store_contact_name,
|
||||||
ss.contact_mobile as store_contact_mobile,
|
ss.contact_mobile as store_contact_mobile,
|
||||||
|
|
|
@ -27,9 +27,4 @@ public interface DeviceAssembler {
|
||||||
*/
|
*/
|
||||||
void assembleOrderCountInfo(List<DeviceVO> list);
|
void assembleOrderCountInfo(List<DeviceVO> list);
|
||||||
|
|
||||||
/**
|
|
||||||
* 拼接物联网数据
|
|
||||||
* @param list
|
|
||||||
*/
|
|
||||||
void assembleIotDeviceInfo(List<DeviceVO> list);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,18 +37,12 @@ import java.util.stream.Collectors;
|
||||||
@Service
|
@Service
|
||||||
public class DeviceAssemblerImpl implements DeviceAssembler {
|
public class DeviceAssemblerImpl implements DeviceAssembler {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SuitService suitService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private StoreService storeService;
|
private StoreService storeService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransactionBillService transactionBillService;
|
private TransactionBillService transactionBillService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private IotService iotService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DeviceSuitService deviceSuitService;
|
private DeviceSuitService deviceSuitService;
|
||||||
|
|
||||||
|
@ -126,37 +120,4 @@ public class DeviceAssemblerImpl implements DeviceAssembler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void assembleIotDeviceInfo(List<DeviceVO> list) {
|
|
||||||
if (CollectionUtils.isEmptyElement(list)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 获取当前设备数据
|
|
||||||
List<String> deviceNames = list.stream().map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList());
|
|
||||||
if (CollectionUtils.isEmpty(deviceNames)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Map<String, IotDeviceInfo> deviceInfoMap = iotService.getDeviceInfo(deviceNames)
|
|
||||||
.stream().collect(Collectors.toMap(IotDeviceInfo::getMac, item -> item));
|
|
||||||
|
|
||||||
// 拼接数据
|
|
||||||
for (DeviceVO device : list) {
|
|
||||||
if (StringUtils.hasText(device.getMac())) {
|
|
||||||
// 在线状态
|
|
||||||
device.setOnlineStatus(iotService.getOnlineStatus(device.getMac()).getStatus());
|
|
||||||
|
|
||||||
// 其他信息
|
|
||||||
IotDeviceInfo deviceInfo = deviceInfoMap.get(device.getMac());
|
|
||||||
if (deviceInfo != null) {
|
|
||||||
device.setElectricity(deviceInfo.getA());
|
|
||||||
device.setVoltage(deviceInfo.getV());
|
|
||||||
device.setRealTimePower(deviceInfo.getP());
|
|
||||||
device.setTotalElectriQuantity(deviceInfo.getW()); // 电量
|
|
||||||
device.setRemainTime(deviceInfo.getTime());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
device.setOnlineStatus(DeviceOnlineStatus.OFFLINE.getStatus());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,8 +161,12 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
ServiceUtil.assertion(deviceValidator.isRepeatMac(data.getDeviceId(), data.getMac()), "MAC重复");
|
ServiceUtil.assertion(deviceValidator.isRepeatMac(data.getDeviceId(), data.getMac()), "MAC重复");
|
||||||
ServiceUtil.assertion(deviceValidator.isRepeatSn(data.getDeviceId(), data.getDeviceNo()), "SN重复");
|
ServiceUtil.assertion(deviceValidator.isRepeatSn(data.getDeviceId(), data.getDeviceNo()), "SN重复");
|
||||||
|
|
||||||
|
SmModelVO model = modelService.selectSmModelByModelId(data.getModelId());
|
||||||
|
ServiceUtil.assertion(model == null, "型号不存在");
|
||||||
|
ServiceUtil.assertion(StringUtils.isBlank(model.getProductId()), "型号产品ID为空");
|
||||||
|
|
||||||
// 创建OneNet设备
|
// 创建OneNet设备
|
||||||
int code = iotService.create(data.getMac());
|
int code = iotService.create(data.getMac(), model.getProductId());
|
||||||
ServiceUtil.assertion(!IotHttpStatus.SUCCESS.equalCode(code) && !IotHttpStatus.DEVICE_EXIST.equalCode(code), "设备注册失败");
|
ServiceUtil.assertion(!IotHttpStatus.SUCCESS.equalCode(code) && !IotHttpStatus.DEVICE_EXIST.equalCode(code), "设备注册失败");
|
||||||
|
|
||||||
data.setCreateTime(DateUtils.getNowDate());
|
data.setCreateTime(DateUtils.getNowDate());
|
||||||
|
@ -377,9 +381,9 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
DeviceVO device = selectSmDeviceByDeviceId(deviceId);
|
DeviceVO device = selectSmDeviceByDeviceId(deviceId);
|
||||||
ServiceUtil.assertion(device == null, "设备不存在");
|
ServiceUtil.assertion(device == null, "设备不存在");
|
||||||
if (open) {
|
if (open) {
|
||||||
return iotService.open(device.getMac());
|
return iotService.open(device.getMac(), device.getModelProductId());
|
||||||
} else {
|
} else {
|
||||||
return iotService.close(device.getMac());
|
return iotService.close(device.getMac(), device.getModelProductId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +426,7 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
DeviceVO newDevice = selectSmDeviceByDeviceId(deviceId);
|
DeviceVO newDevice = selectSmDeviceByDeviceId(deviceId);
|
||||||
long betweenSeconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
|
long betweenSeconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds();
|
||||||
if (betweenSeconds > 0) {
|
if (betweenSeconds > 0) {
|
||||||
CommandResponse rechargeResult = iotService.setTime(device.getMac(), betweenSeconds);
|
CommandResponse rechargeResult = iotService.setTime(device.getMac(), betweenSeconds, device.getModelProductId());
|
||||||
ServiceUtil.assertion(!rechargeResult.isSuccess(), "设备充值失败,请检查设备是否在线");
|
ServiceUtil.assertion(!rechargeResult.isSuccess(), "设备充值失败,请检查设备是否在线");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -481,14 +485,14 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
@Override
|
@Override
|
||||||
public void deviceHeartBeat() {
|
public void deviceHeartBeat() {
|
||||||
log.info("device heart beat running...");
|
log.info("device heart beat running...");
|
||||||
List<DeviceVO> list = deviceMapper.selectSimpleList(new DeviceQuery());
|
List<DeviceVO> list = deviceMapper.selectSmDeviceList(new DeviceQuery());
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
log.info("device list is empty");
|
log.info("device list is empty");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (DeviceVO device : list) {
|
for (DeviceVO device : list) {
|
||||||
if (StringUtils.hasText(device.getMac())) {
|
if (StringUtils.hasText(device.getMac())) {
|
||||||
String status = iotService.getOnlineStatus(device.getMac()).getStatus();
|
String status = iotService.getOnlineStatus(device.getMac(), device.getModelProductId()).getStatus();
|
||||||
log.info("device: {} {} online status is {}", device.getDeviceId(), device.getMac(), status);
|
log.info("device: {} {} online status is {}", device.getDeviceId(), device.getMac(), status);
|
||||||
device.setOnlineStatus(status);
|
device.setOnlineStatus(status);
|
||||||
} else {
|
} else {
|
||||||
|
@ -542,9 +546,9 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
ServiceUtil.assertion(!UserUtil.hasFrontUser(device.getUserId()), "该设备不是您的,无法进行该操作" );
|
ServiceUtil.assertion(!UserUtil.hasFrontUser(device.getUserId()), "该设备不是您的,无法进行该操作" );
|
||||||
|
|
||||||
if (DevicePowerStatus.ON.equals(status)) {
|
if (DevicePowerStatus.ON.equals(status)) {
|
||||||
iotService.open(device.getMac());
|
iotService.open(device.getMac(), device.getModelProductId());
|
||||||
} else if (DevicePowerStatus.OFF.equals(status)) {
|
} else if (DevicePowerStatus.OFF.equals(status)) {
|
||||||
iotService.close(device.getMac());
|
iotService.close(device.getMac(), device.getModelProductId());
|
||||||
} else {
|
} else {
|
||||||
throw new ServiceException("不支持的操作");
|
throw new ServiceException("不支持的操作");
|
||||||
}
|
}
|
||||||
|
@ -568,23 +572,22 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
// 查询设备列表
|
// 查询设备列表
|
||||||
DeviceQuery dto = new DeviceQuery();
|
DeviceQuery dto = new DeviceQuery();
|
||||||
dto.setDeviceIds(deviceIds);
|
dto.setDeviceIds(deviceIds);
|
||||||
List<DeviceVO> list = deviceMapper.selectSimpleList(dto);
|
List<DeviceVO> list = deviceMapper.selectSmDeviceList(dto);
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取数据点信息
|
|
||||||
List<String> deviceNames = list.stream().map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList());
|
|
||||||
List<IotDeviceInfo> deviceInfos = iotService.getDeviceInfo(deviceNames);
|
|
||||||
|
|
||||||
// 更新数据
|
|
||||||
for (DeviceVO device : list) {
|
for (DeviceVO device : list) {
|
||||||
try {
|
try {
|
||||||
IotDeviceInfo deviceInfo = deviceInfos.stream().filter(item -> Objects.equals(device.getMac(), item.getMac())).findFirst().orElse(null);
|
if (StringUtils.isAnyBlank(device.getMac(), device.getModelProductId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 获取数据点信息
|
||||||
|
IotDeviceInfo deviceInfo = iotService.getDeviceInfo(device.getMac(), device.getModelProductId());
|
||||||
|
|
||||||
|
// 更新设备信息
|
||||||
Device data = new Device();
|
Device data = new Device();
|
||||||
data.setDeviceId(device.getDeviceId());
|
data.setDeviceId(device.getDeviceId());
|
||||||
|
|
||||||
// 设备信息
|
|
||||||
if (deviceInfo != null) {
|
if (deviceInfo != null) {
|
||||||
data.setLastPullTime(deviceInfo.getAt());
|
data.setLastPullTime(deviceInfo.getAt());
|
||||||
data.setTotalElectriQuantity(deviceInfo.getW());
|
data.setTotalElectriQuantity(deviceInfo.getW());
|
||||||
|
@ -594,7 +597,7 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
}
|
}
|
||||||
|
|
||||||
// 是否在线
|
// 是否在线
|
||||||
data.setOnlineStatus(iotService.getOnlineStatus(device.getMac()).getStatus());
|
data.setOnlineStatus(iotService.getOnlineStatus(device.getMac(), device.getModelProductId()).getStatus());
|
||||||
|
|
||||||
deviceMapper.updateSmDevice(data);
|
deviceMapper.updateSmDevice(data);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -707,7 +710,7 @@ public class DeviceServiceImpl implements DeviceService
|
||||||
transactionBillService.batchEndBillByDevice(deviceId);
|
transactionBillService.batchEndBillByDevice(deviceId);
|
||||||
|
|
||||||
// 物联网设备归零
|
// 物联网设备归零
|
||||||
CommandResponse commandResponse = iotService.setTime(device.getMac(), 1L);
|
CommandResponse commandResponse = iotService.setTime(device.getMac(), 1L, device.getModelProductId());
|
||||||
ServiceUtil.assertion(!commandResponse.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
|
ServiceUtil.assertion(!commandResponse.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员");
|
||||||
|
|
||||||
// 归零记录
|
// 归零记录
|
||||||
|
|
|
@ -130,15 +130,11 @@ public class SmMeterReadingRecordServiceImpl implements ISmMeterReadingRecordSer
|
||||||
// 查询设备列表
|
// 查询设备列表
|
||||||
DeviceQuery dto = new DeviceQuery();
|
DeviceQuery dto = new DeviceQuery();
|
||||||
dto.setDeviceIds(deviceIds);
|
dto.setDeviceIds(deviceIds);
|
||||||
List<DeviceVO> list = deviceMapper.selectSimpleList(dto);
|
List<DeviceVO> list = deviceMapper.selectSmDeviceList(dto);
|
||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取设备信息
|
|
||||||
List<IotDeviceInfo> deviceInfos = iotService.getDeviceInfo(list.stream()
|
|
||||||
.map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList()));
|
|
||||||
|
|
||||||
// 历史最后一次设备抄表记录
|
// 历史最后一次设备抄表记录
|
||||||
SmMeterReadingRecordQuery recordDto = new SmMeterReadingRecordQuery();
|
SmMeterReadingRecordQuery recordDto = new SmMeterReadingRecordQuery();
|
||||||
recordDto.setDeviceIds(deviceIds);
|
recordDto.setDeviceIds(deviceIds);
|
||||||
|
@ -149,7 +145,10 @@ public class SmMeterReadingRecordServiceImpl implements ISmMeterReadingRecordSer
|
||||||
// 更新数据
|
// 更新数据
|
||||||
for (DeviceVO device : list) {
|
for (DeviceVO device : list) {
|
||||||
try {
|
try {
|
||||||
IotDeviceInfo deviceInfo = deviceInfos.stream().filter(item -> Objects.equals(device.getMac(), item.getMac())).findFirst().orElse(null);
|
if (StringUtils.isAnyBlank(device.getMac(), device.getModelProductId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
IotDeviceInfo deviceInfo = iotService.getDeviceInfo(device.getMac(), device.getModelProductId());
|
||||||
SmMeterReadingRecordVo history = recordHistory.stream().filter(item -> Objects.equals(device.getDeviceId(), item.getDeviceId())).findFirst().orElse(null);
|
SmMeterReadingRecordVo history = recordHistory.stream().filter(item -> Objects.equals(device.getDeviceId(), item.getDeviceId())).findFirst().orElse(null);
|
||||||
|
|
||||||
// 抄表记录
|
// 抄表记录
|
||||||
|
|
|
@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import javax.validation.constraints.Size;
|
import javax.validation.constraints.Size;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
@ -66,4 +67,8 @@ public class SmModel extends BaseEntity
|
||||||
@ApiModelProperty("默认服务费")
|
@ApiModelProperty("默认服务费")
|
||||||
@Min(value = 0, message = "默认服务费不能小于0")
|
@Min(value = 0, message = "默认服务费不能小于0")
|
||||||
private BigDecimal serviceRate;
|
private BigDecimal serviceRate;
|
||||||
|
|
||||||
|
@ApiModelProperty("OneNet产品ID")
|
||||||
|
@NotBlank(message = "OneNet产品ID不允许为空", groups = {ValidGroup.Create.class})
|
||||||
|
private String productId;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class SmModelBO extends SmModel {
|
||||||
bo.setRemark(getRemark());
|
bo.setRemark(getRemark());
|
||||||
bo.setServiceType(getServiceType());
|
bo.setServiceType(getServiceType());
|
||||||
bo.setServiceRate(getServiceRate());
|
bo.setServiceRate(getServiceRate());
|
||||||
|
bo.setProductId(getProductId());
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +35,7 @@ public class SmModelBO extends SmModel {
|
||||||
bo.setRemark(getRemark());
|
bo.setRemark(getRemark());
|
||||||
bo.setServiceType(getServiceType());
|
bo.setServiceType(getServiceType());
|
||||||
bo.setServiceRate(getServiceRate());
|
bo.setServiceRate(getServiceRate());
|
||||||
|
bo.setProductId(getProductId());
|
||||||
return bo;
|
return bo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
sm.tags,
|
sm.tags,
|
||||||
sm.service_type,
|
sm.service_type,
|
||||||
sm.service_rate,
|
sm.service_rate,
|
||||||
|
sm.product_id,
|
||||||
count(case when sd.activation_time is not null and sd.deleted = false then sd.device_id end) as activation_count,
|
count(case when sd.activation_time is not null and sd.deleted = false then sd.device_id end) as activation_count,
|
||||||
count(case when sd.online_status = '1' and sd.activation_time is not null and sd.deleted = false then sd.device_id end) as online_count
|
count(case when sd.online_status = '1' and sd.activation_time is not null and sd.deleted = false then sd.device_id end) as online_count
|
||||||
from sm_model sm
|
from sm_model sm
|
||||||
|
@ -33,6 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="modelName != null and modelName != ''"> and sm.model_name like concat('%', #{modelName}, '%')</if>
|
<if test="modelName != null and modelName != ''"> and sm.model_name like concat('%', #{modelName}, '%')</if>
|
||||||
<if test="model != null and model != ''"> and sm.model = #{model}</if>
|
<if test="model != null and model != ''"> and sm.model = #{model}</if>
|
||||||
<if test="serviceType != null and serviceType != ''"> and sm.service_type = #{serviceType}</if>
|
<if test="serviceType != null and serviceType != ''"> and sm.service_type = #{serviceType}</if>
|
||||||
|
<if test="productId != null and productId != ''"> and sm.product_id = #{productId}</if>
|
||||||
<if test="deleted == null">and sm.deleted = false</if>
|
<if test="deleted == null">and sm.deleted = false</if>
|
||||||
<if test="deleted != null">and sm.deleted = #{deleted}</if>
|
<if test="deleted != null">and sm.deleted = #{deleted}</if>
|
||||||
</sql>
|
</sql>
|
||||||
|
@ -83,6 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="tags != null">tags,</if>
|
<if test="tags != null">tags,</if>
|
||||||
<if test="serviceType != null">service_type,</if>
|
<if test="serviceType != null">service_type,</if>
|
||||||
<if test="serviceRate != null">service_rate,</if>
|
<if test="serviceRate != null">service_rate,</if>
|
||||||
|
<if test="productId != null">product_id,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="modelName != null">#{modelName},</if>
|
<if test="modelName != null">#{modelName},</if>
|
||||||
|
@ -98,6 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="tags != null">#{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
|
<if test="tags != null">#{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
|
||||||
<if test="serviceType != null">#{serviceType},</if>
|
<if test="serviceType != null">#{serviceType},</if>
|
||||||
<if test="serviceRate != null">#{serviceRate},</if>
|
<if test="serviceRate != null">#{serviceRate},</if>
|
||||||
|
<if test="productId != null">#{productId},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
@ -117,6 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="tags != null">tags = #{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
|
<if test="tags != null">tags = #{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler},</if>
|
||||||
<if test="serviceType != null">service_type = #{serviceType},</if>
|
<if test="serviceType != null">service_type = #{serviceType},</if>
|
||||||
<if test="serviceRate != null">service_rate = #{serviceRate},</if>
|
<if test="serviceRate != null">service_rate = #{serviceRate},</if>
|
||||||
|
<if test="productId != null">product_id = #{productId},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where model_id = #{modelId}
|
where model_id = #{modelId}
|
||||||
</update>
|
</update>
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class TimeBillServiceImpl implements TimeBillService
|
||||||
ServiceUtil.assertion(insert != 1, "下单失败,请稍后再试");
|
ServiceUtil.assertion(insert != 1, "下单失败,请稍后再试");
|
||||||
|
|
||||||
// 开启设备
|
// 开启设备
|
||||||
boolean open = iotService.open(dto.getDevice().getMac());
|
boolean open = iotService.open(device.getMac(), device.getModelProductId());
|
||||||
ServiceUtil.assertion(!open, "开启设备失败,请稍后再试");
|
ServiceUtil.assertion(!open, "开启设备失败,请稍后再试");
|
||||||
|
|
||||||
return insert;
|
return insert;
|
||||||
|
@ -218,7 +218,9 @@ public class TimeBillServiceImpl implements TimeBillService
|
||||||
ServiceUtil.assertion(update != 1, "订单状态已发生变化,请刷新后重试");
|
ServiceUtil.assertion(update != 1, "订单状态已发生变化,请刷新后重试");
|
||||||
|
|
||||||
// 关闭设备
|
// 关闭设备
|
||||||
boolean close = iotService.close(bill.getDeviceMac());
|
DeviceVO device = deviceService.selectSmDeviceByDeviceId(bill.getDeviceId());
|
||||||
|
ServiceUtil.assertion(device == null, "设备不存在");
|
||||||
|
boolean close = iotService.close(device.getMac(), device.getModelProductId());
|
||||||
ServiceUtil.assertion(!close, "关闭设备失败,请检查设备是否在线");
|
ServiceUtil.assertion(!close, "关闭设备失败,请检查设备是否在线");
|
||||||
|
|
||||||
return update;
|
return update;
|
||||||
|
|
|
@ -16,7 +16,7 @@ wx:
|
||||||
# 微信小程序id
|
# 微信小程序id
|
||||||
appId: ${wx.appid}
|
appId: ${wx.appid}
|
||||||
# 商户id
|
# 商户id
|
||||||
merchantId: 1656437344
|
merchantId: 1676202154
|
||||||
# apiV3密钥
|
# apiV3密钥
|
||||||
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
||||||
# 通知回调地址
|
# 通知回调地址
|
||||||
|
@ -28,7 +28,7 @@ wx:
|
||||||
# 密钥所在位置
|
# 密钥所在位置
|
||||||
privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem
|
privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem
|
||||||
# 证书序列号
|
# 证书序列号
|
||||||
merchantSerialNumber: 66910F800A60768020F07D39A56AE701574A16AE
|
merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0
|
||||||
|
|
||||||
# 设备配置
|
# 设备配置
|
||||||
device:
|
device:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user