CommentController.java 5.81 KB
package com.server.web.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.server.shiro.persistent.bean.SysUser;
import com.server.utils.DateUtils;
import com.server.web.common.mapper.TBaseSecondClassMapper;
import com.server.web.common.mapper.TKzyCommentMapper;
import com.server.web.common.mapper.TKzyCourseMapper;
import com.server.web.common.model.PageModel;
import com.server.web.common.model.TBaseSecondClass;
import com.server.web.common.model.TKzyComment;
import com.server.web.common.model.TKzyCourse;
import com.server.web.common.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 评论管理
 */
@RestController
@RequestMapping(BaseController.OSS_NAMESPACE + "/comment")
public class CommentController extends BaseController {

    @Autowired
    private TKzyCommentMapper commentMapper;


    /**
     * 课程评论列表
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/commentCourseList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map commentList(Long id,@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "1") Integer pageSize) {
        try {
            Map paramMap = new HashMap<>();
            paramMap.put("id",id);
            PageHelper.startPage(pageNo,pageSize,true,false);
            List list = openSqlRingsService.selectList_Rings("com.mapping.queryModel.commentCourseList",paramMap);
            PageInfo pageInfo = new PageInfo(list);
            PageModel model = new PageModel();
            model.setTotal(pageInfo.getTotal());
            model.setList(list);
            return success(model);
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

    /**
     * 资讯评论列表
     * @param id
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/commentInformationList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map commentInformationList(Long id,@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "1") Integer pageSize) {
        try {
            Map paramMap = new HashMap<>();
            paramMap.put("id",id);
            PageHelper.startPage(pageNo,pageSize,true,false);
            List list = openSqlRingsService.selectList_Rings("com.mapping.queryModel.commentInformationList",paramMap);
            PageInfo pageInfo = new PageInfo(list);
            PageModel model = new PageModel();
            model.setTotal(pageInfo.getTotal());
            model.setList(list);
            return success(model);
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

    /**
     * 删除评论
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/deleteComment", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map deleteComment(@RequestParam long id) {
        try {
            TKzyComment comment = new TKzyComment();
            comment.setId(id);
            comment.setIsDelete(1);
            commentMapper.updateByPrimaryKeySelective(comment);
            return success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }


    /**
     * 审核评论
     * @param id
     * @param status
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/authComment", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map authComment(@RequestParam long id,Integer status) {
        try {
            TKzyComment comment = commentMapper.selectByPrimaryKey(id);
            if(comment.getAuthStatus()!=1){
                return  error("0","评论已审核","评论已审核");
            }
            comment.setId(id);
            comment.setAuthDt(new Date());
            comment.setAuthStatus(status);
            commentMapper.updateByPrimaryKeySelective(comment);
            return success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }


    /**
     * 评论列表
     * @param pageNo
     * @param pageSize
     * @param authStatus
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping(path = "/queryCommentList", method = {RequestMethod.POST, RequestMethod.GET}, produces = "application/json")
    public Map queryCommentList(@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "1") Integer pageSize,
                                @RequestParam(defaultValue ="-1")Integer authStatus,@RequestParam(defaultValue ="")String name) {
        try {
            Map paramMap = new HashMap<>();
            if(authStatus!=-1){
                paramMap.put("authStatus",authStatus);
            }
           if(!("").equals(name)){
               paramMap.put("name","%"+name+"%");
           }
            PageHelper.startPage(pageNo,pageSize,true,false);
            List list = openSqlRingsService.selectList_Rings("com.mapping.queryModel.queryCommentList",paramMap);
            PageInfo pageInfo = new PageInfo(list);
            PageModel model = new PageModel();
            model.setTotal(pageInfo.getTotal());
            model.setList(list);
            return success(model);
        } catch (Exception e) {
            e.printStackTrace();
            return  error("0","系统异常",null);
        }
    }

}