LearningContentController.java 44.1 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
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;
10
import cn.chnmuseum.party.common.util.ListUtil;
liqin's avatar
liqin committed
11 12 13 14 15 16
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
17
import com.alibaba.fastjson.JSONObject;
18
import com.baomidou.mybatisplus.core.conditions.Wrapper;
liqin's avatar
liqin committed
19
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
20
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
21
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
liqin's avatar
liqin committed
22 23 24 25 26 27 28 29
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
wzp's avatar
wzp committed
30
import org.apache.shiro.authz.annotation.RequiresAuthentication;
31
import org.springframework.beans.factory.annotation.Autowired;
32
import org.springframework.transaction.annotation.Transactional;
33
import org.springframework.util.CollectionUtils;
liqin's avatar
liqin committed
34 35 36 37
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
38
import java.util.*;
liqin's avatar
liqin committed
39
import java.util.stream.Collectors;
liqin's avatar
liqin committed
40 41

/**
liqin's avatar
liqin committed
42
 * <pre>
liqin's avatar
liqin committed
43
 * 学习内容 前端控制器
liqin's avatar
liqin committed
44
 * </pre>
liqin's avatar
liqin committed
45 46
 *
 * @author Danny Lee
liqin's avatar
liqin committed
47
 * @since 2021-03-26
liqin's avatar
liqin committed
48
 */
liqin's avatar
liqin committed
49
@Slf4j
liqin's avatar
liqin committed
50
@RestController
liqin's avatar
liqin committed
51 52
@RequestMapping("/learningContent")
@Api(tags = {"学习内容操作接口"})
liqin's avatar
liqin committed
53 54
public class LearningContentController extends BaseController {

liqin's avatar
liqin committed
55 56 57
    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;
    @Resource
liqin's avatar
liqin committed
58
    private VideoContentService videoContentService;
liqin's avatar
liqin committed
59 60
    @Resource
    private CopyrightOwnerService copyrightOwnerService;
liqin's avatar
liqin committed
61 62
    @Resource
    private LearningContentService learningContentService;
liqin's avatar
liqin committed
63 64 65 66 67
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;
    @Resource
    private LearningContentBoardService learningContentBoardService;
    @Resource
liqin's avatar
liqin committed
68 69
    private ExhibitionBoardService exhibitionBoardService;
    @Resource
liqin's avatar
liqin committed
70
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;
liqin's avatar
liqin committed
71 72
    @Resource
    private LearningProjectService learningProjectService;
liqin's avatar
liqin committed
73 74
    @Resource
    private AuditService auditService;
liqin's avatar
liqin committed
75 76
    @Resource
    private AssetService assetService;
77
    @Autowired
78
    TOrganService organService;
liqin's avatar
liqin committed
79

80 81 82
    @Resource
    private LearningContentAssetService learningContentAssetService;

liqin's avatar
liqin committed
83
    @PostMapping("/save")
wzp's avatar
wzp committed
84
    @RequiresAuthentication  //@RequiresPermissions("learning:content:save")
liqin's avatar
liqin committed
85
    @ApiOperation(value = "添加学习内容", notes = "添加学习内容")
wzp's avatar
wzp committed
86
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.ADD)
87
    @Transactional
