Merge pull request 'unifiy_response for music/comment/friend/tag component' (#8) from unifiy_response into main

Reviewed-on: https://go.indie.cn/git/queyue-backend/luoo_parent/pulls/8
main
hechanggeng 1 year ago
commit 83bf6b065a

@ -3,9 +3,12 @@ package com.luoo.comment.controller;
import com.luoo.comment.pojo.Comment; import com.luoo.comment.pojo.Comment;
import com.luoo.comment.service.CommentService; import com.luoo.comment.service.CommentService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -22,64 +25,62 @@ public class CommentController {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@RequestMapping(method = RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<Comment>> findAll(){
return new Result(true, StatusCode.OK,"",commentService.findAll()); return Result.success(commentService.findAll());
} }
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) @GetMapping("/findByVolid/{volid}")
public Result findByVolid(@PathVariable String volid){ public Result<List<Comment>> findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",commentService.findByVolid(volid)); return Result.success(commentService.findByVolid(volid));
} }
@RequestMapping(value = "/{commentId}",method = RequestMethod.GET) @GetMapping("/{commentId}")
public Result findById(@PathVariable String commentId) { public Result<Comment> findById(@PathVariable String commentId) {
return new Result(true, StatusCode.OK,"",commentService.findById(commentId)); return Result.success(commentService.findById(commentId));
} }
@RequestMapping(method = RequestMethod.POST) @PostMapping
public Result save(@RequestBody Comment comment){ public Result<Void> save(@RequestBody Comment comment){
commentService.save(comment); commentService.save(comment);
return new Result(true,StatusCode.OK,"保存成功"); return Result.success();
} }
@RequestMapping(value = "/{commentId}",method = RequestMethod.PUT) @PutMapping("/{commentId}")
public Result update(@PathVariable String commentId,@RequestBody Comment comment){ public Result<Void> update(@PathVariable String commentId,@RequestBody Comment comment){
comment.set_id(commentId); comment.set_id(commentId);
commentService.update(comment); commentService.update(comment);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
@RequestMapping(value = "/{commentId}",method = RequestMethod.DELETE) @DeleteMapping("/{commentId}")
public Result delete(@PathVariable String commentId){ public Result<Void> delete(@PathVariable String commentId){
commentService.deleteById(commentId); commentService.deleteById(commentId);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
@RequestMapping(value = "/{parentid}/{page}/{size}",method = RequestMethod.GET) @GetMapping("/{parentid}/{page}/{size}")
public Result findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){ public Result<PageResult<Comment>> findByParentid(@PathVariable String parentid,@PathVariable int page,@PathVariable int size){
Page<Comment> pageData = commentService.findByParentId(parentid,page,size); Page<Comment> pageData = commentService.findByParentId(parentid,page,size);
return Result.success(new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
return new Result(true,StatusCode.OK,"查询成功",new PageResult<Comment>(pageData.getTotalElements(),pageData.getContent()));
} }
@RequestMapping(value = "/thumbup/{commentId}",method = RequestMethod.PUT) @PutMapping("/thumbup/{commentId}")
public Result thumbup(@PathVariable String commentId){ public Result thumbup(@PathVariable String commentId){
String userid="111"; String userid="111";
if (redisTemplate.opsForValue().get("thumbup_"+userid)!=null){ if (redisTemplate.opsForValue().get("thumbup_"+userid)!=null){
return new Result(true,StatusCode.REPERROR,"重复提交"); return Result.failed(StatusCode.COMMENT_REPEAT_SUBMIT);
} }
commentService.thumbup(commentId); commentService.thumbup(commentId);
redisTemplate.opsForValue().set("thumbup_"+userid,1); redisTemplate.opsForValue().set("thumbup_"+userid,1);
return new Result(true,StatusCode.OK,"点赞成功"); return Result.success();
} }
} }

@ -9,22 +9,29 @@ public enum StatusCode implements IErrorCode {
FORBIDDEN(403, "没有相关权限"), FORBIDDEN(403, "没有相关权限"),
//user 模块错误码以10XXX不足5位补0; //user 模块错误码以10XXX不足5位补0;
USER_COMMON_FAILED(10000, "用户模块失败"), USER_COMMON_FAILED(10000, "用户模块错误"),
USER_VERIFICATION_CODE_EXPIRED(10001, "验证码过期,请重新获取"), USER_VERIFICATION_CODE_EXPIRED(10001, "验证码过期,请重新获取"),
USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"), USER_VERIFICATION_CODE_MISMATCH(10002, "验证码校验失败,请输入正确的验证码"),
USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"), USER_NAME_OR_PASSWORD_FAILED(10003, "用户名或密码错误"),
// music 模块错误码以20XXX不足5位补0; // music 模块错误码以20XXX不足5位补0;
MUSIC_COMMON_FAILED(20000, "歌曲模块错误"),
// comment 模块错误码以30XXX不足5位补0; // comment 模块错误码以30XXX不足5位补0;
COMMENT_COMMON_FAILED(30000, "评论模块错误"),
COMMENT_REPEAT_SUBMIT(30001, "评论重复提交"),
// friend 模块错误码以40XXX不足5位补0; // 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 模块错误码以50XXX不足5位补0;
TAG_COMMON_FAILED(50000, "标签模块错误"),
// music 模块错误码以60XXX不足5位补0;
// recruit 模块错误码以50XXX不足5位补0;
// manage 模块错误码以70XXX不足5位补0; RECRUIT_COMMON_FAILED(60000, "招聘模块错误");
MANAGE_COMMON_FAILED(70000, "管理模块失败");
private int code; private int code;
private String message; private String message;

@ -1,31 +0,0 @@
package entity;
import java.util.List;
public class PageResult<T> {
private Long total;
private List<T> rows;
public PageResult(Long total, List<T> rows) {
super();
this.total = total;
this.rows = rows;
}
public Long getTotal() {
return total;
}
public void setTotal(Long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}

@ -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;
}
}

@ -1,62 +0,0 @@
package entity;
public class ResultVO<T>{
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 <T> ResultVO<T> success(T data){
return new ResultVO<>(true,200,"操作成功", data);
}
public static ResultVO<Void> success(String message){
return new ResultVO<>(true,200,message);
}
}

@ -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;// 重复提交
}

@ -3,12 +3,11 @@ package com.luoo.friend.client;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient("luoo-user") @FeignClient("luoo-user")
public interface UserClient { 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); public void updatefanscountandfollowcount(@PathVariable String userid, @PathVariable String friendid, @PathVariable int x);
} }

