LearningProjectController.java 20 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
import cn.chnmuseum.party.common.log.MethodLog;
import cn.chnmuseum.party.common.log.OperModule;
import cn.chnmuseum.party.common.log.OperType;
nie'hong's avatar
nie'hong committed
6
import cn.chnmuseum.party.common.util.ListUtil;
7
import cn.chnmuseum.party.common.util.TimeUtils;
liqin's avatar
liqin committed
8 9 10
import cn.chnmuseum.party.common.validator.groups.Add;
import cn.chnmuseum.party.common.validator.groups.Update;
import cn.chnmuseum.party.common.vo.GenericPageParam;
11 12
import cn.chnmuseum.party.model.*;
import cn.chnmuseum.party.service.*;
liqin's avatar
liqin committed
13
import cn.chnmuseum.party.web.controller.base.BaseController;
14
import cn.hutool.core.collection.CollectionUtil;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
16
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
liqin's avatar
liqin committed
17 18 19 20 21 22 23
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
24
import org.apache.shiro.authz.annotation.RequiresAuthentication;
nie'hong's avatar
nie'hong committed
25
import org.hibernate.validator.constraints.Length;
26
import org.springframework.beans.factory.annotation.Autowired;
27 28
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
liqin's avatar
liqin committed
29 30 31 32
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
nie'hong's avatar
nie'hong committed
33
import javax.validation.constraints.NotBlank;
34
import java.util.ArrayList;
liqin's avatar
liqin committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
import java.util.List;
import java.util.Map;

/**
 * <pre>
 *  前端控制器
 * </pre>
 *
 * @author Danny Lee
 * @since 2021-03-26
 */
@Slf4j
@RestController
@RequestMapping("/learningProject")
@Api(tags = {"学习项目操作接口"})
public class LearningProjectController extends BaseController {

    @Resource
    private LearningProjectService learningProjectService;
liqin's avatar
liqin committed
54 55
    @Resource
    private LearningContentService learningContentService;
56 57
    @Autowired
    private LearningContentController learningContentController;
58 59 60 61 62 63
    @Resource
    private LearningContentBoardService learningContentBoardService;
    @Resource
    private LearningContentBoardCatService learningContentBoardCatService;
    @Resource
    private LearningContentCopyrightOwnerService learningContentCopyrightOwnerService;
64 65 66 67 68 69 70
    @Resource
    private CopyrightOwnerService copyrightOwnerService;
    @Resource
    private ExhibitionBoardCatService exhibitionBoardCatService;
    @Resource
    private ExhibitionBoardService exhibitionBoardService;

liqin's avatar
liqin committed
71 72

    @PostMapping("/save")
wzp's avatar
wzp committed
73
    @RequiresAuthentication  //@RequiresPermissions("learning:project:save")
liqin's avatar
liqin committed
74
    @ApiOperation(value = "添加", notes = "添加")
wzp's avatar
wzp committed
75
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.ADD)
76
    @Transactional
