mirror of
https://gitee.com/bookshelfplus/bookshelfplus
synced 2025-09-25 19:05:14 +08:00
添加测试类,去除多余的import
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
postRequest('/debug/status', { token: localStorage.token })
|
||||
.then(function (response) {
|
||||
var axiosData = response.data;
|
||||
var status = axiosData.status;
|
||||
var data = axiosData.data;
|
||||
|
||||
if (status === "success") {
|
||||
console.log(data);
|
||||
$(".main").html("请在 F12 查看");
|
||||
} else {
|
||||
alert(`出错啦!${data.errMsg} (错误码: ${data.errCode}) `);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
});
|
@@ -79,6 +79,9 @@ router.get('/dashboard/:group/:page', function (req, res) {
|
||||
}, {
|
||||
name: "用户管理",
|
||||
url: "/dashboard/admin/UserManage"
|
||||
}, {
|
||||
name: "调试",
|
||||
url: "/dashboard/admin/Debug"
|
||||
}
|
||||
];
|
||||
} else if (req.params.group === "user") {
|
||||
@@ -110,7 +113,7 @@ router.get('/dashboard/:group/:page', function (req, res) {
|
||||
}
|
||||
|
||||
// 后台管理 其他管理页面
|
||||
if ((req.params.group === "admin" && ["UserManage", "BookManage", "CategoryManage"].indexOf(req.params.page) > -1) ||
|
||||
if ((req.params.group === "admin" && ["UserManage", "BookManage", "CategoryManage", "Debug"].indexOf(req.params.page) > -1) ||
|
||||
(req.params.group === "user" && ["myBookshelf", "myCollection"].indexOf(req.params.page) > -1)) {
|
||||
res.render(`dashboard/${req.params.group}/manage`, {
|
||||
title: getPageTitle(req.params.group === "admin" ? "后台管理" : "用户中心"),
|
||||
@@ -119,6 +122,7 @@ router.get('/dashboard/:group/:page', function (req, res) {
|
||||
"UserManage": "用户管理",
|
||||
"BookManage": "书籍管理",
|
||||
"CategoryManage": "分类管理",
|
||||
"Debug": "调试",
|
||||
// 用户
|
||||
"myBookshelf": "我的书架",
|
||||
"myCollection": "我的收藏",
|
||||
|
@@ -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) {
|
||||
|
@@ -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);
|
||||
// }
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
Reference in New Issue
Block a user