LearningContentController.java 29.1 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
import cn.wisenergy.chnmuseum.party.common.enums.FileCatEnum;
wzp's avatar
wzp committed
7 8 9
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
10 11 12
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
13 14
import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.*;
liqin's avatar
liqin committed
15
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
16
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
17
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
liqin's avatar
liqin committed
18
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
79
        if (tUser != null) {
liqin's avatar
liqin committed
80
            learningContent.setOrganCode(tUser.getOrgCode());
liqin's avatar
liqin committed
81
        }
liqin's avatar
liqin committed
82
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
liqin's avatar
liqin committed
83
        learningContent.setPublished(false);
liqin's avatar
liqin committed
84 85 86
        QueryWrapper<LearningContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("max(sortorder) as sortorder");
        LearningContent content = this.learningContentService.getOne(queryWrapper);
liqin's avatar
liqin committed
87
        if (content != null && content.getSortorder() != null) {
liqin's avatar
liqin committed
88 89 90 91
            learningContent.setSortorder(content.getSortorder() + 1);
        } else {
            learningContent.setSortorder(1);
        }
liqin's avatar
liqin committed
92 93
        // 保存业务节点信息
        boolean result = learningContentService.save(learningContent);
liqin's avatar
liqin committed
94
        final String learningContentId = learningContent.getId();
liqin's avatar
liqin committed
95

liqin's avatar
liqin committed
96 97 98 99 100
        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
101

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

liqin's avatar
liqin committed
108 109 110
        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        for (String exhibitionBoardId : exhibitionBoardIdList) {
            LearningContentBoard learningContentBoard = LearningContentBoard.builder().exhibitionBoardId(exhibitionBoardId).learningContentId(learningContentId).build();
liqin's avatar
liqin committed
111
            QueryWrapper<LearningContentBoard> learningContentBoardQueryWrapper = new QueryWrapper<>();
liqin's avatar
liqin committed
112
            learningContentBoardQueryWrapper.select("max(sortorder) as sortorder");
liqin's avatar
liqin committed
113
            LearningContentBoard one = this.learningContentBoardService.getOne(learningContentBoardQueryWrapper);
liqin's avatar
liqin committed
114
            if (one != null && one.getSortorder() != null) {
liqin's avatar
liqin committed
115
                learningContent.setSortorder(one.getSortorder() + 1);
liqin's avatar
liqin committed
116
            } else {
liqin's avatar
liqin committed
117
                learningContent.setSortorder(1);
liqin's avatar
liqin committed
118
            }
liqin's avatar
liqin committed
119 120
            this.learningContentBoardService.save(learningContentBoard);
        }
liqin's avatar
liqin committed
121

liqin's avatar
liqin committed
122 123
        // 返回操作结果
        if (result) {
liqin's avatar
liqin committed
124 125
            final Audit audit = Audit.builder()
                    .content(learningContent.getName())
liqin's avatar
liqin committed
126
                    .refItemId(learningContent.getId())
liqin's avatar
liqin committed
127
                    .type(AuditTypeEnum.LEARNING_CONTENT.name())
wzp's avatar
wzp committed
128
                    .userId(tUser.getId())
liqin's avatar
liqin committed
129
                    .operation(AuditOperationEnum.ADD.name())
liqin's avatar
liqin committed
130
                    .status(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
131 132 133
                    .deleted(false)
                    .level(AuditStatusEnum.TBC.name())
                    .build();
liqin's avatar
liqin committed
134
            this.auditService.save(audit);
liqin's avatar
liqin committed
135 136 137 138 139 140 141 142
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
143
    @RequiresAuthentication  //@RequiresPermissions("learning:content:update")
liqin's avatar
liqin committed
144
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
wzp's avatar
wzp committed
145
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.UPDATE)
liqin's avatar
liqin committed
146
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
wzp's avatar
wzp committed
147
        TUser user = getcurUser();
liqin's avatar
liqin committed
148
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
liqin's avatar
liqin committed
149
        learningContent.setPublished(false);
liqin's avatar
liqin committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        // 保存业务节点信息
        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
186 187
        boolean flag = learningContentService.updateById(learningContent);
        if (flag) {
liqin's avatar
liqin committed
188 189
            final Audit audit = Audit.builder()
                    .content(learningContent.getName())
wzp's avatar
wzp committed
190
                    .userId(user.getId())
liqin's avatar
liqin committed
191 192
                    .refItemId(learningContent.getId())
                    .type(AuditTypeEnum.LEARNING_CONTENT.name())
liqin's avatar
liqin committed
193 194 195 196
                    .operation(AuditOperationEnum.EDIT.name())
                    .status(AuditStatusEnum.TBC.name())
                    .deleted(false)
                    .level(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
197 198 199
                    .build();
            this.auditService.save(audit);

liqin's avatar
liqin committed
200 201 202 203 204 205
            return getSuccessResult();
        }
        return getFailResult();
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
206
    @RequiresAuthentication  //@RequiresPermissions("learning:content:list")
liqin's avatar
liqin committed
207 208
    @ApiOperation(value = "获取学习内容全部列表(无分页)", notes = "获取学习内容全部列表(无分页)")
    @ApiImplicitParams(value = {
liqin's avatar
liqin committed
209 210
            @ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String")
liqin's avatar
liqin committed
211
    })
wzp's avatar
wzp committed
212
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
213 214
    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
215 216
        final LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getAuditStatus, auditStatus.name());
        lambdaQueryWrapper.eq(LearningContent::getPublished, true);
liqin's avatar
liqin committed
217 218 219
        if (StringUtils.isNotBlank(learningProjectId)) {
            lambdaQueryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
        }
wzp's avatar
wzp committed
220
        List<LearningContent> learningContentList = learningContentService.list(lambdaQueryWrapper);
liqin's avatar
liqin committed
221 222 223
        return getResult(learningContentList);
    }

