LearningContentController.java 26.6 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;
liqin's avatar
liqin committed
7 8 9
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
10 11
import cn.wisenergy.chnmuseum.party.model.*;
import cn.wisenergy.chnmuseum.party.service.*;
liqin's avatar
liqin committed
12
import cn.wisenergy.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
13
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
14
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
liqin's avatar
liqin committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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
31
import java.util.stream.Collectors;
liqin's avatar
liqin committed
32 33

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

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

    @PostMapping("/save")
liqin's avatar
liqin committed
73 74 75
    @RequiresPermissions("learning:content:save")
    @ApiOperation(value = "添加学习内容", notes = "添加学习内容")
    public Map<String, Object> saveLearningContent(@Validated(value = {Add.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
76
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
77
        if (tUser != null) {
liqin's avatar
liqin committed
78
            learningContent.setOrganCode(tUser.getOrgCode());
liqin's avatar
liqin committed
79
        }
liqin's avatar
liqin committed
80
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
liqin's avatar
liqin committed
81
        learningContent.setPublished(false);
liqin's avatar
liqin committed
82 83 84
        QueryWrapper<LearningContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("max(sortorder) as sortorder");
        LearningContent content = this.learningContentService.getOne(queryWrapper);
liqin's avatar
liqin committed
85
        if (content != null && content.getSortorder() != null) {
liqin's avatar
liqin committed
86 87 88 89
            learningContent.setSortorder(content.getSortorder() + 1);
        } else {
            learningContent.setSortorder(1);
        }
liqin's avatar
liqin committed
90 91
        // 保存业务节点信息
        boolean result = learningContentService.save(learningContent);
liqin's avatar
liqin committed
92
        final String learningContentId = learningContent.getId();
liqin's avatar
liqin committed
93

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

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

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

liqin's avatar
liqin committed
120 121
        // 返回操作结果
        if (result) {
liqin's avatar
liqin committed
122 123 124 125 126 127 128
            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
129 130 131 132 133 134 135 136
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
liqin's avatar
liqin committed
137 138
    @RequiresPermissions("learning:content:update")
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
liqin's avatar
liqin committed
139
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
140
        learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
liqin's avatar
liqin committed
141
        learningContent.setPublished(false);
liqin's avatar
liqin committed
142 143 144 145 146 147 148 149 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
        // 保存业务节点信息
        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
178 179
        boolean flag = learningContentService.updateById(learningContent);
        if (flag) {
liqin's avatar
liqin committed
180 181 182 183 184 185 186 187 188
            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
189 190 191 192 193 194
            return getSuccessResult();
        }
        return getFailResult();
    }

    @DeleteMapping("/delete/{id}")
liqin's avatar
liqin committed
195
    @RequiresPermissions("learning:content:delete")
liqin's avatar
liqin committed
196
    @ApiOperation(value = "根据ID下架学习内容", notes = "根据ID下架学习内容")
liqin's avatar
liqin committed
197 198 199
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String")
    })
liqin's avatar
liqin committed
200
    public Map<String, Object> deleteLearningContent(@PathVariable("id") String id) {
liqin's avatar
liqin committed
201 202 203 204 205 206 207 208
        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
209 210 211 212 213 214 215
        if (result) {
            return getSuccessResult();
        }
        return getFailResult();
    }

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

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

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

liqin's avatar
liqin committed
300 301 302 303
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }
liqin's avatar
liqin committed
304

liqin's avatar
liqin committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
        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);
        learningContent.setExhibitionBoardCatIdList(exhibitionBoardCats.stream().map(ExhibitionBoardCat::getId).collect(Collectors.toList()));
        learningContent.setExhibitionBoardCatNameList(exhibitionBoardCats.stream().map(ExhibitionBoardCat::getName).collect(Collectors.toList()));

        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);
        learningContent.setCopyrightOwnerIdList(copyrightOwnerList.stream().map(CopyrightOwner::getId).collect(Collectors.toList()));
        learningContent.setCopyrightOwnerNameList(copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.toList()));

        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);
        final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
        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
326 327 328 329 330 331 332 333 334
        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());
            }
