Merge remote-tracking branch 'origin/main' into main

main
HuangHuiKang 2 days ago
commit 9a4d0a45a7

@ -311,8 +311,10 @@ public class DeviceController {
@Operation(summary = "获取首页设备运行状态")
// @PreAuthorize("@ss.hasPermission('iot:device:query')")
@Parameter(name = "orgId", description = "产线组织Id")
public CommonResult<DeviceOperationStatusRespVO> getDeviceOperationalStatus(@RequestParam(name = "orgId",required = false) Long orgId) throws JsonProcessingException {
DeviceOperationStatusRespVO deviceOperationalStatus=deviceService.getDeviceOperationalStatus();
public CommonResult<DeviceOperationStatusRespVO> getDeviceOperationalStatus(
@RequestParam(name = "orgId", required = false) Long orgId,
@RequestParam(name = "deviceType", required = false) Integer deviceType) throws JsonProcessingException {
DeviceOperationStatusRespVO deviceOperationalStatus=deviceService.getDeviceOperationalStatus(deviceType);
return success(deviceOperationalStatus);
}
@ -445,8 +447,10 @@ public class DeviceController {
@Operation(summary = "获得多个设备的属性数据")
@Parameter(name = "goviewId", description = "大屏ID", required = true)
//@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<List<Map<String, Object>>> getMultiDeviceAttributes(@RequestParam("goviewId") Long goviewId) {
return success(deviceService.getMultiDeviceAttributes(goviewId));
public CommonResult<List<Map<String, Object>>> getMultiDeviceAttributes(
@RequestParam("goviewId") Long goviewId,
@RequestParam(name = "deviceType", required = false) Integer deviceType) {
return success(deviceService.getMultiDeviceAttributes(goviewId, deviceType));
}

@ -130,8 +130,12 @@ public interface DeviceMapper extends BaseMapperX<DeviceDO> {
Integer getTotalDeviceCount();
Integer getTotalDeviceCountByType(@Param("deviceType") Integer deviceType);
List<Long> getAllDeviceIds();
List<Long> getAllDeviceIdsByType(@Param("deviceType") Integer deviceType);
List<DeviceSelectRespVO> selectDeviceSelectList();
DeviceDO selectByIdWithDeleted(@Param("id") Long id);

@ -145,13 +145,13 @@ public interface DeviceService {
Boolean scheduledStop(Long id);
DeviceOperationStatusRespVO getDeviceOperationalStatus();
DeviceOperationStatusRespVO getDeviceOperationalStatus(Integer deviceType);
DeviceOverviewRespVO getDeviceOverview();
List<DeviceRateTrendPointRespVO> getDeviceRateTrend(DeviceRateTrendReqVO reqVO);
List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId);
List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId, Integer deviceType);
List<DeviceContactModelDO> getDeviceAttributeList(Long deviceId);

@ -1809,16 +1809,20 @@ public class DeviceServiceImpl implements DeviceService {
}
@Override
public DeviceOperationStatusRespVO getDeviceOperationalStatus() {
public DeviceOperationStatusRespVO getDeviceOperationalStatus(Integer deviceType) {
DeviceOperationStatusRespVO result = new DeviceOperationStatusRespVO();
// 1. 从 MySQL 获取设备总数
Integer totalDevices = deviceMapper.getTotalDeviceCount();
Integer totalDevices = deviceType == null
? deviceMapper.getTotalDeviceCount()
: deviceMapper.getTotalDeviceCountByType(deviceType);
result.setTotalDevices(totalDevices);
// 2. 从 MySQL 获取所有设备ID
List<Long> deviceIds = deviceMapper.getAllDeviceIds();
List<Long> deviceIds = deviceType == null
? deviceMapper.getAllDeviceIds()
: deviceMapper.getAllDeviceIdsByType(deviceType);
if (CollectionUtils.isEmpty(deviceIds)) {
// 没有设备所有状态设为0
@ -1957,7 +1961,7 @@ public class DeviceServiceImpl implements DeviceService {
}
@Override
public List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId) {
public List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId, Integer deviceType) {
List<Map<String, Object>> result = new ArrayList<>();
@ -1994,7 +1998,9 @@ public class DeviceServiceImpl implements DeviceService {
// 3. 批量查设备
Map<Long, DeviceDO> deviceMap = deviceMapper
.selectBatchIds(allDeviceIds)
.selectList(Wrappers.<DeviceDO>lambdaQuery()
.in(DeviceDO::getId, allDeviceIds)
.eq(deviceType != null, DeviceDO::getDeviceType, deviceType))
.stream()
.collect(Collectors.toMap(DeviceDO::getId, Function.identity()));
log.info("deviceMap size: {}", deviceMap.size());

@ -207,6 +207,13 @@
WHERE deleted = 0
</select>
<select id="getTotalDeviceCountByType" resultType="java.lang.Integer">
SELECT COUNT(DISTINCT id)
FROM iot_device
WHERE deleted = 0
AND device_type = #{deviceType}
</select>
<select id="getAllDeviceIds" resultType="java.lang.Long">
SELECT id
FROM iot_device
@ -214,6 +221,14 @@
ORDER BY id
</select>
<select id="getAllDeviceIdsByType" resultType="java.lang.Long">
SELECT id
FROM iot_device
WHERE deleted = 0
AND device_type = #{deviceType}
ORDER BY id
</select>
<select id="selectDeviceSelectList"
resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceSelectRespVO">
SELECT

Loading…
Cancel
Save