liqin's avatar
liqin committed
77
    public Map<String, Object> saveLearningProject(@Validated(value = {Add.class}) LearningProject learningProject) {
nie'hong's avatar
nie'hong committed
78 79 80 81 82 83
        LambdaQueryWrapper<LearningProject> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(LearningProject::getName, learningProject.getName());
        LearningProject one = learningProjectService.getOne(lambdaQuery);
        if (one != null) {
            return getFailResult("学习项目名称已存在!");
        }
liqin's avatar
liqin committed
84 85
        // 保存业务节点信息
        boolean result = learningProjectService.save(learningProject);
86 87 88
        if (!result) {
            return getFailResult();
        }
89

90
        // 该学习项目下的主学习内容
91 92 93 94 95 96 97 98 99 100
        LearningContent majorLearningContent = LearningContent.builder()
                .learningProjectId(learningProject.getId())
                .applicableScope("ALL_PLAT")
                .name(learningProject.getMajor())
                .cover(learningProject.getCover())
                .exhibitionBoardCatIdList(learningProject.getExhibitionBoardCatIdList())
                .copyrightOwnerIdList(learningProject.getCopyrightOwnerIdList())
                .exhibitionBoardIdList(learningProject.getExhibitionBoardIdList())
                .build();

101 102 103 104
        Map<String, Object> resultMap = learningContentController.saveLearningContent(majorLearningContent, true);
        if (!resultMap.get("resultCode").equals("200")) {
            return getFailResult();
        }
liqin's avatar
liqin committed
105 106 107 108 109 110 111 112 113 114
        // 返回操作结果
        if (result) {
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
115
    @RequiresAuthentication  //@RequiresPermissions("learning:project:update")
liqin's avatar
liqin committed
116
    @ApiOperation(value = "修改信息", notes = "修改信息")
wzp's avatar
wzp committed
117
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.UPDATE)
118
    @Transactional
liqin's avatar
liqin committed
119
    public Map<String, Object> updateLearningProject(@Validated(value = {Update.class}) LearningProject learningProject) {
nie'hong's avatar
nie'hong committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        // 是否重名
        LambdaQueryWrapper<LearningProject> lambdaQuery1 = Wrappers.<LearningProject>lambdaQuery();
        lambdaQuery1.eq(LearningProject::getName, learningProject.getName()).ne(LearningProject::getId, learningProject.getId());
        LearningProject one1 = learningProjectService.getOne(lambdaQuery1);
        if (one1 != null) {
            return getFailResult("学习项目名已存在!");
        }

        StringBuilder resultMsg = new StringBuilder();
        // 查询学习项目原有信息
        LearningProject project = learningProjectService.getById(learningProject.getId());
        // 项目基本信息被修改
        if (!project.getName().equals(learningProject.getName()) || !project.getRemarks().equals(learningProject.getRemarks())) {
            boolean flag = learningProjectService.updateById(learningProject);
            if (!flag) {
                return getFailResult();
            }
            resultMsg.append("项目信息修改成功,");
nie'hong's avatar
nie'hong committed
138
        } else {
nie'hong's avatar
nie'hong committed
139
            resultMsg.append("未修改项目信息,");
140
        }
nie'hong's avatar
nie'hong committed
141

142
        // 查询项目的主学习内容
143
        LambdaQueryWrapper<LearningContent> queryWrapper = Wrappers.lambdaQuery();
144 145
        queryWrapper.eq(LearningContent::getLearningProjectId, learningProject.getId());
        queryWrapper.eq(LearningContent::getIsMajor, true);
nie'hong's avatar
nie'hong committed
146 147 148
        LearningContent content = this.learningContentService.getOne(queryWrapper);
        Map<String, Object> map = this.learningContentController.getById(content.getId());
        LearningContent one = (LearningContent) map.get("data");
149 150
        if (one == null) {
            return getFailResult("该学习项目下没有主学习内容");
liqin's avatar
liqin committed
151
        }
nie'hong's avatar
nie'hong committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        // 判断是否修改主学习内容
        String learningProjectMajorName = learningProject.getMajor();
        String cover = learningProject.getCover();
        List<String> copyrightOwnerIdList = learningProject.getCopyrightOwnerIdList();
        List<String> exhibitionBoardCatIdList = learningProject.getExhibitionBoardCatIdList();
        List<String> exhibitionBoardIdList = learningProject.getExhibitionBoardIdList();
        if (one.getName().equals(learningProjectMajorName)
                && one.getCover().equals(cover)
                && ListUtil.compareValue(copyrightOwnerIdList, one.getCopyrightOwnerIdList())
                && ListUtil.compareValue(exhibitionBoardCatIdList, one.getExhibitionBoardCatIdList())
                && ListUtil.compareValue(exhibitionBoardIdList, one.getExhibitionBoardIdList())) {
            resultMsg.append("未修改项目主学习内容信息。");
            return getSuccessResult(resultMsg.toString());
        }

167
        // 查询该学习项目的子学习内容版权方、展板分类、展板
168
        LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.lambdaQuery();
169
        lambdaQueryWrapper.eq(LearningContent::getLearningProjectId, learningProject.getId());
nie'hong's avatar
nie'hong committed
170
        lambdaQueryWrapper.eq(LearningContent::getIsMajor, false);
171 172 173 174
        lambdaQueryWrapper.select(LearningContent::getId);
        List<String> list = this.learningContentService.listObjs(lambdaQueryWrapper, Object::toString);
        if (CollectionUtil.isNotEmpty(list)) {
            // 查询子学习内容的版权方
175
            LambdaQueryWrapper<LearningContentCopyrightOwner> query = Wrappers.lambdaQuery();
176 177 178 179 180 181 182 183 184
            query.in(LearningContentCopyrightOwner::getLearningContentId, list);
            query.select(LearningContentCopyrightOwner::getCopyrightOwnerId);
            List<String> list1 = this.learningContentCopyrightOwnerService.listObjs(query, Object::toString);
            // 修改主内容的版权信息中删除了子学习内容的版权信息
            if (CollectionUtil.isNotEmpty(list1) && !learningProject.getCopyrightOwnerIdList().containsAll(list1)) {
                list1.removeAll(learningProject.getCopyrightOwnerIdList());
                // 查询子学习内容中被删除的版权方信息
                List<CopyrightOwner> copyrightOwners = this.copyrightOwnerService.listByIds(list1);
                StringBuilder stringBuilder = new StringBuilder();
185 186 187 188
                copyrightOwners.forEach(s -> {
                    stringBuilder.append(s.getName());
                    if (copyrightOwners.get(copyrightOwners.size() - 1).equals(s)) {
                        stringBuilder.append(",");
nie'hong's avatar
nie'hong committed
189
                    } else {
190 191 192 193
                        stringBuilder.append("、");
                    }
                });
                return getFailResult("展板版权方:" + stringBuilder + "被子学习内容使用,不能被删除,更新失败!");
194 195 196
            }

            // 查询子学习内容的展板分类
197
            LambdaQueryWrapper<LearningContentBoardCat> query1 = Wrappers.lambdaQuery();
198 199 200 201 202 203 204 205 206 207
            query1.in(LearningContentBoardCat::getLearningContentId, list);
            query1.select(LearningContentBoardCat::getExhibitionBoardCatId);
            List<String> list2 = this.learningContentBoardCatService.listObjs(query1, Object::toString);
            // 主学习内容展板分类不能完全子学习内容的展板分类
            if (CollectionUtil.isNotEmpty(list2) && !learningProject.getExhibitionBoardCatIdList().containsAll(list2)) {
                // 差集
                list2.removeAll(learningProject.getExhibitionBoardCatIdList());
                // 查询被删除的展板分类信息
                List<ExhibitionBoardCat> learningContentBoardCats = this.exhibitionBoardCatService.listByIds(list2);
                StringBuilder stringBuilder = new StringBuilder();
208 209 210 211
                learningContentBoardCats.forEach(s -> {
                    stringBuilder.append(s.getName());
                    if (learningContentBoardCats.get(learningContentBoardCats.size() - 1).equals(s)) {
                        stringBuilder.append(",");
nie'hong's avatar
nie'hong committed
212
                    } else {
213 214 215 216
                        stringBuilder.append("、");
                    }
                });
                return getFailResult("展板类别:" + stringBuilder + "被子学习内容使用,不能被删除,更新失败");
217 218 219
            }

            // 查询子学习内容的展板
220
            LambdaQueryWrapper<LearningContentBoard> query2 = Wrappers.lambdaQuery();
221 222 223 224 225 226
            query2.in(LearningContentBoard::getLearningContentId, list);
            query2.select(LearningContentBoard::getExhibitionBoardId);
            List<String> list3 = this.learningContentBoardService.listObjs(query2, Object::toString);
            // 修改主要学习内容时删除了子学习内容所使用展板
            if (CollectionUtil.isNotEmpty(list3) && !learningProject.getExhibitionBoardIdList().containsAll(list3)) {
                // 差集
227
                list3.removeAll(learningProject.getExhibitionBoardIdList());
228
                // 查询被删除的展板信息
229 230 231 232
                LambdaQueryWrapper<ExhibitionBoard> lambdaQuery = Wrappers.lambdaQuery();
                lambdaQuery.eq(ExhibitionBoard::getPublished, true);
                lambdaQuery.in(ExhibitionBoard::getId, list3);
                List<ExhibitionBoard> exhibitionBoards = this.exhibitionBoardService.list(lambdaQuery);
233 234 235 236 237 238 239 240 241 242 243 244
                if (CollectionUtil.isNotEmpty(exhibitionBoards)) {
                    // 被删除的展板名称
                    StringBuilder stringBuilder = new StringBuilder();
                    exhibitionBoards.forEach(s -> {
                        stringBuilder.append(s.getName());
                        if (exhibitionBoards.get(exhibitionBoards.size() - 1).equals(s)) {
                            stringBuilder.append(",");
                        } else {
                            stringBuilder.append("、");
                        }
                    });
                    return getFailResult("展板:" + stringBuilder + "被子学习内容使用,不能被删除,更新失败!");
nie'hong's avatar
nie'hong committed
245
                    }
246
                }
247 248
        }

249 250 251 252 253 254 255
        LearningContent learningContent = LearningContent.builder()
                .id(one.getId())
                .name(learningProject.getMajor())
                .copyrightOwnerIdList(learningProject.getCopyrightOwnerIdList())
                .cover(learningProject.getCover())
                .exhibitionBoardCatIdList(learningProject.getExhibitionBoardCatIdList())
                .exhibitionBoardIdList(learningProject.getExhibitionBoardIdList()).build();
nie'hong's avatar
nie'hong committed
256
        Map<String, Object> resultMap = this.learningContentController.updateLearningContent(learningContent);
nie'hong's avatar
nie'hong committed
257
        resultMsg.append("修改学习内容已提交,待审核!");
nie'hong's avatar
nie'hong committed
258 259
        if (resultMap.get("resultCode").equals("200")) {
            resultMap.replace("message", resultMsg);
nie'hong's avatar
nie'hong committed
260
        }
261
        return map;
liqin's avatar
liqin committed
262 263 264
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
265
    @RequiresAuthentication  //@RequiresPermissions("learning:project:list")
liqin's avatar
liqin committed
266
    @ApiOperation(value = "获取全部列表(无分页)", notes = "获取全部列表(无分页)")
wzp's avatar
wzp committed
267
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
268
    public Map<String, Object> getLearningProjectList() {
liqin's avatar
liqin committed
269
        List<LearningProject> learningProjectList = learningProjectService.list(Wrappers.<LearningProject>lambdaQuery().orderByDesc(LearningProject::getCreateTime));
liqin's avatar
liqin committed
270 271 272 273 274 275 276 277 278 279 280
        return getResult(learningProjectList);
    }

    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "_index", value = "分页起始偏移量", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "_size", value = "返回条数", paramType = "query", dataType = "Integer"),
            @ApiImplicitParam(name = "nameOrCode", value = "名称或编码", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "startDate", value = "创建时间-开始", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "创建时间-结束", paramType = "query", dataType = "String")
    })
    @PostMapping("/getPageList")
