diff --git a/pom.xml b/pom.xml index 57b3d437aebb07d91bbe18ec868046345fb42617..e3ed399f7b5b0c45597a45653a5db260d6b998d4 100644 --- a/pom.xml +++ b/pom.xml @@ -11,6 +11,7 @@ com.test community 0.0.1-SNAPSHOT + jar 1.8 diff --git a/src/main/java/com/test/community/CommunityServletInitializer.java b/src/main/java/com/test/community/CommunityServletInitializer.java new file mode 100644 index 0000000000000000000000000000000000000000..3eb150dd39e77d2c74921b6f1061eece7db11b25 --- /dev/null +++ b/src/main/java/com/test/community/CommunityServletInitializer.java @@ -0,0 +1,16 @@ +package com.test.community; + +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +/** + * @author chenjunji + * @version 1.0 + * @description: TODO + * @since 2023/5/3 16:13 + */ +public class CommunityServletInitializer extends SpringBootServletInitializer{ + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){ + return builder.sources(CommunityApplication.class); + } +} diff --git a/src/main/java/com/test/community/controller/CommentController.java b/src/main/java/com/test/community/controller/CommentController.java index c7c6092def11808b9ec93bb0711bce522a1da8ad..e3292f06022d143d67ff1587660c7d3f0fd1420c 100644 --- a/src/main/java/com/test/community/controller/CommentController.java +++ b/src/main/java/com/test/community/controller/CommentController.java @@ -4,6 +4,7 @@ import com.test.community.Event.EventProducer; import com.test.community.entity.Comment; import com.test.community.entity.DiscussPost; import com.test.community.entity.Event; +import com.test.community.entity.Page; import com.test.community.service.CommentService; import com.test.community.service.DiscussPostService; import com.test.community.service.LikeService; @@ -46,7 +47,6 @@ public class CommentController implements CommunityConstant { @Autowired private LikeService likeService; - //@RequestMapping(path = "/add/{discussPostId}",method = RequestMethod.POST) @PostMapping("/add/{discussPostId}") @ResponseBody public String addComment(@PathVariable("discussPostId") int discussPostId, Comment comment, @RequestParam(value = "file",required = false) List fileList){ @@ -59,7 +59,6 @@ public class CommentController implements CommunityConstant { comment.setUserId(hostHolder.getUser().getId());//统一处理用户没登陆的情况 comment.setStatus(0); comment.setCreateTime(new Date()); - //处理图片 if (fileList!=null){ List urlList = new ArrayList<>(); @@ -80,7 +79,6 @@ public class CommentController implements CommunityConstant { }else { comment.setUrl(""); } - commentService.addComment(comment); //触发评论事件 Event event = new Event() @@ -108,12 +106,81 @@ public class CommentController implements CommunityConstant { .setEntityType(ENTITY_TYPE_POST) .setEntityId(discussPostId); eventProducer.handleEvent(event); + //计算帖子分数 + String redisKey = RedisKeyUtil.getPostScoreKey(); + redisTemplate.opsForSet().add(redisKey,discussPostId); + } + DiscussPost discussPost = discussPostService.findDiscussPostById(discussPostId); + Page page = new Page(); + page.setLimit(5); + page.setRows(discussPost.getCommentCount()); + return CommunityUtil.getJSONString(0,""+page.getTotal()); + } + + @PostMapping("/addReplay/{discussPostId}/{current}") + public String addReplayComment(@PathVariable("discussPostId") int discussPostId,@PathVariable("current") int current ,Comment comment, @RequestParam(value = "file",required = false) List fileList){ + if ("".equals(comment.getContent())){ + return CommunityUtil.getJSONString(403,"内容不能为空"); + } + if(hostHolder.getUser()==null){ + return CommunityUtil.getJSONString(403,"小伙子你还没登陆"); + } + comment.setUserId(hostHolder.getUser().getId());//统一处理用户没登陆的情况 + comment.setStatus(0); + comment.setCreateTime(new Date()); + //处理图片 + if (fileList!=null){ + List urlList = new ArrayList<>(); + for (MultipartFile file:fileList){ + String fileName = file.getOriginalFilename(); + String suffix = fileName.substring(fileName.lastIndexOf(".")); + fileName = CommunityUtil.generateUUID()+suffix; + try { + String url = OssFileUtil.uploadAliyun(file,fileName); + urlList.add(url); + } catch (IOException e) { + log.error("上传图片失败"+e); + throw new RuntimeException("上传文件失败,服务器发生异常",e); + } + } + String urls = String.valueOf(urlList).substring(1,urlList.toString().length()-1); + comment.setUrl(urls); + }else { + comment.setUrl(""); + } + commentService.addComment(comment); + //触发评论事件 + Event event = new Event() + .setTopic(TOPIC_COMMENT) + .setUserId(hostHolder.getUser().getId()) + .setEntityType(comment.getEntityType()) + .setEntityId(comment.getEntityId()) + .setData("discussPostId",discussPostId); + + if (comment.getEntityType() == ENTITY_TYPE_POST) { + DiscussPost target = discussPostService.findDiscussPostById(comment.getEntityId()); + event.setEntityUserId(target.getUserId()); + } else if (comment.getEntityType() == ENTITY_TYPE_COMMENT) { + Comment target = commentService.findCommentById(comment.getEntityId()); + event.setEntityUserId(target.getUserId()); + } + eventProducer.handleEvent(event); + + // 回复帖子相当于更改了帖子信息,需要触发事件 以便更新到es + if (comment.getEntityType() ==ENTITY_TYPE_POST){ + //触发发帖事件 + event = new Event() + .setTopic(TOPIC_PUBLISH) + .setUserId(comment.getUserId()) + .setEntityType(ENTITY_TYPE_POST) + .setEntityId(discussPostId); + eventProducer.handleEvent(event); //计算帖子分数 String redisKey = RedisKeyUtil.getPostScoreKey(); redisTemplate.opsForSet().add(redisKey,discussPostId); } - return CommunityUtil.getJSONString(0,"发送成功"); + return "redirect:/discuss/replay/" + discussPostId+"/"+comment.getEntityId()+"/"+current; } } diff --git a/src/main/java/com/test/community/controller/DataController.java b/src/main/java/com/test/community/controller/DataController.java index c37e73917ab2802a2939ff3d8a67a79a6481aab4..8238611cd3980ca8c5c49dceddad4b9c05cade65 100644 --- a/src/main/java/com/test/community/controller/DataController.java +++ b/src/main/java/com/test/community/controller/DataController.java @@ -22,7 +22,7 @@ public class DataController { //统计页面 @RequestMapping(path = "/data",method = {RequestMethod.POST,RequestMethod.GET}) public String getDataPage(){ - return "/site/admin/data"; + return "site/admin/data"; } //统计网站uv diff --git a/src/main/java/com/test/community/controller/DiscussPostController.java b/src/main/java/com/test/community/controller/DiscussPostController.java index 9f7d7d60188ffb87661220603455864f58beb81d..dd4d47f7312ddeddaa9c600f6e1347809b14ff9d 100644 --- a/src/main/java/com/test/community/controller/DiscussPostController.java +++ b/src/main/java/com/test/community/controller/DiscussPostController.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; import java.io.IOException; import java.util.*; @@ -88,8 +89,6 @@ public class DiscussPostController implements CommunityConstant { discussPost.setContent(content); discussPost.setCreateTime(new Date()); discussPostService.addDiscussPosts(discussPost); - - //触发发帖事件 Event event = new Event() .setTopic(TOPIC_PUBLISH) @@ -97,17 +96,16 @@ public class DiscussPostController implements CommunityConstant { .setEntityType(ENTITY_TYPE_POST) .setEntityId(discussPost.getId()); eventProducer.handleEvent(event); - // 报错的情况,将来统一处理. return CommunityUtil.getJSONString(0, "发布成功!"); } @RequestMapping(path = "/detail/getReply",method = RequestMethod.GET) public String getReply(){ - return "/site/discuss-detail :: replyList"; + return "site/discuss-detail :: replyList"; } - @RequestMapping(path = "/detail/{discussPostId}",method = RequestMethod.GET) + @GetMapping ("/detail/{discussPostId}") public String getDiscussPost(@PathVariable("discussPostId") int discussPostId, Model model, Page page){ //帖子 DiscussPost discussPost = discussPostService.findDiscussPostById(discussPostId); @@ -198,13 +196,104 @@ public class DiscussPostController implements CommunityConstant { } } commentMap.put("replys",replyVoList); + commentMap.put("replysNumber",replyVoList.size()); int replyCount = commentService.findCommentCount(ENTITY_TYPE_COMMENT, comment.getId()); commentMap.put("replyCount",replyCount); commentVoList.add(commentMap); } } model.addAttribute("comments", commentVoList); - return "/site/discuss-detail"; + return "site/discuss-detail"; + } + + + /** + * 获取评论的回复的页面(局部) + * @param discussPostId + * @param model + * @param page + * @return + */ + @GetMapping("/replay/{discussPostId}/{commentId}/{current}") + public String getMyDiscussPost(@PathVariable("discussPostId") int discussPostId, @PathVariable("commentId") int commentId, Model model, Page page,@PathVariable("current") int current){ + //帖子 + DiscussPost discussPost = discussPostService.findDiscussPostById(discussPostId); + model.addAttribute("post",discussPost); + //评论分页信息 + page.setCurrent(current); + page.setLimit(5); + page.setPath("/discuss/detail/"+discussPostId); + page.setRows(discussPost.getCommentCount()); + long likeCount=0; + long likeStatus=0; + + List commentList = commentService.findCommentByEntity( + ENTITY_TYPE_POST,discussPost.getId(),page.getOffset(),page.getLimit()); + //评论的VO(显示对象的)列表 + List> commentVoList = new ArrayList<>(); + if (commentList != null){ + for(Comment comment : commentList){ + //一个评论VO + Map commentMap = new HashMap<>(); + //评论 + commentMap.put("comment",comment); + //评论图片 + if (comment.getUrl()!=null){ + String[] urls = comment.getUrl().split(","); + List urlList = new ArrayList<>(Arrays.asList(urls)); + commentMap.put("urlList",urlList); + } + //作者 + commentMap.put("user",userService.findUserById(comment.getUserId())); + //帖子评论点赞 + likeCount = likeService.findEntityLikeCount(ENTITY_TYPE_COMMENT,comment.getId()); + commentMap.put("likeCount",likeCount); + //点赞状态 + likeStatus = hostHolder.getUser() == null? 0: + likeService.findEntityLikeStatus(hostHolder.getUser().getId(),ENTITY_TYPE_COMMENT,comment.getId()); + commentMap.put("likeStatus",likeStatus); + //回复列表 + List replyList = commentService.findCommentByEntity( + ENTITY_TYPE_COMMENT,comment.getId(),0,Integer.MAX_VALUE); + //回复的显示列表 + List> replyVoList = new ArrayList<>(); + if (replyList != null){ + for(Comment reply : replyList){ + //一个回复 + Map replyMap = new HashMap<>(); + //回复 + replyMap.put("reply",reply); + //回复的图片 + if (reply.getUrl()!=null){ + String[] urls = reply.getUrl().split(","); + List urlList = new ArrayList<>(Arrays.asList(urls)); + replyMap.put("replyUrl",urlList); + } + //作者 + replyMap.put("user",userService.findUserById(reply.getUserId())); + //回复的目标(对哪个评论进行回复) + User target = reply.getTargetId() == 0 ? null : userService.findUserById(reply.getTargetId()); + replyMap.put("target",target); + // 点赞数量 + likeCount = likeService.findEntityLikeCount(ENTITY_TYPE_COMMENT, reply.getId()); + replyMap.put("likeCount", likeCount); + // 点赞状态 + likeStatus = hostHolder.getUser() == null ? 0 : + likeService.findEntityLikeStatus(hostHolder.getUser().getId(), ENTITY_TYPE_COMMENT, reply.getId()); + replyMap.put("likeStatus", likeStatus); + replyVoList.add(replyMap); + } + } + commentMap.put("replys",replyVoList); + commentMap.put("replysNumber",replyVoList.size()); + int replyCount = commentService.findCommentCount(ENTITY_TYPE_COMMENT, comment.getId()); + commentMap.put("replyCount",replyCount); + commentVoList.add(commentMap); + } + } + + model.addAttribute("comments", commentVoList); + return "site/discuss-detail :: repay-reload"; } // 置顶/取消置顶 帖子 类型为 1 为置顶帖子 diff --git a/src/main/java/com/test/community/controller/FollowController.java b/src/main/java/com/test/community/controller/FollowController.java index 93aba7d66beb070dc1a375c60ce24acea84e7b4b..4cf7bae9ce4a927d2942928d0826e38bbf931e2f 100644 --- a/src/main/java/com/test/community/controller/FollowController.java +++ b/src/main/java/com/test/community/controller/FollowController.java @@ -85,7 +85,7 @@ public class FollowController implements CommunityConstant { } model.addAttribute("users", userList); - return "/site/followee"; + return "site/followee"; } @RequestMapping(path = "/followers/{userId}", method = RequestMethod.GET) @@ -110,7 +110,7 @@ public class FollowController implements CommunityConstant { } model.addAttribute("users", userList); - return "/site/follower"; + return "site/follower"; } private boolean hasFollowed(int userId) { diff --git a/src/main/java/com/test/community/controller/HomeController.java b/src/main/java/com/test/community/controller/HomeController.java index 7966b5c5158e38ae20541cc29f8c547cd2d9c70d..d974501afaaaa49cd52e2f46e11ac6c759aa712d 100644 --- a/src/main/java/com/test/community/controller/HomeController.java +++ b/src/main/java/com/test/community/controller/HomeController.java @@ -11,6 +11,7 @@ import com.test.community.util.CommunityConstant; 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.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @@ -32,6 +33,11 @@ public class HomeController implements CommunityConstant { @Autowired private LikeService likeService; + @GetMapping("/") + public String root(){ + return "forward:/index"; + } + @RequestMapping(path = "/index", method = RequestMethod.GET) //响应的是网页所以不用@ResponseBody public String getIndexPage(Model model, Page page, @@ -56,18 +62,18 @@ public class HomeController implements CommunityConstant { } model.addAttribute("discussPosts",discussPosts); model.addAttribute("orderByWay",orderByWay); - return "/index"; + return "index"; } //重定向错误页面,此请求目的是 可以返回json 不单单是靠服务器只返回页面 @RequestMapping(path = "/error", method = RequestMethod.GET) public String getErrorPage() { - return "/error/500"; + return "error/500"; } // 拒绝访问时的提示页面 @RequestMapping(path = "/denied", method = RequestMethod.GET) public String getDeniedPage() { - return "/error/404"; + return "error/404"; } } diff --git a/src/main/java/com/test/community/controller/LoginController.java b/src/main/java/com/test/community/controller/LoginController.java index 8cee596f93b68a82e33eba077e4daec0e00a8307..61e057ca1e318e9b6071cd24cb108f2f79beb822 100644 --- a/src/main/java/com/test/community/controller/LoginController.java +++ b/src/main/java/com/test/community/controller/LoginController.java @@ -2,6 +2,7 @@ package com.test.community.controller; import com.google.code.kaptcha.Producer; import com.test.community.entity.User; +import com.test.community.service.ElasticSearchService; import com.test.community.service.UserService; import com.test.community.util.*; import org.apache.commons.lang3.StringUtils; @@ -49,55 +50,59 @@ public class LoginController implements CommunityConstant { @Autowired private RedisTemplate redisTemplate; + @Autowired + private ElasticSearchService elasticSearchService; + @Value("${server.servlet.context-path}") private String contextPath; @GetMapping("/kk") public String kk(){return "/site/kk";} @GetMapping("/chat") - public String chat(){return "/site/chat";} + public String chat(){return "site/chat";} @GetMapping("/authorization") - public String Authorization(){return "/site/authorization";} + public String Authorization(){return "site/authorization";} @GetMapping("/links") - public String links(){return "/site/links";} + public String links(){return "site/links";} @GetMapping("/disclaimer") - public String disclaimer(){return "/site/disclaimer";} + public String disclaimer(){return "site/disclaimer";} @GetMapping("/joinus") - public String joinUs(){return "/site/joinus";} + public String joinUs(){return "site/joinus";} @GetMapping("/cooperation") - public String cooperation(){return "/site/cooperation";} + public String cooperation(){return "site/cooperation";} @RequestMapping(value = "/aboutus",method = RequestMethod.GET) public String aboutUs(){ - return "/site/aboutus"; + return "site/aboutus"; } @RequestMapping(value = "/login",method = RequestMethod.GET) public String getLoginPage(){ - return "/site/login"; + return "site/login"; } @RequestMapping(path = "register",method = RequestMethod.GET) public String getRegisterPage(){ - return "/site/register"; + return "site/register"; } @RequestMapping(path = "/forget",method = RequestMethod.GET) - public String getForgetPage(){return "/site/forget";} + public String getForgetPage(){return "site/forget";} @RequestMapping(path = "/register",method = RequestMethod.POST) public String register(Model model, User user){ Map map = userService.register(user); if(map==null || map.isEmpty()){ + elasticSearchService.saveUser(user); model.addAttribute("msg","注册成功,激活邮件已经到你的邮箱,请尽快去邮箱激活"); model.addAttribute("target","/index"); - return "/site/operate-result"; + return "site/operate-result"; }else if (map.get("mailError")!=null){ model.addAttribute("msg","注册失败,邮件无法发送到你的邮箱"); model.addAttribute("url",map.get("url")); - return "/site/operate-result-fail"; + return "site/operate-result-fail"; } else{ model.addAttribute("usernameMsg",map.get("usernameMsg")); model.addAttribute("passwordMsg",map.get("passwordMsg")); model.addAttribute("emailMsg",map.get("emailMsg")); - return "/site/register"; + return "site/register"; } } //http://localhost:8080/community/activation/100/code @@ -107,6 +112,7 @@ public class LoginController implements CommunityConstant { if (result == ACTIVATION_SUCCESS){ model.addAttribute("msg","账号激活成功可以使用"); model.addAttribute("target","/login"); + }else if(result == ACTIVATION_REPEAT){ model.addAttribute("msg","该账号已经激活,请不要重复激活"); model.addAttribute("target","/index"); @@ -114,7 +120,7 @@ public class LoginController implements CommunityConstant { model.addAttribute("msg","账号激活失败"); model.addAttribute("target","/index"); } - return "/site/operate-result"; + return "site/operate-result"; } @RequestMapping(path="/captcha",method = RequestMethod.GET) @@ -159,7 +165,7 @@ public class LoginController implements CommunityConstant { if (StringUtils.isBlank(captcha) || StringUtils.isBlank(code) || !captcha.equalsIgnoreCase(code)) { model.addAttribute("codeMsg", "验证码不正确!"); - return "/site/login"; + return "site/login"; } //检查账号和密码 @@ -174,7 +180,7 @@ public class LoginController implements CommunityConstant { }else{ model.addAttribute("usernameMsg",map.get("usernameMsg")); model.addAttribute("passwordMsg",map.get("passwordMsg")); - return "/site/login"; + return "site/login"; } } @RequestMapping(path = "/logout", method = RequestMethod.GET) @@ -211,7 +217,7 @@ public class LoginController implements CommunityConstant { String compare = (String) session.getAttribute("code"); if (StringUtils.isBlank(code) || StringUtils.isBlank(code) || !compare.equalsIgnoreCase(code)) { model.addAttribute("codeMsg", "验证码不正确!"); - return "/site/forget"; + return "site/forget"; } //检查账号和密码 Map map = userService.resetPwd(newPassword,email); @@ -221,7 +227,7 @@ public class LoginController implements CommunityConstant { }else { model.addAttribute("newPasswordMsg",map.get("newPasswordMsg")); model.addAttribute("emailMsg",map.get("emailMsg")); - return "/site/forget"; + return "site/forget"; } } diff --git a/src/main/java/com/test/community/controller/MessageController.java b/src/main/java/com/test/community/controller/MessageController.java index 6a52eb676204e8d48b5379fb05f931bba717d543..a7ff5797cc9389d925e1f0efc8e4418874435c28 100644 --- a/src/main/java/com/test/community/controller/MessageController.java +++ b/src/main/java/com/test/community/controller/MessageController.java @@ -51,6 +51,7 @@ public class MessageController implements CommunityConstant { List conversationList = messageService.findConversations( user.getId(), page.getOffset(), page.getLimit()); List> conversations = new ArrayList<>(); + if (conversationList != null){ for (Message message : conversationList){ Map map = new HashMap<>(); @@ -73,7 +74,7 @@ public class MessageController implements CommunityConstant { int noticeUnreadCount = messageService.findNoticeUnreadCount(user.getId(), null); model.addAttribute("noticeUnreadCount", noticeUnreadCount); - return "/site/letter"; + return "site/letter"; } @LoginRequired @@ -118,7 +119,7 @@ public class MessageController implements CommunityConstant { messageService.readMessage(ids); } - return "/site/letter-detail"; + return "site/letter-detail"; } //获取未读私信 @@ -148,7 +149,7 @@ public class MessageController implements CommunityConstant { } //发送私信 @RequestMapping(path = "/letter/send", method = RequestMethod.POST) - @ResponseBody +// @ResponseBody public String sendLetter(String toName, String content, MultipartFile multipartFile) throws IOException { User target = userService.findUserByName(toName); if (target == null) { @@ -165,6 +166,7 @@ public class MessageController implements CommunityConstant { } else { message.setConversationId(message.getToId() + "_" + message.getFromId()); } + String conversationId = message.getConversationId(); if (multipartFile!=null){ String fileName = multipartFile.getOriginalFilename(); try { @@ -184,18 +186,50 @@ public class MessageController implements CommunityConstant { message.setContent(content); message.setCreateTime(new Date()); messageService.addMessage(message); - if (multipartFile!=null){ - MyWebSocketServer.sendInfo("image",String.valueOf(target.getId())); - }else{ - MyWebSocketServer.sendInfo("text",String.valueOf(target.getId())); +// if (multipartFile!=null){ + MyWebSocketServer.sendInfo(conversationId,String.valueOf(target.getId())); +// }else{ +// MyWebSocketServer.sendInfo("text",String.valueOf(target.getId())); +// } + + return "redirect:/letter/" + conversationId; + } + + @GetMapping("/letter/{conversationId}") + public String comments(@PathVariable String conversationId, Model model) { + User user = hostHolder.getUser(); + List letterList=messageService.findLettersNoPage(conversationId); + List letterDeleteList = new ArrayList<>(); + for (Message message:letterList){ + //如果信息表单条数据中 发送用户是此刻登陆用户且状态为3就不展示 + if (message.getFromId()==user.getId()&&message.getStatus()==3||message.getToId()==user.getId()&&message.getStatus()==4){ + letterDeleteList.add(message); + } } + letterList.removeAll(letterDeleteList); - //如果没有报错 就给页面返回一个状态0 - return CommunityUtil.getJSONString(0); + List> letters = new ArrayList<>(); + if (letterList != null){ + for (Message message : letterList){ + Map map = new HashMap<>(); + map.put("letter",message); + map.put("fromUser",userService.findUserById(message.getFromId())); + map.put("toUser",user); + map.put("url",message.getUrl()); + map.put("fileName",message.getFileName()); + map.put("fileSize",message.getFileSize()); + letters.add(map); + } + } + //将数据库里面所有的评论拿出来,回传给前端页面 + model.addAttribute("letters", letters); + //局部刷新的语法。前面是html页面,后面是th:fragment的值 + return "site/letter-detail :: list-unstyled"; } + //发送文件(不是头像) @RequestMapping(path = "/letter/sendFile", method = RequestMethod.POST) - @ResponseBody +// @ResponseBody public String sendFile(String toName, MultipartFile multipartFile) throws IOException { User target = userService.findUserByName(toName); if (target == null) { @@ -212,6 +246,7 @@ public class MessageController implements CommunityConstant { } else { message.setConversationId(message.getToId() + "_" + message.getFromId()); } + String conversationId = message.getConversationId(); String fileName = multipartFile.getOriginalFilename(); String fileSize = formatSize(multipartFile.getSize()); @@ -232,10 +267,11 @@ public class MessageController implements CommunityConstant { } message.setCreateTime(new Date()); messageService.addMessage(message); - MyWebSocketServer.sendInfo("file",String.valueOf(target.getId())); + MyWebSocketServer.sendInfo(conversationId,String.valueOf(target.getId())); + return "redirect:/letter/" + conversationId; //如果没有报错 就给页面返回一个状态0 - return CommunityUtil.getJSONString(0); + //return CommunityUtil.getJSONString(0,conversationId); } //获取文件下载 @@ -273,7 +309,7 @@ public class MessageController implements CommunityConstant { } messageService.deleteMessage(id); //OssFileUtil.deleteAliyun(message.getUrl()); - MyWebSocketServer.sendInfo("delete",String.valueOf(message.getToId())); + MyWebSocketServer.sendInfo(message.getConversationId(),String.valueOf(message.getToId())); return CommunityUtil.getJSONString(0); } @@ -382,7 +418,7 @@ public class MessageController implements CommunityConstant { int noticeUnreadCount = messageService.findNoticeUnreadCount(user.getId(), null); model.addAttribute("noticeUnreadCount", noticeUnreadCount); - return "/site/notice"; + return "site/notice"; } @RequestMapping(path = "/notice/detail/{topic}",method = RequestMethod.GET) @@ -418,7 +454,7 @@ public class MessageController implements CommunityConstant { if (!ids.isEmpty()) { messageService.readMessage(ids); } - return "/site/notice-detail"; + return "site/notice-detail"; } //计算文件大小并返回 diff --git a/src/main/java/com/test/community/controller/SearchController.java b/src/main/java/com/test/community/controller/SearchController.java index 7d43433804a10b65d6549254d6a539d99e5502e1..099fdab901e26dee43e7c3e6ce96749583921a72 100644 --- a/src/main/java/com/test/community/controller/SearchController.java +++ b/src/main/java/com/test/community/controller/SearchController.java @@ -2,7 +2,9 @@ package com.test.community.controller; import com.test.community.entity.DiscussPost; import com.test.community.entity.Page; +import com.test.community.entity.User; import com.test.community.service.ElasticSearchService; +import com.test.community.service.FollowService; import com.test.community.service.LikeService; import com.test.community.service.UserService; import com.test.community.util.CommunityConstant; @@ -12,6 +14,7 @@ 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.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -33,11 +36,15 @@ public class SearchController implements CommunityConstant { @Autowired private LikeService likeService; + @Autowired + private FollowService followService; + @Autowired private RestHighLevelClient restHighLevelClient; + @RequestMapping(path = "/search",method = RequestMethod.GET) - public String search(String keyword, Page page, Model model){ + public String searchDiscuss(String keyword, Page page, Model model){ try { Map searchDiscussPost = elasticSearchService.searchDiscussPost(keyword, page.getOffset(), page.getLimit()); List discussPosts = (List) searchDiscussPost.get("discussPost"); @@ -54,6 +61,7 @@ public class SearchController implements CommunityConstant { } } model.addAttribute("discussPosts",list); + model.addAttribute("count",list.size()); model.addAttribute("keyword",keyword); //分页信息 @@ -63,6 +71,76 @@ public class SearchController implements CommunityConstant { } catch (IOException e) { logger.error("没有数据:"+e.getMessage()); } - return "/site/search"; + return "site/search"; + } + + /** + * 局部刷新获取数据 + * @param keyword + * @param page + * @param model + * @return + */ + @RequestMapping(path = "/search/discuss",method = RequestMethod.GET) + public String searchLocalDiscuss(String keyword, Page page, Model model){ + try { + Map searchDiscussPost = elasticSearchService.searchDiscussPost(keyword, page.getOffset(), page.getLimit()); + List discussPosts = (List) searchDiscussPost.get("discussPost"); + List> list = new ArrayList<>(); + if (discussPosts != null){ + for (DiscussPost post : discussPosts){ + Map map = new HashMap<>(); + //帖子 和 作者 + map.put("post",post); + map.put("user",userService.findUserById(post.getUserId())); + // 点赞数目 + map.put("likeCount",likeService.findEntityLikeCount(ENTITY_TYPE_POST, post.getId())); + list.add(map); + } + } + model.addAttribute("discussPosts",list); + model.addAttribute("count",list.size()); + model.addAttribute("keyword",keyword); + + //分页信息 + long total = (long) searchDiscussPost.get("total"); + page.setPath("/search/?keyword="+keyword); + page.setRows(total==0? 0:total); + } catch (IOException e) { + logger.error("没有数据:"+e.getMessage()); + } + return "site/search :: discuss-frame"; + } + + @RequestMapping(path = "/search/user",method = RequestMethod.GET) + public String searchUser(String keyword, Page page, Model model){ + try { + Map searchUser = elasticSearchService.searchUser(keyword, page.getOffset(), page.getLimit()); + List users = (List) searchUser.get("user"); + List> list = new ArrayList<>(); + if (users != null){ + for (User user : users){ + Map map = new HashMap<>(); + // 用户 + map.put("user",user); + // 用户获得的点赞数目 + map.put("likeCount",likeService.findUserLikeCount(user.getId())); + map.put("followCount",followService.findFolloweeCount(user.getId(), ENTITY_TYPE_USER)); + map.put("fansCount",followService.findFollowerCount(ENTITY_TYPE_USER, user.getId())); + list.add(map); + } + } + model.addAttribute("users",list); + model.addAttribute("count",list.size()); + model.addAttribute("keyword",keyword); + + //分页信息 + long total = (long) searchUser.get("total"); + page.setPath("/search/user?keyword="+keyword); + page.setRows(total==0? 0:total); + } catch (IOException e) { + logger.error("没有数据:"+e.getMessage()); + } + return "site/search::user-frame"; } } diff --git a/src/main/java/com/test/community/controller/UserController.java b/src/main/java/com/test/community/controller/UserController.java index b0064ba4f4b375fd96072fc7d6b3101d39a2f8f9..14f620e2bf6c969ec58111274d084dfacb3fe3fd 100644 --- a/src/main/java/com/test/community/controller/UserController.java +++ b/src/main/java/com/test/community/controller/UserController.java @@ -50,6 +50,8 @@ public class UserController implements CommunityConstant { private CommentService commentService; @Autowired private MessageService messageService; + @Autowired + private ElasticSearchService elasticSearchService; @Value("${community.path.upload}") private String uploadPath; @@ -69,7 +71,7 @@ public class UserController implements CommunityConstant { @RequestMapping(path = "/setting",method = RequestMethod.GET) public String getSetPage(){ - return "/site/setting"; + return "site/setting"; } //将上传图片保存在云服务器 @@ -77,19 +79,19 @@ public class UserController implements CommunityConstant { public String uploadHeader(MultipartFile headerImage, Model model){ if (headerImage == null){ model.addAttribute("error","图片不能为空上传失败"); - return "/site/setting"; + return "site/setting"; } String fileName = headerImage.getOriginalFilename(); if(fileName==null){ model.addAttribute("error","图片名错误"); - return "/site/setting"; + return "site/setting"; } //文件后缀 String suffix = fileName.substring(fileName.lastIndexOf(".")); if (StringUtils.isBlank(suffix)){ model.addAttribute("error","文件格式不正确"); - return "/site/setting"; + return "site/setting"; } //生成随机文件名 @@ -183,11 +185,12 @@ public class UserController implements CommunityConstant { Map map = userService.updatePassword(user.getId(),oldPassword,newPassword); if (map.containsKey("Pwd")) { + elasticSearchService.saveUser(user); return "redirect:/logout"; }else { model.addAttribute("newPasswordMsg",map.get("newPasswordMsg")); model.addAttribute("oldPasswordMsg",map.get("oldPasswordMsg")); - return "/site/setting"; + return "site/setting"; } } // 个人主页 @@ -225,7 +228,7 @@ public class UserController implements CommunityConstant { } model.addAttribute("hasFollowed", hasFollowed); - return "/site/profile"; + return "site/profile"; } @RequestMapping(path = "/my-post/{userId}",method = RequestMethod.GET) @@ -256,7 +259,7 @@ public class UserController implements CommunityConstant { discussPosts.add(map); } } model.addAttribute("discussPosts",discussPosts); - return "/site/my-post"; + return "site/my-post"; } @RequestMapping(path = "/my-reply/{userId}",method = RequestMethod.GET) @@ -282,6 +285,6 @@ public class UserController implements CommunityConstant { comments.add(map); } }model.addAttribute("comments",comments); - return "/site/my-reply"; + return "site/my-reply"; } } diff --git a/src/main/java/com/test/community/dao/MessageMapper.java b/src/main/java/com/test/community/dao/MessageMapper.java index c13e9e5c4c3846a8561547d8877455de1ff0c95e..69b31002efa58f752c52b423d36e5f3da1fc975b 100644 --- a/src/main/java/com/test/community/dao/MessageMapper.java +++ b/src/main/java/com/test/community/dao/MessageMapper.java @@ -51,4 +51,11 @@ public interface MessageMapper { //修改信息状态 int updateFromStatus(Integer[] ids,int status); + + //根据会话id查询最近的一条信息 + Message selectByConversationId(String conversationId, int status); + + Message selectByConversationIdFrom(String conversationId, int status, int userId); + + Message selectByConversationIdTo(String conversationId, int status, int userId); } diff --git a/src/main/java/com/test/community/dao/elasticsearch/UserRepository.java b/src/main/java/com/test/community/dao/elasticsearch/UserRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..32c5db492a9838d85e4668885105539881d43af9 --- /dev/null +++ b/src/main/java/com/test/community/dao/elasticsearch/UserRepository.java @@ -0,0 +1,10 @@ +package com.test.community.dao.elasticsearch; + +import com.test.community.entity.DiscussPost; +import com.test.community.entity.User; +import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends ElasticsearchRepository { +} diff --git a/src/main/java/com/test/community/entity/User.java b/src/main/java/com/test/community/entity/User.java index ae70ac352bf41f11b58f9a5710b25ea17c1ee125..1efbb9a9f5f47f06b058ec7de735c4df4b0c2563 100644 --- a/src/main/java/com/test/community/entity/User.java +++ b/src/main/java/com/test/community/entity/User.java @@ -1,19 +1,37 @@ package com.test.community.entity; import lombok.Data; +import org.springframework.data.annotation.Id; +import org.springframework.data.elasticsearch.annotations.Document; +import org.springframework.data.elasticsearch.annotations.Field; +import org.springframework.data.elasticsearch.annotations.FieldType; +import org.springframework.data.elasticsearch.annotations.Setting; import java.util.Date; @Data +@Setting(shards = 6,replicas = 3) +@Document(indexName = "user" /*, shards = 6, replicas = 3*/) public class User { + @Id private int id; + @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart") private String username; + private String password; + @Field(type = FieldType.Text) private String salt; + @Field(type = FieldType.Text, analyzer = "ik_max_word", searchAnalyzer = "ik_smart") private String email; + @Field(type = FieldType.Integer) private int type; //0-普通用户; 1-超级管理员; 2-版主; + @Field(type = FieldType.Integer) private int status;//0-未激活; 1-已激活 + @Field(type = FieldType.Text) private String activationCode;//激活码 + @Field(type = FieldType.Text) private String headerUrl;//头像地址 + @Field(type = FieldType.Date) private Date createTime; + private String authorizationCode;//邮箱授权码 } diff --git a/src/main/java/com/test/community/service/ElasticSearchService.java b/src/main/java/com/test/community/service/ElasticSearchService.java index d317c7a330ec92f2ca5c2eeb1024c057b9e7e4cf..22f3e4914c0d7d5767e6b3066d06fd0ca02779a1 100644 --- a/src/main/java/com/test/community/service/ElasticSearchService.java +++ b/src/main/java/com/test/community/service/ElasticSearchService.java @@ -1,6 +1,7 @@ package com.test.community.service; import com.test.community.entity.DiscussPost; +import com.test.community.entity.User; import java.io.IOException; import java.util.List; @@ -11,5 +12,11 @@ public interface ElasticSearchService { void deleteDiscussPost(int id); + void saveUser(User user); + + void deleterUser(int id); + Map searchDiscussPost(String keyword, int current, int limit) throws IOException; + + Map searchUser(String keyword, int current, int limit) throws IOException; } diff --git a/src/main/java/com/test/community/service/MessageService.java b/src/main/java/com/test/community/service/MessageService.java index 5f5364a2a3643cfd9c4c5a56203e3166806611a9..6098e54504e43a85647fda45907cc7d12edba8ee 100644 --- a/src/main/java/com/test/community/service/MessageService.java +++ b/src/main/java/com/test/community/service/MessageService.java @@ -8,6 +8,11 @@ public interface MessageService { List findConversations(int userId, int offset, int limit); + /** + * 根据对话id查询最近的一条对话信息 + */ + Message findMessageByConversationId(String conversationId,int status); + int findConversationCount(int userId); List findLetters(String conversationId, int offset, int limit); @@ -49,4 +54,8 @@ public interface MessageService { * @param id */ int deleteRealMessage(int id,int status); + + Message findMessageByConversationIdFrom(String conversationId, int status, int userId); + + Message findMessageByConversationIdTo(String conversationId, int status, int id); } diff --git a/src/main/java/com/test/community/service/impl/CommentServiceImpl.java b/src/main/java/com/test/community/service/impl/CommentServiceImpl.java index bfc997e71fe021022ba8e411aed8f48f57e4f9eb..ebf5afbc08661e8430b069f76e6d474d635e4604 100644 --- a/src/main/java/com/test/community/service/impl/CommentServiceImpl.java +++ b/src/main/java/com/test/community/service/impl/CommentServiceImpl.java @@ -30,6 +30,7 @@ public class CommentServiceImpl implements CommentService, CommunityConstant { return commentMapper.selectCommentsByEntity(entityType,entityId,offset,limit); } + @Override public List findCommentByEntityNoPage(int entityType, int entityId) { return commentMapper.selectCommentsByEntityNoPage(entityType,entityId); diff --git a/src/main/java/com/test/community/service/impl/ElasticSearchServiceImpl.java b/src/main/java/com/test/community/service/impl/ElasticSearchServiceImpl.java index ebcbb266532b883f81c67f4404697e563c32b70d..3d39250751f35e4e8795b4e396519e7d3fdaceba 100644 --- a/src/main/java/com/test/community/service/impl/ElasticSearchServiceImpl.java +++ b/src/main/java/com/test/community/service/impl/ElasticSearchServiceImpl.java @@ -2,7 +2,9 @@ package com.test.community.service.impl; import com.alibaba.fastjson.JSONObject; import com.test.community.dao.elasticsearch.DiscussPostRepository; +import com.test.community.dao.elasticsearch.UserRepository; import com.test.community.entity.DiscussPost; +import com.test.community.entity.User; import com.test.community.service.ElasticSearchService; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; @@ -30,6 +32,9 @@ public class ElasticSearchServiceImpl implements ElasticSearchService { @Autowired private DiscussPostRepository discussPostRepository; + @Autowired + private UserRepository userRepository; + @Autowired @Qualifier("elasticClient") private RestHighLevelClient restHighLevelClient; @@ -41,6 +46,16 @@ public class ElasticSearchServiceImpl implements ElasticSearchService { discussPostRepository.deleteById(id); } + @Override + public void saveUser(User user) { + userRepository.save(user); + } + + @Override + public void deleterUser(int id) { + userRepository.deleteById(id); + } + public Map searchDiscussPost(String keyword, int current, int limit) throws IOException { Map map = new HashMap();//目的只是为了返回两个值从而采用map SearchRequest searchRequest = new SearchRequest("discusspost");//discusspost是索引名,就是表名 @@ -51,8 +66,8 @@ public class ElasticSearchServiceImpl implements ElasticSearchService { highlightBuilder.field("title"); highlightBuilder.field("content"); highlightBuilder.requireFieldMatch(false); - highlightBuilder.preTags(""); // - highlightBuilder.postTags(""); // + highlightBuilder.preTags(""); // + highlightBuilder.postTags(""); // //构建搜索条件 SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() @@ -82,11 +97,57 @@ public class ElasticSearchServiceImpl implements ElasticSearchService { if (contentField != null) { discussPost.setContent(contentField.getFragments()[0].toString()); } -// list.add(discussPost); } map.put("discussPost",list); map.put("total",total); return map; } + + + public Map searchUser(String keyword, int current, int limit) throws IOException { + Map map = new HashMap();//目的只是为了返回两个值从而采用map + SearchRequest searchRequest = new SearchRequest("user");//user是索引名,就是表名 + + //高亮 + HighlightBuilder highlightBuilder = new HighlightBuilder(); + + highlightBuilder.field("username"); + highlightBuilder.field("email"); + highlightBuilder.requireFieldMatch(false); + highlightBuilder.preTags(""); // + highlightBuilder.postTags(""); // + + //构建搜索条件 + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() + .query(QueryBuilders.multiMatchQuery(keyword, "username", "email")) + .sort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC)) + .from(current)// 指定从哪条开始查询 + .size(limit)// 需要查出的总记录条数 + .highlighter(highlightBuilder);//高亮 + + searchRequest.source(searchSourceBuilder); + SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); + + List list = new ArrayList<>(); + long total = searchResponse.getHits().getTotalHits().value; + + for (SearchHit hit : searchResponse.getHits().getHits()) { + User user = JSONObject.parseObject(hit.getSourceAsString(), User.class); + + // 处理高亮显示的结果 + HighlightField usernameField = hit.getHighlightFields().get("username"); + if (usernameField != null) { + user.setUsername(usernameField.getFragments()[0].toString()); + } + HighlightField emailField = hit.getHighlightFields().get("email"); + if (emailField != null) { + user.setEmail(emailField.getFragments()[0].toString()); + } + list.add(user); + } + map.put("user",list); + map.put("total",total); + return map; + } } diff --git a/src/main/java/com/test/community/service/impl/MessageServiceImpl.java b/src/main/java/com/test/community/service/impl/MessageServiceImpl.java index a40a71343185dcd84815d84b8d3c0d8362368b4b..da7e641c033cb245497f02e9a9084c0f8caf36a4 100644 --- a/src/main/java/com/test/community/service/impl/MessageServiceImpl.java +++ b/src/main/java/com/test/community/service/impl/MessageServiceImpl.java @@ -25,6 +25,11 @@ public class MessageServiceImpl implements MessageService { return messageMapper.selectConversations(userId, offset, limit); } + @Override + public Message findMessageByConversationId(String conversationId, int status) { + return messageMapper.selectByConversationId(conversationId,status); + } + @Override public int findConversationCount(int userId) { return messageMapper.selectConversationCount(userId); @@ -60,6 +65,7 @@ public class MessageServiceImpl implements MessageService { return messageMapper.insertMessage(message); } + @Override public int readMessage(List ids) { return messageMapper.updateStatus(ids,1); @@ -106,4 +112,14 @@ public class MessageServiceImpl implements MessageService { return messageMapper.updateFromStatus(integers,status); } + @Override + public Message findMessageByConversationIdFrom(String conversationId, int status, int userId) { + return messageMapper.selectByConversationIdFrom(conversationId,status,userId); + } + + @Override + public Message findMessageByConversationIdTo(String conversationId, int status, int userId) { + return messageMapper.selectByConversationIdTo(conversationId,status,userId); + } + } diff --git a/src/main/java/com/test/community/util/MyWebSocketServer.java b/src/main/java/com/test/community/util/MyWebSocketServer.java index cec481f365d34a8042a6aea36eaed357795deb72..c8f29eeff77d57fb07ce42c8e7fd082d8b82d67b 100644 --- a/src/main/java/com/test/community/util/MyWebSocketServer.java +++ b/src/main/java/com/test/community/util/MyWebSocketServer.java @@ -117,6 +117,10 @@ public class MyWebSocketServer { this.session.getBasicRemote().sendText(message); } + public void sendObject(Object object) throws EncodeException, IOException { + this.session.getBasicRemote().sendObject(object); + } + /** * 发送自定义消息 diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties new file mode 100644 index 0000000000000000000000000000000000000000..d64fae7b9ebbde051ef224671845d3abe9ad645b --- /dev/null +++ b/src/main/resources/application-dev.properties @@ -0,0 +1,92 @@ +server.port=8080 +server.servlet.context-path= + +spring.thymeleaf.cache=false + +# DataSourceProperties +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://localhost:3306/community?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai +spring.datasource.username=root +spring.datasource.password=0417 +spring.datasource.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.hikari.maximum-pool-size=15 +spring.datasource.hikari.minimum-idle=5 +spring.datasource.hikari.idle-timeout=30000 + +spring.servlet.multipart.max-file-size = -1 +spring.servlet.multipart.max-request-size=-1 + + +# MybatisProperties +mybatis.mapper-locations=classpath:mapper/*.xml +mybatis.type-aliases-package=com.test.community.entity +mybatis.configuration.useGeneratedKeys=true +mybatis.configuration.mapUnderscoreToCamelCase=true + +# logger +logging.level.com.test.community=debug + +# MailProperties +spring.mail.host=smtp.qq.com +spring.mail.port=465 +spring.mail.username=1173998166@qq.com +spring.mail.password=ulieztgbksnohgfa +spring.mail.protocol=smtps +#spring.mail.properties.mail.smtp.ssl.enable=true +#spring.mail.properties.mail.smtp.auth=true + +# ncpytyvykyrddcij ulieztgbksnohgfa + +# community +community.path.domain=http://localhost:8080 +community.path.upload=E:/work/data/upload + +# RedisProperties +spring.redis.database=11 +spring.redis.host=192.168.128.140 +spring.redis.port=6379 + +# KafkaProperties ??????? server.properties ??????? +spring.kafka.bootstrap-servers=192.168.128.140:9092 +# ?????Id +spring.kafka.consumer.group-id=test-consumer-group +spring.kafka.consumer.enable-auto-commit=true +# ???????3? +spring.kafka.consumer.auto-commit-interval=3000 + +# ElasticsearchProperties +#selasticsearch.host=192.168.128.131 +#elasticsearch.port=9200 +spring.elasticsearch.uris=192.168.128.140:9200 + +# TaskExecutionProperties +#spring.task.execution.pool.core-size=5 +#spring.task.execution.pool.max-size=15 +#spring.task.execution.pool.queue-capacity=100 + +# TaskSchedulingProperties +#spring.task.scheduling.pool.size=5 + +# QuartzProperties +spring.quartz.job-store-type=jdbc +spring.quartz.scheduler-name=communityScheduler +spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO +spring.quartz.properties.org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore +spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate +spring.quartz.properties.org.quartz.jobStore.isClustered=true +spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool +spring.quartz.properties.org.quartz.threadPool.threadCount=5 + +# aliyun +aliyun.endpoint=oss-cn-chengdu.aliyuncs.com +aliyun.sccess-key-id=LTAI5tG5dJcVaNrQQXhbURCi +aliyun.sccess-key-secret=eD23Am9J3Xw0tUwjHAxRVTBBVzytmo +aliyun.bucket-name=community-test1 + +# caffeine +caffeine.posts.max-size=15 +caffeine.posts.expire-seconds=180 + +# actuator +management.endpoints.web.exposure.include=* +management.endpoints.web.exposure.exclude=info,caches \ No newline at end of file diff --git a/src/main/resources/application-produce.properties b/src/main/resources/application-produce.properties new file mode 100644 index 0000000000000000000000000000000000000000..6c90b6e739347b7809670131d01573ae966246ed --- /dev/null +++ b/src/main/resources/application-produce.properties @@ -0,0 +1,91 @@ +server.port=8080 +server.servlet.context-path= + +spring.thymeleaf.cache=true + +# DataSourceProperties +spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver +spring.datasource.url=jdbc:mysql://47.99.157.147:3306/community?characterEncoding=utf-8&serverTimezone=Asia/Shanghai +spring.datasource.username=root +spring.datasource.password=Cjjsr010417 +spring.datasource.type=com.zaxxer.hikari.HikariDataSource +spring.datasource.hikari.maximum-pool-size=15 +spring.datasource.hikari.minimum-idle=5 +spring.datasource.hikari.idle-timeout=30000 + +spring.servlet.multipart.max-file-size = -1 +spring.servlet.multipart.max-request-size=-1 + + +# MybatisProperties +mybatis.mapper-locations=classpath:mapper/*.xml +mybatis.type-aliases-package=com.test.community.entity +mybatis.configuration.useGeneratedKeys=true +mybatis.configuration.mapUnderscoreToCamelCase=true + +# logger +logging.level.com.test.community=debug + +# MailProperties +spring.mail.host=smtp.qq.com +spring.mail.port=465 +spring.mail.username=1173998166@qq.com +spring.mail.password=ulieztgbksnohgfa +spring.mail.protocol=smtps +spring.mail.properties.mail.smtp.ssl.enable=true +spring.mail.properties.mail.smtp.socketFactory.port=465 +#spring.mail.properties.mail.smtp.auth=true + +# community +community.path.domain=http://47.99.157.147 +community.path.upload=/tmp/uploads + +# RedisProperties +spring.redis.database=11 +spring.redis.host=localhost +spring.redis.port=6379 + +# KafkaProperties ??????? server.properties ??????? +spring.kafka.bootstrap-servers=localhost:9092 +# ?????Id +spring.kafka.consumer.group-id=test-consumer-group +spring.kafka.consumer.enable-auto-commit=true +# ???????3? +spring.kafka.consumer.auto-commit-interval=3000 + +# ElasticsearchProperties +#selasticsearch.host=192.168.128.131 +#elasticsearch.port=9200 +spring.elasticsearch.uris=localhost:9200 + +# TaskExecutionProperties +#spring.task.execution.pool.core-size=5 +#spring.task.execution.pool.max-size=15 +#spring.task.execution.pool.queue-capacity=100 + +# TaskSchedulingProperties +#spring.task.scheduling.pool.size=5 + +# QuartzProperties +spring.quartz.job-store-type=jdbc +spring.quartz.scheduler-name=communityScheduler +spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO +spring.quartz.properties.org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore +spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate +spring.quartz.properties.org.quartz.jobStore.isClustered=true +spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool +spring.quartz.properties.org.quartz.threadPool.threadCount=5 + +# aliyun +aliyun.endpoint=oss-cn-chengdu.aliyuncs.com +aliyun.sccess-key-id=LTAI5tG5dJcVaNrQQXhbURCi +aliyun.sccess-key-secret=eD23Am9J3Xw0tUwjHAxRVTBBVzytmo +aliyun.bucket-name=community-test1 + +# caffeine +caffeine.posts.max-size=15 +caffeine.posts.expire-seconds=180 + +# actuator +management.endpoints.web.exposure.include=* +management.endpoints.web.exposure.exclude=info,caches \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 0149668488e403ca5a64dfd7f5de02f147d05c6f..8067d1b500a500f75fc722251a9d97343e9ba328 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,92 +1,5 @@ -server.port=8080 -server.servlet.context-path=/community +# profile +spring.profiles.active=dev -spring.thymeleaf.cache=false - -# DataSourceProperties -spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver -spring.datasource.url=jdbc:mysql://localhost:3306/community?characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai -spring.datasource.username=root -spring.datasource.password=0417 -spring.datasource.type=com.zaxxer.hikari.HikariDataSource -spring.datasource.hikari.maximum-pool-size=15 -spring.datasource.hikari.minimum-idle=5 -spring.datasource.hikari.idle-timeout=30000 - -spring.servlet.multipart.max-file-size = -1 -spring.servlet.multipart.max-request-size=-1 - - -# MybatisProperties -mybatis.mapper-locations=classpath:mapper/*.xml -mybatis.type-aliases-package=com.test.community.entity -mybatis.configuration.useGeneratedKeys=true -mybatis.configuration.mapUnderscoreToCamelCase=true - -# logger -logging.level.com.test.community=debug - -# MailProperties -spring.mail.host=smtp.qq.com -spring.mail.port=465 -spring.mail.username=1173998166@qq.com -spring.mail.password=ulieztgbksnohgfa -spring.mail.protocol=smtps -#spring.mail.properties.mail.smtp.ssl.enable=true -#spring.mail.properties.mail.smtp.auth=true - -# ncpytyvykyrddcij ulieztgbksnohgfa - -# community -community.path.domain=http://localhost:8080 -community.path.upload=E:/work/data/upload - -# RedisProperties -spring.redis.database=11 -spring.redis.host=192.168.128.136 -spring.redis.port=6379 - -# KafkaProperties ??????? server.properties ??????? -spring.kafka.bootstrap-servers=192.168.128.136:9092 -# ?????Id -spring.kafka.consumer.group-id=test-consumer-group -spring.kafka.consumer.enable-auto-commit=true -# ???????3? -spring.kafka.consumer.auto-commit-interval=3000 - -# ElasticsearchProperties -#selasticsearch.host=192.168.128.131 -#elasticsearch.port=9200 -spring.elasticsearch.uris=192.168.128.136:9200 - -# TaskExecutionProperties -#spring.task.execution.pool.core-size=5 -#spring.task.execution.pool.max-size=15 -#spring.task.execution.pool.queue-capacity=100 - -# TaskSchedulingProperties -#spring.task.scheduling.pool.size=5 - -# QuartzProperties -spring.quartz.job-store-type=jdbc -spring.quartz.scheduler-name=communityScheduler -spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO -spring.quartz.properties.org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore -spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.StdJDBCDelegate -spring.quartz.properties.org.quartz.jobStore.isClustered=true -spring.quartz.properties.org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool -spring.quartz.properties.org.quartz.threadPool.threadCount=5 - -# aliyun -aliyun.endpoint=oss-cn-chengdu.aliyuncs.com -aliyun.sccess-key-id=LTAI5tG5dJcVaNrQQXhbURCi -aliyun.sccess-key-secret=eD23Am9J3Xw0tUwjHAxRVTBBVzytmo -aliyun.bucket-name=community-test1 - -# caffeine -caffeine.posts.max-size=15 -caffeine.posts.expire-seconds=180 - -# actuator -management.endpoints.web.exposure.include=* -management.endpoints.web.exposure.exclude=info,caches \ No newline at end of file +#logback +logging.config=classpath:logback-spring-${spring.profiles.active}.xml \ No newline at end of file diff --git a/src/main/resources/logback-spring-dev.xml b/src/main/resources/logback-spring-dev.xml new file mode 100644 index 0000000000000000000000000000000000000000..de9a4af9ef985daeb5c112d7bc31f3de2ff4d9d2 --- /dev/null +++ b/src/main/resources/logback-spring-dev.xml @@ -0,0 +1,93 @@ + + + community + + + + + + ${LOG_PATH}/${APPDIR}/log_error.log + + ${LOG_PATH}/${APPDIR}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + error + ACCEPT + DENY + + + + + + ${LOG_PATH}/${APPDIR}/log_warn.log + + ${LOG_PATH}/${APPDIR}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + warn + ACCEPT + DENY + + + + + + ${LOG_PATH}/${APPDIR}/log_info.log + + ${LOG_PATH}/${APPDIR}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + info + ACCEPT + DENY + + + + + + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + debug + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring-produce.xml b/src/main/resources/logback-spring-produce.xml new file mode 100644 index 0000000000000000000000000000000000000000..4dcdeade03df9923ab9e73dba9fff18b5df797cb --- /dev/null +++ b/src/main/resources/logback-spring-produce.xml @@ -0,0 +1,93 @@ + + + community + + + + + + ${LOG_PATH}/${APPDIR}/log_error.log + + ${LOG_PATH}/${APPDIR}/error/log-error-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + error + ACCEPT + DENY + + + + + + ${LOG_PATH}/${APPDIR}/log_warn.log + + ${LOG_PATH}/${APPDIR}/warn/log-warn-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + warn + ACCEPT + DENY + + + + + + ${LOG_PATH}/${APPDIR}/log_info.log + + ${LOG_PATH}/${APPDIR}/info/log-info-%d{yyyy-MM-dd}.%i.log + + 5MB + + 30 + + true + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + info + ACCEPT + DENY + + + + + + + %d %level [%thread] %logger{10} [%file:%line] %msg%n + utf-8 + + + debug + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 3fe47ba029a01c62799de8736c3e5d6542b7d2a8..de9a4af9ef985daeb5c112d7bc31f3de2ff4d9d2 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -1,7 +1,7 @@ community - + diff --git a/src/main/resources/mapper/message-mapper.xml b/src/main/resources/mapper/message-mapper.xml index 18d2355bb99e06465985704b7fe6576638562871..43da2e18b14373e48384d3a7ce23c509c0f4a856 100644 --- a/src/main/resources/mapper/message-mapper.xml +++ b/src/main/resources/mapper/message-mapper.xml @@ -16,11 +16,12 @@ select from message where id in ( - select max(id) from message - where status != 2 - and from_id != 1 - and (from_id = #{userId} or to_id = #{userId}) - group by conversation_id + select max(id) from message + where status != 2 + and status !=5 + and from_id != 1 + and (from_id = #{userId} or to_id = #{userId}) + group by conversation_id ) order by id desc limit #{offset}, #{limit} @@ -31,6 +32,7 @@ select count(m.maxid) from ( select max(id) as maxid from message where status != 2 + and status !=5 and from_id != 1 and (from_id = #{userId} or to_id = #{userId}) group by conversation_id @@ -158,5 +160,46 @@ from message where id = #{id} + + + diff --git a/src/main/resources/static/css/discuss-detail.css b/src/main/resources/static/css/discuss-detail.css index 85a13ec861eada8a50a247bbb9ec98a8d411841f..984e84921e54cc39d3d6fe33177237b2645222c7 100644 --- a/src/main/resources/static/css/discuss-detail.css +++ b/src/main/resources/static/css/discuss-detail.css @@ -56,7 +56,7 @@ .list-unstyled.mt-4.bg-gray.p-3.font-size-12.text-muted { overflow-y: auto; width: 800px; - max-height: 500px; + max-height: 300px; } /*滚动条样式*/ .list-unstyled.mt-4.bg-gray.p-3.font-size-12.text-muted::-webkit-scrollbar { diff --git a/src/main/resources/static/css/global.css b/src/main/resources/static/css/global.css index cca5f960c5a8e8eea46eeb3ce6b384d6c4ba316e..ba3a1863556cacfa5b0848eae78db63f68b7d921 100644 --- a/src/main/resources/static/css/global.css +++ b/src/main/resources/static/css/global.css @@ -3,7 +3,7 @@ html { } body { - background: url('../img/img.png') no-repeat; + background: url('https://community-test1.oss-cn-chengdu.aliyuncs.com/img.png') no-repeat; font-family: 阿里巴巴普惠体; font-size: 17px; background-size:cover; @@ -35,10 +35,11 @@ body { .container { width: 960px; padding: 0; + border-radius: 8px; } header .navbar-brand { - background: url('../img/maxLogo.png') no-repeat; + background: url('https://community-test1.oss-cn-chengdu.aliyuncs.com/maxLogo.jpg') no-repeat; background-size: 140px 50px; width: 140px; height: 50px; @@ -83,7 +84,7 @@ footer .company-info li { } .main .container { - background: #e5e5e5 ; + background: #fff ; padding: 20px; opacity: 0.9; } @@ -198,6 +199,10 @@ img { background-color: #00dc93; border-color: #00dc93; } +.btn-info:hover{ + background-color: rgba(128, 125, 125, 0.7); + border-color: rgba(128, 125, 125, 0.35); +} .btn-secondary{ color: #666666; @@ -281,6 +286,10 @@ span.emotion:hover { filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#6b9d28', endColorstr='#436b0c'); } +.btn-1:hover{ + filter: brightness(0.8); +} + diff --git a/src/main/resources/static/css/letter.css b/src/main/resources/static/css/letter.css index c0e7808e44d9850a72eb8bb5bb1bc0b0e003c800..16837a699e62a3157ff6f86e61957880624355f6 100644 --- a/src/main/resources/static/css/letter.css +++ b/src/main/resources/static/css/letter.css @@ -19,22 +19,38 @@ overflow-y: auto; width: 900px; max-height: 400px; + /*overflow: hidden;*/ +} +/*表情滑动条*/ +.qqFace { + overflow: auto; + width: 630px; + max-height: 150px; } /*滚动条样式*/ .list-unstyled.mt-4::-webkit-scrollbar { width: 6px; /*height: 4px;*/ } +.qqFace::-webkit-scrollbar{ + width: 6px; +} .list-unstyled.mt-4::-webkit-scrollbar-thumb { border-radius: 10px; - -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2); - background: rgba(0,0,0,0.2); + /*-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);*/ + background: rgba(0,0,0,10%); +} +.qqFace::-webkit-scrollbar-thumb{ + border-radius: 10px; + background: rgba(0,0,0,10%); } .list-unstyled.mt-4::-webkit-scrollbar-track { /*-webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);*/ border-radius: 0; /*background: rgba(0,0,0,0.1);*/ - +} +.qqFace::-webkit-scrollbar-track{ + border-radius: 0; } .toast-body{ @@ -57,3 +73,10 @@ color: black; } +.my-skin .layui-layer-btn a { + background-color: #00dc93; + border: 1px solid #00dc93; + color: #FFF; +} + + diff --git a/src/main/resources/static/img/aboutus.jpg b/src/main/resources/static/img/aboutus.jpg deleted file mode 100644 index 3cedc405e88f603dac64d93d19e6921ef6b6b3df..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/aboutus.jpg and /dev/null differ diff --git a/src/main/resources/static/img/collectionQRcode.jpg b/src/main/resources/static/img/collectionQRcode.jpg deleted file mode 100644 index 30d07f80f893d1d2f77678cfee933688ab7d60b7..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/collectionQRcode.jpg and /dev/null differ diff --git a/src/main/resources/static/img/img.png b/src/main/resources/static/img/img.png deleted file mode 100644 index 5e3e9355c0ccc3211db08c8156bc596ed71dc2a0..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/img.png and /dev/null differ diff --git a/src/main/resources/static/img/mailCode1.png b/src/main/resources/static/img/mailCode1.png deleted file mode 100644 index cd8f9d4699d9190d54c15d29619cd8de3e011da8..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/mailCode1.png and /dev/null differ diff --git a/src/main/resources/static/img/mailCode2.png b/src/main/resources/static/img/mailCode2.png deleted file mode 100644 index 08dfa31e3d6117664bd388b22635c16537b77180..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/mailCode2.png and /dev/null differ diff --git a/src/main/resources/static/img/maxLogo.png b/src/main/resources/static/img/maxLogo.png deleted file mode 100644 index 0b44bb40c927d3ad768b252089b0df26ae464e22..0000000000000000000000000000000000000000 Binary files a/src/main/resources/static/img/maxLogo.png and /dev/null differ diff --git a/src/main/resources/static/js/discuss.js b/src/main/resources/static/js/discuss.js index cdd56ed959a95c38ea2d86ca56ec7af3b89bbb23..c37bc8656566ceb67e08f35c4b3f988e304abc80 100644 --- a/src/main/resources/static/js/discuss.js +++ b/src/main/resources/static/js/discuss.js @@ -75,13 +75,9 @@ function setDelete() { function fileCountCheck(filesObj, maxFileNum) { // console.log(filesObj.files); // 文件对象 - if (window.File && window.FileList) { - var fileCount = filesObj.files.length; - if (fileCount >= maxFileNum) { - // 不符合数量的处理 window.alert('文件数不能超过6个,你选择了' + fileCount + '个'); setTimeout(function(){ @@ -89,21 +85,14 @@ function setDelete() { window.location.reload(); }, 2000); return false; - } else { - // 符合数量的处理 return true; - } - } else { - // 不支持FileAPI window.alert('抱歉,你的浏览器不支持FileAPI,请升级浏览器!'); - return false; - } } //帖子的点击 @@ -119,7 +108,6 @@ window.onload=function(){ onSubmit.onclick=function (){ sendFile(this); } - //处理图片并添加都dom中的函数 var readFile=function(obj){ // 获取input里面的文件组 @@ -149,8 +137,27 @@ window.onload=function(){ } } + /** + * 回车发送,ctrl+enter换行 + */ + $("#contentInput").keydown( function(event){ + //var msgInput=$(this).val() + //兼容Chrome和Firefox + event=(event)?event:((window.event)?window.event:""); + var keyCode=event.keyCode?event.keyCode:(event.which?event.which:event.charCode); + var altKey = event.ctrlKey || event.metaKey; + if(keyCode == 13 && altKey){ //ctrl+enter换行 + var newDope=$(this).val()+"\n";// 获取textarea数据进行 换行 + $(this).val(newDope); + }else if(keyCode==13){ //enter发送 + sendFile(); + event.preventDefault();//禁止回车的默认换行 + } + }) + //发送文件 function sendFile() { + var current = $("#current").val() var submitArr = [], myFile, fileList = []; $('.subPic').each(function () { submitArr.push({ @@ -179,13 +186,19 @@ window.onload=function(){ dataType: 'json', processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 - success: function (result) { - if (result.code==0){ - window.alert("发送成功") - setTimeout(window.location.reload(),2000) - }else{ - Toast(result.msg); + success: function (data) { + if (data.code==0){ + if (data.msg==current){ + //使用document目的:使刷新后仍在页面原来的高度上 + document.location.reload() + }else { + window.location.replace(CONTEXT_PATH+"/discuss/detail/"+$("#entityId").val()+"?current="+data.msg) + } + Toast("发送成功") + }else { + alert(data.msg) } + }, error:function (){ Toast("提交失败"); @@ -194,7 +207,7 @@ window.onload=function(){ } } //回复帖子的点击 -function replyClick(entityType,id,entityId,postId){ +function replyClick(entityType,id,entityId,postId,value,current){ var submitArr = [], myFile, fileList = []; $('.subPic').each(function () { submitArr.push({ @@ -216,19 +229,34 @@ function replyClick(entityType,id,entityId,postId){ formData.append("entityId",entityId); formData.append("content",$("#"+contentId+"").val()); $.ajax({ - url:CONTEXT_PATH+"/comment/add/"+postId, + url:CONTEXT_PATH+"/comment/addReplay/"+postId+"/"+current, type:"post", data: formData, - dataType: 'json', + dataType: 'html', processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 - success: function (result) { - console.log(result); - if (result.code==0){ - alert("发送成功") - setTimeout(window.location.reload(),2000) - }else{ - Toast(result.msg); + success:function (data) { + $(".repay-reload").html($(data).html()); + + //遍历class进行分别处理 + $(".mt_m-2").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = replace_em(li.text()) + li.html(m); + }) + //遍历class进行分别处理 + $(".reply").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = replace_em(li.text()) + li.html(m); + }) + var ele = document.getElementById("huifu-frame-"+value); + //判断元素是否出现了滚动条 + if(ele.scrollHeight > ele.clientHeight) { + //设置滚动条到最底部 + ele.scrollTop = ele.scrollHeight; } }, error:function (){ @@ -297,7 +325,7 @@ function previewReplyCommentFile(obj,value){ } } -function replyCommentClick(entityType,entityId,targetId,postId,contentId,value){ +function replyCommentClick(entityType,entityId,targetId,postId,contentId,value,current){ console.log(contentId) var submitArr = [], myFile, fileList = []; $('.subPic').each(function () { @@ -320,23 +348,34 @@ function replyCommentClick(entityType,entityId,targetId,postId,contentId,value){ formData.append("targetId",targetId); formData.append("content",$("#"+contentId+"").val()); $.ajax({ - url:CONTEXT_PATH+"/comment/add/"+postId, + url:CONTEXT_PATH+"/comment/addReplay/"+postId+"/"+current, type:"post", data: formData, - dataType: 'json', + dataType: 'html', processData: false, // 告诉jQuery不要去处理发送的数据 contentType: false, // 告诉jQuery不要去设置Content-Type请求头 success: function (data) { - //console.log(result); - // if (result.code==0){ - //console.log(result.data) - alert("发送成功") - //$(".replyList").html(data) - setTimeout(window.location.reload(),2000) - - // }else{ - // Toast(result.msg); - // } + $(".repay-reload").html($(data).html()); + //遍历class进行分别处理 + $(".mt_m-2").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = replace_em(li.text()) + li.html(m); + }) + //遍历class进行分别处理 + $(".reply").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = replace_em(li.text()) + li.html(m); + }) + var ele = document.getElementById(value); + //判断元素是否出现了滚动条 + if(ele.scrollHeight > ele.clientHeight) { + //设置滚动条到最底部 + ele.scrollTop = ele.scrollHeight; + } }, error:function (data){ Toast("提交失败"); @@ -347,13 +386,12 @@ function replyCommentClick(entityType,entityId,targetId,postId,contentId,value){ //滚动条最底部 //$(".list-unstyled.mt-4.bg-gray.p-3").scrollTop($(".list-unstyled.mt-4.bg-gray.p-3").prop('scrollHeight')); - //回帖的表情js $(function() { $('.emotion').qqFace({ id: 'facebox', assign: 'contentInput', - path: '/community/arclist/' //表情存放的路径 + path: 'https://community-test1.oss-cn-chengdu.aliyuncs.com/arclist/' //表情存放的路径 }); $(".sub_btn").click(function() { var str = $("#contentInput").val(); @@ -370,7 +408,7 @@ function sub_btn(obj,value){ $('#'+emotion).qqFace({ id: 'facebox', assign: ''+replyText, - path: '/community/arclist/' //表情存放的路径 + path: 'https://community-test1.oss-cn-chengdu.aliyuncs.com/arclist/' //表情存放的路径 }); $("#sub_btn-"+value).click(function() { var str = $("#"+replyText).val(); @@ -385,7 +423,7 @@ function sub_btn2(obj,value,key){ $('#'+emotion).qqFace({ id: 'facebox', assign: ''+replyText, - path: '/community/arclist/' //表情存放的路径 + path: 'https://community-test1.oss-cn-chengdu.aliyuncs.com/arclist/' //表情存放的路径 }); $("#sub_btn2-"+value).click(function() { var str = $("#"+replyText).val(); @@ -406,13 +444,6 @@ function expandPicture_3(obj,id,value){ imgShow("#outerdiv","#innerdiv","#bigimg",toId); } -// $(function(){ -// $("#plus").click(function(){ -// var _this=$(this);//将当前的pimg元素作为_this传入函数 -// imgShow("#outerdiv","#innerdiv","#bigimg",_this); -// }); -// }); - function imgShow(outerdiv,innerdiv,bigimg,id){ var src = id.attr("src") @@ -458,3 +489,8 @@ function imgShow(outerdiv,innerdiv,bigimg,id){ + + + + + diff --git a/src/main/resources/static/js/global.js b/src/main/resources/static/js/global.js index 1f179015365e4e9e26743c1f795b967340829585..d048762c844b4a5d92b4e91fc1a81983c1edb124 100644 --- a/src/main/resources/static/js/global.js +++ b/src/main/resources/static/js/global.js @@ -1,4 +1,4 @@ -var CONTEXT_PATH= "/community"; +var CONTEXT_PATH= ""; window.alert = function(message) { if(!$(".alert-box").length) { $("body").append( @@ -85,6 +85,6 @@ function replace_em(str) { str = str.replace(/\/g, '>'); str = str.replace(/\n/g, '
'); - str = str.replace(/\[em_([0-9]*)\]/g, ''); + str = str.replace(/\[em_([0-9]*)\]/g, ''); return str; } diff --git a/src/main/resources/static/js/index.js b/src/main/resources/static/js/index.js index c87b767c9f048fb7d04ee797430df108ef65e112..08d4f2662eb4752fb544de458b845ba57cea518d 100644 --- a/src/main/resources/static/js/index.js +++ b/src/main/resources/static/js/index.js @@ -65,4 +65,22 @@ function publish() { } }); -} \ No newline at end of file +} + +/** + * 回车发送,ctrl+enter换行 + */ +$("#message-text").keydown( function(event){ + //var msgInput=$(this).val() + //兼容Chrome和Firefox + event=(event)?event:((window.event)?window.event:""); + var keyCode=event.keyCode?event.keyCode:(event.which?event.which:event.charCode); + var altKey = event.ctrlKey || event.metaKey; + if(keyCode == 13 && altKey){ //ctrl+enter换行 + var newDope=$(this).val()+"\n";// 获取textarea数据进行 换行 + $(this).val(newDope); + }else if(keyCode==13){ //enter发送 + publish(); + event.preventDefault();//禁止回车的默认换行 + } +}) \ No newline at end of file diff --git a/src/main/resources/static/js/jquery.qqFace.js b/src/main/resources/static/js/jquery.qqFace.js index 63df53bcd2bd2f79ed568e1c365ddd7f908c253f..cac8e7fa4b23309eb71b44c98b826014e26ad6be 100644 --- a/src/main/resources/static/js/jquery.qqFace.js +++ b/src/main/resources/static/js/jquery.qqFace.js @@ -23,10 +23,10 @@ if($('#'+id).length<=0){ strFace = ''; } diff --git a/src/main/resources/static/js/letter.js b/src/main/resources/static/js/letter.js index 904c7d414284ff8fee94a48009e1b07fe1ea50f0..ab2f7623b90a37faaaf8b61da536e50d65edef07 100644 --- a/src/main/resources/static/js/letter.js +++ b/src/main/resources/static/js/letter.js @@ -1,178 +1,116 @@ + $(function(){ $("#sendBtn").click(send_letter); - $(".closeMessage").click(delete_msg); $("#sendBtn-2").click(sendLetter); }); function send_letter() { $("#sendModal").modal("hide"); var toName = $("#recipient-name").val(); - var content = $("#message-text").val(); - $.post( - CONTEXT_PATH+"/letter/send", - {"toName":toName,"content":content}, - function (data) { //接收后端的数据 - data = $.parseJSON(data);//将数据转为js对象 - if(data.code == 0){ - $("#hintBody").text("发送成功") - }else{ - $("#hintBody").text(data.msg) - } - $("#hintModal").modal("show"); - //设定执行时间 - setTimeout(function(){$("#hintModal").modal("hide");}, 2000); - setTimeout(function(){window.location.reload()},2000) - } - ) -} -function sendImage(){ - var toName = $("#recipient-name-2").val(); - var file = $("#messageImage")[0].files; - var files = document.getElementById("messageImage").files; - console.log(files[0]) - var formData = new FormData(); - formData.append("toName",toName); - formData.append("multipartFile",files[0]); - console.log(formData) - $.ajax({ - url:CONTEXT_PATH+"/letter/send", - type:"post", - data:formData, - dataType:"json", - processData: false, - contentType: false, - success:function (data) { //接收后端的数据 - if(data.code == 0){ - setTimeout(function(){window.location.reload()},200) - //window.location.reload() - //alert("发送成功"), - }else{ - alert(data.msg); - } - }, - error:function (){ - alert("提交失败"); - } - }) -} -function sendFile(){ - var toName = $("#recipient-name-2").val(); - var files = document.getElementById("messageFile").files; - for (var i=0;i1){ - return alert("文件不能超过1GB") - } - } - var formData = new FormData(); - formData.append("toName",toName); - formData.append("multipartFile",files[0]); - console.log(formData) - $.ajax({ - url:CONTEXT_PATH+"/letter/sendFile", - type:"post", - data:formData, - dataType:"json", - processData: false, - contentType: false, - success:function (data) { //接收后端的数据 - if(data.code == 0){ - setTimeout(function(){window.location.reload()},200) - //window.location.reload() - //alert("发送成功"), - }else{ - alert(data.msg); - } - }, - error:function (){ - alert("提交失败"); - } - }) + // var content = $("#message-text").val(); + // $.post( + // CONTEXT_PATH+"/letter/send", + // {"toName":toName,"content":content}, + // function (data) { //接收后端的数据 + // data = $.parseJSON(data);//将数据转为js对象 + // if(data.code == 0){ + // $("#hintBody").text("发送成功") + // }else{ + // $("#hintBody").text(data.msg) + // } + // $("#hintModal").modal("show"); + // //设定执行时间 + // setTimeout(function(){$("#hintModal").modal("hide");}, 2000); + // setTimeout(function(){window.location.reload()},2000) + // } + // ) } + function sendLetter(){ var toName = $("#recipient-name-2").val(); var content = $("#message-text-2").val(); + if (content.trim().length==0){ + layer.msg("不能发送空白消息"); + return; + } $.post( CONTEXT_PATH+"/letter/send", {"toName":toName,"content":content}, function (data) { //接收后端的数据 - data = $.parseJSON(data);//将数据转为js对象 - if(data.code == 0){ - setTimeout(function(){window.location.reload()},200) - //$("#list-unstyled").load(location.href + " #list-unstyled",""); - //alert("发送成功"), - }else{ - alert(data.msg); - } + //data = $.parseJSON(data);//将数据转为js对象 + //清空输入框内容 + $("#message-text-2").val('') + $(".list-unstyled").html($(data).html()); + var dates = new Date(); + //遍历消息撤回按钮,当时间超过发送时间5分钟后,隐藏 + $(".img-display").each(function () { + var li = $(this); + var mytime = Date.parse(li.attr('value')) + //.log(mytime) + var time = Date.parse(dates); + var minutes=Math.ceil(parseFloat((time-mytime)/1000/60)); + if(minutes>5){ + li.children(".appearImg").show() + li.children(".disappearImg").hide() + } + }) + + $(".disappear").each(function () { + var li = $(this); + var mytime = Date.parse(li.val()) + var time = Date.parse(dates); + var minutes=Math.ceil(parseFloat((time-mytime)/1000/60)); + if(minutes>5){ + li.hide(); + } + }) + $(".appear").each(function () { + var li = $(this); + var mytime = Date.parse(li.val()) + var time = Date.parse(dates); + var minutes=Math.ceil(parseFloat((time-mytime)/1000/60)); + if(minutes>5){ + li.show() + } + }) + //遍历class进行分别处理 + $(".toast-body").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = replace_em(li.text()) + li.html(m); + }) + $(document).ready(function(){ + var myLen = arr.length-len; + if(arr.length>len){ + $('.list-unstyled li:lt('+(myLen)+')').hide(); + $('.list-unstyled li:gt('+(myLen)+')').show(); + }else { + $("#loadData").remove(); + } + }) } ) } + var ele = document.getElementById("list-unstyled"); + $("#list-unstyled").bind("DOMNodeInserted",function (e) { + //设置滚动条到最底部 + ele.scrollTop = ele.scrollHeight; + + }); + //判断元素是否出现了滚动条 + if(ele.scrollHeight > ele.clientHeight) { + //设置滚动条到最底部 + ele.scrollTop = ele.scrollHeight; + } + - var ele = document.getElementById("list-unstyled"); - //判断元素是否出现了滚动条 - //if(ele.scrollHeight > ele.clientHeight) { - //设置滚动条到最底部 - ele.scrollTop = ele.scrollHeight; - //} -//撤回消息 -function delete_msg() { - // TODO 删除数据 - var btn = this; - var id = $(btn).prev().val(); - $.post( - CONTEXT_PATH+"/letter/delete", - {"id":id}, - function (data){ - data = $.parseJSON(data); - if (data.code == 0){ - $(btn).parents(".media").hide(); - //window.location.reload(); - }else { - Toast(data.msg); - } - } - ); -} -//撤回图片 -function deleteImgMsg(obj,id) { - // TODO 删除数据 - $.post( - CONTEXT_PATH+"/letter/delete", - {"id":id}, - function (data){ - data = $.parseJSON(data); - if (data.code == 0){ - $(obj).parents(".media").hide(); - //window.location.reload(); - }else { - Toast(data.msg); - } - } - ); -} -//删除消息 -function deleteMsg(obj,id){ - console.log($(obj).parents(".media")) - $.post( - CONTEXT_PATH+"/letter/deleteMsg", - {"id":id}, - function (data){ - data = $.parseJSON(data); - if (data.code == 0){ - $(obj).parents(".media").hide(); - Toast("删除此条记录成功") - }else { - Toast(data.msg); - } - } - ); -} //表情 $(function() { $('.emotion').qqFace({ id: 'facebox', assign: 'message-text-2', - path: '/community/arclist/' //表情存放的路径 + path: 'https://community-test1.oss-cn-chengdu.aliyuncs.com/arclist/' //表情存放的路径 }); $(".sub_btn").click(function() { var str = $("#message-text-2").val(); @@ -181,51 +119,3 @@ $(function() { }); }); -//图片放大 -function expandPicture(obj,id){ - var toId = $("#deflation-"+id) - imgShow("#outerdiv","#innerdiv","#bigimg",toId); -} - - -function imgShow(outerdiv,innerdiv,bigimg,id){ - var src = id.attr("src") - - //$("#deflation-"+_this).attr("src"); - // var src = _this.attr("src");//获取当前点击的pimg元素中的src属性 - $(bigimg).attr("src", src);//设置#bigimg元素的src属性 - - /*获取当前点击图片的真实大小,并显示弹出层及大图*/ - $("").attr("src", src).load(function(){ - var windowW = $(window).width();//获取当前窗口宽度 - var windowH = $(window).height();//获取当前窗口高度 - var realWidth = this.width;//获取图片真实宽度 - var realHeight = this.height;//获取图片真实高度 - var imgWidth, imgHeight; - var scale = 0.8;//缩放尺寸,当图片真实宽度和高度大于窗口宽度和高度时进行缩放 - - if(realHeight>windowH*scale) {//判断图片高度 - imgHeight = windowH*scale;//如大于窗口高度,图片高度进行缩放 - imgWidth = imgHeight/realHeight*realWidth;//等比例缩放宽度 - if(imgWidth>windowW*scale) {//如宽度扔大于窗口宽度 - imgWidth = windowW*scale;//再对宽度进行缩放 - } - } else if(realWidth>windowW*scale) {//如图片高度合适,判断图片宽度 - imgWidth = windowW*scale;//如大于窗口宽度,图片宽度进行缩放 - imgHeight = imgWidth/realWidth*realHeight;//等比例缩放高度 - } else {//如果图片真实高度和宽度都符合要求,高宽不变 - imgWidth = realWidth; - imgHeight = realHeight; - } - $(bigimg).css("width",imgWidth);//以最终的宽度对图片缩放 - - var w = (windowW-imgWidth)/2;//计算图片与窗口左边距 - var h = (windowH-imgHeight)/2;//计算图片与窗口上边距 - $(innerdiv).css({"top":h,"left":w});//设置#innerdiv的top和left属性 - $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg - }); - - $(outerdiv).click(function(){//再次点击淡出消失弹出层 - $(this).fadeOut("fast"); - }); -} \ No newline at end of file diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 927948a53900d566c4967b8db53caec02dbb6446..7052278ce71fb502d72393b0228d75f8ab1a76a4 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -7,8 +7,9 @@ - - + + + 唠嗑网-首页 @@ -53,8 +54,8 @@ @@ -72,7 +73,7 @@ -
+
@@ -93,9 +94,6 @@ 消息 12 - - - @@ -117,7 +115,7 @@
- +
@@ -126,7 +124,7 @@
-
+
- +
@@ -176,12 +174,12 @@
  • 首页
  • -
  • +
  • <
  • 1
  • -
  • +
  • >
  • @@ -199,7 +197,7 @@
    @@ -251,10 +249,11 @@
    - + + - + @@ -265,7 +264,6 @@ input.onchange=function(){ readFile(this); } - //处理图片并添加都dom中的函数 var readFile=function(obj){ // 获取input里面的文件组 @@ -300,7 +298,7 @@ $('.emotion').qqFace({ id: 'facebox', assign: 'message-text', - path: '/community/arclist/' //表情存放的路径 + path: 'https://community-test1.oss-cn-chengdu.aliyuncs.com/arclist/' //表情存放的路径 }); $(".sub_btn").click(function() { var str = $("#message-text").val(); @@ -308,6 +306,13 @@ }); }); + + $(".letter").each(function () { + //将遍历到的类赋给li + var li = $(this); + var m = li.text().replace(/\[em_([0-9]*)\]/g, '') + li.html(m); + }) diff --git a/src/main/resources/templates/mail/activation.html b/src/main/resources/templates/mail/activation.html index 14e255c444e48a4716c902d1f1b68129cc3bedf7..f9f72569f5cd8b243d1a384e2ee35d9e59982475 100644 --- a/src/main/resources/templates/mail/activation.html +++ b/src/main/resources/templates/mail/activation.html @@ -3,6 +3,7 @@ + 唠嗑网-激活账号 diff --git a/src/main/resources/templates/mail/forget.html b/src/main/resources/templates/mail/forget.html index f221537cc69f2b6e6aa85157546bc01750861492..b25d47012daf8873654f371a92f14c23af691bdb 100644 --- a/src/main/resources/templates/mail/forget.html +++ b/src/main/resources/templates/mail/forget.html @@ -2,7 +2,7 @@ - + 唠嗑网-忘记密码 diff --git a/src/main/resources/templates/site/aboutus.html b/src/main/resources/templates/site/aboutus.html index ac0692a84deddfb9827e3987d1b5b34b4569b4d9..ee44a0db8ce8d20e33ac3044a3cdef012236bcc2 100644 --- a/src/main/resources/templates/site/aboutus.html +++ b/src/main/resources/templates/site/aboutus.html @@ -4,7 +4,7 @@ - + 关于我们-唠嗑网 @@ -67,9 +67,9 @@
  • @@ -78,10 +78,10 @@
    - 未来像 + 未来像

    -
    +

    唠嗑网属于个人创造的论坛网站,唠嗑网成立于 2022 年 3 月。欢迎各位小伙伴参与使用

    diff --git a/src/main/resources/templates/site/admin/data.html b/src/main/resources/templates/site/admin/data.html index 761488d1fe680b400b98dd851c44a850ed96e753..0f1c5d2865b085be6f78f6097f7cfa8823aa910b 100644 --- a/src/main/resources/templates/site/admin/data.html +++ b/src/main/resources/templates/site/admin/data.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-数据统计 diff --git a/src/main/resources/templates/site/authorization.html b/src/main/resources/templates/site/authorization.html index bb98e62a22708ff252e1e87c1191424f6a5b36f5..1c20f4867c1a2a133e5547d7c50f75c1a3d607eb 100644 --- a/src/main/resources/templates/site/authorization.html +++ b/src/main/resources/templates/site/authorization.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-操作结果 @@ -135,7 +135,7 @@ - + - + diff --git a/src/main/resources/templates/site/disclaimer.html b/src/main/resources/templates/site/disclaimer.html index 1839cfb44b123b36f032075a790be79f655b4c75..f46f78a766b5dc25fe48e245087602e1387e2d91 100644 --- a/src/main/resources/templates/site/disclaimer.html +++ b/src/main/resources/templates/site/disclaimer.html @@ -3,8 +3,8 @@ - - + + 联系我们-唠嗑网 @@ -63,14 +63,13 @@
    -
    +
    @@ -167,7 +166,7 @@ - + diff --git a/src/main/resources/templates/site/discuss-detail.html b/src/main/resources/templates/site/discuss-detail.html index 6eaa04e1427955fbe63eb54f7a0b97ffab957493..c15726c34b4e0de47f208a1d89749ea755574c30 100644 --- a/src/main/resources/templates/site/discuss-detail.html +++ b/src/main/resources/templates/site/discuss-detail.html @@ -3,8 +3,10 @@ - - + + + + @@ -69,11 +71,11 @@
    -
    +
    - 备战春招,面试刷题跟他复习,一个月全搞定! + 备战春招,面试刷题跟他复习,一个月全搞定!
    -
    +
    @@ -127,10 +129,11 @@   回  帖  
    + -
    -
      +
      • @@ -216,23 +219,23 @@
        - +
        - +
    -
    + +

    -

    + @@ -261,13 +264,15 @@
    - +
    +

    + +

    -

    - -

    +
    +
    @@ -337,19 +342,57 @@
    - + + - + diff --git a/src/main/resources/templates/site/followee.html b/src/main/resources/templates/site/followee.html index 85e8b75fe81ee3fbef48d9e741e7c508feffaf42..46fdbf3e085e5e5b62f257f91190612988ccfadf 100644 --- a/src/main/resources/templates/site/followee.html +++ b/src/main/resources/templates/site/followee.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-关注 @@ -177,7 +177,7 @@ - + diff --git a/src/main/resources/templates/site/follower.html b/src/main/resources/templates/site/follower.html index 0d8e00ea08f4c06bc480c601c0be3dda966adebc..3cbcb618c565ee619ee9be1fbaa26daa4bcee9ad 100644 --- a/src/main/resources/templates/site/follower.html +++ b/src/main/resources/templates/site/follower.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-关注 @@ -181,7 +181,7 @@ - + diff --git a/src/main/resources/templates/site/forget.html b/src/main/resources/templates/site/forget.html index 3717bd647c058ab79799cf942a35a52b21327823..67cddbef28d475ec57db3fcd6fe689c83cfe487c 100644 --- a/src/main/resources/templates/site/forget.html +++ b/src/main/resources/templates/site/forget.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-忘记密码 @@ -177,7 +177,7 @@ - + diff --git a/src/main/resources/templates/site/joinus.html b/src/main/resources/templates/site/joinus.html index d68e19679ecae3ad097acd935662d579501f6604..0ac7b5a992e22816ae314c4b9425c08f3c6a4efe 100644 --- a/src/main/resources/templates/site/joinus.html +++ b/src/main/resources/templates/site/joinus.html @@ -3,8 +3,8 @@ - - + + 加入我们-唠嗑网 @@ -65,19 +65,19 @@

    互联网职位

    @@ -149,7 +149,7 @@ - + diff --git a/src/main/resources/templates/site/letter-detail.html b/src/main/resources/templates/site/letter-detail.html index c1a8a08f3ea89e21f712df4355afadfa70d9ff71..53f7acb319402b8ed2c0ef8dba259ebcec2b8680 100644 --- a/src/main/resources/templates/site/letter-detail.html +++ b/src/main/resources/templates/site/letter-detail.html @@ -3,12 +3,16 @@ - + + + - + + + 唠嗑网-私信详情 @@ -69,7 +73,7 @@
    -
    +
    来自 落基山脉下的闲人 的私信
    @@ -122,7 +126,8 @@
    -
    @@ -163,7 +168,7 @@ 落基山脉下的闲人 2022-04-25 15:49:32 -
    用户头像 - +
    @@ -188,10 +194,11 @@ - + + - +
    @@ -276,13 +283,101 @@
    - + + - + + - + diff --git a/src/main/resources/templates/site/links.html b/src/main/resources/templates/site/links.html index ff2c1ad2fe9ab846a1a6fd7dc9f24b8d09c52b4f..15656549b68e629de2d50dcccd543c6a474bfa74 100644 --- a/src/main/resources/templates/site/links.html +++ b/src/main/resources/templates/site/links.html @@ -3,8 +3,8 @@ - - + + 联系我们-唠嗑网 @@ -68,7 +68,7 @@
  • 关于我们
  • 友情链接
  • 联系我们
  • -
  • 加入我们
  • +
  • 加入我们
  • 免责申明
  • @@ -164,7 +164,7 @@ - + diff --git a/src/main/resources/templates/site/login.html b/src/main/resources/templates/site/login.html index e1923bcc80fe276d9500274a60e1b554843d320b..0892cabf7c847349012d6f52affb5ef573960aaa 100644 --- a/src/main/resources/templates/site/login.html +++ b/src/main/resources/templates/site/login.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-登录 @@ -61,7 +61,7 @@
    -

    登  录

    +

    登  录

    @@ -187,7 +187,7 @@
    - + - + - + - + - + diff --git a/src/main/resources/templates/site/operate-result-fail.html b/src/main/resources/templates/site/operate-result-fail.html index 2d620998e0c8651d086ba9f20144e3d95e09cb59..a434a27943a1dba183301aa6c2d195a35357dedf 100644 --- a/src/main/resources/templates/site/operate-result-fail.html +++ b/src/main/resources/templates/site/operate-result-fail.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-操作结果 @@ -136,7 +136,7 @@ - + - + - + diff --git a/src/main/resources/templates/site/register.html b/src/main/resources/templates/site/register.html index 2256917a5cb0ac75c295522b1feee4bf76b2f142..55e3feb41cd65183ad1c27c2d416b2071d18386c 100644 --- a/src/main/resources/templates/site/register.html +++ b/src/main/resources/templates/site/register.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-注册 @@ -62,7 +62,7 @@
    -

    注  册

    +

    注  册

    diff --git a/src/main/resources/templates/site/search.html b/src/main/resources/templates/site/search.html index 0fa586e8a9ff5174c210fb7f59f01310b2d6bff5..9c504f133919a2f9206630116bd0a3b6d51ed505 100644 --- a/src/main/resources/templates/site/search.html +++ b/src/main/resources/templates/site/search.html @@ -1,10 +1,11 @@ - + - - + + + 唠嗑网-搜索结果 @@ -58,14 +59,62 @@
    + +
    + +
    + -
    -
    -
    相关帖子
    - - - -
    @@ -167,7 +221,40 @@ - + + + diff --git a/src/main/resources/templates/site/setting.html b/src/main/resources/templates/site/setting.html index b7186e6c77b5143c6a8885825d3fc24135f27ec1..25658eef4a10d2ad2ebfadfc3ee5bbd41c65c7d0 100644 --- a/src/main/resources/templates/site/setting.html +++ b/src/main/resources/templates/site/setting.html @@ -3,8 +3,8 @@ - - + + 唠嗑网-账号设置 @@ -197,7 +197,7 @@ - + diff --git a/src/test/java/com/test/community/ElasticsearchTests.java b/src/test/java/com/test/community/ElasticsearchTests.java index 39d66aeabd4f83a1480b5d0e17e5beba8aaeb417..29ec67279420a53bc93fd83bb09e9d22ed90effe 100644 --- a/src/test/java/com/test/community/ElasticsearchTests.java +++ b/src/test/java/com/test/community/ElasticsearchTests.java @@ -2,8 +2,11 @@ package com.test.community; import com.alibaba.fastjson.JSONObject; import com.test.community.dao.DiscussPostMapper; +import com.test.community.dao.UserMapper; import com.test.community.dao.elasticsearch.DiscussPostRepository; +import com.test.community.dao.elasticsearch.UserRepository; import com.test.community.entity.DiscussPost; +import com.test.community.entity.User; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.RequestOptions; @@ -44,6 +47,12 @@ public class ElasticsearchTests { @Autowired private DiscussPostRepository discussPostRepository; + @Autowired + private UserMapper userMapper; + + @Autowired + private UserRepository userRepository; + // 注入ElasticsearchRestTemplate // @Autowired // private ElasticsearchRestTemplate elasticsearchRestTemplate; @@ -79,15 +88,47 @@ public class ElasticsearchTests { // discussPostRepository.saveAll(discussPostMapper.selectDiscussPosts(146, 0, 100)); // discussPostRepository.saveAll(discussPostMapper.selectDiscussPosts(149, 0, 100)); // discussPostRepository.saveAll(discussPostMapper.selectDiscussPosts(158, 0, 100)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(323)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(324)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(325)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(326)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(327)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(328)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(329)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(330)); - discussPostRepository.save(discussPostMapper.selectDiscussPostById(333)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(323)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(324)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(325)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(326)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(327)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(328)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(329)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(330)); +// discussPostRepository.save(discussPostMapper.selectDiscussPostById(333)); +// userRepository.save(userMapper.selectById(103)); +// userRepository.save(userMapper.selectById(111)); +// userRepository.save(userMapper.selectById(112)); +// userRepository.save(userMapper.selectById(113)); +// userRepository.save(userMapper.selectById(114)); +// userRepository.save(userMapper.selectById(115)); +// userRepository.save(userMapper.selectById(116)); +// userRepository.save(userMapper.selectById(117)); +// userRepository.save(userMapper.selectById(118)); +// userRepository.save(userMapper.selectById(119)); +// userRepository.save(userMapper.selectById(120)); +// userRepository.save(userMapper.selectById(121)); +// userRepository.save(userMapper.selectById(122)); +// userRepository.save(userMapper.selectById(123)); +// userRepository.save(userMapper.selectById(124)); +// userRepository.save(userMapper.selectById(125)); +// userRepository.save(userMapper.selectById(126)); + userRepository.save(userMapper.selectById(1)); +// userRepository.save(userMapper.selectById(3)); +// userRepository.save(userMapper.selectById(11)); +// userRepository.save(userMapper.selectById(12)); +// userRepository.save(userMapper.selectById(13)); +// userRepository.save(userMapper.selectById(21)); +// userRepository.save(userMapper.selectById(22)); +// userRepository.save(userMapper.selectById(23)); +// userRepository.save(userMapper.selectById(24)); +// userRepository.save(userMapper.selectById(25)); +// userRepository.save(userMapper.selectById(101)); +// userRepository.save(userMapper.selectById(102)); + + + } @@ -299,4 +340,56 @@ public class ElasticsearchTests { System.out.println(res.get("total")); } } + + + @Test + public void highlightQueryUser() throws Exception{ + SearchRequest searchRequest = new SearchRequest("user");//discusspost是索引名,就是表名 + Map res = new HashMap<>(); + + HighlightBuilder highlightBuilder = new HighlightBuilder(); + highlightBuilder.field("username"); + highlightBuilder.field("email"); + highlightBuilder.requireFieldMatch(false); + highlightBuilder.preTags(""); // + highlightBuilder.postTags(""); // + + //构建搜索条件 + SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder() + .query(QueryBuilders.multiMatchQuery("aaa", "username", "email")) + .sort(SortBuilders.fieldSort("createTime").order(SortOrder.DESC)) + .from(0)// 指定从哪条开始查询 + .size(10)// 需要查出的总记录条数 + .highlighter(highlightBuilder);//高亮 + + searchRequest.source(searchSourceBuilder); + SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT); + + List list = new ArrayList<>(); + long total = searchResponse.getHits().getTotalHits().value; + + for (SearchHit hit : searchResponse.getHits().getHits()) { + User user = JSONObject.parseObject(hit.getSourceAsString(), User.class); + + // 处理高亮显示的结果 + HighlightField usernameField = hit.getHighlightFields().get("username"); + if (usernameField != null) { + user.setUsername(usernameField.getFragments()[0].toString()); + } + HighlightField emailField = hit.getHighlightFields().get("email"); + if (emailField != null) { + user.setEmail(emailField.getFragments()[0].toString()); + } + list.add(user); + } + + res.put("list",list); + res.put("total",total); + if(res.get("list")!= null){ + for (User user : list = (List) res.get("list")) { + System.out.println(user); + } + System.out.println(res.get("total")); + } + } }