88
    public Map<String, Object> saveLearningContent(@Validated(value = {Add.class}) LearningContent learningContent, Boolean isMajor) {
wzp's avatar
wzp committed
89 90 91 92 93 94
        TUser tUser1 = getcurUser();
        if ("1".equals(tUser1.getType())){
            learningContent.setCreateType(1);
        }else {
            learningContent.setCreateType(2);
        }
liqin's avatar
liqin committed
95 96 97 98 99 100
        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
101
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
102
        if (tUser != null) {
liqin's avatar
liqin committed
103
            learningContent.setOrganCode(tUser.getOrgCode());
liqin's avatar
liqin committed
104
        }
105 106 107 108 109 110 111 112
        //
        boolean nonUnitRole = !isUnitRole(tUser);
        if (nonUnitRole){
            learningContent.setAuditStatus(AuditStatusEnum.TBC.name());
        }else {
            //是单位管理员直接变成通过
            learningContent.setAuditStatus(AuditStatusEnum.APPROVED_FINAL.name());
        }
liqin's avatar
liqin committed
113
        learningContent.setPublished(false);
liqin's avatar
liqin committed
114 115 116
        QueryWrapper<LearningContent> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("max(sortorder) as sortorder");
        LearningContent content = this.learningContentService.getOne(queryWrapper);
liqin's avatar
liqin committed
117
        if (content != null && content.getSortorder() != null) {
liqin's avatar
liqin committed
118 119 120 121
            learningContent.setSortorder(content.getSortorder() + 1);
        } else {
            learningContent.setSortorder(1);
        }
122 123 124 125 126 127
        // 如果isMajor为null则新建学习内容为子学习内容
        if (isMajor == null) {
            learningContent.setIsMajor(false);
        }else {
            learningContent.setIsMajor(true);
        }
liqin's avatar
liqin committed
128 129
        // 保存业务节点信息
        boolean result = learningContentService.save(learningContent);
liqin's avatar
liqin committed
130
        final String learningContentId = learningContent.getId();
liqin's avatar
liqin committed
131

liqin's avatar
liqin committed
132 133 134 135 136
        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
137

liqin's avatar
liqin committed
138 139 140 141 142
        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
143

liqin's avatar
liqin committed
144 145
        final List<String> exhibitionBoardIdList = learningContent.getExhibitionBoardIdList();
        for (String exhibitionBoardId : exhibitionBoardIdList) {
liqin's avatar
liqin committed
146 147 148 149 150
            LearningContentBoard learningContentBoard = LearningContentBoard.builder()
                    .learningContentId(learningContentId)
                    .exhibitionBoardCatId(this.exhibitionBoardService.getById(exhibitionBoardId).getExhibitionBoardCatId())
                    .exhibitionBoardId(exhibitionBoardId)
                    .build();
liqin's avatar
liqin committed
151
            QueryWrapper<LearningContentBoard> learningContentBoardQueryWrapper = new QueryWrapper<>();
liqin's avatar
liqin committed
152
            learningContentBoardQueryWrapper.select("max(sortorder) as sortorder");
liqin's avatar
liqin committed
153
            LearningContentBoard one = this.learningContentBoardService.getOne(learningContentBoardQueryWrapper);
liqin's avatar
liqin committed
154
            if (one != null && one.getSortorder() != null) {
155 156
//                learningContent.setSortorder(one.getSortorder() + 1);
                learningContentBoard.setSortorder(one.getSortorder() + 1);
liqin's avatar
liqin committed
157
            } else {
158 159
//                learningContent.setSortorder(1);
                learningContentBoard.setSortorder(1);
liqin's avatar
liqin committed
160
            }
liqin's avatar
liqin committed
161 162
            this.learningContentBoardService.save(learningContentBoard);
        }
liqin's avatar
liqin committed
163

164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
        // 保存需要在app端显示的参考资料
        List<String> fileList = learningContent.getFileList();
        if (!CollectionUtils.isEmpty(fileList)) {
            List<LearningContentAsset> learningContentAssets = new ArrayList<>();
            List<Asset> assets = this.assetService.listByIds(fileList);
            assets.forEach(asset -> {
                LearningContentAsset learningContentAsset = LearningContentAsset.builder()
                        .learningContentId(learningContentId)
                        .boardId(asset.getRefItemId())
                        .assetId(asset.getId())
                        .build();
                learningContentAssets.add(learningContentAsset);
            });
            boolean b = this.learningContentAssetService.saveBatch(learningContentAssets);
            if (!b) {
                return getFailResult("添加数据失败!");
            }
        }

liqin's avatar
liqin committed
183
        // 返回操作结果
184
        if (result && nonUnitRole) {
liqin's avatar
liqin committed
185 186
            final Audit audit = Audit.builder()
                    .content(learningContent.getName())
liqin's avatar
liqin committed
187
                    .name(learningContent.getName())
liqin's avatar
liqin committed
188
                    .refItemId(learningContent.getId())
liqin's avatar
liqin committed
189
                    .type(AuditTypeEnum.LEARNING_CONTENT.name())
wzp's avatar
wzp committed
190
                    .userId(tUser.getId())
liqin's avatar
liqin committed
191
                    .organId(tUser.getOrgId())
liqin's avatar
liqin committed
192
                    .operation(AuditOperationEnum.ADD.name())
liqin's avatar
liqin committed
193
                    .status(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
194 195
                    .level(AuditStatusEnum.TBC.name())
                    .build();
liqin's avatar
liqin committed
196
            this.auditService.save(audit);
liqin's avatar
liqin committed
197
            return getSuccessResult();
198 199
        } else if (result) {
            return getSuccessResult();
liqin's avatar
liqin committed
200 201 202 203 204 205
        } else {
            // 保存失败
            return getFailResult();
        }
    }

206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
    /**
     * 判断是否为单位管理员
     *
     * @param tUser
     * @return
     */
    private boolean isUnitRole(TUser tUser) {
        boolean result = false;
        if (tUser != null) {
            List<String> roleList = tUser.getRoleList();
            if (!CollectionUtils.isEmpty(roleList)) {
                //单位管理员角色id为2
                result = roleList.contains("2");
            }
        }
        return result;
    }

liqin's avatar
liqin committed
224
    @PutMapping("/update")
wzp's avatar
wzp committed
225
    @RequiresAuthentication  //@RequiresPermissions("learning:content:update")
liqin's avatar
liqin committed
226
    @ApiOperation(value = "修改学习内容信息", notes = "修改学习内容信息")
wzp's avatar
wzp committed
227
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.UPDATE)
228
    @Transactional
