AuditServiceImpl.java 27.8 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
import java.util.Map;
wzp's avatar
wzp committed
26
import java.util.function.Consumer;
liqin's avatar
liqin committed
27
import java.util.stream.Collectors;
wzp's avatar
wzp committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

/**
 * <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
44 45 46
    @Resource
    private AssetMapper assetMapper;

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

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

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

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

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

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

    @Resource
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;

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

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

liqin's avatar
liqin committed
110
        return pageByType(ew, name, type, auditPage);
wzp's avatar
wzp committed
111
    }
112 113 114 115

    /**
     * 分别查询
     */
liqin's avatar
liqin committed
116
    private Page<Audit> pageByType(QueryWrapper<Audit> ew, String name, AuditTypeEnum type, Page<Audit> auditPage) {
117 118 119 120 121 122 123 124 125 126
        Page<Audit> selectPage = null;
        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
127
            case VIDEO_CONTENT:
liqin's avatar
liqin committed
128
                selectPage = auditMapper.getVideoContentPage(auditPage, ew);
129 130 131 132 133 134
            default:
        }
        //
        return selectPage;
    }

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    /**
     * 根据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
155 156 157 158 159 160 161 162 163 164
    @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
165
        return getOne(wrapper);
wzp's avatar
wzp committed
166 167
    }

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
    /**
     * 初审级别的修改情况
     */
    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("");
        }
183
        audit.setSecondRemarks("");
184 185
        //通过与不通过时 都修改
        boolean updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
186
        int update = auditMapper.updateById(audit);
187 188 189 190
        return updateRefItemByRefItemId && update >= 1;
        //初审驳回时,不做状态修改
//        int update = auditMapper.updateById(audit);
//        return update >= 1;
191 192 193 194 195 196 197 198 199 200 201 202
    }

    /**
     * 复审级别的修改情况
     */
    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("");
        }
203
        audit.setFirstRemarks("");
204
        //复审通过时,
205 206 207 208 209
//        boolean updateRefItemByRefItemId = true;
//        if (AuditStatusEnum.APPROVED_FINAL.equals(auditStatusEnum)) {
//            //修改对应审核项中的信息
//            updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
//        }
liqin's avatar
liqin committed
210

211 212
        //通过与不通过时 都修改
        boolean updateRefItemByRefItemId = updateRefItemByRefItemId(audit);
213 214 215 216 217 218 219 220 221 222 223 224
        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
225
            case VIDEO_CONTENT:
liqin's avatar
liqin committed
226
                update = fillVideoContentByAudit(audit);
227 228 229 230
                break;
//            case ACCOUNT:
//                break;
            case EXHIBITION_BOARD:
liqin's avatar
liqin committed
231
                update = fillExhibitionBoardByAudit(audit);
232 233
                break;
            case LEARNING_CONTENT:
liqin's avatar
liqin committed
234
                update = fillLearningContentByAudit(audit);
235 236 237 238 239 240 241 242
                break;
            default:
                throw new InterfaceException("type参数不正确");
        }
        return update;
    }

    /**
liqin's avatar
liqin committed
243
     * 根据审核操作 填充VideoContent属性用于更改
244
     */
liqin's avatar
liqin committed
245
    public boolean fillVideoContentByAudit(Audit audit) {
liqin's avatar
liqin committed
246
        final String videoContentId = audit.getRefItemId();
liqin's avatar
liqin committed
247
        VideoContent videoContent = new VideoContent();
liqin's avatar
liqin committed
248
        videoContent.setId(videoContentId);
liqin's avatar
liqin committed
249
        videoContent.setAuditStatus(audit.getStatus());
250
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
251
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
252
        if (!continueFill) {
liqin's avatar
liqin committed
253
            return this.videoContentService.updateById(videoContent);
254
        }
255 256
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
257
        boolean update = false;
258
        switch (auditOperationEnum) {
259
            case ENABLE:
liqin's avatar
liqin committed
260
                videoContent.setPublished(true);
liqin's avatar
liqin committed
261
                update = this.videoContentService.updateById(videoContent);
liqin's avatar
liqin committed
262
                break;
263
            case DISABLE:
liqin's avatar
liqin committed
264
                videoContent.setPublished(false);
liqin's avatar
liqin committed
265
                update = this.videoContentService.updateById(videoContent);
266 267
                break;
            case REMOVE:
liqin's avatar
liqin committed
268 269 270 271
                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
272
                    this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().in(Asset::getRefItemId, exhibitionBoardIdList));
liqin's avatar
liqin committed
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290

                    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
291
                this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().in(Asset::getRefItemId, videoContentId));
liqin's avatar
liqin committed
292
                update = this.videoContentService.removeById(videoContentId);
293
                break;
wzp's avatar
wzp committed
294
            case ADD:
liqin's avatar
liqin committed
295
                this.assetMapper.update(Asset.builder().published(true).build(), Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, videoContentId));
liqin's avatar
liqin committed
296
                videoContent.setPublished(true);
liqin's avatar
liqin committed
297
                update = this.videoContentService.updateById(videoContent);
wzp's avatar
wzp committed
298 299
                break;
            case EDIT:
liqin's avatar
liqin committed
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
                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);
                    }
liqin's avatar
liqin committed
322 323 324
                    if (!collect.isEmpty()) {
                        this.assetMapper.deleteBatchIds(collect.keySet());
                    }
liqin's avatar
liqin committed
325 326 327
                }
                one.setAuditStatus(audit.getStatus());
                update = this.videoContentService.updateById(one);
wzp's avatar
wzp committed
328
                break;
329 330
            default:
        }
liqin's avatar
liqin committed
331
        return update;
332 333 334 335 336
    }

    /**
     * 根据审核操作 填充ExhibitionBoard属性用于更改
     */
