CourseController.java 5.65 KB
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;
        }
    }

}