CommentsController.java
4.66 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
package com.cnlive.shenhe.controller;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.entity.ShyComments;
import com.cnlive.shenhe.entity.ShyUsers;
import com.cnlive.shenhe.serviceImpl.CommentsServiceImpl;
import com.cnlive.shenhe.serviceImpl.UsersServiceImpl;
import com.cnlive.shenhe.utils.AuditPass;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping("/comments")
public class CommentsController {
@Autowired
AuditPass Pass;
@Autowired
CommentsServiceImpl commentsService;
@Autowired
UsersServiceImpl usersService;
/**
* 评论列表页
*
* @param activity_id
* @param content
* @param is_hot
* @param start_date
* @param end_date
* @param state
* @param page
* @param pageSize
* @param orderByClause
* @return
*/
@GetMapping("/page")
public String getPage(Model model, String activity_id, String content, Integer is_hot,
String start_date, String end_date, String state,
Integer page, Integer pageSize, String orderByClause, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
Integer spid = sessionUser.getSpid();
if (spid == 0) spid = 82;
if (CommonUtils.isNull(page)) page = 1;
if (CommonUtils.isNull(pageSize)) pageSize = 10;
Date sDate = null;
Date eDate = null;
if (CommonUtils.isNotEmpty(start_date)) {
try {
sDate = CommonUtils.parseDate(start_date, "yyyy-MM-dd hh:mm");
} catch (Exception e) {
}
}
if (CommonUtils.isNotEmpty(end_date)) {
try {
eDate = CommonUtils.parseDate(end_date, "yyyy-MM-dd hh:mm");
} catch (Exception e) {
}
}
PageInfo<ShyComments> commentPage = commentsService.getPage(activity_id, content, is_hot, sDate, eDate, state, null, page, pageSize, orderByClause, spid);
List<ShyComments> list = commentPage.getList();
if (!list.isEmpty()) {
for (ShyComments comment : list) {
String auditor = "白名单";
String auditor_id = comment.getAuditor_id();
if (CommonUtils.isNotEmpty(auditor_id)) {
ShyUsers user = new ShyUsers();
user.setUser_id(auditor_id);
user = usersService.select(user);
if (CommonUtils.isNotNull(user)) auditor = user.getUsername() + user.getEmail();
}
comment.setAuditor(auditor);
}
}
model.addAttribute("commentPage", commentPage);
return "page/comment.html";
}
/**
* 评论详情
*
* @param id
* @return
*/
@GetMapping("/details/{id}")
public String getDetailsComments(@PathVariable Integer id, Model model) {
ShyComments comment = commentsService.getDetailsComment(id);
model.addAttribute("comment", comment);
return "page/commentDetail.html";
}
/**
* 审核通过
*
* @param ids
* @return
*/
@PostMapping("/pass")
@ResponseBody
public ResponseBean pass(String ids, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
boolean success = commentsService.updateState(ids, CommonConst.AUDIT_SUCCESS, userId);
if (success) {
return new ResponseBean();
} else {
return new ResponseBean(ErrorEnum.ERROR);
}
}
/**
* 审核拒绝
*
* @param ids
* @return
*/
@PostMapping("/refuse")
@ResponseBody
public ResponseBean refuse(String ids, HttpSession session) {
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
String userId = sessionUser.getUserId();
boolean success = commentsService.updateState(ids, CommonConst.AUDIT_REFUSE, userId);
if (success) {
return new ResponseBean();
} else {
return new ResponseBean(ErrorEnum.ERROR);
}
}
}