liqin's avatar
liqin committed
224 225 226
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
227
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String"),
liqin's avatar
liqin committed
228 229 230 231
            @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
232
    @PostMapping("/getPageList")
wzp's avatar
wzp committed
233
    @RequiresAuthentication  //@RequiresPermissions("learning:content:page")
liqin's avatar
liqin committed
234
    @ApiOperation(value = "获取学习内容分页列表", notes = "获取学习内容分页列表")
wzp's avatar
wzp committed
235
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
236
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam, @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
liqin's avatar
liqin committed
237
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
liqin's avatar
liqin committed
238 239 240 241
        // 根据创建时间区间检索
        if (genericPageParam.getIsPublished() != null) {
            queryWrapper.eq(LearningContent::getPublished, genericPageParam.getIsPublished());
        }
liqin's avatar
liqin committed
242
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
243
        if (StringUtils.isNotBlank(learningProjectId)) {
liqin's avatar
liqin committed
244
            queryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
liqin's avatar
liqin committed
245 246
        }
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
247 248 249 250 251 252 253 254 255
        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
256
        queryWrapper.orderByDesc(LearningContent::getSortorder);
liqin's avatar
liqin committed
257 258 259 260
        // 设置查询内容
        queryWrapper.select(
                LearningContent::getId,
                LearningContent::getName,
liqin's avatar
liqin committed
261
                LearningContent::getApplicableScope,
liqin's avatar
liqin committed
262
                LearningContent::getCreatorName,
liqin's avatar
liqin committed
263
                LearningContent::getAuditStatus,
liqin's avatar
liqin committed
264
                LearningContent::getPublished,
liqin's avatar
liqin committed
265 266
                LearningContent::getDeleted,
                LearningContent::getSortorder,
liqin's avatar
liqin committed
267 268 269 270
                LearningContent::getCreateTime,
                LearningContent::getUpdateTime);
        Page<LearningContent> page = this.learningContentService.page(getPage(), queryWrapper);
        for (LearningContent learningContent : page.getRecords()) {
liqin's avatar
liqin committed
271 272 273
            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
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289

//            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
290 291
        }
        return getResult(page);
liqin's avatar
liqin committed
292 293 294 295 296 297 298
    }

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

liqin's avatar
liqin committed
304 305 306 307
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }
liqin's avatar
liqin committed
308

liqin's avatar
liqin committed
309 310 311 312
        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);
        final List<ExhibitionBoardCat> exhibitionBoardCats = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
liqin's avatar
liqin committed
313 314 315 316
        if (!exhibitionBoardCats.isEmpty()) {
            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
317 318 319 320 321

        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);
        final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
322 323 324 325
        if (!copyrightOwnerList.isEmpty()) {
            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
326 327 328 329

        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
330 331
        if (!exhibitionBoardIdList.isEmpty()) {
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
liqin's avatar
liqin committed
332 333 334 335
            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
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363

            for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
                String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
                if (exhibitionBoardCatId != null) {
                    exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
                }
                String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
                if (boardCopyrightOwnerId != null) {
                    exhibitionBoard.setBoardCopyrightOwnerName(this.copyrightOwnerService.getById(boardCopyrightOwnerId).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());
                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());
                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
364 365 366 367 368 369 370 371 372
                    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);
                        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
373 374 375 376
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }
liqin's avatar
liqin committed
377

