视频分组改成tree

This commit is contained in:
guoshengxiong 2024-05-17 18:40:47 +08:00
parent aa01896a2e
commit 7a35cc8257
6 changed files with 147 additions and 48 deletions

View File

@ -1,9 +1,11 @@
package com.zhgd.xmgl.modules.video.controller; package com.zhgd.xmgl.modules.video.controller;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.zhgd.xmgl.modules.video.entity.VideoGroup;
import com.zhgd.xmgl.modules.video.service.IVideoGroupService; 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.Api;
import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
@ -11,11 +13,10 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody; import springfox.documentation.annotations.ApiIgnore;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -50,15 +51,25 @@ import java.util.Map;
return result; return result;
} }
/** @ApiOperation(value = "树形列表查询视频分组信息", notes = "树形列表查询视频分组信息", httpMethod = "GET")
* 添加 @ApiImplicitParams({
* @param videoGroup @ApiImplicitParam(name = "projectSn", value = "一级公司sn", paramType = "body", required = true, dataType = "String"),
* @return })
*/ @GetMapping(value = "tree/list")
@ApiOperation(value = "添加视频分组信息", notes = "添加视频分组信息", httpMethod = "POST") public Result<JSONArray> treeList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
@PostMapping(value = "/add") return Result.success(videoGroupService.treeList(paramMap));
public Result<VideoGroup> add(@RequestBody VideoGroup videoGroup) { }
videoGroupService.saveVideoGroup(videoGroup);
/**
* 添加
*
* @param videoGroup
* @return
*/
@ApiOperation(value = "添加视频分组信息", notes = "添加视频分组信息", httpMethod = "POST")
@PostMapping(value = "/add")
public Result<VideoGroup> add(@RequestBody VideoGroup videoGroup) {
videoGroupService.saveVideoGroup(videoGroup);
return Result.ok(); return Result.ok();
} }

View File

@ -22,17 +22,25 @@ import io.swagger.annotations.ApiModelProperty;
@ApiModel(value="VideoGroup实体类",description="VideoGroup") @ApiModel(value="VideoGroup实体类",description="VideoGroup")
public class VideoGroup implements Serializable { public class VideoGroup implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**id*/ /**id*/
@TableId(type = IdType.ASSIGN_ID) @TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value="id") @ApiModelProperty(value = "id")
private java.lang.Long id ; private java.lang.Long id;
/**项目sn*/ /**
@Excel(name = "项目sn", width = 15) * 项目sn
@ApiModelProperty(value="项目sn") */
private java.lang.String projectSn ; @Excel(name = "项目sn", width = 15)
/**分组名称*/ @ApiModelProperty(value = "项目sn")
@Excel(name = "分组名称", width = 15) private java.lang.String projectSn;
@ApiModelProperty(value="分组名称") /**
private java.lang.String groupName ; * 分组名称
*/
@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;
} }

View File

@ -7,15 +7,20 @@ import com.zhgd.jeecg.common.mybatis.EntityMap;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.zhgd.xmgl.modules.video.entity.VideoGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
/** /**
* @Description: 视频分组 * @Description: 视频分组
* @author pds * @author pds
* @date 2021-07-08 * @date 2021-07-08
* @version V1.0 * @version V1.0
*/ */
@Mapper @Mapper
public interface VideoGroupMapper extends BaseMapper<VideoGroup> { public interface VideoGroupMapper extends BaseMapper<VideoGroup> {
List<EntityMap> selectVideoGroupList(Map<String, Object> map); List<EntityMap> selectVideoGroupList(Map<String, Object> map);
List<VideoGroup> getChildren(Long id);
void updateAncestors(@Param("oldAncestor") String oldAncestor, @Param("newAncestor") String newAncestor, @Param("projectSn") String projectSn, @Param("id") Long id);
} }

View File

