查询设备分组列表
This commit is contained in:
@ -24,7 +24,7 @@ public class DeviceGroup extends TenantEntity {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@TableId(value = "id")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
|
@ -5,6 +5,7 @@ import com.fuyuanshen.common.core.validate.EditGroup;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGroup;
|
||||
import com.fuyuanshen.common.mybatis.core.domain.BaseEntity;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import jakarta.validation.constraints.*;
|
||||
@ -55,4 +56,10 @@ public class DeviceGroupBo extends BaseEntity {
|
||||
private Long isDeleted;
|
||||
|
||||
|
||||
@Schema(name = "页码", example = "1")
|
||||
private Integer pageNum = 1;
|
||||
|
||||
@Schema(name = "每页数据量", example = "10")
|
||||
private Integer pageSize = 10;
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.fuyuanshen.equipment.domain.vo;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGroup;
|
||||
import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
@ -44,7 +46,7 @@ public class DeviceGroupVo implements Serializable {
|
||||
* 状态:0-禁用,1-正常
|
||||
*/
|
||||
@ExcelProperty(value = "状态:0-禁用,1-正常")
|
||||
private Long status;
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 父分组ID
|
||||
@ -69,4 +71,9 @@ public class DeviceGroupVo implements Serializable {
|
||||
*/
|
||||
private List<DeviceGroupVo> children;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private String createTime;
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,15 @@
|
||||
package com.fuyuanshen.equipment.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceGroup;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
|
||||
import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 设备分组Mapper接口
|
||||
@ -12,4 +19,20 @@ import com.fuyuanshen.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
*/
|
||||
public interface DeviceGroupMapper extends BaseMapperPlus<DeviceGroup, DeviceGroupVo> {
|
||||
|
||||
/**
|
||||
* 查询设备分组列表
|
||||
*
|
||||
* @param bo 设备分组
|
||||
* @return 设备分组
|
||||
*/
|
||||
IPage<DeviceGroup> selectRootGroups(@Param("bo") DeviceGroupBo bo, Page<Device> page);
|
||||
|
||||
/**
|
||||
* 查询子分组
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<DeviceGroup> selectByParentId(Long id);
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fuyuanshen.equipment.service;
|
||||
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.equipment.domain.vo.DeviceGroupVo;
|
||||
import com.fuyuanshen.equipment.domain.bo.DeviceGroupBo;
|
||||
|
||||
|
@ -1,10 +1,16 @@
|
||||
package com.fuyuanshen.equipment.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fuyuanshen.common.core.domain.R;
|
||||
import com.fuyuanshen.common.core.utils.MapstructUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fuyuanshen.common.mybatis.core.page.TableDataInfo;
|
||||
import com.fuyuanshen.common.satoken.utils.LoginHelper;
|
||||
import com.fuyuanshen.equipment.domain.Device;
|
||||
import com.fuyuanshen.equipment.domain.DeviceTypeGrants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@ -15,9 +21,11 @@ import com.fuyuanshen.equipment.domain.DeviceGroup;
|
||||
import com.fuyuanshen.equipment.mapper.DeviceGroupMapper;
|
||||
import com.fuyuanshen.equipment.service.IDeviceGroupService;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 设备分组Service业务层处理
|
||||
@ -32,6 +40,7 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
|
||||
private final DeviceGroupMapper baseMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备分组
|
||||
*
|
||||
@ -52,8 +61,34 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
*/
|
||||
@Override
|
||||
public List<DeviceGroupVo> queryList(DeviceGroupBo bo) {
|
||||
LambdaQueryWrapper<DeviceGroup> lqw = buildQueryWrapper(bo);
|
||||
return baseMapper.selectVoList(lqw);
|
||||
Page<Device> page = new Page<>(bo.getPageNum(), bo.getPageSize());
|
||||
// 1. 查询顶级分组(parent_id为null)
|
||||
IPage<DeviceGroup> rootGroups = baseMapper.selectRootGroups(bo, page);
|
||||
List<DeviceGroup> records = rootGroups.getRecords();
|
||||
|
||||
// 2. 递归构建树形结构
|
||||
return records.stream()
|
||||
.map(this::buildGroupTree)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private DeviceGroupVo buildGroupTree(DeviceGroup group) {
|
||||
DeviceGroupVo vo = convertToVO(group);
|
||||
// 递归查询子分组
|
||||
List<DeviceGroup> children = baseMapper.selectByParentId(group.getId());
|
||||
vo.setChildren(children.stream()
|
||||
.map(this::buildGroupTree)
|
||||
.collect(Collectors.toList()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
private DeviceGroupVo convertToVO(DeviceGroup group) {
|
||||
DeviceGroupVo vo = new DeviceGroupVo();
|
||||
vo.setId(group.getId());
|
||||
vo.setGroupName(group.getGroupName());
|
||||
vo.setStatus(group.getStatus() == 1 ? "正常" : "禁用");
|
||||
vo.setCreateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(group.getCreateTime()));
|
||||
return vo;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<DeviceGroup> buildQueryWrapper(DeviceGroupBo bo) {
|
||||
@ -81,13 +116,13 @@ public class DeviceGroupServiceImpl implements IDeviceGroupService {
|
||||
// 验证分组名称唯一性
|
||||
DeviceGroup deviceGroup = baseMapper.selectOne(new QueryWrapper<DeviceGroup>().eq("group_name", bo.getGroupName()));
|
||||
if (deviceGroup != null) {
|
||||
throw new RuntimeException("分组名称已存在,请勿重复添加");
|
||||
throw new RuntimeException("分组名称已存在,请勿重复添加!!!");
|
||||
}
|
||||
|
||||
// 验证父分组是否存在(如果提供了parentId)
|
||||
DeviceGroup pDeviceGroup = baseMapper.selectById(bo.getParentId());
|
||||
if (bo.getParentId() != null && pDeviceGroup == null) {
|
||||
throw new RuntimeException("父分组不存在");
|
||||
throw new RuntimeException("父分组不存在!!!");
|
||||
}
|
||||
|
||||
DeviceGroup add = MapstructUtils.convert(bo, DeviceGroup.class);
|
||||
|
@ -1,7 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.fuyuanshen.equipment.mapper.DeviceGroupMapper">
|
||||
|
||||
<!-- 查询顶级分组 -->
|
||||
<select id="selectRootGroups" resultType="DeviceGroup">
|
||||
SELECT * FROM device_group
|
||||
WHERE parent_id IS NULL
|
||||
<if test="bo.groupName != null and bo.groupName != ''">
|
||||
AND group_name LIKE CONCAT('%', #{bo.groupName}, '%')
|
||||
</if>
|
||||
<if test="bo.status != null">
|
||||
AND status = #{bo.status}
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据父ID查询子分组 -->
|
||||
<select id="selectByParentId" resultType="DeviceGroup">
|
||||
SELECT *
|
||||
FROM device_group
|
||||
WHERE parent_id = #{parentId}
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user