@ -3,14 +3,11 @@ package com.luoo.friend.controller;
import com.luoo.friend.client.UserClient; import com.luoo.friend.client.UserClient;
import com.luoo.friend.service.FriendService; import com.luoo.friend.service.FriendService;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import io.jsonwebtoken.Claims; import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -32,13 +29,13 @@ public class FriendController {
* *
* @return * @return
*/ */
@RequestMapping(value = "/like/{friendid}/{type}", method = RequestMethod.PUT) @PutMapping("/like/{friendid}/{type}")
public Result addFriend(@PathVariable String friendid, @PathVariable String type) { public Result<Void> addFriend(@PathVariable String friendid, @PathVariable String type) {
//验证是否登录并且拿到ID //验证是否登录并且拿到ID
Claims claims = (Claims) request.getAttribute("claims_user"); Claims claims = (Claims) request.getAttribute("claims_user");
if (claims == null) { if (claims == null) {
return new Result(false, StatusCode.LOGINERROR, "权限不足"); return Result.unauthorized(null);
} }
String userid = claims.getId(); String userid = claims.getId();
//判断是添加好友还是非好友 //判断是添加好友还是非好友
@ -47,41 +44,41 @@ public class FriendController {
//添加好友 //添加好友
int flag = friendService.addFriend(userid,friendid); int flag = friendService.addFriend(userid,friendid);
if (flag == 0) { if (flag == 0) {
return new Result(false, StatusCode.ERROR, "不能重复添加好友"); return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_FRIEND);
} }
if (flag == 1) { if (flag == 1) {
userClient.updatefanscountandfollowcount(userid,friendid,1); userClient.updatefanscountandfollowcount(userid,friendid,1);
return new Result(true, StatusCode.OK, "添加成功"); return Result.success();
} }
} else if (type.equals("2")) { } else if (type.equals("2")) {
//添加非好友 //添加非好友
int flag = friendService.addNoFriend(userid,friendid); int flag = friendService.addNoFriend(userid,friendid);
if (flag == 0) { if (flag == 0) {
return new Result(false, StatusCode.ERROR, "不能重复添加非好友"); return Result.failed(StatusCode.FRIEND_CAN_NOT_REPEAT_ADD_NON_FRIEND);
} }
if (flag == 1) { 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 { } else {
return new Result(false, StatusCode.ERROR, "参数异常"); return Result.failed(StatusCode.VALIDATE_FAILED);
} }
} }
@RequestMapping(value = "/{friendid}", method = RequestMethod.DELETE) @DeleteMapping("/{friendid}")
public Result deleteFriend(@PathVariable String friendid){ public Result<Void> deleteFriend(@PathVariable String friendid){
//验证是否登录并且拿到ID //验证是否登录并且拿到ID
Claims claims = (Claims) request.getAttribute("claims_user"); Claims claims = (Claims) request.getAttribute("claims_user");
if (claims == null) { if (claims == null) {
return new Result(false, StatusCode.LOGINERROR, "权限不足"); return Result.unauthorized(null);
} }
String userid = claims.getId(); String userid = claims.getId();
friendService.deleteFriend(userid,friendid); friendService.deleteFriend(userid,friendid);
userClient.updatefanscountandfollowcount(userid,friendid,-1); userClient.updatefanscountandfollowcount(userid,friendid,-1);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,12 +1,8 @@
package com.luoo.gathering.controller; package com.luoo.gathering.controller;
import entity.Result; import api.Result;
import entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; 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) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result<Void> error(Exception e){
e.printStackTrace(); e.printStackTrace();
return new Result(false, StatusCode.ERROR, "执行出错"); return Result.failed();
} }
} }

