puzhibing
2023-11-25 53e7558400dcacecdce70e39ebfe1727740f9296
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
package com.dsh.course.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.TCoursePackage;
import com.dsh.course.entity.TCoursePackageType;
import com.dsh.course.model.vo.CoursePackageTypeVO;
import com.dsh.course.service.TCoursePackageService;
import com.dsh.course.service.TCoursePackageTypeService;
import net.bytebuddy.asm.Advice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/1 12:05
 */
@RestController
@RequestMapping("")
public class CoursePackageTypeController {
 
    @Autowired
    private TCoursePackageTypeService coursePackageTypeService;
    @Autowired
    private TCoursePackageService tCoursePackageService;
 
    /**
     * 根据ids获取类型
     */
    @RequestMapping("/coursePackageType/getByCourseIds")
    public List<TCoursePackageType> getByCourseIds(@RequestBody List<Integer> ids) {
        if (ids.size() == 0) {
            return new ArrayList<>();
        }
        return coursePackageTypeService.list(new QueryWrapper<TCoursePackageType>().in("id", ids));
    }
 
    /**
     * 新增课包类型
     */
    @ResponseBody
    @RequestMapping("/coursePackageType/add")
    public Object add(@RequestBody String name) {
 
        List<TCoursePackageType> list = coursePackageTypeService.list(new QueryWrapper<TCoursePackageType>().eq("name", name).ne("state", 3));
        if (list.size() != 0) {
            return 500;
        } else {
            TCoursePackageType coachType = new TCoursePackageType();
            coachType.setName(name);
            coachType.setState(1);
            coachType.setInsertTime(new Date());
            coursePackageTypeService.save(coachType);
            return 200;
        }
    }
 
    /**
     * 修改课包类型
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/coursePackageType/update")
    public Object update(@RequestBody CoursePackageTypeVO vo) {
        List<TCoursePackageType> list = coursePackageTypeService.list(new QueryWrapper<TCoursePackageType>().eq("name", vo.getName()));
        if (list.size() != 0) {
            return 500;
        } else {
            TCoursePackageType tCoursePackageType = new TCoursePackageType();
            tCoursePackageType.setId(vo.getId());
            tCoursePackageType.setName(vo.getName());
            coursePackageTypeService.updateById(tCoursePackageType);
            return 200;
        }
    }
 
    /**
     * 删除课包类型
     *
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("/coursePackageType/delete")
    public Object delete(@RequestBody CoursePackageTypeVO vo) {
        Integer id = vo.getId();
        QueryWrapper<TCoursePackage> coursePackageTypeId = new QueryWrapper<TCoursePackage>().eq("coursePackageTypeId", id);
        List<TCoursePackage> list = tCoursePackageService.list(coursePackageTypeId);
        // 500表明当前课包类型正在被使用不能删除
        if (list.size() > 0) {
            return 500;
        } else {
            TCoursePackageType tCoursePackageType = new TCoursePackageType();
            tCoursePackageType.setId(vo.getId());
            tCoursePackageType.setName(vo.getName());
            tCoursePackageType.setState(3);
            coursePackageTypeService.updateById(tCoursePackageType);
            return 200;
        }
    }
 
    /**
     * 获取课包所有类型
     *
     * @return
     */
    @ResponseBody
    @PostMapping("/coursePackageType/queryAllCoursePackageType")
    public List<TCoursePackageType> queryAllCoursePackageType() {
        QueryWrapper<TCoursePackageType> state = new QueryWrapper<TCoursePackageType>().ne("state", 3);
        return coursePackageTypeService.list(state);
    }
}