VideoContentCatController.java 11.5 KB
Newer Older
liqin's avatar
liqin committed
1 2
package cn.wisenergy.chnmuseum.party.web.controller;

wzp's avatar
wzp committed
3 4 5
import cn.wisenergy.chnmuseum.party.common.log.MethodLog;
import cn.wisenergy.chnmuseum.party.common.log.OperModule;
import cn.wisenergy.chnmuseum.party.common.log.OperType;
liqin's avatar
liqin committed
6 7
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
liqin's avatar
liqin committed
8 9 10 11
import cn.wisenergy.chnmuseum.party.model.CopyrightOwner;
import cn.wisenergy.chnmuseum.party.model.CopyrightOwnerVideoContentCat;
import cn.wisenergy.chnmuseum.party.model.VideoContent;
import cn.wisenergy.chnmuseum.party.model.VideoContentCat;
liqin's avatar
liqin committed
12
import cn.wisenergy.chnmuseum.party.service.*;
liqin's avatar
liqin committed
13 14
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
liqin's avatar
liqin committed
16 17 18 19 20 21 22 23
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
wzp's avatar
wzp committed
24
import org.apache.shiro.authz.annotation.RequiresAuthentication;
liqin's avatar
liqin committed
25 26 27 28
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
liqin's avatar
liqin committed
29
import java.util.Collections;
liqin's avatar
liqin committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * <pre>
 * 视频内容分类 前端控制器
 * </pre>
 *
 * @author Danny Lee
 * @since 2021-03-17
 */
@Slf4j
@RestController
@RequestMapping("/videoContentCat")
@Api(tags = {"视频内容分类接口"})
public class VideoContentCatController extends BaseController {

liqin's avatar
liqin committed
49 50 51
    @Resource
    private CopyrightOwnerVideoContentCatService copyrightOwnerVideoContentCatService;

liqin's avatar
liqin committed
52 53 54 55 56 57 58 59 60
    @Resource
    private VideoContentCatService videoContentCatService;

    @Resource
    private VideoContentService videoContentService;

    @Resource
    private CopyrightOwnerService copyrightOwnerService;

liqin's avatar
liqin committed
61 62 63 64 65 66
    @Resource
    private ExhibitionBoardService exhibitionBoardService;

    @Resource
    private CopyrightOwnerBoardCatService copyrightOwnerBoardCatService;

liqin's avatar
liqin committed
67
    @PostMapping(value = "/save")
wzp's avatar
wzp committed
68
    @RequiresAuthentication  //@RequiresPermissions("video:content:cat:save")
liqin's avatar
liqin committed
69
    @ApiOperation(value = "添加视频内容分类", notes = "添加视频内容分类")
wzp's avatar
wzp committed
70
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.ADD)
liqin's avatar
liqin committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84
    public Map<String, Object> saveVideoContentCat(@Validated(value = {Add.class}) VideoContentCat videoContentCat) {
        // 保存业务节点信息
        boolean result = videoContentCatService.save(videoContentCat);
        // 返回操作结果
        if (result) {
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping(value = "/update")
    @ApiOperation(value = "修改视频内容分类信息", notes = "修改视频内容分类信息")
wzp's avatar
wzp committed
85
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.UPDATE)
liqin's avatar
liqin committed
86 87 88 89 90 91 92 93
    public Map<String, Object> updateVideoContentCat(@Validated VideoContentCat videoContentCat) {
        boolean flag = videoContentCatService.updateById(videoContentCat);
        if (flag) {
            return getSuccessResult();
        }
        return getFailResult();
    }

liqin's avatar
liqin committed
94 95 96
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "copyrightOwnerId", value = "视频内容版权方ID", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
97
    @GetMapping("/getList")
wzp's avatar
wzp committed
98
    @RequiresAuthentication  //@RequiresPermissions("video:content:cat:list")
liqin's avatar
liqin committed
99
    @ApiOperation(value = "获取视频内容分类全部列表(无分页)", notes = "获取视频内容分类全部列表(无分页)")
wzp's avatar
wzp committed
100
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
101
    public Map<String, Object> getVideoContentCatList(@RequestParam(value = "copyrightOwnerId", required = false) List<String> copyrightOwnerIdList) {
liqin's avatar
liqin committed
102
        final LambdaQueryWrapper<VideoContentCat> videoContentCatLambdaQueryWrapper = Wrappers.<VideoContentCat>lambdaQuery().orderByDesc(VideoContentCat::getCreateTime);
liqin's avatar
liqin committed
103 104 105 106 107 108
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
            final LambdaQueryWrapper<CopyrightOwnerVideoContentCat> queryWrapper = Wrappers.<CopyrightOwnerVideoContentCat>lambdaQuery().in(CopyrightOwnerVideoContentCat::getCopyrightOwnerId, copyrightOwnerIdList);
            final List<CopyrightOwnerVideoContentCat> copyrightOwnerVideoContentCatList = this.copyrightOwnerVideoContentCatService.list(queryWrapper);
            if (!copyrightOwnerVideoContentCatList.isEmpty()) {
                final List<String> collect = copyrightOwnerVideoContentCatList.stream().map(CopyrightOwnerVideoContentCat::getVideoContentCatId).distinct().collect(Collectors.toList());
                videoContentCatLambdaQueryWrapper.in(VideoContentCat::getId, collect);
liqin's avatar
liqin committed
109 110
            } else {
                return getResult(Collections.emptyList());
liqin's avatar
liqin committed
111
            }
liqin's avatar
liqin committed
112 113
        }
        List<VideoContentCat> videoContentCatList = videoContentCatService.list(videoContentCatLambdaQueryWrapper);
liqin's avatar
liqin committed
114 115 116 117 118 119 120 121 122 123 124
        return getResult(videoContentCatList);
    }

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
    @PostMapping("/getPageList")
