feat(iot):【设备定位:100%】首页接入地图,基于 sequential-crafting-thacker.md 规划

This commit is contained in:
YunaiV
2026-01-21 13:41:35 +08:00
parent 6892571a33
commit 45638b35f4
5 changed files with 54 additions and 3 deletions

View File

@@ -1,14 +1,18 @@
package cn.iocoder.yudao.module.iot.controller.admin.device;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.device.*;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.product.IotProductDO;
import cn.iocoder.yudao.module.iot.service.device.IotDeviceService;
import cn.iocoder.yudao.module.iot.service.product.IotProductService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
@@ -22,13 +26,12 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
@Tag(name = "管理后台 - IoT 设备")
@RestController
@@ -38,6 +41,8 @@ public class IotDeviceController {
@Resource
private IotDeviceService deviceService;
@Resource
private IotProductService productService;
@PostMapping("/create")
@Operation(summary = "创建设备")
@@ -135,6 +140,26 @@ public class IotDeviceController {
.setProductId(device.getProductId()).setState(device.getState())));
}
@GetMapping("/location-list")
@Operation(summary = "获取设备位置列表", description = "获取有经纬度信息的设备列表,用于地图展示")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<List<IotDeviceRespVO>> getDeviceLocationList() {
// 1. 获取有位置信息的设备列表
List<IotDeviceDO> devices = deviceService.getDeviceListByHasLocation();
if (CollUtil.isEmpty(devices)) {
return success(Collections.emptyList());
}
// 2. 转换并返回
Map<Long, IotProductDO> productMap = convertMap(productService.getProductList(), IotProductDO::getId);
return success(convertList(devices, device -> {
IotDeviceRespVO respVO = BeanUtils.toBean(device, IotDeviceRespVO.class);
MapUtils.findAndThen(productMap, device.getProductId(),
product -> respVO.setProductName(product.getName()));
return respVO;
}));
}
@PostMapping("/import")
@Operation(summary = "导入设备")
@PreAuthorize("@ss.hasPermission('iot:device:import')")

View File

@@ -45,6 +45,9 @@ public class IotDeviceRespVO {
@ExcelProperty("产品编号")
private Long productId;
@Schema(description = "产品名称", example = "温湿度传感器")
private String productName; // 只有部分接口返回,例如 getDeviceLocationList
@Schema(description = "产品标识", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("产品 Key")
private String productKey;

View File

@@ -118,4 +118,15 @@ public interface IotDeviceMapper extends BaseMapperX<IotDeviceDO> {
));
}
/**
* 查询有位置信息的设备列表
*
* @return 设备列表
*/
default List<IotDeviceDO> selectListByHasLocation() {
return selectList(new LambdaQueryWrapperX<IotDeviceDO>()
.isNotNull(IotDeviceDO::getLatitude)
.isNotNull(IotDeviceDO::getLongitude));
}
}

View File

@@ -281,4 +281,11 @@ public interface IotDeviceService {
*/
void updateDeviceLocation(IotDeviceDO device, BigDecimal longitude, BigDecimal latitude);
/**
* 获得有位置信息的设备列表
*
* @return 设备列表
*/
List<IotDeviceDO> getDeviceListByHasLocation();
}

View File

@@ -509,6 +509,11 @@ public class IotDeviceServiceImpl implements IotDeviceService {
deleteDeviceCache(device);
}
@Override
public List<IotDeviceDO> getDeviceListByHasLocation() {
return deviceMapper.selectListByHasLocation();
}
private IotDeviceServiceImpl getSelf() {
return SpringUtil.getBean(getClass());
}