视频分组改成tree
This commit is contained in:
parent
aa01896a2e
commit
7a35cc8257
@ -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<VideoGroup> 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<JSONArray> treeList(@ApiIgnore @RequestParam HashMap<String, Object> paramMap) {
|
||||
return Result.success(videoGroupService.treeList(paramMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param videoGroup
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "添加视频分组信息", notes = "添加视频分组信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<VideoGroup> add(@RequestBody VideoGroup videoGroup) {
|
||||
videoGroupService.saveVideoGroup(videoGroup);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
@ -25,14 +25,22 @@ public class VideoGroup implements Serializable {
|
||||
|
||||
/**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;
|
||||
}
|
||||
|
||||
@ -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<VideoGroup> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1,11 +1,20 @@
|
||||
<?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">
|
||||
<mapper namespace="com.zhgd.xmgl.modules.video.mapper.VideoGroupMapper">
|
||||
|
||||
<select id="selectVideoGroupList" resultType="com.zhgd.jeecg.common.mybatis.EntityMap">
|
||||
SELECT a.*,a.group_name name
|
||||
from video_group a
|
||||
WHERE a.project_sn=#{projectSn}
|
||||
|
||||
</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>
|
||||
@ -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<VideoGroup> {
|
||||
@ -16,4 +20,6 @@ public interface IVideoGroupService extends IService<VideoGroup> {
|
||||
void editVideoGroup(VideoGroup videoGroup);
|
||||
|
||||
void deleteVideoGroup(String id);
|
||||
|
||||
JSONArray treeList(HashMap<String, Object> paramMap);
|
||||
}
|
||||
|
||||
@ -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<VideoGroupMapper, VideoGr
|
||||
|
||||
@Override
|
||||
public void saveVideoGroup(VideoGroup videoGroup) {
|
||||
QueryWrapper<VideoGroup> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VideoGroup::getProjectSn,videoGroup.getProjectSn())
|
||||
.eq(VideoGroup::getGroupName,videoGroup.getGroupName());
|
||||
int count=videoGroupMapper.selectCount(queryWrapper);
|
||||
if(count>0){
|
||||
QueryWrapper<VideoGroup> 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<VideoGroup>()
|
||||
.eq(VideoGroup::getId, videoGroup.getParentId()));
|
||||
if (pOrg != null) {
|
||||
videoGroup.setAncestors(pOrg.getAncestors() + "," + pOrg.getId());
|
||||
}
|
||||
}
|
||||
videoGroupMapper.insert(videoGroup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void editVideoGroup(VideoGroup videoGroup) {
|
||||
QueryWrapper<VideoGroup> 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<VideoGroup> 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<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
|
||||
public void deleteVideoGroup(String id) {
|
||||
QueryWrapper<VideoItem> queryWrapper=new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VideoItem::getGroupId,id);
|
||||
int count=videoItemMapper.selectCount(queryWrapper);
|
||||
if(count>0){
|
||||
QueryWrapper<VideoItem> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(VideoItem::getGroupId, id);
|
||||
int count = videoItemMapper.selectCount(queryWrapper);
|
||||
if (count > 0) {
|
||||
throw new OpenAlertException(MessageUtil.get("videoGroupUseErr"));
|
||||
}
|
||||
List<VideoGroup> children = baseMapper.getChildren(Long.valueOf(id));
|
||||
if (CollUtil.isNotEmpty(children)) {
|
||||
throw new OpenAlertException("分组下存在子分组,请先删除子分组");
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user