wzp's avatar
wzp committed
125
    @RequiresAuthentication  //@RequiresPermissions("video:content:cat:page")
liqin's avatar
liqin committed
126
    @ApiOperation(value = "获取视频内容分类分页列表", notes = "获取视频内容分类分页列表")
wzp's avatar
wzp committed
127
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
    public Map<String, Object> getVideoContentCatPageList(GenericPageParam genericPageParam) {
        LambdaQueryWrapper<VideoContentCat> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(VideoContentCat::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(VideoContentCat::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(VideoContentCat::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(VideoContentCat::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                VideoContentCat::getId,
                VideoContentCat::getName,
                VideoContentCat::getCreateTime,
                VideoContentCat::getUpdateTime);
        Page<VideoContentCat> page = this.videoContentCatService.page(getPage(), queryWrapper);
        for (VideoContentCat videoContentCat : page.getRecords()) {
            LambdaQueryWrapper<VideoContent> lambdaQueryWrapper = Wrappers.<VideoContent>lambdaQuery().eq(VideoContent::getVideoContentCatId, videoContentCat.getId());
            lambdaQueryWrapper = lambdaQueryWrapper.select(VideoContent::getId).select(VideoContent::getVideoContentCopyrightOwnerId);
            List<VideoContent> videoContentList = this.videoContentService.list(lambdaQueryWrapper);
            if (!videoContentList.isEmpty()) {
liqin's avatar
liqin committed
153 154
                final Set<String> videoContentCopyrightOwnerIdList = videoContentList.stream().map(VideoContent::getVideoContentCopyrightOwnerId).collect(Collectors.toSet());
                List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(videoContentCopyrightOwnerIdList);
liqin's avatar
liqin committed
155 156 157 158 159 160 161 162 163 164 165 166
                String copyrightOwnerName = copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.joining("、"));
                videoContentCat.setCopyrightOwnerName(copyrightOwnerName);
            }
        }
        return getResult(page);
    }

    @ApiOperation(value = "获取视频内容分类详情", notes = "获取视频内容分类详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
    })
    @GetMapping("/get/{id}")
wzp's avatar
wzp committed
167
    @RequiresAuthentication  //@RequiresPermissions("video:content:cat:get:id")
wzp's avatar
wzp committed
168
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
169 170 171 172 173
    public Map<String, Object> getById(@PathVariable("id") String id) {
        VideoContentCat videoContentCat = videoContentCatService.getById(id);
        return getResult(videoContentCat);
    }

liqin's avatar
liqin committed
174 175 176 177 178 179
    @DeleteMapping("/delete/{id}")
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:delete")
    @ApiOperation(value = "根据ID删除视频内容分类", notes = "根据ID删除视频内容分类")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String")
    })
wzp's avatar
wzp committed
180
    @MethodLog(operModule = OperModule.VIDEOCLASSIFY, operType = OperType.DELETE)
liqin's avatar
liqin committed
181 182
    public Map<String, Object> deleteVideoContentCat(@PathVariable("id") String id) {
        this.videoContentCatService.removeById(id);
liqin's avatar
liqin committed
183 184 185 186 187

        final LambdaUpdateWrapper<VideoContent> updateWrapper = Wrappers.<VideoContent>lambdaUpdate().eq(VideoContent::getVideoContentCatId, id);
        updateWrapper.set(VideoContent::getDeleted, true);
        this.videoContentService.update(updateWrapper);

liqin's avatar
liqin committed
188 189 190
        final LambdaUpdateWrapper<CopyrightOwnerVideoContentCat> updateWrapper1 = Wrappers.<CopyrightOwnerVideoContentCat>lambdaUpdate().eq(CopyrightOwnerVideoContentCat::getVideoContentCatId, id);
        this.copyrightOwnerVideoContentCatService.remove(updateWrapper1);

liqin's avatar
liqin committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204
//        final LambdaQueryWrapper<CopyrightOwnerVideoContentCat> eq = Wrappers.<CopyrightOwnerVideoContentCat>lambdaQuery().eq(CopyrightOwnerVideoContentCat::getVideoContentCatId, id);
//        final List<CopyrightOwnerVideoContentCat> list = this.copyrightOwnerVideoContentCatService.list(eq);
//        final List<String> collect = list.stream().map(CopyrightOwnerVideoContentCat::getCopyrightOwnerId).distinct().collect(Collectors.toList());
//
//        final LambdaUpdateWrapper<VideoContent> updateWrapper2 = Wrappers.<VideoContent>lambdaUpdate().in(VideoContent::getVideoContentCopyrightOwnerId, collect);
//        updateWrapper2.set(VideoContent::getDeleted, true);
//        this.videoContentService.update(updateWrapper2);
//
//        final LambdaUpdateWrapper<ExhibitionBoard> updateWrapper3 = Wrappers.<ExhibitionBoard>lambdaUpdate().in(ExhibitionBoard::getBoardCopyrightOwnerId, collect);
//        updateWrapper3.set(ExhibitionBoard::getDeleted, true);
//        this.exhibitionBoardService.update(updateWrapper3);
//
//        LambdaUpdateWrapper<CopyrightOwnerBoardCat> deleteWrapper = Wrappers.<CopyrightOwnerBoardCat>lambdaUpdate().in(CopyrightOwnerBoardCat::getCopyrightOwnerId, collect);
//        this.copyrightOwnerBoardCatService.remove(deleteWrapper);
liqin's avatar
liqin committed
205

liqin's avatar
liqin committed
206 207 208
        return getSuccessResult();
    }

liqin's avatar
liqin committed
209 210
}