liqin's avatar
liqin committed
229
    public Map<String, Object> updateLearningContent(@Validated(value = {Update.class}) LearningContent learningContent) {
liqin's avatar
liqin committed
230 231 232 233 234 235
        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
236

liqin's avatar
liqin committed
237
        final LearningContent one = this.learningContentService.getById(learningContent.getId());
238 239 240 241 242 243 244 245 246 247

        //单位管理员只能修改所属机构及其子机构下的的学习内容
        List<String> curUserSubOrgIds = getCurUserSubOrgIds();
        if (!CollectionUtils.isEmpty(curUserSubOrgIds)){
            String organCode = one.getOrganCode();
            boolean contains = curUserSubOrgIds.contains(organCode);
            if (!contains){
                return getFailResult("单位管理员只能修改所属机构及其子机构的学习内容");
            }
        }
248

249 250 251 252 253 254 255 256
        // 学习内容下显示的参考信息被修改
        LambdaQueryWrapper<LearningContentAsset> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(LearningContentAsset::getLearningContentId,one.getId());
        lambdaQuery.select(LearningContentAsset::getAssetId);
        List<String> list = this.learningContentAssetService.listObjs(lambdaQuery, Object::toString);
        if (!ListUtil.compareValue(list, learningContent.getFileList())) {
            LambdaUpdateWrapper<LearningContentAsset> updateWrapper = Wrappers.lambdaUpdate();
            updateWrapper.eq(LearningContentAsset::getLearningContentId, one.getId());
257 258 259 260
            // 删除原有信息
            this.learningContentAssetService.remove(updateWrapper);

            // 新增
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
            List<String> fileList = learningContent.getFileList();
            if (!CollectionUtils.isEmpty(fileList)) {
                LambdaQueryWrapper<Asset> queryWrapper = Wrappers.<Asset>lambdaQuery().in(Asset::getId, fileList);
                List<Asset> list1 = this.assetService.list(queryWrapper);
                ArrayList<LearningContentAsset> learningContentAssets = new ArrayList<>();
                list1.forEach(asset -> {
                    LearningContentAsset learningContentAsset = LearningContentAsset.builder()
                            .learningContentId(learningContent.getId())
                            .boardId(asset.getRefItemId())
                            .assetId(asset.getId())
                            .build();
                    learningContentAssets.add(learningContentAsset);
                });
                boolean b = this.learningContentAssetService.saveBatch(learningContentAssets);
                if (!b) {
                    return getFailResult("更新数据失败!");
                }
            }
        }
280

liqin's avatar
liqin committed
281 282 283
        one.setAuditStatus(AuditStatusEnum.TBC.name());
        this.learningContentService.updateById(one);

liqin's avatar
liqin committed
284
        final TUser tUser = getcurUser();
liqin's avatar
liqin committed
285 286 287
        final Audit audit = Audit.builder()
                .content(learningContent.getName())
                .name(learningContent.getName())
liqin's avatar
liqin committed
288 289
                .userId(tUser.getId())
                .organId(tUser.getOrgId())
liqin's avatar
liqin committed
290 291 292 293 294 295 296 297 298
                .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
299 300 301
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
302
    @RequiresAuthentication  //@RequiresPermissions("learning:content:list")
liqin's avatar
liqin committed
303 304
    @ApiOperation(value = "获取学习内容全部列表(无分页)", notes = "获取学习内容全部列表(无分页)")
    @ApiImplicitParams(value = {
liqin's avatar
liqin committed
305 306
            @ApiImplicitParam(name = "auditStatus", value = "审核状态", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String")
liqin's avatar
liqin committed
307
    })
wzp's avatar
wzp committed
308
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
309 310
    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
311 312
        final LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery().eq(LearningContent::getAuditStatus, auditStatus.name());
        lambdaQueryWrapper.eq(LearningContent::getPublished, true);
liqin's avatar
liqin committed
313 314 315
        if (StringUtils.isNotBlank(learningProjectId)) {
            lambdaQueryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
        }
wzp's avatar
wzp committed
316
        List<LearningContent> learningContentList = learningContentService.list(lambdaQueryWrapper);
liqin's avatar
liqin committed
317 318 319
        return getResult(learningContentList);
    }

liqin's avatar
liqin committed
320 321 322
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
liqin's avatar
liqin committed
323
            @ApiImplicitParam(name = "learningProjectId", value = "学习项目ID", paramType = "query", dataType = "String"),
liqin's avatar
liqin committed
324 325 326 327
            @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
328
    @PostMapping("/getPageList")
wzp's avatar
wzp committed
329
    @RequiresAuthentication  //@RequiresPermissions("learning:content:page")
liqin's avatar
liqin committed
330
    @ApiOperation(value = "获取学习内容分页列表", notes = "获取学习内容分页列表")
wzp's avatar
wzp committed
331
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.SELECT)
liqin's avatar
liqin committed
332
    public Map<String, Object> getLearningContentPageList(GenericPageParam genericPageParam, @RequestParam(value = "learningProjectId", required = false) String learningProjectId) {
liqin's avatar
liqin committed
333
        LambdaQueryWrapper<LearningContent> queryWrapper = new LambdaQueryWrapper<>();
334 335
        // 分页查询这里不包括主学习内容
        queryWrapper.eq(LearningContent::getIsMajor, false);
336 337
        List<String> curUserSubOrgIds = getCurUserSubOrgIds();
        if (!CollectionUtils.isEmpty(curUserSubOrgIds)){
338 339 340
            List<String> list = Arrays.asList("ALL_PLAT");
            queryWrapper.and(s -> s.in(LearningContent::getOrganCode, curUserSubOrgIds).or()
                    .in(LearningContent::getApplicableScope, list));
341
        }
liqin's avatar
liqin committed
342 343 344 345
        // 根据创建时间区间检索
        if (genericPageParam.getIsPublished() != null) {
            queryWrapper.eq(LearningContent::getPublished, genericPageParam.getIsPublished());
        }
liqin's avatar
liqin committed
346
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
347
        if (StringUtils.isNotBlank(learningProjectId)) {
liqin's avatar
liqin committed
348
            queryWrapper.eq(LearningContent::getLearningProjectId, learningProjectId);
liqin's avatar
liqin committed
349 350
        }
        // 对名称或编码模糊查询
liqin's avatar
liqin committed
351 352 353 354 355 356 357 358 359
        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
360
        queryWrapper.orderByDesc(LearningContent::getSortorder);
liqin's avatar
liqin committed
361 362 363 364
        // 设置查询内容
        queryWrapper.select(
                LearningContent::getId,
                LearningContent::getName,
liqin's avatar
liqin committed
365
                LearningContent::getApplicableScope,
liqin's avatar
liqin committed
366
                LearningContent::getCreatorName,
liqin's avatar
liqin committed
367
                LearningContent::getAuditStatus,
liqin's avatar
liqin committed
368
                LearningContent::getPublished,
liqin's avatar
liqin committed
369 370
                LearningContent::getDeleted,
                LearningContent::getSortorder,
liqin's avatar
liqin committed
371
                LearningContent::getCreateTime,
wzp's avatar
wzp committed
372
                LearningContent::getCreateType,
liqin's avatar
liqin committed
373 374 375
                LearningContent::getUpdateTime);
        Page<LearningContent> page = this.learningContentService.page(getPage(), queryWrapper);
        for (LearningContent learningContent : page.getRecords()) {
376 377 378 379 380
            LambdaQueryWrapper<LearningContentBoard> lambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery()
                    .select(LearningContentBoard::getExhibitionBoardId)
                    .eq(LearningContentBoard::getLearningContentId, learningContent.getId());
//            int exhibitionBoardCount = this.learningContentBoardService.count(lambdaQueryWrapper);
            List<String> exhibitionBoardIds = learningContentBoardService.listObjs(lambdaQueryWrapper, Object::toString);
381
            LambdaQueryWrapper<ExhibitionBoard> ExhibitionBoardIn = Wrappers.<ExhibitionBoard>lambdaQuery().in(ExhibitionBoard::getId, exhibitionBoardIds).eq(ExhibitionBoard::getPublished,true);
382 383 384
            int count = exhibitionBoardService.count(ExhibitionBoardIn);
//            learningContent.setExhibitionBoardCount(exhibitionBoardCount);
            learningContent.setExhibitionBoardCount(count);
liqin's avatar
liqin committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398

//            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);
399
//            learningContent.setExhibitionBoardCount(exhibitionBoardCount);
liqin's avatar
liqin committed
400 401
        }
        return getResult(page);
liqin's avatar
liqin committed
402 403
    }

