AuditServiceImpl.java 27.1 KB
Newer Older
liqin's avatar
liqin committed
1
package cn.chnmuseum.party.service.impl;
wzp's avatar
wzp committed
2

liqin's avatar
liqin committed
3
import cn.chnmuseum.party.common.enums.*;
liqin's avatar
liqin committed
4 5 6 7 8
import cn.chnmuseum.party.common.mvc.InterfaceException;
import cn.chnmuseum.party.mapper.AssetMapper;
import cn.chnmuseum.party.mapper.AuditMapper;
import cn.chnmuseum.party.model.*;
import cn.chnmuseum.party.service.*;
liqin's avatar
liqin committed
9
import com.alibaba.fastjson.JSONObject;
liqin's avatar
liqin committed
10
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
11
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
liqin's avatar
liqin committed
12
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
wzp's avatar
wzp committed
13
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
liqin's avatar
liqin committed
14
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
wzp's avatar
wzp committed
15 16 17
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
18
import org.apache.commons.lang3.StringUtils;
jiawei's avatar
jiawei committed
19
import org.apache.shiro.SecurityUtils;
20
import org.springframework.stereotype.Service;
wzp's avatar
wzp committed
21 22

import javax.annotation.Resource;
23
import java.time.LocalDateTime;
liqin's avatar
liqin committed
24
import java.util.List;
liqin's avatar
liqin committed
25 26
import java.util.Map;
import java.util.stream.Collectors;
wzp's avatar
wzp committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

/**
 * <pre>
 * 学习内容信息 服务实现类
 * </pre>
 *
 * @author Danny Lee
 * @since 2021-03-26
 */
@Slf4j
@Service
public class AuditServiceImpl extends ServiceImpl<AuditMapper, Audit> implements AuditService {

    @Resource
    private AuditMapper auditMapper;

liqin's avatar
liqin committed
43 44 45
    @Resource
    private AssetMapper assetMapper;

liqin's avatar
liqin committed
46
    @Resource
47 48
    private TUserServiceImpl userService;

liqin's avatar
liqin committed
49 50
    @Resource
    private VideoContentService videoContentService;
51

liqin's avatar
liqin committed
52 53
    @Resource
    private ExhibitionBoardService exhibitionBoardService;
54

liqin's avatar
liqin committed
55 56
    @Resource
    private LearningContentService learningContentService;
57

liqin's avatar
liqin committed
58 59 60
    @Resource
    private LearningContentBoardService learningContentBoardService;

liqin's avatar
liqin committed
61 62 63 64 65 66
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;

    @Resource
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;

wzp's avatar
wzp committed
67
    @Override
wzp's avatar
wzp committed
68
    public Page<Audit> getUserList(Page<Audit> page, TUser user) {
69 70 71 72 73 74 75
        return page.setRecords(auditMapper.getUserList(page, user));
    }

    /**
     * 分页查询
     */
    @Override
76
    public Page<Audit> pageList(String name, AuditStatusEnum status, AuditStatusEnum auditStatusLevel, AuditTypeEnum type, Page<Object> page) {
77 78 79 80 81 82
        //分页
        Page<Audit> auditPage = new Page<>();
        auditPage.setCurrent(page.getCurrent());
        auditPage.setSize(page.getSize());
        //条件
        QueryWrapper<Audit> ew = new QueryWrapper<Audit>()
wzp's avatar
wzp committed
83 84
                //暂时注掉
//                .eq("a.level", auditStatusLevel.name())
85
                .eq("a.type", type.name())
86 87
//                .eq("b.is_deleted", 0)
//                .eq("c.is_deleted", 0)
88 89 90 91 92
                .orderByDesc("a.create_time", "a.id");
        //
        if (status != null) {
            ew.eq(status != null, "a.status", status.name());
        }
liqin's avatar
liqin committed
93
        return pageByType(ew, name, type, auditPage);
wzp's avatar
wzp committed
94
    }
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