liqin's avatar
liqin committed
378 379 380 381 382 383 384 385 386 387 388 389 390
        final LambdaQueryWrapper<Audit> auditQueryWrapper = Wrappers.<Audit>lambdaQuery().eq(Audit::getRefItemId, id);
        auditQueryWrapper.select(Audit::getContent);
        auditQueryWrapper.select(Audit::getType);
        auditQueryWrapper.select(Audit::getOperation);
        auditQueryWrapper.select(Audit::getStatus);
        auditQueryWrapper.select(Audit::getFirstTime);
        auditQueryWrapper.select(Audit::getFirstRemarks);
        auditQueryWrapper.select(Audit::getSecondTime);
        auditQueryWrapper.select(Audit::getSecondTime);
        auditQueryWrapper.select(Audit::getLevel);
        final List<Audit> auditList = this.auditService.list(auditQueryWrapper);
        learningContent.setAuditHistoryList(auditList);

liqin's avatar
liqin committed
391
        return getResult(learningContent);
liqin's avatar
liqin committed
392 393
    }

liqin's avatar
liqin committed
394 395 396 397 398 399 400
    /**
     * 通用排序方法(拖拽排序/所有排序完成后点击保存)
     *
     * @param sourceId 源实体ID
     * @param targetId 目标实体ID
     * @return Void
     */
liqin's avatar
liqin committed
401 402
    @ApiOperation(value = "学习内容排序")
    @PutMapping(value = "/sort")
wzp's avatar
wzp committed
403
    @RequiresAuthentication  //@RequiresPermissions("learning:content:sort")
liqin's avatar
liqin committed
404
    public Map<String, Object> updateSortorder(String sourceId, String targetId) {
liqin's avatar
liqin committed
405 406
        LearningContent theSource = this.learningContentService.getById(sourceId);
        LearningContent theTarget = this.learningContentService.getById(targetId);
liqin's avatar
liqin committed
407
        String moveType = theSource.getSortorder() > theTarget.getSortorder() ? "down" : "up";
liqin's avatar
liqin committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
        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
423 424
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
425 426 427 428 429 430 431 432 433 434 435 436 437
        }
        //默认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
438 439
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
440 441 442 443 444 445 446 447 448 449 450 451 452
        }
        //默认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
453 454
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
        }
        //默认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
471
        return getSuccessResult();
liqin's avatar
liqin committed
472 473
    }

liqin's avatar
liqin committed
474 475 476
    @ApiOperation(value = "启用/禁用学习内容", notes = "启用/禁用学习内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
liqin's avatar
liqin committed
477
            @ApiImplicitParam(name = "isPublish", value = "是否启用", dataType = "boolean", paramType = "query", allowableValues = "True, False")
liqin's avatar
liqin committed
478 479
    })
    @PutMapping("/enable/{id}")
wzp's avatar
wzp committed
480
    @RequiresAuthentication  //@RequiresPermissions("learning:content:enable")
wzp's avatar
wzp committed
481
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.ENABLE)
liqin's avatar
liqin committed
482
    public Map<String, Object> enableLearningContent(@PathVariable("id") String id, @RequestParam("isPublish") Boolean isPublish) {
wzp's avatar
wzp committed
483
        TUser user = getcurUser();
liqin's avatar
liqin committed
484 485
        final Audit audit = Audit.builder()
                .content(this.learningContentService.getById(id).getName())
liqin's avatar
liqin committed
486
                .refItemId(id)
wzp's avatar
wzp committed
487
                .userId(user.getId())
liqin's avatar
liqin committed
488 489
                .type(AuditTypeEnum.LEARNING_CONTENT.name())
                .operation(isPublish ? AuditOperationEnum.ENABLE.name() : AuditOperationEnum.DISABLE.name())
liqin's avatar
liqin committed
490
                .status(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
491
                .deleted(false)
liqin's avatar
liqin committed
492
                .level(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
493
                .build();
liqin's avatar
liqin committed
494
        this.auditService.save(audit);
liqin's avatar
liqin committed
495
        this.learningContentService.updateById(LearningContent.builder().id(id).auditStatus(AuditStatusEnum.TBC.name()).build());
liqin's avatar
liqin committed
496 497 498
        return getSuccessResult();
    }

liqin's avatar
liqin committed
499 500
}