404 405 406 407 408 409 410 411 412 413
    /**
     * 获取当前用户的所有子机构
     *
     * @return
     */
    public List<String> getCurUserSubOrgIds() {
        TUser tUser = getcurUser();
        if (tUser == null || StringUtils.isBlank(tUser.getOrgId())) {
            return null;
        }
414
        //平台管理员、单位管理员、学习内容管理员  单位管理员不能看到其它非同一机构的单位管理员
415 416 417 418 419 420
        List<String> roleList = tUser.getRoleList();
        boolean condition = !CollectionUtils.isEmpty(roleList)   //不为空
                && roleList.contains("2")      //2是单位管理员
                && !roleList.contains("1")        //不包含 1是平台管理员
                && !roleList.contains("8");       //不包含  8是学习内容管理员

421 422
        //不是只为单位管理员这种情况查询全部
//        userRoleService
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 456 457 458 459 460
        if (!condition) {
            return null;
        }
        String orgId = tUser.getOrgId();
        LambdaQueryWrapper<TOrgan> wrapper = new QueryWrapper<TOrgan>().lambda()
                .select(TOrgan::getId, TOrgan::getParentId, TOrgan::getCode)
                .eq(TOrgan::getIsDeleted, false);

        List<TOrgan> tOrgans = organService.list(wrapper);
        ArrayList<String> strings = new ArrayList<>();
        strings.add(orgId);
        List<String> result = new ArrayList<>();
        List<String> code = tOrgans.stream().filter(a -> a.getId().equals(orgId)).map(TOrgan::getCode).collect(Collectors.toList());
        if (code != null && code.size() >= 1) {
            result.add(code.get(0));
        }
        treeCode(strings, tOrgans, result);
        return result;
    }

    private void treeCode(List<String> parentCodes, List<TOrgan> all, List<String> codes) {
        if (CollectionUtils.isEmpty(parentCodes)) {
            return;
        }
        ArrayList<String> idArray = new ArrayList<>();
        parentCodes.stream().forEach(s -> {
            List<TOrgan> subOrgans = all.stream().filter(a -> a.getParentId() != null && a.getParentId().equals(s)).collect(Collectors.toList());
            subOrgans.stream().forEach(sub -> {
                String code = sub.getCode();
                String id = sub.getId();
                codes.add(code);
                idArray.add(id);
            });
        });
        //递归查询
        treeCode(idArray, all, codes);
    }

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

