接口逻辑完善,大屏树状结构接口,站点图json数据存储等,零碎修改等

This commit is contained in:
mi9688 2024-10-12 17:45:54 +08:00
parent eefc4e9a45
commit 22b3df8ddb
29 changed files with 500 additions and 183 deletions

View File

@ -10,12 +10,18 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* Entity基类
*
* @author ruoyi
*/
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class BaseEntity implements Serializable
{
private static final long serialVersionUID = 1L;

View File

@ -34,16 +34,26 @@ public class GGroupsController extends BaseController
private IGGroupsService gGroupsService;
/**
* 查询组列表
* 查询组树状结构列表
*/
@PreAuthorize("@ss.hasPermi('iot:groups:list')")
@GetMapping("/list")
@ApiOperation("查询组列表")
public AjaxResult list(GGroups gGroups)
{
List<GGroups> list = gGroupsService.selectGGroupsList(gGroups);
return success(list);
return success(gGroupsService.selectGGroupsList(gGroups));
}
/**
* 查询组带叶子节点树状列表
*/
@PreAuthorize("@ss.hasPermi('iot:groups:list')")
@GetMapping("/list-with-leaf")
@ApiOperation("查询组带叶子节点树状列表")
public AjaxResult listWithLeaf(GGroups gGroups){
return success(gGroupsService.selectGGroupsAndSitesList(gGroups));
}
/**
* 查询组下面的直属站点
*/

View File

@ -1,9 +1,9 @@
package com.fastbee.data.controller.gis;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.fastbee.ggroup.domain.GSites;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.ggroup.domain.dto.GLegendUpdateDto;
import com.fastbee.ggroup.domain.dto.GLegendDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -17,15 +17,14 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.fastbee.common.annotation.Log;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.ggroup.domain.GLegend;
import com.fastbee.ggroup.service.IGLegendService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;
import javax.servlet.http.HttpServletResponse;
/**
* 图例Controller
*
@ -41,7 +40,7 @@ public class GLegendController extends BaseController
private IGLegendService gLegendService;
/**
* 查询图例列表
* 查询/搜索图例列表
*/
@PreAuthorize("@ss.hasPermi('ggroup:legend:list')")
@GetMapping("/list")
@ -56,15 +55,15 @@ public class GLegendController extends BaseController
/**
* 导出图例列表
*/
// @ApiOperation("导出图例列表")
// @PreAuthorize("@ss.hasPermi('ggroup:legend:export')")
// @PostMapping("/export")
// public void export(HttpServletResponse response, GLegend gLegend)
// {
// List<GLegend> list = gLegendService.selectGLegendList(gLegend);
// ExcelUtil<GLegend> util = new ExcelUtil<GLegend>(GLegend.class);
// util.exportExcel(response, list, "图例数据");
// }
@ApiOperation("导出图例列表")
@PreAuthorize("@ss.hasPermi('ggroup:legend:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, GLegend gLegend)
{
List<GLegendDto> list = gLegendService.selectGLegendList(gLegend);
ExcelUtil<GLegendDto> util = new ExcelUtil<GLegendDto>(GLegendDto.class);
util.exportExcel(response, list, "图例数据");
}
/**
* 获取图例详细信息
@ -94,7 +93,7 @@ public class GLegendController extends BaseController
@PreAuthorize("@ss.hasPermi('ggroup:legend:edit')")
@PutMapping
@ApiOperation("修改图例")
public AjaxResult edit(@RequestBody GLegend gLegend)
public AjaxResult edit(@RequestBody GLegendUpdateDto gLegend)
{
return toAjax(gLegendService.updateGLegend(gLegend));
}

View File

@ -6,6 +6,7 @@ import javax.servlet.http.HttpServletResponse;
import com.fastbee.ggroup.domain.dto.GGroupSiteDto;
import com.fastbee.ggroup.domain.dto.GGroupSiteRelateDto;
import com.fastbee.ggroup.domain.dto.GSitesEditDto;
import com.fastbee.ggroup.domain.dto.GSitesSelectDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
@ -42,15 +43,15 @@ public class GSitesController extends BaseController
private IGSitesService gSitesService;
/**
* 查询站点列表
* 查询/搜索站点列表
*/
@PreAuthorize("@ss.hasPermi('ggroup:sites:list')")
@GetMapping("/list")
@ApiOperation("查询站点列表")
public TableDataInfo list(GSites gSites)
public TableDataInfo list(GSitesSelectDto gSites)
{
startPage();
List<GSites> list = gSitesService.selectGSitesList(gSites);
List<?> list = gSitesService.selectGSitesList(gSites);
return getDataTable(list);
}
@ -64,18 +65,18 @@ public class GSitesController extends BaseController
return toAjax(gSitesService.relateGroup(gGroupSiteRelateDto));
}
/**
* 导出站点列表
*/
@ApiOperation("导出站点列表")
@PreAuthorize("@ss.hasPermi('ggroup:sites:export')")
@PostMapping("/export")
public void export(HttpServletResponse response, GSites gSites)
{
List<GSites> list = gSitesService.selectGSitesList(gSites);
ExcelUtil<GSites> util = new ExcelUtil<GSites>(GSites.class);
util.exportExcel(response, list, "站点数据");
}
// /**
// * 导出站点列表
// */
// @ApiOperation("导出站点列表")
// @PreAuthorize("@ss.hasPermi('ggroup:sites:export')")
// @PostMapping("/export")
// public void export(HttpServletResponse response, GSitesSelectDto gSites)
// {
// List<GSites> list = gSitesService.selectGSitesList(gSites);
// ExcelUtil<GSites> util = new ExcelUtil<GSites>(GSites.class);
// util.exportExcel(response, list, "站点数据");
// }
/**
* 获取站点详细信息

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,7 @@
package com.fastbee.oss.domain;
import lombok.Builder;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
@ -12,7 +13,7 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author zhuangpeng.li
* @date 2024-04-22
*/
@Builder
@SuperBuilder
public class OssDetail extends BaseEntity
{
private static final long serialVersionUID = 1L;

View File

@ -2,12 +2,15 @@ package com.fastbee.ggroup.domain;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
import com.fastbee.ggroup.domain.vo.GGroupSiteVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
@ -16,9 +19,12 @@ import java.util.List;
* @author kerwincui
* @date 2024-09-27
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GGroups",description = "组 g_groups")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GGroups extends BaseEntity
{
private static final long serialVersionUID = 1L;
@ -56,6 +62,8 @@ private static final long serialVersionUID = 1L;
@ApiModelProperty("空间数据")
private String space;
private String spaceValue;
/** 父菜单名称 */
private String parentName;
@ -68,7 +76,16 @@ private static final long serialVersionUID = 1L;
/** 祖级列表 */
private String ancestors;
/** 子部门 */
/** 子 */
private List<GGroups> children = new ArrayList<>();
private List<GGroupSiteVo>childrenSite = new ArrayList<>();
/**节点类型0组1站点 */
private Integer nodeType= 0;
/**节点类型为1时使用 站点id */
private Long siteId;
}

View File

@ -2,9 +2,10 @@ package com.fastbee.ggroup.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.*;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
import lombok.experimental.SuperBuilder;
/**
* 图例对象 g_legend
@ -12,8 +13,12 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author kerwincui
* @date 2024-10-08
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GLegend",description = "图例 g_legend")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GLegend extends BaseEntity
{
private static final long serialVersionUID = 1L;

View File

@ -2,7 +2,8 @@ package com.fastbee.ggroup.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
@ -14,8 +15,12 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author kerwincui
* @date 2024-10-09
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GLegendType",description = "图例类型 g_legend_type")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GLegendType extends BaseEntity
{
private static final long serialVersionUID = 1L;

View File

@ -4,8 +4,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
@ -17,8 +17,12 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author kerwincui
* @date 2024-09-30
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GSiteGroups",description = "站点组关系 g_site_groups")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GSiteGroups extends BaseEntity
{
private static final long serialVersionUID = 1L;

View File

@ -3,7 +3,8 @@ package com.fastbee.ggroup.domain;
import java.math.BigDecimal;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.*;
import lombok.experimental.SuperBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
@ -15,8 +16,12 @@ import com.fastbee.common.core.domain.BaseEntity;
* @author kerwincui
* @date 2024-10-10
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GSiteInfo",description = "站点基础信息 g_site_info")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GSiteInfo extends BaseEntity
{
private static final long serialVersionUID = 1L;

View File

@ -4,22 +4,25 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import lombok.*;
import lombok.experimental.SuperBuilder;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
import java.util.Map;
/**
* 站点对象 g_sites
*
* @author kerwincui
* @date 2024-09-29
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "GSites",description = "站点 g_sites")
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class GSites extends BaseEntity
{
private static final long serialVersionUID = 1L;
@ -53,5 +56,6 @@ private static final long serialVersionUID = 1L;
@ApiModelProperty("项目id")
private Long projectId;
private String spaceValue;
}

View File

@ -0,0 +1,32 @@
package com.fastbee.ggroup.domain.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
public class GLegendUpdateDto {
/** 主键id */
private Long id;
/** 图标 */
private String icon;
/** 类型 */
private Long type;
/** 图标名称 */
private String name;
/** 项目id */
private Long projectId;
/** 图例类型名称 */
private String typeName;
/** 类别 */
private String category;
}

View File

@ -0,0 +1,38 @@
package com.fastbee.ggroup.domain.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fastbee.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class GSitesSelectDto {
/** 主键 */
private Long id;
/** 站点名称 */
private String name;
/** 图标 */
private String icon;
/** 类型 */
private String type;
/** 空间数据 */
private String space;
/** 项目id */
private Long projectId;
/** 站点id */
private Long siteId;
/** 组id(关联表g_group的id) */
private Long parentId;
/** 搜索值 */
private String searchValue;
}

View File

@ -0,0 +1,47 @@
package com.fastbee.ggroup.domain.vo;
import com.fastbee.common.annotation.Excel;
import com.fastbee.ggroup.domain.GGroups;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
public class GGroupIncorporateSiteVo {
/** 主键 */
private Long id;
/** 组名 */
private String name;
/** 图标 */
private String icon;
/** 标签(1江河湖泊2水利工程3.检测站点4.其他对象5.水利事务6.报警事件) */
private Long tag;
/** 项目id */
private Long projectId;
/** 项目名称 */
private String projectName;
/** 空间数据 */
private String space;
/** 父菜单名称 */
private String parentName;
/** 父菜单ID */
private Long parentId;
/** 显示顺序 */
private Integer orderNum;
/** 祖级列表 */
private String ancestors;
/** 子组 */
private List<GGroupIncorporateSiteVo> children = new ArrayList<>();
}

View File

@ -12,5 +12,7 @@ public class GGroupSiteVo {
private String icon; // 对应 gs.icon
private String type; // 对应 gs.type
private String space; // 对应 gs.space
private String spaceValue; // 对应 gs.space
// Getter Setter
}

View File

@ -0,0 +1,34 @@
package com.fastbee.ggroup.domain.vo;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fastbee.common.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
public class GSitesListVo {
/** 主键 */
private Long id;
/** 站点名称 */
private String name;
/** 图标 */
private String icon;
/** 类型 */
private String type;
/** 空间数据 */
private String space;
/** 项目id */
private Long projectId;
/** 站点id */
private Long siteId;
/** 组id(关联表g_group的id) */
private Long parentId;
}

View File

@ -36,7 +36,7 @@ public interface GGroupsMapper extends BaseMapper<GGroups>
@Select({
"<script>",
"select gsg.id ,gsg.parent_id as parent_id, gg.name as parent_name, gsg.site_id as siteId, gs.name as name, gs.icon, gs.type, gs.space",
"select gsg.id, gsg.parent_id as parent_id, gg.name as parent_name, gsg.site_id as siteId, gs.name as name, gs.icon, gs.type, gs.space,gs.space_value",
"from g_site_groups gsg",
"left join g_groups gg on gsg.parent_id = gg.id",
"left join g_sites gs on gsg.site_id = gs.id",
@ -47,9 +47,13 @@ public interface GGroupsMapper extends BaseMapper<GGroups>
"<if test='parentId != null'>",
"and gsg.parent_id = #{parentId}",
"</if>",
"<if test='searchValue != null'>",
"and gs.name like CONCAT('%', #{searchValue}, '%')", // 使用 CONCAT % 和参数拼接
"</if>",
"</script>"
})
List<GGroupSiteVo> selectGGroupsSiteList(GGroups gGroups);
List<GGroupSiteVo> selectGGroupsSiteList(GGroups gGroups);
/**
* 新增组

View File

@ -4,6 +4,9 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.ggroup.domain.GSiteGroups;
import com.fastbee.ggroup.domain.dto.GGroupSiteDto;
import com.github.yulichang.base.MPJBaseMapper;
import org.apache.ibatis.annotations.Insert;
/**
* 站点组关系Mapper接口
@ -11,7 +14,7 @@ import com.fastbee.ggroup.domain.GSiteGroups;
* @author kerwincui
* @date 2024-09-30
*/
public interface GSiteGroupsMapper extends BaseMapper<GSiteGroups>
public interface GSiteGroupsMapper extends MPJBaseMapper<GSiteGroups>
{
/**
@ -36,7 +39,9 @@ public interface GSiteGroupsMapper extends BaseMapper<GSiteGroups>
* @param gSiteGroups 站点组关系
* @return 结果
*/
public int insertGSiteGroups(GSiteGroups gSiteGroups);
@Insert("insert into g_site_groups (site_id, parent_id, project_id,order_num) " +
"value (#{siteId},#{parentId},#{projectId},#{orderNum})")
public int insertGSiteGroups(GGroupSiteDto gSiteGroups);
/**
* 修改站点组关系

View File

@ -39,8 +39,6 @@ public interface GSitesMapper extends MPJBaseMapper<GSites>
* @param gGroupSiteDto 站点
* @return 结果
*/
@Insert("insert into g_site_groups (site_id, parent_id, project_id,order_num) " +
"value (#{siteId},#{parentId},#{projectId},#{orderNum})")
public int insertGSites(GGroupSiteDto gGroupSiteDto);
/**

View File

@ -64,4 +64,7 @@ public interface IGGroupsService
* @return 结果
*/
public int deleteGGroupsById(Long id);
List<?> selectGGroupsAndSitesList(GGroups gGroups);
}

View File

@ -1,10 +1,9 @@
package com.fastbee.ggroup.service;
import java.util.List;
import java.util.Map;
import com.fastbee.ggroup.domain.GLegend;
import com.fastbee.ggroup.domain.dto.GLegendCateGoryDto;
import com.fastbee.ggroup.domain.dto.GLegendUpdateDto;
import com.fastbee.ggroup.domain.dto.GLegendDto;
/**
@ -21,10 +20,10 @@ public interface IGLegendService
* @param id 图例主键
* @return 图例
*/
public GLegend selectGLegendById(Long id);
public GLegendDto selectGLegendById(Long id);
/**
* 查询图例列表
* 查询/搜索图例列表
*
* @param gLegend 图例
* @return 图例集合
@ -45,7 +44,7 @@ public interface IGLegendService
* @param gLegend 图例
* @return 结果
*/
public int updateGLegend(GLegend gLegend);
public int updateGLegend(GLegendUpdateDto gLegend);
/**
* 批量删除图例

View File

@ -5,6 +5,7 @@ import com.fastbee.ggroup.domain.GSites;
import com.fastbee.ggroup.domain.dto.GGroupSiteDto;
import com.fastbee.ggroup.domain.dto.GGroupSiteRelateDto;
import com.fastbee.ggroup.domain.dto.GSitesEditDto;
import com.fastbee.ggroup.domain.dto.GSitesSelectDto;
/**
* 站点Service接口
@ -28,7 +29,7 @@ public interface IGSitesService
* @param gSites 站点
* @return 站点集合
*/
public List<GSites> selectGSitesList(GSites gSites);
public List<?> selectGSitesList(GSitesSelectDto gSites);
/**
* 新增站点
@ -70,5 +71,10 @@ public interface IGSitesService
*/
int relateGroup(GGroupSiteRelateDto gGroupSiteRelateDto);
/**
* 搜索站点列表
* @param gSites
* @return
*/
List<GSites> searchGSitesList(GSites gSites);
}