    /**
     * 分别查询
     */
    private Page<Audit> pageByType(QueryWrapper<Audit> ew, String name,
                                   AuditTypeEnum type, Page<Audit> auditPage) {
        Page<Audit> selectPage = null;
        if (StringUtils.isNotBlank(name)) {
            ew.and(i -> i.like("b.name", name).or().like("c.user_name", name));
        }
        switch (type) {
            case LEARNING_CONTENT:
                selectPage = auditMapper.getLearningContentPage(auditPage, ew);
                break;
            case EXHIBITION_BOARD:
                selectPage = auditMapper.getExhibitionBoardPage(auditPage, ew);
                break;
            case ACCOUNT:
                break;
liqin's avatar
liqin committed
114
            case VIDEO_CONTENT:
liqin's avatar
liqin committed
115
                selectPage = auditMapper.getVideoContentPage(auditPage, ew);
116 117 118 119 120 121
            default:
        }
        //
        return selectPage;
    }

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    /**
     * 根据id更新审核信息
     */
    @Override
    public boolean updateAuditAllById(Audit audit) {
        //审核层级,初审 和 复审
        AuditStatusEnum auditStatusLevel = AuditStatusEnum.valueOf(audit.getLevel());
        boolean update;
        switch (auditStatusLevel) {
            case TBC:
                update = updateOnTBC(audit);
                return update;
            case TBCA:
                update = updateOnTBCA(audit);
                return update;
            default:
                throw new InterfaceException("level参数不正确");
        }
    }

wzp's avatar
wzp committed
142 143 144 145 146 147 148 149 150 151
    @Override
    public Audit selectOne(String id, String type) {
        UpdateWrapper<Audit> wrapper = new UpdateWrapper<>();
        if (StringUtils.isNotBlank(id)) {
            wrapper.eq("ref_item_id", id);
        }
        if (StringUtils.isNotBlank(type)) {
            wrapper.eq("type", type);
        }
        wrapper.orderByDesc("create_time").last("limit 1");
liqin's avatar
liqin committed
152
        return getOne(wrapper);
wzp's avatar
wzp committed
153 154
    }

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
    /**
     * 初审级别的修改情况
     */
    private boolean updateOnTBC(Audit audit) {
        audit.setFirstTime(LocalDateTime.now());
        String status = audit.getStatus();
        AuditStatusEnum auditStatusEnum = AuditStatusEnum.valueOf(status);
        //初审 通过时,修改状态为待复审
        if (AuditStatusEnum.APPROVED_FINAL.equals(auditStatusEnum)) {
            audit.setStatus(AuditStatusEnum.TBCA.name());
            audit.setLevel(AuditStatusEnum.TBCA.name());
        }
        if (!AuditStatusEnum.REFUSED.equals(auditStatusEnum)) {
            audit.setFirstRemarks("");
        }
170
        audit.setSecondRemarks("");
171 172
        //通过与不通过时 都修改
        boolean updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
173
        int update = auditMapper.updateById(audit);
174 175 176 177
        return updateRefItemByRefItemId && update >= 1;
        //初审驳回时,不做状态修改
//        int update = auditMapper.updateById(audit);
//        return update >= 1;
178 179 180 181 182 183 184 185 186 187 188 189
    }

    /**
     * 复审级别的修改情况
     */
    private boolean updateOnTBCA(Audit audit) {
        audit.setSecondTime(LocalDateTime.now());
        String status = audit.getStatus();
        AuditStatusEnum auditStatusEnum = AuditStatusEnum.valueOf(status);
        if (!AuditStatusEnum.REFUSED.equals(auditStatusEnum)) {
            audit.setSecondRemarks("");
        }
190
        audit.setFirstRemarks("");
191
        //复审通过时,
192 193 194 195 196
//        boolean updateRefItemByRefItemId = true;
//        if (AuditStatusEnum.APPROVED_FINAL.equals(auditStatusEnum)) {
//            //修改对应审核项中的信息
//            updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
//        }
liqin's avatar
liqin committed
197

198 199
        //通过与不通过时 都修改
        boolean updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
200 201 202 203 204 205 206 207 208 209 210 211
        int update = auditMapper.updateById(audit);
        return updateRefItemByRefItemId && update >= 1;
    }

    /**
     * 根据审核项ID 修改 审核项表中的信息
     */
    private boolean updateRefItemByRefItemId(Audit audit) {
        String type = audit.getType();
        AuditTypeEnum auditTypeEnum = AuditTypeEnum.valueOf(type);
        boolean update;
        switch (auditTypeEnum) {
liqin's avatar
liqin committed
212
            case VIDEO_CONTENT:
liqin's avatar
liqin committed
213
                update = fillVideoContentByAudit(audit);
214 215 216 217
                break;
//            case ACCOUNT:
//                break;
            case EXHIBITION_BOARD:
liqin's avatar
liqin committed
218
                update = fillExhibitionBoardByAudit(audit);
219 220
                break;
            case LEARNING_CONTENT:
liqin's avatar
liqin committed
221
                update = fillLearningContentByAudit(audit);
222 223 224 225 226 227 228 229
                break;
            default:
                throw new InterfaceException("type参数不正确");
        }
        return update;
    }

