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

liqin's avatar
liqin committed
3 4 5 6 7 8 9 10 11 12 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
                    .organId(tUser.getOrgId())
liqin's avatar
liqin committed
141
                    .operation(AuditOperationEnum.ADD.name())
liqin's avatar
liqin committed
142
                    .status(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
143 144
                    .level(AuditStatusEnum.TBC.name())
                    .build();
liqin's avatar
liqin committed
145
            this.auditService.save(audit);
liqin's avatar
liqin committed
146 147 148 149 150 151 152 153
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
154
    @RequiresAuthentication  //@RequiresPermissions("learning:content:update")
liqin's avatar
liqin committed
155
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
wzp's avatar
wzp committed
156
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.UPDATE)
liqin's avatar
liqin committed
157
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
158 159 160 161 162 163
        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
164

liqin's avatar
liqin committed
165 166 167 168
        final LearningContent one = this.learningContentService.getById(learningContent.getId());
        one.setAuditStatus(AuditStatusEnum.TBC.name());
        this.learningContentService.updateById(one);

liqin's avatar
liqin committed
169
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
170 171 172
        final Audit audit = Audit.builder()
                .content(learningContent.getName())
                .name(learningContent.getName())
liqin's avatar
liqin committed
173 174
                .userId(tUser.getId())
                .organId(tUser.getOrgId())
liqin's avatar
liqin committed
175 176 177 178 179 180 181 182 183
                .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
184 185 186
    }

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

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

//            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
271 272
        }
        return getResult(page);
liqin's avatar
liqin committed
273 274 275 276 277 278 279
    }

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

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

liqin's avatar
liqin committed
290 291 292
        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
293 294
        if (!exhibitionBoardCatIdList.isEmpty()) {
            final List<ExhibitionBoardCat> exhibitionBoardCats = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
liqin's avatar
liqin committed
295 296 297
            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
298 299 300 301

        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
302 303
        if (!copyrightOwnerIdList.isEmpty()) {
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
304 305 306
            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
307 308 309 310

        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
311 312
        if (!exhibitionBoardIdList.isEmpty()) {
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
liqin's avatar
liqin committed
313 314 315 316
            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
317 318 319 320

            for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
                String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
                if (exhibitionBoardCatId != null) {
liqin's avatar
liqin committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
                    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
336
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
337 338 339 340 341 342
                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
343
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
344 345 346 347 348 349 350 351 352 353
                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
354
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
                        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
374
            @ApiImplicitParam(name = "auditId", value = "审核ID", dataType = "String", paramType = "path")
liqin's avatar
liqin committed
375
    })
liqin's avatar
liqin committed
376
    @GetMapping("/getAudit/{auditId}")
liqin's avatar
liqin committed
377 378 379 380 381 382 383 384 385 386
    @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
387 388
        final List<String> copyrightOwnerIdList = learningContent.getCopyrightOwnerIdList();
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
liqin's avatar
liqin committed
389
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
390
            learningContent.setCopyrightOwnerIdList(copyrightOwnerIdList);
liqin's avatar
liqin committed
391 392 393
            learningContent.setCopyrightOwnerNameList(copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.toList()));
        }

liqin's avatar
liqin committed
394 395 396 397 398 399 400 401
        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();
liqin's avatar
liqin committed
402
        if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
liqin's avatar
liqin committed
403 404
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
            if (!exhibitionBoardList.isEmpty()) {
liqin's avatar
liqin committed
405
                learningContent.setExhibitionBoardIdList(exhibitionBoardIdList);
liqin's avatar
liqin committed
406 407 408 409 410 411
                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
412 413 414 415
                    exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
                }
                String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
                if (boardCopyrightOwnerId != null) {
liqin's avatar
liqin committed
416 417 418 419
                    final CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(boardCopyrightOwnerId);
                    if (copyrightOwner != null) {
                        exhibitionBoard.setBoardCopyrightOwnerName(copyrightOwner.getName());
                    }
liqin's avatar
liqin committed
420 421 422 423 424 425 426
                }
                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
427
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
428 429 430 431 432 433
                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
434
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
435 436 437 438 439 440
                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
441 442 443 444
                    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
445
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
446 447 448 449 450
                        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
451 452 453 454
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }
liqin's avatar
liqin committed
455 456 457 458
        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
459
        return getResult(learningContent);
liqin's avatar
liqin committed
460 461
    }

liqin's avatar
liqin committed
462 463 464 465 466 467 468
    /**
     * 通用排序方法(拖拽排序/所有排序完成后点击保存)
     *
     * @param sourceId 源实体ID
     * @param targetId 目标实体ID
     * @return Void
     */
liqin's avatar
liqin committed
469 470
    @ApiOperation(value = "学习内容排序")
    @PutMapping(value = "/sort")
wzp's avatar
wzp committed
471
    @RequiresAuthentication  //@RequiresPermissions("learning:content:sort")
liqin's avatar
liqin committed
472
    public Map<String, Object> updateSortorder(String sourceId, String targetId) {
liqin's avatar
liqin committed
473 474
        LearningContent theSource = this.learningContentService.getById(sourceId);
        LearningContent theTarget = this.learningContentService.getById(targetId);
liqin's avatar
liqin committed
475
        String moveType = theSource.getSortorder() > theTarget.getSortorder() ? "down" : "up";
liqin's avatar
liqin committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
        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
491 492
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
493 494 495 496 497 498 499 500 501 502 503 504 505
        }
        //默认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
506 507
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
508 509 510 511 512 513 514 515 516 517 518 519 520
        }
        //默认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
521 522
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
        }
        //默认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
539
        return getSuccessResult();
liqin's avatar
liqin committed
540 541
    }

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

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

liqin's avatar
liqin committed
570 571
}