ExhibitionBoardCatController.java 16.5 KB
Newer Older
liqin's avatar
liqin committed
1
package cn.chnmuseum.party.web.controller;
liqin's avatar
liqin committed
2

liqin's avatar
liqin committed
3 4 5 6 7 8 9 10 11 12
import cn.chnmuseum.party.common.enums.AuditStatusEnum;
import cn.chnmuseum.party.common.log.MethodLog;
import cn.chnmuseum.party.common.log.OperModule;
import cn.chnmuseum.party.common.log.OperType;
import cn.chnmuseum.party.common.validator.groups.Add;
import cn.chnmuseum.party.common.validator.groups.Update;
import cn.chnmuseum.party.common.vo.GenericPageParam;
import cn.chnmuseum.party.model.*;
import cn.chnmuseum.party.service.*;
import cn.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
13
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
14
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
liqin's avatar
liqin committed
16
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
liqin's avatar
liqin committed
17 18 19 20 21 22 23
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 29
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
liqin's avatar
liqin committed
30
import java.util.Collections;
liqin's avatar
liqin committed
31 32
import java.util.List;
import java.util.Map;
liqin's avatar
liqin committed
33
import java.util.Set;
liqin's avatar
liqin committed
34
import java.util.stream.Collectors;
liqin's avatar
liqin committed
35 36

/**
liqin's avatar
liqin committed
37
 * <pre>
liqin's avatar
liqin committed
38
 * 展板分类 前端控制器
liqin's avatar
liqin committed
39
 * </pre>
liqin's avatar
liqin committed
40 41
 *
 * @author Danny Lee
liqin's avatar
liqin committed
42
 * @since 2021-03-19
liqin's avatar
liqin committed
43
 */
liqin's avatar
liqin committed
44
@Slf4j
liqin's avatar
liqin committed
45
@RestController
liqin's avatar
liqin committed
46 47
@RequestMapping("/exhibitionBoardCat")
@Api(tags = {"展板分类操作接口"})
liqin's avatar
liqin committed
48 49
public class ExhibitionBoardCatController extends BaseController {

liqin's avatar
liqin committed
50 51
    @Resource
    private ExhibitionBoardService exhibitionBoardService;
liqin's avatar
liqin committed
52 53
    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;
liqin's avatar
liqin committed
54 55
    @Resource
    private CopyrightOwnerService copyrightOwnerService;
liqin's avatar
liqin committed
56 57
    @Resource
    private CopyrightOwnerBoardCatService copyrightOwnerBoardCatService;
liqin's avatar
liqin committed
58 59
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;
liqin's avatar
liqin committed
60
    @Resource
liqin's avatar
liqin committed
61 62
    private LearningContentService learningContentService;
    @Resource
liqin's avatar
liqin committed
63
    private LearningContentBoardService learningContentBoardService;
liqin's avatar
liqin committed
64 65 66
    @Resource
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;
    @Resource
liqin's avatar
liqin committed
67
    private AssetService assetService;
liqin's avatar
liqin committed
68 69

    @PostMapping("/save")
wzp's avatar
wzp committed
70
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:save")
liqin's avatar
liqin committed
71
    @ApiOperation(value = "添加展板分类", notes = "添加展板分类")
wzp's avatar
wzp committed
72
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.ADD)
liqin's avatar
liqin committed
73 74 75 76 77 78 79 80 81 82 83 84 85
    public Map<String, Object> saveExhibitionBoardCat(@Validated(value = {Add.class}) ExhibitionBoardCat exhibitionBoardCat) {
        // 保存业务节点信息
        boolean result = exhibitionBoardCatService.save(exhibitionBoardCat);
        // 返回操作结果
        if (result) {
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
86
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:update")
liqin's avatar
liqin committed
87
    @ApiOperation(value = "修改展板分类信息", notes = "修改展板分类信息")
wzp's avatar
wzp committed
88
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.UPDATE)
liqin's avatar
liqin committed
89 90 91 92 93 94 95 96 97
    public Map<String, Object> updateExhibitionBoardCat(@Validated(value = {Update.class}) ExhibitionBoardCat exhibitionBoardCat) {
        boolean flag = exhibitionBoardCatService.updateById(exhibitionBoardCat);
        if (flag) {
            return getSuccessResult();
        }
        return getFailResult();
    }

    @PutMapping("/updateAuditStatus/{id}")
wzp's avatar
wzp committed
98
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:update:audit:status")
liqin's avatar
liqin committed
99 100 101 102 103
    @ApiOperation(value = "更新展板分类审核状态", notes = "更新展板分类审核状态")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
            @ApiImplicitParam(name = "status", value = "状态", paramType = "query", dataType = "String")
    })