liqin's avatar
liqin committed
337
    public boolean fillExhibitionBoardByAudit(Audit audit) {
liqin's avatar
liqin committed
338
        final String exhibitionBoardId = audit.getRefItemId();
339
        ExhibitionBoard exhibitionBoard = new ExhibitionBoard();
liqin's avatar
liqin committed
340
        exhibitionBoard.setId(exhibitionBoardId);
341
        exhibitionBoard.setAuditStatus(audit.getStatus());
342
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
343
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
344
        if (!continueFill) {
liqin's avatar
liqin committed
345
            return this.exhibitionBoardService.updateById(exhibitionBoard);
346
        }
347 348
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
349
        boolean update = false;
350
        switch (auditOperationEnum) {
wzp's avatar
wzp committed
351
            case UPPER:
liqin's avatar
liqin committed
352
                exhibitionBoard.setPublished(true);
liqin's avatar
liqin committed
353
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
liqin's avatar
liqin committed
354
                break;
wzp's avatar
wzp committed
355
            case LOWER:
liqin's avatar
liqin committed
356
                exhibitionBoard.setPublished(false);
liqin's avatar
liqin committed
357
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
358 359
                break;
            case REMOVE:
liqin's avatar
liqin committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
                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
375
                this.assetMapper.delete(Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, exhibitionBoardId));
liqin's avatar
liqin committed
376
                update = this.exhibitionBoardService.removeById(exhibitionBoardId);
377
                break;
wzp's avatar
wzp committed
378
            case ADD:
liqin's avatar
liqin committed
379
                this.assetMapper.update(Asset.builder().published(true).build(), Wrappers.<Asset>lambdaUpdate().eq(Asset::getRefItemId, exhibitionBoardId));
liqin's avatar
liqin committed
380
                exhibitionBoard.setPublished(true);
liqin's avatar
liqin committed
381
                update = this.exhibitionBoardService.updateById(exhibitionBoard);
wzp's avatar
wzp committed
382 383
                break;
            case EDIT:
liqin's avatar
liqin committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
                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);
                    }
liqin's avatar
liqin committed
402 403 404
                    if (!collect.isEmpty()) {
                        this.assetMapper.deleteBatchIds(collect.keySet());
                    }
liqin's avatar
liqin committed
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
                }
                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);
                    }
liqin's avatar
liqin committed
421 422 423
                    if (!collect.isEmpty()) {
                        this.assetMapper.deleteBatchIds(collect.keySet());
                    }
liqin's avatar
liqin committed
424 425 426
                }
                one.setAuditStatus(audit.getStatus());
                update = this.exhibitionBoardService.updateById(one);
wzp's avatar
wzp committed
427
                break;
428 429
            default:
        }
liqin's avatar
liqin committed
430
        return update;
431 432 433 434 435
    }

    /**
     * 根据审核操作 填充LearningContent属性用于更改
     */
liqin's avatar
liqin committed
436
    public boolean fillLearningContentByAudit(Audit audit) {
liqin's avatar
liqin committed
437
        final String learningContentId = audit.getRefItemId();
438 439
        LearningContent learningContent = new LearningContent();
        learningContent.setAuditStatus(audit.getStatus());
liqin's avatar
liqin committed
440
        learningContent.setId(learningContentId);
441
        //当审核级别为复审,审核状态为通过是,会修改审核项其它表中的 发布与删除字段,不是此情况下是直接修改审核状态
liqin's avatar
liqin committed
442
        boolean continueFill = AuditStatusEnum.APPROVED_FINAL.name().equals(audit.getStatus()) && AuditStatusEnum.TBCA.name().equals(audit.getLevel());
443
        if (!continueFill) {
liqin's avatar
liqin committed
444
            return this.learningContentService.updateById(learningContent);
445
        }
446 447
        String operation = audit.getOperation();
        AuditOperationEnum auditOperationEnum = AuditOperationEnum.valueOf(operation);
liqin's avatar
liqin committed
448
        boolean update = false;
449
        switch (auditOperationEnum) {
450
            case ENABLE:
liqin's avatar
liqin committed
451
                learningContent.setPublished(true);
liqin's avatar
liqin committed
452
                update = this.learningContentService.updateById(learningContent);
liqin's avatar
liqin committed
453
                break;
454
            case DISABLE:
liqin's avatar
liqin committed
455
                learningContent.setPublished(false);
liqin's avatar
liqin committed
456
                update = this.learningContentService.updateById(learningContent);
457 458
                break;
            case REMOVE:
liqin's avatar
liqin committed
459 460 461
                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
462
                update = this.learningContentService.removeById(learningContentId);
463
                break;
wzp's avatar
wzp committed
464
            case ADD:
liqin's avatar
liqin committed
465
                learningContent.setPublished(true);
wzp's avatar
wzp committed
466
                update = this.learningContentService.updateById(learningContent);
wzp's avatar
wzp committed
467 468
                break;
            case EDIT:
liqin's avatar
liqin committed
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
                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());
                update = this.learningContentService.updateById(one);
wzp's avatar
wzp committed
507
                break;
508 509
            default:
        }
liqin's avatar
liqin committed
510
        return update;
511 512
    }

jiawei's avatar
jiawei committed
513 514 515 516 517 518 519 520 521
    /**
     * 根据审核项数据插入审核记录
     *
     * @param refItemId     审核项ID
     * @param content       审核内容
     * @param typeEnum      审核类型
     * @param operationEnum 操作类型
     */
    @Override
liqin's avatar
liqin committed
522
    public boolean saveByRefItemInfo(String refItemId, String content, AuditTypeEnum typeEnum, AuditOperationEnum operationEnum) {
jiawei's avatar
jiawei committed
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
        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
546

wzp's avatar
wzp committed
547
}