CourseController.java
5.65 KB
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
160
161
162
163
package com.server.web.controller;
import com.server.web.common.mapper.TKzyUserMapper;
import com.server.web.common.model.TKzyUser;
import com.server.web.common.service.TKzyCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* 课程相关action
* Created by weiwenfu@163.com on 2018/12/5 上午 11:56.
*/
@SpringBootApplication
@RestController
@RequestMapping(BaseController.WX_NAMESPACE + "/course")
@ControllerAdvice
public class CourseController extends BaseController {
@Autowired
private TKzyCourseService tKzyCourseService;
@Autowired
private TKzyUserMapper tKzyUserMapper;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private RestTemplate restTemplate;
@Value("${wx.http.danmu.url}")
private String danmuUrl;
/**
* 热门课程
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/hotCourse", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> hotCourse() {
return tKzyCourseService.hotCourse();
}
/**
* 录播课列表
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/recordCourse", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> recordCourse(@RequestParam(value = "typeId", required = false) Long typeId, @RequestParam(value = "pageNo", required = false) Integer pageNo, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
return tKzyCourseService.recordCourse(typeId, pageNo, pageSize);
}
/**
* 直播课列表(全查)
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/livingCourse", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> livingCourse() {
return tKzyCourseService.livingCourse();
}
/**
* 直播课详情页
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/livingCourseDetail", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> livingCourseDetail(HttpServletRequest request, @RequestParam(value = "courseId", required = true) Long courseId) {
TKzyUser tKzyUser = getLoginUser(request);
Long userId = null;
if (tKzyUser != null) {
userId = tKzyUser.getId();
}
return tKzyCourseService.livingCourseDetail(courseId, userId);
}
/**
* 录播课详情页
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/recordCourseDetail", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> recordCourseDetail(HttpServletRequest request, @RequestParam(value = "courseId", required = true) Long courseId) {
TKzyUser tKzyUser = getLoginUser(request);
Long userId = null;
if (tKzyUser != null) {
userId = tKzyUser.getId();
}
return tKzyCourseService.recordCourseDetail(courseId, userId);
}
/**
* 评论列表
*
* @param courseId
* @return
*/
@ResponseBody
@RequestMapping(value = "/commentList", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> commentList(@RequestParam(value = "courseId") Long courseId, @RequestParam(value = "pageNo", required = false) Integer pageNo, @RequestParam(value = "pageSize", required = false) Integer pageSize) {
return tKzyCourseService.commentList(courseId, pageNo, pageSize);
}
/**
* 提交评论
*
* @param courseId
* @param comment
* @return
*/
@ResponseBody
@RequestMapping(value = "/comment", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> comment(HttpServletRequest request, @RequestParam(value = "courseId") Long courseId, @RequestParam(value = "comment") String comment) {
TKzyUser tKzyUser = getLoginUser(request);
Long userId = null;
if (tKzyUser != null) {
userId = tKzyUser.getId();
}
return tKzyCourseService.comment(courseId, userId, comment);
}
/**
* 临时设置登录信息
*
* @param request
* @param userId
* @return
*/
@ResponseBody
@RequestMapping(value = "/tmpSetSession", method = {RequestMethod.POST,RequestMethod.GET},produces = "application/json")
public Map<String, Object> tmpSetSession(HttpServletRequest request, @RequestParam(value = "userId", required = true) Long userId) {
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("status", "0");
resultMap.put("message", "");
if (userId == null || userId <= 0l) {
resultMap.put("message", "用户ID不能为空~");
return resultMap;
}
TKzyUser tKzyUser = tKzyUserMapper.selectByPrimaryKey(userId);
if (tKzyUser != null) {
request.getSession().setAttribute(WX_USER_SESSION_KEY, tKzyUser);
resultMap.put("message", "操作成功~");
return resultMap;
} else {
resultMap.put("message", "未查到该用户信息~");
return resultMap;
}
}
}