feat(ems): 添加位置坐标字段及区域功能

-树设备挂载 在 EmsLocation 实体及其相关 BO、VO 中新增 x、y 坐标字段
- 更新 Mapper XML 配置以支持新字段映射
- 新增 LocationTreeNodeVo 类用于表示区域树节点结构
- 在 EmsLocationController 中增加 /treeWithDevices 接口
- 在 EmsLocationServiceImpl 中实现 treeWithDevices 方法,
  构建带路径的区域树并在叶子节点挂载设备信息
- 注入 IEmsAlarmDeviceService 服务以查询设备数据
- 修改生产环境数据库端口号与密码配置
This commit is contained in:
2025-10-14 16:59:09 +08:00
parent d8175ef41d
commit 4a2e0c37f3
9 changed files with 119 additions and 2 deletions

View File

@@ -58,9 +58,9 @@ spring:
driverClassName: com.mysql.cj.jdbc.Driver
# jdbc 所有参数配置参考 https://lionli.blog.csdn.net/article/details/122018562
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
url: jdbc:mysql://140.143.206.120:3306/klp-oa?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
url: jdbc:mysql://140.143.206.120:13306/klp-oa?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
username: klp
password: KeLunPu123@
password: KeLunPu@123
# 从库数据源
slave:
lazy: true

View File

@@ -3,6 +3,7 @@ package com.klp.ems.controller;
import java.util.List;
import java.util.Arrays;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
@@ -20,6 +21,7 @@ import com.klp.common.utils.poi.ExcelUtil;
import com.klp.ems.domain.vo.EmsLocationVo;
import com.klp.ems.domain.bo.EmsLocationBo;
import com.klp.ems.service.IEmsLocationService;
import com.klp.ems.domain.vo.LocationTreeNodeVo;
/**
* 位置
@@ -96,4 +98,12 @@ public class EmsLocationController extends BaseController {
@PathVariable Long[] locationIds) {
return toAjax(iEmsLocationService.deleteWithValidByIds(Arrays.asList(locationIds), true));
}
/**
* 查询全量区域树,并在叶子节点挂载设备
*/
@GetMapping("/treeWithDevices")
public R<List<LocationTreeNodeVo>> treeWithDevices() {
return R.ok(iEmsLocationService.treeWithDevices());
}
}

View File

@@ -50,4 +50,7 @@ public class EmsLocation extends BaseEntity {
*/
private String remark;
private Integer x;
private Integer y;
}

View File

@@ -47,5 +47,8 @@ public class EmsLocationBo extends BaseEntity {
*/
private String remark;
private Integer x;
private Integer y;
}

View File

@@ -55,5 +55,16 @@ public class EmsLocationVo {
@ExcelProperty(value = "备注")
private String remark;
/**
* 坐标X
*/
@ExcelProperty(value = "坐标X")
private Integer x;
/**
* 坐标Y
*/
@ExcelProperty(value = "坐标Y")
private Integer y;
}

View File

@@ -0,0 +1,17 @@
package com.klp.ems.domain.vo;
import lombok.Data;
import java.util.List;
/**
* 区域树节点(包含路径与叶子设备)
*/
@Data
public class LocationTreeNodeVo {
private Long locationId;
private String name;
private Long parentId;
private String path;
private List<LocationTreeNodeVo> children;
private List<com.klp.ems.domain.vo.EmsAlarmDeviceVo> devices;
}

View File

@@ -3,6 +3,7 @@ package com.klp.ems.service;
import com.klp.ems.domain.EmsLocation;
import com.klp.ems.domain.vo.EmsLocationVo;
import com.klp.ems.domain.bo.EmsLocationBo;
import com.klp.ems.domain.vo.LocationTreeNodeVo;
import java.util.Collection;
import java.util.List;
@@ -40,4 +41,9 @@ public interface IEmsLocationService {
* 校验并批量删除位置信息
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 查询全量区域树(包含路径),仅在叶子节点挂载设备列表
*/
List<LocationTreeNodeVo> treeWithDevices();
}

View File

