模态框跟换为layx,代码优化,新建帖子时可新建标签
This commit is contained in:
@@ -5,6 +5,7 @@ import com.yaoyuan.jiscuss.entity.Tag;
|
||||
import com.yaoyuan.jiscuss.entity.UserInfo;
|
||||
import com.yaoyuan.jiscuss.entity.User;
|
||||
import com.yaoyuan.jiscuss.entity.custom.DiscussionCustom;
|
||||
import com.yaoyuan.jiscuss.entity.custom.TagCustom;
|
||||
import com.yaoyuan.jiscuss.service.IDiscussionsService;
|
||||
import com.yaoyuan.jiscuss.service.ITagsService;
|
||||
import com.yaoyuan.jiscuss.service.IUsersService;
|
||||
@@ -16,16 +17,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 用户页面系统控制器
|
||||
* 首页页面系统控制器
|
||||
*/
|
||||
@Controller
|
||||
public class UserSystemController extends BaseController {
|
||||
@@ -41,28 +39,98 @@ public class UserSystemController extends BaseController {
|
||||
@Autowired
|
||||
private ITagsService tagsService;
|
||||
|
||||
//首页
|
||||
/**
|
||||
* 首页index
|
||||
* @param tag
|
||||
* @param type
|
||||
* @param pageNum
|
||||
* @param request
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping({"/", "/main", "/index"})
|
||||
public String home(@RequestParam(defaultValue = "all") String tag, @RequestParam(defaultValue = "all") String type, @RequestParam(defaultValue = "1") Integer
|
||||
pageNum, HttpServletRequest request, ModelMap map) {
|
||||
logger.info(">>> index");
|
||||
logger.info(">>> tag:" + tag);
|
||||
logger.info(">>> pageNum:" + pageNum);
|
||||
List<User> userall = usersService.getAllList();
|
||||
logger.info(">>> 第一遍的全部用户:" + userall);
|
||||
|
||||
List<User> useral2 = usersService.getAllList();
|
||||
logger.info(">>> 第二遍的全部用户:" + useral2);
|
||||
|
||||
int pageSiz = 10;
|
||||
int pageNumNew = pageNum - 1;
|
||||
Discussion discussion = new Discussion();
|
||||
//分页获取主题帖子
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion, pageNumNew, pageSiz);
|
||||
//分页获取主题帖子-默认
|
||||
Page<Discussion> allDiscussionsPage = discussionsService.queryAllDiscussionsList(discussion, pageNumNew, pageSiz, tag, type);
|
||||
|
||||
List<Discussion> allDiscussions = allDiscussionsPage.getContent();
|
||||
List<DiscussionCustom> newAllD = new ArrayList<>();
|
||||
|
||||
setTagAndUserList(newAllD,allDiscussions);
|
||||
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
|
||||
Long total = allDiscussionsPage.getTotalElements();
|
||||
|
||||
//获取主题帖子的分页数据
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}", allTags);
|
||||
|
||||
map.put("data", "Jiscuss 用户");
|
||||
map.put("allDiscussions", newAllD);
|
||||
map.put("allUser", usersService.getAllList());
|
||||
map.put("pageDiscussions", pageNumList);
|
||||
map.put("allTags", allTags);
|
||||
map.put("tag", tag);
|
||||
map.put("type", type);
|
||||
|
||||
if (type.equals("all")) {
|
||||
map.put("typeAll", "active");
|
||||
}
|
||||
if (type.equals("hot")) {
|
||||
map.put("typeHot", "active");
|
||||
}
|
||||
if (type.equals("new")) {
|
||||
map.put("typeNew", "active");
|
||||
}
|
||||
map.put("pageSize", pageSiz);
|
||||
map.put("pageTotal", total);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
|
||||
UserInfo user = getUserInfo(request);
|
||||
if (user != null) {
|
||||
map.put("username", user.getUsername());
|
||||
map.put("data", "Jiscuss 用户:" + user.getUsername());
|
||||
}
|
||||
return "index";
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装DiscussionCustom
|
||||
* @param newAllD
|
||||
* @param allDiscussions
|
||||
*/
|
||||
private void setTagAndUserList(List<DiscussionCustom> newAllD, List<Discussion> allDiscussions) {
|
||||
|
||||
List<Integer> discussionIdLsit = new ArrayList<>();
|
||||
for (Discussion dd : allDiscussions) {
|
||||
discussionIdLsit.add(dd.getId());
|
||||
}
|
||||
List<TagCustom> TagCustomList = tagsService.findByDiscussionIdlistId(discussionIdLsit);
|
||||
|
||||
Map<Integer, List<TagCustom>> tagMap = new HashMap<>();
|
||||
for (TagCustom tc : TagCustomList) {
|
||||
List<TagCustom> tagCustomListTemp = new ArrayList<>();
|
||||
if(tagMap.containsKey(tc.getDiscussionId())){
|
||||
tagCustomListTemp = tagMap.get(tc.getDiscussionId());
|
||||
tagCustomListTemp.add(tc);
|
||||
tagMap.put(tc.getDiscussionId(),tagCustomListTemp);
|
||||
}else{
|
||||
tagCustomListTemp.add(tc);
|
||||
tagMap.put(tc.getDiscussionId(),tagCustomListTemp);
|
||||
}
|
||||
}
|
||||
for (Discussion dd : allDiscussions) {
|
||||
DiscussionCustom newdd = new DiscussionCustom();
|
||||
BeanUtils.copyProperties(dd, newdd);
|
||||
@@ -86,42 +154,17 @@ public class UserSystemController extends BaseController {
|
||||
newdd.setRealnameLast(lastUser.getRealname());
|
||||
newdd.setUsernameLast(lastUser.getUsername());
|
||||
}
|
||||
|
||||
//组装tag
|
||||
newdd.setTagList(tagMap.get(dd.getId()));
|
||||
newAllD.add(newdd);
|
||||
}
|
||||
|
||||
logger.info("全部主题==>:{}", allDiscussions);
|
||||
|
||||
Long total = allDiscussionsPage.getTotalElements();
|
||||
|
||||
//获取主题帖子的分页数据
|
||||
List<String> pageNumList = getPageNumList(allDiscussionsPage.getTotalPages());
|
||||
|
||||
//获取所有标签(以后尝试去缓存中取)
|
||||
List<Tag> allTags = tagsService.getAllList();
|
||||
logger.info("全部标签==>:{}", allTags);
|
||||
|
||||
System.out.println(userall.toString());
|
||||
map.put("data", "Jiscuss 用户");
|
||||
map.put("allDiscussions", newAllD);
|
||||
map.put("pageDiscussions", pageNumList);
|
||||
map.put("allTags", allTags);
|
||||
map.put("tag", tag);
|
||||
map.put("type", type);
|
||||
|
||||
map.put("pageSize", pageSiz);
|
||||
map.put("pageTotal", total);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageTotalPages", allDiscussionsPage.getTotalPages());
|
||||
UserInfo user = getUserInfo(request);
|
||||
if (user != null) {
|
||||
map.put("username", user.getUsername());
|
||||
map.put("data", "Jiscuss 用户:" + user.getUsername());
|
||||
}
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页信息
|
||||
* @param size
|
||||
* @return
|
||||
*/
|
||||
private List<String> getPageNumList(int size) {
|
||||
List<String> pageNumList = new ArrayList<String>();
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -130,14 +173,14 @@ public class UserSystemController extends BaseController {
|
||||
return pageNumList;
|
||||
}
|
||||
|
||||
//登录页
|
||||
@GetMapping("/test")
|
||||
public String test() {
|
||||
return "test";
|
||||
}
|
||||
|
||||
|
||||
//登录页
|
||||
/**
|
||||
* 登录页
|
||||
* @param error
|
||||
* @param logout
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/login")
|
||||
public String login(@RequestParam(value = "error", required = false) String error,
|
||||
@RequestParam(value = "logout", required = false) String logout, ModelMap map) {
|
||||
@@ -154,7 +197,44 @@ public class UserSystemController extends BaseController {
|
||||
}
|
||||
|
||||
|
||||
//注册
|
||||
/**
|
||||
* 注册提交
|
||||
* @param username
|
||||
* @param email
|
||||
* @param password
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/registerDo")
|
||||
public String registerDo(@RequestParam String username, @RequestParam String email,
|
||||
@RequestParam String password, ModelMap map) {
|
||||
//验证用户名是否存在
|
||||
if (null != usersService.getByUsername(username)) {
|
||||
map.put("msg", "用户已存在,请重试!");
|
||||
return "register";
|
||||
} else {
|
||||
User user = new User();
|
||||
|
||||
user.setEmail(email);
|
||||
user.setPassword(password);
|
||||
user.setUsername(username);
|
||||
user.setRealname(username);
|
||||
user.setJoinTime(new Date());
|
||||
User userInsert = usersService.insert(user);
|
||||
map.put("msg", "注册成功,请登陆!");
|
||||
return "login";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册页面
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/register")
|
||||
public String register() {
|
||||
return "register";
|
||||
}
|
||||
|
||||
|
||||
//获取设置信息
|
||||
|
||||
|
||||
Reference in New Issue
Block a user