AlgorithmicProblemController.java 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
package com.kwan.springbootkwan.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kwan.springbootkwan.entity.AlgorithmicProblem;
import com.kwan.springbootkwan.entity.Result;
import com.kwan.springbootkwan.entity.dto.AlgorithmicProblemDTO;
import com.kwan.springbootkwan.service.AlgorithmicProblemService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 算法题(AlgorithmicProblem)表控制层
 *
 * @author makejava
 * @since 2023-10-07 09:15:45
 */
@RestController
@RequestMapping("algorithmicProblem")
public class AlgorithmicProblemController {

    /**
     * 服务对象
     */
    @Resource
    private AlgorithmicProblemService algorithmicProblemService;

    /**
     * 获取面试题的种类的数量
     *
     * @return
     */
    @GetMapping("/questionType")
    public Result questionType() {
        return Result.ok(this.algorithmicProblemService.questionType());
    }

    /**
     * 分页查询所有数据
     *
     * @return 所有数据
     */
    @GetMapping("/page")
    public Result selectAll(@RequestParam Integer page
            , @RequestParam Integer pageSize
            , @RequestParam String questionName
            , @RequestParam Integer questionType) {
        Page<AlgorithmicProblem> pageParm = new Page<>();
        pageParm.setCurrent(page);
        pageParm.setSize(pageSize);
        QueryWrapper<AlgorithmicProblem> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        if (questionType != 0) {
            wrapper.eq("question_type", questionType);
        }
        wrapper.eq("is_delete", 0);
        if (StringUtils.isNotEmpty(questionName)) {
            wrapper.like("question_name", questionName);
        }
        return Result.ok(AlgorithmicProblemDTO.Converter.INSTANCE.from(this.algorithmicProblemService.page(pageParm, wrapper)));
    }

    /**
     * 随机一题
     */
    @GetMapping("/random")
    public Result random() {
        QueryWrapper<AlgorithmicProblem> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        wrapper.orderByAsc("rand()").last("limit 1");
        return Result.ok(AlgorithmicProblemDTO.Converter.INSTANCE.from(this.algorithmicProblemService.getOne(wrapper)));
    }
}