@@ -11,10 +11,17 @@ import com.klp.ems.domain.vo.EmsLocationVo;
import com.klp.ems.domain.EmsLocation;
import com.klp.ems.mapper.EmsLocationMapper;
import com.klp.ems.service.IEmsLocationService;
import com.klp.ems.service.IEmsAlarmDeviceService;
import com.klp.ems.domain.vo.EmsAlarmDeviceVo;
import com.klp.ems.domain.bo.EmsAlarmDeviceBo;
import com.klp.ems.domain.vo.LocationTreeNodeVo;
import java.util.List;
import java.util.Map;
import java.util.Collection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.stream.Collectors;
/**
* 位置Service业务层处理
@@ -27,6 +34,7 @@ import java.util.Collection;
public class EmsLocationServiceImpl implements IEmsLocationService {
private final EmsLocationMapper baseMapper;
private final IEmsAlarmDeviceService alarmDeviceService;
/**
* 查询位置
@@ -53,6 +61,8 @@ public class EmsLocationServiceImpl implements IEmsLocationService {
lqw.eq(bo.getParentId() != null, EmsLocation::getParentId, bo.getParentId());
lqw.eq(StringUtils.isNotBlank(bo.getDescription()), EmsLocation::getDescription, bo.getDescription());
lqw.eq(StringUtils.isNotBlank(bo.getAddress()), EmsLocation::getAddress, bo.getAddress());
lqw.eq(bo.getX() != null, EmsLocation::getX, bo.getX());
lqw.eq(bo.getY() != null, EmsLocation::getY, bo.getY());
return lqw;
}
@@ -97,4 +107,59 @@ public class EmsLocationServiceImpl implements IEmsLocationService {
}
return baseMapper.deleteBatchIds(ids) > 0;
}
/**
* 查询全量区域树(包含路径),仅在叶子节点挂载设备列表
*/
@Override
public List<LocationTreeNodeVo> treeWithDevices() {
// 查询全部位置
List<EmsLocationVo> all = baseMapper.selectVoList(Wrappers.lambdaQuery());
if (all == null || all.isEmpty()) {
return new ArrayList<>();
}
// 映射与根节点
Map<Long, List<EmsLocationVo>> parent2children = new HashMap<>();
List<EmsLocationVo> roots = new ArrayList<>();
for (EmsLocationVo vo : all) {
Long pid = vo.getParentId();
if (pid == null) {
roots.add(vo);
} else {
parent2children.computeIfAbsent(pid, k -> new ArrayList<>()).add(vo);
}
}
// 递归构建
return roots.stream()
.map(root -> buildNode(root, parent2children, root.getName()))
.collect(Collectors.toList());
}
private LocationTreeNodeVo buildNode(EmsLocationVo vo,
Map<Long, List<EmsLocationVo>> parent2children,
String path) {
LocationTreeNodeVo node = new LocationTreeNodeVo();
node.setLocationId(vo.getLocationId());
node.setName(vo.getName());
node.setParentId(vo.getParentId());
node.setPath(path);
List<EmsLocationVo> children = parent2children.get(vo.getLocationId());
if (children == null || children.isEmpty()) {
// 叶子节点:查询设备
EmsAlarmDeviceBo bo = new EmsAlarmDeviceBo();
bo.setLocationId(vo.getLocationId());
List<EmsAlarmDeviceVo> devices = alarmDeviceService.queryList(bo);
node.setDevices(devices != null ? devices : new ArrayList<>());
node.setChildren(new ArrayList<>());
} else {
// 非叶子:递归子节点,不挂设备
List<LocationTreeNodeVo> childNodes = children.stream()
.map(c -> buildNode(c, parent2children, path + "/" + c.getName()))
.collect(Collectors.toList());
node.setChildren(childNodes);
node.setDevices(new ArrayList<>());
}
return node;
}
}

View File

@@ -8,6 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="locationId" column="location_id"/>
<result property="name" column="name"/>
<result property="parentId" column="parent_id"/>
<result property="x" column="x"/>
<result property="y" column="y"/>
<result property="description" column="description"/>
<result property="address" column="address"/>
<result property="createBy" column="create_by"/>