Pu Zhibing
2025-03-17 7f302004e78ca5220a4f88a7fab843964a18739a
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.panzhihua.sangeshenbian.api;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.interfaces.OperLog;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.sangeshenbian.model.entity.ProblemType;
import com.panzhihua.sangeshenbian.model.entity.SystemUser;
import com.panzhihua.sangeshenbian.service.IProblemTypeService;
import com.panzhihua.sangeshenbian.service.ISystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2025/2/23 2:27
 */
@Api
@RestController
@RequestMapping("/problemType")
public class ProblemTypeController extends BaseController {
    
    @Resource
    private IProblemTypeService problemTypeService;
    
    @Resource
    private ISystemUserService systemUserService;
    
    
    
    
    @GetMapping("/list")
    @ApiOperation(value = "获取问题类型列表", tags = {"三个身边后台-问题类型管理"})
    @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取问题类型列表")
    public R<IPage<ProblemType>> list(String name, Integer pageNum, Integer pageSize){
        Integer id = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(id);
        if(systemUser.getAccountLevel() != 1){
            return R.ok();
        }
        IPage<ProblemType> list = problemTypeService.list(name, pageNum, pageSize);
        return R.ok(list);
    }
    
    
    @PostMapping("/add")
    @ApiOperation(value = "添加问题类型", tags = {"三个身边后台-问题类型管理"})
    @OperLog(operModul = "三个身边后台",operType = 1, businessType = "添加问题类型")
    public R add(@RequestBody ProblemType problemType){
        Integer id = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(id);
        if(systemUser.getAccountLevel() != 1){
            return R.fail("添加失败");
        }
        long count = problemTypeService.count(new LambdaQueryWrapper<ProblemType>().eq(ProblemType::getName, problemType.getName()).eq(ProblemType::getDel, 0));
        if(0 < count){
            return R.fail("该问题类型已存在");
        }
        problemType.setDel(0);
        problemType.setCreateTime(LocalDateTime.now());
        problemTypeService.save(problemType);
        return R.ok();
    }
    
    
    @PostMapping("/edit")
    @ApiOperation(value = "编辑问题类型", tags = {"三个身边后台-问题类型管理"})
    @OperLog(operModul = "三个身边后台",operType = 2, businessType = "编辑问题类型")
    public R edit(@RequestBody ProblemType problemType){
        Integer id = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(id);
        if(systemUser.getAccountLevel() != 1){
            return R.fail("编辑失败");
        }
        long count = problemTypeService.count(new LambdaQueryWrapper<ProblemType>().eq(ProblemType::getName, problemType.getName()).eq(ProblemType::getDel, 0).ne(ProblemType::getId, problemType.getId()));
        if(0 < count){
            return R.fail("该问题类型已存在");
        }
        problemTypeService.updateById(problemType);
        return R.ok();
    }
    
    
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除问题类型", tags = {"三个身边后台-问题类型管理"})
    @OperLog(operModul = "三个身边后台",operType = 3, businessType = "删除问题类型")
    public R delete(@PathVariable("id") Integer id){
        Integer userid = this.getLoginUserInfoSanGeShenBian().getId();
        SystemUser systemUser = systemUserService.getById(userid);
        if(systemUser.getAccountLevel() != 1){
            return R.fail("删除失败");
        }
        problemTypeService.update(new UpdateWrapper<ProblemType>().eq("id", id).set("del", 1));
        return R.ok();
    }
    
    @GetMapping("/getProblemTypeInfo/{id}")
    @ApiOperation(value = "获取问题类型信息", tags = {"三个身边后台-问题类型管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "问题类型ID", required = true, dataType = "Integer")
    })
    @OperLog(operModul = "三个身边后台",operType = 0, businessType = "获取问题类型信息")
    public R<ProblemType> getProblemTypeInfo(@PathVariable("id") Integer id){
        ProblemType problemType = problemTypeService.getById(id);
        return R.ok(problemType);
    }
    @ApiOperation(value = "获取问题类型列表(不分页)")
    @GetMapping("/list-no-page")
    public R<List<ProblemType>> listNoPage(){
        List<ProblemType> list = problemTypeService.list(new LambdaQueryWrapper<ProblemType>().eq(ProblemType::getDel, 0));
        return R.ok(list);
    }
}