liqin's avatar
liqin committed
471 472 473 474
        LearningProject learningProject = this.learningProjectService.getById(learningContent.getLearningProjectId());
        if (learningProject != null) {
            learningContent.setLearningProjectName(learningProject.getName());
        }
liqin's avatar
liqin committed
475

liqin's avatar
liqin committed
476 477 478
        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
479 480
        if (!exhibitionBoardCatIdList.isEmpty()) {
            final List<ExhibitionBoardCat> exhibitionBoardCats = this.exhibitionBoardCatService.listByIds(exhibitionBoardCatIdList);
liqin's avatar
liqin committed
481 482 483
            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
484 485 486 487

        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
488 489
        if (!copyrightOwnerIdList.isEmpty()) {
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
490 491 492
            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
493 494

        final LambdaQueryWrapper<LearningContentBoard> queryWrapper2 = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getLearningContentId, id);
495 496 497 498 499 500
        queryWrapper2.select(LearningContentBoard::getExhibitionBoardId,LearningContentBoard::getSortorder)
                .orderByAsc(LearningContentBoard::getSortorder);
        final List<LearningContentBoard> exhibitionBoardIdListNew = this.learningContentBoardService.list(queryWrapper2);
        final List<String> exhibitionBoardIdList = exhibitionBoardIdListNew.stream().map(LearningContentBoard::getExhibitionBoardId).collect(Collectors.toList());

//        final List<String> exhibitionBoardIdList = this.learningContentBoardService.listObjs(queryWrapper2, Object::toString);
liqin's avatar
liqin committed
501
        if (!exhibitionBoardIdList.isEmpty()) {
502 503 504 505
            LambdaQueryWrapper<ExhibitionBoard> lambdaQuery = Wrappers.lambdaQuery();
            lambdaQuery.ne(ExhibitionBoard::getPublished, false);
            lambdaQuery.in(ExhibitionBoard::getId, exhibitionBoardIdList);
            List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.list(lambdaQuery);
506 507 508 509 510 511 512 513
            //设置sortorder ,然后在排序
            exhibitionBoardList.stream().forEach(eb -> {
                exhibitionBoardIdListNew.stream().forEach(lcb -> {
                    if (eb.getId().equals(lcb.getExhibitionBoardId())) {
                        eb.setSortorder(lcb.getSortorder());
                    }
                });
            });
514
            exhibitionBoardList = exhibitionBoardList.stream().sorted(Comparator.comparing(ExhibitionBoard::getSortorder).reversed()).collect(Collectors.toList());
515

liqin's avatar
liqin committed
516
            if (!exhibitionBoardList.isEmpty()) {
517 518
                learningContent.setExhibitionBoardIdList(exhibitionBoardList.stream().sorted(Comparator.comparing(ExhibitionBoard::getSortorder).reversed()).map(ExhibitionBoard::getId).collect(Collectors.toList()));
                learningContent.setExhibitionBoardNameList(exhibitionBoardList.stream().sorted(Comparator.comparing(ExhibitionBoard::getSortorder).reversed()).map(ExhibitionBoard::getName).collect(Collectors.toList()));
liqin's avatar
liqin committed
519
            }
liqin's avatar
liqin committed
520 521 522 523

            for (ExhibitionBoard exhibitionBoard : exhibitionBoardList) {
                String exhibitionBoardCatId = exhibitionBoard.getExhibitionBoardCatId();
                if (exhibitionBoardCatId != null) {
liqin's avatar
liqin committed
524 525 526 527 528 529 530 531 532
                    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());
                    }
                }
533
                if (StringUtils.isNotEmpty(exhibitionBoard.getVideoContentCopyrightOwnerId())) {
liqin's avatar
liqin committed
534 535 536 537 538 539
                    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());
540
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
541 542 543 544 545 546
                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());