    /**
liqin's avatar
liqin committed
230
     * 根据审核操作 填充VideoContent属性用于更改
231
     */
liqin's avatar
liqin committed
232
    public boolean fillVideoContentByAudit(Audit audit) {
liqin's avatar
liqin committed
233
        final String videoContentId = audit.getRefItemId();
liqin's avatar
liqin committed
234
        VideoContent videoContent = new VideoContent();
liqin's avatar
liqin committed
235
        videoContent.setId(videoContentId);
liqin's avatar
liqin committed
236
        videoContent.setAuditStatus(audit.getStatus());
237
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
238
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
239
        if (!continueFill) {
liqin's avatar
liqin committed
240
            return this.videoContentService.updateById(videoContent);
241
        }
242 243
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
244
        boolean update = false;
245
        switch (auditOperationEnum) {
246
            case ENABLE:
liqin's avatar
liqin committed
247
                videoContent.setPublished(true);
liqin's avatar
liqin committed
248
                update = this.videoContentService.updateById(videoContent);
liqin's avatar
liqin committed
249
                break;
250
            case DISABLE:
liqin's avatar
liqin committed
251
                videoContent.setPublished(false);
liqin's avatar
liqin committed
252
                update = this.videoContentService.updateById(videoContent);
253 254
                break;
            case REMOVE:
liqin's avatar
liqin committed
255 256 257 258
                final LambdaQueryWrapper<ExhibitionBoard> queryWrapper = Wrappers.<ExhibitionBoard>lambdaQuery().eq(ExhibitionBoard::getVideoContentId, videoContentId).select(ExhibitionBoard::getId);
                final List<String> exhibitionBoardIdList = this.exhibitionBoardService.listObjs(queryWrapper, Object::toString);
                if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
                    this.exhibitionBoardService.removeByIds(exhibitionBoardIdList);
liqin's avatar
liqin committed
259
                    this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().in(Asset::getRefItemId, exhibitionBoardIdList));
liqin's avatar
liqin committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277

                    final LambdaQueryWrapper<LearningContentBoard> learningContentBoardLambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery().in(LearningContentBoard::getExhibitionBoardCatId, exhibitionBoardIdList);
                    final List<LearningContentBoard> learningContentBoardList = this.learningContentBoardService.list(learningContentBoardLambdaQueryWrapper);
                    if (learningContentBoardList != null && !learningContentBoardList.isEmpty()) {
                        final Map<String, List<String>> collect = learningContentBoardList.stream().collect(Collectors.groupingBy(LearningContentBoard::getLearningContentId, Collectors.mapping(LearningContentBoard::getExhibitionBoardId, Collectors.toList())));
                        collect.forEach((k, v) -> {
                            if (v.size() == 1) {
                                this.learningContentService.removeById(k);
                                this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, k));
                                this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, k));
                                this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, k));
                            }
                        });

                        LambdaUpdateWrapper<LearningContentBoard> deleteWrapper1 = Wrappers.<LearningContentBoard>lambdaUpdate().in(LearningContentBoard::getExhibitionBoardId, exhibitionBoardIdList);
                        this.learningContentBoardService.remove(deleteWrapper1);
                    }
                }
liqin's avatar
liqin committed
278
                this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().in(Asset::getRefItemId, videoContentId));
liqin's avatar
liqin committed
279
                update = this.videoContentService.removeById(videoContentId);
280
                break;
wzp's avatar
wzp committed
281
            case ADD:
liqin's avatar
liqin committed
282
                this.assetMapper.update(Asset.builder().published(true).build(), Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, videoContentId));
liqin's avatar
liqin committed
283
                videoContent.setPublished(true);
liqin's avatar
liqin committed
284
                update = this.videoContentService.updateById(videoContent);
wzp's avatar
wzp committed
285 286
                break;
            case EDIT:
liqin's avatar
liqin committed
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
                final String data = this.auditMapper.selectById(audit.getId()).getModelData();
                final VideoContent one = JSONObject.parseObject(data, VideoContent.class);
                final List<String> videoFileIdList = one.getVideoFileIdList();
                if (videoFileIdList != null && !videoFileIdList.isEmpty()) {
                    final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, videoContentId);
                    assetQueryWrapper.eq(Asset::getPublished, true);
                    final List<Asset> assetList = this.assetMapper.selectList(assetQueryWrapper);
                    final Map<String, String> collect = assetList.stream().collect(Collectors.toMap(Asset::getId, Asset::getFileUrl));
                    for (String videoFileId : videoFileIdList) {
                        final Asset asset = this.assetMapper.selectById(videoFileId);
                        asset.setThumbnail(videoContent.getThumbnail());
                        asset.setFileType(FileTypeEnum.VIDEO.name());
                        asset.setFileCat(FileCatEnum.VIDEO_CONTENT.name());
                        asset.setRefItemId(videoContentId);
                        asset.setPublished(true);
                        this.assetMapper.updateById(asset);
                        if (StringUtils.isBlank(videoContent.getName())) {
                            videoContent.setName(asset.getVideoContentName());
                            this.videoContentService.updateById(videoContent);
                        }
                        collect.remove(videoFileId);
                    }
                    this.assetMapper.deleteBatchIds(collect.keySet());
                }
                one.setAuditStatus(audit.getStatus());
                one.setPublished(true);
                update = this.videoContentService.updateById(one);
wzp's avatar
wzp committed
314
                break;
315 316
            default:
        }
liqin's avatar
liqin committed
317
        return update;
318 319 320 321 322
    }

    /**
     * 根据审核操作 填充ExhibitionBoard属性用于更改
     */
liqin's avatar
liqin committed
323
    public boolean fillExhibitionBoardByAudit(Audit audit) {
liqin's avatar
liqin committed
324
        final String exhibitionBoardId = audit.getRefItemId();
325
        ExhibitionBoard exhibitionBoard = new ExhibitionBoard();
liqin's avatar
liqin committed
326
        exhibitionBoard.setId(exhibitionBoardId);
327
        exhibitionBoard.setAuditStatus(audit.getStatus());
328
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
329
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
330
        if (!continueFill) {
liqin's avatar
liqin committed
331
            return this.exhibitionBoardService.updateById(exhibitionBoard);
332
        }
333 334
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
335
        boolean update = false;
336
        switch (auditOperationEnum) {
wzp's avatar
wzp committed
337
            case UPPER:
liqin's avatar
liqin committed
338
                exhibitionBoard.setPublished(true);
liqin's avatar
liqin committed
339
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
liqin's avatar
liqin committed
340
                break;
wzp's avatar
wzp committed
341
            case LOWER:
liqin's avatar
liqin committed
342
                exhibitionBoard.setPublished(false);
liqin's avatar
liqin committed
343
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
344 345
                break;
            case REMOVE:
liqin's avatar
liqin committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
                final LambdaQueryWrapper<LearningContentBoard> learningContentBoardLambdaQueryWrapper = Wrappers.<LearningContentBoard>lambdaQuery().eq(LearningContentBoard::getExhibitionBoardCatId, exhibitionBoardId);
                final List<LearningContentBoard> learningContentBoardList = this.learningContentBoardService.list(learningContentBoardLambdaQueryWrapper);
                if (learningContentBoardList != null && !learningContentBoardList.isEmpty()) {
                    final Map<String, List<String>> collect = learningContentBoardList.stream().collect(Collectors.groupingBy(LearningContentBoard::getLearningContentId, Collectors.mapping(LearningContentBoard::getExhibitionBoardId, Collectors.toList())));
                    collect.forEach((k, v) -> {
                        if (v.size() == 1) {
                            this.learningContentService.removeById(k);
                            this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, k));
                            this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, k));
                            this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, k));
                        }
                    });
                    LambdaUpdateWrapper<LearningContentBoard> learningContentBoardLambdaUpdateWrapper = Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getExhibitionBoardId, exhibitionBoardId);
                    this.learningContentBoardService.remove(learningContentBoardLambdaUpdateWrapper);
                }
liqin's avatar
liqin committed
361
                this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, exhibitionBoardId));
liqin's avatar
liqin committed
362
                update = this.exhibitionBoardService.removeById(exhibitionBoardId);
363
                break;
wzp's avatar
wzp committed
364
            case ADD:
liqin's avatar
liqin committed
365
                this.assetMapper.update(Asset.builder().published(true).build(), Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, exhibitionBoardId));
liqin's avatar
liqin committed
366
                exhibitionBoard.setPublished(true);
liqin's avatar
liqin committed
367
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
wzp's avatar
wzp committed
368 369
                break;
            case EDIT:
liqin's avatar
liqin committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
                final String data = this.auditMapper.selectById(audit.getId()).getModelData();
                final ExhibitionBoard one = JSONObject.parseObject(data, ExhibitionBoard.class);
                final List<String> audioIdList = one.getAudioIdList();
                if (audioIdList != null && !audioIdList.isEmpty()) {
                    final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoardId);
                    assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
                    assetQueryWrapper.eq(Asset::getPublished, true);
                    final List<Asset> assetList = this.assetMapper.selectList(assetQueryWrapper);
                    final Map<String, String> collect = assetList.stream().collect(Collectors.toMap(Asset::getId, Asset::getFileUrl));
                    for (String audioId : audioIdList) {
                        final Asset asset = this.assetMapper.selectById(audioId);
                        asset.setFileType(FileTypeEnum.AUDIO.name());
                        asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_AUDIO.name());
                        asset.setRefItemId(exhibitionBoardId);
                        asset.setPublished(true);
                        this.assetMapper.updateById(asset);
                        collect.remove(audioId);
                    }
                    this.assetMapper.deleteBatchIds(collect.keySet());
                }
                final List<String> datumIdList = one.getDatumIdList();
                if (datumIdList != null && !datumIdList.isEmpty()) {
                    final LambdaQueryWrapper<Asset> assetQueryWrapper = Wrappers.<Asset>lambdaQuery().eq(Asset::getRefItemId, exhibitionBoardId);
                    assetQueryWrapper.eq(Asset::getFileCat, FileCatEnum.EXHIBITION_BOARD_DATUM.name());
                    assetQueryWrapper.eq(Asset::getPublished, true);
                    final List<Asset> assetList = this.assetMapper.selectList(assetQueryWrapper);
                    final Map<String, String> collect = assetList.stream().collect(Collectors.toMap(Asset::getId, Asset::getFileUrl));
                    for (String datumId : datumIdList) {
                        final Asset asset = this.assetMapper.selectById(datumId);
                        asset.setFileCat(FileCatEnum.EXHIBITION_BOARD_DATUM.name());
                        asset.setRefItemId(exhibitionBoardId);
                        asset.setPublished(true);
                        this.assetMapper.updateById(asset);
                        collect.remove(datumId);
                    }
                    this.assetMapper.deleteBatchIds(collect.keySet());
                }
                one.setAuditStatus(audit.getStatus());
                one.setPublished(true);
                update = this.exhibitionBoardService.updateById(one);
wzp's avatar
wzp committed
410
                break;
411 412
            default:
        }
liqin's avatar
liqin committed
413
        return update;
414 415 416 417 418
    }

    /**
     * 根据审核操作 填充LearningContent属性用于更改
     */
liqin's avatar
liqin committed
419
    public boolean fillLearningContentByAudit(Audit audit) {
liqin's avatar
liqin committed
420
        final String learningContentId = audit.getRefItemId();
421 422
        LearningContent learningContent = new LearningContent();
        learningContent.setAuditStatus(audit.getStatus());
liqin's avatar
liqin committed
423
        learningContent.setId(learningContentId);
424
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
425
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
426
        if (!continueFill) {
liqin's avatar
liqin committed
427
            return this.learningContentService.updateById(learningContent);
428
        }
429 430
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
431
        boolean update = false;
432
        switch (auditOperationEnum) {
433
            case ENABLE:
liqin's avatar
liqin committed
434
                learningContent.setPublished(true);
liqin's avatar
liqin committed
435
                update = this.learningContentService.updateById(learningContent);
liqin's avatar
liqin committed
436
                break;
437
            case DISABLE:
liqin's avatar
liqin committed
438
                learningContent.setPublished(false);
liqin's avatar
liqin committed
439
                update = this.learningContentService.updateById(learningContent);
440 441
                break;
            case REMOVE:
liqin's avatar
liqin committed
442 443 444
                this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, learningContentId));
                this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, learningContentId));
                this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, learningContentId));
liqin's avatar
liqin committed
445
                update = this.learningContentService.removeById(learningContentId);
446
                break;
wzp's avatar
wzp committed
447
            case ADD:
liqin's avatar
liqin committed
448
                learningContent.setPublished(true);
wzp's avatar
wzp committed
449
                update = this.learningContentService.updateById(learningContent);
wzp's avatar
wzp committed
450 451
                break;
            case EDIT:
