From 6ef84a9fe35b610c3817c943f37bc27d9cf6dc3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Mon, 12 Aug 2024 20:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9E=8B=E5=8F=B7=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=BA=A7=E5=93=81ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/iot/service/IotService.java | 58 +++++++++++++------ .../com/ruoyi/iot/service/IotServiceImpl.java | 54 ++++++++--------- .../ruoyi/ss/device/domain/vo/DeviceVO.java | 2 + .../ruoyi/ss/device/mapper/DeviceMapper.xml | 1 + .../ss/device/service/DeviceAssembler.java | 5 -- .../service/impl/DeviceAssemblerImpl.java | 39 ------------- .../service/impl/DeviceServiceImpl.java | 41 +++++++------ .../SmMeterReadingRecordServiceImpl.java | 11 ++-- .../com/ruoyi/ss/model/domain/SmModel.java | 5 ++ .../com/ruoyi/ss/model/domain/SmModelBO.java | 2 + .../ruoyi/ss/model/mapper/SmModelMapper.xml | 5 ++ .../service/impl/TimeBillServiceImpl.java | 6 +- .../src/main/resources/application-prod.yml | 4 +- 13 files changed, 114 insertions(+), 119 deletions(-) diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java index f7a9e9fa..8fa7beb1 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotService.java @@ -18,12 +18,14 @@ import java.util.List; public interface IotService { /** * 向设备发送命令 + * * @param deviceName OneNet设备名称(即设备表的MAC号) - * @param command 命令字符串 + * @param command 命令字符串 + * @param productId * @return */ - default CommandResponse sendCommand(String deviceName, String command) { - return sendCommand(deviceName, command, null); + default CommandResponse sendCommand(String deviceName, String command, String productId) { + return sendCommand(deviceName, command, null, productId); } /** @@ -32,84 +34,106 @@ public interface IotService { * @param deviceName OneNet设备名称(即设备表的MAC号) * @param command 命令字符串 * @param timeout + * @param productId * @return */ - CommandResponse sendCommand(String deviceName, String command, Integer timeout); + CommandResponse sendCommand(String deviceName, String command, Integer timeout, String productId); /** * 获取设备在线状态 + * * @param deviceName OneNet设备名称(即设备表的MAC号) + * @param productId */ - DeviceOnlineStatus getOnlineStatus(String deviceName); + DeviceOnlineStatus getOnlineStatus(String deviceName, String productId); /** * 通电 + * * @param deviceName OneNet设备名称(即设备表的MAC号) + * @param productId * @return 是否成功 */ - boolean open(String deviceName); + boolean open(String deviceName, String productId); /** * 断电 + * * @param deviceName OneNet设备名称(即设备表的MAC号) + * @param productId * @return 是否成功 */ - boolean close(String deviceName); + boolean close(String deviceName, String productId); /** * 获取历史设备数据点信息 + * * @param deviceName OneNet设备名称(即设备表的MAC号) + * @param productId */ - HistoryDeviceData getHistoryDataPoint(String deviceName); + HistoryDeviceData getHistoryDataPoint(String deviceName, String productId); /** * 批量获取当前设备数据点信息 + * * @param deviceNames 设备名称列表 + * @param productId */ - List getCurrentDataPoint(List deviceNames); + List getCurrentDataPoint(List deviceNames, String productId); /** * 获取当前设备数据点信息 + * * @param deviceName 设备名称 + * @param productId */ - CurrentDeviceData getCurrentDataPoint(String deviceName); + CurrentDeviceData getCurrentDataPoint(String deviceName, String productId); /** * 获取设备详情 + * * @param deviceName 设备名称 + * @param productId */ - IotDeviceDetail getDeviceDetail(String deviceName); + IotDeviceDetail getDeviceDetail(String deviceName, String productId); /** * 设置剩余时长 * * @param deviceName 设备名称 * @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 + * * @param deviceName 设备名称 + * @param productId */ - IotDeviceInfo getDeviceInfo(String deviceName); + IotDeviceInfo getDeviceInfo(String deviceName, String productId); /** * 获取设备信息列表,并转换为IotDeviceInfo + * * @param deviceNames 设备名称列表 + * @param productId */ - List getDeviceInfo(List deviceNames); + List getDeviceInfo(List deviceNames, String productId); /** * 注册设备 */ - int create(String mac); + int create(String mac, String productId); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java index 7b631051..998ac168 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/iot/service/IotServiceImpl.java @@ -40,9 +40,6 @@ public class IotServiceImpl implements IotService { @Value("${sm.iotHost}") private String iotHost; - @Value(value = "${sm.productId}") - private String productId; - @Value(value = "${sm.version}") private String version; @@ -63,14 +60,14 @@ public class IotServiceImpl implements IotService { // 查询OneNet设备在线状态 @Override - public DeviceOnlineStatus getOnlineStatus(String deviceName) { + public DeviceOnlineStatus getOnlineStatus(String deviceName, String productId) { if (StringUtils.isBlank(deviceName)) { return DeviceOnlineStatus.OFFLINE; } // CommandResponse response = sendCommand(deviceName, "111"); // 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) { return DeviceOnlineStatus.OFFLINE; } @@ -80,8 +77,8 @@ public class IotServiceImpl implements IotService { // 通电 @Override - public boolean open(String deviceName) { - CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN); + public boolean open(String deviceName, String productId) { + CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_OPEN, productId); IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode()); if (!IotHttpStatus.SUCCESS.equals(status)) { throw new ServiceException("通电发生异常:" + status.getMsg()); @@ -91,8 +88,8 @@ public class IotServiceImpl implements IotService { // 断电 @Override - public boolean close(String deviceName) { - CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE); + public boolean close(String deviceName, String productId) { + CommandResponse response = sendCommand(deviceName, IotConstants.COMMAND_CLOSE, productId); IotHttpStatus status = IotHttpStatus.convertByCode(response.getCode()); if (!IotHttpStatus.SUCCESS.equals(status)) { throw new ServiceException("断电发生异常:" + status.getMsg()); @@ -102,7 +99,7 @@ public class IotServiceImpl implements IotService { // 获取历史设备数据点信息 @Override - public HistoryDeviceData getHistoryDataPoint(String deviceName) { + public HistoryDeviceData getHistoryDataPoint(String deviceName, String productId) { String param = "device_name=" + deviceName + "&product_id=" + productId; String sendUrl = iotHost + IotConstants.ADDS_HISTORY_DATAPOINTS + "?"+param; @@ -125,7 +122,7 @@ public class IotServiceImpl implements IotService { // 获取当前设备数据点信息 @Override - public List getCurrentDataPoint(List deviceNames) { + public List getCurrentDataPoint(List deviceNames, String productId) { String param = "device_name=" + String.join(",", deviceNames) + "&product_id=" + productId; String sendUrl = iotHost+ IotConstants.ADDS_CURRENT_DATAPOINTS + "?" + param; @@ -147,8 +144,8 @@ public class IotServiceImpl implements IotService { // 获取当前设备数据点信息 @Override - public CurrentDeviceData getCurrentDataPoint(String deviceName) { - List list = this.getCurrentDataPoint(Collections.singletonList(deviceName)); + public CurrentDeviceData getCurrentDataPoint(String deviceName, String productId) { + List list = this.getCurrentDataPoint(Collections.singletonList(deviceName), productId); if (CollectionUtils.isEmpty(list)) { return null; } @@ -156,7 +153,7 @@ public class IotServiceImpl implements IotService { } @Override - public IotDeviceDetail getDeviceDetail(String deviceName) { + public IotDeviceDetail getDeviceDetail(String deviceName, String productId) { String sendUrl = iotHost + IotConstants.ADDS_DEVICE_DETAIL; String param = "device_name=" + deviceName + "&product_id=" + productId; @@ -182,45 +179,44 @@ public class IotServiceImpl implements IotService { * * @param deviceName 设备名称 * @param seconds 时长(秒) + * @param productId * @return 是否成功 */ @Override @Transactional - public CommandResponse setTime(String deviceName, long seconds) { + public CommandResponse setTime(String deviceName, long seconds, String productId) { if (seconds < 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 @Transactional - public boolean updateDevice(Device device) { - // DEBUG模式下直接返回true - if (debug) { - return true; - } + public boolean updateDevice(Device device, String productId) { DeviceOutageWay deviceOutageWay = DeviceOutageWay.parse(device.getOutageWay()); String command = CommandBuilder.builder() // 断电方式,若为空,则立即断电 .setIfNull(IotConstants.COMMAND_OUTAGE_WAY, deviceOutageWay.getValue() , DeviceOutageWay.IMMEDIATE.getValue()) .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()); return true; } @Override - public IotDeviceInfo getDeviceInfo(String deviceName) { + public IotDeviceInfo getDeviceInfo(String deviceName, String productId) { if (StringUtils.isBlank(deviceName)) { return null; } - CurrentDeviceData currentDataPoint = getCurrentDataPoint(deviceName); + CurrentDeviceData currentDataPoint = getCurrentDataPoint(deviceName, productId); if (currentDataPoint == null) { return null; } @@ -228,11 +224,11 @@ public class IotServiceImpl implements IotService { } @Override - public List getDeviceInfo(List deviceNames) { + public List getDeviceInfo(List deviceNames, String productId) { if (CollectionUtils.isEmpty(deviceNames)) { return Collections.emptyList(); } - List dataList = getCurrentDataPoint(deviceNames); + List dataList = getCurrentDataPoint(deviceNames, productId); if (CollectionUtils.isEmpty(dataList)) { return Collections.emptyList(); } @@ -240,7 +236,7 @@ public class IotServiceImpl implements IotService { } @Override - public int create(String mac) { + public int create(String mac, String productId) { String sendUrl = iotHost + IotConstants.CREATE_DEVICE; CreateDeviceVo createDeviceVo = new CreateDeviceVo(); createDeviceVo.setDevice_name(mac); @@ -256,7 +252,7 @@ public class IotServiceImpl implements IotService { // 发送MQTT命令 @Override - public CommandResponse sendCommand(String deviceName, String command, Integer timeout) { + public CommandResponse sendCommand(String deviceName, String command, Integer timeout, String productId) { if (timeout == null) { timeout = this.timeout; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java index 06080201..decad94b 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/domain/vo/DeviceVO.java @@ -71,4 +71,6 @@ public class DeviceVO extends Device { @JsonView(DeviceView.SuitList.class) private String storeContactMobile; + @ApiModelProperty("型号产品ID") + private String modelProductId; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml index d309280e..430cd68a 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/mapper/DeviceMapper.xml @@ -113,6 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sm.model_name as model, sm.picture as picture, sm.tags as model_tags, + sm.product_id as model_product_id, ss.name as store_name, ss.contact_name as store_contact_name, ss.contact_mobile as store_contact_mobile, diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceAssembler.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceAssembler.java index b10f6acc..d7314893 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceAssembler.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/DeviceAssembler.java @@ -27,9 +27,4 @@ public interface DeviceAssembler { */ void assembleOrderCountInfo(List list); - /** - * 拼接物联网数据 - * @param list - */ - void assembleIotDeviceInfo(List list); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java index a7e9512f..d55f35cc 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceAssemblerImpl.java @@ -37,18 +37,12 @@ import java.util.stream.Collectors; @Service public class DeviceAssemblerImpl implements DeviceAssembler { - @Autowired - private SuitService suitService; - @Autowired private StoreService storeService; @Autowired private TransactionBillService transactionBillService; - @Autowired - private IotService iotService; - @Autowired private DeviceSuitService deviceSuitService; @@ -126,37 +120,4 @@ public class DeviceAssemblerImpl implements DeviceAssembler { } } - @Override - public void assembleIotDeviceInfo(List list) { - if (CollectionUtils.isEmptyElement(list)) { - return; - } - // 获取当前设备数据 - List deviceNames = list.stream().map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList()); - if (CollectionUtils.isEmpty(deviceNames)) { - return; - } - Map 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()); - } - } - } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java index 42912dcc..bbc0804b 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/device/service/impl/DeviceServiceImpl.java @@ -161,8 +161,12 @@ public class DeviceServiceImpl implements DeviceService ServiceUtil.assertion(deviceValidator.isRepeatMac(data.getDeviceId(), data.getMac()), "MAC重复"); 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设备 - 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), "设备注册失败"); data.setCreateTime(DateUtils.getNowDate()); @@ -377,9 +381,9 @@ public class DeviceServiceImpl implements DeviceService DeviceVO device = selectSmDeviceByDeviceId(deviceId); ServiceUtil.assertion(device == null, "设备不存在"); if (open) { - return iotService.open(device.getMac()); + return iotService.open(device.getMac(), device.getModelProductId()); } 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); long betweenSeconds = Duration.between(LocalDateTime.now(), newDevice.getExpireTime()).getSeconds(); if (betweenSeconds > 0) { - CommandResponse rechargeResult = iotService.setTime(device.getMac(), betweenSeconds); + CommandResponse rechargeResult = iotService.setTime(device.getMac(), betweenSeconds, device.getModelProductId()); ServiceUtil.assertion(!rechargeResult.isSuccess(), "设备充值失败,请检查设备是否在线"); } } @@ -481,14 +485,14 @@ public class DeviceServiceImpl implements DeviceService @Override public void deviceHeartBeat() { log.info("device heart beat running..."); - List list = deviceMapper.selectSimpleList(new DeviceQuery()); + List list = deviceMapper.selectSmDeviceList(new DeviceQuery()); if (CollectionUtils.isEmpty(list)) { log.info("device list is empty"); return; } for (DeviceVO device : list) { 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); device.setOnlineStatus(status); } else { @@ -542,9 +546,9 @@ public class DeviceServiceImpl implements DeviceService ServiceUtil.assertion(!UserUtil.hasFrontUser(device.getUserId()), "该设备不是您的,无法进行该操作" ); if (DevicePowerStatus.ON.equals(status)) { - iotService.open(device.getMac()); + iotService.open(device.getMac(), device.getModelProductId()); } else if (DevicePowerStatus.OFF.equals(status)) { - iotService.close(device.getMac()); + iotService.close(device.getMac(), device.getModelProductId()); } else { throw new ServiceException("不支持的操作"); } @@ -568,23 +572,22 @@ public class DeviceServiceImpl implements DeviceService // 查询设备列表 DeviceQuery dto = new DeviceQuery(); dto.setDeviceIds(deviceIds); - List list = deviceMapper.selectSimpleList(dto); + List list = deviceMapper.selectSmDeviceList(dto); if (CollectionUtils.isEmpty(list)) { return; } - // 获取数据点信息 - List deviceNames = list.stream().map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList()); - List deviceInfos = iotService.getDeviceInfo(deviceNames); - - // 更新数据 for (DeviceVO device : list) { 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(); data.setDeviceId(device.getDeviceId()); - - // 设备信息 if (deviceInfo != null) { data.setLastPullTime(deviceInfo.getAt()); 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); } catch (Exception e) { @@ -707,7 +710,7 @@ public class DeviceServiceImpl implements DeviceService transactionBillService.batchEndBillByDevice(deviceId); // 物联网设备归零 - CommandResponse commandResponse = iotService.setTime(device.getMac(), 1L); + CommandResponse commandResponse = iotService.setTime(device.getMac(), 1L, device.getModelProductId()); ServiceUtil.assertion(!commandResponse.isSuccess(), "设备归零失败,请检查设备是否在线或联系管理员"); // 归零记录 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/meterReadingRecord/service/SmMeterReadingRecordServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/meterReadingRecord/service/SmMeterReadingRecordServiceImpl.java index 2a92316f..c2e690eb 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/meterReadingRecord/service/SmMeterReadingRecordServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/meterReadingRecord/service/SmMeterReadingRecordServiceImpl.java @@ -130,15 +130,11 @@ public class SmMeterReadingRecordServiceImpl implements ISmMeterReadingRecordSer // 查询设备列表 DeviceQuery dto = new DeviceQuery(); dto.setDeviceIds(deviceIds); - List list = deviceMapper.selectSimpleList(dto); + List list = deviceMapper.selectSmDeviceList(dto); if (CollectionUtils.isEmpty(list)) { return true; } - // 获取设备信息 - List deviceInfos = iotService.getDeviceInfo(list.stream() - .map(DeviceVO::getMac).filter(StringUtils::hasText).collect(Collectors.toList())); - // 历史最后一次设备抄表记录 SmMeterReadingRecordQuery recordDto = new SmMeterReadingRecordQuery(); recordDto.setDeviceIds(deviceIds); @@ -149,7 +145,10 @@ public class SmMeterReadingRecordServiceImpl implements ISmMeterReadingRecordSer // 更新数据 for (DeviceVO device : list) { 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); // 抄表记录 diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModel.java b/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModel.java index 267198bf..b1cb05b7 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModel.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModel.java @@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModelProperty; import lombok.Data; import javax.validation.constraints.Min; +import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; import java.math.BigDecimal; @@ -66,4 +67,8 @@ public class SmModel extends BaseEntity @ApiModelProperty("默认服务费") @Min(value = 0, message = "默认服务费不能小于0") private BigDecimal serviceRate; + + @ApiModelProperty("OneNet产品ID") + @NotBlank(message = "OneNet产品ID不允许为空", groups = {ValidGroup.Create.class}) + private String productId; } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModelBO.java b/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModelBO.java index ac07617f..1b94c1e7 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModelBO.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/model/domain/SmModelBO.java @@ -19,6 +19,7 @@ public class SmModelBO extends SmModel { bo.setRemark(getRemark()); bo.setServiceType(getServiceType()); bo.setServiceRate(getServiceRate()); + bo.setProductId(getProductId()); return bo; } @@ -34,6 +35,7 @@ public class SmModelBO extends SmModel { bo.setRemark(getRemark()); bo.setServiceType(getServiceType()); bo.setServiceRate(getServiceRate()); + bo.setProductId(getProductId()); return bo; } } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/model/mapper/SmModelMapper.xml b/smart-switch-service/src/main/java/com/ruoyi/ss/model/mapper/SmModelMapper.xml index 2de23d14..38c3858d 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/model/mapper/SmModelMapper.xml +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/model/mapper/SmModelMapper.xml @@ -23,6 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sm.tags, sm.service_type, 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.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 @@ -33,6 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and sm.model_name like concat('%', #{modelName}, '%') and sm.model = #{model} and sm.service_type = #{serviceType} + and sm.product_id = #{productId} and sm.deleted = false and sm.deleted = #{deleted} @@ -83,6 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" tags, service_type, service_rate, + product_id, #{modelName}, @@ -98,6 +101,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler}, #{serviceType}, #{serviceRate}, + #{productId}, @@ -117,6 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" tags = #{tags,typeHandler=com.ruoyi.system.mapper.typehandler.StringSplitListTypeHandler}, service_type = #{serviceType}, service_rate = #{serviceRate}, + product_id = #{productId}, where model_id = #{modelId} diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/timeBill/service/impl/TimeBillServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/timeBill/service/impl/TimeBillServiceImpl.java index e8ea0a52..b7a353a8 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/timeBill/service/impl/TimeBillServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/timeBill/service/impl/TimeBillServiceImpl.java @@ -175,7 +175,7 @@ public class TimeBillServiceImpl implements TimeBillService ServiceUtil.assertion(insert != 1, "下单失败,请稍后再试"); // 开启设备 - boolean open = iotService.open(dto.getDevice().getMac()); + boolean open = iotService.open(device.getMac(), device.getModelProductId()); ServiceUtil.assertion(!open, "开启设备失败,请稍后再试"); return insert; @@ -218,7 +218,9 @@ public class TimeBillServiceImpl implements TimeBillService 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, "关闭设备失败,请检查设备是否在线"); return update; diff --git a/smart-switch-web/src/main/resources/application-prod.yml b/smart-switch-web/src/main/resources/application-prod.yml index 88eb75a8..c1d6c2d1 100644 --- a/smart-switch-web/src/main/resources/application-prod.yml +++ b/smart-switch-web/src/main/resources/application-prod.yml @@ -16,7 +16,7 @@ wx: # 微信小程序id appId: ${wx.appid} # 商户id - merchantId: 1656437344 + merchantId: 1676202154 # apiV3密钥 apiV3Key: 49819e0f0abdb2df3246f7b27f264d75 # 通知回调地址 @@ -28,7 +28,7 @@ wx: # 密钥所在位置 privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem # 证书序列号 - merchantSerialNumber: 66910F800A60768020F07D39A56AE701574A16AE + merchantSerialNumber: 6AD69237C0F22A9AE51A64F1927E3A0962AC1FB0 # 设备配置 device: