LearningContentController.java 33.3 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 13 14 15
import cn.chnmuseum.party.common.enums.AuditOperationEnum;
import cn.chnmuseum.party.common.enums.AuditStatusEnum;
import cn.chnmuseum.party.common.enums.AuditTypeEnum;
import cn.chnmuseum.party.common.enums.FileCatEnum;
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
16
import com.alibaba.fastjson.JSONObject;
liqin's avatar
liqin committed
17
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
18
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
liqin's avatar
liqin committed
19 20 21 22 23 24 25 26
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
27
import org.apache.shiro.authz.annotation.RequiresAuthentication;
liqin's avatar
liqin committed
28 29 30 31 32 33
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
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-26
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("/learningContent")
@Api(tags = {"学习内容操作接口"})
liqin's avatar
liqin committed
48 49
public class LearningContentController extends BaseController {

liqin's avatar
liqin committed
50 51 52
    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;
    @Resource
liqin's avatar
liqin committed
53
    private VideoContentService videoContentService;
liqin's avatar
liqin committed
54 55
    @Resource
    private CopyrightOwnerService copyrightOwnerService;
liqin's avatar
liqin committed
56 57
    @Resource
    private LearningContentService learningContentService;
liqin's avatar
liqin committed
58 59 60 61 62
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;
    @Resource
    private LearningContentBoardService learningContentBoardService;
    @Resource
liqin's avatar
liqin committed
63 64
    private ExhibitionBoardService exhibitionBoardService;
    @Resource
liqin's avatar
liqin committed
65
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;
liqin's avatar
liqin committed
66 67
    @Resource
    private LearningProjectService learningProjectService;
liqin's avatar
liqin committed
68 69
    @Resource
    private AuditService auditService;
liqin's avatar
liqin committed
70 71
    @Resource
    private AssetService assetService;
liqin's avatar
liqin committed
72 73

    @PostMapping("/save")
wzp's avatar
wzp committed
74
    @RequiresAuthentication  //@RequiresPermissions("learning:content:save")
liqin's avatar
liqin committed
75
    @ApiOperation(value = "添加学习内容", notes = "添加学习内容")
wzp's avatar
wzp committed
76
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.ADD)
liqin's avatar
liqin committed
77
    public Map<String, Object> saveLearningContent(@Validated(value = {Add.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
78 79 80 81 82 83
        final LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getName, learningContent.getName().trim());
        final int count = this.learningContentService.count(lambdaQueryWrapper);
        if (count > 0) {
            return getFailResult("400", "名称已存在,请修改名称");
        }

liqin's avatar
liqin committed
84
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
85
        if (tUser != null) {
liqin's avatar
liqin committed
86
            learningContent.setOrganCode(tUser.getOrgCode());
liqin's avatar
liqin committed
87
        }
liqin's avatar
liqin committed
88
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
liqin's avatar
liqin committed
89
        learningContent.setPublished(false);
liqin's avatar
liqin committed
90 91 92
        QueryWrapper<LearningContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("max(sortorder) as sortorder");
        LearningContent content = this.learningContentService.getOne(queryWrapper);
liqin's avatar
liqin committed
93
        if (content != null && content.getSortorder() != null) {
liqin's avatar
liqin committed
94 95 96 97
            learningContent.setSortorder(content.getSortorder() + 1);
        } else {
            learningContent.setSortorder(1);
        }
liqin's avatar
liqin committed
98 99
        // 保存业务节点信息
        boolean result = learningContentService.save(learningContent);
liqin's avatar
liqin committed
100
        final String learningContentId = learningContent.getId();
liqin's avatar
liqin committed
101

liqin's avatar
liqin committed
102 103 104 105 106
        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
107

liqin's avatar
liqin committed
108 109 110 111 112
        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
113

liqin's avatar
liqin committed
114 115
        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        for (String exhibitionBoardId : exhibitionBoardIdList) {
liqin's avatar
liqin committed
116 117 118 119 120
            LearningContentBoard learningContentBoard = LearningContentBoard.builder()
                    .learningContentId(learningContentId)
                    .exhibitionBoardCatId(this.exhibitionBoardService.getById(exhibitionBoardId).getExhibitionBoardCatId())
                    .exhibitionBoardId(exhibitionBoardId)
                    .build();
liqin's avatar
liqin committed
121
            QueryWrapper<LearningContentBoard> learningContentBoardQueryWrapper = new QueryWrapper<>();
liqin's avatar
liqin committed
122
            learningContentBoardQueryWrapper.select("max(sortorder) as sortorder");
liqin's avatar
liqin committed
123
            LearningContentBoard one = this.learningContentBoardService.getOne(learningContentBoardQueryWrapper);
liqin's avatar
liqin committed
124
            if (one != null && one.getSortorder() != null) {
liqin's avatar
liqin committed
125
                learningContent.setSortorder(one.getSortorder() + 1);
liqin's avatar
liqin committed
126
            } else {
liqin's avatar
liqin committed
127
                learningContent.setSortorder(1);
liqin's avatar
liqin committed
128
            }
liqin's avatar
liqin committed
129 130
            this.learningContentBoardService.save(learningContentBoard);
        }
liqin's avatar
liqin committed
131

liqin's avatar
liqin committed
132 133
        // 返回操作结果
        if (result) {
liqin's avatar
liqin committed
134 135
            final Audit audit = Audit.builder()
                    .content(learningContent.getName())
liqin's avatar
liqin committed
136
                    .name(learningContent.getName())
liqin's avatar
liqin committed
137
                    .refItemId(learningContent.getId())
liqin's avatar
liqin committed
138
                    .type(AuditTypeEnum.LEARNING_CONTENT.name())
wzp's avatar
wzp committed
139
                    .userId(tUser.getId())
liqin's avatar
liqin committed
140
                    .operation(AuditOperationEnum.ADD.name())
liqin's avatar
liqin committed
141
                    .status(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
142 143
                    .level(AuditStatusEnum.TBC.name())
                    .build();
liqin's avatar
liqin committed
144
            this.auditService.save(audit);
liqin's avatar
liqin committed
145 146 147 148 149 150 151 152
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
153
    @RequiresAuthentication  //@RequiresPermissions("learning:content:update")
liqin's avatar
liqin committed
154
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
wzp's avatar
wzp committed
155
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.UPDATE)
liqin's avatar
liqin committed
156
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
157 158 159 160 161 162
        final LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getName, learningContent.getName().trim());
        lambdaQueryWrapper.ne(LearningContent::getId, learningContent.getId());
        final int count = this.learningContentService.count(lambdaQueryWrapper);
        if (count > 0) {
            return getFailResult("400", "名称已存在,请修改名称");
        }
liqin's avatar
liqin committed
163

liqin's avatar
liqin committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        final LearningContent one = this.learningContentService.getById(learningContent.getId());
        one.setAuditStatus(AuditStatusEnum.TBC.name());
        this.learningContentService.updateById(one);

        final Audit audit = Audit.builder()
                .content(learningContent.getName())
                .name(learningContent.getName())
                .userId(getcurUser().getId())
                .refItemId(learningContent.getId())
                .type(AuditTypeEnum.LEARNING_CONTENT.name())
                .operation(AuditOperationEnum.EDIT.name())
                .status(AuditStatusEnum.TBC.name())
                .level(AuditStatusEnum.TBC.name())
                .modelData(JSONObject.toJSONString(learningContent))
                .build();
        this.auditService.save(audit);
        return getSuccessResult();
liqin's avatar
liqin committed
181 182 183
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
184
    @RequiresAuthentication  //@RequiresPermissions("learning:content:list")
liqin's avatar
liqin committed
185 186
    @ApiOperation(value = "获取学习内容全部列表(无分页)", notes = "获取学习内容全部列表(无分页)")
    @ApiImplicitParams(value = {
liqin's avatar
liqin committed
187 188
            @ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String")
liqin's avatar
liqin committed
189
    })
wzp's avatar
wzp committed
190
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
191 192
    public Map<String, Object> getLearningContentList(@RequestParam(value = "auditStatus", defaultValue = "APPROVED_FINAL", required = false) AuditStatusEnum auditStatus,
                                                      @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
liqin's avatar
liqin committed
193 194
        final LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getAuditStatus, auditStatus.name());
        lambdaQueryWrapper.eq(LearningContent::getPublished, true);
liqin's avatar
liqin committed
195 196 197
        if (StringUtils.isNotBlank(learningProjectId)) {
            lambdaQueryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
        }
wzp's avatar
wzp committed
198
        List<LearningContent> learningContentList = learningContentService.list(lambdaQueryWrapper);
liqin's avatar
liqin committed
199 200 201
        return getResult(learningContentList);
    }

liqin's avatar
liqin committed
202 203 204
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
205
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String"),
liqin's avatar
liqin committed
206 207 208 209
            @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
210
    @PostMapping("/getPageList")
wzp's avatar
wzp committed
211
    @RequiresAuthentication  //@RequiresPermissions("learning:content:page")
liqin's avatar
liqin committed
212
    @ApiOperation(value = "获取学习内容分页列表", notes = "获取学习内容分页列表")
wzp's avatar
wzp committed
213
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
214
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam, @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
liqin's avatar
liqin committed
215
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
liqin's avatar
liqin committed
216 217 218 219
        // 根据创建时间区间检索
        if (genericPageParam.getIsPublished() != null) {
            queryWrapper.eq(LearningContent::getPublished, genericPageParam.getIsPublished());
        }
liqin's avatar
liqin committed
220
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
221
        if (StringUtils.isNotBlank(learningProjectId)) {
liqin's avatar
liqin committed
222
            queryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
liqin's avatar
liqin committed
223 224
        }
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
225 226 227 228 229 230 231 232 233
        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));
        }
        // 设置排序规则
liqin's avatar
liqin committed
234
        queryWrapper.orderByDesc(LearningContent::getSortorder);
liqin's avatar
liqin committed
235 236 237 238
        // 设置查询内容
        queryWrapper.select(
                LearningContent::getId,
                LearningContent::getName,
liqin's avatar
liqin committed
239
                LearningContent::getApplicableScope,
liqin's avatar
liqin committed
240
                LearningContent::getCreatorName,
liqin's avatar
liqin committed
241
                LearningContent::getAuditStatus,
liqin's avatar
liqin committed
242
                LearningContent::getPublished,
liqin's avatar
liqin committed
243 244
                LearningContent::getDeleted,
                LearningContent::getSortorder,
liqin's avatar
liqin committed
245 246 247 248
                LearningContent::getCreateTime,
                LearningContent::getUpdateTime);
        Page<LearningContent> page = this.learningContentService.page(getPage(), queryWrapper);
        for (LearningContent learningContent : page.getRecords()) {
liqin's avatar
liqin committed
249 250 251
            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
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

//            LambdaQueryWrapper<LearningContentBoardCat> boardCatLambdaQueryWrapper = Wrappers.<LearningContentBoardCat>lambdaQuery().eq(LearningContentBoardCat::getLearningContentId, learningContent.getId());
//            boardCatLambdaQueryWrapper.select(LearningContentBoardCat::getExhibitionBoardCatId);
//            List<String> exhibitionBoardCatIdList = this.learningContentBoardCatService.listObjs(boardCatLambdaQueryWrapper, Object::toString);
//            List<ExhibitionBoardCat> exhibitionBoardCatList = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
//            String exhibitionBoardCatNames = exhibitionBoardCatList.stream().map(ExhibitionBoardCat::getName).collect(Collectors.joining("、"));
//            learningContent.setExhibitionBoardCatNames(exhibitionBoardCatNames);
//
//            LambdaQueryWrapper<LearningContentCopyrightOwner> copyrightOwnerLambdaQueryWrapper = Wrappers.<LearningContentCopyrightOwner>lambdaQuery().eq(LearningContentCopyrightOwner::getLearningContentId, learningContent.getId());
//            copyrightOwnerLambdaQueryWrapper.select(LearningContentCopyrightOwner::getCopyrightOwnerId);
//             List<String> copyrightOwnerIdList = this.learningContentCopyrightOwnerService.listObjs(copyrightOwnerLambdaQueryWrapper, Object::toString);
//            List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
//            String copyrightOwnerNames = copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.joining("、"));
//            learningContent.setCopyrightOwnerNames(copyrightOwnerNames);

            learningContent.setExhibitionBoardCount(exhibitionBoardCount);
liqin's avatar
liqin committed
268 269
        }
        return getResult(page);
liqin's avatar
liqin committed
270 271 272 273 274 275 276
    }

    @ApiOperation(value = "获取学习内容详情", notes = "获取学习内容详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path")
    })
    @GetMapping("/get/{id}")
wzp's avatar
wzp committed
277
    @RequiresAuthentication  //@RequiresPermissions("learning:content:get:id")
wzp's avatar
wzp committed
278
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
279
    public Map<String, Object> getById(@PathVariable("id") String id) {
liqin's avatar
liqin committed
280
        LearningContent learningContent = learningContentService.getById(id);
liqin's avatar
liqin committed
281

liqin's avatar
liqin committed
282 283 284 285
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }
liqin's avatar
liqin committed
286

liqin's avatar
liqin committed
287 288 289
        final LambdaQueryWrapper<LearningContentBoardCat> queryWrapper = Wrappers.<LearningContentBoardCat>lambdaQuery().eq(LearningContentBoardCat::getLearningContentId, id);
        queryWrapper.select(LearningContentBoardCat::getExhibitionBoardCatId);
        final List<String> exhibitionBoardCatIdList = this.learningContentBoardCatService.listObjs(queryWrapper, Object::toString);
liqin's avatar
liqin committed
290 291
        if (!exhibitionBoardCatIdList.isEmpty()) {
            final List<ExhibitionBoardCat> exhibitionBoardCats = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
liqin's avatar
liqin committed
292 293 294
            learningContent.setExhibitionBoardCatIdList(exhibitionBoardCats.stream().map(ExhibitionBoardCat::getId).collect(Collectors.toList()));
            learningContent.setExhibitionBoardCatNameList(exhibitionBoardCats.stream().map(ExhibitionBoardCat::getName).collect(Collectors.toList()));
        }
liqin's avatar
liqin committed
295 296 297 298

        final LambdaQueryWrapper<LearningContentCopyrightOwner> queryWrapper1 = Wrappers.<LearningContentCopyrightOwner>lambdaQuery().eq(LearningContentCopyrightOwner::getLearningContentId, id);
        queryWrapper1.select(LearningContentCopyrightOwner::getCopyrightOwnerId);
        final List<String> copyrightOwnerIdList = this.learningContentCopyrightOwnerService.listObjs(queryWrapper1, Object::toString);
liqin's avatar
liqin committed
299 300
        if (!copyrightOwnerIdList.isEmpty()) {
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
301 302 303
            learningContent.setCopyrightOwnerIdList(copyrightOwnerList.stream().map(CopyrightOwner::getId).collect(Collectors.toList()));
            learningContent.setCopyrightOwnerNameList(copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.toList()));
        }
liqin's avatar
liqin committed
304 305 306 307

        final LambdaQueryWrapper<LearningContentBoard> queryWrapper2 = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getLearningContentId, id);
        queryWrapper2.select(LearningContentBoard::getExhibitionBoardId);
        final List<String> exhibitionBoardIdList = this.learningContentBoardService.listObjs(queryWrapper2, Object::toString);
liqin's avatar
liqin committed
308 309
        if (!exhibitionBoardIdList.isEmpty()) {
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
liqin's avatar
liqin committed
310 311 312 313
            if (!exhibitionBoardList.isEmpty()) {
                learningContent.setExhibitionBoardIdList(exhibitionBoardList.stream().map(ExhibitionBoard::getId).collect(Collectors.toList()));
                learningContent.setExhibitionBoardNameList(exhibitionBoardList.stream().map(ExhibitionBoard::getName).collect(Collectors.toList()));
            }
liqin's avatar
liqin committed
314 315 316 317

            for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
                String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
                if (exhibitionBoardCatId != null) {
liqin's avatar
liqin committed
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
                    exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
                }
                String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
                if (boardCopyrightOwnerId != null) {
                    final CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(boardCopyrightOwnerId);
                    if (copyrightOwner != null) {
                        exhibitionBoard.setBoardCopyrightOwnerName(copyrightOwner.getName());
                    }
                }
                if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
                    String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
                    exhibitionBoard.setVideoContentCopyrightOwnerName(name);
                }

                LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
liqin's avatar
liqin committed
333
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
334 335 336 337 338 339
                assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
                final List<Asset> audioList = this.assetService.list(assetQueryWrapper);
                exhibitionBoard.setAudioList(audioList);

                assetQueryWrapper.clear();
                assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
liqin's avatar
liqin committed
340
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
341 342 343 344 345 346 347 348 349 350
                assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
                final List<Asset> datumList = this.assetService.list(assetQueryWrapper);
                exhibitionBoard.setDatumList(datumList);

                String videoContentId = exhibitionBoard.getVideoContentId();
                if (videoContentId != null) {
                    final VideoContent videoContent = this.videoContentService.getOne(Wrappers.<VideoContent>lambdaQuery().eq(VideoContent::getId, videoContentId));
                    if (videoContent != null) {
                        assetQueryWrapper.clear();
                        assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, videoContentId);
liqin's avatar
liqin committed
351
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
                        assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.VIDEO_CONTENT.name());
                        final List<Asset> videoList = this.assetService.list(assetQueryWrapper);
                        exhibitionBoard.setVideoList(videoList);
                        exhibitionBoard.setVideoContentName(videoContent.getName());
                    }
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }

        final LambdaQueryWrapper<Audit> auditQueryWrapper = Wrappers.<Audit>lambdaQuery().eq(Audit::getRefItemId, id);
        final List<Audit> auditList = this.auditService.list(auditQueryWrapper);
        learningContent.setAuditHistoryList(auditList);

        return getResult(learningContent);
    }

    @ApiOperation(value = "获取学习内容详情(审核详情使用)", notes = "获取学习内容详情(审核详情使用)")
    @ApiImplicitParams({
liqin's avatar
liqin committed
371
            @ApiImplicitParam(name = "auditId", value = "审核ID", dataType = "String", paramType = "path")
liqin's avatar
liqin committed
372
    })
liqin's avatar
liqin committed
373
    @GetMapping("/getAudit/{auditId}")
liqin's avatar
liqin committed
374 375 376 377 378 379 380 381 382 383
    @RequiresAuthentication  //@RequiresPermissions("learning:content:get:id")
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
    public Map<String, Object> getAuditInfoById(@PathVariable("auditId") String auditId) {
        final LearningContent learningContent = JSONObject.parseObject(this.auditService.getById(auditId).getModelData(), LearningContent.class);
        String id = learningContent.getId();
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }

liqin's avatar
liqin committed
384 385
        final List<String> copyrightOwnerIdList = learningContent.getCopyrightOwnerIdList();
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
liqin's avatar
liqin committed
386
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
387
            learningContent.setCopyrightOwnerIdList(copyrightOwnerIdList);
liqin's avatar
liqin committed
388 389 390
            learningContent.setCopyrightOwnerNameList(copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.toList()));
        }

liqin's avatar
liqin committed
391 392 393 394 395 396 397 398 399
        final List<String> exhibitionBoardCatIdList = learningContent.getExhibitionBoardCatIdList();
        if (exhibitionBoardCatIdList != null && !exhibitionBoardCatIdList.isEmpty()) {
            final List<ExhibitionBoardCat> exhibitionBoardCats = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
            learningContent.setExhibitionBoardCatIdList(exhibitionBoardCatIdList);
            learningContent.setExhibitionBoardCatNameList(exhibitionBoardCats.stream().map(ExhibitionBoardCat::getName).collect(Collectors.toList()));
        }

        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        if (exhibitionBoardIdList!= null && !exhibitionBoardIdList.isEmpty()) {
liqin's avatar
liqin committed
400 401
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
            if (!exhibitionBoardList.isEmpty()) {
liqin's avatar
liqin committed
402
                learningContent.setExhibitionBoardIdList(exhibitionBoardIdList);
liqin's avatar
liqin committed
403 404 405 406 407 408
                learningContent.setExhibitionBoardNameList(exhibitionBoardList.stream().map(ExhibitionBoard::getName).collect(Collectors.toList()));
            }

            for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
                String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
                if (exhibitionBoardCatId != null) {
liqin's avatar
liqin committed
409 410 411 412
                    exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
                }
                String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
                if (boardCopyrightOwnerId != null) {
liqin's avatar
liqin committed
413 414 415 416
                    final CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(boardCopyrightOwnerId);
                    if (copyrightOwner != null) {
                        exhibitionBoard.setBoardCopyrightOwnerName(copyrightOwner.getName());
                    }
liqin's avatar
liqin committed
417 418 419 420 421 422 423
                }
                if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
                    String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
                    exhibitionBoard.setVideoContentCopyrightOwnerName(name);
                }

                LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
liqin's avatar
liqin committed
424
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
425 426 427 428 429 430
                assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
                final List<Asset> audioList = this.assetService.list(assetQueryWrapper);
                exhibitionBoard.setAudioList(audioList);

                assetQueryWrapper.clear();
                assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoard.getId());
liqin's avatar
liqin committed
431
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
432 433 434 435 436 437
                assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
                final List<Asset> datumList = this.assetService.list(assetQueryWrapper);
                exhibitionBoard.setDatumList(datumList);

                String videoContentId = exhibitionBoard.getVideoContentId();
                if (videoContentId != null) {
liqin's avatar
liqin committed
438 439 440 441
                    final VideoContent videoContent = this.videoContentService.getOne(Wrappers.<VideoContent>lambdaQuery().eq(VideoContent::getId, videoContentId));
                    if (videoContent != null) {
                        assetQueryWrapper.clear();
                        assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, videoContentId);
liqin's avatar
liqin committed
442
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
443 444 445 446 447
                        assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.VIDEO_CONTENT.name());
                        final List<Asset> videoList = this.assetService.list(assetQueryWrapper);
                        exhibitionBoard.setVideoList(videoList);
                        exhibitionBoard.setVideoContentName(videoContent.getName());
                    }
liqin's avatar
liqin committed
448 449 450 451
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }
liqin's avatar
liqin committed
452 453 454 455
        final LambdaQueryWrapper<Audit> auditQueryWrapper = Wrappers.<Audit>lambdaQuery().eq(Audit::getRefItemId, id);
        final List<Audit> auditList = this.auditService.list(auditQueryWrapper);
        learningContent.setAuditHistoryList(auditList);

liqin's avatar
liqin committed
456
        return getResult(learningContent);
liqin's avatar
liqin committed
457 458
    }

liqin's avatar
liqin committed
459 460 461 462 463 464 465
    /**
     * 通用排序方法(拖拽排序/所有排序完成后点击保存)
     *
     * @param sourceId 源实体ID
     * @param targetId 目标实体ID
     * @return Void
     */
liqin's avatar
liqin committed
466 467
    @ApiOperation(value = "学习内容排序")
    @PutMapping(value = "/sort")
wzp's avatar
wzp committed
468
    @RequiresAuthentication  //@RequiresPermissions("learning:content:sort")