@ -1,4 +1,5 @@
package com.luoo.gathering.controller; package com.luoo.gathering.controller;
import java.util.List; import java.util.List;
import java.util.Map; 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.pojo.Gathering;
import com.luoo.gathering.service.GatheringService; import com.luoo.gathering.service.GatheringService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
/** /**
* *
*
* @author Administrator * @author Administrator
* *
*/ */
@ -29,80 +31,86 @@ public class GatheringController {
@Autowired @Autowired
private GatheringService gatheringService; private GatheringService gatheringService;
/** /**
* *
*
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public Result findAll(){ public Result<List<Gathering>> findAll() {
return new Result(true,StatusCode.OK,"查询成功",gatheringService.findAll()); return Result.success(gatheringService.findAll());
} }
/** /**
* ID * ID
*
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Result findById(@PathVariable String id){ public Result<Gathering> findById(@PathVariable String id) {
return new Result(true,StatusCode.OK,"查询成功",gatheringService.findById(id)); return Result.success(gatheringService.findById(id));
} }
/** /**
* + * +
*
* @param searchMap * @param searchMap
* @param page * @param page
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Gathering>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
@PathVariable int size) {
Page<Gathering> pageList = gatheringService.findSearch(searchMap, page, size); Page<Gathering> pageList = gatheringService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Gathering>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Gathering>(pageList.getTotalElements(), pageList.getContent()));
} }
/** /**
* *
* @param searchMap *
* @return * @param searchMap
*/ * @return
@RequestMapping(value="/search",method = RequestMethod.POST) */
public Result findSearch( @RequestBody Map searchMap){ @RequestMapping(value = "/search", method = RequestMethod.POST)
return new Result(true,StatusCode.OK,"查询成功",gatheringService.findSearch(searchMap)); public Result findSearch(@RequestBody Map searchMap) {
} return Result.success(gatheringService.findSearch(searchMap));
}
/** /**
* *
*
* @param gathering * @param gathering
*/ */
@RequestMapping(method=RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public Result add(@RequestBody Gathering gathering ){ public Result<Void> add(@RequestBody Gathering gathering) {
gatheringService.add(gathering); gatheringService.add(gathering);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
*
* @param gathering * @param gathering
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@RequestBody Gathering gathering, @PathVariable String id ){ public Result<Void> update(@RequestBody Gathering gathering, @PathVariable String id) {
gathering.setId(id); gathering.setId(id);
gatheringService.update(gathering); gatheringService.update(gathering);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
*
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id) {
gatheringService.deleteById(id); gatheringService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,6 +1,6 @@
package com.luoo.music.client; package com.luoo.music.client;
import entity.Result; import api.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;

@ -5,19 +5,13 @@ import java.util.Map;
import com.luoo.music.client.UserClient; import com.luoo.music.client.UserClient;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
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 com.luoo.music.pojo.Article; import com.luoo.music.pojo.Article;
import com.luoo.music.service.ArticleService; import com.luoo.music.service.ArticleService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
/** /**
* *
* @author Administrator * @author Administrator
@ -34,33 +28,32 @@ public class ArticleController {
@Autowired @Autowired
private UserClient userClient; private UserClient userClient;
@RequestMapping(value = "/admin",method = RequestMethod.GET) @GetMapping("/admin")
public Result findAdmin(){ public Result findAdmin(){
Result result =userClient.findAll(); return userClient.findAll();
return result;
} }
@RequestMapping(value = "/examine/{articleId}",method = RequestMethod.PUT) @PutMapping("/examine/{articleId}")
public Result examine (@PathVariable String articleId){ public Result<Void> examine (@PathVariable String articleId){
articleService.updateState(articleId); articleService.updateState(articleId);
return new Result(true,StatusCode.OK,"审核成功"); return Result.success();
} }
@RequestMapping(value = "/thumbup/{articleId}",method = RequestMethod.PUT) @PutMapping("/thumbup/{articleId}")
public Result thumbup (@PathVariable String articleId){ public Result<Void> thumbup (@PathVariable String articleId){
articleService.addThumbup(articleId); articleService.addThumbup(articleId);
return new Result(true,StatusCode.OK,"点赞成功"); return Result.success();
} }
/** /**
* *
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<Article>> findAll(){
return new Result(true,StatusCode.OK,"查询成功",articleService.findAll()); return Result.success(articleService.findAll());
} }
/** /**
@ -68,14 +61,14 @@ public class ArticleController {
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<Article> findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",articleService.findById(id)); return Result.success(articleService.findById(id));
} }
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) @GetMapping("/findByVolid/{volid}")
public Result findByVolid(@PathVariable String volid){ public Result<Article> findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",articleService.findByVolid(volid)); return Result.success(articleService.findByVolid(volid));
} }
@ -86,10 +79,10 @@ public class ArticleController {
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Article>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Article> pageList = articleService.findSearch(searchMap, page, size); Page<Article> pageList = articleService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Article>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Article>(pageList.getTotalElements(), pageList.getContent()) );
} }
/** /**
@ -97,40 +90,40 @@ public class ArticleController {
* @param searchMap * @param searchMap
* @return * @return
*/ */
@RequestMapping(value="/search",method = RequestMethod.POST) @PostMapping("/search")
public Result findSearch( @RequestBody Map searchMap){ public Result<List<Article>> findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",articleService.findSearch(searchMap)); return Result.success(articleService.findSearch(searchMap));
} }
/** /**
* *
* @param article * @param article
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody Article article ){ public Result<Void> add(@RequestBody Article article ){
articleService.add(article); articleService.add(article);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
* @param article * @param article
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody Article article, @PathVariable String id ){ public Result<Void> update(@RequestBody Article article, @PathVariable String id ){
article.setId(id); article.setId(id);
articleService.update(article); articleService.update(article);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id ){
articleService.deleteById(id); articleService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,12 +1,9 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; 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) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result<Void> error(Exception e){
e.printStackTrace(); e.printStackTrace();
return new Result(false, StatusCode.ERROR, "执行出错"); return Result.failed(StatusCode.MUSIC_COMMON_FAILED);
} }
} }

@ -4,19 +4,14 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
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 com.luoo.music.pojo.Channel; import com.luoo.music.pojo.Channel;
import com.luoo.music.service.ChannelService; import com.luoo.music.service.ChannelService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
/** /**
* *
* @author Administrator * @author Administrator
@ -35,9 +30,9 @@ public class ChannelController {
* *
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<Channel>> findAll(){
return new Result(true,StatusCode.OK,"查询成功",channelService.findAll()); return Result.success(channelService.findAll());
} }
/** /**
@ -45,9 +40,9 @@ public class ChannelController {
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<Channel> findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",channelService.findById(id)); return Result.success(channelService.findById(id));
} }
@ -58,10 +53,10 @@ public class ChannelController {
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Channel>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Channel> pageList = channelService.findSearch(searchMap, page, size); Page<Channel> pageList = channelService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Channel>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Channel>(pageList.getTotalElements(), pageList.getContent()) );
} }
/** /**
@ -69,40 +64,40 @@ public class ChannelController {
* @param searchMap * @param searchMap
* @return * @return
*/ */
@RequestMapping(value="/search",method = RequestMethod.POST) @PostMapping("/search")
public Result findSearch( @RequestBody Map searchMap){ public Result<List<Channel>> findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",channelService.findSearch(searchMap)); return Result.success(channelService.findSearch(searchMap));
} }
/** /**
* *
* @param channel * @param channel
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody Channel channel ){ public Result<Void> add(@RequestBody Channel channel ){
channelService.add(channel); channelService.add(channel);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
* @param channel * @param channel
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody Channel channel, @PathVariable String id ){ public Result<Void> update(@RequestBody Channel channel, @PathVariable String id ){
channel.setId(id); channel.setId(id);
channelService.update(channel); channelService.update(channel);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id ){
channelService.deleteById(id); channelService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -4,19 +4,14 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.*;
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 com.luoo.music.pojo.Column; import com.luoo.music.pojo.Column;
import com.luoo.music.service.ColumnService; import com.luoo.music.service.ColumnService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
/** /**
* *
* @author Administrator * @author Administrator
@ -35,9 +30,9 @@ public class ColumnController {
* *
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<Column>> findAll(){
return new Result(true,StatusCode.OK,"查询成功",columnService.findAll()); return Result.success(columnService.findAll());
} }
/** /**
@ -45,9 +40,9 @@ public class ColumnController {
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<Column> findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",columnService.findById(id)); return Result.success(columnService.findById(id));
} }
@ -58,10 +53,10 @@ public class ColumnController {
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Column>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Column> pageList = columnService.findSearch(searchMap, page, size); Page<Column> pageList = columnService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Column>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Column>(pageList.getTotalElements(), pageList.getContent()) );
} }
/** /**
@ -69,40 +64,40 @@ public class ColumnController {
* @param searchMap * @param searchMap
* @return * @return
*/ */
@RequestMapping(value="/search",method = RequestMethod.POST) @PostMapping("/search")
public Result findSearch( @RequestBody Map searchMap){ public Result<List<Column>> findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",columnService.findSearch(searchMap)); return Result.success(columnService.findSearch(searchMap));
} }
/** /**
* *
* @param column * @param column
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody Column column ){ public Result<Void> add(@RequestBody Column column ){
columnService.add(column); columnService.add(column);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
* @param column * @param column
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody Column column, @PathVariable String id ){ public Result<Void> update(@RequestBody Column column, @PathVariable String id ){
column.setId(id); column.setId(id);
columnService.update(column); columnService.update(column);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id ){
columnService.deleteById(id); columnService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -3,13 +3,11 @@ package com.luoo.music.controller;
import com.luoo.music.pojo.Article; import com.luoo.music.pojo.Article;
import com.luoo.music.pojo.Song; 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 com.luoo.music.service.SongService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.json.JsonParser;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -26,23 +24,18 @@ public class SongController {
@Autowired @Autowired
private SongService songService; private SongService songService;
/** /**
* *
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @GetMapping
public Result findAll(){ public Result<List<Song>> findAll(){
return new Result(true, StatusCode.OK,"查询成功",songService.findAll()); return Result.success(songService.findAll());
} }
@GetMapping("/findByVolid/{volid}")
public Result<List<SongVO>> findByVolid(@PathVariable String volid){
@RequestMapping(value = "/findByVolid/{volid}",method = RequestMethod.GET) return Result.success(songService.findByVolid(volid));
public Result findByVolid(@PathVariable String volid){
return new Result(true,StatusCode.OK,"查询成功",songService.findByVolid(volid));
} }
/** /**
@ -50,9 +43,9 @@ public class SongController {
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @GetMapping("/{id}")
public Result findById(@PathVariable String id){ public Result<Song> findById(@PathVariable String id){
return new Result(true,StatusCode.OK,"查询成功",songService.findById(id)); return Result.success(songService.findById(id));
} }
@ -63,15 +56,15 @@ public class SongController {
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @PostMapping("/search/{page}/{size}")
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Song>> findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){
Page<Song> pageList = songService.findSearch(searchMap, page, size); Page<Song> pageList = songService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Song>(pageList.getTotalElements(), pageList.getContent()) );
} }
@RequestMapping(value = "/init",method = RequestMethod.POST) @PostMapping("/init")
public Result init(@RequestBody Map map) { public Result<Void> init(@RequestBody Map map) {
List<Map> data = (List) map.get("data"); List<Map> data = (List) map.get("data");
System.out.println(data.size()); System.out.println(data.size());
Song song = new Song(); Song song = new Song();
@ -112,7 +105,7 @@ public class SongController {
for (Article pojo : set) { for (Article pojo : set) {
// articleService.add(pojo); // articleService.add(pojo);
} }
return new Result(true,StatusCode.OK,"init"); return Result.success();
} }
/** /**
@ -120,9 +113,9 @@ public class SongController {
* @param searchMap * @param searchMap
* @return * @return
*/ */
@RequestMapping(value="/search",method = RequestMethod.POST) @PostMapping("/search")
public Result findSearch( @RequestBody Map searchMap){ public Result<List<Song>> findSearch( @RequestBody Map searchMap){
return new Result(true,StatusCode.OK,"查询成功",songService.findSearch(searchMap)); return Result.success(songService.findSearch(searchMap));
} }
@ -130,30 +123,30 @@ public class SongController {
* *
* @param song * @param song
*/ */
@RequestMapping(method=RequestMethod.POST) @PostMapping
public Result add(@RequestBody Song song){ public Result<Void> add(@RequestBody Song song){
songService.add(song); songService.add(song);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
* @param song * @param song
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @PutMapping("/{id}")
public Result update(@RequestBody Song song, @PathVariable String id ){ public Result<Void> update(@RequestBody Song song, @PathVariable String id ){
song.setId(id); song.setId(id);
songService.update(song); songService.update(song);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @DeleteMapping("/{id}")
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id ){
songService.deleteById(id); songService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,12 +1,9 @@
package com.luoo.recruit.controller; package com.luoo.recruit.controller;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; 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) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result<Void> error(Exception e){
e.printStackTrace(); e.printStackTrace();
return new Result(false, StatusCode.ERROR, "执行出错"); return Result.failed(StatusCode.RECRUIT_COMMON_FAILED);
} }
} }

@ -1,4 +1,5 @@
package com.luoo.recruit.controller; package com.luoo.recruit.controller;
import java.util.List; import java.util.List;
import java.util.Map; 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.pojo.Enterprise;
import com.luoo.recruit.service.EnterpriseService; import com.luoo.recruit.service.EnterpriseService;
import entity.*; import api.PageResult;
import api.Result;
/** /**
* *
*
* @author Administrator * @author Administrator
* *
*/ */
@ -28,80 +31,86 @@ public class EnterpriseController {
@Autowired @Autowired
private EnterpriseService enterpriseService; private EnterpriseService enterpriseService;
/** /**
* *
*
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public Result findAll(){ public Result<List<Enterprise>> findAll() {
return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findAll()); return Result.success(enterpriseService.findAll());
} }
/** /**
* ID * ID
*
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Result findById(@PathVariable String id){ public Result<Enterprise> findById(@PathVariable String id) {
return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findById(id)); return Result.success(enterpriseService.findById(id));
} }
/** /**
* + * +
*
* @param searchMap * @param searchMap
* @param page * @param page
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Enterprise>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
@PathVariable int size) {
Page<Enterprise> pageList = enterpriseService.findSearch(searchMap, page, size); Page<Enterprise> pageList = enterpriseService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Enterprise>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Enterprise>(pageList.getTotalElements(), pageList.getContent()));
} }
/** /**
* *
* @param searchMap *
* @return * @param searchMap
*/ * @return
@RequestMapping(value="/search",method = RequestMethod.POST) */
public Result findSearch( @RequestBody Map searchMap){ @RequestMapping(value = "/search", method = RequestMethod.POST)
return new Result(true,StatusCode.OK,"查询成功",enterpriseService.findSearch(searchMap)); public Result<List<Enterprise>> findSearch(@RequestBody Map searchMap) {
} return Result.success(enterpriseService.findSearch(searchMap));
}
/** /**
* *
*
* @param enterprise * @param enterprise
*/ */
@RequestMapping(method=RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public Result add(@RequestBody Enterprise enterprise ){ public Result<Void> add(@RequestBody Enterprise enterprise) {
enterpriseService.add(enterprise); enterpriseService.add(enterprise);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
*
* @param enterprise * @param enterprise
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@RequestBody Enterprise enterprise, @PathVariable String id ){ public Result<Void> update(@RequestBody Enterprise enterprise, @PathVariable String id) {
enterprise.setId(id); enterprise.setId(id);
enterpriseService.update(enterprise); enterpriseService.update(enterprise);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
*
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id) {
enterpriseService.deleteById(id); enterpriseService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,4 +1,5 @@
package com.luoo.recruit.controller; package com.luoo.recruit.controller;
import java.util.List; import java.util.List;
import java.util.Map; 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.pojo.Recruit;
import com.luoo.recruit.service.RecruitService; import com.luoo.recruit.service.RecruitService;
import entity.PageResult; import api.PageResult;
import entity.Result; import api.Result;
import entity.StatusCode;
/** /**
* *
*
* @author Administrator * @author Administrator
* *
*/ */
@ -29,80 +31,86 @@ public class RecruitController {
@Autowired @Autowired
private RecruitService recruitService; private RecruitService recruitService;
/** /**
* *
*
* @return * @return
*/ */
@RequestMapping(method= RequestMethod.GET) @RequestMapping(method = RequestMethod.GET)
public Result findAll(){ public Result<List<Recruit>> findAll() {
return new Result(true,StatusCode.OK,"查询成功",recruitService.findAll()); return Result.success(recruitService.findAll());
} }
/** /**
* ID * ID
*
* @param id ID * @param id ID
* @return * @return
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.GET) @RequestMapping(value = "/{id}", method = RequestMethod.GET)
public Result findById(@PathVariable String id){ public Result<Recruit> findById(@PathVariable String id) {
return new Result(true,StatusCode.OK,"查询成功",recruitService.findById(id)); return Result.success(recruitService.findById(id));
} }
/** /**
* + * +
*
* @param searchMap * @param searchMap
* @param page * @param page
* @param size * @param size
* @return * @return
*/ */
@RequestMapping(value="/search/{page}/{size}",method=RequestMethod.POST) @RequestMapping(value = "/search/{page}/{size}", method = RequestMethod.POST)
public Result findSearch(@RequestBody Map searchMap , @PathVariable int page, @PathVariable int size){ public Result<PageResult<Recruit>> findSearch(@RequestBody Map searchMap, @PathVariable int page,
@PathVariable int size) {
Page<Recruit> pageList = recruitService.findSearch(searchMap, page, size); Page<Recruit> pageList = recruitService.findSearch(searchMap, page, size);
return new Result(true,StatusCode.OK,"查询成功", new PageResult<Recruit>(pageList.getTotalElements(), pageList.getContent()) ); return Result.success(new PageResult<Recruit>(pageList.getTotalElements(), pageList.getContent()));
} }
/** /**
* *
* @param searchMap *
* @return * @param searchMap
*/ * @return
@RequestMapping(value="/search",method = RequestMethod.POST) */
public Result findSearch( @RequestBody Map searchMap){ @RequestMapping(value = "/search", method = RequestMethod.POST)
return new Result(true,StatusCode.OK,"查询成功",recruitService.findSearch(searchMap)); public Result<List<Recruit>> findSearch(@RequestBody Map searchMap) {
} return Result.success(recruitService.findSearch(searchMap));
}
/** /**
* *
*
* @param recruit * @param recruit
*/ */
@RequestMapping(method=RequestMethod.POST) @RequestMapping(method = RequestMethod.POST)
public Result add(@RequestBody Recruit recruit ){ public Result<Void> add(@RequestBody Recruit recruit) {
recruitService.add(recruit); recruitService.add(recruit);
return new Result(true,StatusCode.OK,"增加成功"); return Result.success();
} }
/** /**
* *
*
* @param recruit * @param recruit
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.PUT) @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@RequestBody Recruit recruit, @PathVariable String id ){ public Result<Void> update(@RequestBody Recruit recruit, @PathVariable String id) {
recruit.setId(id); recruit.setId(id);
recruitService.update(recruit); recruitService.update(recruit);
return new Result(true,StatusCode.OK,"修改成功"); return Result.success();
} }
/** /**
* *
*
* @param id * @param id
*/ */
@RequestMapping(value="/{id}",method= RequestMethod.DELETE) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public Result delete(@PathVariable String id ){ public Result<Void> delete(@PathVariable String id) {
recruitService.deleteById(id); recruitService.deleteById(id);
return new Result(true,StatusCode.OK,"删除成功"); return Result.success();
} }
} }

@ -1,13 +1,12 @@
package com.luoo.tag.client; package com.luoo.tag.client;
import entity.Result; import api.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient("luoo-user") @FeignClient("luoo-user")
public interface UserClient { public interface UserClient {
@RequestMapping(value = "/admin",method= RequestMethod.GET) @GetMapping("/admin")
public Result findAll(); public Result findAll();
} }

@ -1,8 +1,8 @@
package com.luoo.tag.controller; package com.luoo.tag.controller;
import exception.BizException; import exception.BizException;
import entity.Result; import api.Result;
import entity.StatusCode; import api.StatusCode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
@ -16,15 +16,15 @@ public class BaseExceptionHandler {
@ExceptionHandler(value = Exception.class) @ExceptionHandler(value = Exception.class)
@ResponseBody @ResponseBody
public Result error(Exception e){ public Result<Void> error(Exception e){
log.error("执行出错", e); log.error("执行出错", e);
return new Result(false, StatusCode.ERROR, "执行出错"); return Result.failed(StatusCode.TAG_COMMON_FAILED);
} }
@ExceptionHandler(value = BizException.class) @ExceptionHandler(value = BizException.class)
@ResponseBody @ResponseBody
public Result error(BizException e){ public Result<String> error(BizException e){
log.info("业务错误:{}", e.getMessage()); log.info("业务错误:{}", e.getMessage());
return new Result(false, StatusCode.ERROR, e.getMessage()); return Result.failed(StatusCode.TAG_COMMON_FAILED, e.getMessage());
} }
} }

@ -5,7 +5,7 @@ import com.luoo.tag.pojo.TagDTO;
import com.luoo.tag.pojo.TagQueryReq; import com.luoo.tag.pojo.TagQueryReq;
import com.luoo.tag.pojo.TagUpdateReq; import com.luoo.tag.pojo.TagUpdateReq;
import com.luoo.tag.service.TagService; import com.luoo.tag.service.TagService;
import entity.ResultVO; import api.Result;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -32,23 +32,23 @@ public class TagController {
@ApiImplicitParam(name = "pageNum", value = "页码", required = true), @ApiImplicitParam(name = "pageNum", value = "页码", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页数", required = true) }) @ApiImplicitParam(name = "pageSize", value = "每页数", required = true) })
@GetMapping("/list") @GetMapping("/list")
public ResultVO<Page<TagDTO>> getById(@Validated TagQueryReq queryReq) { public Result<Page<TagDTO>> getById(@Validated TagQueryReq queryReq) {
return ResultVO.success(tagService.queryPage(queryReq)); return Result.success(tagService.queryPage(queryReq));
} }
@ApiOperation(value = "查询标签详情", notes = "查询标签详情") @ApiOperation(value = "查询标签详情", notes = "查询标签详情")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@GetMapping("/{id}") @GetMapping("/{id}")
public ResultVO<TagDTO> getById(@PathVariable String id) { public Result<TagDTO> getById(@PathVariable String id) {
return ResultVO.success(tagService.queryById(id)); return Result.success(tagService.queryById(id));
} }
@ApiOperation(value = "新增标签信息", notes = "新增标签信息") @ApiOperation(value = "新增标签信息", notes = "新增标签信息")
@ApiImplicitParams({ @ApiImplicitParam(name = "createReq", value = "创建参数", required = true) }) @ApiImplicitParams({ @ApiImplicitParam(name = "createReq", value = "创建参数", required = true) })
@PostMapping @PostMapping
public ResultVO<Void> create(@Validated @RequestBody TagCreateReq createReq) { public Result<Void> create(@Validated @RequestBody TagCreateReq createReq) {
tagService.create(createReq); tagService.create(createReq);
return ResultVO.success("创建成功"); return Result.success();
} }
@ApiOperation(value = "更新标签信息", notes = "更新标签信息") @ApiOperation(value = "更新标签信息", notes = "更新标签信息")
@ -56,10 +56,10 @@ public class TagController {
@ApiImplicitParam(name = "updateReq", value = "更新参数", required = true), @ApiImplicitParam(name = "updateReq", value = "更新参数", required = true),
@ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@PutMapping("/{id}") @PutMapping("/{id}")
public ResultVO<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) { public Result<Void> update(@Validated @RequestBody TagUpdateReq updateReq, @PathVariable String id) {
updateReq.setId(id); updateReq.setId(id);
tagService.update(updateReq); tagService.update(updateReq);
return ResultVO.success("更新成功"); return Result.success();
} }
@ApiOperation(value = "更新标签状态", notes = "更新标签状态") @ApiOperation(value = "更新标签状态", notes = "更新标签状态")
@ -67,16 +67,16 @@ public class TagController {
@ApiImplicitParam(name = "id", value = "标签ID", required = true), @ApiImplicitParam(name = "id", value = "标签ID", required = true),
@ApiImplicitParam(name = "state", value = "标签状态", required = true) }) @ApiImplicitParam(name = "state", value = "标签状态", required = true) })
@PutMapping("/status/{id}") @PutMapping("/status/{id}")
public ResultVO<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) { public Result<Void> updateStatus(@PathVariable String id, @RequestParam Integer state) {
tagService.updateState(id, state); tagService.updateState(id, state);
return ResultVO.success("状态更新成功"); return Result.success();
} }
@ApiOperation(value = "删除标签", notes = "删除标签") @ApiOperation(value = "删除标签", notes = "删除标签")
@ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) }) @ApiImplicitParams({ @ApiImplicitParam(name = "id", value = "标签ID", required = true) })
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResultVO<Void> delete(@PathVariable String id) { public Result<Void> delete(@PathVariable String id) {
tagService.delete(id); tagService.delete(id);
return ResultVO.success("删除成功"); return Result.success();
} }
} }

@ -67,7 +67,7 @@ public class AdminController {
* *
* @return * @return
*/ */
@GetMapping("/list") @GetMapping
public Result<List<Admin>> findAll(){ public Result<List<Admin>> findAll(){
return Result.success(adminService.findAll()); return Result.success(adminService.findAll());
} }

@ -1,22 +1,18 @@
package com.luoo.user.service; package com.luoo.user.service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;

@ -5,24 +5,16 @@ import java.util.concurrent.TimeUnit;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.servlet.http.HttpServletRequest; 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.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification; import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

Loading…
Cancel
Save