视频分组改成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,8 +51,18 @@ import java.util.Map;
return result; return result;
} }
@ApiOperation(value = "树形列表查询视频分组信息", notes = "树形列表查询视频分组信息", httpMethod = "GET")
@ApiImplicitParams({
@ApiImplicitParam(name = "projectSn", value = "一级公司sn", paramType = "body", required = true, dataType = "String"),
})
@GetMapping(value = "tree/list")
public Result<JSONArray> treeList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
return Result.success(videoGroupService.treeList(paramMap));
}
/** /**
* 添加 * 添加
*
* @param videoGroup * @param videoGroup
* @return * @return
*/ */

View File

@ -27,12 +27,20 @@ public class VideoGroup implements Serializable {
@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*/ /**
* 项目sn
*/
@Excel(name = "项目sn", width = 15) @Excel(name = "项目sn", width = 15)
@ApiModelProperty(value = "项目sn") @ApiModelProperty(value = "项目sn")
private java.lang.String projectSn; private java.lang.String projectSn;
/**分组名称*/ /**
* 分组名称
*/
@Excel(name = "分组名称", width = 15) @Excel(name = "分组名称", width = 15)
@ApiModelProperty(value = "分组名称") @ApiModelProperty(value = "分组名称")
private java.lang.String groupName; private java.lang.String groupName;
@ApiModelProperty(value = "父级id")
private java.lang.Long parentId;
@ApiModelProperty(value = "祖级列表")
private java.lang.String ancestors;
} }

View File

@ -7,6 +7,7 @@ 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: 视频分组
@ -18,4 +19,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
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>
<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> </mapper>

View File

@ -1,8 +1,12 @@
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
@ -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,19 +1,32 @@
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
@ -37,6 +50,17 @@ public class VideoGroupServiceImpl extends ServiceImpl<VideoGroupMapper, VideoGr
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);
} }
@ -50,7 +74,33 @@ public class VideoGroupServiceImpl extends ServiceImpl<VideoGroupMapper, VideoGr
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
@ -61,6 +111,16 @@ public class VideoGroupServiceImpl extends ServiceImpl<VideoGroupMapper, VideoGr
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");
}
} }