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

liqin's avatar
liqin committed
3 4 5 6 7 8 9 10 11 12 13
import cn.chnmuseum.party.common.log.MethodLog;
import cn.chnmuseum.party.common.log.OperModule;
import cn.chnmuseum.party.common.log.OperType;
import cn.chnmuseum.party.common.validator.groups.Add;
import cn.chnmuseum.party.common.validator.groups.Update;
import cn.chnmuseum.party.common.vo.GenericPageParam;
import cn.chnmuseum.party.model.LearningContent;
import cn.chnmuseum.party.model.LearningProject;
import cn.chnmuseum.party.service.LearningContentService;
import cn.chnmuseum.party.service.LearningProjectService;
import cn.chnmuseum.party.web.controller.base.BaseController;
liqin's avatar
liqin committed
14
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
liqin's avatar
liqin committed
15
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
liqin's avatar
liqin committed
16 17 18 19 20 21 22
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
23
import org.apache.shiro.authz.annotation.RequiresAuthentication;
liqin's avatar
liqin committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
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
47 48
    @Resource
    private LearningContentService learningContentService;
liqin's avatar
liqin committed
49 50

    @PostMapping("/save")
wzp's avatar
wzp committed
51
    @RequiresAuthentication  //@RequiresPermissions("learning:project:save")
liqin's avatar
liqin committed
52
    @ApiOperation(value = "添加", notes = "添加")
wzp's avatar
wzp committed
53
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.ADD)
liqin's avatar
liqin committed
54 55 56 57 58 59 60 61 62 63 64 65 66
    public Map<String, Object> saveLearningProject(@Validated(value = {Add.class}) LearningProject learningProject) {
        // 保存业务节点信息
        boolean result = learningProjectService.save(learningProject);
        // 返回操作结果
        if (result) {
            return getSuccessResult();
        } else {
            // 保存失败
            return getFailResult();
        }
    }

    @PutMapping("/update")
wzp's avatar
wzp committed
67
    @RequiresAuthentication  //@RequiresPermissions("learning:project:update")
liqin's avatar
liqin committed
68
    @ApiOperation(value = "修改信息", notes = "修改信息")
wzp's avatar
wzp committed
69
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.UPDATE)
liqin's avatar
liqin committed
70 71 72 73 74 75 76 77 78
    public Map<String, Object> updateLearningProject(@Validated(value = {Update.class}) LearningProject learningProject) {
        boolean flag = learningProjectService.updateById(learningProject);
        if (flag) {
            return getSuccessResult();
        }
        return getFailResult();
    }

    @GetMapping("/getList")
wzp's avatar
wzp committed
79
    @RequiresAuthentication  //@RequiresPermissions("learning:project:list")
liqin's avatar
liqin committed
80
    @ApiOperation(value = "获取全部列表(无分页)", notes = "获取全部列表(无分页)")
wzp's avatar
wzp committed
81
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
82
    public Map<String, Object> getLearningProjectList() {
liqin's avatar
liqin committed
83
        List<LearningProject> learningProjectList = learningProjectService.list(Wrappers.<LearningProject>lambdaQuery().orderByDesc(LearningProject::getCreateTime));
liqin's avatar
liqin committed
84 85 86 87 88 89 90 91 92 93 94
        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
95
    @RequiresAuthentication  //@RequiresPermissions("learning:project:page")
liqin's avatar
liqin committed
96
    @ApiOperation(value = "获取分页列表", notes = "获取分页列表")
wzp's avatar
wzp committed
97
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    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);
        for (LearningProject learningProject : page.getRecords()) {
liqin's avatar
liqin committed
120
            LambdaQueryWrapper<LearningContent> lambdaQueryWrapper = Wrappers.<LearningContent>lambdaQuery()
liqin's avatar
liqin committed
121
                    .eq(LearningContent::getLearningProjectId, learningProject.getId());
liqin's avatar
liqin committed
122
            lambdaQueryWrapper.select(LearningContent::getName);
liqin's avatar
liqin committed
123 124
            List<String> learningContentNameList = this.learningContentService.listObjs(lambdaQueryWrapper, Object::toString);
            learningProject.setLearningContentNames(String.join("、", learningContentNameList));
liqin's avatar
liqin committed
125 126 127 128 129 130
        }
        return getResult(page);
    }

    @ApiOperation(value = "获取详情", notes = "获取详情")
    @ApiImplicitParams({
liqin's avatar
liqin committed
131
            @ApiImplicitParam(name = "id", value = "标识ID", dataType = "String", paramType = "path", required = true)
liqin's avatar
liqin committed
132 133
    })
    @GetMapping("/get/{id}")
wzp's avatar
wzp committed
134
    @RequiresAuthentication  //@RequiresPermissions("learning:project:get:id")
wzp's avatar
wzp committed
135
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.SELECT)
liqin's avatar
liqin committed
136 137 138 139 140
    public Map<String, Object> getById(@PathVariable("id") String id) {
        LearningProject learningProject = learningProjectService.getById(id);
        return getResult(learningProject);
    }

liqin's avatar
liqin committed
141 142
    @DeleteMapping("/delete/{id}")
    @RequiresAuthentication  //@RequiresPermissions("learning:project:delete")
liqin's avatar
liqin committed
143
    @ApiOperation(value = "根据ID删除学习项目", notes = "根据ID删除学习项目")
liqin's avatar
liqin committed
144 145 146 147 148
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "标识ID", paramType = "path", dataType = "String", required = true)
    })
    @MethodLog(operModule = OperModule.LEARNPROJECT, operType = OperType.DELETE)
    public Map<String, Object> deleteLearningProject(@PathVariable("id") String id) {
149 150
        //按照王亭亭的要求 删除学习项目,不删除学习内容 所以注释掉下面一行代码
//        this.learningContentService.remove(Wrappers.<LearningContent>lambdaUpdate().eq(LearningContent::getLearningProjectId, id));
151 152 153 154
        int count = this.learningContentService.count(Wrappers.<LearningContent>lambdaUpdate().eq(LearningContent::getLearningProjectId, id).last("LIMIT 1"));
        if (count >= 1) {
            return getFailResult("该项目已有关联学习内容,不能删除");
        }
liqin's avatar
liqin committed
155 156 157 158
        this.learningProjectService.removeById(id);
        return getSuccessResult();
    }

liqin's avatar
liqin committed
159 160
}