547
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
548 549 550 551
                final List<Asset> datumList = this.assetService.list(assetQueryWrapper);
                exhibitionBoard.setDatumList(datumList);

                String videoContentId = exhibitionBoard.getVideoContentId();
552
                if (StringUtils.isNotEmpty(videoContentId)) {
liqin's avatar
liqin committed
553 554 555 556 557
                    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());
558
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
559 560 561 562 563 564 565 566
                        final List<Asset> videoList = this.assetService.list(assetQueryWrapper);
                        exhibitionBoard.setVideoList(videoList);
                        exhibitionBoard.setVideoContentName(videoContent.getName());
                    }
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }
567 568 569 570 571
        // 查询该学习内容下哪些展板参考资料在app展示
        LambdaQueryWrapper<LearningContentAsset> lambdaQueryWrapper = Wrappers.<LearningContentAsset>lambdaQuery().eq(LearningContentAsset::getLearningContentId, id);
        lambdaQueryWrapper.select(LearningContentAsset::getAssetId);
        List<String> list = this.learningContentAssetService.listObjs(lambdaQueryWrapper, Object::toString);
        learningContent.setFileList(list);
liqin's avatar
liqin committed
572 573 574 575 576 577 578 579 580 581

        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
582
            @ApiImplicitParam(name = "auditId", value = "审核ID", dataType = "String", paramType = "path")