@ -1,11 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper"> <mapper namespace="com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper">
<select id="selectVideoGroupList" resultType="com.zhgd.jeecg.common.mybatis.EntityMap"> <select id="selectVideoGroupList" resultType="com.zhgd.jeecg.common.mybatis.EntityMap">
SELECT a.*,a.group_name name SELECT a.*,a.group_name name
from video_group a from video_group a
WHERE a.project_sn=#{projectSn} WHERE a.project_sn=#{projectSn}
</select> </select>
</mapper>
<select id="getChildren" resultType="com.zhgd.xmgl.modules.video.entity.VideoGroup">
select * from video_group
where find_in_set(#{id}, ancestors)
</select>
<update id="updateAncestors">
UPDATE video_group
SET ancestors=REPLACE(ancestors, #{oldAncestor}, #{newAncestor})
WHERE ancestors LIKE N'${oldAncestor},${id}%' and project_sn = #{projectSn}
</update>
</mapper>

View File

@ -1,12 +1,16 @@
package com.zhgd.xmgl.modules.video.service; package com.zhgd.xmgl.modules.video.service;
import com.alibaba.fastjson.JSONArray;
import com.zhgd.xmgl.modules.video.entity.VideoGroup; import com.zhgd.xmgl.modules.video.entity.VideoGroup;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.HashMap;
import java.util.List;
/** /**
* @Description: 视频分组 * @Description: 视频分组
* @author pds * @author pds
* @date 2021-07-08 * @date 2021-07-08
* @version V1.0 * @version V1.0
*/ */
public interface IVideoGroupService extends IService<VideoGroup> { public interface IVideoGroupService extends IService<VideoGroup> {
@ -16,4 +20,6 @@ public interface IVideoGroupService extends IService<VideoGroup> {
void editVideoGroup(VideoGroup videoGroup); void editVideoGroup(VideoGroup videoGroup);
void deleteVideoGroup(String id); void deleteVideoGroup(String id);
JSONArray treeList(HashMap<String, Object> paramMap);
} }

View File

@ -1,23 +1,36 @@
package com.zhgd.xmgl.modules.video.service.impl; 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.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhgd.jeecg.common.execption.OpenAlertException; 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.VideoGroup;
import com.zhgd.xmgl.modules.video.entity.VideoItem; import com.zhgd.xmgl.modules.video.entity.VideoItem;
import com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper; import com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper;
import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper; import com.zhgd.xmgl.modules.video.mapper.VideoItemMapper;
import com.zhgd.xmgl.modules.video.service.IVideoGroupService; 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 com.zhgd.xmgl.util.MessageUtil;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* @Description: 视频分组 * @Description: 视频分组
* @author pds * @author pds
* @date 2021-07-08 * @date 2021-07-08
* @version V1.0 * @version V1.0
*/ */
@Service @Service
@ -30,37 +43,84 @@ public class VideoGroupServiceImpl extends ServiceImpl<VideoGroupMapper, VideoGr
@Override @Override
public void saveVideoGroup(VideoGroup videoGroup) { public void saveVideoGroup(VideoGroup videoGroup) {
QueryWrapper<VideoGroup> queryWrapper=new QueryWrapper<>(); QueryWrapper<VideoGroup> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(VideoGroup::getProjectSn,videoGroup.getProjectSn()) queryWrapper.lambda().eq(VideoGroup::getProjectSn, videoGroup.getProjectSn())
.eq(VideoGroup::getGroupName,videoGroup.getGroupName()); .eq(VideoGroup::getGroupName, videoGroup.getGroupName());
int count=videoGroupMapper.selectCount(queryWrapper); int count = videoGroupMapper.selectCount(queryWrapper);
if(count>0){ if (count > 0) {
throw new OpenAlertException(MessageUtil.get("nameExistErr")); 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<VideoGroup>()
.eq(VideoGroup::getId, videoGroup.getParentId()));
if (pOrg != null) {
videoGroup.setAncestors(pOrg.getAncestors() + "," + pOrg.getId());
}
}
videoGroupMapper.insert(videoGroup); videoGroupMapper.insert(videoGroup);
} }
@Override @Override
public void editVideoGroup(VideoGroup videoGroup) { public void editVideoGroup(VideoGroup videoGroup) {
QueryWrapper<VideoGroup> queryWrapper=new QueryWrapper<>(); QueryWrapper<VideoGroup> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(VideoGroup::getProjectSn,videoGroup.getProjectSn()) queryWrapper.lambda().eq(VideoGroup::getProjectSn, videoGroup.getProjectSn())
.eq(VideoGroup::getGroupName,videoGroup.getGroupName()) .eq(VideoGroup::getGroupName, videoGroup.getGroupName())
.ne(VideoGroup::getId,videoGroup.getId()); .ne(VideoGroup::getId, videoGroup.getId());
int count=videoGroupMapper.selectCount(queryWrapper); int count = videoGroupMapper.selectCount(queryWrapper);
if(count>0){ if (count > 0) {
throw new OpenAlertException(MessageUtil.get("nameExistErr")); throw new OpenAlertException(MessageUtil.get("nameExistErr"));
} }
videoGroupMapper.updateById(videoGroup); if (Objects.equals(videoGroup.getId(), videoGroup.getParentId())) {
throw new OpenAlertException("不能将分组移动到其自身");
}
List<VideoGroup> 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 @Override
public void deleteVideoGroup(String id) { public void deleteVideoGroup(String id) {
QueryWrapper<VideoItem> queryWrapper=new QueryWrapper<>(); QueryWrapper<VideoItem> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(VideoItem::getGroupId,id); queryWrapper.lambda().eq(VideoItem::getGroupId, id);
int count=videoItemMapper.selectCount(queryWrapper); int count = videoItemMapper.selectCount(queryWrapper);
if(count>0){ if (count > 0) {
throw new OpenAlertException(MessageUtil.get("videoGroupUseErr")); throw new OpenAlertException(MessageUtil.get("videoGroupUseErr"));
} }
List<VideoGroup> children = baseMapper.getChildren(Long.valueOf(id));
if (CollUtil.isNotEmpty(children)) {
throw new OpenAlertException("分组下存在子分组,请先删除子分组");
}
videoGroupMapper.deleteById(id); videoGroupMapper.deleteById(id);
} }
@Override
public JSONArray treeList(HashMap<String, Object> paramMap) {
QueryWrapper<VideoGroup> queryWrapper = QueryGenerator.initPageQueryWrapper(VideoGroup.class, paramMap);
return ListUtils.listToTree(JSONArray.parseArray(JSON.toJSONString(list(queryWrapper))), "id", "parentId", "children");
}
} }