1
0
mirror of https://gitee.com/bookshelfplus/bookshelfplus synced 2025-09-13 04:01:40 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee

添加测试类,去除多余的import

This commit is contained in:
2022-04-04 00:47:14 +08:00
parent 1b2d61723e
commit 8d30e4898d
8 changed files with 84 additions and 40 deletions

View File

@@ -9,7 +9,10 @@ public enum BusinessErrorCode implements CommonError {
USER_NOT_EXIST(20001, "用户不存在"),
USER_LOGIN_FAILED(20002, "用户手机号或密码不正确"),
USER_NOT_LOGIN(20003, "用户还未登录"),
USER_TOKEN_EXPIRED(20004, "用户令牌过期");
USER_TOKEN_EXPIRED(20004, "用户令牌过期"),
// 30000开头为权限相关错误定义
OPERATION_NOT_ALLOWED(30001, "用户没有此操作的权限");
private BusinessErrorCode(int errCode, String errMsg) {

View File

@@ -3,23 +3,11 @@ package plus.bookshelf.Controller.Controller;
import com.aventrix.jnanoid.jnanoid.NanoIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Common.Response.CommonReturnTypeStatus;
import plus.bookshelf.Common.SessionManager.LocalSessionManager;
import plus.bookshelf.Common.SessionManager.RedisSessionManager;
import plus.bookshelf.Common.SessionManager.SessionManager;
import plus.bookshelf.Service.Model.UserModel;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
public class BaseController {
@@ -78,23 +66,23 @@ public class BaseController {
// return;
}
// 定义ExceptionHandler解决未被Controller层吸收的Exception
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public Object handlerException(HttpServletRequest request, Exception ex) {
HashMap<Object, Object> responseData = new HashMap<>();
if (ex instanceof BusinessException) {
BusinessException businessException = (BusinessException) ex;
responseData.put("errCode", businessException.getErrCode());
responseData.put("errMsg", businessException.getErrMsg());
} else {
// 生产环境输出格式化信息
responseData.put("errCode", BusinessErrorCode.UNKNOWN_ERROR.getErrCode());
responseData.put("errMsg", BusinessErrorCode.UNKNOWN_ERROR.getErrMsg());
}
return CommonReturnType.create(responseData, CommonReturnTypeStatus.FAILED);
}
// // 定义ExceptionHandler解决未被Controller层吸收的Exception
// @ExceptionHandler(Exception.class)
// @ResponseStatus(HttpStatus.OK)
// @ResponseBody
// public Object handlerException(HttpServletRequest request, Exception ex) {
// HashMap<Object, Object> responseData = new HashMap<>();
//
// if (ex instanceof BusinessException) {
// BusinessException businessException = (BusinessException) ex;
// responseData.put("errCode", businessException.getErrCode());
// responseData.put("errMsg", businessException.getErrMsg());
// } else {
// // 生产环境输出格式化信息
// responseData.put("errCode", BusinessErrorCode.UNKNOWN_ERROR.getErrCode());
// responseData.put("errMsg", BusinessErrorCode.UNKNOWN_ERROR.getErrMsg());
// }
//
// return CommonReturnType.create(responseData, CommonReturnTypeStatus.FAILED);
// }
}

View File

@@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.BookVO;

View File

@@ -10,11 +10,8 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Controller.VO.BookVO;
import plus.bookshelf.Controller.VO.CategoryVO;
import plus.bookshelf.Service.Model.BookModel;
import plus.bookshelf.Service.Model.CategoryModel;
import plus.bookshelf.Service.Service.BookService;
import plus.bookshelf.Service.Service.CategoryService;
import java.util.ArrayList;

View File

@@ -0,0 +1,41 @@
package plus.bookshelf.Controller.Controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Common.ThirdParty.ThirdPartyConfig;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import plus.bookshelf.Service.Model.UserModel;
import java.util.Objects;
@Api(tags = "系统调试接口")
@Controller("debug")
@RequestMapping("/debug")
public class DebugController extends BaseController {
@Autowired
ThirdPartyConfig thirdPartyConfig;
@Autowired
UserServiceImpl userService;
@ApiOperation(value = "获取系统配置", notes = "仅限管理员登录状态下可获取")
@RequestMapping(value = "status", method = {RequestMethod.POST}, consumes = {CONTENT_TYPE_FORMED})
@ResponseBody
public CommonReturnType status(@RequestParam(value = "token", required = false) String token) throws BusinessException {
UserModel userModel = userService.getUserByToken(redisTemplate, token);
if (userModel == null || !Objects.equals(userModel.getGroup(), "ADMIN")) {
throw new BusinessException(BusinessErrorCode.OPERATION_NOT_ALLOWED, "非管理员用户无权进行此操作");
}
return CommonReturnType.create(thirdPartyConfig);
}
}

View File

@@ -14,9 +14,6 @@ import plus.bookshelf.Common.Error.BusinessErrorCode;
import plus.bookshelf.Common.Error.BusinessException;
import plus.bookshelf.Common.Response.CommonReturnType;
import plus.bookshelf.Common.ThirdParty.ThirdPartyConfig;
import plus.bookshelf.Service.Impl.UserServiceImpl;
import java.util.Map;
@Api(tags = "第三方登录")
@Controller