liqin's avatar
liqin committed
583
    })
liqin's avatar
liqin committed
584
    @GetMapping("/getAudit/{auditId}")
liqin's avatar
liqin committed
585 586 587 588 589 590 591 592 593 594
    @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
595 596
        final List<String> copyrightOwnerIdList = learningContent.getCopyrightOwnerIdList();
        if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
liqin's avatar
liqin committed
597
            final List<CopyrightOwner> copyrightOwnerList = this.copyrightOwnerService.listByIds(copyrightOwnerIdList);
liqin's avatar
liqin committed
598
            learningContent.setCopyrightOwnerIdList(copyrightOwnerIdList);
liqin's avatar
liqin committed
599 600 601
            learningContent.setCopyrightOwnerNameList(copyrightOwnerList.stream().map(CopyrightOwner::getName).collect(Collectors.toList()));
        }

liqin's avatar
liqin committed
602 603 604 605 606 607 608 609
        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
610
        if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
liqin's avatar
liqin committed
611 612
            final List<ExhibitionBoard> exhibitionBoardList = this.exhibitionBoardService.listByIds(exhibitionBoardIdList);
            if (!exhibitionBoardList.isEmpty()) {
liqin's avatar
liqin committed
613
                learningContent.setExhibitionBoardIdList(exhibitionBoardIdList);
liqin's avatar
liqin committed
614 615 616 617 618 619
                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
620 621 622 623
                    exhibitionBoard.setExhibitionBoardCatName(this.exhibitionBoardCatService.getById(exhibitionBoardCatId).getName());
                }
                String boardCopyrightOwnerId = exhibitionBoard.getBoardCopyrightOwnerId();
                if (boardCopyrightOwnerId != null) {
liqin's avatar
liqin committed
624 625 626 627
                    final CopyrightOwner copyrightOwner = this.copyrightOwnerService.getById(boardCopyrightOwnerId);
                    if (copyrightOwner != null) {
                        exhibitionBoard.setBoardCopyrightOwnerName(copyrightOwner.getName());
                    }
liqin's avatar
liqin committed
628 629 630 631 632 633 634
                }
                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
635
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
636 637 638 639 640 641
                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
642
                assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
643 644 645 646 647 648
                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
649 650 651 652
                    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
653
                        assetQueryWrapper.eq(Asset::getPublished, true);
liqin's avatar
liqin committed
654 655 656 657 658
                        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
659 660 661 662
                }
            }
            learningContent.setExhibitionBoardList(exhibitionBoardList);
        }
liqin's avatar
liqin committed
663 664 665 666
        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
667
        return getResult(learningContent);
liqin's avatar
liqin committed
668 669
    }

liqin's avatar
liqin committed
670 671 672 673 674 675 676
    /**
     * 通用排序方法(拖拽排序/所有排序完成后点击保存)
     *
     * @param sourceId 源实体ID
     * @param targetId 目标实体ID
     * @return Void
     */
