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

liqin's avatar
liqin committed
3
import cn.wisenergy.chnmuseum.party.common.enums.AuditOperationEnum;
liqin's avatar
liqin committed
4
import cn.wisenergy.chnmuseum.party.common.enums.AuditStatusEnum;
liqin's avatar
liqin committed
5
import cn.wisenergy.chnmuseum.party.common.enums.AuditTypeEnum;
liqin's avatar
liqin committed
6 7 8
import cn.wisenergy.chnmuseum.party.common.validator.groups.Add;
import cn.wisenergy.chnmuseum.party.common.validator.groups.Update;
import cn.wisenergy.chnmuseum.party.common.vo.GenericPageParam;
liqin's avatar
liqin committed
9 10
import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.*;
liqin's avatar
liqin committed
11
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
12
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
13
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
liqin's avatar
liqin committed
14
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
liqin's avatar
liqin committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
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;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
liqin's avatar
liqin committed
30 31

/**
liqin's avatar
liqin committed
32
 * <pre>
liqin's avatar
liqin committed
33
 * 学习内容 前端控制器
liqin's avatar
liqin committed
34
 * </pre>
liqin's avatar
liqin committed
35 36
 *
 * @author Danny Lee
liqin's avatar
liqin committed
37
 * @since 2021-03-26
liqin's avatar
liqin committed
38
 */
liqin's avatar
liqin committed
39
@Slf4j
liqin's avatar
liqin committed
40
@RestController
liqin's avatar
liqin committed
41 42
@RequestMapping("/learningContent")
@Api(tags = {"学习内容操作接口"})
liqin's avatar
liqin committed
43 44
public class LearningContentController extends BaseController {

liqin's avatar
liqin committed
45 46
    @Resource
    private LearningContentService learningContentService;
liqin's avatar
liqin committed
47 48 49 50 51 52
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;
    @Resource
    private LearningContentBoardService learningContentBoardService;
    @Resource
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;
liqin's avatar
liqin committed
53 54
    @Resource
    private LearningProjectService learningProjectService;
liqin's avatar
liqin committed
55 56
    @Resource
    private AuditService auditService;
liqin's avatar
liqin committed
57 58

