From 6f21d9c1c9cb2071c786615ba8f7b8301100809e Mon Sep 17 00:00:00 2001 From: HuangHuiKang Date: Wed, 1 Jul 2026 16:39:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E6=94=B9=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=8F=B0=E8=B4=A6=E5=85=B3=E8=81=94=E7=89=A9=E8=81=94=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E5=8F=8A=E7=89=A9=E8=81=94=E8=AE=BE=E5=A4=87=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/device/vo/DevicePageReqVO.java | 6 + .../admin/device/vo/DeviceRespVO.java | 14 +- .../admin/device/vo/DeviceSelectRespVO.java | 2 +- .../iot/dal/mysql/device/DeviceMapper.java | 3 + .../iot/service/device/DeviceServiceImpl.java | 33 ++- .../resources/mapper/device/DeviceMapper.xml | 72 ++++- .../deviceledger/vo/DeviceLedgerRespVO.java | 6 + .../vo/DeviceLedgerSaveReqVO.java | 2 +- .../deviceline/DeviceLineController.java | 10 + .../deviceledger/DeviceLedgerDO.java | 12 + .../deviceledger/DeviceLedgerMapper.java | 2 + .../deviceledger/DeviceLedgerServiceImpl.java | 63 +++++ .../service/deviceline/DeviceLineService.java | 3 + .../deviceline/DeviceLineServiceImpl.java | 255 ++++++++++++++++++ .../deviceledger/DeviceledgerMapper.xml | 15 +- 15 files changed, 479 insertions(+), 19 deletions(-) diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java index 7823c8c49..762d66d08 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DevicePageReqVO.java @@ -83,4 +83,10 @@ public class DevicePageReqVO extends PageParam { @Schema(description = "mqtt订阅主题") private String topic; + @Schema(description = "台账绑定场景:当前设备台账ID,编辑时用于保留当前已绑定设备") + private Long currentLedgerId; + + @Schema(description = "台账绑定场景:是否只查询可绑定的物联设备") + private Boolean onlyAvailableForLedger; + } diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java index 39e951aae..48be2d806 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceRespVO.java @@ -129,4 +129,16 @@ public class DeviceRespVO { @Schema(description = "设备图片", example = "{}") private String images; -} \ No newline at end of file + + @Schema(description = "是否已被设备台账绑定") + private Boolean ledgerBound; + + @Schema(description = "当前场景是否可选") + private Boolean selectable; + + @Schema(description = "已绑定的设备台账ID") + private Long boundLedgerId; + + @Schema(description = "已绑定的设备台账名称") + private String boundLedgerName; +} diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSelectRespVO.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSelectRespVO.java index 8dc62bf05..5b438f869 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSelectRespVO.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/controller/admin/device/vo/DeviceSelectRespVO.java @@ -15,7 +15,7 @@ public class DeviceSelectRespVO { @Schema(description = "设备名称(原始)") private String deviceName; - @Schema(description = "设备名称(展示用,删除状态会拼接“(已删除)”)") + @Schema(description = "设备名称(展示用,删除状态会拼接“已删除”)") private String displayName; @Schema(description = "是否已被mes_organization.dv_id选择") diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java index a1d3fd804..b6c82ca51 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/dal/mysql/device/DeviceMapper.java @@ -144,6 +144,9 @@ public interface DeviceMapper extends BaseMapperX { List getAvailableDevicePage(@Param("page") Page page,@Param("param") DevicePageReqVO pageReqVO); + List selectDeviceLedgerBoundList(@Param("deviceIds") Collection deviceIds, + @Param("currentLedgerId") Long currentLedgerId); + List selectHolidayDaysInRange(@Param("startDay") Date startDay, @Param("endDayExclusive") Date endDayExclusive); diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java index 0ee723937..7a26cb7fa 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/device/DeviceServiceImpl.java @@ -456,6 +456,7 @@ public class DeviceServiceImpl implements DeviceService { } + fillDeviceLedgerBoundInfo(deviceRespVOPageResult.getList(), pageReqVO.getCurrentLedgerId()); return deviceRespVOPageResult; } @@ -485,7 +486,37 @@ public class DeviceServiceImpl implements DeviceService { List filteredList = deviceRespVOList.stream() .filter(device -> matchesOperatingStatus(device.getOperatingStatus(), pageReqVO.getOperatingStatus())) .collect(Collectors.toList()); - return new PageResult<>(subPage(filteredList, pageReqVO), (long) filteredList.size()); + List pageList = subPage(filteredList, pageReqVO); + fillDeviceLedgerBoundInfo(pageList, pageReqVO.getCurrentLedgerId()); + return new PageResult<>(pageList, (long) filteredList.size()); + } + + private void fillDeviceLedgerBoundInfo(List deviceList, Long currentLedgerId) { + if (CollUtil.isEmpty(deviceList)) { + return; + } + List deviceIds = deviceList.stream() + .map(DeviceRespVO::getId) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + if (CollUtil.isEmpty(deviceIds)) { + return; + } + + Map boundMap = deviceMapper.selectDeviceLedgerBoundList(deviceIds, currentLedgerId).stream() + .collect(Collectors.toMap(DeviceRespVO::getId, Function.identity(), (a, b) -> a)); + for (DeviceRespVO device : deviceList) { + DeviceRespVO bound = boundMap.get(device.getId()); + if (bound == null) { + device.setLedgerBound(false); + device.setSelectable(true); + continue; + } + device.setLedgerBound(bound.getLedgerBound()); + device.setSelectable(bound.getSelectable()); + device.setBoundLedgerId(bound.getBoundLedgerId()); + device.setBoundLedgerName(bound.getBoundLedgerName()); + } } private String resolveDeviceOperatingStatus(DeviceOperationRecordDO record) { diff --git a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml index 66435e082..2a3f99bc2 100644 --- a/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml +++ b/yudao-module-iot/yudao-module-iot-biz/src/main/resources/mapper/device/DeviceMapper.xml @@ -167,29 +167,38 @@ resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.LineCodeAndNameRespVO"> SELECT - iotd.id AS deviceId, - mo.code AS lineCode, - mo.name AS lineName - FROM mes_organization mo - LEFT JOIN iot_device iotd ON mo.dv_id = iotd.id - WHERE iotd.id IN + mdl.dv_id AS deviceId, + top_dl.code AS lineCode, + top_dl.name AS lineName + FROM mes_device_ledger mdl + INNER JOIN mes_device_line dl ON dl.id = mdl.device_line AND dl.deleted = 0 + INNER JOIN mes_device_line top_dl ON top_dl.id = CASE + WHEN dl.parent_chain IS NULL OR dl.parent_chain = '' THEN dl.id + ELSE CAST(SUBSTRING_INDEX(dl.parent_chain, ',', 1) AS UNSIGNED) + END AND top_dl.deleted = 0 + WHERE mdl.deleted = 0 + AND mdl.dv_id IS NOT NULL + AND mdl.dv_id IN #{id} - AND mo.deleted = 0 + + + + + - \ No newline at end of file +