liqin's avatar
liqin committed
335 336 337 338
            if (exhibitionBoard.getVideoContentCopyrightOwnerId() != null) {
                String name = this.copyrightOwnerService.getById(exhibitionBoard.getVideoContentCopyrightOwnerId()).getName();
                exhibitionBoard.setVideoContentCopyrightOwnerName(name);
            }
liqin's avatar
liqin committed
339

liqin's avatar
liqin committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
            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) {
                final VideoContent videoContent = this.videoContentService.getById(videoContentId);
                exhibitionBoard.setVideoContentName(videoContent.getName());

                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);
liqin's avatar
liqin committed
361 362 363 364
            }
        }
        learningContent.setExhibitionBoardList(exhibitionBoardList);

liqin's avatar
liqin committed
365
        return getResult(learningContent);
liqin's avatar
liqin committed
366 367
    }

liqin's avatar
liqin committed
368 369 370 371 372 373 374
    /**
     * 通用排序方法(拖拽排序/所有排序完成后点击保存)
     *
     * @param sourceId 源实体ID
     * @param targetId 目标实体ID
     * @return Void
     */
liqin's avatar
liqin committed
375 376 377
    @ApiOperation(value = "学习内容排序")
    @PutMapping(value = "/sort")
    @RequiresPermissions("learning:content:sort")
liqin's avatar
liqin committed
378
    public Map<String, Object> updateSortorder(String sourceId, String targetId) {
liqin's avatar
liqin committed
379 380 381 382
        String moveType;
        LearningContent theSource = this.learningContentService.getById(sourceId);
        LearningContent theTarget = this.learningContentService.getById(targetId);

liqin's avatar
liqin committed
383
        if (theSource.getSortorder() > theTarget.getSortorder()) {
liqin's avatar
liqin committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
            moveType = "down";
        } else {
            moveType = "up";
        }
        Integer sourceSortorder = theSource.getSortorder();
        Integer targetSortorder = theTarget.getSortorder();

        boolean flag = false;
        //默认sortorder为降序排序,向上移动
        if ("up".equalsIgnoreCase(moveType) && sourceSortorder < targetSortorder) {
            flag = true;
            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);
                }
            }
        }
        //默认sortorder为降序排序,向下移动
        else if ("down".equalsIgnoreCase(moveType) && sourceSortorder > targetSortorder) {
            flag = true;
            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);
                }
            }
        }
        //默认sortorder为正序排序,向下移动
        else if ("down".equalsIgnoreCase(moveType) && sourceSortorder < targetSortorder) {
            flag = true;
            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);
                }
            }
        }
        //默认sortorder为正序排序,向上移动
        else if ("up".equalsIgnoreCase(moveType) && sourceSortorder > targetSortorder) {
            flag = true;
            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);
                }
            }
        }
        if (flag) {
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
            return getSuccessResult();
        }
        return getFailResult();
    }

liqin's avatar
liqin committed
456 457 458
    @ApiOperation(value = "启用/禁用学习内容", notes = "启用/禁用学习内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
liqin's avatar
liqin committed
459
            @ApiImplicitParam(name = "isPublish", value = "是否上架", dataType = "boolean", paramType = "query", allowableValues = "True, False")
liqin's avatar
liqin committed
460 461 462 463 464 465 466 467 468 469 470
    })
    @PutMapping("/enable/{id}")
    @RequiresPermissions("learning:content:enable")
    public Map<String, Object> enableLearningContent(@PathVariable("id") String id, @RequestParam("isPublish") Boolean isPublish) {
        final Audit audit = Audit.builder().content("")
                .isDeleted(false)
                .refItemId(id)
                .status(AuditStatusEnum.TBC.name())
                .level(AuditStatusEnum.TBC.name())
                .type(AuditTypeEnum.LEARNING_CONTENT.name()).build();
        if (isPublish) {
liqin's avatar
liqin committed
471
            audit.setOperation(AuditOperationEnum.ENABLE.name());
liqin's avatar
liqin committed
472
        } else {
liqin's avatar
liqin committed
473
            audit.setOperation(AuditOperationEnum.DISABLE.name());
liqin's avatar
liqin committed
474 475 476 477 478
        }
        this.auditService.save(audit);
        return getSuccessResult();
    }

liqin's avatar
liqin committed
479 480
}