liqin's avatar
liqin committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
                final String data = this.auditMapper.selectById(audit.getId()).getModelData();
                final LearningContent one = JSONObject.parseObject(data, LearningContent.class);
                final List<String> exhibitionBoardCatIdList = one.getExhibitionBoardCatIdList();
                if (exhibitionBoardCatIdList != null && !exhibitionBoardCatIdList.isEmpty()) {
                    LambdaUpdateWrapper<LearningContentBoardCat> lambdaUpdateWrapper = Wrappers.<LearningContentBoardCat>lambdaUpdate().eq(LearningContentBoardCat::getLearningContentId, learningContentId);
                    this.learningContentBoardCatService.remove(lambdaUpdateWrapper);

                    for (String exhibitionBoardCatId : exhibitionBoardCatIdList) {
                        LearningContentBoardCat learningContentBoardCat = LearningContentBoardCat.builder().exhibitionBoardCatId(exhibitionBoardCatId).learningContentId(learningContentId).build();
                        this.learningContentBoardCatService.save(learningContentBoardCat);
                    }
                }
                final List<String> copyrightOwnerIdList = one.getCopyrightOwnerIdList();
                if (copyrightOwnerIdList != null && !copyrightOwnerIdList.isEmpty()) {
                    LambdaUpdateWrapper<LearningContentCopyrightOwner> lambdaUpdateWrapper = Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().eq(LearningContentCopyrightOwner::getLearningContentId, learningContentId);
                    this.learningContentCopyrightOwnerService.remove(lambdaUpdateWrapper);

                    for (String copyrightOwnerId : copyrightOwnerIdList) {
                        LearningContentCopyrightOwner contentCopyrightOwner = LearningContentCopyrightOwner.builder().copyrightOwnerId(copyrightOwnerId).learningContentId(learningContentId).build();
                        this.learningContentCopyrightOwnerService.save(contentCopyrightOwner);
                    }
                }
                final List<String> exhibitionBoardIdList = one.getExhibitionBoardIdList();
                if (exhibitionBoardIdList != null && !exhibitionBoardIdList.isEmpty()) {
                    LambdaUpdateWrapper<LearningContentBoard> lambdaUpdateWrapper = Wrappers.<LearningContentBoard>lambdaUpdate().eq(LearningContentBoard::getLearningContentId, learningContentId);
                    this.learningContentBoardService.remove(lambdaUpdateWrapper);

                    for (String exhibitionBoardId : exhibitionBoardIdList) {
                        LearningContentBoard learningContentBoard = LearningContentBoard.builder()
                                .learningContentId(learningContentId)
                                .exhibitionBoardCatId(this.exhibitionBoardService.getById(exhibitionBoardId).getExhibitionBoardCatId())
                                .exhibitionBoardId(exhibitionBoardId)
                                .build();
                        this.learningContentBoardService.save(learningContentBoard);
                    }
                }
                one.setAuditStatus(audit.getStatus());
                one.setPublished(true);
                update = this.learningContentService.updateById(one);
wzp's avatar
wzp committed
491
                break;
492 493
            default:
        }
liqin's avatar
liqin committed
494
        return update;
495 496
    }

jiawei's avatar
jiawei committed
497 498 499 500 501 502 503 504 505
    /**
     * 根据审核项数据插入审核记录
     *
     * @param refItemId     审核项ID
     * @param content       审核内容
     * @param typeEnum      审核类型
     * @param operationEnum 操作类型
     */
    @Override
liqin's avatar
liqin committed
506
    public boolean saveByRefItemInfo(String refItemId, String content, AuditTypeEnum typeEnum, AuditOperationEnum operationEnum) {
jiawei's avatar
jiawei committed
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
        Audit audit = new Audit();
        //
        audit.setRefItemId(refItemId);
        audit.setContent(content);
        audit.setType(typeEnum.name());
        audit.setOperation(operationEnum.name());
        //
        audit.setLevel(AuditStatusEnum.TBC.name());
        audit.setStatus(AuditStatusEnum.TBC.name());
        audit.setCreateTime(LocalDateTime.now());
        //
        Object principal = SecurityUtils.getSubject().getPrincipal();
        if (principal instanceof TUser) {
            TUser user = (TUser) principal;
            audit.setUserId(user.getId());
            audit.setUserName(user.getUserName());
            audit.setOrganId(user.getOrgId());
            audit.setOrgName(user.getOrgName());
        }
        //保存
        int insert = auditMapper.insert(audit);
        return insert >= 1;
    }
liqin's avatar
liqin committed
530

wzp's avatar
wzp committed
531
}