wzp's avatar
wzp committed
281
    @RequiresAuthentication  //@RequiresPermissions("learning:project:page")
liqin's avatar
liqin committed
282
    @ApiOperation(value = "获取分页列表", notes = "获取分页列表")
wzp's avatar
wzp committed
283
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    public Map<String, Object> getLearningProjectPageList(GenericPageParam genericPageParam) {
        LambdaQueryWrapper<LearningProject> queryWrapper = new LambdaQueryWrapper<>();
        // 对名称或编码模糊查询
        if (StringUtils.isNotBlank(genericPageParam.getNameOrCode())) {
            queryWrapper.like(LearningProject::getName, genericPageParam.getNameOrCode());
        }
        // 根据创建时间区间检索
        if (genericPageParam.getStartDate() != null && genericPageParam.getEndDate() != null) {
            queryWrapper.ge(LearningProject::getCreateTime, genericPageParam.getStartDate().atTime(0, 0, 0))
                    .le(LearningProject::getCreateTime, genericPageParam.getEndDate().atTime(23, 59, 59));
        }
        // 设置排序规则
        queryWrapper.orderByDesc(LearningProject::getCreateTime);
        // 设置查询内容
        queryWrapper.select(
                LearningProject::getId,
                LearningProject::getName,
                LearningProject::getRemarks,
                LearningProject::getCreateTime,
                LearningProject::getUpdateTime);
        Page<LearningProject> page = this.learningProjectService.page(getPage(), queryWrapper);
305

liqin's avatar
liqin committed
306
        for (LearningProject learningProject : page.getRecords()) {
liqin's avatar
liqin committed
307
            LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery()
liqin's avatar
liqin committed
308
                    .eq(LearningContent::getLearningProjectId, learningProject.getId());
309 310
            List<LearningContent> learningContentList = this.learningContentService.list(lambdaQueryWrapper);
            List<String> learningContentNameList = new ArrayList<>();
nie'hong's avatar
nie'hong committed
311
            learningContentList.forEach(s -> {
312 313
                if (s.getIsMajor()) {
                    learningProject.setAuditStatus(s.getAuditStatus());
nie'hong's avatar
nie'hong committed
314
                } else {
315 316 317
                    learningContentNameList.add(s.getName());
                }
            });
liqin's avatar
liqin committed
318
            learningProject.setLearningContentNames(String.join("、", learningContentNameList));
liqin's avatar
liqin committed
319 320 321 322 323 324
        }
        return getResult(page);
    }

    @ApiOperation(value = "获取详情", notes = "获取详情")
    @ApiImplicitParams({
liqin's avatar
liqin committed
325
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path", required = true)
liqin's avatar
liqin committed
326 327
    })
    @GetMapping("/get/{id}")