View File

@ -1,11 +1,21 @@
package com.fastbee.ggroup.service.impl;
import cn.hutool.extra.ssh.JschUtil;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.ggroup.domain.GGroups;
import com.fastbee.ggroup.domain.GSiteGroups;
import com.fastbee.ggroup.domain.GSites;
import com.fastbee.ggroup.domain.vo.GGroupSiteVo;
import com.fastbee.ggroup.mapper.GGroupsMapper;
import com.fastbee.ggroup.mapper.GSiteGroupsMapper;
import com.fastbee.ggroup.mapper.GSitesMapper;
import com.fastbee.ggroup.service.IGGroupsService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -15,6 +25,7 @@ import java.util.List;
import java.util.Map;
/**
* 组Service业务层处理
*
@ -27,6 +38,12 @@ public class GGroupsServiceImpl implements IGGroupsService
@Autowired
private GGroupsMapper gGroupsMapper;
@Autowired
private GSitesMapper gSitesMapper;
@Autowired
private GSiteGroupsMapper gSiteGroupsMapper;
/**
* 查询组
*
@ -36,12 +53,10 @@ public class GGroupsServiceImpl implements IGGroupsService
@Override
public GGroups selectGGroupsById(Long id)
{
return gGroupsMapper.selectGGroupsById(id);
}
/**
* 查询组列表
*
@ -51,22 +66,33 @@ public class GGroupsServiceImpl implements IGGroupsService
@Override
public List<GGroups> selectGGroupsList(GGroups gGroups)
{
List<GGroups> groups = gGroupsMapper.selectGGroupsList(gGroups);
return buildTree(groups);
return buildTree(gGroupsMapper.selectGGroupsList(gGroups));
}
/**
* 查询/搜索组列表
*
* @param gGroups
* @return
*/
@Override
public List<GGroupSiteVo> selectGGroupsListSites(GGroups gGroups) {
return gGroupsMapper.selectGGroupsSiteList(gGroups);
}
private List<GGroups> buildTree(List<GGroups> groups) {
Map<Long, GGroups> map = new HashMap<>();
List<GGroups> roots = new ArrayList<>();
for (GGroups group : groups) {
map.put(group.getId(), group);
}
return getgGroups(groups, map, roots);
}
/**
* 组合组树状结构列表
*/
private List<GGroups> getgGroups(List<GGroups> groups, Map<Long, GGroups> map, List<GGroups> roots) {
for (GGroups group : groups) {
Long parentId = group.getParentId();
if (parentId == null || !map.containsKey(parentId)) {
@ -79,13 +105,42 @@ public class GGroupsServiceImpl implements IGGroupsService
parent.getChildren().add(group);
}
}
return roots;
}
private List<GGroups> buildTreeSite(List<GGroups> groupsList) {
// 构建一个Map用于存储每个组对象:id->组对象
Map<Long, GGroups> map = new HashMap<>();
//根组列表
List<GGroups> roots = new ArrayList<>();
for (GGroups group : groupsList) {
//查询组的直接子站点列表
//TODO 优化为查询出所有站点列表内存中处理
List<GGroupSiteVo> gGroupSiteVoList = gGroupsMapper.selectGGroupsSiteList(GGroups.builder()
.parentId(group.getId())
.build());
//将子站点列表添加到组对象中
List<GGroups> childrenList= group.getChildren();
gGroupSiteVoList.forEach(site->{
childrenList.add(GGroups.builder()
.id(site.getId())
.name(site.getName())
.icon(site.getIcon())
.space(site.getSpace())
.spaceValue(site.getSpaceValue())
.nodeType(1)
.siteId(site.getId())
.build());
});
map.put(group.getId(), group);
}
//构建组树状结构
return getgGroups(groupsList, map, roots);
}
/**
* 新增组
*
*
* @param gGroups
* @return 结果
*/
@ -132,4 +187,15 @@ public class GGroupsServiceImpl implements IGGroupsService
{
return gGroupsMapper.deleteGGroupsById(id);
}
/**
* 查询组和站点的树状结构
* @param gGroups
* @return 列表
*/
@Override
public List<?> selectGGroupsAndSitesList(GGroups gGroups) {
//组的树状结构
return buildTreeSite(gGroupsMapper.selectGGroupsList(gGroups));
}
}