liqin's avatar
liqin committed
677 678
    @ApiOperation(value = "学习内容排序")
    @PutMapping(value = "/sort")
wzp's avatar
wzp committed
679
    @RequiresAuthentication  //@RequiresPermissions("learning:content:sort")
liqin's avatar
liqin committed
680
    public Map<String, Object> updateSortorder(String sourceId, String targetId) {
liqin's avatar
liqin committed
681 682
        LearningContent theSource = this.learningContentService.getById(sourceId);
        LearningContent theTarget = this.learningContentService.getById(targetId);
liqin's avatar
liqin committed
683
        String moveType = theSource.getSortorder() > theTarget.getSortorder() ? "down" : "up";
liqin's avatar
liqin committed
684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
        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
699 700
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
701 702 703 704 705 706 707 708 709 710 711 712 713
        }
        //默认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
714 715
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
716 717 718 719 720 721 722 723 724 725 726 727 728
        }
        //默认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
729 730
            theSource.setSortorder(targetSortorder);
            this.learningContentService.updateById(theSource);
liqin's avatar
liqin committed
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
        }
        //默认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
747
        return getSuccessResult();
liqin's avatar
liqin committed
748 749
    }

liqin's avatar
liqin committed
750 751 752
    @ApiOperation(value = "启用/禁用学习内容", notes = "启用/禁用学习内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path"),
liqin's avatar
liqin committed
753
            @ApiImplicitParam(name = "isPublish", value = "是否启用", dataType = "boolean", paramType = "query", allowableValues = "True, False")
liqin's avatar
liqin committed
754 755
    })
    @PutMapping("/enable/{id}")
wzp's avatar
wzp committed
756
    @RequiresAuthentication  //@RequiresPermissions("learning:content:enable")
wzp's avatar
wzp committed
757
    @MethodLog(operModule = OperModule.LEARNCONTENT, operType = OperType.ENABLE)
liqin's avatar
liqin committed
758
    public Map<String, Object> enableLearningContent(@PathVariable("id") String id, @RequestParam("isPublish") Boolean isPublish) {
liqin's avatar
liqin committed
759
        final TUser user = getcurUser();
liqin's avatar
liqin committed
760 761

        LearningContent learningContent = this.learningContentService.getById(id);
762 763 764 765 766 767 768 769 770 771 772

        //单位管理员只能禁用或启用所属机构及其子机构的学习内容
        List<String> curUserSubOrgIds = getCurUserSubOrgIds();
        if (!CollectionUtils.isEmpty(curUserSubOrgIds)){
            String organCode = learningContent.getOrganCode();
            boolean contains = curUserSubOrgIds.contains(organCode);
            if (!contains){
                return getFailResult("单位管理员只能禁用或启用所属机构及其子机构的学习内容");
            }
        }

liqin's avatar
liqin committed
773
        final Audit audit = Audit.builder()
liqin's avatar
liqin committed
774 775
                .content(learningContent.getName())
                .name(learningContent.getName())
liqin's avatar
liqin committed
776
                .refItemId(id)
wzp's avatar
wzp committed
777
                .userId(user.getId())
liqin's avatar
liqin committed
778
                .organId(user.getOrgId())
liqin's avatar
liqin committed
779 780
                .type(AuditTypeEnum.LEARNING_CONTENT.name())
                .operation(isPublish ? AuditOperationEnum.ENABLE.name() : AuditOperationEnum.DISABLE.name())
liqin's avatar
liqin committed
781 782
                .status(AuditStatusEnum.TBC.name())
                .level(AuditStatusEnum.TBC.name())
liqin's avatar
liqin committed
783
                .build();
liqin's avatar
liqin committed
784
        this.auditService.save(audit);
liqin's avatar
liqin committed
785
        this.learningContentService.updateById(LearningContent.builder().id(id).auditStatus(AuditStatusEnum.TBC.name()).build());
liqin's avatar
liqin committed
786 787 788
        return getSuccessResult();
    }

liqin's avatar
liqin committed
789 790
}