wzp's avatar
wzp committed
328
    @RequiresAuthentication  //@RequiresPermissions("learning:project:get:id")
wzp's avatar
wzp committed
329
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
330 331
    public Map<String, Object> getById(@PathVariable("id") String id) {
        LearningProject learningProject = learningProjectService.getById(id);
332 333 334 335 336
        // 该项目的主学习内容
        LambdaQueryWrapper<LearningContent> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(LearningContent::getLearningProjectId, id);
        lambdaQuery.eq(LearningContent::getIsMajor, true);
        LearningContent majorLearningContent = this.learningContentService.getOne(lambdaQuery);
337 338 339 340 341
        if (majorLearningContent != null) {
            Map<String, Object> map = this.learningContentController.getById(majorLearningContent.getId());
            LearningContent data = (LearningContent) map.get("data");
            learningProject.setMajorLearning(data);
        }
liqin's avatar
liqin committed
342 343 344
        return getResult(learningProject);
    }

liqin's avatar
liqin committed
345 346
    @DeleteMapping("/delete/{id}")
    @RequiresAuthentication  //@RequiresPermissions("learning:project:delete")
liqin's avatar
liqin committed
347
    @ApiOperation(value = "根据ID删除学习项目", notes = "根据ID删除学习项目")
liqin's avatar
liqin committed
348 349 350
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String", required = true)
    })
