UsersFreeController.java
5.06 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
package com.cnlive.shenhe.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cnlive.shenhe.bean.ErrorEnum;
import com.cnlive.shenhe.bean.ResponseBean;
import com.cnlive.shenhe.bean.SessionUser;
import com.cnlive.shenhe.dto.UsersFreeDTO;
import com.cnlive.shenhe.entity.ShySites;
import com.cnlive.shenhe.entity.ShyUsersfree;
import com.cnlive.shenhe.service.SitesService;
import com.cnlive.shenhe.service.UsersfreeService;
import com.cnlive.shenhe.utils.CommonConst;
import com.cnlive.shenhe.utils.CommonUtils;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpSession;
import java.util.List;
/**
* @author Administrator
* @Auther: liwei
* @Date: 2019/08/20 14:22
* @Description:
*/
@Controller
@RequestMapping("/usersFree")
public class UsersFreeController extends BaseController {
private static Logger logger = LoggerFactory.getLogger(UsersFreeController.class);
@Autowired
UsersfreeService usersfreeService;
@Autowired
SitesService sitesService;
/**
* 返回分页列表
*
* @param model
* @param usersFreeDTO
* @param session
* @return
*/
@GetMapping(value = "/page")
public String wangjiajiaPage(Model model, UsersFreeDTO usersFreeDTO, HttpSession session) {
logger.info("列表请求参数:{}", JSON.toJSONString(usersFreeDTO));
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
if (CommonUtils.isNull(sessionUser)) {
return "redirect:/users/login";
}
Integer spid = sessionUser.getSpid();
usersFreeDTO.setSpid(spid);
if (!sessionUser.isMaster() && usersFreeDTO.getSpid() != 0) {
return "page/error.html";
}
if (spid == 0) {
usersFreeDTO.setSpid(null);
}
PageInfo<ShyUsersfree> usersPage = usersfreeService.getPage(usersFreeDTO);
List<ShyUsersfree> list = usersPage.getList();
JSONObject category = CommonConst.CATEGORY;
if (!list.isEmpty()) {
for (ShyUsersfree users : list) {
//显示spid简称
ShySites shySites = sitesService.findspidDescByspid(users.getSp_id());
if (CommonUtils.isNotNull(shySites)) {
users.setSp_desc(shySites.getName());
}
//获取栏目名称
String categoryName = users.getCategory();
if (CommonUtils.isNotEmpty(categoryName)) {
for (String bkey : category.keySet()) {
categoryName = categoryName.replace(bkey, category.getString(bkey));
}
} else {
categoryName = "无";
}
users.setCategory_name(categoryName);
}
}
model.addAttribute("usersPage", usersPage);
model.addAttribute("pageSize", usersFreeDTO.getPageSize());
model.addAttribute("category", category);
return "page/usersFree.html";
}
/**
* 修改用户白名单状态
*
* @param id
* @param isEnable
* @return
*/
@PostMapping("/updateState")
@ResponseBody
public ResponseBean updateState(Integer id, Boolean isEnable) {
Integer n = usersfreeService.updateState(id, isEnable);
if (n > 0) {
return new ResponseBean(ErrorEnum.SUCCESS.getErrorCode(), "当前用户" + (isEnable ? "启用" : "禁用") + "成功");
}
return new ResponseBean(ErrorEnum.ERROR.getErrorCode(), "操作失败,请重试");
}
@PostMapping(value = "/write")
public String write(Model model, String userId, String userMobile, Integer spId, String[] write_business, HttpSession session, String redirect_url) {
if (CommonUtils.isEmpty(userId) && CommonUtils.isEmpty(userMobile)) {
setmodelParam(model, "userId,userMobile不能为空!");
return "error.html";
}
SessionUser sessionUser = (SessionUser) session.getAttribute(SessionUser.getSessionKey());
StringBuilder write = new StringBuilder();
if (CommonUtils.isNotNull(write_business) && write_business.length > 0) {
for (String w : write_business) {
write.append(",").append(w);
}
write = new StringBuilder(write.substring(1));
}
boolean success = usersfreeService.update(userId, userMobile, write.toString(), spId, sessionUser.getUserId());
if (success) {
return "redirect:" + redirect_url;
} else {
setmodelResult(model);
return "error.html";
}
}
}