View File

@ -1,6 +1,5 @@
package com.fastbee.ggroup.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -8,8 +7,10 @@ import java.util.stream.Collectors;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.ggroup.domain.GLegendType;
import com.fastbee.ggroup.domain.dto.GLegendUpdateDto;
import com.fastbee.ggroup.domain.dto.GLegendCateGoryDto;
import com.fastbee.ggroup.domain.dto.GLegendDto;
import com.fastbee.ggroup.mapper.GLegendTypeMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -18,12 +19,13 @@ import org.springframework.stereotype.Service;
import com.fastbee.ggroup.mapper.GLegendMapper;
import com.fastbee.ggroup.domain.GLegend;
import com.fastbee.ggroup.service.IGLegendService;
import org.springframework.transaction.annotation.Transactional;
/**
* 图例Service业务层处理
*
* @author kerwincui
* @date 2024-10-08
* &#064;date 2024-10-08
*/
@Service
@Slf4j
@ -32,6 +34,9 @@ public class GLegendServiceImpl implements IGLegendService
@Autowired
private GLegendMapper gLegendMapper;
@Autowired
private GLegendTypeMapper gLegendTypeMapper;
/**
* 查询图例
*
@ -39,28 +44,29 @@ public class GLegendServiceImpl implements IGLegendService
* @return 图例
*/
@Override
public GLegend selectGLegendById(Long id)
public GLegendDto selectGLegendById(Long id)
{
return gLegendMapper.selectGLegendById(id);
return gLegendMapper.selectJoinOne(GLegendDto.class,new MPJLambdaWrapper<GLegend>()
.select(GLegend::getId,GLegend::getIcon,GLegend::getType,GLegend::getName)
.select(GLegendType::getTypeName,GLegendType::getCategory)
.leftJoin(GLegendType.class,GLegendType::getId,GLegend::getType)
.eq(GLegend::getId,id));
}
/**
* 查询图例列表
*
* 查询/搜索图例列表
* @param gLegend 图例
* @return 图例
*/
@Override
public List<GLegendDto> selectGLegendList(GLegend gLegend)
{
MPJLambdaWrapper<GLegend> wrapper = new MPJLambdaWrapper<GLegend>()
.select(GLegend::getId,GLegend::getIcon,GLegend::getType,GLegend::getName)
.select(GLegendType::getTypeName,GLegendType::getCategory)
.leftJoin(GLegendType.class,GLegendType::getId,GLegend::getType);
if(StringUtils.isNotBlank(gLegend.getSearchValue())){
wrapper.like(GLegend::getName,gLegend.getSearchValue());
}
return gLegendMapper.selectJoinList(GLegendDto.class,wrapper);
public List<GLegendDto> selectGLegendList(GLegend gLegend) {
return gLegendMapper.selectJoinList(GLegendDto.class, new MPJLambdaWrapper<GLegend>()
.select(GLegend::getId, GLegend::getIcon, GLegend::getType, GLegend::getName)
.select(GLegendType::getTypeName, GLegendType::getCategory)
.leftJoin(GLegendType.class, GLegendType::getId, GLegend::getType)
.like(StringUtils.isNotBlank(gLegend.getSearchValue()),
GLegend::getName, StringUtils.isNotBlank(gLegend.getSearchValue()) ?
gLegend.getSearchValue() : null));
}
/**
@ -72,7 +78,6 @@ public class GLegendServiceImpl implements IGLegendService
@Override
public int insertGLegend(GLegend gLegend)
{
gLegend.setCreateTime(DateUtils.getNowDate());
return gLegendMapper.insertGLegend(gLegend);
}
@ -83,12 +88,22 @@ public class GLegendServiceImpl implements IGLegendService
* @return 结果
*/
@Override
public int updateGLegend(GLegend gLegend)
@Transactional(rollbackFor = Exception.class)
public int updateGLegend(GLegendUpdateDto gLegend)
{
gLegend.setUpdateTime(DateUtils.getNowDate());
return gLegendMapper.updateGLegend(gLegend);
return (gLegendTypeMapper.updateGLegendType(GLegendType.builder()
.id( gLegend.getType())
.category(gLegend.getCategory())
.updateTime(DateUtils.getNowDate())
.build())==1&&
gLegendMapper.updateGLegend( GLegend.builder()
.id(gLegend.getId())
.icon(gLegend.getIcon())
.name(gLegend.getName())
.type(gLegend.getType())
.updateTime(DateUtils.getNowDate())
.build())==1)?1:0;
}
/**
* 批量删除图例
*
@ -113,31 +128,27 @@ public class GLegendServiceImpl implements IGLegendService
return gLegendMapper.deleteGLegendById(id);
}
/**
* 按照类别返回所有类别下图例列表
* @return 图例列表
*/
@Override
public List<?> getLegendListByCategory() {
MPJLambdaWrapper<GLegend> wrapper = new MPJLambdaWrapper<GLegend>()
public List<Map<String, Object>> getLegendListByCategory() {
// 按照类别分组并生成结果列表
return gLegendMapper.selectJoinList(GLegendCateGoryDto.class, new MPJLambdaWrapper<GLegend>()
.select(GLegend::getIcon, GLegend::getName)
.select(GLegendType::getTypeName, GLegendType::getCategory)
.leftJoin(GLegendType.class, GLegendType::getId, GLegend::getType);
// 获取所有的 GLegendCateGoryDto 列表
List<GLegendCateGoryDto> gLegendCateGoryList = gLegendMapper.selectJoinList(GLegendCateGoryDto.class, wrapper);
// 按照类别分成多个list结集合
gLegendCateGoryList.forEach(System.err::println);
Map<String, List<GLegendCateGoryDto>> map = gLegendCateGoryList.stream()
.collect(Collectors.groupingBy(GLegendCateGoryDto::getCategory));
System.err.println(map);
List<Map<String, Object>> list=new ArrayList<>();
// 循环这个map
for (Map.Entry<String, List<GLegendCateGoryDto>> entry : map.entrySet()) {
System.err.println(entry.getKey() + " : " + entry.getValue());
Map<String,Object> itemMap=new HashMap<>();
itemMap.put("category",entry.getKey());
itemMap.put("list",entry.getValue());
list.add(itemMap);
}
return list;
.leftJoin(GLegendType.class, GLegendType::getId, GLegend::getType)).stream()
.collect(Collectors.groupingBy(GLegendCateGoryDto::getCategory))
.entrySet().stream()
.map(entry -> {
Map<String, Object> itemMap = new HashMap<>();
itemMap.put("category", entry.getKey());
itemMap.put("list", entry.getValue());
return itemMap;
})
.collect(Collectors.toList());
}
}

View File

@ -1,17 +1,27 @@
package com.fastbee.ggroup.service.impl;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import cn.hutool.json.JSONException;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fastbee.common.config.RuoYiConfig;
import com.fastbee.common.exception.ServiceException;
import com.fastbee.ggroup.domain.GSiteGroups;
import com.fastbee.ggroup.domain.dto.GGroupSiteDto;
import com.fastbee.ggroup.domain.dto.GGroupSiteRelateDto;
import com.fastbee.ggroup.domain.dto.GSitesEditDto;
import com.fastbee.ggroup.domain.dto.GSitesSelectDto;
import com.fastbee.ggroup.mapper.GSiteGroupsMapper;
import org.apache.commons.lang3.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -24,9 +34,10 @@ import org.springframework.transaction.annotation.Transactional;
* 站点Service业务层处理
*
* @author kerwincui
* @date 2024-09-29
* &#064;date 2024-09-29
*/
@Service
@Slf4j
public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups> implements IGSitesService {
@Autowired
private GSitesMapper gSitesMapper;
@ -46,14 +57,13 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
}
/**
* 查询全部站点列表
* 查询/搜索全部站点列表
*
* @param gSites 站点
* @return 站点
*/
@Override
public List<GSites> selectGSitesList(GSites gSites) {
public List<?> selectGSitesList(GSitesSelectDto gSites) {
return gSitesMapper.selectList(new LambdaQueryWrapper<GSites>()
.select(GSites::getId, GSites::getName, GSites::getIcon, GSites::getType)
.eq(GSites::getProjectId, gSites.getProjectId())
@ -76,17 +86,40 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
GSites sameNameSite = gSitesMapper.selectOne(new LambdaQueryWrapper<GSites>()
.select(GSites::getName, GSites::getId)
.eq(GSites::getName, gGroupSiteDto.getName().trim()));
if (Objects.isNull(sameNameSite )) {
if (Objects.nonNull(sameNameSite)) {
throw new ServiceException("站点名称重复!");
}
//设置坐标值等信息
getReadJsonFileContent(gSites);
//插入站点表
int inserted = gSitesMapper.insert(gSites);
gGroupSiteDto.setSiteId(gSites.getId());
//插入关系表
int inserted1 = gSitesMapper.insertGSites(gGroupSiteDto);
int inserted1 = gSiteGroupsMapper.insertGSiteGroups(gGroupSiteDto);
return inserted == 1 && inserted1 == 1 ? 1 : 0;
}
/**
* 读取上传的站点图信息并赋值
* @param gSites 站点
*/
private void getReadJsonFileContent(GSites gSites) {
String json;
try {
//TODO: 文件路径拼接优化
InputStream i = Files.newInputStream(new File(RuoYiConfig.getProfile() + gSites.getSpace().substring(15)).toPath());
json = IOUtils.toString(i, StandardCharsets.UTF_8);
//校验json格式是否正确
if (!isValidJson(json)) {
throw new ServiceException("json格式不正确");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
gSites.setSpaceValue(json);
}
/**
* 修改站点
*
@ -105,9 +138,23 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
}
GSites sites = new GSites();
BeanUtils.copyProperties(gSitesEditDto, sites);
//读取文件内容
getReadJsonFileContent(sites);
return gSitesMapper.updateById(sites);
}
/**
* 验证字符串是否是json格式
*/
public boolean isValidJson(String jsonStr) {
try {
JSONUtil.parseObj(jsonStr);
} catch (JSONException e) {
return false;
}
return true;
}
/**
* 批量删除站点
*
@ -138,25 +185,16 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
*/
@Override
public int relateGroup(GGroupSiteRelateDto gGroupSiteRelateDto) {
if (StringUtils.isBlank(gGroupSiteRelateDto.getParentId().toString())) {
throw new ServiceException("请选择分组!");
}
List<Long> siteIds = gGroupSiteRelateDto.getSiteIds();
if (siteIds.isEmpty()) {
throw new ServiceException("请选择站点!");
}
super.saveBatch(siteIds
return super.saveBatch(gGroupSiteRelateDto.getSiteIds()
.stream()
.map(this::setSiteIdToSiteGroups)
.map(siteId -> GSiteGroups.builder().siteId(siteId).build())
.collect(Collectors.toList())
.stream()
.map(item -> {
.peek(item -> {
item.setParentId(gGroupSiteRelateDto.getParentId());
item.setProjectId(gGroupSiteRelateDto.getProjectId());
return item;
})
.collect(Collectors.toList()));
return 1;
.collect(Collectors.toList()))? 1 : 0;
}
@Override
@ -167,11 +205,7 @@ public class GSitesServiceImpl extends ServiceImpl<GSiteGroupsMapper,GSiteGroups
.like(GSites::getName, gSites.getSearchValue()));
}
private GSiteGroups setSiteIdToSiteGroups(Long siteId) {
GSiteGroups gSiteGroups = new GSiteGroups();
gSiteGroups.setSiteId(siteId);
return gSiteGroups;
}
}

View File

@ -35,29 +35,7 @@
where id = #{id}
</select>
<insert id="insertGSiteGroups" parameterType="GSiteGroups" useGeneratedKeys="true" keyProperty="id">
insert into g_site_groups
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="siteId != null">site_id,</if>
<if test="parentId != null">parent_id,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="projectId != null">project_id,</if>
<if test="orderNum != null">order_num,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="siteId != null">#{siteId},</if>
<if test="parentId != null">#{parentId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="projectId != null">#{projectId},</if>
<if test="orderNum != null">#{orderNum},</if>
</trim>
</insert>
<update id="updateGSiteGroups" parameterType="GSiteGroups">
update g_site_groups

View File

@ -37,29 +37,31 @@
where id = #{id}
</select>
<!-- <insert id="insertGSites" parameterType="GSites" useGeneratedKeys="true" keyProperty="id">-->
<!-- insert into g_sites-->
<!-- <trim prefix="(" suffix=")" suffixOverrides=",">-->
<!-- <if test="name != null and name != ''">name,</if>-->
<!-- <if test="icon != null">icon,</if>-->
<!-- <if test="type != null">type,</if>-->
<!-- <if test="createBy != null">create_by,</if>-->
<!-- <if test="createTime != null">create_time,</if>-->
<!-- <if test="updateTime != null">update_time,</if>-->
<!-- <if test="updateBy != null">update_by,</if>-->
<!-- <if test="space != null">space,</if>-->
<!-- </trim>-->
<!-- <trim prefix="values (" suffix=")" suffixOverrides=",">-->
<!-- <if test="name != null and name != ''">#{name},</if>-->
<!-- <if test="icon != null">#{icon},</if>-->
<!-- <if test="type != null">#{type},</if>-->
<!-- <if test="createBy != null">#{createBy},</if>-->
<!-- <if test="createTime != null">#{createTime},</if>-->
<!-- <if test="updateTime != null">#{updateTime},</if>-->
<!-- <if test="updateBy != null">#{updateBy},</if>-->
<!-- <if test="space != null">#{space},</if>-->
<!-- </trim>-->
<!-- </insert>-->
<insert id="insertGSites" parameterType="GSites" useGeneratedKeys="true" keyProperty="id">
insert into g_sites
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">name,</if>
<if test="icon != null">icon,</if>
<if test="type != null">type,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="space != null">space,</if>
<if test="spaceValue != null">spaceValue,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null and name != ''">#{name},</if>
<if test="icon != null">#{icon},</if>
<if test="type != null">#{type},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="space != null">#{space},</if>
<if test="spaceValue != null">#{spaceValue},</if>
</trim>
</insert>
<update id="updateGSites" parameterType="GSitesEditDto">
update g_sites
@ -72,6 +74,7 @@
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="space != null">space = #{space},</if>
<if test="spaceValue != null">space_value = #{spaceValue},</if>
</trim>
where id = #{id}
</update>