package com.islizx.controller.admin;
import cn.hutool.core.lang.Validator;
import cn.hutool.extra.servlet.ServletUtil;
import com.github.pagehelper.PageInfo;
import com.islizx.config.annotation.SystemLog;
import com.islizx.entity.*;
import com.islizx.model.dto.LizxConst;
import com.islizx.model.dto.Msg;
import com.islizx.model.enums.*;
import com.islizx.service.BlogService;
import com.islizx.service.CommentService;
import com.islizx.service.MailService;
import com.islizx.vo.CommentQuery;
import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.*;
/**
* @author lizx
* @date 2020-02-14 - 15:26
*/
@Controller
@Slf4j
@RequestMapping("/admin")
public class CommentController {
@Autowired
private CommentService commentService;
@Autowired
private BlogService blogService;
@Autowired
private MailService mailService;
/**
* 评论人相关信息
*/
public static final String COMMENT_AUTHOR_IP = "ip";
public static final String COMMENT_AUTHOR = "nickname";
public static final String COMMENT_EMAIL = "email";
public static final String COMMENT_CONTENT = "content";
@RequestMapping("/comments/getpublishedsize")
@ResponseBody
public Msg getpublishedsize() {
// 三种评论类型个数
Integer publish = commentService.countCommentByPass(CommentStatusEnum.PUBLISHED.getCode());
Integer draft = commentService.countCommentByPass(CommentStatusEnum.CHECKING.getCode());
Integer trash = commentService.countCommentByPass(CommentStatusEnum.RECYCLE.getCode());
return Msg.success().add("publish", publish).add("draft", draft).add("trash", trash);
}
/**
* 后台评论列表显示
*
* @return modelAndView
*/
@RequestMapping(value = "/comments", method = RequestMethod.GET)
public String index(@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "15") Integer pageSize,
@RequestParam(required = false, defaultValue = "1") Integer pass,
HttpSession session, Model model) {
// 三种文章类型个数
Integer publish = commentService.countCommentByPass(CommentStatusEnum.PUBLISHED.getCode());
Integer draft = commentService.countCommentByPass(CommentStatusEnum.CHECKING.getCode());
Integer trash = commentService.countCommentByPass(CommentStatusEnum.RECYCLE.getCode());
HashMap<String, Object> criteria = new HashMap<>(1);
criteria.put("pass", pass);
PageInfo<Comment> commentPageInfo = commentService.pageComment(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", commentPageInfo);
model.addAttribute("publish", publish);
model.addAttribute("draft", draft);
model.addAttribute("trash", trash);
model.addAttribute("pass", pass);
String msg = (String) session.getAttribute("msg");
if (msg != null && !msg.equals("")) {
model.addAttribute("msg", msg);
session.removeAttribute("msg");
}
return "admin/comment/comments";
}
/**
* 分页条件查询
*
* @param pageIndex 页数
* @param pageSize
* @param commentQuery
* @param model
* @return
*/
@RequestMapping("/comments/search")
public String search(@RequestParam(required = false, defaultValue = "1") Integer pageIndex,
@RequestParam(required = false, defaultValue = "15") Integer pageSize, CommentQuery commentQuery, Model model) {
HashMap<String, Object> criteria = new HashMap<>();
String keywords = commentQuery.getKeywords();
Integer pass = commentQuery.getPass();
String sort = commentQuery.getSort();
String order = commentQuery.getOrder();
String searchType = commentQuery.getSearchType();
if (!StringUtils.isBlank(keywords)) {
if (COMMENT_CONTENT.equals(searchType)) {
criteria.put("content", keywords);
} else if (COMMENT_AUTHOR.equals(searchType)) {
criteria.put("nickname", keywords);
} else if (COMMENT_EMAIL.equals(searchType)) {
criteria.put("email", keywords);
} else if (COMMENT_AUTHOR_IP.equals(searchType)) {
criteria.put("ip", keywords);
}
}
if (pass != null) {
criteria.put("pass", pass);
} else {
criteria.put("pass", 1);
}
if (sort != null && !StringUtils.isBlank(sort)) criteria.put("sort", sort);
if (order != null && !StringUtils.isBlank(order)) criteria.put("order", order);
PageInfo<Comment> commentPageInfo = commentService.pageComment(pageIndex, pageSize, criteria);
model.addAttribute("pageInfo", commentPageInfo);
return "admin/comment/comments :: commentList";
}
/**
* 将评论改变为发布状态
* 评论状态有两种:待审核1,回收站2
* 对待审核转发布的,发邮件
*
* @param commentId 评论编号
* @return 重定向到/admin/comment
*/
@ResponseBody
@RequestMapping(value = "/comments/revert", method = RequestMethod.PUT)
@SystemLog(description = "回滚评论", type = LogTypeEnum.OPERATION)
public Msg moveToPublish(@RequestParam("id") Integer commentId, HttpSession session) {
User loginUser = (User) session.getAttribute("user");
//评论
Comment comment = commentService.getById(null,null,null,commentId);
Blog blog = blogService.getBlogByPublishedAndId(null, null,comment.getBlogId());
Comment result = commentService.updateCommentPass(commentId, CommentStatusEnum.PUBLISHED.getCode());
// 判断是不是子评论,如果是,也对被回复人发邮件
if(result.getParentCommentId() != null && result.getParentCommentId() > 0){
//被回复的评论
Comment lastComment = commentService.getById(null,null, null,comment.getParentCommentId());
//邮件通知
new EmailToAuthor(result, lastComment, blog).start();
}
//判断是否启用邮件服务
new NoticeToAuthor(result, blog, result.getPass()).start();
return Msg.success().add("msg", "评论已发布!");
}
/**
* 删除评论
*
* @param commentId commentId
* @return string 重定向到/admin/comment
*/
@RequestMapping(value = "/comments/delete", method = RequestMethod.DELETE)
@ResponseBody
@SystemLog(description = "删除评论", type = LogTypeEnum.OPERATION)
public Msg moveToAway(@RequestParam("id") Integer commentId) {
//评论
Comment comment = commentService.getById(null,null, null, commentId);
if (Objects.equals(comment.getPass(), CommentStatusEnum.RECYCLE.getCode())) {
commentService.deleteComment(commentId);
return Msg.success().add("msg", "评论已彻底删除");
} else {
commentService.updateCommentPass(commentId, CommentStatusEnum.RECYCLE.getCode());
return Msg.success().add("msg", "评论仍入回收站");
}
}
/**
* 管理员回复评论,并通过评论
*
* @param commentId 被回复的评论
* @param commentContent 回复的内容
九转成圣
- 粉丝: 6044
- 资源: 2958
最新资源
- Java毕业设计-springboot-vue-工作量统计系统(源码+sql脚本+29页零基础部署图文详解+29页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-高校疫情防控web系统(源码+sql脚本+29页零基础部署图文详解+31页论文+环境工具+教程+视频+模板).zip
- 基于模型的六轴机器人阻抗控制算法演示与仿真参数设置指导(matlab simscape仿真机器人模型自定义切换,跟踪轨迹展示及算法学习),基于模型的六轴机器人阻抗力控制算法(matlab simsca
- Java毕业设计-springboot-vue-工资信息管理系统(源码+sql脚本+29页零基础部署图文详解+25页论文+环境工具+教程+视频+模板).zip
- 基于PaddlePaddle的眼疾识别项目(包含训练集、测试集、模型权重)
- Java毕业设计-springboot-vue-航班进出港管理系统(源码+sql脚本+29页零基础部署图文详解+29页论文+环境工具+教程+视频+模板).zip
- 基于ABAQUS、Opensees和Perform3d的结构易损性评估与IDA曲线绘制:matlab函数调用与地震波选波调幅实战指南,ABAQUS 、Opensees、Perform3d IDA曲线
- Java毕业设计-springboot-vue-果蔬作物疾病防治系统(源码+sql脚本+29页零基础部署图文详解+30页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-滑雪场管理系统(源码+sql脚本+29页零基础部署图文详解+27页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-家教管理系统(源码+sql脚本+29页零基础部署图文详解+32页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-驾校预约学习系统(源码+sql脚本+29页零基础部署图文详解+34页论文+环境工具+教程+视频+模板).zip
- 数据采集系统:下位机与上位机协同工作,高性能模数转换与灵活配置滤波功能,数据采集系统下位机与上位机代码 下位机采用开发板来完成 AD9226模数转芯片,最大65MHz采样,12bit量化 双通
- Java毕业设计-springboot-vue-集团门户网站(源码+sql脚本+29页零基础部署图文详解+33页论文+环境工具+教程+视频+模板).zip
- 蓝桥杯Java历年真题及其解析.docx
- Java毕业设计-springboot-vue-教师薪酬管理系统(源码+sql脚本+29页零基础部署图文详解+32页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-教学辅助系统(源码+sql脚本+29页零基础部署图文详解+31页论文+环境工具+教程+视频+模板).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