From c7414e18e71a4a35772c4d396b2d3f9cdfe47ad9 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 16:25:01 +0800 Subject: [PATCH 1/5] 1.uniform response status code for music component --- luoo_common/src/main/java/api/StatusCode.java | 12 +-- .../com/luoo/music/client/UserClient.java | 2 +- .../music/controller/ArticleController.java | 81 +++++++++---------- .../controller/BaseExceptionHandler.java | 13 ++- .../music/controller/ChannelController.java | 55 ++++++------- .../music/controller/ColumnController.java | 55 ++++++------- .../luoo/music/controller/SongController.java | 67 +++++++-------- .../luoo/user/controller/AdminController.java | 2 +- 8 files changed, 128 insertions(+), 159 deletions(-) diff --git a/luoo_common/src/main/java/api/StatusCode.java b/luoo_common/src/main/java/api/StatusCode.java index a424728..b8bd5ce 100644 --- a/luoo_common/src/main/java/api/StatusCode.java +++ b/luoo_common/src/main/java/api/StatusCode.java @@ -14,17 +14,13 @@ public enum StatusCode implements IErrorCode { USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"), USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"), // music 模块错误码以20XXX,不足5位补0; - + MUSIC_COMMON_FAILED(20000, "歌曲模块失败"), // comment 模块错误码以30XXX,不足5位补0; - + COMMENT_COMMON_FAILED(30000, "评论模块失败"), // friend 模块错误码以40XXX,不足5位补0; - + FRIEND_COMMON_FAILED(40000, "交友模块失败"), // tag 模块错误码以50XXX,不足5位补0; - - // music 模块错误码以60XXX,不足5位补0; - - // manage 模块错误码以70XXX,不足5位补0; - MANAGE_COMMON_FAILED(70000, "管理模块失败"); + TAG_COMMON_FAILED(50000, "标签模块失败"); private int code; private String message; diff --git a/luoo_music/src/main/java/com/luoo/music/client/UserClient.java b/luoo_music/src/main/java/com/luoo/music/client/UserClient.java index 7727aa3..6a7099d 100644 --- a/luoo_music/src/main/java/com/luoo/music/client/UserClient.java +++ b/luoo_music/src/main/java/com/luoo/music/client/UserClient.java @@ -1,6 +1,6 @@ package com.luoo.music.client; -import entity.Result; +import api.Result; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; diff --git a/luoo_music/src/main/java/com/luoo/music/controller/ArticleController.java b/luoo_music/src/main/java/com/luoo/music/controller/ArticleController.java index cd9daa9..d315454 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/ArticleController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/ArticleController.java @@ -5,19 +5,13 @@ import java.util.Map; import com.luoo.music.client.UserClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; - +import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Article; import com.luoo.music.service.ArticleService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; + /** * 控制器层 * @author Administrator @@ -34,33 +28,32 @@ public class ArticleController { @Autowired private UserClient userClient; - @RequestMapping(value = "/admin",method = RequestMethod.GET) - public Result findAdmin(){ - Result result =userClient.findAll(); - return result; + @GetMapping("/admin") + public Result findAdmin(){ + return userClient.findAll(); } - @RequestMapping(value = "/examine/{articleId}",method = RequestMethod.PUT) - public Result examine (@PathVariable String articleId){ + @PutMapping("/examine/{articleId}") + public Result examine (@PathVariable String articleId){ articleService.updateState(articleId); - return new Result(true,StatusCode.OK,"审核成功"); + return Result.success(); } - @RequestMapping(value = "/thumbup/{articleId}",method = RequestMethod.PUT) - public Result thumbup (@PathVariable String articleId){ + @PutMapping("/thumbup/{articleId}") + public Result thumbup (@PathVariable String articleId){ articleService.addThumbup(articleId); - return new Result(true,StatusCode.OK,"点赞成功"); + return Result.success(); } /** * 查询全部数据 * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",articleService.findAll()); + @GetMapping + public Result> findAll(){ + return Result.success(articleService.findAll()); } /** @@ -68,14 +61,14 @@ public class ArticleController { * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",articleService.findById(id)); + @GetMapping("/{id}") + public Result
findById(@PathVariable String id){ + return Result.success(articleService.findById(id)); } - @RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) - public Result findByVolid(@PathVariable String volid){ - return new Result(true,StatusCode.OK,"查询成功",articleService.findByVolid(volid)); + @GetMapping("/findByVolid/{volid}") + public Result
findByVolid(@PathVariable String volid){ + return Result.success(articleService.findByVolid(volid)); } @@ -86,10 +79,10 @@ public class ArticleController { * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @PostMapping("/search/{page}/{size}") + public Result> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page
pageList = articleService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult
(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult
(pageList.getTotalElements(), pageList.getContent()) ); } /** @@ -97,40 +90,40 @@ public class ArticleController { * @param searchMap * @return */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",articleService.findSearch(searchMap)); + @PostMapping("/search") + public Result> findSearch( @RequestBody Map searchMap){ + return Result.success(articleService.findSearch(searchMap)); } /** * 增加 * @param article */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Article article ){ + @PostMapping + public Result add(@RequestBody Article article ){ articleService.add(article); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } /** * 修改 * @param article */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Article article, @PathVariable String id ){ + @PutMapping("/{id}") + public Result update(@RequestBody Article article, @PathVariable String id ){ article.setId(id); articleService.update(article); - return new Result(true,StatusCode.OK,"修改成功"); + return Result.success(); } /** * 删除 * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id ){ articleService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/BaseExceptionHandler.java b/luoo_music/src/main/java/com/luoo/music/controller/BaseExceptionHandler.java index 24d1b63..5bfcce7 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/BaseExceptionHandler.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/BaseExceptionHandler.java @@ -1,12 +1,9 @@ package com.luoo.music.controller; -import entity.Result; -import entity.StatusCode; +import api.Result; +import api.StatusCode; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; /** * 统一异常处理类 */ @@ -15,8 +12,8 @@ public class BaseExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody - public Result error(Exception e){ - e.printStackTrace(); - return new Result(false, StatusCode.ERROR, "执行出错"); + public Result error(Exception e){ + e.printStackTrace(); + return Result.failed(StatusCode.MUSIC_COMMON_FAILED); } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/ChannelController.java b/luoo_music/src/main/java/com/luoo/music/controller/ChannelController.java index cf8c077..1483bea 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/ChannelController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/ChannelController.java @@ -4,19 +4,14 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Channel; import com.luoo.music.service.ChannelService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; + /** * 控制器层 * @author Administrator @@ -35,9 +30,9 @@ public class ChannelController { * 查询全部数据 * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",channelService.findAll()); + @GetMapping + public Result> findAll(){ + return Result.success(channelService.findAll()); } /** @@ -45,9 +40,9 @@ public class ChannelController { * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",channelService.findById(id)); + @GetMapping("/{id}") + public Result findById(@PathVariable String id){ + return Result.success(channelService.findById(id)); } @@ -58,10 +53,10 @@ public class ChannelController { * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @PostMapping("/search/{page}/{size}") + public Result> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page pageList = channelService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent()) ); } /** @@ -69,40 +64,40 @@ public class ChannelController { * @param searchMap * @return */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",channelService.findSearch(searchMap)); + @PostMapping("/search") + public Result> findSearch( @RequestBody Map searchMap){ + return Result.success(channelService.findSearch(searchMap)); } /** * 增加 * @param channel */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Channel channel ){ + @PostMapping + public Result add(@RequestBody Channel channel ){ channelService.add(channel); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } /** * 修改 * @param channel */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Channel channel, @PathVariable String id ){ + @PutMapping("/{id}") + public Result update(@RequestBody Channel channel, @PathVariable String id ){ channel.setId(id); channelService.update(channel); - return new Result(true,StatusCode.OK,"修改成功"); + return Result.success(); } /** * 删除 * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id ){ channelService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/ColumnController.java b/luoo_music/src/main/java/com/luoo/music/controller/ColumnController.java index 02f510b..625fdea 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/ColumnController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/ColumnController.java @@ -4,19 +4,14 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.web.bind.annotation.CrossOrigin; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.luoo.music.pojo.Column; import com.luoo.music.service.ColumnService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; + /** * 控制器层 * @author Administrator @@ -35,9 +30,9 @@ public class ColumnController { * 查询全部数据 * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",columnService.findAll()); + @GetMapping + public Result> findAll(){ + return Result.success(columnService.findAll()); } /** @@ -45,9 +40,9 @@ public class ColumnController { * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",columnService.findById(id)); + @GetMapping("/{id}") + public Result findById(@PathVariable String id){ + return Result.success(columnService.findById(id)); } @@ -58,10 +53,10 @@ public class ColumnController { * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @PostMapping("/search/{page}/{size}") + public Result> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page pageList = columnService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent()) ); } /** @@ -69,40 +64,40 @@ public class ColumnController { * @param searchMap * @return */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",columnService.findSearch(searchMap)); + @PostMapping("/search") + public Result> findSearch( @RequestBody Map searchMap){ + return Result.success(columnService.findSearch(searchMap)); } /** * 增加 * @param column */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Column column ){ + @PostMapping + public Result add(@RequestBody Column column ){ columnService.add(column); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } /** * 修改 * @param column */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Column column, @PathVariable String id ){ + @PutMapping("/{id}") + public Result update(@RequestBody Column column, @PathVariable String id ){ column.setId(id); columnService.update(column); - return new Result(true,StatusCode.OK,"修改成功"); + return Result.success(); } /** * 删除 * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id ){ columnService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } } diff --git a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java index 95618b6..1d272ba 100644 --- a/luoo_music/src/main/java/com/luoo/music/controller/SongController.java +++ b/luoo_music/src/main/java/com/luoo/music/controller/SongController.java @@ -3,13 +3,11 @@ package com.luoo.music.controller; import com.luoo.music.pojo.Article; import com.luoo.music.pojo.Song; -import com.luoo.music.service.ArticleService; +import com.luoo.music.pojo.SongVO; import com.luoo.music.service.SongService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.json.JsonParser; import org.springframework.data.domain.Page; import org.springframework.web.bind.annotation.*; @@ -26,23 +24,18 @@ public class SongController { @Autowired private SongService songService; - - - /** * 查询全部数据 * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true, StatusCode.OK,"查询成功",songService.findAll()); + @GetMapping + public Result> findAll(){ + return Result.success(songService.findAll()); } - - - @RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) - public Result findByVolid(@PathVariable String volid){ - return new Result(true,StatusCode.OK,"查询成功",songService.findByVolid(volid)); + @GetMapping("/findByVolid/{volid}") + public Result> findByVolid(@PathVariable String volid){ + return Result.success(songService.findByVolid(volid)); } /** @@ -50,9 +43,9 @@ public class SongController { * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",songService.findById(id)); + @GetMapping("/{id}") + public Result findById(@PathVariable String id){ + return Result.success(songService.findById(id)); } @@ -63,15 +56,15 @@ public class SongController { * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @PostMapping("/search/{page}/{size}") + public Result> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ Page pageList = songService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent()) ); } - @RequestMapping(value = "/init",method = RequestMethod.POST) - public Result init(@RequestBody Map map) { + @PostMapping("/init") + public Result init(@RequestBody Map map) { List data = (List) map.get("data"); System.out.println(data.size()); Song song = new Song(); @@ -112,7 +105,7 @@ public class SongController { for (Article pojo : set) { // articleService.add(pojo); } - return new Result(true,StatusCode.OK,"init"); + return Result.success(); } /** @@ -120,9 +113,9 @@ public class SongController { * @param searchMap * @return */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",songService.findSearch(searchMap)); + @PostMapping("/search") + public Result> findSearch( @RequestBody Map searchMap){ + return Result.success(songService.findSearch(searchMap)); } @@ -130,30 +123,30 @@ public class SongController { * 增加 * @param song */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Song song){ + @PostMapping + public Result add(@RequestBody Song song){ songService.add(song); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } /** * 修改 * @param song */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Song song, @PathVariable String id ){ + @PutMapping("/{id}") + public Result update(@RequestBody Song song, @PathVariable String id ){ song.setId(id); songService.update(song); - return new Result(true,StatusCode.OK,"修改成功"); + return Result.success(); } /** * 删除 * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @DeleteMapping("/{id}") + public Result delete(@PathVariable String id ){ songService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } } diff --git a/luoo_user/src/main/java/com/luoo/user/controller/AdminController.java b/luoo_user/src/main/java/com/luoo/user/controller/AdminController.java index 1bed98f..25ff1fe 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/AdminController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/AdminController.java @@ -67,7 +67,7 @@ public class AdminController { * 查询全部数据 * @return */ - @GetMapping("/list") + @GetMapping public Result> findAll(){ return Result.success(adminService.findAll()); } From 67b26776b582ba7af59d589ed31368477b1f7a0c Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 16:33:05 +0800 Subject: [PATCH 2/5] 1.uniform response status code for comment component --- .../comment/controller/CommentController.java | 59 ++++++++++--------- luoo_common/src/main/java/api/StatusCode.java | 1 + 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java index 9d7fd3c..36f4504 100644 --- a/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java +++ b/luoo_comment/src/main/java/com/luoo/comment/controller/CommentController.java @@ -3,9 +3,12 @@ package com.luoo.comment.controller; import com.luoo.comment.pojo.Comment; import com.luoo.comment.service.CommentService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; +import api.StatusCode; + +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.redis.core.RedisTemplate; @@ -22,64 +25,62 @@ public class CommentController { @Autowired private RedisTemplate redisTemplate; - @RequestMapping(method = RequestMethod.GET) - public Result findAll(){ - return new Result(true, StatusCode.OK,"",commentService.findAll()); + @GetMapping + public Result> findAll(){ + return Result.success(commentService.findAll()); } - @RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) - public Result findByVolid(@PathVariable String volid){ - return new Result(true,StatusCode.OK,"查询成功",commentService.findByVolid(volid)); + @GetMapping("/findByVolid/{volid}") + public Result> findByVolid(@PathVariable String volid){ + return Result.success(commentService.findByVolid(volid)); } - @RequestMapping(value = "/{commentId}",method = RequestMethod.GET) - public Result findById(@PathVariable String commentId) { - return new Result(true, StatusCode.OK,"",commentService.findById(commentId)); + @GetMapping("/{commentId}") + public Result findById(@PathVariable String commentId) { + return Result.success(commentService.findById(commentId)); } - @RequestMapping(method = RequestMethod.POST) - public Result save(@RequestBody Comment comment){ + @PostMapping + public Result save(@RequestBody Comment comment){ commentService.save(comment); - return new Result(true,StatusCode.OK,"保存成功"); + return Result.success(); } - @RequestMapping(value = "/{commentId}",method = RequestMethod.PUT) - public Result update(@PathVariable String commentId,@RequestBody Comment comment){ + @PutMapping("/{commentId}") + public Result update(@PathVariable String commentId,@RequestBody Comment comment){ comment.set_id(commentId); commentService.update(comment); - return new Result(true,StatusCode.OK,"修改成功"); + return Result.success(); } - @RequestMapping(value = "/{commentId}",method = RequestMethod.DELETE) - public Result delete(@PathVariable String commentId){ + @DeleteMapping("/{commentId}") + public Result delete(@PathVariable String commentId){ commentService.deleteById(commentId); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } - @RequestMapping(value = "/{parentid}/{page}/{size}",method = RequestMethod.GET) - public Result findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){ + @GetMapping("/{parentid}/{page}/{size}") + public Result> findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){ Page pageData = commentService.findByParentId(parentid,page,size); - - return new Result(true,StatusCode.OK,"查询成功",new PageResult(pageData.getTotalElements(),pageData.getContent())); + return Result.success(new PageResult(pageData.getTotalElements(),pageData.getContent())); } - @RequestMapping(value = "/thumbup/{commentId}",method = RequestMethod.PUT) + @PutMapping("/thumbup/{commentId}") public Result thumbup(@PathVariable String commentId){ - String userid="111"; if (redisTemplate.opsForValue().get("thumbup_"+userid)!=null){ - return new Result(true,StatusCode.REPERROR,"重复提交"); + return Result.failed(StatusCode.COMMENT_REPEAT_SUBMIT); } commentService.thumbup(commentId); redisTemplate.opsForValue().set("thumbup_"+userid,1); - return new Result(true,StatusCode.OK,"点赞成功"); + return Result.success(); } } diff --git a/luoo_common/src/main/java/api/StatusCode.java b/luoo_common/src/main/java/api/StatusCode.java index b8bd5ce..04e42b8 100644 --- a/luoo_common/src/main/java/api/StatusCode.java +++ b/luoo_common/src/main/java/api/StatusCode.java @@ -17,6 +17,7 @@ public enum StatusCode implements IErrorCode { MUSIC_COMMON_FAILED(20000, "歌曲模块失败"), // comment 模块错误码以30XXX,不足5位补0; COMMENT_COMMON_FAILED(30000, "评论模块失败"), + COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"), // friend 模块错误码以40XXX,不足5位补0; FRIEND_COMMON_FAILED(40000, "交友模块失败"), // tag 模块错误码以50XXX,不足5位补0; From a29d8b9bc1a1fe589078463e61048f014ed84047 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 16:45:28 +0800 Subject: [PATCH 3/5] 1.uniform response status code for friend component --- luoo_common/src/main/java/api/StatusCode.java | 2 ++ .../com/luoo/friend/client/UserClient.java | 5 ++- .../friend/controller/FriendController.java | 35 +++++++++---------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/luoo_common/src/main/java/api/StatusCode.java b/luoo_common/src/main/java/api/StatusCode.java index 04e42b8..ce17ac1 100644 --- a/luoo_common/src/main/java/api/StatusCode.java +++ b/luoo_common/src/main/java/api/StatusCode.java @@ -20,6 +20,8 @@ public enum StatusCode implements IErrorCode { COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"), // friend 模块错误码以40XXX,不足5位补0; FRIEND_COMMON_FAILED(40000, "交友模块失败"), + FRIEND_CAN_NOT_REPEAT_ADD_FRIEND(40001, "不能重复添加好友"), + FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND(40002, "不能重复添加非好友"), // tag 模块错误码以50XXX,不足5位补0; TAG_COMMON_FAILED(50000, "标签模块失败"); private int code; diff --git a/luoo_friend/src/main/java/com/luoo/friend/client/UserClient.java b/luoo_friend/src/main/java/com/luoo/friend/client/UserClient.java index bdf3712..b422e74 100644 --- a/luoo_friend/src/main/java/com/luoo/friend/client/UserClient.java +++ b/luoo_friend/src/main/java/com/luoo/friend/client/UserClient.java @@ -3,12 +3,11 @@ package com.luoo.friend.client; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PutMapping; @FeignClient("luoo-user") public interface UserClient { - @RequestMapping(value = "/user/{userid}/{friendid}/{x}",method = RequestMethod.PUT) + @PutMapping("/user/{userid}/{friendid}/{x}") public void updatefanscountandfollowcount(@PathVariable String userid, @PathVariable String friendid, @PathVariable int x); } diff --git a/luoo_friend/src/main/java/com/luoo/friend/controller/FriendController.java b/luoo_friend/src/main/java/com/luoo/friend/controller/FriendController.java index 1184416..2f51878 100644 --- a/luoo_friend/src/main/java/com/luoo/friend/controller/FriendController.java +++ b/luoo_friend/src/main/java/com/luoo/friend/controller/FriendController.java @@ -3,14 +3,11 @@ package com.luoo.friend.controller; import com.luoo.friend.client.UserClient; import com.luoo.friend.service.FriendService; -import entity.Result; -import entity.StatusCode; +import api.Result; +import api.StatusCode; import io.jsonwebtoken.Claims; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; @@ -32,13 +29,13 @@ public class FriendController { * * @return */ - @RequestMapping(value = "/like/{friendid}/{type}", method = RequestMethod.PUT) - public Result addFriend(@PathVariable String friendid, @PathVariable String type) { + @PutMapping("/like/{friendid}/{type}") + public Result addFriend(@PathVariable String friendid, @PathVariable String type) { //验证是否登录,并且拿到ID Claims claims = (Claims) request.getAttribute("claims_user"); if (claims == null) { - return new Result(false, StatusCode.LOGINERROR, "权限不足"); + return Result.unauthorized(null); } String userid = claims.getId(); //判断是添加好友还是非好友 @@ -47,41 +44,41 @@ public class FriendController { //添加好友 int flag = friendService.addFriend(userid,friendid); if (flag == 0) { - return new Result(false, StatusCode.ERROR, "不能重复添加好友"); + return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_FRIEND); } if (flag == 1) { userClient.updatefanscountandfollowcount(userid,friendid,1); - return new Result(true, StatusCode.OK, "添加成功"); + return Result.success(); } } else if (type.equals("2")) { //添加非好友 int flag = friendService.addNoFriend(userid,friendid); if (flag == 0) { - return new Result(false, StatusCode.ERROR, "不能重复添加非好友"); + return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND); } if (flag == 1) { - return new Result(true, StatusCode.OK, "添加成功"); + return Result.success(); } } - return new Result(false, StatusCode.ERROR, "参数异常"); + return Result.failed(StatusCode.VALIDATE_FAILED); } else { - return new Result(false, StatusCode.ERROR, "参数异常"); + return Result.failed(StatusCode.VALIDATE_FAILED); } } - @RequestMapping(value = "/{friendid}", method = RequestMethod.DELETE) - public Result deleteFriend(@PathVariable String friendid){ + @DeleteMapping("/{friendid}") + public Result deleteFriend(@PathVariable String friendid){ //验证是否登录,并且拿到ID Claims claims = (Claims) request.getAttribute("claims_user"); if (claims == null) { - return new Result(false, StatusCode.LOGINERROR, "权限不足"); + return Result.unauthorized(null); } String userid = claims.getId(); friendService.deleteFriend(userid,friendid); userClient.updatefanscountandfollowcount(userid,friendid,-1); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } } From 91a8962550483c4882508de38e0715f188e190d7 Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 16:51:54 +0800 Subject: [PATCH 4/5] 1.uniform response status code for tag component --- .../java/com/luoo/tag/client/UserClient.java | 7 +++-- .../tag/controller/BaseExceptionHandler.java | 12 ++++----- .../luoo/tag/controller/TagController.java | 26 +++++++++---------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/luoo_tag/src/main/java/com/luoo/tag/client/UserClient.java b/luoo_tag/src/main/java/com/luoo/tag/client/UserClient.java index 4087884..273aebf 100644 --- a/luoo_tag/src/main/java/com/luoo/tag/client/UserClient.java +++ b/luoo_tag/src/main/java/com/luoo/tag/client/UserClient.java @@ -1,13 +1,12 @@ package com.luoo.tag.client; -import entity.Result; +import api.Result; import org.springframework.cloud.openfeign.FeignClient; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.GetMapping; @FeignClient("luoo-user") public interface UserClient { - @RequestMapping(value = "/admin",method= RequestMethod.GET) + @GetMapping("/admin") public Result findAll(); } diff --git a/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java b/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java index 8191039..c6cebd6 100644 --- a/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java +++ b/luoo_tag/src/main/java/com/luoo/tag/controller/BaseExceptionHandler.java @@ -1,8 +1,8 @@ package com.luoo.tag.controller; import exception.BizException; -import entity.Result; -import entity.StatusCode; +import api.Result; +import api.StatusCode; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -16,15 +16,15 @@ public class BaseExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody - public Result error(Exception e){ + public Result error(Exception e){ log.error("执行出错", e); - return new Result(false, StatusCode.ERROR, "执行出错"); + return Result.failed(StatusCode.TAG_COMMON_FAILED); } @ExceptionHandler(value = BizException.class) @ResponseBody - public Result error(BizException e){ + public Result error(BizException e){ log.info("业务错误:{}", e.getMessage()); - return new Result(false, StatusCode.ERROR, e.getMessage()); + return Result.failed(StatusCode.TAG_COMMON_FAILED, e.getMessage()); } } diff --git a/luoo_tag/src/main/java/com/luoo/tag/controller/TagController.java b/luoo_tag/src/main/java/com/luoo/tag/controller/TagController.java index d9b31b6..2412c2b 100644 --- a/luoo_tag/src/main/java/com/luoo/tag/controller/TagController.java +++ b/luoo_tag/src/main/java/com/luoo/tag/controller/TagController.java @@ -5,7 +5,7 @@ import com.luoo.tag.pojo.TagDTO; import com.luoo.tag.pojo.TagQueryReq; import com.luoo.tag.pojo.TagUpdateReq; import com.luoo.tag.service.TagService; -import entity.ResultVO; +import api.Result; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.validation.annotation.Validated; @@ -32,23 +32,23 @@ public class TagController { @ApiImplicitParam(name = "pageNum", value = "页码", required = true), @ApiImplicitParam(name = "pageSize", value = "每页数", required = true) }) @GetMapping("/list") - public ResultVO> getById(@Validated TagQueryReq queryReq) { - return ResultVO.success(tagService.queryPage(queryReq)); + public Result> getById(@Validated TagQueryReq queryReq) { + return Result.success(tagService.queryPage(queryReq)); } @ApiOperation(value = "查询标签详情", notes = "查询标签详情") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @GetMapping("/{id}") - public ResultVO getById(@PathVariable String id) { - return ResultVO.success(tagService.queryById(id)); + public Result getById(@PathVariable String id) { + return Result.success(tagService.queryById(id)); } @ApiOperation(value = "新增标签信息", notes = "新增标签信息") @ApiImplicitParams({ @ApiImplicitParam(name = "createReq", value = "创建参数", required = true) }) @PostMapping - public ResultVO create(@Validated @RequestBody TagCreateReq createReq) { + public Result create(@Validated @RequestBody TagCreateReq createReq) { tagService.create(createReq); - return ResultVO.success("创建成功"); + return Result.success(); } @ApiOperation(value = "更新标签信息", notes = "更新标签信息") @@ -56,10 +56,10 @@ public class TagController { @ApiImplicitParam(name = "updateReq", value = "更新参数", required = true), @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @PutMapping("/{id}") - public ResultVO update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) { + public Result update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) { updateReq.setId(id); tagService.update(updateReq); - return ResultVO.success("更新成功"); + return Result.success(); } @ApiOperation(value = "更新标签状态", notes = "更新标签状态") @@ -67,16 +67,16 @@ public class TagController { @ApiImplicitParam(name = "id", value = "标签ID", required = true), @ApiImplicitParam(name = "state", value = "标签状态", required = true) }) @PutMapping("/status/{id}") - public ResultVO updateStatus(@PathVariable String id, @RequestParam Integer state) { + public Result updateStatus(@PathVariable String id, @RequestParam Integer state) { tagService.updateState(id, state); - return ResultVO.success("状态更新成功"); + return Result.success(); } @ApiOperation(value = "删除标签", notes = "删除标签") @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @DeleteMapping("/{id}") - public ResultVO delete(@PathVariable String id) { + public Result delete(@PathVariable String id) { tagService.delete(id); - return ResultVO.success("删除成功"); + return Result.success(); } } From cac494fb939a48787bf263a9308ec7fdb09feb9a Mon Sep 17 00:00:00 2001 From: Gary Date: Fri, 12 Jan 2024 17:33:22 +0800 Subject: [PATCH 5/5] 1.remove entity package in common 2.uniform response status code for gathering/recruit component --- luoo_common/src/main/java/api/StatusCode.java | 18 ++-- .../src/main/java/entity/PageResult.java | 31 ------- luoo_common/src/main/java/entity/Result.java | 56 ------------ .../src/main/java/entity/ResultVO.java | 62 ------------- .../src/main/java/entity/StatusCode.java | 16 ---- .../controller/BaseExceptionHandler.java | 12 +-- .../controller/GatheringController.java | 88 ++++++++++--------- .../controller/BaseExceptionHandler.java | 13 ++- .../controller/EnterpriseController.java | 85 ++++++++++-------- .../recruit/controller/RecruitController.java | 88 ++++++++++--------- .../com/luoo/user/service/AdminService.java | 4 - .../com/luoo/user/service/UserService.java | 8 -- 12 files changed, 165 insertions(+), 316 deletions(-) delete mode 100644 luoo_common/src/main/java/entity/PageResult.java delete mode 100644 luoo_common/src/main/java/entity/Result.java delete mode 100644 luoo_common/src/main/java/entity/ResultVO.java delete mode 100644 luoo_common/src/main/java/entity/StatusCode.java diff --git a/luoo_common/src/main/java/api/StatusCode.java b/luoo_common/src/main/java/api/StatusCode.java index ce17ac1..32f8763 100644 --- a/luoo_common/src/main/java/api/StatusCode.java +++ b/luoo_common/src/main/java/api/StatusCode.java @@ -9,21 +9,29 @@ public enum StatusCode implements IErrorCode { FORBIDDEN(403, "没有相关权限"), //user 模块错误码以10XXX,不足5位补0; - USER_COMMON_FAILED(10000, "用户模块失败"), + USER_COMMON_FAILED(10000, "用户模块错误"), USER_VERIFICATION_CODE_EXPIRED(10001, "验证码过期,请重新获取"), USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"), USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"), + // music 模块错误码以20XXX,不足5位补0; - MUSIC_COMMON_FAILED(20000, "歌曲模块失败"), + MUSIC_COMMON_FAILED(20000, "歌曲模块错误"), + // comment 模块错误码以30XXX,不足5位补0; - COMMENT_COMMON_FAILED(30000, "评论模块失败"), + COMMENT_COMMON_FAILED(30000, "评论模块错误"), COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"), + // friend 模块错误码以40XXX,不足5位补0; - FRIEND_COMMON_FAILED(40000, "交友模块失败"), + FRIEND_COMMON_FAILED(40000, "交友模块错误"), FRIEND_CAN_NOT_REPEAT_ADD_FRIEND(40001, "不能重复添加好友"), FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND(40002, "不能重复添加非好友"), + // tag 模块错误码以50XXX,不足5位补0; - TAG_COMMON_FAILED(50000, "标签模块失败"); + TAG_COMMON_FAILED(50000, "标签模块错误"), + + // recruit 模块错误码以50XXX,不足5位补0; + RECRUIT_COMMON_FAILED(60000, "招聘模块错误"); + private int code; private String message; diff --git a/luoo_common/src/main/java/entity/PageResult.java b/luoo_common/src/main/java/entity/PageResult.java deleted file mode 100644 index 1bcff74..0000000 --- a/luoo_common/src/main/java/entity/PageResult.java +++ /dev/null @@ -1,31 +0,0 @@ -package entity; - -import java.util.List; - -public class PageResult { - - private Long total; - private List rows; - - public PageResult(Long total, List rows) { - super(); - this.total = total; - this.rows = rows; - } - - public Long getTotal() { - return total; - } - public void setTotal(Long total) { - this.total = total; - } - public List getRows() { - return rows; - } - public void setRows(List rows) { - this.rows = rows; - } - - - -} diff --git a/luoo_common/src/main/java/entity/Result.java b/luoo_common/src/main/java/entity/Result.java deleted file mode 100644 index 9b18b6e..0000000 --- a/luoo_common/src/main/java/entity/Result.java +++ /dev/null @@ -1,56 +0,0 @@ -package entity; - -public class Result { - - - private boolean flag; - private Integer code; - private String message; - private Object data; - - public Result() { - } - - public Result(boolean flag, Integer code, String message, Object data) { - super(); - this.flag = flag; - this.code = code; - this.message = message; - this.data = data; - } - - public Result(boolean flag, Integer code, String message) { - super(); - this.flag = flag; - this.code = code; - this.message = message; - } - - public boolean isFlag() { - return flag; - } - public void setFlag(boolean flag) { - this.flag = flag; - } - public Integer getCode() { - return code; - } - public void setCode(Integer code) { - this.code = code; - } - public String getMessage() { - return message; - } - public void setMessage(String message) { - this.message = message; - } - public Object getData() { - return data; - } - public void setData(Object data) { - this.data = data; - } - - - -} diff --git a/luoo_common/src/main/java/entity/ResultVO.java b/luoo_common/src/main/java/entity/ResultVO.java deleted file mode 100644 index 0bbb950..0000000 --- a/luoo_common/src/main/java/entity/ResultVO.java +++ /dev/null @@ -1,62 +0,0 @@ -package entity; - -public class ResultVO{ - - - private boolean flag; - private Integer code; - private String message; - private T data; - - public ResultVO() { - } - - public ResultVO(boolean flag, Integer code, String message, T data) { - super(); - this.flag = flag; - this.code = code; - this.message = message; - this.data = data; - } - - public ResultVO(boolean flag, Integer code, String message) { - super(); - this.flag = flag; - this.code = code; - this.message = message; - } - - public boolean isFlag() { - return flag; - } - public void setFlag(boolean flag) { - this.flag = flag; - } - public Integer getCode() { - return code; - } - public void setCode(Integer code) { - this.code = code; - } - public String getMessage() { - return message; - } - public void setMessage(String message) { - this.message = message; - } - public T getData() { - return data; - } - public void setData(T data) { - this.data = data; - } - - public static ResultVO success(T data){ - return new ResultVO<>(true,200,"操作成功", data); - } - - public static ResultVO success(String message){ - return new ResultVO<>(true,200,message); - } - -} diff --git a/luoo_common/src/main/java/entity/StatusCode.java b/luoo_common/src/main/java/entity/StatusCode.java deleted file mode 100644 index 7b86391..0000000 --- a/luoo_common/src/main/java/entity/StatusCode.java +++ /dev/null @@ -1,16 +0,0 @@ -package entity; - -/** - * 状态 - */ -public class StatusCode { - - public static final int OK=200;//成功 - public static final int ERROR=20001;// 失败 - public static final int LOGINERROR=20002;// 用户名或密码错误 - - public static final int ACCESSERROR=20003;// 无权访问 - - public static final int REPERROR=20009;// 重复提交 - -} diff --git a/luoo_gathering/src/main/java/com/luoo/gathering/controller/BaseExceptionHandler.java b/luoo_gathering/src/main/java/com/luoo/gathering/controller/BaseExceptionHandler.java index aebd74f..add93e7 100644 --- a/luoo_gathering/src/main/java/com/luoo/gathering/controller/BaseExceptionHandler.java +++ b/luoo_gathering/src/main/java/com/luoo/gathering/controller/BaseExceptionHandler.java @@ -1,12 +1,8 @@ package com.luoo.gathering.controller; -import entity.Result; -import entity.StatusCode; +import api.Result; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; /** * 统一异常处理类 */ @@ -15,8 +11,8 @@ public class BaseExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody - public Result error(Exception e){ - e.printStackTrace(); - return new Result(false, StatusCode.ERROR, "执行出错"); + public Result error(Exception e){ + e.printStackTrace(); + return Result.failed(); } } diff --git a/luoo_gathering/src/main/java/com/luoo/gathering/controller/GatheringController.java b/luoo_gathering/src/main/java/com/luoo/gathering/controller/GatheringController.java index 1341eaa..0e22d81 100644 --- a/luoo_gathering/src/main/java/com/luoo/gathering/controller/GatheringController.java +++ b/luoo_gathering/src/main/java/com/luoo/gathering/controller/GatheringController.java @@ -1,4 +1,5 @@ package com.luoo.gathering.controller; + import java.util.List; import java.util.Map; @@ -14,11 +15,12 @@ import org.springframework.web.bind.annotation.RestController; import com.luoo.gathering.pojo.Gathering; import com.luoo.gathering.service.GatheringService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; + /** * 控制器层 + * * @author Administrator * */ @@ -29,80 +31,86 @@ public class GatheringController { @Autowired private GatheringService gatheringService; - - + /** * 查询全部数据 + * * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",gatheringService.findAll()); + @RequestMapping(method = RequestMethod.GET) + public Result> findAll() { + return Result.success(gatheringService.findAll()); } - + /** * 根据ID查询 + * * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",gatheringService.findById(id)); + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public Result findById(@PathVariable String id) { + return Result.success(gatheringService.findById(id)); } - /** * 分页+多条件查询 + * * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 + * @param page 页码 + * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST) + public Result> findSearch(@RequestBody Map searchMap, @PathVariable int page, + @PathVariable int size) { Page pageList = gatheringService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent())); } /** - * 根据条件查询 - * @param searchMap - * @return - */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",gatheringService.findSearch(searchMap)); - } - + * 根据条件查询 + * + * @param searchMap + * @return + */ + @RequestMapping(value = "/search", method = RequestMethod.POST) + public Result findSearch(@RequestBody Map searchMap) { + return Result.success(gatheringService.findSearch(searchMap)); + } + /** * 增加 + * * @param gathering */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Gathering gathering ){ + @RequestMapping(method = RequestMethod.POST) + public Result add(@RequestBody Gathering gathering) { gatheringService.add(gathering); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } - + /** * 修改 + * * @param gathering */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Gathering gathering, @PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.PUT) + public Result update(@RequestBody Gathering gathering, @PathVariable String id) { gathering.setId(id); - gatheringService.update(gathering); - return new Result(true,StatusCode.OK,"修改成功"); + gatheringService.update(gathering); + return Result.success(); } - + /** * 删除 + * * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public Result delete(@PathVariable String id) { gatheringService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } - + } diff --git a/luoo_recruit/src/main/java/com/luoo/recruit/controller/BaseExceptionHandler.java b/luoo_recruit/src/main/java/com/luoo/recruit/controller/BaseExceptionHandler.java index 1f11fff..257ea19 100644 --- a/luoo_recruit/src/main/java/com/luoo/recruit/controller/BaseExceptionHandler.java +++ b/luoo_recruit/src/main/java/com/luoo/recruit/controller/BaseExceptionHandler.java @@ -1,12 +1,9 @@ package com.luoo.recruit.controller; -import entity.Result; -import entity.StatusCode; +import api.Result; +import api.StatusCode; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; /** * 统一异常处理类 */ @@ -15,8 +12,8 @@ public class BaseExceptionHandler { @ExceptionHandler(value = Exception.class) @ResponseBody - public Result error(Exception e){ - e.printStackTrace(); - return new Result(false, StatusCode.ERROR, "执行出错"); + public Result error(Exception e){ + e.printStackTrace(); + return Result.failed(StatusCode.RECRUIT_COMMON_FAILED); } } diff --git a/luoo_recruit/src/main/java/com/luoo/recruit/controller/EnterpriseController.java b/luoo_recruit/src/main/java/com/luoo/recruit/controller/EnterpriseController.java index 2a90ff8..fddb78e 100644 --- a/luoo_recruit/src/main/java/com/luoo/recruit/controller/EnterpriseController.java +++ b/luoo_recruit/src/main/java/com/luoo/recruit/controller/EnterpriseController.java @@ -1,4 +1,5 @@ package com.luoo.recruit.controller; + import java.util.List; import java.util.Map; @@ -14,10 +15,12 @@ import org.springframework.web.bind.annotation.RestController; import com.luoo.recruit.pojo.Enterprise; import com.luoo.recruit.service.EnterpriseService; -import entity.*; +import api.PageResult; +import api.Result; /** * 控制器层 + * * @author Administrator * */ @@ -28,80 +31,86 @@ public class EnterpriseController { @Autowired private EnterpriseService enterpriseService; - - + /** * 查询全部数据 + * * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findAll()); + @RequestMapping(method = RequestMethod.GET) + public Result> findAll() { + return Result.success(enterpriseService.findAll()); } - + /** * 根据ID查询 + * * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findById(id)); + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public Result findById(@PathVariable String id) { + return Result.success(enterpriseService.findById(id)); } - /** * 分页+多条件查询 + * * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 + * @param page 页码 + * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST) + public Result> findSearch(@RequestBody Map searchMap, @PathVariable int page, + @PathVariable int size) { Page pageList = enterpriseService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent())); } /** - * 根据条件查询 - * @param searchMap - * @return - */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findSearch(searchMap)); - } - + * 根据条件查询 + * + * @param searchMap + * @return + */ + @RequestMapping(value = "/search", method = RequestMethod.POST) + public Result> findSearch(@RequestBody Map searchMap) { + return Result.success(enterpriseService.findSearch(searchMap)); + } + /** * 增加 + * * @param enterprise */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Enterprise enterprise ){ + @RequestMapping(method = RequestMethod.POST) + public Result add(@RequestBody Enterprise enterprise) { enterpriseService.add(enterprise); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } - + /** * 修改 + * * @param enterprise */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Enterprise enterprise, @PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.PUT) + public Result update(@RequestBody Enterprise enterprise, @PathVariable String id) { enterprise.setId(id); - enterpriseService.update(enterprise); - return new Result(true,StatusCode.OK,"修改成功"); + enterpriseService.update(enterprise); + return Result.success(); } - + /** * 删除 + * * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public Result delete(@PathVariable String id) { enterpriseService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } - + } diff --git a/luoo_recruit/src/main/java/com/luoo/recruit/controller/RecruitController.java b/luoo_recruit/src/main/java/com/luoo/recruit/controller/RecruitController.java index 19f202c..b3d6e41 100644 --- a/luoo_recruit/src/main/java/com/luoo/recruit/controller/RecruitController.java +++ b/luoo_recruit/src/main/java/com/luoo/recruit/controller/RecruitController.java @@ -1,4 +1,5 @@ package com.luoo.recruit.controller; + import java.util.List; import java.util.Map; @@ -14,11 +15,12 @@ import org.springframework.web.bind.annotation.RestController; import com.luoo.recruit.pojo.Recruit; import com.luoo.recruit.service.RecruitService; -import entity.PageResult; -import entity.Result; -import entity.StatusCode; +import api.PageResult; +import api.Result; + /** * 控制器层 + * * @author Administrator * */ @@ -29,80 +31,86 @@ public class RecruitController { @Autowired private RecruitService recruitService; - - + /** * 查询全部数据 + * * @return */ - @RequestMapping(method= RequestMethod.GET) - public Result findAll(){ - return new Result(true,StatusCode.OK,"查询成功",recruitService.findAll()); + @RequestMapping(method = RequestMethod.GET) + public Result> findAll() { + return Result.success(recruitService.findAll()); } - + /** * 根据ID查询 + * * @param id ID * @return */ - @RequestMapping(value="/{id}",method= RequestMethod.GET) - public Result findById(@PathVariable String id){ - return new Result(true,StatusCode.OK,"查询成功",recruitService.findById(id)); + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + public Result findById(@PathVariable String id) { + return Result.success(recruitService.findById(id)); } - /** * 分页+多条件查询 + * * @param searchMap 查询条件封装 - * @param page 页码 - * @param size 页大小 + * @param page 页码 + * @param size 页大小 * @return 分页结果 */ - @RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) - public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ + @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST) + public Result> findSearch(@RequestBody Map searchMap, @PathVariable int page, + @PathVariable int size) { Page pageList = recruitService.findSearch(searchMap, page, size); - return new Result(true,StatusCode.OK,"查询成功", new PageResult(pageList.getTotalElements(), pageList.getContent()) ); + return Result.success(new PageResult(pageList.getTotalElements(), pageList.getContent())); } /** - * 根据条件查询 - * @param searchMap - * @return - */ - @RequestMapping(value="/search",method = RequestMethod.POST) - public Result findSearch( @RequestBody Map searchMap){ - return new Result(true,StatusCode.OK,"查询成功",recruitService.findSearch(searchMap)); - } - + * 根据条件查询 + * + * @param searchMap + * @return + */ + @RequestMapping(value = "/search", method = RequestMethod.POST) + public Result> findSearch(@RequestBody Map searchMap) { + return Result.success(recruitService.findSearch(searchMap)); + } + /** * 增加 + * * @param recruit */ - @RequestMapping(method=RequestMethod.POST) - public Result add(@RequestBody Recruit recruit ){ + @RequestMapping(method = RequestMethod.POST) + public Result add(@RequestBody Recruit recruit) { recruitService.add(recruit); - return new Result(true,StatusCode.OK,"增加成功"); + return Result.success(); } - + /** * 修改 + * * @param recruit */ - @RequestMapping(value="/{id}",method= RequestMethod.PUT) - public Result update(@RequestBody Recruit recruit, @PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.PUT) + public Result update(@RequestBody Recruit recruit, @PathVariable String id) { recruit.setId(id); - recruitService.update(recruit); - return new Result(true,StatusCode.OK,"修改成功"); + recruitService.update(recruit); + return Result.success(); } - + /** * 删除 + * * @param id */ - @RequestMapping(value="/{id}",method= RequestMethod.DELETE) - public Result delete(@PathVariable String id ){ + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + public Result delete(@PathVariable String id) { recruitService.deleteById(id); - return new Result(true,StatusCode.OK,"删除成功"); + return Result.success(); } - + } diff --git a/luoo_user/src/main/java/com/luoo/user/service/AdminService.java b/luoo_user/src/main/java/com/luoo/user/service/AdminService.java index 1c7394f..2088f79 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/AdminService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/AdminService.java @@ -1,22 +1,18 @@ package com.luoo.user.service; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import javax.persistence.criteria.Selection; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserService.java b/luoo_user/src/main/java/com/luoo/user/service/UserService.java index 8a08606..f8416c6 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserService.java @@ -5,24 +5,16 @@ import java.util.concurrent.TimeUnit; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Expression; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import javax.persistence.criteria.Selection; import javax.servlet.http.HttpServletRequest; -import entity.Result; -import entity.StatusCode; -import io.jsonwebtoken.Claims; import org.apache.commons.lang3.RandomStringUtils; -import org.apache.commons.lang3.RandomUtils; -import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;