puzhibing
2023-07-06 ac6a07af9baba0e0fc8d181aae904da679ae8f5a
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.dsh.course.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.course.entity.TCourse;
import com.dsh.course.entity.TCoursePackageType;
import com.dsh.course.feignclient.model.ExerciseVideo;
import com.dsh.course.model.*;
import com.dsh.course.service.TCoursePackageService;
import com.dsh.course.service.TCoursePackageTypeService;
import com.dsh.course.service.TCourseService;
import com.dsh.course.util.ResultUtil;
import com.dsh.course.util.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.ArrayList;
import java.util.List;
 
@Api
@CrossOrigin
@RestController
@RequestMapping("")
public class CourseController {
 
    private Logger logger = LoggerFactory.getLogger("business-log");
 
    @Autowired
    private TCourseService courseService;
 
    @Autowired
    private TCoursePackageService coursePackageService;
 
    @Autowired
    private TokenUtil tokenUtil;
 
    @Autowired
    private TCoursePackageTypeService coursePackageTypeService;
 
 
 
 
 
 
    @PostMapping("/course/queryList")
    public List<ExerciseVideo> queryStuCourseAfterVideos(@RequestBody List<Integer> courseIds){
        List<ExerciseVideo> videos = new ArrayList<>();
        List<TCourse> list = courseService.list(new QueryWrapper<TCourse>()
                .in("id", courseIds)
                .eq("state",1));
        if (list.size() > 0){
            list.forEach( vs ->{
                ExerciseVideo video = new ExerciseVideo();
                video.setVideoUrl(vs.getCourseVideo());
                video.setVideoName(vs.getName());
                video.setVideoCoverImgUrl(vs.getCoverDrawing());
                videos.add(video);
            });
        }
        return videos;
    }
 
 
    @ResponseBody
    @PostMapping("/api/course/queryCoursePackageType")
    @ApiOperation(value = "获取课程类型列表", tags = {"APP-课程列表"})
    @ApiImplicitParams({
    })
    public ResultUtil<List<BaseVo>> queryCoursePackageType(){
        try {
            List<TCoursePackageType> coursePackageTypes = coursePackageTypeService.list(new QueryWrapper<TCoursePackageType>().eq("state", 1));
            List<BaseVo> list = new ArrayList<>();
            coursePackageTypes.forEach(c -> {
                BaseVo baseVo = new BaseVo();
                BeanUtils.copyProperties(c, baseVo);
                list.add(baseVo);
            });
            return ResultUtil.success(list);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
    @ResponseBody
    @PostMapping("/api/course/queryCourseList")
    @ApiOperation(value = "获取课程列表", tags = {"APP-课程列表"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<List<CoursePackageListVo>> queryCourseList(@RequestBody CoursePackageList coursePackageList){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<CoursePackageListVo> coursePackageListVos = coursePackageService.queryCourseList(uid, coursePackageList);
            return ResultUtil.success(coursePackageListVos);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/course/queryCourseInfo")
    @ApiOperation(value = "获取课程详情", tags = {"APP-课程列表"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "课包id", name = "id", dataType = "int", required = true),
            @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = true),
            @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = true),
            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<CoursePackageInfo> queryCourseInfo(@RequestBody Integer id, @RequestBody String lon, @RequestBody String lat){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            CoursePackageInfo coursePackageInfo = coursePackageService.queryCourseInfo(uid, id, lon, lat);
            return ResultUtil.success(coursePackageInfo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
 
    public ResultUtil paymentCourse(@RequestBody PaymentCourseVo paymentCourseVo){
        try {
            Integer uid = tokenUtil.getUserIdFormRedis();
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return coursePackageService.paymentCourse(uid, paymentCourseVo);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
}