nie'hong's avatar
nie'hong committed
351
    @Transactional
liqin's avatar
liqin committed
352 353
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.DELETE)
    public Map<String, Object> deleteLearningProject(@PathVariable("id") String id) {
nie'hong's avatar
nie'hong committed
354
        // 项目下的学习内容id
nie'hong's avatar
nie'hong committed
355 356 357 358 359 360 361 362 363 364 365 366 367
        LambdaQueryWrapper<LearningContent> queryWrapper = Wrappers.<LearningContent>lambdaQuery();
        queryWrapper.eq(LearningContent::getLearningProjectId, id);
        queryWrapper.select(LearningContent::getId);
        List<String> list = this.learningContentService.listObjs(queryWrapper, Object::toString);
        // 删除学习内容和展板关联关系
        this.learningContentBoardService.remove(Wrappers.<LearningContentBoard>lambdaUpdate().in(LearningContentBoard::getLearningContentId, list));
        // 删除学习内容和展板分类的关联关系
        this.learningContentBoardCatService.remove(Wrappers.<LearningContentBoardCat>lambdaUpdate().in(LearningContentBoardCat::getLearningContentId, list));
        // 删除学习内容和展板版权方的关联关系
        this.learningContentCopyrightOwnerService.remove(Wrappers.<LearningContentCopyrightOwner>lambdaUpdate().in(LearningContentCopyrightOwner::getLearningContentId, list));
        // 删除学习内容
        this.learningContentService.remove(Wrappers.<LearningContent>lambdaUpdate().eq(LearningContent::getLearningProjectId, id));
        // 删除学习项目
liqin's avatar
liqin committed
368 369 370 371
        this.learningProjectService.removeById(id);
        return getSuccessResult();
    }

liqin's avatar
liqin committed
372 373
}