    @PostMapping("/save")
liqin's avatar
liqin committed
59 60 61
    @RequiresPermissions("learning:content:save")
    @ApiOperation(value = "添加学习内容", notes = "添加学习内容")
    public Map<String, Object> saveLearningContent(@Validated(value = {Add.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
62 63
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
        learningContent.setIsPublished(false);
liqin's avatar
liqin committed
64 65
        // 保存业务节点信息
        boolean result = learningContentService.save(learningContent);
liqin's avatar
liqin committed
66
        final String learningContentId = learningContent.getId();
liqin's avatar
liqin committed
67

liqin's avatar
liqin committed
68 69 70 71 72
        final List<String> exhibitionBoardCatIdList = learningContent.getExhibitionBoardCatIdList();
        for (String exhibitionBoardCatId : exhibitionBoardCatIdList) {
            LearningContentBoardCat learningContentBoardCat = LearningContentBoardCat.builder().exhibitionBoardCatId(exhibitionBoardCatId).learningContentId(learningContentId).build();
            this.learningContentBoardCatService.save(learningContentBoardCat);
        }
liqin's avatar
liqin committed
73

liqin's avatar
liqin committed
74 75 76 77 78
        final List<String> copyrightOwnerIdList = learningContent.getCopyrightOwnerIdList();
        for (String copyrightOwnerId : copyrightOwnerIdList) {
            LearningContentCopyrightOwner contentCopyrightOwner = LearningContentCopyrightOwner.builder().copyrightOwnerId(copyrightOwnerId).learningContentId(learningContentId).build();
            this.learningContentCopyrightOwnerService.save(contentCopyrightOwner);
        }
liqin's avatar
liqin committed
79

liqin's avatar
liqin committed
80 81 82
        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        for (String exhibitionBoardId : exhibitionBoardIdList) {
            LearningContentBoard learningContentBoard = LearningContentBoard.builder().exhibitionBoardId(exhibitionBoardId).learningContentId(learningContentId).build();
liqin's avatar
liqin committed
83 84 85 86 87 88 89 90
            QueryWrapper<LearningContentBoard> queryWrapper = new QueryWrapper<>();
            queryWrapper.select("max(sortorder) as sortorder");
            LearningContentBoard one = this.learningContentBoardService.getOne(queryWrapper);
            if (one != null) {
                learningContentBoard.setSortorder(one.getSortorder() + 1);
            } else {
                learningContentBoard.setSortorder(1);
            }
liqin's avatar
liqin committed
91 92
            this.learningContentBoardService.save(learningContentBoard);
        }
liqin's avatar
liqin committed
93

liqin's avatar
liqin committed
94 95
        // 返回操作结果
        if (result) {
liqin's avatar
liqin committed
96 97 98 99 100 101 102
            final Audit audit = Audit.builder().content("")
                    .isDeleted(false)
                    .operation(AuditOperationEnum.ADD.name())
                    .refItemId(learningContent.getId())
                    .status(AuditStatusEnum.TBC.name())
                    .type(AuditTypeEnum.LEARNING_CONTENT.name()).build();
            this.auditService.save(audit);
liqin's avatar
liqin committed
103 104 105 106 107 108 109 110
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
liqin's avatar
liqin committed
111 112
    @RequiresPermissions("learning:content:update")
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
liqin's avatar
liqin committed
113
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
        learningContent.setIsPublished(false);
        // 保存业务节点信息
        final String learningContentId = learningContent.getId();

        final List<String> exhibitionBoardCatIdList = learningContent.getExhibitionBoardCatIdList();
        if (exhibitionBoardCatIdList != null && !exhibitionBoardCatIdList.isEmpty()) {
            LambdaUpdateWrapper<LearningContentBoardCat> lambdaUpdateWrapper = Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, learningContentId);
            this.learningContentBoardCatService.remove(lambdaUpdateWrapper);

            for (String exhibitionBoardCatId : exhibitionBoardCatIdList) {
                LearningContentBoardCat learningContentBoardCat = LearningContentBoardCat.builder().exhibitionBoardCatId(exhibitionBoardCatId).learningContentId(learningContentId).build();
                this.learningContentBoardCatService.save(learningContentBoardCat);
            }
        }

        final List<String> copyrightOwnerIdList = learningContent.getCopyrightOwnerIdList();
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
            LambdaUpdateWrapper<LearningContentCopyrightOwner> lambdaUpdateWrapper = Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, learningContentId);
            this.learningContentCopyrightOwnerService.remove(lambdaUpdateWrapper);

            for (String copyrightOwnerId : copyrightOwnerIdList) {
                LearningContentCopyrightOwner contentCopyrightOwner = LearningContentCopyrightOwner.builder().copyrightOwnerId(copyrightOwnerId).learningContentId(learningContentId).build();
                this.learningContentCopyrightOwnerService.save(contentCopyrightOwner);
            }
        }

        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
            LambdaUpdateWrapper<LearningContentBoard> lambdaUpdateWrapper = Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, learningContentId);
            this.learningContentBoardService.remove(lambdaUpdateWrapper);

            for (String exhibitionBoardId : exhibitionBoardIdList) {
                LearningContentBoard learningContentBoard = LearningContentBoard.builder().exhibitionBoardId(exhibitionBoardId).learningContentId(learningContentId).build();
                this.learningContentBoardService.save(learningContentBoard);
            }
        }

liqin's avatar
liqin committed
152 153
        boolean flag = learningContentService.updateById(learningContent);
        if (flag) {
liqin's avatar
liqin committed
154 155 156 157 158 159 160 161 162
            final Audit audit = Audit.builder().content("")
                    .isDeleted(false)
                    .operation(AuditOperationEnum.EDIT.name())
                    .refItemId(learningContent.getId())
                    .status(AuditStatusEnum.TBC.name())
                    .type(AuditTypeEnum.LEARNING_CONTENT.name())
                    .build();
            this.auditService.save(audit);

liqin's avatar
liqin committed
163 164 165 166 167 168
            return getSuccessResult();
        }
        return getFailResult();
    }

    @DeleteMapping("/delete/{id}")