wzp's avatar
wzp committed
104
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
105
    public Map<String, Object> updateStatus(@NotNull(message = "展板分类ID不能为空") @PathVariable("id") String id, @RequestParam("auditStatus") AuditStatusEnum status) {
liqin's avatar
liqin committed
106 107 108 109 110 111 112 113 114 115
        UpdateWrapper<ExhibitionBoardCat> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", id);
        updateWrapper.eq("audit_status", status.name());
        boolean flag = exhibitionBoardCatService.update(updateWrapper);
        if (flag) {
            return getSuccessResult();
        }
        return getFailResult();
    }

liqin's avatar
liqin committed
116 117 118
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "copyrightOwnerId", value = "展板内容版权方ID", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
119
    @PostMapping("/getList")
wzp's avatar
wzp committed
120
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:list")
liqin's avatar
liqin committed
121
    @ApiOperation(value = "获取展板分类全部列表(无分页)", notes = "获取展板分类全部列表(无分页)")
wzp's avatar
wzp committed
122
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
123
    public Map<String, Object> getExhibitionBoardCatList(@RequestParam(value = "copyrightOwnerId", required = false) List<String> copyrightOwnerIdList) {
liqin's avatar
liqin committed
124
        final LambdaQueryWrapper<ExhibitionBoardCat> exhibitionBoardCatLambdaQueryWrapper = Wrappers.<ExhibitionBoardCat>lambdaQuery().orderByDesc(ExhibitionBoardCat::getCreateTime);
liqin's avatar
liqin committed
125 126
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
            final LambdaQueryWrapper<CopyrightOwnerBoardCat> queryWrapper = Wrappers.<CopyrightOwnerBoardCat>lambdaQuery().in(CopyrightOwnerBoardCat::getCopyrightOwnerId, copyrightOwnerIdList);
liqin's avatar
liqin committed
127
            final List<CopyrightOwnerBoardCat> copyrightOwnerBoardCatList = this.copyrightOwnerBoardCatService.list(queryWrapper);
liqin's avatar
liqin committed
128 129 130
            if (!copyrightOwnerBoardCatList.isEmpty()) {
                final List<String> collect = copyrightOwnerBoardCatList.stream().map(CopyrightOwnerBoardCat::getBoardCatId).distinct().collect(Collectors.toList());
                exhibitionBoardCatLambdaQueryWrapper.in(ExhibitionBoardCat::getId, collect);
liqin's avatar
liqin committed
131 132
            } else {
                return getResult(Collections.emptyList());
liqin's avatar
liqin committed
133
            }
liqin's avatar
liqin committed
134
        }
liqin's avatar
liqin committed
135 136
        List<ExhibitionBoardCat> exhibitionBoardCatList = exhibitionBoardCatService.list(exhibitionBoardCatLambdaQueryWrapper);
        return getResult(exhibitionBoardCatList);
liqin's avatar
liqin committed
137 138 139 140 141 142 143 144 145 146 147
    }

    @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 = "copyrightOwner", 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
148
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:page")
liqin's avatar
liqin committed
149
    @ApiOperation(value = "获取展板分类分页列表", notes = "获取展板分类分页列表")
