refactor: 项目结构优化

This commit is contained in:
haoxr
2022-12-18 12:50:44 +08:00
parent 0e8e56a24a
commit e8affeca51
20 changed files with 36 additions and 33 deletions

View File

@@ -0,0 +1,32 @@
package com.youlai.system.common.enums;
import com.youlai.system.common.base.IBaseEnum;
import lombok.Getter;
/**
* 数据权限枚举
*
* @author haoxr
* @date 2022/10/14
*/
public enum DataScopeEnum implements IBaseEnum<Integer> {
/**
* value 越小,数据权限范围越大
*/
ALL(0, "所有数据"),
DEPT_AND_SUB(1, "部门及子部门数据"),
DEPT(2, "本部门数据"),
SELF(3, "本人数据");
@Getter
private Integer value;
@Getter
private String label;
DataScopeEnum(Integer value, String label) {
this.value = value;
this.label = label;
}
}

View File

@@ -0,0 +1,27 @@
package com.youlai.system.common.enums;
import com.youlai.system.common.base.IBaseEnum;
import lombok.Getter;
/**
* 性别枚举
*
* @author haoxr
* @date 2022/10/14
*/
public enum GenderEnum implements IBaseEnum<Integer> {
MALE(1, ""),
FEMALE (2, "");
@Getter
private Integer value;
@Getter
private String label;
GenderEnum(Integer value, String label) {
this.value = value;
this.label = label;
}
}

View File

@@ -0,0 +1,35 @@
package com.youlai.system.common.enums;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.youlai.system.common.base.IBaseEnum;
import lombok.Getter;
/**
* 菜单类型枚举
*
* @author haoxr
* @date 2022/4/23 9:36
*/
public enum MenuTypeEnum implements IBaseEnum<Integer> {
NULL(0, null),
MENU(1, "菜单"),
CATALOG(2, "目录"),
EXTLINK(3, "外链"),
BUTTON(4, "按钮");
@Getter
@EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值
private Integer value;
@Getter
// @JsonValue // 表示对枚举序列化时返回此字段
private String label;
MenuTypeEnum(Integer value, String label) {
this.value = value;
this.label = label;
}
}

View File

@@ -0,0 +1,27 @@
package com.youlai.system.common.enums;
import com.youlai.system.common.base.IBaseEnum;
import lombok.Getter;
/**
* 状态枚举
*
* @author haoxr
* @date 2022/10/14
*/
public enum StatusEnum implements IBaseEnum<Integer> {
ENABLE(1, "启用"),
DISABLE (0, "禁用");
@Getter
private Integer value;
@Getter
private String label;
StatusEnum(Integer value, String label) {
this.value = value;
this.label = label;
}
}

View File

@@ -28,12 +28,11 @@ import java.util.stream.Collectors;
/**
* 全局系统异常处理
*
* 调整异常处理的HTTP状态码丰富异常处理类型
*
* @author hxrui
* @author Gadfly
* @date 2020-02-25 13:54
* <p>
**/
@RestControllerAdvice
@Slf4j
@@ -166,12 +165,10 @@ public class GlobalExceptionHandler {
}
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BusinessException.class)
public <T> Result<T> handleBizException(BusinessException e) {
log.error("业务异常,异常原因:{}", e.getMessage(), e);
log.error("biz exception,{}", e.getMessage());
if (e.getResultCode() != null) {
return Result.failed(e.getResultCode());
}
@@ -181,6 +178,7 @@ public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(Exception.class)
public <T> Result<T> handleException(Exception e) {
log.error("unknown exception, {}", e.getMessage());
return Result.failed(e.getLocalizedMessage());
}

View File

@@ -0,0 +1,45 @@
package com.youlai.system.common.util;
import cn.hutool.json.JSONUtil;
import com.youlai.system.common.result.Result;
import com.youlai.system.common.result.ResultCode;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* response 响应工具类
*
* @author haoxr
* @date 2022/10/18
*/
public class ResponseUtils {
/**
* 异常消息返回(适用过滤器异常响应)
*
* @param response
* @param resultCode
*/
public static void writeErrMsg(HttpServletResponse response, ResultCode resultCode) throws IOException {
switch (resultCode) {
case ACCESS_UNAUTHORIZED:
case TOKEN_INVALID:
response.setStatus(HttpStatus.UNAUTHORIZED.value());
break;
case TOKEN_ACCESS_FORBIDDEN:
response.setStatus(HttpStatus.FORBIDDEN.value());
break;
default:
response.setStatus(HttpStatus.BAD_REQUEST.value());
break;
}
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setCharacterEncoding("UTF-8");
response.getWriter().print(JSONUtil.toJsonStr(Result.failed(resultCode)));
}
}