liqin's avatar
liqin committed
169
    @RequiresPermissions("learning:content:delete")
liqin's avatar
liqin committed
170
    @ApiOperation(value = "根据ID下架学习内容", notes = "根据ID下架学习内容")
liqin's avatar
liqin committed
171 172 173
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String")
    })
liqin's avatar
liqin committed
174
    public Map<String, Object> deleteLearningContent(@PathVariable("id") String id) {
liqin's avatar
liqin committed
175 176 177 178 179 180 181 182
        final Audit audit = Audit.builder().content("")
                .isDeleted(false)
                .operation(AuditOperationEnum.REMOVE.name())
                .refItemId(id)
                .status(AuditStatusEnum.TBC.name())
                .type(AuditTypeEnum.LEARNING_CONTENT.name())
                .build();
        final boolean result = this.auditService.save(audit);
liqin's avatar
liqin committed
183 184 185 186 187 188 189
        if (result) {
            return getSuccessResult();
        }
        return getFailResult();
    }

    @GetMapping("/getList")
liqin's avatar
liqin committed
190 191 192 193 194
    @RequiresPermissions("learning:content:list")
    @ApiOperation(value = "获取学习内容全部列表(无分页)", notes = "获取学习内容全部列表(无分页)")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String")
    })
liqin's avatar
liqin committed
195 196 197 198 199
    public Map<String, Object> getLearningContentList(@RequestParam(value = "auditStatus", defaultValue = "APPROVED_FINAL", required = false) AuditStatusEnum auditStatus) {
        List<LearningContent> learningContentList = learningContentService.list(Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getAuditStatus, auditStatus.name()));
        return getResult(learningContentList);
    }

liqin's avatar
liqin committed
200 201 202 203 204 205 206
    @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")
    })
liqin's avatar
liqin committed
207
    @PostMapping("/getPageList")
liqin's avatar
liqin committed
208 209
    @RequiresPermissions("learning:content:page")
    @ApiOperation(value = "获取学习内容分页列表", notes = "获取学习内容分页列表")
liqin's avatar
liqin committed
210
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam) {
liqin's avatar
liqin committed
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(LearningContent::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(LearningContent::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(LearningContent::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(LearningContent::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                LearningContent::getId,
                LearningContent::getName,
                LearningContent::getAuditStatus,
                LearningContent::getCreateTime,
                LearningContent::getUpdateTime);
        Page<LearningContent> page = this.learningContentService.page(getPage(), queryWrapper);
        for (LearningContent learningContent : page.getRecords()) {
liqin's avatar
liqin committed
232 233 234
            LambdaQueryWrapper<LearningContentBoard> lambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getLearningContentId, learningContent.getId());
            int exhibitionBoardCount = this.learningContentBoardService.count(lambdaQueryWrapper);
            learningContent.setExhibitionBoardCount(exhibitionBoardCount);
liqin's avatar
liqin committed
235 236
        }
        return getResult(page);
liqin's avatar
liqin committed
237 238 239 240 241 242 243
    }

    @ApiOperation(value = "获取学习内容详情", notes = "获取学习内容详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
    })
    @GetMapping("/get/{id}")
liqin's avatar
liqin committed
244 245
    @RequiresPermissions("learning:content:get:id")
    public Map<String, Object> getById(@PathVariable("id") String id) {
liqin's avatar
liqin committed
246
        LearningContent learningContent = learningContentService.getById(id);
liqin's avatar
liqin committed
247

liqin's avatar
liqin committed
248 249 250 251
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }
liqin's avatar
liqin committed
252

liqin's avatar
liqin committed
253
        return getResult(learningContent);
liqin's avatar
liqin committed
254 255
    }

liqin's avatar
liqin committed
256 257
}