wzp's avatar
wzp committed
150
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
    public Map<String, Object> getExhibitionBoardCatPageList(GenericPageParam genericPageParam) {
        LambdaQueryWrapper<ExhibitionBoardCat> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(ExhibitionBoardCat::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(ExhibitionBoardCat::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(ExhibitionBoardCat::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(ExhibitionBoardCat::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                ExhibitionBoardCat::getId,
                ExhibitionBoardCat::getName,
liqin's avatar
liqin committed
168
                ExhibitionBoardCat::getRemarks,
liqin's avatar
liqin committed
169 170 171 172
                ExhibitionBoardCat::getCreateTime,
                ExhibitionBoardCat::getUpdateTime);
        Page<ExhibitionBoardCat> page = this.exhibitionBoardCatService.page(getPage(), queryWrapper);
        for (ExhibitionBoardCat exhibitionBoardCat : page.getRecords()) {
liqin's avatar
liqin committed
173
            LambdaQueryWrapper<ExhibitionBoard> lambdaQueryWrapper = Wrappers.<ExhibitionBoard>lambdaQuery().eq(ExhibitionBoard::getExhibitionBoardCatId, exhibitionBoardCat.getId());
liqin's avatar
liqin committed
174
            List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.list(lambdaQueryWrapper);
liqin's avatar
liqin committed
175 176 177 178 179 180
            if (!exhibitionBoardList.isEmpty()) {
                Set<String> boardCopyrightOwnerIdList = exhibitionBoardList.stream().map(ExhibitionBoard::getBoardCopyrightOwnerId).collect(Collectors.toSet());
                List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(boardCopyrightOwnerIdList);
                String copyrightOwnerNames = copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.joining("、"));
                exhibitionBoardCat.setCopyrightOwnerNames(copyrightOwnerNames);
            }
liqin's avatar
liqin committed
181 182 183 184 185 186 187 188 189
        }
        return getResult(page);
    }

    @ApiOperation(value = "获取展板分类详情", notes = "获取展板分类详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
    })
    @GetMapping("/get/{id}")
wzp's avatar
wzp committed
190
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:get:id")
wzp's avatar
wzp committed
191
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.SELECT)
liqin's avatar
liqin committed
192 193 194 195 196
    public Map<String, Object> getById(@PathVariable("id") String id) {
        ExhibitionBoardCat exhibitionBoardCat = exhibitionBoardCatService.getById(id);
        return getResult(exhibitionBoardCat);
    }

liqin's avatar
liqin committed
197 198 199 200
    @DeleteMapping("/delete/{id}")
    @RequiresAuthentication  //@RequiresPermissions("exhibition:board:cat:delete")
    @ApiOperation(value = "根据ID删除展板分类", notes = "根据ID删除展板分类")
    @ApiImplicitParams(value = {
liqin's avatar
liqin committed
201
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String", required = true)
liqin's avatar
liqin committed
202 203 204 205 206
    })
    @MethodLog(operModule = OperModule.DISPLAYCLASSIFY, operType = OperType.DELETE)
    public Map<String, Object> deleteExhibitionBoardCat(@PathVariable("id") String id) {
        this.exhibitionBoardCatService.removeById(id);

liqin's avatar
liqin committed
207 208 209 210 211
        LambdaUpdateWrapper<CopyrightOwnerBoardCat> copyrightOwnerBoardCatLambdaUpdateWrapper = Wrappers.<CopyrightOwnerBoardCat>lambdaUpdate().eq(CopyrightOwnerBoardCat::getBoardCatId, id);
        this.copyrightOwnerBoardCatService.remove(copyrightOwnerBoardCatLambdaUpdateWrapper);

        final LambdaQueryWrapper<ExhibitionBoard> exhibitionBoardLambdaQueryWrapper = Wrappers.<ExhibitionBoard>lambdaQuery().eq(ExhibitionBoard::getExhibitionBoardCatId, id).select(ExhibitionBoard::getId);
        final List<String> exhibitionBoardIdList = this.exhibitionBoardService.listObjs(exhibitionBoardLambdaQueryWrapper, Object::toString);
liqin's avatar
liqin committed
212
        if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
liqin's avatar
liqin committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
            this.exhibitionBoardService.removeByIds(exhibitionBoardIdList);
            this.assetService.remove(Wrappers.<Asset>lambdaUpdate().in(Asset::getRefItemId, exhibitionBoardIdList));

            final LambdaQueryWrapper<LearningContentBoard> learningContentBoardLambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery().in(LearningContentBoard::getExhibitionBoardCatId, exhibitionBoardIdList);
            final List<LearningContentBoard> learningContentBoardList = this.learningContentBoardService.list(learningContentBoardLambdaQueryWrapper);
            if (learningContentBoardList != null && !learningContentBoardList.isEmpty()) {
                final Map<String, List<String>> collect = learningContentBoardList.stream().collect(Collectors.groupingBy(LearningContentBoard::getLearningContentId, Collectors.mapping(LearningContentBoard::getExhibitionBoardId, Collectors.toList())));
                collect.forEach((k, v) -> {
                    if (v.size() == 1) {
                        this.learningContentService.removeById(k);
                        this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, k));
                        this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, k));
                        this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, k));
                    }
                });
                LambdaUpdateWrapper<LearningContentBoard> learningContentBoardLambdaUpdateWrapper = Wrappers.<LearningContentBoard>lambdaUpdate().in(LearningContentBoard::getExhibitionBoardId, exhibitionBoardIdList);
                this.learningContentBoardService.remove(learningContentBoardLambdaUpdateWrapper);
            }
