template = new RedisTemplate();
+ template.setConnectionFactory(factory);
+
+ //Json序列化配置
+ Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
+ ObjectMapper om = new ObjectMapper();
+ om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
+// om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
+ om.activateDefaultTyping(LaissezFaireSubTypeValidator.instance, ObjectMapper.DefaultTyping.NON_FINAL);
+ jackson2JsonRedisSerializer.setObjectMapper(om);
+ //String 的序列化
+ StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
+
+ //key采用string的序列化方式
+ template.setKeySerializer(stringRedisSerializer);
+ //value的序列化方式采用jackson
+ template.setValueSerializer(jackson2JsonRedisSerializer);
+ //hash的key也采用String的序列化方式
+ template.setHashKeySerializer(stringRedisSerializer);
+ //hash的value序列化方式采用jackson
+ template.setHashValueSerializer(jackson2JsonRedisSerializer);
+ template.afterPropertiesSet();
+
+ return template;
+ }
+}
+
diff --git a/src/main/java/com/javaee/newssystem/controller/AdminController.java b/src/main/java/com/javaee/newssystem/controller/AdminController.java
index 35867cdbb7284432f47e2cd0e7c1d602f896eb85..af7b64404439291b34d004186a37f5c57be82881 100644
--- a/src/main/java/com/javaee/newssystem/controller/AdminController.java
+++ b/src/main/java/com/javaee/newssystem/controller/AdminController.java
@@ -6,13 +6,26 @@ import com.javaee.newssystem.entity.*;
import com.javaee.newssystem.service.INewsService;
import com.javaee.newssystem.service.impl.*;
import com.javaee.newssystem.utils.JwtUtil;
+import com.javaee.newssystem.vo.AdminVo;
+import com.javaee.newssystem.vo.NewsVo;
+import com.javaee.newssystem.vo.UserRespVo;
+import com.javaee.newssystem.vo.UserVo;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.Cursor;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ScanOptions;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
+import java.nio.charset.StandardCharsets;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
/**
*
@@ -36,20 +49,24 @@ public class AdminController {
TeamServiceImpl teamService;
@Autowired
CommentServiceImpl commentService;
+ @Autowired
+ RedisServiceImpl redisService;
// 管理员登录
@RequestMapping(value = "/login",method = RequestMethod.POST)
- public Msg Login(String userName, String password){
+ public Msg Login(@RequestBody AdminVo vo){
+ String userName = vo.getUserName();
+ String password = vo.getPassword();
if(StringUtils.isNullOrEmpty(userName)&&StringUtils.isNullOrEmpty(password)){
return Msg.fail("登录失败,缺少参数");
}
else {
- Admin admin = adminService.Login(userName, password);
- if (admin!=null){
+ AdminVo adminVo = adminService.Login(userName, password);
+ if (adminVo!=null){
Msg msg = Msg.success("登录成功");
- msg.add("data",admin);
+ msg.add("data",adminVo);
// 生成token
- msg.add("token", JwtUtil.getToken(admin.getAdminId(),"管理员"));
+ msg.add("token", JwtUtil.getToken(adminVo.getAdminId(),"管理员"));
return msg;
}
else
@@ -62,7 +79,7 @@ public class AdminController {
@RequestMapping(value = "/userlist",method = RequestMethod.GET)
public Msg getUserList(Integer current,Integer size){
if(current!=null&&size!=null){
- Page page = userService.adminGetUserList(current, size);
+ Page page = userService.adminGetUserList(current, size);
Msg msg = Msg.success("获取成功");
msg.add("data",page);
return msg;
@@ -73,7 +90,7 @@ public class AdminController {
// 管理员注销用户账号
@RequestMapping(value = "/logout",method = RequestMethod.POST)
- public Msg logoutUser(Long userId){
+ public Msg logoutUser(@RequestBody Long userId){
if(userId!=null){
Boolean b = userService.adminLogoutUser(userId);
return b?Msg.success("注销用户成功"):Msg.fail("此用户不存在或已被注销");
@@ -83,9 +100,9 @@ public class AdminController {
// 管理员恢复用户账号
@RequestMapping(value = "/unlogout",method = RequestMethod.POST)
- public Msg unlogoutUser(Long userId){
- if(userId!=null){
- Boolean b = userService.adminUnlogoutUser(userId);
+ public Msg unlogoutUser(@RequestBody UserVo vo){
+ if(vo.getUserId()!=null){
+ Boolean b = userService.adminUnlogoutUser(vo.getUserId());
if(b)
return Msg.success("恢复用户账号成功");
else
@@ -96,9 +113,9 @@ public class AdminController {
// 管理员修改消息状态为通过
@RequestMapping(value = "/status/pass",method = RequestMethod.POST)
- public Msg pass(Long newsId){
- if(newsId!=null){
- Boolean b = newsService.PassNews(newsId);
+ public Msg pass(@RequestBody NewsVo vo){
+ if(vo.getNewsId()!=null){
+ Boolean b = newsService.PassNews(vo.getNewsId());
return b?Msg.success("修改为通过成功"):Msg.fail("修改为通过失败");
}
return Msg.fail("缺少参数");
@@ -106,9 +123,9 @@ public class AdminController {
// 管理员修改消息状态为未通过
@RequestMapping(value = "/status/unpass",method = RequestMethod.POST)
- public Msg unpass(Long newsId){
- if(newsId!=null){
- Boolean b = newsService.UnPassNews(newsId);
+ public Msg unpass(@RequestBody NewsVo vo){
+ if(vo.getNewsId()!=null){
+ Boolean b = newsService.UnPassNews(vo.getNewsId());
return b?Msg.success("修改为未通过成功"):Msg.fail("修改为未通过失败");
}
return Msg.fail("缺少参数");
@@ -118,7 +135,7 @@ public class AdminController {
@RequestMapping(value = "/status/pass",method = RequestMethod.GET)
public Msg getPassedNews(Integer current,Integer size){
if(current!=null&&size!=null){
- Page page = newsService.GetPassList(current, size);
+ Page page = newsService.GetPassList(current, size,null);
return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
@@ -128,7 +145,7 @@ public class AdminController {
@RequestMapping(value = "/status/list",method = RequestMethod.GET)
public Msg getNewsList(Integer current,Integer size){
if(current!=null&&size!=null){
- Page Page = newsService.GetUnReviewed(current, size);
+ Page Page = newsService.GetUnReviewed(current,size);
return Msg.success("获取成功").add("data",Page);
}
return Msg.fail("缺少参数");
@@ -138,26 +155,18 @@ public class AdminController {
@RequestMapping(value = "/status/unpass",method = RequestMethod.GET)
public Msg getUnpassNews(Integer current,Integer size){
if(current!=null&&size!=null){
- Page page = newsService.GetUnPassList(current, size);
+ Page page = newsService.GetUnPassList(current, size);
return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
}
-// 管理员删除消息
-// @RequestMapping(value = "/delete/list",method = RequestMethod.POST)
-// public Msg deleteNews(Long newsId){
-// if(newsId!=null){
-// return Msg.success("参数接收到了,但是接口开发中。。。。");
-// }
-// return Msg.fail("缺少参数");
-// }
// 管理员获取用户已保存的消息
@GetMapping("/save")
public Msg SaveNews(Long userId,Integer current,Integer size){
if(current!=null && size!=null){
- Page page=newsService.GetSaveNews(userId,current,size);
+ Page page=newsService.GetSaveNews(userId,current,size);
Msg msg=Msg.success("获取成功");
msg.add("data",page);
return msg;
@@ -179,4 +188,18 @@ public class AdminController {
}
return Msg.fail("参数缺失");
}
+
+// 管理员获取一周的新增新闻数
+ @GetMapping("/getNewsNumber")
+ public Msg getNewsNumber(){
+ Double[] number = redisService.getNewsNumber();
+ return Msg.success("成功").add("data",number);
+ }
+
+// 管理员获取月活跃人数
+ @GetMapping("/getUserNumber")
+ public Msg getUserNumber(){
+ Integer number = redisService.getUserNumber();
+ return Msg.success("获取成功").add("data",number);
+ }
}
diff --git a/src/main/java/com/javaee/newssystem/controller/CommentController.java b/src/main/java/com/javaee/newssystem/controller/CommentController.java
index ac20d3a01676e282b83d86a8b1b6fea17656161b..d22c3d804cc67a9011890377a73b2d67c8bea6d3 100644
--- a/src/main/java/com/javaee/newssystem/controller/CommentController.java
+++ b/src/main/java/com/javaee/newssystem/controller/CommentController.java
@@ -4,6 +4,8 @@ package com.javaee.newssystem.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaee.newssystem.entity.*;
import com.javaee.newssystem.service.impl.CommentServiceImpl;
+import com.javaee.newssystem.vo.CommentVo;
+import com.javaee.newssystem.vo.CommentWithUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -26,9 +28,9 @@ public class CommentController {
//发表一级评论
@PostMapping("/first")
- public Msg createComment(Comment comment){
+ public Msg createComment(@RequestBody Comment comment){
if(comment!=null){
- comment=commentService.createComment(comment);
+ commentService.createComment(comment);
if (comment.getCommentId() != null){
Msg msg = Msg.success("评论成功");
return msg;
@@ -40,9 +42,9 @@ public class CommentController {
//发表二级评论
@PostMapping("/second")
- public Msg createSecondComment(Comment comment){
+ public Msg createSecondComment(@RequestBody Comment comment){
if(comment!=null){
- comment=commentService.createComment(comment);
+ commentService.createComment(comment);
if (comment.getCommentId() != null){
Msg msg = Msg.success("评论成功");
return msg;
@@ -54,9 +56,9 @@ public class CommentController {
//点赞评论
@PostMapping("/like")
- public Msg createLike(Long userId,Long commentId){
- if(userId!=null && commentId != null){
- Boolean b = commentService.createLike(userId,commentId);
+ public Msg createLike(@RequestBody CommentWithUserVo vo){
+ if(vo.getUserId()!=null && vo.getCommentId() != null){
+ Boolean b = commentService.createLike(vo.getUserId(),vo.getCommentId());
return b?Msg.success("点赞成功"):Msg.fail("点赞失败");
}
return Msg.fail("缺少参数");
@@ -64,9 +66,9 @@ public class CommentController {
//取消点赞
@PostMapping("/unlike")
- public Msg deleteLike(Long userId,Long commentId){
- if(userId!=null && commentId != null){
- Boolean b = commentService.deleteLike(userId,commentId);
+ public Msg deleteLike(@RequestBody CommentWithUserVo vo){
+ if(vo.getUserId()!=null && vo.getCommentId() != null){
+ Boolean b = commentService.deleteLike(vo.getUserId(),vo.getCommentId());
return b?Msg.success("取消成功"):Msg.fail("取消失败");
}
return Msg.fail("缺少参数");
@@ -74,9 +76,9 @@ public class CommentController {
//删除评论
@PostMapping("/delete")
- public Msg deleteComment(Long commentId){
- if(commentId != null){
- Boolean b = commentService.deleteComment(commentId);
+ public Msg deleteComment(@RequestBody CommentWithUserVo vo){
+ if(vo.getCommentId() != null){
+ Boolean b = commentService.deleteComment(vo.getCommentId());
return b?Msg.success("删除评论成功"):Msg.fail("删除评论失败");
}
return Msg.fail("缺少参数");
@@ -84,9 +86,9 @@ public class CommentController {
//获取一级评论
@GetMapping(value = "/firstList")
- public Msg getFirstList(Long newsId,Integer current,Integer size){
+ public Msg getFirstList(Long newsId,Integer current,Integer size,@RequestHeader("token") String token){
if(current!=null && size!=null && newsId != null){
- Page page=commentService.GetFirstCommentList(newsId,current,size);
+ Page page=commentService.GetFirstCommentList(newsId,current,size,token);
Msg msg=Msg.success("获取成功");
msg.add("data",page);
return msg;
@@ -96,9 +98,9 @@ public class CommentController {
//获取二级评论
@GetMapping(value = "/secondList")
- public Msg getSecondList(Long commentId,Integer current,Integer size){
+ public Msg getSecondList(Long commentId,Integer current,Integer size,@RequestHeader("token") String token){
if(current!=null && size!=null && commentId !=null){
- Page page=commentService.GetSecondCommentList(commentId,current,size);
+ Page page=commentService.GetSecondCommentList(commentId,current,size,token);
Msg msg=Msg.success("获取成功");
msg.add("data",page);
return msg;
@@ -110,7 +112,7 @@ public class CommentController {
@GetMapping(value = "/myself")
public Msg getMyselfComment(Long userId,Integer current,Integer size){
if(current!=null && size!=null){
- Page page=commentService.GetMyselfList(userId,current,size);
+ Page page=commentService.GetMyselfList(userId,current,size);
Msg msg=Msg.success("获取成功");
msg.add("data",page);
return msg;
@@ -121,7 +123,7 @@ public class CommentController {
@GetMapping("/like")
public Msg getLikeComment(Long userId,Integer current,Integer size){
if(userId!=null&¤t!=null&&size!=null){
- Page page = commentService.getLikeComment(userId, current, size);
+ Page page = commentService.getLikeComment(userId, current, size);
Msg msg = Msg.success("查询成功");
msg.add("data",page);
return msg;
diff --git a/src/main/java/com/javaee/newssystem/controller/ExceptionControllerAdvice.java b/src/main/java/com/javaee/newssystem/controller/ExceptionControllerAdvice.java
new file mode 100644
index 0000000000000000000000000000000000000000..fabebdd5bd930892bf09c60c27e5db8353119506
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/controller/ExceptionControllerAdvice.java
@@ -0,0 +1,49 @@
+package com.javaee.newssystem.controller;
+import com.javaee.newssystem.entity.Msg;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.BindException;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.ObjectError;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+@RestControllerAdvice(basePackages = "com.javaee.newssystem.controller")
+public class ExceptionControllerAdvice {
+
+ @ExceptionHandler(BindException.class)
+ public Msg handleVaildException(BindException e){
+// List errorList = e.getAllErrors();
+// List messageStr = new ArrayList<>();
+// for (ObjectError item:errorList) {
+// log.error("数据校验出现问题:{},异常类型:{}",item.getDefaultMessage(),item.getObjectName());
+// //获取错误信息
+// String message = item.getDefaultMessage();
+// //获取错误的属性名字
+// String field = item.getObjectName();
+// messageStr.add(field+":"+message);
+// }
+ log.error("数据校验出现问题{},异样类型:{}",e.getMessage(),e.getClass());
+ BindingResult bindingResult = e.getBindingResult();
+ Map errorMap = new HashMap<>();
+ List errorList = new ArrayList<>();
+ bindingResult.getFieldErrors().forEach(fieldError -> {
+ errorList.add(fieldError.getDefaultMessage());
+ errorMap.put(fieldError.getField(),fieldError.getDefaultMessage());
+ });
+ return Msg.fail(String.join(";",errorList),400);
+ }
+
+
+ @ExceptionHandler(value = Throwable.class)
+ public Msg handleException(Throwable throwable){
+ log.error("错误",throwable);
+ return Msg.fail("系统内部异常");
+ }
+}
diff --git a/src/main/java/com/javaee/newssystem/controller/NewsController.java b/src/main/java/com/javaee/newssystem/controller/NewsController.java
index 34a30f9ded78d55b6cf26fb0824f90c078b036e0..7c85b7fc235d4695f7d794c53dfabeb282a90423 100644
--- a/src/main/java/com/javaee/newssystem/controller/NewsController.java
+++ b/src/main/java/com/javaee/newssystem/controller/NewsController.java
@@ -2,13 +2,21 @@ package com.javaee.newssystem.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.javaee.newssystem.entity.HotWord;
import com.javaee.newssystem.entity.Msg;
import com.javaee.newssystem.entity.News;
import com.javaee.newssystem.service.impl.NewsServiceImpl;
+import com.javaee.newssystem.service.impl.RedisServiceImpl;
import com.javaee.newssystem.utils.CheckClassUtil;
+import com.javaee.newssystem.vo.NewsVo;
+import com.javaee.newssystem.vo.NewsWithUserVo;
+import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import javax.validation.Valid;
+import java.util.List;
+
/**
*
* 前端控制器
@@ -24,16 +32,16 @@ public class NewsController {
@Autowired
NewsServiceImpl newsService;
+ @Autowired
+ RedisServiceImpl redisService;
//创建消息
@PostMapping(value = "/upload")
- public Msg CreateNews(News news){
+ public Msg CreateNews(@RequestBody @Valid News news,@RequestHeader("token") String token){
if(CheckClassUtil.checkNews(news)){
- newsService.CreateNews(news);
+ NewsVo newsVo = newsService.CreateNews(news,token);
if(news.getNewsId()!=null){
- Msg msg=Msg.success("创建成功");
- msg.add("data",news);
- return msg;
+ return Msg.success("创建成功").add("data",newsVo);
}
}
return Msg.fail("缺少参数");
@@ -41,13 +49,11 @@ public class NewsController {
//保存消息
@PostMapping(value = "/save")
- public Msg SaveNews(News news){
+ public Msg SaveNews(@RequestBody @Valid News news,@RequestHeader("token") String token){
if(CheckClassUtil.checkNews(news)){
- newsService.SaveNews(news);
+ NewsVo newsVo = newsService.SaveNews(news,token);
if(news.getNewsId()!=null){
- Msg msg=Msg.success("创建成功");
- msg.add("data",news);
- return msg;
+ return Msg.success("创建成功").add("data",newsVo);
}
}
return Msg.fail("缺少参数");
@@ -57,147 +63,115 @@ public class NewsController {
@GetMapping(value = "/focuslist")
public Msg GetFocusList(Long userId,Integer current,Integer size){
if(userId!=null && current!=null && size!=null){
- Page page=newsService.GetFocusList(userId,current,size);
- Msg msg=Msg.success("获取成功");
- msg.add("data",page);
- return msg;
+ Page page=newsService.GetFocusList(userId,current,size);
+ return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
}
//获取公共消息
@GetMapping(value = "/public")
- public Msg getPublicList(Integer current,Integer size){
+ public Msg getPublicList(Integer current,Integer size,@RequestHeader("token") String token){
if(current!=null && size!=null){
- Page page=newsService.GetPublicList(current,size);
- Msg msg=Msg.success("获取成功");
- msg.add("data",page);
- return msg;
+ Page page=newsService.GetPublicList(current,size,token);
+ return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
}
//获取团队消息
@GetMapping(value = "/team")
- public Msg getTeamnews(Long teamId,Integer current,Integer size){
+ public Msg getTeamnews(Long teamId,Integer current,Integer size,@RequestHeader("token") String token){
if(current!=null && size!=null){
- Page page=newsService.GetTeamList(teamId,current,size);
- Msg msg=Msg.success("获取成功");
- msg.add("data",page);
- return msg;
+ Page page=newsService.GetTeamList(teamId,current,size,token);
+ return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
}
//获取自己发布的消息
@GetMapping(value = "/myself")
- public Msg getMyselfnews(Long userId,Integer current,Integer size){
+ public Msg getMyselfnews(Long userId,Integer current,Integer size,@RequestHeader("token") String token){
if(current!=null && size!=null){
- Page page=newsService.GetMyselfList(userId,current,size);
- Msg msg=Msg.success("获取成功");
- msg.add("data",page);
- return msg;
+ Page page=newsService.GetMyselfList(userId,current,size,token);
+ return Msg.success("获取成功").add("data",page);
}
return Msg.fail("缺少参数");
}
//修改新闻内容
@PostMapping(value = "/update")
- public Msg updateNews(News news){
+ public Msg updateNews(@RequestBody News news,@RequestHeader("token") String token){
if(news!=null){
- news=newsService.updateInfo(news);
- Msg msg=Msg.success("更改信息成功");
- msg.add("data",news);
- return msg;
+ NewsVo newsVo = newsService.updateInfo(news,token);
+ return Msg.success("更改信息成功").add("data",newsVo);
}
return Msg.fail("缺少参数");
}
//删除新闻内容
@PostMapping("/delete")
- public Msg deleteTeam(Long newsId){
- if(newsId!=null){
- Boolean b = newsService.deleteNews(newsId);
- if(b){
- Msg msg = Msg.success("删除成功");
- return msg;
- }
+ public Msg deleteTeam(@RequestBody NewsVo vo){
+ if(vo.getNewsId()!=null){
+ Boolean b = newsService.deleteNews(vo.getNewsId());
+ return b?Msg.success("删除成功"):Msg.fail("删除失败");
}
return Msg.fail("缺少参数");
}
//获取消息的关注人数
@GetMapping("focus/user")
- public Msg FocusNews(Long newsId){
+ public Msg FocusNewsUserNumber(Long newsId){
if(newsId!=null){
Integer focusnum=newsService.GetFocusNews(newsId);
- Msg msg=Msg.success("查询成功");
- msg.add("total",focusnum);
- return msg;
+ return Msg.success("查询成功").add("data",focusnum);
}
return Msg.fail("缺少参数");
}
-// //获取已通过消息
-// @GetMapping("/pass")
-// public Msg PassNews(Integer current,Integer size){
-// if(current!=null && size!=null){
-// Page page=newsService.GetPassList(current,size);
-// Msg msg=Msg.success("获取成功");
-// msg.add("data",page);
-// return msg;
-// }
-// return Msg.fail("缺少参数");
-// }
-//
-// //获取未通过消息
-// @GetMapping("/unpass")
-// public Msg UnPassNews(Integer current,Integer size){
-// if(current!=null && size!=null){
-// Page page=newsService.GetUnPassList(current,size);
-// Msg msg=Msg.success("获取成功");
-// msg.add("data",page);
-// return msg;
-// }
-// return Msg.fail("缺少参数");
-// }
-//
-// //获取未审核
-// @GetMapping("/unreviewed")
-// public Msg UnReviewedNews(Integer current,Integer size){
-// if(current!=null && size!=null){
-// Page page=newsService.GetUnReviewed(current,size);
-// Msg msg=Msg.success("获取成功");
-// msg.add("data",page);
-// return msg;
-// }
-// return Msg.fail("缺少参数");
-// }
-//
-// //获取用户已保存
-// @GetMapping("/save")
-// public Msg SaveNews(Long userId,Integer current,Integer size){
-// if(current!=null && size!=null){
-// Page page=newsService.GetSaveNews(userId,current,size);
-// Msg msg=Msg.success("获取成功");
-// msg.add("data",page);
-// return msg;
-// }
-// return Msg.fail("缺少参数");
-// }
-//
-// //管理员审核新闻
-// @PostMapping("/pass")
-// public Msg PassNews(Long newsId){
-// if(newsId!=null){
-// Boolean b = newsService.PassNews(newsId);
-// if(b){
-// Msg msg = Msg.success("审核成功");
-// return msg;
-// }
-// else{
-// return Msg.fail("状态码错误");
-// }
-// }
-// return Msg.fail("缺少参数");
-// }
+ //关注消息
+ @PostMapping("focus")
+ public Msg FocusNews(@RequestBody NewsWithUserVo vo){
+ if(vo!=null&&vo.getNewsId()!=null&&vo.getUserId()!=null){
+ Boolean b=newsService.UserFocusNews(vo.getNewsId(),vo.getUserId());
+ return b?Msg.success("关注成功"):Msg.fail("已关注,无需再次关注");
+ }
+ return Msg.fail("缺少参数");
+ }
+
+ //取消关注消息
+ @PostMapping("focus/cancel")
+ public Msg cancelFocusNews(@RequestBody NewsWithUserVo vo){
+ if(vo!=null&&vo.getNewsId()!=null&&vo.getUserId()!=null){
+ Boolean b=newsService.UserCancelFocusNews(vo.getNewsId(),vo.getUserId());
+ return b?Msg.success("取消关注成功"):Msg.fail("已经取消关注,无法取消");
+ }
+ return Msg.fail("缺少参数");
+ }
+
+// 根据关键词查找消息
+ @GetMapping("search")
+ public Msg searchNews(String key,Integer current,Integer size,@RequestHeader("token") String token){
+ if(!StringUtils.isNullOrEmpty(key)){
+ Page page = newsService.searchNews(key,current,size,token);
+ return Msg.success("获取成功").add("data",page);
+ }
+ return Msg.fail("缺少参数");
+ }
+
+// 获取热搜
+ @GetMapping("/topsearch")
+ public Msg getTopsearch(Integer number){
+ List hotWords = redisService.getHotKey(number);
+ return Msg.success("获取成功").add("data",hotWords);
+ }
+
+// 根据类型获取消息
+ @GetMapping("/category/list")
+ public Msg getNewsListBycategory(String key,Integer current,Integer size){
+ if(!StringUtils.isNullOrEmpty(key)){
+ Page page = newsService.getNewsListBycategory(key,current,size);
+ return Msg.success("获取成功").add("data",page);
+ }
+ return Msg.fail("缺少参数");
+ }
}
diff --git a/src/main/java/com/javaee/newssystem/controller/RedisController.java b/src/main/java/com/javaee/newssystem/controller/RedisController.java
new file mode 100644
index 0000000000000000000000000000000000000000..7fd1ad709053801a2f130f8517c6d9adfb543b67
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/controller/RedisController.java
@@ -0,0 +1,15 @@
+package com.javaee.newssystem.controller;
+
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class RedisController {
+
+ @Autowired
+ RedisTemplate redisTemplate;
+
+
+}
diff --git a/src/main/java/com/javaee/newssystem/controller/TeamController.java b/src/main/java/com/javaee/newssystem/controller/TeamController.java
index 6ae9072a6992502c0cd600556e1a0f647dc814eb..aa1649187fc24c979b94f1d0486bc852f7dda142 100644
--- a/src/main/java/com/javaee/newssystem/controller/TeamController.java
+++ b/src/main/java/com/javaee/newssystem/controller/TeamController.java
@@ -6,13 +6,13 @@ import com.javaee.newssystem.entity.Msg;
import com.javaee.newssystem.entity.Team;
import com.javaee.newssystem.service.impl.TeamServiceImpl;
import com.javaee.newssystem.utils.CheckClassUtil;
+import com.javaee.newssystem.vo.TeamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
-import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;
-import java.util.List;
+import javax.validation.Valid;
/**
*
@@ -31,9 +31,9 @@ public class TeamController {
// 创建团队
@PostMapping("/create")
- public Msg createTeam(Team team, @RequestPart("headImg")MultipartFile headImg){
+ public Msg createTeam(@RequestBody @Valid Team team){
if(CheckClassUtil.checkTeam(team)){
- team = teamService.createTeam(team,headImg);
+ team = teamService.createTeam(team);
if(team.getTeamId()!=null){
Msg msg = Msg.success("创建成功");
msg.add("data",team);
@@ -60,9 +60,9 @@ public class TeamController {
// 更新团队信息
@PostMapping("/update/info")
- public Msg updateInfo(Team team, @RequestPart("headImg")MultipartFile headImg){
+ public Msg updateInfo(@RequestBody @Valid Team team){
if(team!=null&&team.getTeamId()!=null){
- team = teamService.updateInfo(team,headImg);
+ team = teamService.updateInfo(team);
Msg msg = Msg.success("更改信息成功");
msg.add("data",team);
return msg;
@@ -72,9 +72,9 @@ public class TeamController {
// 解散团队
@PostMapping("/delete")
- public Msg deleteTeam(Long teamId){
- if(teamId!=null){
- Boolean b = teamService.deleteTeam(teamId);
+ public Msg deleteTeam(@RequestBody TeamVo vo){
+ if(vo.getTeamId()!=null){
+ Boolean b = teamService.deleteTeam(vo.getTeamId());
return b?Msg.success("解散成功"):Msg.fail("解散失败");
}
return Msg.fail("缺少参数");
@@ -82,9 +82,9 @@ public class TeamController {
// 置顶消息
@PostMapping("/first")
- public Msg firstNews(Long teamId,Long newsId){
- if(teamId!=null&&newsId!=null){
- Team team = teamService.firstNews(teamId,newsId);
+ public Msg firstNews(@RequestBody TeamVo vo){
+ if(vo.getTeamId()!=null&&vo.getNewsId()!=null){
+ Team team = teamService.firstNews(vo.getTeamId(),vo.getNewsId());
if(team!=null){
Msg msg = Msg.success("置顶消息成功");
msg.add("data",team);
@@ -96,9 +96,9 @@ public class TeamController {
// 邀请用户
@PostMapping("/invite")
- public Msg inviteUser(Long teamId,Long userId){
- if(teamId!=null&&userId!=null){
- Boolean b = teamService.invite(teamId,userId);
+ public Msg inviteUser(@RequestBody TeamVo vo){
+ if(vo.getTeamId()!=null&&vo.getUserId()!=null){
+ Boolean b = teamService.invite(vo.getTeamId(),vo.getUserId());
if (b){
return Msg.success("邀请成功");
}
@@ -110,9 +110,9 @@ public class TeamController {
// 踢出用户
@PostMapping("/deleteMember")
- public Msg deleteUser(Long teamId,Long userId){
- if(teamId!=null&&userId!=null){
- Boolean b = teamService.deleteUser(teamId,userId);
+ public Msg deleteUser(@RequestBody TeamVo vo){
+ if(vo.getTeamId()!=null&&vo.getUserId()!=null){
+ Boolean b = teamService.deleteUser(vo.getTeamId(),vo.getUserId());
if(b){
return Msg.success("踢出成功");
}
@@ -124,9 +124,9 @@ public class TeamController {
// 转换管理权
@PostMapping("/change/leader")
- public Msg changeLeader(Long teamId,Long userId){
- if(teamId!=null&&userId!=null){
- Boolean b = teamService.changeLeader(teamId,userId);
+ public Msg changeLeader(@RequestBody TeamVo vo){
+ if(vo.getTeamId()!=null&&vo.getUserId()!=null){
+ Boolean b = teamService.changeLeader(vo.getTeamId(),vo.getUserId());
return b?Msg.success("转让成功"):Msg.fail("转让失败");
}
return Msg.fail("缺少参数");
@@ -150,9 +150,9 @@ public class TeamController {
// 成员退出团队
@PostMapping("/member/delete")
- public Msg memberDelete(Long userId,Long teamId){
- if(userId!=null&&teamId!=null){
- Boolean b = teamService.memberDelete(userId,teamId);
+ public Msg memberDelete(@RequestBody TeamVo vo){
+ if(vo.getUserId()!=null&&vo.getTeamId()!=null){
+ Boolean b = teamService.memberDelete(vo.getUserId(),vo.getTeamId());
if(b)
return Msg.success("退出成功");
else
diff --git a/src/main/java/com/javaee/newssystem/controller/UploadController.java b/src/main/java/com/javaee/newssystem/controller/UploadController.java
new file mode 100644
index 0000000000000000000000000000000000000000..a374db1d185eb1c790085936f90e1b6e7d695292
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/controller/UploadController.java
@@ -0,0 +1,24 @@
+package com.javaee.newssystem.controller;
+
+import com.javaee.newssystem.entity.Msg;
+import com.javaee.newssystem.service.impl.UploadServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestPart;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+@RestController
+public class UploadController {
+
+ @Autowired
+ UploadServiceImpl uploadService;
+
+ @PostMapping("/upload")
+ public Msg upload( @RequestPart(value = "headImg") MultipartFile headImg){
+ String name = uploadService.upload(headImg);
+ if(name!=null)
+ return Msg.success("上传成功").add("data",name);
+ return Msg.fail("上传失败");
+ }
+}
diff --git a/src/main/java/com/javaee/newssystem/controller/UserController.java b/src/main/java/com/javaee/newssystem/controller/UserController.java
index 928984a3445999488ecbea45448b6dcb8f893649..de3ffad48759a9c19ba5bd32cac8fba3c2bff674 100644
--- a/src/main/java/com/javaee/newssystem/controller/UserController.java
+++ b/src/main/java/com/javaee/newssystem/controller/UserController.java
@@ -7,16 +7,18 @@ import com.javaee.newssystem.entity.User;
import com.javaee.newssystem.service.impl.UserServiceImpl;
import com.javaee.newssystem.utils.CheckClassUtil;
import com.javaee.newssystem.utils.JwtUtil;
+import com.javaee.newssystem.vo.UserRespVo;
+import com.javaee.newssystem.vo.UserVo;
import com.mysql.cj.util.StringUtils;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
-import javax.servlet.http.HttpServletRequest;
-import java.util.Date;
-import java.util.Enumeration;
+import javax.validation.Valid;
import java.util.List;
+import java.util.Map;
/**
*
@@ -35,18 +37,23 @@ public class UserController {
// 用户登录
@RequestMapping(value = "/login",method = RequestMethod.POST)
- public Msg Login(String userName,String userPassword){
+ public Msg Login(@RequestBody UserVo userVo){
+ String userName = userVo.getUserName();
+ String userPassword = userVo.getUserPassword();
if(StringUtils.isNullOrEmpty(userName)||StringUtils.isNullOrEmpty(userPassword)){
return Msg.fail("登录失败,缺少参数");
}
else {
- User user = userService.Login(userName, userPassword);
- if (user!=null){
- Msg msg = Msg.success("登录成功");
- msg.add("data",user);
+ Long userId = userService.Login(userName, userPassword);
+ if (userId!=null){
+ UserRespVo vo = userService.getUserInfo(userId);
+ if(vo!=null){
+ Msg msg = Msg.success("登录成功").add("data",vo);
// 生成token
- msg.add("token", JwtUtil.getToken(user.getUserId(),"用户"));
- return msg;
+ msg.add("token", JwtUtil.getToken(vo.getUserId(),"用户"));
+ return msg;
+ }
+ return Msg.fail("登录成功,但服务器内部出现错误");
}
else
return Msg.fail("账号或密码错误");
@@ -55,54 +62,51 @@ public class UserController {
// 用户注册
@RequestMapping(value = "/register",method = RequestMethod.POST)
- public Msg Register(User user){
+ public Msg Register(@RequestBody @Valid User user){
if (CheckClassUtil.checkUser(user)){
- userService.Register(user);
- if(user.getUserId()!=null){
- Msg msg = Msg.success("注册成功");
- user.setUserPassword(null);
- msg.add("data",user);
- return msg;
- }
- else
- return Msg.fail("用户名已存在");
+ Boolean b = userService.Register(user);
+ return b?Msg.success("注册成功"):Msg.fail("用户已存在");
}
return Msg.fail("注册失败,缺少参数");
}
// 用户修改信息
@RequestMapping(value = "/update/info",method = RequestMethod.POST)
- public Msg updateInfo(User user,@RequestPart("headImg") MultipartFile headImg){
+ public Msg updateInfo(@RequestBody @Valid User user){
if(user.getUserId()!=null){
- user = userService.updateInfo(user, headImg);
- if(user!=null){
- Msg msg = Msg.success("修改成功");
- user.setUserPassword(null);
- msg.add("data",user);
- return msg;
+ UserRespVo vo = userService.updateInfo(user);
+ if(vo!=null){
+ return Msg.success("修改成功").add("data",vo);
}
else
- Msg.fail("修改失败");
+ return Msg.fail("修改失败");
}
return Msg.fail("修改失败,缺少用户id");
}
// 用户获取个人信息(通过token)
@GetMapping("/info")
- public Msg userInfo(HttpServletRequest request){
- String token = request.getHeader("token");
- User user = userService.getUserInfo(token);
- if(user!=null){
- return Msg.success("获取成功").add("data",user);
- }
- else {
- return Msg.fail("不存在此用户");
+ public Msg userInfo(@RequestHeader("token") String token){
+ Map map = JwtUtil.parse(token);
+ if((Boolean) map.get("status")){
+ Long id = (Long) map.get("id");
+ UserRespVo vo = userService.getUserInfo(id);
+ if(vo!=null){
+ return Msg.success("获取成功").add("data",vo);
+ }
+ else {
+ return Msg.fail("不存在此用户");
+ }
}
+ return Msg.fail("token失效,请重新登录");
}
// 用户修改密码
@PostMapping("/update/password")
- public Msg updatePassword(Long userId,String oldPassword,String newPassword){
+ public Msg updatePassword(@RequestBody UserVo userVo){
+ Long userId = userVo.getUserId();
+ String oldPassword = userVo.getOldPassword();
+ String newPassword = userVo.getNewPassword();
if(userId!=null&&CheckClassUtil.checkStringList(oldPassword,newPassword)){
Boolean b = userService.updatePassword(userId,oldPassword,newPassword);
return b?Msg.success("修改密码成功"):Msg.fail("密码错误");
@@ -112,15 +116,10 @@ public class UserController {
// 用户注销账号
@RequestMapping(value = "logout",method = RequestMethod.POST)
- public Msg Logout(Long userId){
- if(userId!=null){
- Boolean b = userService.Logout(userId);
- if(b){
- return Msg.success("注销成功");
- }
- else {
- return Msg.fail("该用户已被注销");
- }
+ public Msg Logout(@RequestBody UserVo vo){
+ if(vo.getUserId()!=null){
+ Boolean b = userService.Logout(vo.getUserId());
+ return b?Msg.success("注销成功"):Msg.fail("该用户已被注销");
}
return Msg.fail("缺少参数");
}
@@ -129,40 +128,32 @@ public class UserController {
@RequestMapping(value = "/focus",method = RequestMethod.GET)
public Msg getFocusUser(Long userId,Integer current,Integer size){
if(userId!=null&¤t!=null&&size!=null){
- Page page = userService.getFocusUser(userId, current, size);
- Msg msg = Msg.success("查询成功");
- msg.add("data",page);
- return msg;
+ Page page = userService.getFocusUser(userId, current, size);
+ return Msg.success("查询成功").add("data",page);
}
return Msg.fail("缺少参数");
}
// 添加关注用户
@RequestMapping(value = "/focus",method = RequestMethod.POST)
- public Msg addFocusUser(Long userId,Long focusedUserId){
+ public Msg addFocusUser(@RequestBody UserVo userVo){
+ Long userId = userVo.getUserId();
+ Long focusedUserId = userVo.getFocusedUserId();
if(userId!=null&&focusedUserId!=null){
Boolean b = userService.addFocusUser(userId, focusedUserId);
- if(b){
- return Msg.success("添加关注成功");
- }
- else {
- return Msg.fail("添加关注失败");
- }
+ return b?Msg.success("取消关注成功"):Msg.fail("该用户已被关注");
}
return Msg.fail("缺少参数");
}
// 取消关注用户
@RequestMapping(value = "/unfocus",method = RequestMethod.POST)
- public Msg unfocus(Long userId,Long focusedUserId){
+ public Msg unfocus(@RequestBody UserVo userVo){
+ Long userId = userVo.getUserId();
+ Long focusedUserId = userVo.getFocusedUserId();
if(userId!=null&&focusedUserId!=null){
Boolean b = userService.unFocus(userId, focusedUserId);
- if(b){
- return Msg.success("取消关注成功");
- }
- else {
- return Msg.fail("该用户未被关注");
- }
+ return b?Msg.success("取消关注成功"):Msg.fail("该用户未被关注");
}
return Msg.fail("缺少参数");
}
@@ -171,13 +162,11 @@ public class UserController {
@RequestMapping(value = "/search",method = RequestMethod.GET)
public Msg search(String userName){
if(!StringUtils.isNullOrEmpty(userName)){
- List userList = userService.search(userName);
- if (!userList.isEmpty()){
- Msg msg = Msg.success("查找成功");
- msg.add("data",userList);
- return msg;
+ List voList = userService.search(userName);
+ if (!voList.isEmpty()){
+ return Msg.success("查找成功").add("data",voList);
}
- else return Msg.fail("不存在此人");
+ else return Msg.fail("查无此人");
}
return Msg.fail("缺少参数");
}
diff --git a/src/main/java/com/javaee/newssystem/entity/HotWord.java b/src/main/java/com/javaee/newssystem/entity/HotWord.java
new file mode 100644
index 0000000000000000000000000000000000000000..0367a315676f6635984688b83f45aa0aa147b2ad
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/entity/HotWord.java
@@ -0,0 +1,18 @@
+package com.javaee.newssystem.entity;
+
+
+import lombok.Data;
+
+@Data
+public class HotWord {
+
+ String hotWord;
+ Integer num;
+
+
+
+ public HotWord(String hotWord, Integer num) {
+ this.hotWord = hotWord;
+ this.num = num;
+ }
+}
diff --git a/src/main/java/com/javaee/newssystem/entity/Msg.java b/src/main/java/com/javaee/newssystem/entity/Msg.java
index 0f38a69df1bd35fb22eaf80710f77b56b106f676..403ca026e52229799d68722c651ee618d0f7070f 100644
--- a/src/main/java/com/javaee/newssystem/entity/Msg.java
+++ b/src/main/java/com/javaee/newssystem/entity/Msg.java
@@ -1,5 +1,7 @@
package com.javaee.newssystem.entity;
+
+
import java.util.HashMap;
import java.util.Map;
@@ -7,25 +9,31 @@ public class Msg {
private String msg;
// 200:成功,0:失败
private Integer status;
- private Map data = new HashMap<>();
+ private Map data;
public Msg add(String key,Object value){
+ if(data==null){
+ data = new HashMap<>();
+ }
data.put(key,value);
return this;
}
public static Msg success(String msg){
- Msg msgClass = new Msg();
- msgClass.setMsg(msg);
- msgClass.setStatus(200);
- return msgClass;
+ return new Msg(msg,200);
}
public static Msg fail(String msg){
- Msg msgClass = new Msg();
- msgClass.setMsg(msg);
- msgClass.setStatus(0);
- return msgClass;
+ return new Msg(msg,0);
+ }
+
+ public static Msg fail(String msg,Integer status){
+ return new Msg(msg,status);
+ }
+
+ private Msg(String msg, Integer status ) {
+ this.msg = msg;
+ this.status = status;
}
private void setMsg(String msg) {
diff --git a/src/main/java/com/javaee/newssystem/entity/News.java b/src/main/java/com/javaee/newssystem/entity/News.java
index 96503ca9773a07f721c11e90e1226ff45898155b..f58627483eaab7f7f3596f318979ae3c13621fb9 100644
--- a/src/main/java/com/javaee/newssystem/entity/News.java
+++ b/src/main/java/com/javaee/newssystem/entity/News.java
@@ -1,8 +1,10 @@
package com.javaee.newssystem.entity;
+
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
+import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
@@ -37,6 +39,7 @@ public class News implements Serializable {
/**
* 新闻标题
*/
+ @Pattern(regexp = "^.{3,100}$",message = "标题长度必须在3-100之间")
private String title;
/**
@@ -65,13 +68,7 @@ public class News implements Serializable {
@TableLogic
private Integer status;
- public Long getNewsId() {
- return newsId;
- }
- public void setNewsId(Long newsId) {
- this.newsId = newsId;
- }
public Long getUserId() {
return userId;
}
@@ -79,6 +76,15 @@ public class News implements Serializable {
public void setUserId(Long userId) {
this.userId = userId;
}
+
+ public Long getNewsId() {
+ return newsId;
+ }
+
+ public void setNewsId(Long newsId) {
+ this.newsId = newsId;
+ }
+
public String getCategory() {
return category;
}
@@ -132,15 +138,15 @@ public class News implements Serializable {
@Override
public String toString() {
return "News{" +
- "newsId=" + newsId +
- ", userId=" + userId +
- ", category=" + category +
- ", title=" + title +
- ", content=" + content +
- ", createTime=" + createTime +
- ", belongTeamId=" + belongTeamId +
- ", state=" + state +
- ", status=" + status +
- "}";
+ "newsId=" + newsId +
+ ", userId=" + userId +
+ ", category='" + category + '\'' +
+ ", title='" + title + '\'' +
+ ", content='" + content + '\'' +
+ ", createTime=" + createTime +
+ ", belongTeamId=" + belongTeamId +
+ ", state='" + state + '\'' +
+ ", status=" + status +
+ '}';
}
}
diff --git a/src/main/java/com/javaee/newssystem/entity/Team.java b/src/main/java/com/javaee/newssystem/entity/Team.java
index 80ab34c75592610cadaf7b02a500651f1f840c0e..b271d396f9d098b281a0e28a005b7f8d09b290b4 100644
--- a/src/main/java/com/javaee/newssystem/entity/Team.java
+++ b/src/main/java/com/javaee/newssystem/entity/Team.java
@@ -3,6 +3,7 @@ package com.javaee.newssystem.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
+import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
@@ -27,6 +28,7 @@ public class Team implements Serializable {
/**
* 团队名字
*/
+ @Pattern(regexp = "^.{3,20}$",message = "团队名字长度必须在3-20之间")
private String teamName;
/**
diff --git a/src/main/java/com/javaee/newssystem/entity/User.java b/src/main/java/com/javaee/newssystem/entity/User.java
index 4aab674a64f4debabe18637dfecf55e401019a28..6ba96c220b52ba5403038a222458c5f80d7eafcc 100644
--- a/src/main/java/com/javaee/newssystem/entity/User.java
+++ b/src/main/java/com/javaee/newssystem/entity/User.java
@@ -3,6 +3,8 @@ package com.javaee.newssystem.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
import java.io.Serializable;
import java.util.Date;
@@ -14,6 +16,7 @@ import java.util.Date;
* @author qjj
* @since 2022-11-28
*/
+
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@@ -27,21 +30,25 @@ public class User implements Serializable {
/**
* 用户名
*/
+ @Pattern(regexp = "^.{3,20}$",message = "用户名长度必须在3-20之间")
private String userName;
/**
* 密码
*/
+ @Pattern(regexp = "^[a-zA-Z]\\w{5,17}$",message = "密码必须以字母开头,长度在6~18之间,只能包含字母、数字和下划线")
private String userPassword;
/**
* 手机号
*/
+ @Pattern(regexp = "^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\\d{8}$",message = "手机号格式不对")
private String userPhone;
/**
* 邮箱,对照着用户id,登录使用
*/
+ @Pattern(regexp = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$",message = "邮箱格式不对")
private String userEmail;
/**
diff --git a/src/main/java/com/javaee/newssystem/interceptor/LoginInterceptor.java b/src/main/java/com/javaee/newssystem/interceptor/LoginInterceptor.java
index 8728c71b59813253ea7d79738decbfc525a21e09..d61832b69d24f57952286bae98689cfd51e37cea 100644
--- a/src/main/java/com/javaee/newssystem/interceptor/LoginInterceptor.java
+++ b/src/main/java/com/javaee/newssystem/interceptor/LoginInterceptor.java
@@ -26,7 +26,7 @@ public class LoginInterceptor implements HandlerInterceptor {
}
else {
mapjson.put("code","402");
- mapjson.put("msg","登录过期");
+ mapjson.put("msg","登录过期,请重新登录");
}
}
else {
diff --git a/src/main/java/com/javaee/newssystem/mapper/CommentMapper.java b/src/main/java/com/javaee/newssystem/mapper/CommentMapper.java
index adb9316639397b1c344eddd55a4c85a109187ad4..adad32c58200b8e7ef9e922265f94ad798d90bc3 100644
--- a/src/main/java/com/javaee/newssystem/mapper/CommentMapper.java
+++ b/src/main/java/com/javaee/newssystem/mapper/CommentMapper.java
@@ -2,8 +2,10 @@ package com.javaee.newssystem.mapper;
import com.javaee.newssystem.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Insert;
import org.springframework.stereotype.Repository;
+import java.util.Date;
import java.util.List;
@Repository
@@ -17,4 +19,5 @@ public interface CommentMapper extends BaseMapper {
List selectLikeByUserId(Long userId);
+ Integer isExist(Long userId, Long commentId);
}
diff --git a/src/main/java/com/javaee/newssystem/mapper/JacksonObjectMapper.java b/src/main/java/com/javaee/newssystem/mapper/JacksonObjectMapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..eb2949d775b0faf08f1c657eee41d226c1a0682d
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/mapper/JacksonObjectMapper.java
@@ -0,0 +1,23 @@
+package com.javaee.newssystem.mapper;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
+
+public class JacksonObjectMapper extends ObjectMapper {
+
+ public JacksonObjectMapper(){
+ super();
+// 收到未知属性时不报异常
+ this.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,false);
+
+// 反序列化时,属性不存在的兼容处理
+ this.getDeserializationConfig().withoutFeatures(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+ SimpleModule simpleModule = new SimpleModule()
+ .addSerializer(Long.class, ToStringSerializer.instance)
+ .addSerializer(long.class, ToStringSerializer.instance);
+// 注册
+ this.registerModule(simpleModule);
+ }
+}
diff --git a/src/main/java/com/javaee/newssystem/mapper/NewsMapper.java b/src/main/java/com/javaee/newssystem/mapper/NewsMapper.java
index c26a376d7c3c9f64ac3ade7056c97c8de54f24d0..2811c0e6152754057b23b5a2532cc6b356476508 100644
--- a/src/main/java/com/javaee/newssystem/mapper/NewsMapper.java
+++ b/src/main/java/com/javaee/newssystem/mapper/NewsMapper.java
@@ -1,6 +1,5 @@
package com.javaee.newssystem.mapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaee.newssystem.entity.News;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
@@ -20,4 +19,11 @@ public interface NewsMapper extends BaseMapper {
List getFocusListByid(Long userId);
Integer getFocusNewsListByid(Long newsId);
+
+ Integer insertToFocusWithNews(Long newsId, Long userId);
+
+ Integer deleteFromFocusWithNews(Long newsId, Long userId);
+
+
+ Integer isExist(Long newsId, Long userId);
}
diff --git a/src/main/java/com/javaee/newssystem/mapper/UserMapper.java b/src/main/java/com/javaee/newssystem/mapper/UserMapper.java
index 167551334c9a0876758ad43afb565acd445460f0..4a6df551431dbd2802d1df4f9c23f0f6a5e74c8b 100644
--- a/src/main/java/com/javaee/newssystem/mapper/UserMapper.java
+++ b/src/main/java/com/javaee/newssystem/mapper/UserMapper.java
@@ -1,10 +1,12 @@
package com.javaee.newssystem.mapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.javaee.newssystem.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
+import java.util.Map;
/**
*
@@ -21,7 +23,12 @@ public interface UserMapper extends BaseMapper {
Integer insertFocus(Long userId,Long focusedUserId);
- Integer delete(Long userId,Long focusedUserId);
+ Integer deleteFromFocusAndUser(Long userId,Long focusedUserId);
Integer changeStatus(Long userId);
+
+ Integer isExist(Long userId,Long newsId);
+
+ Integer isExistInFocusUser(Long userId,Long focusedUserId);
+
}
diff --git a/src/main/java/com/javaee/newssystem/mybatisgener.java b/src/main/java/com/javaee/newssystem/mybatisgener.java
deleted file mode 100644
index ebd640e5a1d3f6de8a0512e2e7315c2fbc810f2f..0000000000000000000000000000000000000000
--- a/src/main/java/com/javaee/newssystem/mybatisgener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.javaee.newssystem;
-
-import com.baomidou.mybatisplus.generator.FastAutoGenerator;
-import com.baomidou.mybatisplus.generator.config.OutputFile;
-import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
-
-import java.util.Collections;
-//代码生成器,不要运行!
-public class mybatisgener {
-
- public static void main(String[] args) {
- FastAutoGenerator.create("jdbc:mysql://124.70.20.202:3306/javaee?serverTimezone=GMT","root","QQqq814287041")
- .globalConfig(builder -> {
- builder.author("qjj")
- .fileOverride()
- .outputDir("D:\\ProgramFiles\\IdeaProjects\\news-system\\src\\main\\java");
- })
- .packageConfig(builder -> {
- builder.parent("com.javaee")
- .moduleName("newssystem")
- .pathInfo(Collections.singletonMap(OutputFile.mapperXml,"D:\\ProgramFiles\\IdeaProjects\\news-system\\src\\main\\resources\\mapper"));
- })
- .strategyConfig(builder -> {
- builder.addInclude("admin","comment","news","team","user");
- })
- .templateEngine(new FreemarkerTemplateEngine())
- .execute();
- }
-}
diff --git a/src/main/java/com/javaee/newssystem/service/IAdminService.java b/src/main/java/com/javaee/newssystem/service/IAdminService.java
index 36426d5dcfe7f3cb03f90f6ac063be462e82ecf1..371f43ab5b75ed31209899d4afe091e1a19b94ab 100644
--- a/src/main/java/com/javaee/newssystem/service/IAdminService.java
+++ b/src/main/java/com/javaee/newssystem/service/IAdminService.java
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaee.newssystem.entity.Admin;
import com.baomidou.mybatisplus.extension.service.IService;
import com.javaee.newssystem.entity.User;
+import com.javaee.newssystem.vo.AdminVo;
/**
*
@@ -15,6 +16,6 @@ import com.javaee.newssystem.entity.User;
*/
public interface IAdminService extends IService {
- Admin Login(String userName,String password);
+ AdminVo Login(String userName, String password);
}
diff --git a/src/main/java/com/javaee/newssystem/service/ICommentService.java b/src/main/java/com/javaee/newssystem/service/ICommentService.java
index 975e2e3bf8c8001f4f1f6112d884cf7c790a8edb..629406200ab8b1a198b5453ba64dc42b4f8a2171 100644
--- a/src/main/java/com/javaee/newssystem/service/ICommentService.java
+++ b/src/main/java/com/javaee/newssystem/service/ICommentService.java
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.javaee.newssystem.entity.News;
import com.javaee.newssystem.entity.Team;
import com.javaee.newssystem.entity.User;
+import com.javaee.newssystem.vo.CommentVo;
import org.springframework.web.multipart.MultipartFile;
/**
@@ -18,7 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
*/
public interface ICommentService extends IService {
- Comment createComment(Comment comment);
+ CommentVo createComment(Comment comment);
Boolean createLike(Long userId, Long commentId);
@@ -26,10 +27,12 @@ public interface ICommentService extends IService {
Boolean deleteComment(Long commentId);
- Page GetFirstCommentList(Long newsId,Integer current, Integer size);
+ Page GetFirstCommentList(Long newsId, Integer current, Integer size, String token);
- Page GetMyselfList(Long userId, Integer current, Integer size);
+ Page GetMyselfList(Long userId, Integer current, Integer size);
- Page getLikeComment(Long userId, Integer current, Integer size);
+ Page getLikeComment(Long userId, Integer current, Integer size);
+
+ Page GetSecondCommentList(Long userId, Integer current, Integer size,String token);
}
diff --git a/src/main/java/com/javaee/newssystem/service/INewsService.java b/src/main/java/com/javaee/newssystem/service/INewsService.java
index 3d98e095f28f503099ff5f81da4811fb809c0153..1f037e44d3d3aa2e89c21de238a1367f999b117e 100644
--- a/src/main/java/com/javaee/newssystem/service/INewsService.java
+++ b/src/main/java/com/javaee/newssystem/service/INewsService.java
@@ -1,9 +1,13 @@
package com.javaee.newssystem.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.javaee.newssystem.entity.HotWord;
import com.javaee.newssystem.entity.News;
import com.baomidou.mybatisplus.extension.service.IService;
import com.javaee.newssystem.mapper.NewsMapper;
+import com.javaee.newssystem.vo.NewsVo;
+
+import java.util.List;
/**
*
@@ -15,34 +19,46 @@ import com.javaee.newssystem.mapper.NewsMapper;
*/
public interface INewsService extends IService {
- Page GetPublicList(Integer current, Integer size);
+ Page GetPublicList(Integer current, Integer size,String token);
- void CreateNews(News news);
+ NewsVo CreateNews(News news,String token);
- void SaveNews(News news);
+ NewsVo SaveNews(News news,String token);
- Page GetFocusList(Long userId, Integer current, Integer size);
+ Page GetFocusList(Long userId, Integer current, Integer size);
- Page GetTeamList(Long teamId,Integer current, Integer size);
+ Page GetTeamList(Long teamId,Integer current, Integer size,String token);
- Page GetMyselfList(Long userId, Integer current, Integer size);
+ Page GetMyselfList(Long userId, Integer current, Integer size,String token);
- News updateInfo(News news);
+ NewsVo updateInfo(News news,String token);
Boolean deleteNews(Long newsId);
- Page GetPassList(Integer current, Integer size);
+ Page GetPassList(Integer current, Integer size,String token);
- Page GetUnPassList(Integer current, Integer size);
+ Page GetUnPassList(Integer current, Integer size);
- Page GetUnReviewed(Integer current, Integer size);
+ Page GetUnReviewed(Integer current, Integer size);
- Page GetSaveNews(Long userId, Integer current, Integer size);
+ Page GetSaveNews(Long userId, Integer current, Integer size);
Boolean PassNews(Long newsId);
Integer GetFocusNews(Long newsId);
Boolean UnPassNews(Long newsId);
+
+ Page searchNews(String key, Integer current, Integer size,String token);
+
+ Page addUserInfo(Page page,Long requestorId);
+
+ NewsVo addUserInfo(News news,Long requestorId);
+
+ Boolean UserFocusNews(Long newsId,Long userId);
+
+ Boolean UserCancelFocusNews(Long newsId, Long userId);
+
+ Page getNewsListBycategory(String key, Integer current, Integer size);
}
diff --git a/src/main/java/com/javaee/newssystem/service/ITeamService.java b/src/main/java/com/javaee/newssystem/service/ITeamService.java
index bb2d032da7f7eb8c2e9d74000e3378fa07d2696c..15da038c874fe2479f1639e9a952d478ee465a14 100644
--- a/src/main/java/com/javaee/newssystem/service/ITeamService.java
+++ b/src/main/java/com/javaee/newssystem/service/ITeamService.java
@@ -17,11 +17,11 @@ import java.util.List;
*/
public interface ITeamService extends IService {
- Team createTeam(Team team, MultipartFile headImg);
+ Team createTeam(Team team);
Page getTeamList(Long userId, Integer current, Integer size);
- Team updateInfo(Team team, MultipartFile headImg);
+ Team updateInfo(Team team);
Boolean deleteTeam(Long teamId);
diff --git a/src/main/java/com/javaee/newssystem/service/IUploadService.java b/src/main/java/com/javaee/newssystem/service/IUploadService.java
new file mode 100644
index 0000000000000000000000000000000000000000..4049d0865d45c5dcbf7bc678765b4221d1128ff3
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/service/IUploadService.java
@@ -0,0 +1,7 @@
+package com.javaee.newssystem.service;
+
+import org.springframework.web.multipart.MultipartFile;
+
+public interface IUploadService {
+ String upload(MultipartFile headImg);
+}
diff --git a/src/main/java/com/javaee/newssystem/service/IUserService.java b/src/main/java/com/javaee/newssystem/service/IUserService.java
index 2bb1fe403142cbae054ad0b7887dc7af0e208418..3d155482276031f2731bfb97f321ecee92eff056 100644
--- a/src/main/java/com/javaee/newssystem/service/IUserService.java
+++ b/src/main/java/com/javaee/newssystem/service/IUserService.java
@@ -3,6 +3,7 @@ package com.javaee.newssystem.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.javaee.newssystem.entity.User;
import com.baomidou.mybatisplus.extension.service.IService;
+import com.javaee.newssystem.vo.UserRespVo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@@ -17,29 +18,29 @@ import java.util.List;
*/
public interface IUserService extends IService {
- User Login(String userName,String password);
+ Long Login(String userName,String password);
- void Register(User user);
+ Boolean Register(User user);
- User updateInfo(User user, MultipartFile headImg);
+ UserRespVo updateInfo(User user);
Boolean Logout(Long userId);
- Page getFocusUser(Long userId, Integer current, Integer size);
+ Page getFocusUser(Long userId, Integer current, Integer size);
Boolean addFocusUser(Long userId,Long focusedUserId);
Boolean unFocus(Long userId,Long focusedUserId);
- Page adminGetUserList(Integer current,Integer size);
+ Page adminGetUserList(Integer current,Integer size);
Boolean adminLogoutUser(Long userId);
Boolean adminUnlogoutUser(Long userId);
- List search(String userName);
+ List search(String userName);
Boolean updatePassword(Long userId, String oldPassword, String newsPassword);
- User getUserInfo(String token);
+ UserRespVo getUserInfo(Long userId);
}
diff --git a/src/main/java/com/javaee/newssystem/service/RedisService.java b/src/main/java/com/javaee/newssystem/service/RedisService.java
new file mode 100644
index 0000000000000000000000000000000000000000..36c3ee15c64cd582a27f1edb344df3fd69aedce1
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/service/RedisService.java
@@ -0,0 +1,14 @@
+package com.javaee.newssystem.service;
+
+import com.javaee.newssystem.entity.HotWord;
+
+import java.util.List;
+
+public interface RedisService {
+
+ List getHotKey(Integer number);
+
+ Integer getUserNumber();
+
+ Double[] getNewsNumber();
+}
diff --git a/src/main/java/com/javaee/newssystem/service/ScheduledService.java b/src/main/java/com/javaee/newssystem/service/ScheduledService.java
new file mode 100644
index 0000000000000000000000000000000000000000..df9e8a43ce12d2360c1457830582d356a6f95241
--- /dev/null
+++ b/src/main/java/com/javaee/newssystem/service/ScheduledService.java
@@ -0,0 +1,85 @@
+package com.javaee.newssystem.service;
+
+import com.javaee.newssystem.entity.HotWord;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.Cursor;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.ScanOptions;
+import org.springframework.data.redis.core.ZSetOperations;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Set;
+
+@Service
+public class ScheduledService {
+
+ /**
+ * second(秒),minute(分),hour(时),day of month(日),month(月),day of week(周几).
+ *
+ */
+
+// @Scheduled(cron = "0/10 * * * * *")
+ public void hello(){
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ System.out.println("当前时间:"+simpleDateFormat.format(new Date()));
+ System.out.println("hello(测试定时任务,每10秒输出)");
+ }
+
+ @Autowired
+ RedisTemplate redisTemplate;
+
+// 每天凌晨0点执行,清理热搜内容。
+ @Scheduled(cron = "0 0 0 * * *")
+ public void redisHotKeyClean(){
+ Set> typedTupleSet = redisTemplate.opsForZSet().reverseRangeByScoreWithScores("newsHotKey",1,50000);
+ Iterator> iterator = typedTupleSet.iterator();
+ int flag = 0;
+ double score = 1;
+ while (iterator.hasNext()){
+ flag++;
+ ZSetOperations.TypedTuple