From 7a35cc82571b0941cb80dea6c60f454a386d7bbf Mon Sep 17 00:00:00 2001 From: guoshengxiong <1923636941@qq.com> Date: Fri, 17 May 2024 18:40:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=88=86=E7=BB=84=E6=94=B9?= =?UTF-8?q?=E6=88=90tree?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/VideoGroupController.java | 37 ++++--- .../xmgl/modules/video/entity/VideoGroup.java | 30 +++--- .../video/mapper/VideoGroupMapper.java | 7 +- .../video/mapper/xml/VideoGroupMapper.xml | 15 ++- .../video/service/IVideoGroupService.java | 8 +- .../service/impl/VideoGroupServiceImpl.java | 98 +++++++++++++++---- 6 files changed, 147 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/zhgd/xmgl/modules/video/controller/VideoGroupController.java b/src/main/java/com/zhgd/xmgl/modules/video/controller/VideoGroupController.java index 67de1c005..522cde05a 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/controller/VideoGroupController.java +++ b/src/main/java/com/zhgd/xmgl/modules/video/controller/VideoGroupController.java @@ -1,9 +1,11 @@ package com.zhgd.xmgl.modules.video.controller; +import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.zhgd.xmgl.modules.video.service.IVideoGroupService; +import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -11,11 +13,10 @@ import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import springfox.documentation.annotations.ApiIgnore; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,15 +51,25 @@ import java.util.Map; return result; } - /** - * 添加 - * @param videoGroup - * @return - */ - @ApiOperation(value = "添加视频分组信息", notes = "添加视频分组信息", httpMethod = "POST") - @PostMapping(value = "/add") - public Result add(@RequestBody VideoGroup videoGroup) { - videoGroupService.saveVideoGroup(videoGroup); + @ApiOperation(value = "树形列表查询视频分组信息", notes = "树形列表查询视频分组信息", httpMethod = "GET") + @ApiImplicitParams({ + @ApiImplicitParam(name = "projectSn", value = "一级公司sn", paramType = "body", required = true, dataType = "String"), + }) + @GetMapping(value = "tree/list") + public Result treeList(@ApiIgnore @RequestParam HashMap paramMap) { + return Result.success(videoGroupService.treeList(paramMap)); + } + + /** + * 添加 + * + * @param videoGroup + * @return + */ + @ApiOperation(value = "添加视频分组信息", notes = "添加视频分组信息", httpMethod = "POST") + @PostMapping(value = "/add") + public Result add(@RequestBody VideoGroup videoGroup) { + videoGroupService.saveVideoGroup(videoGroup); return Result.ok(); } diff --git a/src/main/java/com/zhgd/xmgl/modules/video/entity/VideoGroup.java b/src/main/java/com/zhgd/xmgl/modules/video/entity/VideoGroup.java index 469197c9c..497464013 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/entity/VideoGroup.java +++ b/src/main/java/com/zhgd/xmgl/modules/video/entity/VideoGroup.java @@ -22,17 +22,25 @@ import io.swagger.annotations.ApiModelProperty; @ApiModel(value="VideoGroup实体类",description="VideoGroup") public class VideoGroup implements Serializable { private static final long serialVersionUID = 1L; - + /**id*/ @TableId(type = IdType.ASSIGN_ID) - @ApiModelProperty(value="id") - private java.lang.Long id ; - /**项目sn*/ - @Excel(name = "项目sn", width = 15) - @ApiModelProperty(value="项目sn") - private java.lang.String projectSn ; - /**分组名称*/ - @Excel(name = "分组名称", width = 15) - @ApiModelProperty(value="分组名称") - private java.lang.String groupName ; + @ApiModelProperty(value = "id") + private java.lang.Long id; + /** + * 项目sn + */ + @Excel(name = "项目sn", width = 15) + @ApiModelProperty(value = "项目sn") + private java.lang.String projectSn; + /** + * 分组名称 + */ + @Excel(name = "分组名称", width = 15) + @ApiModelProperty(value = "分组名称") + private java.lang.String groupName; + @ApiModelProperty(value = "父级id") + private java.lang.Long parentId; + @ApiModelProperty(value = "祖级列表") + private java.lang.String ancestors; } diff --git a/src/main/java/com/zhgd/xmgl/modules/video/mapper/VideoGroupMapper.java b/src/main/java/com/zhgd/xmgl/modules/video/mapper/VideoGroupMapper.java index eec173f83..db46f9b58 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/mapper/VideoGroupMapper.java +++ b/src/main/java/com/zhgd/xmgl/modules/video/mapper/VideoGroupMapper.java @@ -7,15 +7,20 @@ import com.zhgd.jeecg.common.mybatis.EntityMap; import org.apache.ibatis.annotations.Mapper; import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; /** * @Description: 视频分组 * @author: pds - * @date: 2021-07-08 + * @date: 2021-07-08 * @version: V1.0 */ @Mapper public interface VideoGroupMapper extends BaseMapper { List selectVideoGroupList(Map map); + + List getChildren(Long id); + + void updateAncestors(@Param("oldAncestor") String oldAncestor, @Param("newAncestor") String newAncestor, @Param("projectSn") String projectSn, @Param("id") Long id); } diff --git a/src/main/java/com/zhgd/xmgl/modules/video/mapper/xml/VideoGroupMapper.xml b/src/main/java/com/zhgd/xmgl/modules/video/mapper/xml/VideoGroupMapper.xml index b68997f29..a5cc156b9 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/mapper/xml/VideoGroupMapper.xml +++ b/src/main/java/com/zhgd/xmgl/modules/video/mapper/xml/VideoGroupMapper.xml @@ -1,11 +1,20 @@ - - \ No newline at end of file + + + + + UPDATE video_group + SET ancestors=REPLACE(ancestors, #{oldAncestor}, #{newAncestor}) + WHERE ancestors LIKE N'${oldAncestor},${id}%' and project_sn = #{projectSn} + + diff --git a/src/main/java/com/zhgd/xmgl/modules/video/service/IVideoGroupService.java b/src/main/java/com/zhgd/xmgl/modules/video/service/IVideoGroupService.java index 38877dd94..f1d1d4435 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/service/IVideoGroupService.java +++ b/src/main/java/com/zhgd/xmgl/modules/video/service/IVideoGroupService.java @@ -1,12 +1,16 @@ package com.zhgd.xmgl.modules.video.service; +import com.alibaba.fastjson.JSONArray; import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.HashMap; +import java.util.List; + /** * @Description: 视频分组 * @author: pds - * @date: 2021-07-08 + * @date: 2021-07-08 * @version: V1.0 */ public interface IVideoGroupService extends IService { @@ -16,4 +20,6 @@ public interface IVideoGroupService extends IService { void editVideoGroup(VideoGroup videoGroup); void deleteVideoGroup(String id); + + JSONArray treeList(HashMap paramMap); } diff --git a/src/main/java/com/zhgd/xmgl/modules/video/service/impl/VideoGroupServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/video/service/impl/VideoGroupServiceImpl.java index 1e4379bed..a373854bc 100644 --- a/src/main/java/com/zhgd/xmgl/modules/video/service/impl/VideoGroupServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/video/service/impl/VideoGroupServiceImpl.java @@ -1,23 +1,36 @@ package com.zhgd.xmgl.modules.video.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.zhgd.jeecg.common.execption.OpenAlertException; +import com.zhgd.jeecg.common.system.query.QueryGenerator; import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.zhgd.xmgl.modules.video.entity.VideoItem; import com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper; import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper; import com.zhgd.xmgl.modules.video.service.IVideoGroupService; +import com.zhgd.xmgl.modules.xz.entity.XzProjectOrg; +import com.zhgd.xmgl.util.ListUtils; import com.zhgd.xmgl.util.MessageUtil; +import org.apache.commons.collections.MapUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; - -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + /** * @Description: 视频分组 * @author: pds - * @date: 2021-07-08 + * @date: 2021-07-08 * @version: V1.0 */ @Service @@ -30,37 +43,84 @@ public class VideoGroupServiceImpl extends ServiceImpl queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(VideoGroup::getProjectSn,videoGroup.getProjectSn()) - .eq(VideoGroup::getGroupName,videoGroup.getGroupName()); - int count=videoGroupMapper.selectCount(queryWrapper); - if(count>0){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(VideoGroup::getProjectSn, videoGroup.getProjectSn()) + .eq(VideoGroup::getGroupName, videoGroup.getGroupName()); + int count = videoGroupMapper.selectCount(queryWrapper); + if (count > 0) { throw new OpenAlertException(MessageUtil.get("nameExistErr")); } + boolean top = videoGroup.getParentId() == null || videoGroup.getParentId() == 0; + if (top) { + videoGroup.setParentId(0L); + videoGroup.setAncestors("0"); + } else { + VideoGroup pOrg = videoGroupMapper.selectOne(new LambdaQueryWrapper() + .eq(VideoGroup::getId, videoGroup.getParentId())); + if (pOrg != null) { + videoGroup.setAncestors(pOrg.getAncestors() + "," + pOrg.getId()); + } + } videoGroupMapper.insert(videoGroup); } @Override public void editVideoGroup(VideoGroup videoGroup) { - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(VideoGroup::getProjectSn,videoGroup.getProjectSn()) - .eq(VideoGroup::getGroupName,videoGroup.getGroupName()) - .ne(VideoGroup::getId,videoGroup.getId()); - int count=videoGroupMapper.selectCount(queryWrapper); - if(count>0){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(VideoGroup::getProjectSn, videoGroup.getProjectSn()) + .eq(VideoGroup::getGroupName, videoGroup.getGroupName()) + .ne(VideoGroup::getId, videoGroup.getId()); + int count = videoGroupMapper.selectCount(queryWrapper); + if (count > 0) { throw new OpenAlertException(MessageUtil.get("nameExistErr")); } - videoGroupMapper.updateById(videoGroup); + if (Objects.equals(videoGroup.getId(), videoGroup.getParentId())) { + throw new OpenAlertException("不能将分组移动到其自身"); + } + List children = baseMapper.getChildren(videoGroup.getId()); + for (VideoGroup child : children) { + if (child.getId().equals(videoGroup.getParentId())) { + throw new OpenAlertException("不能将分组移动到其自身下级"); + } + } + VideoGroup pOrg = videoGroupMapper.selectById(videoGroup.getParentId()); + // 修改子分组 + boolean top = videoGroup.getParentId() == null || videoGroup.getParentId() == 0; + if (top) { + videoGroup.setParentId(0L); + videoGroup.setAncestors("0"); + } else { + if (pOrg == null) { + throw new OpenAlertException("上级分组不存在"); + } + videoGroup.setAncestors(pOrg.getAncestors() + "," + pOrg.getId()); + } + VideoGroup oldPo = baseMapper.selectById(videoGroup.getId()); + if (oldPo == null) { + throw new OpenAlertException("分组不存在"); + } + baseMapper.updateAncestors(oldPo.getAncestors(), videoGroup.getAncestors(), videoGroup.getProjectSn(), videoGroup.getId()); + baseMapper.updateById(videoGroup); } @Override public void deleteVideoGroup(String id) { - QueryWrapper queryWrapper=new QueryWrapper<>(); - queryWrapper.lambda().eq(VideoItem::getGroupId,id); - int count=videoItemMapper.selectCount(queryWrapper); - if(count>0){ + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.lambda().eq(VideoItem::getGroupId, id); + int count = videoItemMapper.selectCount(queryWrapper); + if (count > 0) { throw new OpenAlertException(MessageUtil.get("videoGroupUseErr")); } + List children = baseMapper.getChildren(Long.valueOf(id)); + if (CollUtil.isNotEmpty(children)) { + throw new OpenAlertException("分组下存在子分组,请先删除子分组"); + } videoGroupMapper.deleteById(id); } + + @Override + public JSONArray treeList(HashMap paramMap) { + QueryWrapper queryWrapper = QueryGenerator.initPageQueryWrapper(VideoGroup.class, paramMap); + return ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(list(queryWrapper))), "id", "parentId", "children"); + } }