liqin's avatar
liqin committed
469
    public Map<String, Object> updateSortorder(String sourceId, String targetId) {
liqin's avatar
liqin committed
470 471
        LearningContent theSource = this.learningContentService.getById(sourceId);
        LearningContent theTarget = this.learningContentService.getById(targetId);
liqin's avatar
liqin committed
472
        String moveType = theSource.getSortorder() > theTarget.getSortorder() ? "down" : "up";
liqin's avatar
liqin committed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
        Integer sourceSortorder = theSource.getSortorder();
        Integer targetSortorder = theTarget.getSortorder();

        //默认sortorder为降序排序,向上移动
        if ("up".equalsIgnoreCase(moveType) && sourceSortorder < targetSortorder) {
            QueryWrapper<LearningContent> wrapper = new QueryWrapper<>();
            wrapper.between("sortorder", sourceSortorder, targetSortorder);
            wrapper.select("id", "sortorder");
            List<LearningContent> list = this.learningContentService.list(wrapper);
            for (LearningContent entity : list) {
                if (!entity.getId().equals(sourceId)) {
                    entity.setSortorder(entity.getSortorder() - 1);
                    this.learningContentService.updateById(entity);
                }
            }
liqin's avatar
liqin committed
488 489
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
490 491 492 493 494 495 496 497 498 499 500 501 502
        }
        //默认sortorder为降序排序,向下移动
        else if ("down".equalsIgnoreCase(moveType) && sourceSortorder > targetSortorder) {
            QueryWrapper<LearningContent> wrapper = new QueryWrapper<>();
            wrapper.between("sortorder", targetSortorder, sourceSortorder);
            wrapper.select("id", "sortorder");
            List<LearningContent> slideList = this.learningContentService.list(wrapper);
            for (LearningContent entity : slideList) {
                if (!entity.getId().equals(sourceId)) {
                    entity.setSortorder(entity.getSortorder() + 1);
                    this.learningContentService.updateById(entity);
                }
            }
liqin's avatar
liqin committed
503 504
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
505 506 507 508 509 510 511 512 513 514 515 516 517
        }
        //默认sortorder为正序排序,向下移动
        else if ("down".equalsIgnoreCase(moveType) && sourceSortorder < targetSortorder) {
            QueryWrapper<LearningContent> wrapper = new QueryWrapper<>();
            wrapper.between("sortorder", sourceSortorder, targetSortorder);
            wrapper.select("id", "sortorder");
            List<LearningContent> slideList = this.learningContentService.list(wrapper);
            for (LearningContent slide : slideList) {
                if (!slide.getId().equals(sourceId)) {
                    slide.setSortorder(slide.getSortorder() - 1);
                    this.learningContentService.updateById(slide);
                }
            }
liqin's avatar
liqin committed
518 519
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
        }
        //默认sortorder为正序排序,向上移动
        else if ("up".equalsIgnoreCase(moveType) && sourceSortorder > targetSortorder) {
            QueryWrapper<LearningContent> wrapper = new QueryWrapper<>();
            wrapper.between("sortorder", targetSortorder, sourceSortorder);
            wrapper.select("id", "sortorder");
            List<LearningContent> slideList = this.learningContentService.list(wrapper);
            for (LearningContent slide : slideList) {
                if (!slide.getId().equals(sourceId)) {
                    slide.setSortorder(slide.getSortorder() + 1);
                    this.learningContentService.updateById(slide);
                }
            }
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
        }
liqin's avatar
liqin committed
536
        return getSuccessResult();
liqin's avatar
liqin committed
537 538
    }

liqin's avatar
liqin committed
539 540 541
    @ApiOperation(value = "启用/禁用学习内容", notes = "启用/禁用学习内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
liqin's avatar
liqin committed
542
            @ApiImplicitParam(name = "isPublish", value = "是否启用", dataType = "boolean", paramType = "query", allowableValues = "True, False")
liqin's avatar
liqin committed
543 544
    })
    @PutMapping("/enable/{id}")
wzp's avatar
wzp committed
545
    @RequiresAuthentication  //@RequiresPermissions("learning:content:enable")
wzp's avatar
wzp committed
546
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.ENABLE)
liqin's avatar
liqin committed
547
    public Map<String, Object> enableLearningContent(@PathVariable("id") String id, @RequestParam("isPublish") Boolean isPublish) {
wzp's avatar
wzp committed
548
        TUser user = getcurUser();
liqin's avatar
liqin committed
549 550

        LearningContent learningContent = this.learningContentService.getById(id);
liqin's avatar
liqin committed
551
        final Audit audit = Audit.builder()
liqin's avatar
liqin committed
552 553
                .content(learningContent.getName())
                .name(learningContent.getName())
liqin's avatar
liqin committed
554
                .refItemId(id)
wzp's avatar
wzp committed
555
                .userId(user.getId())
liqin's avatar
liqin committed
556 557
                .type(AuditTypeEnum.LEARNING_CONTENT.name())
                .operation(isPublish ? AuditOperationEnum.ENABLE.name() : AuditOperationEnum.DISABLE.name())
liqin's avatar
liqin committed
558 559
                .status(AuditStatusEnum.TBC.name())
                .level(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
560
                .build();
liqin's avatar
liqin committed
561
        this.auditService.save(audit);
liqin's avatar
liqin committed
562
        this.learningContentService.updateById(LearningContent.builder().id(id).auditStatus(AuditStatusEnum.TBC.name()).build());
liqin's avatar
liqin committed
563 564 565
        return getSuccessResult();
    }

liqin's avatar
liqin committed
566 567
}