liqin's avatar
liqin committed
231
        }
liqin's avatar
liqin committed
232

liqin's avatar
liqin committed
233 234 235
        final LambdaQueryWrapper<LearningContentBoardCat> learningContentBoardCatLambdaQueryWrapper = Wrappers.<LearningContentBoardCat>lambdaQuery().eq(LearningContentBoardCat::getExhibitionBoardCatId, id);
        final List<LearningContentBoardCat> learningContentBoardCatList = this.learningContentBoardCatService.list(learningContentBoardCatLambdaQueryWrapper);
        if (learningContentBoardCatList != null && !learningContentBoardCatList.isEmpty()) {
liqin's avatar
liqin committed
236
            final Map<String, List<String>> collect = learningContentBoardCatList.stream().collect(Collectors.groupingBy(LearningContentBoardCat::getLearningContentId, Collectors.mapping(LearningContentBoardCat::getExhibitionBoardCatId, Collectors.toList())));
liqin's avatar
liqin committed
237
            collect.forEach((k, v) -> {
liqin's avatar
liqin committed
238 239
                if (v.size() == 1) {
                    this.learningContentService.removeById(k);
liqin's avatar
liqin committed
240 241 242
                    this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, k));
                    this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, k));
                    this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, k));
liqin's avatar
liqin committed
243 244 245
                }
            });

liqin's avatar
liqin committed
246 247
            LambdaUpdateWrapper<LearningContentBoardCat> learningContentBoardCatLambdaUpdateWrapper = Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getExhibitionBoardCatId, id);
            this.learningContentBoardCatService.remove(learningContentBoardCatLambdaUpdateWrapper);
liqin's avatar
liqin committed
248
        }
liqin's avatar
liqin committed
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

//        final LambdaUpdateWrapper<VideoContent> updateWrapper = Wrappers.<VideoContent>lambdaUpdate().eq(VideoContent::getVideoContentCopyrightOwnerId, id);
//        updateWrapper.set(VideoContent::getDeleted, true);
//        this.videoContentService.update(updateWrapper);
//
//        final LambdaUpdateWrapper<ExhibitionBoard> updateWrapper1 = Wrappers.<ExhibitionBoard>lambdaUpdate().eq(ExhibitionBoard::getBoardCopyrightOwnerId, id);
//        updateWrapper1.set(ExhibitionBoard::getDeleted, true);
//        this.exhibitionBoardService.update(updateWrapper1);
//
//        LambdaUpdateWrapper<CopyrightOwnerBoardCat> deleteWrapper = Wrappers.<CopyrightOwnerBoardCat>lambdaUpdate().eq(CopyrightOwnerBoardCat::getCopyrightOwnerId, id);
//        this.copyrightOwnerBoardCatService.remove(deleteWrapper);
//
//        LambdaUpdateWrapper<CopyrightOwnerVideoContentCat> deleteWrapper1 = Wrappers.<CopyrightOwnerVideoContentCat>lambdaUpdate().eq(CopyrightOwnerVideoContentCat::getCopyrightOwnerId, id);
//        this.copyrightOwnerVideoContentCatService.remove(deleteWrapper1);

        return getSuccessResult();
    }

liqin's avatar
liqin committed
267 268
}