mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-10-08 13:16:41 +08:00
update error code
This commit is contained in:
parent
da7ef2b641
commit
664309804a
@ -0,0 +1,46 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
/**
|
||||
* @author zhuoda
|
||||
* @Date 2021-09-27
|
||||
*/
|
||||
public interface ErrorCode {
|
||||
|
||||
/**
|
||||
* 系统等级
|
||||
*/
|
||||
String LEVEL_SYSTEM = "system";
|
||||
|
||||
/**
|
||||
* 用户等级
|
||||
*/
|
||||
String LEVEL_USER = "user";
|
||||
|
||||
/**
|
||||
* 未预期到的等级
|
||||
*/
|
||||
String LEVEL_UNEXPECTED = "unexpected";
|
||||
|
||||
/**
|
||||
* 错误码
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int getCode();
|
||||
|
||||
/**
|
||||
* 错误消息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getMsg();
|
||||
|
||||
/**
|
||||
* 错误等级
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getLevel();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 返回 状态码 注册
|
||||
*
|
||||
* @author zhuoda
|
||||
* @date 2021/09/27 22:09
|
||||
*/
|
||||
class ErrorCodeRangeContainer {
|
||||
|
||||
/**
|
||||
* 所有的错误码均大于10000
|
||||
*/
|
||||
static final int MIN_START_CODE = 10000;
|
||||
|
||||
static final Map<Class<? extends ErrorCode>, ImmutablePair<Integer, Integer>> CODE_RANGE_MAP = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 注册状态码
|
||||
* 校验是否重复 是否越界
|
||||
*
|
||||
* @param clazz
|
||||
* @param start
|
||||
* @param end
|
||||
*/
|
||||
static void register(Class<? extends ErrorCode> clazz, int start, int end) {
|
||||
String simpleName = clazz.getSimpleName();
|
||||
if (!clazz.isEnum()) {
|
||||
throw new ExceptionInInitializerError(String.format("<<ErrorCodeRangeValidator>> error: %s not Enum class !", simpleName));
|
||||
}
|
||||
if (start > end) {
|
||||
throw new ExceptionInInitializerError(String.format("<<ErrorCodeRangeValidator>> error: %s start must be less than the end !", simpleName));
|
||||
}
|
||||
|
||||
if (start <= MIN_START_CODE) {
|
||||
throw new ExceptionInInitializerError(String.format("<<ErrorCodeRangeValidator>> error: %s start must be more than %s !", simpleName, MIN_START_CODE));
|
||||
}
|
||||
|
||||
// 校验是否重复注册
|
||||
boolean containsKey = CODE_RANGE_MAP.containsKey(clazz);
|
||||
if (containsKey) {
|
||||
throw new ExceptionInInitializerError(String.format("<<ErrorCodeRangeValidator>> error: Enum %s already exist !", simpleName));
|
||||
}
|
||||
|
||||
// 校验 开始结束值 是否越界
|
||||
CODE_RANGE_MAP.forEach((k, v) -> {
|
||||
if (isExistOtherRange(start, end, v)) {
|
||||
throw new IllegalArgumentException(String.format("<<ErrorCodeRangeValidator>> error: %s[%d,%d] has intersection with class:%s[%d,%d]", simpleName, start, end,
|
||||
k.getSimpleName(), v.getLeft(), v.getRight()));
|
||||
}
|
||||
});
|
||||
|
||||
// 循环校验code并存储
|
||||
List<Integer> codeList = Stream.of(clazz.getEnumConstants()).map(codeEnum -> {
|
||||
Integer code = codeEnum.getCode();
|
||||
if (code < start || code > end) {
|
||||
throw new IllegalArgumentException(String.format("<<ErrorCodeRangeValidator>> error: %s[%d,%d] code %d out of range", simpleName, start, end, code));
|
||||
}
|
||||
return code;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 校验code是否重复
|
||||
List<Integer> distinctCodeList = codeList.stream().distinct().collect(Collectors.toList());
|
||||
Collection<Integer> subtract = CollectionUtils.subtract(codeList, distinctCodeList);
|
||||
if (CollectionUtils.isNotEmpty(subtract)) {
|
||||
throw new IllegalArgumentException(String.format("<<ErrorCodeRangeValidator>> error: %s code %s is repeat!", simpleName, subtract));
|
||||
}
|
||||
|
||||
CODE_RANGE_MAP.put(clazz, ImmutablePair.of(start, end));
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否存在于其他范围
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @param range
|
||||
* @return
|
||||
*/
|
||||
private static boolean isExistOtherRange(int start, int end, ImmutablePair<Integer, Integer> range) {
|
||||
if (start >= range.getLeft() && start <= range.getRight()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (end >= range.getLeft() && end <= range.getRight()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void finish() {
|
||||
System.out.println("-------------- ErrorCode init finish-------------");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
|
||||
import static net.lab1024.smartadmin.service.common.code.ErrorCodeRangeContainer.register;
|
||||
|
||||
/**
|
||||
* 注册code状态码
|
||||
* 之所以需要在此处手动注册
|
||||
* 主要是为了 有一个地方能统一、清楚的看到所有状态码目前的范围,方便新增定义
|
||||
*
|
||||
* @author zhuoda
|
||||
* @date 2021/09/27 23:09
|
||||
*/
|
||||
public class ErrorCodeRegister {
|
||||
|
||||
static {
|
||||
|
||||
// 系统 错误码
|
||||
register(SystemErrorCode.class, 10001, 20000);
|
||||
|
||||
// 意外 错误码
|
||||
register(UnexpectedErrorCode.class, 20001, 30000);
|
||||
|
||||
// 用户 通用错误码
|
||||
register(UserErrorCode.class, 30001, 40000);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void init() {
|
||||
ErrorCodeRangeContainer.finish();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ErrorCodeRegister.init();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author zhuoda
|
||||
* @Date 2021-09-27
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum SystemErrorCode implements ErrorCode {
|
||||
|
||||
SYSTEM_ERROR(10001, "系统似乎出现了点小问题"),
|
||||
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String msg;
|
||||
|
||||
private final String level;
|
||||
|
||||
SystemErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.level = LEVEL_SYSTEM;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author zhuoda
|
||||
* @Date 2021-09-27
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UnexpectedErrorCode implements ErrorCode {
|
||||
|
||||
BUSINESS_HANDING(20001, "呃~ 业务繁忙,请稍后重试"),
|
||||
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String msg;
|
||||
|
||||
private final String level;
|
||||
|
||||
UnexpectedErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.level = LEVEL_UNEXPECTED;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package net.lab1024.smartadmin.service.common.code;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author zhuoda
|
||||
* @Date 2021-09-27
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum UserErrorCode implements ErrorCode {
|
||||
|
||||
PARAM_ERROR(30001, "参数错误"),
|
||||
|
||||
DATA_NOT_EXIST(30002, "左翻右翻,数据竟然找不到了~"),
|
||||
|
||||
ALREADY_EXIST(30003, "数据已存在了呀~"),
|
||||
|
||||
REPEAT_SUBMIT(30004, "亲~您操作的可太快了,请稍等下再操作~"),
|
||||
|
||||
NO_PERMISSION(30005, "对不起,您没有权限哦~"),
|
||||
|
||||
DEVELOPING(30006, "系統正在紧急开发中,敬请期待~"),
|
||||
|
||||
LOGIN_STATE_INVALID(30007, "您还未登录或登录失效,请重新登录!"),
|
||||
|
||||
LOGIN_OTHER_DEVICE(30008, "您的账号已在其他设备登录,请重新登录"),
|
||||
|
||||
USER_STATUS_ERROR(30009, "用户状态异常"),
|
||||
|
||||
LOGIN_FAILED(30010, "用户名或密码错误!"),
|
||||
|
||||
VERIFICATION_CODE_INVALID(30011, "验证码错误或已过期,请输入正确的验证码"),
|
||||
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String msg;
|
||||
|
||||
private final String level;
|
||||
|
||||
UserErrorCode(int code, String msg) {
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.level = LEVEL_USER;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* 部门返回信息常量类
|
||||
* 2001 - 2999
|
||||
*
|
||||
* @author listen
|
||||
* @date 2017/12/19 18:52
|
||||
*/
|
||||
public class DepartmentResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
/**
|
||||
* 部门不存在 1001
|
||||
*/
|
||||
public static final DepartmentResponseCodeConst DEPT_NOT_EXISTS = new DepartmentResponseCodeConst(2001, "部门不存在");
|
||||
|
||||
/**
|
||||
* 当前部门有子级部门 不能删除 10003
|
||||
*/
|
||||
public static final DepartmentResponseCodeConst CANNOT_DEL_DEPARTMENT_WITH_CHILD = new
|
||||
DepartmentResponseCodeConst(2002, "当前部门有子级部门,无法删除!");
|
||||
|
||||
/**
|
||||
* 当前部门有员工 不能删除 10004
|
||||
*/
|
||||
public static final DepartmentResponseCodeConst CANNOT_DEL_DEPARTMENT_WITH_EMPLOYEE = new
|
||||
DepartmentResponseCodeConst(2003, "当前部门有员工,无法删除!");
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final DepartmentResponseCodeConst PARENT_ID_ERROR = new DepartmentResponseCodeConst(2004, "上级部门id不能等于当前部门id");
|
||||
|
||||
public DepartmentResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* 员工常量类
|
||||
* 3001-3999
|
||||
*
|
||||
* @author 开云
|
||||
* @date 2017年12月19日下午19:04:52
|
||||
*/
|
||||
public class EmployeeResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
/**
|
||||
* 员工不存在
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst EMP_NOT_EXISTS = new EmployeeResponseCodeConst(3001, "员工不存在!");
|
||||
|
||||
/**
|
||||
* 更新员工信息失败
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst UPDATE_FAILED = new EmployeeResponseCodeConst(3002, "员工更新失败!");
|
||||
|
||||
/**
|
||||
* 部门信息不存在
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst DEPT_NOT_EXIST = new EmployeeResponseCodeConst(3003, "部门信息不存在!");
|
||||
|
||||
/**
|
||||
* 用户名或密码错误
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst LOGIN_FAILED = new EmployeeResponseCodeConst(3004, "用户名或密码错误!");
|
||||
|
||||
/**
|
||||
* 您的账号已被禁用,不得登录系统
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst IS_DISABLED = new EmployeeResponseCodeConst(3005, "您的账号已被禁用");
|
||||
|
||||
/**
|
||||
* 登录名已存在
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst LOGIN_NAME_EXISTS = new EmployeeResponseCodeConst(3006, "登录名已存在!");
|
||||
|
||||
/**
|
||||
* 密码输入有误,请重新输入
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst PASSWORD_ERROR = new EmployeeResponseCodeConst(3007, "密码错误");
|
||||
|
||||
/**
|
||||
* 手机号已存在
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst PHONE_EXISTS = new EmployeeResponseCodeConst(3008, "手机号已经存在");
|
||||
|
||||
public static final EmployeeResponseCodeConst ID_CARD_ERROR = new EmployeeResponseCodeConst(3009, "请输入正确的身份证号");
|
||||
|
||||
public static final EmployeeResponseCodeConst BIRTHDAY_ERROR = new EmployeeResponseCodeConst(3010, "生日格式不正确");
|
||||
|
||||
public static final EmployeeResponseCodeConst VERIFICATION_CODE_INVALID = new EmployeeResponseCodeConst(3011, "请输入正确的验证码");
|
||||
|
||||
/**
|
||||
* 用户名或密码错误 多次错误用于前端判断展示验证码
|
||||
*/
|
||||
public static final EmployeeResponseCodeConst LOGIN_FAILED_REPEATEDLY = new EmployeeResponseCodeConst(3012, "用户名或密码错误!");
|
||||
|
||||
public EmployeeResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* [ ]
|
||||
*
|
||||
* @author 罗伊
|
||||
* @date 2020/8/25 11:57
|
||||
*/
|
||||
public class FileResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
/**
|
||||
* 4001 -4999
|
||||
*/
|
||||
public static final FileResponseCodeConst FILE_EMPTY = new FileResponseCodeConst(4001, "上传文件不能为空");
|
||||
|
||||
public static final FileResponseCodeConst FILE_SIZE_ERROR = new FileResponseCodeConst(4002, "上传文件超过%s,请重新上传!");
|
||||
|
||||
public static final FileResponseCodeConst UNKNOWN_FILE_TYPE = new FileResponseCodeConst(4003, "未知的文件类型!");
|
||||
|
||||
public static final FileResponseCodeConst LOCAL_UPDATE_PREFIX_ERROR = new FileResponseCodeConst(4004, "文件本地上传缺少URL前缀配置[local_upload_url_prefix]");
|
||||
|
||||
public static final FileResponseCodeConst UPLOAD_ERROR = new FileResponseCodeConst(4005, "上传失败");
|
||||
|
||||
public static final FileResponseCodeConst URL_ERROR = new FileResponseCodeConst(4006, "获取URL失败");
|
||||
|
||||
public static final FileResponseCodeConst FILE_MODULE_ERROR = new FileResponseCodeConst(4007, "文件目录类型错误");
|
||||
|
||||
public static final FileResponseCodeConst FILE_NOT_EXIST = new FileResponseCodeConst(4008, "文件不存在");
|
||||
|
||||
public static final FileResponseCodeConst DOWNLOAD_ERROR = new FileResponseCodeConst(4009, "文件下载失败");
|
||||
|
||||
public static final FileResponseCodeConst VOD_SERVICE_ERROR = new FileResponseCodeConst(4010, "VOD服务错误:");
|
||||
|
||||
public static final FileResponseCodeConst VOD_FILE_ERROR = new FileResponseCodeConst(4011, "请上传正确的音/视频格式");
|
||||
|
||||
public static final FileResponseCodeConst VOD_FILE_NOT_EXIST = new FileResponseCodeConst(4012, "视频文件不存在");
|
||||
|
||||
public static final FileResponseCodeConst FILE_NAME_ERROR = new FileResponseCodeConst(4013, "文件名称必须1-100个字符");
|
||||
|
||||
public static final FileResponseCodeConst VOD_TOKEN_ERROR = new FileResponseCodeConst(4014, "视频文件TOKEN失效");
|
||||
|
||||
public static final FileResponseCodeConst VOD_CIPHER_TEXT_ERROR = new FileResponseCodeConst(4015, "视频文件CIPHER_TEXT无效");
|
||||
|
||||
public FileResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* 员工常量类
|
||||
* 1001-1999
|
||||
*
|
||||
* @author 开云
|
||||
* @date 2017年12月19日下午19:04:52
|
||||
*/
|
||||
public class LoginResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
public static final LoginResponseCodeConst LOGIN_ERROR = new LoginResponseCodeConst(1001, "您还未登录或登录失效,请重新登录!");
|
||||
|
||||
public static final LoginResponseCodeConst NOT_HAVE_PRIVILEGES = new LoginResponseCodeConst(1002, "对不起,您没有权限哦!");
|
||||
|
||||
public LoginResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* @author
|
||||
*/
|
||||
public class PositionResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
public static final PositionResponseCodeConst REMOVE_DEFINE = new PositionResponseCodeConst(13000, "还有人关联该岗位,不能删除");
|
||||
|
||||
protected PositionResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
|
||||
/**
|
||||
* @author 罗伊
|
||||
*/
|
||||
public class PrivilegeResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
public static final PrivilegeResponseCodeConst PRIVILEGE_NOT_EXISTS = new PrivilegeResponseCodeConst(7001, "当前数据不存在,请联系你的管理员!");
|
||||
|
||||
public static final PrivilegeResponseCodeConst ROUTER_KEY_NO_REPEAT = new PrivilegeResponseCodeConst(7002, "模块和页面的“功能Key”值不能重复!");
|
||||
|
||||
public static final PrivilegeResponseCodeConst MENU_NOT_EXIST = new PrivilegeResponseCodeConst(7003, "菜单不存在,清先保存菜单!");
|
||||
|
||||
public static final PrivilegeResponseCodeConst POINT_NOT_EXIST = new PrivilegeResponseCodeConst(7004, "功能点不存在,清先保存功能点!");
|
||||
|
||||
public PrivilegeResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
||||
|
@ -1,111 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 1 表示成功
|
||||
* 10 - 100 表示 系统异常,即java报错了
|
||||
* 100 以上, 业务
|
||||
* <p>
|
||||
* 根据实际业务,设置范围值
|
||||
* 正常100就够了
|
||||
*
|
||||
* @author Administrator
|
||||
*/
|
||||
@Slf4j
|
||||
public class ResponseCodeConst {
|
||||
|
||||
public static final ResponseCodeConst SUCCESS = new ResponseCodeConst(1, "操作成功!", true);
|
||||
|
||||
public static final ResponseCodeConst SYSTEM_ERROR = new ResponseCodeConst(11, "系统繁忙,请稍后重试");
|
||||
|
||||
public static final ResponseCodeConst ERROR_PARAM = new ResponseCodeConst(101, "参数异常");
|
||||
|
||||
public static final ResponseCodeConst ERROR_PARAM_ANY = new ResponseCodeConst(102, "%s参数异常!");
|
||||
|
||||
public static final ResponseCodeConst DEVELOPMENT = new ResponseCodeConst(112, "此功能正在开发中");
|
||||
|
||||
public static final ResponseCodeConst NOT_EXISTS = new ResponseCodeConst(113, "数据不存在");
|
||||
|
||||
public static final ResponseCodeConst REQUEST_METHOD_ERROR = new ResponseCodeConst(114, "请求方式错误");
|
||||
|
||||
public static final ResponseCodeConst JSON_FORMAT_ERROR = new ResponseCodeConst(115, "前端请求参数格式错误");
|
||||
|
||||
public static final ResponseCodeConst PERMISSION_DENIED = new ResponseCodeConst(116, "您没有权限修改数据");
|
||||
|
||||
public static final ResponseCodeConst ALREADY_EXIST = new ResponseCodeConst(117, "数据已存在");
|
||||
|
||||
public static final ResponseCodeConst STATUS_ERROR = new ResponseCodeConst(118, "数据状态异常");
|
||||
|
||||
public static final ResponseCodeConst AREA_ERROR = new ResponseCodeConst(119, "地区数据错误");
|
||||
|
||||
public static final ResponseCodeConst REQUEST_ERROR = new ResponseCodeConst(120, "请求异常");
|
||||
|
||||
public static final ResponseCodeConst TOKEN_ERROR = new ResponseCodeConst(121, "登录失效,请重新登录");
|
||||
|
||||
public static final ResponseCodeConst BUSINESS_HANDING = new ResponseCodeConst(122, "业务正在繁忙处理中,请稍后再试");
|
||||
|
||||
public static final ResponseCodeConst NOT_SUPPORT = new ResponseCodeConst(123, "暂不支持");
|
||||
|
||||
public static final ResponseCodeConst REPEAT_SUBMIT = new ResponseCodeConst(125, "太...太快了,请您稍后重试~");
|
||||
|
||||
protected int code;
|
||||
|
||||
protected String msg;
|
||||
|
||||
protected boolean success;
|
||||
|
||||
public ResponseCodeConst() {
|
||||
}
|
||||
|
||||
protected ResponseCodeConst(int code, String msg) {
|
||||
super();
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
ResponseCodeContainer.put(this);
|
||||
}
|
||||
|
||||
protected ResponseCodeConst(int code, String msg, boolean success) {
|
||||
super();
|
||||
this.code = code;
|
||||
this.msg = msg;
|
||||
this.success = success;
|
||||
ResponseCodeContainer.put(this);
|
||||
}
|
||||
|
||||
protected ResponseCodeConst(int code) {
|
||||
super();
|
||||
this.code = code;
|
||||
ResponseCodeContainer.put(this);
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public boolean issucc() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
log.info("-------------- ResponseCodeConst init -------------");
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* [ ]
|
||||
*
|
||||
* @author 罗伊
|
||||
* @date 2021/1/8 11:28
|
||||
*/
|
||||
@Slf4j
|
||||
public class ResponseCodeContainer {
|
||||
|
||||
private static final Map<Integer, ResponseCodeConst> RESPONSE_CODE_MAP = new HashMap<>();
|
||||
|
||||
private static final Map<Class<? extends ResponseCodeConst>, int[]> RESPONSE_CODE_RANGE_MAP = new HashMap<>();
|
||||
|
||||
/**
|
||||
* id的范围:[start, end]左闭右闭
|
||||
*
|
||||
* @param clazz
|
||||
* @param start
|
||||
* @param end
|
||||
*/
|
||||
public static void register(Class<? extends ResponseCodeConst> clazz, int start, int end) {
|
||||
if (start > end) {
|
||||
throw new IllegalArgumentException("<ResponseDTO> start > end!");
|
||||
}
|
||||
|
||||
if (RESPONSE_CODE_RANGE_MAP.containsKey(clazz)) {
|
||||
throw new IllegalArgumentException(String.format("<ResponseDTO> Class:%s already exist!", clazz.getSimpleName()));
|
||||
}
|
||||
RESPONSE_CODE_RANGE_MAP.forEach((k, v) -> {
|
||||
if ((start >= v[0] && start <= v[1]) || (end >= v[0] && end <= v[1])) {
|
||||
throw new IllegalArgumentException(String.format("<ResponseDTO> Class:%s 's id range[%d,%d] has " + "intersection with " + "class:%s", clazz.getSimpleName(), start, end,
|
||||
k.getSimpleName()));
|
||||
}
|
||||
});
|
||||
|
||||
RESPONSE_CODE_RANGE_MAP.put(clazz, new int[]{start, end});
|
||||
|
||||
// 提前初始化static变量,进行范围检测
|
||||
Field[] fields = clazz.getFields();
|
||||
if (fields.length != 0) {
|
||||
try {
|
||||
fields[0].get(clazz);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void put(ResponseCodeConst codeConst) {
|
||||
int[] idRange = RESPONSE_CODE_RANGE_MAP.get(codeConst.getClass());
|
||||
if (idRange == null) {
|
||||
throw new IllegalArgumentException(String.format("<ResponseDTO> Class:%s has not been registered!", codeConst.getClass().getSimpleName()));
|
||||
}
|
||||
int code = codeConst.code;
|
||||
if (code < idRange[0] || code > idRange[1]) {
|
||||
throw new IllegalArgumentException(String.format("<ResponseDTO> Id(%d) out of range[%d,%d], " + "class:%s", code, idRange[0], idRange[1], codeConst.getClass().getSimpleName()));
|
||||
}
|
||||
if (RESPONSE_CODE_MAP.keySet().contains(code)) {
|
||||
log.error(String.format("<ResponseDTO> Id(%d) out of range[%d,%d], " + "class:%s code is repeat!", code, idRange[0], idRange[1], codeConst.getClass().getSimpleName()));
|
||||
System.exit(0);
|
||||
}
|
||||
RESPONSE_CODE_MAP.put(code, codeConst);
|
||||
}
|
||||
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* [ ]
|
||||
*
|
||||
* @author 罗伊
|
||||
* @date 2021/1/8 15:59
|
||||
*/
|
||||
@Slf4j
|
||||
public class ResponseCodeRegister {
|
||||
|
||||
// 范围声明
|
||||
static {
|
||||
// 系统功能,从0开始,step=1000
|
||||
ResponseCodeContainer.register(ResponseCodeConst.class, 0, 1000);
|
||||
ResponseCodeContainer.register(LoginResponseCodeConst.class, 1001, 1999);
|
||||
ResponseCodeContainer.register(DepartmentResponseCodeConst.class, 2001, 2999);
|
||||
ResponseCodeContainer.register(EmployeeResponseCodeConst.class, 3001, 3999);
|
||||
ResponseCodeContainer.register(FileResponseCodeConst.class, 4001, 5000);
|
||||
ResponseCodeContainer.register(RoleResponseCodeConst.class, 6001, 6999);
|
||||
ResponseCodeContainer.register(PrivilegeResponseCodeConst.class, 7001, 7999);
|
||||
ResponseCodeContainer.register(PositionResponseCodeConst.class, 13000, 13999);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
log.info("-------------- ResponseCodeConst init -------------");
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package net.lab1024.smartadmin.service.common.codeconst;
|
||||
|
||||
/**
|
||||
* @author 罗伊
|
||||
* 角色业务状态码 6001 - 6999
|
||||
*/
|
||||
public class RoleResponseCodeConst extends ResponseCodeConst {
|
||||
|
||||
/**
|
||||
* 10501 角色名称已存在
|
||||
*/
|
||||
public static final RoleResponseCodeConst ROLE_NAME_EXISTS = new RoleResponseCodeConst(6001, "角色名称已存在");
|
||||
|
||||
/**
|
||||
* 10502 角色不存在
|
||||
*/
|
||||
public static final RoleResponseCodeConst ROLE_NOT_EXISTS = new RoleResponseCodeConst(6002, "角色不存在");
|
||||
|
||||
public RoleResponseCodeConst(int code, String msg) {
|
||||
super(code, msg);
|
||||
}
|
||||
}
|
@ -3,9 +3,10 @@ package net.lab1024.smartadmin.service.common.domain;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.Range;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
@ -22,11 +23,12 @@ public class PageBaseDTO {
|
||||
|
||||
@ApiModelProperty(value = "页码(不能为空)", required = true, example = "1")
|
||||
@NotNull(message = "分页参数不能为空")
|
||||
@Min(value = 1, message = "分页参数最小1")
|
||||
private Integer pageNum;
|
||||
|
||||
@ApiModelProperty(value = "每页数量(不能为空)", required = true, example = "10")
|
||||
@NotNull(message = "每页数量不能为空")
|
||||
@Max(value = 200, message = "每页最大为200")
|
||||
@Range(min = 1, max = 200, message = "每页数量1-200")
|
||||
private Integer pageSize;
|
||||
|
||||
@ApiModelProperty("排序字段集合")
|
||||
|
@ -1,150 +1,82 @@
|
||||
package net.lab1024.smartadmin.service.common.domain;
|
||||
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import lombok.Data;
|
||||
import net.lab1024.smartadmin.service.common.code.ErrorCode;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* 返回类
|
||||
*
|
||||
* @param <T>
|
||||
* @author 1024lab
|
||||
*/
|
||||
@Data
|
||||
public class ResponseDTO<T> {
|
||||
|
||||
protected Integer code;
|
||||
public static final int OK_CODE = 0;
|
||||
|
||||
protected String msg;
|
||||
public static final String OK_MSG = "success";
|
||||
|
||||
protected Boolean success;
|
||||
private Integer code;
|
||||
|
||||
protected T data;
|
||||
private String level;
|
||||
|
||||
public ResponseDTO() {
|
||||
}
|
||||
private String msg;
|
||||
|
||||
public ResponseDTO(ResponseCodeConst responseCodeConst, String msg) {
|
||||
this.code = responseCodeConst.getCode();
|
||||
this.msg = msg;
|
||||
this.success = responseCodeConst.issucc();
|
||||
}
|
||||
private Boolean ok;
|
||||
|
||||
public ResponseDTO(ResponseCodeConst responseCodeConst, T data) {
|
||||
super();
|
||||
this.code = responseCodeConst.getCode();
|
||||
this.msg = responseCodeConst.getMsg();
|
||||
this.data = data;
|
||||
this.success = responseCodeConst.issucc();
|
||||
}
|
||||
private T data;
|
||||
|
||||
public ResponseDTO(ResponseCodeConst responseCodeConst, T data, String msg) {
|
||||
super();
|
||||
this.code = responseCodeConst.getCode();
|
||||
this.msg = msg;
|
||||
this.data = data;
|
||||
this.success = responseCodeConst.issucc();
|
||||
}
|
||||
|
||||
private ResponseDTO(ResponseCodeConst responseCodeConst) {
|
||||
this.code = responseCodeConst.getCode();
|
||||
this.msg = responseCodeConst.getMsg();
|
||||
this.success = responseCodeConst.issucc();
|
||||
}
|
||||
|
||||
public ResponseDTO(ResponseDTO responseDTO) {
|
||||
this.code = responseDTO.getCode();
|
||||
this.msg = responseDTO.getMsg();
|
||||
this.success = responseDTO.isSuccess();
|
||||
}
|
||||
|
||||
public ResponseDTO(ResponseCodeConst codeConst, boolean isSuccess) {
|
||||
this.code = codeConst.getCode();
|
||||
this.msg = codeConst.getMsg();
|
||||
this.success = isSuccess;
|
||||
}
|
||||
|
||||
public ResponseDTO(int code, String msg, boolean isSuccess) {
|
||||
public ResponseDTO(Integer code, String level, boolean ok, String msg, T data) {
|
||||
this.code = code;
|
||||
this.level = level;
|
||||
this.ok = ok;
|
||||
this.msg = msg;
|
||||
this.success = isSuccess;
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> succ() {
|
||||
return new ResponseDTO(ResponseCodeConst.SUCCESS);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> succData(T data, String msg) {
|
||||
return new ResponseDTO(ResponseCodeConst.SUCCESS, data, msg);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> succData(T data) {
|
||||
return new ResponseDTO(ResponseCodeConst.SUCCESS, data);
|
||||
}
|
||||
|
||||
public static ResponseDTO succMsg(String msg) {
|
||||
return new ResponseDTO(ResponseCodeConst.SUCCESS, msg);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst) {
|
||||
return new ResponseDTO<>(codeConst);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> wrap(ResponseCodeConst codeConst, boolean isSuccess) {
|
||||
return new ResponseDTO<>(codeConst, isSuccess);
|
||||
}
|
||||
|
||||
public static ResponseDTO wrap(ResponseDTO responseDTO) {
|
||||
return new ResponseDTO<>(responseDTO.getCode(), responseDTO.getMsg(), responseDTO.isSuccess());
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> wrapData(ResponseCodeConst codeConst, T t) {
|
||||
return new ResponseDTO<T>(codeConst, t);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> wrapMsg(ResponseCodeConst codeConst, String msg) {
|
||||
return new ResponseDTO<T>(codeConst, msg);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> wrapDataMsg(ResponseCodeConst codeConst, T t, String msg) {
|
||||
return new ResponseDTO<T>(codeConst, t, msg);
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public ResponseDTO setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public ResponseDTO setCode(Integer code) {
|
||||
this.code = code;
|
||||
return this;
|
||||
}
|
||||
|
||||
public T getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ResponseDTO setData(T data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
public ResponseDTO(ErrorCode errorCode, boolean ok, String msg, T data) {
|
||||
this.code = errorCode.getCode();
|
||||
this.level = errorCode.getLevel();
|
||||
this.ok = ok;
|
||||
if (StringUtils.isNotBlank(msg)) {
|
||||
this.msg = msg;
|
||||
} else {
|
||||
this.msg = errorCode.getMsg();
|
||||
}
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
public static <T> ResponseDTO<T> ok() {
|
||||
return new ResponseDTO<>(OK_CODE, null, true, OK_MSG, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResponseDTO{" + "code=" + code + ", msg='" + msg + '\'' + ", success=" + success + ", data=" + data + '}';
|
||||
public static <T> ResponseDTO<T> ok(T data) {
|
||||
return new ResponseDTO<>(OK_CODE, null, true, OK_MSG, data);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> okMsg(String msg) {
|
||||
return new ResponseDTO<>(OK_CODE, null, true, msg, null);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> error(ErrorCode errorCode) {
|
||||
return new ResponseDTO<>(errorCode, false, null, null);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> error(ErrorCode errorCode, boolean ok) {
|
||||
return new ResponseDTO<>(errorCode, ok, null, null);
|
||||
}
|
||||
|
||||
public static ResponseDTO error(ResponseDTO responseDTO) {
|
||||
return new ResponseDTO<>(responseDTO.getCode(), responseDTO.getLevel(), responseDTO.getOk(), responseDTO.getMsg(), responseDTO.getData());
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> error(ErrorCode errorCode, String msg) {
|
||||
return new ResponseDTO<>(errorCode, false, msg, null);
|
||||
}
|
||||
|
||||
public static <T> ResponseDTO<T> errorData(ErrorCode errorCode, T data) {
|
||||
return new ResponseDTO<>(errorCode, false, null, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,44 +1,27 @@
|
||||
package net.lab1024.smartadmin.service.common.domain;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum;
|
||||
|
||||
/**
|
||||
*
|
||||
* 系统环境
|
||||
*
|
||||
* @author zhuoda
|
||||
* @Date 2021/8/13
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class SystemEnvironmentBO {
|
||||
|
||||
/**
|
||||
* 是否位生产环境
|
||||
*/
|
||||
private boolean isProd;
|
||||
private Boolean isProd;
|
||||
|
||||
/**
|
||||
* 当前环境
|
||||
*/
|
||||
private SystemEnvironmentEnum currentEnvironment;
|
||||
|
||||
public SystemEnvironmentBO(boolean isProd, SystemEnvironmentEnum currentEnvironment) {
|
||||
this.isProd = isProd;
|
||||
this.currentEnvironment = currentEnvironment;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isProd() {
|
||||
return isProd;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前环境
|
||||
* @return
|
||||
*/
|
||||
public SystemEnvironmentEnum getCurrentEnvironment() {
|
||||
return currentEnvironment;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.lab1024.smartadmin.service.common.exception;
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.ErrorCode;
|
||||
|
||||
/**
|
||||
* [ 业务逻辑异常,全局异常拦截后统一返回ResponseCodeConst.SYSTEM_ERROR ]
|
||||
@ -13,8 +13,8 @@ public class SmartBusinessException extends RuntimeException {
|
||||
public SmartBusinessException() {
|
||||
}
|
||||
|
||||
public SmartBusinessException(ResponseCodeConst responseCodeConst) {
|
||||
super(responseCodeConst.getMsg());
|
||||
public SmartBusinessException(ErrorCode errorCode) {
|
||||
super(errorCode.getMsg());
|
||||
}
|
||||
|
||||
public SmartBusinessException(String message) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.lab1024.smartadmin.service.common.security;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.LoginResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.ErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -23,18 +22,18 @@ public class SmartSecurityAuthenticationFailHandler implements AuthenticationEnt
|
||||
|
||||
@Override
|
||||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException {
|
||||
this.outputResult(response, LoginResponseCodeConst.LOGIN_ERROR);
|
||||
this.outputResult(response, UserErrorCode.LOGIN_STATE_INVALID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 输出
|
||||
*
|
||||
* @param response
|
||||
* @param respCode
|
||||
* @param errorCode
|
||||
* @throws IOException
|
||||
*/
|
||||
private void outputResult(HttpServletResponse response, ResponseCodeConst respCode) throws IOException {
|
||||
String msg = JSONObject.toJSONString(ResponseDTO.wrap(respCode));
|
||||
private void outputResult(HttpServletResponse response, ErrorCode errorCode) throws IOException {
|
||||
String msg = JSONObject.toJSONString(ResponseDTO.error(errorCode));
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.getWriter().write(msg);
|
||||
response.flushBuffer();
|
||||
|
@ -33,7 +33,7 @@ public class FileKeySerializer extends JsonSerializer<String> {
|
||||
return;
|
||||
}
|
||||
ResponseDTO<String> responseDTO = fileService.getFileUrl(value);
|
||||
if(responseDTO.isSuccess()){
|
||||
if(responseDTO.getOk()){
|
||||
jsonGenerator.writeString(responseDTO.getData());
|
||||
return;
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package net.lab1024.smartadmin.service.handler;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum;
|
||||
import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.SystemEnvironmentBO;
|
||||
import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum;
|
||||
import net.lab1024.smartadmin.service.common.exception.SmartBusinessException;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -50,7 +51,7 @@ public class SmartGlobalExceptionHandler {
|
||||
|
||||
// json 格式错误
|
||||
if (e instanceof HttpMessageNotReadableException) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.JSON_FORMAT_ERROR);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请求参数JSON格式错误");
|
||||
}
|
||||
|
||||
String uri = null;
|
||||
@ -62,45 +63,44 @@ public class SmartGlobalExceptionHandler {
|
||||
|
||||
// http 请求方式错误
|
||||
if (e instanceof HttpRequestMethodNotSupportedException) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.REQUEST_METHOD_ERROR);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请求方式错误");
|
||||
}
|
||||
|
||||
// 参数类型错误
|
||||
if (e instanceof TypeMismatchException) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
|
||||
}
|
||||
|
||||
// 参数校验未通过
|
||||
if (e instanceof MethodArgumentNotValidException) {
|
||||
List<FieldError> fieldErrors = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors();
|
||||
List<String> msgList = fieldErrors.stream().map(FieldError::getDefaultMessage).collect(Collectors.toList());
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, String.join(",", msgList));
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, String.join(",", msgList));
|
||||
}
|
||||
|
||||
// 参数绑定错误
|
||||
if (e instanceof BindException) {
|
||||
List<FieldError> fieldErrors = ((BindException) e).getFieldErrors();
|
||||
List<String> error = fieldErrors.stream().map(field -> field.getField() + ":" + field.getRejectedValue()).collect(Collectors.toList());
|
||||
String errorMsg = ResponseCodeConst.ERROR_PARAM.getMsg() + ":" + error.toString();
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, errorMsg);
|
||||
String errorMsg = UserErrorCode.PARAM_ERROR.getMsg() + ":" + error.toString();
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, errorMsg);
|
||||
}
|
||||
|
||||
if (e instanceof SmartBusinessException) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, e.getMessage());
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, e.getMessage());
|
||||
}
|
||||
|
||||
if (e instanceof AccessDeniedException) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "您暂无权限");
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "您暂无权限");
|
||||
}
|
||||
|
||||
log.error("捕获全局异常,URL:{}", uri, e);
|
||||
|
||||
// 正式环境 不返回错误信息
|
||||
SystemEnvironmentEnum currentEnvironment = systemEnvironmentBO.getCurrentEnvironment();
|
||||
if (SystemEnvironmentEnum.PROD == currentEnvironment) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
|
||||
if (SystemEnvironmentEnum.PROD == systemEnvironmentBO.getCurrentEnvironment()) {
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR);
|
||||
}
|
||||
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, e.toString());
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, e.toString());
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.listener;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeRegister;
|
||||
import net.lab1024.smartadmin.service.common.code.ErrorCodeRegister;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -22,7 +22,7 @@ public class SmartAdminStartupRunner implements CommandLineRunner {
|
||||
log.info("###################### init start ######################");
|
||||
|
||||
// 初始化状态码
|
||||
ResponseCodeRegister.init();
|
||||
ErrorCodeRegister.init();
|
||||
|
||||
log.info("###################### init complete ######################");
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.business.category;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.business.category.domain.*;
|
||||
@ -39,7 +39,7 @@ public class CategoryService {
|
||||
// 校验类目
|
||||
CategoryEntity categoryEntity = SmartBeanUtil.copy(addDTO, CategoryEntity.class);
|
||||
ResponseDTO<String> res = this.checkCategory(categoryEntity, false);
|
||||
if (!res.isSuccess()) {
|
||||
if (!res.getOk()) {
|
||||
return res;
|
||||
}
|
||||
// 没有父类则使用默认父类
|
||||
@ -53,7 +53,7 @@ public class CategoryService {
|
||||
|
||||
// 更新缓存
|
||||
categoryQueryService.removeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ public class CategoryService {
|
||||
Long categoryId = updateDTO.getCategoryId();
|
||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
||||
if (!optional.isPresent()) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
CategoryEntity categoryEntity = SmartBeanUtil.copy(updateDTO, CategoryEntity.class);
|
||||
|
||||
@ -81,14 +81,14 @@ public class CategoryService {
|
||||
categoryEntity.setParentId(optional.get().getParentId());
|
||||
|
||||
ResponseDTO<String> responseDTO = this.checkCategory(categoryEntity, true);
|
||||
if (!responseDTO.isSuccess()) {
|
||||
if (!responseDTO.getOk()) {
|
||||
return responseDTO;
|
||||
}
|
||||
categoryDao.updateById(categoryEntity);
|
||||
|
||||
// 更新缓存
|
||||
categoryQueryService.removeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,17 +104,17 @@ public class CategoryService {
|
||||
Integer categoryType = categoryEntity.getCategoryType();
|
||||
if (null != parentId) {
|
||||
if (Objects.equals(categoryEntity.getCategoryId(), parentId)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "父级类目怎么和自己相同了");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "父级类目怎么和自己相同了");
|
||||
}
|
||||
if (!Objects.equals(parentId, CommonConst.DEFAULT_PARENT_ID)) {
|
||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(parentId);
|
||||
if (!optional.isPresent()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.NOT_EXISTS, "父级类目不存在~");
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "父级类目不存在~");
|
||||
}
|
||||
|
||||
CategoryEntity parent = optional.get();
|
||||
if (!Objects.equals(categoryType, parent.getCategoryType())) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "与父级类目类型不一致");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "与父级类目类型不一致");
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,13 +133,13 @@ public class CategoryService {
|
||||
if (null != queryEntity) {
|
||||
if (isUpdate) {
|
||||
if (!Objects.equals(queryEntity.getCategoryId(), categoryEntity.getCategoryId())) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "同级下已存在相同类目~");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "同级下已存在相同类目~");
|
||||
}
|
||||
} else {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "同级下已存在相同类目~");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "同级下已存在相同类目~");
|
||||
}
|
||||
}
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -151,10 +151,10 @@ public class CategoryService {
|
||||
public ResponseDTO<CategoryVO> queryDetail(Long categoryId) {
|
||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
||||
if (!optional.isPresent()) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
CategoryVO adminVO = SmartBeanUtil.copy(optional.get(), CategoryVO.class);
|
||||
return ResponseDTO.succData(adminVO);
|
||||
return ResponseDTO.ok(adminVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -167,12 +167,12 @@ public class CategoryService {
|
||||
public ResponseDTO<List<CategoryTreeVO>> queryTree(CategoryTreeQueryDTO queryDTO) {
|
||||
if (null == queryDTO.getParentId()) {
|
||||
if (null == queryDTO.getCategoryType()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "类目类型不能为空");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "类目类型不能为空");
|
||||
}
|
||||
queryDTO.setParentId(CommonConst.DEFAULT_PARENT_ID);
|
||||
}
|
||||
List<CategoryTreeVO> treeList = categoryQueryService.queryCategoryTree(queryDTO);
|
||||
return ResponseDTO.succData(treeList);
|
||||
return ResponseDTO.ok(treeList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -185,12 +185,12 @@ public class CategoryService {
|
||||
public ResponseDTO<String> delete(Long categoryId) {
|
||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
||||
if (!optional.isPresent()) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
List<Long> categorySubId = categoryQueryService.queryCategorySubId(Lists.newArrayList(categoryId));
|
||||
if (CollectionUtils.isNotEmpty(categorySubId)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "请先删除子级类目");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请先删除子级类目");
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
@ -201,7 +201,7 @@ public class CategoryService {
|
||||
|
||||
// 更新缓存
|
||||
categoryQueryService.removeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.business.goods;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.business.category.CategoryQueryService;
|
||||
@ -46,13 +46,13 @@ public class GoodsService {
|
||||
public ResponseDTO<String> add(GoodsAddDTO addDTO) {
|
||||
// 商品校验
|
||||
ResponseDTO<String> res = this.checkGoods(addDTO, null);
|
||||
if (!res.isSuccess()) {
|
||||
if (!res.getOk()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
GoodsEntity goodsEntity = SmartBeanUtil.copy(addDTO, GoodsEntity.class);
|
||||
goodsDao.insert(goodsEntity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,13 +64,13 @@ public class GoodsService {
|
||||
public ResponseDTO<String> update(GoodsUpdateDTO updateDTO) {
|
||||
// 商品校验
|
||||
ResponseDTO<String> res = this.checkGoods(updateDTO, updateDTO.getGoodsId());
|
||||
if (!res.isSuccess()) {
|
||||
if (!res.getOk()) {
|
||||
return res;
|
||||
}
|
||||
|
||||
GoodsEntity goodsEntity = SmartBeanUtil.copy(updateDTO, GoodsEntity.class);
|
||||
goodsDao.updateById(goodsEntity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,17 +92,17 @@ public class GoodsService {
|
||||
GoodsEntity goodsEntity = goodsDao.selectOne(goodsBO);
|
||||
if (null != goodsEntity) {
|
||||
if (null == goodsId || !Objects.equals(goodsEntity.getGoodsId(), goodsId)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "商品名称不能重复~");
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "商品名称不能重复~");
|
||||
}
|
||||
}
|
||||
|
||||
// 校验类目id
|
||||
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
|
||||
if (!optional.isPresent() || !CategoryTypeEnum.GOODS.equalsValue(optional.get().getCategoryType())) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.NOT_EXISTS, "商品类目不存在~");
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "商品类目不存在~");
|
||||
}
|
||||
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +120,7 @@ public class GoodsService {
|
||||
return goodsEntity;
|
||||
}).collect(Collectors.toList());
|
||||
goodsManager.updateBatchById(goodsList);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -135,12 +135,12 @@ public class GoodsService {
|
||||
List<GoodsAdminVO> list = goodsDao.query(page, queryDTO);
|
||||
PageResultDTO<GoodsAdminVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
|
||||
if (pageResult.getEmptyFlag()) {
|
||||
return ResponseDTO.succData(pageResult);
|
||||
return ResponseDTO.ok(pageResult);
|
||||
}
|
||||
// 查询分类名称
|
||||
List<Long> categoryIdList = list.stream().map(GoodsAdminVO::getCategoryId).distinct().collect(Collectors.toList());
|
||||
Map<Long, CategoryEntity> categoryMap = categoryQueryService.queryCategoryList(categoryIdList);
|
||||
list.forEach(e -> e.setCategoryName(categoryMap.get(e.getCategoryId()).getCategoryName()));
|
||||
return ResponseDTO.succData(pageResult);
|
||||
return ResponseDTO.ok(pageResult);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.business.notice;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.PageBaseDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
@ -47,7 +47,7 @@ public class NoticeService {
|
||||
Page page = SmartPageUtil.convert2PageQuery(queryDTO);
|
||||
List<NoticeVO> dtoList = noticeDao.queryByPage(page, queryDTO);
|
||||
PageResultDTO<NoticeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ public class NoticeService {
|
||||
e.setReadStatus(e.getReceiveTime() != null);
|
||||
});
|
||||
PageResultDTO<NoticeReceiveDTO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,7 +78,7 @@ public class NoticeService {
|
||||
Page page = SmartPageUtil.convert2PageQuery(queryDTO);
|
||||
List<NoticeVO> dtoList = noticeDao.queryUnreadByPage(page, employeeId, true);
|
||||
PageResultDTO<NoticeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -92,7 +92,7 @@ public class NoticeService {
|
||||
entity.setSendStatus(false);
|
||||
entity.setDeletedFlag(true);
|
||||
noticeDao.insert(entity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,16 +104,16 @@ public class NoticeService {
|
||||
public ResponseDTO<String> update(NoticeUpdateDTO updateDTO) {
|
||||
NoticeEntity entity = noticeDao.selectById(updateDTO.getId());
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
|
||||
}
|
||||
if (entity.getDeletedFlag()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知已删除");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知已删除");
|
||||
}
|
||||
if (entity.getSendStatus()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知已发送无法修改");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知已发送无法修改");
|
||||
}
|
||||
noticeManage.update(updateDTO);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -124,10 +124,10 @@ public class NoticeService {
|
||||
public ResponseDTO<String> delete(Long id) {
|
||||
NoticeEntity entity = noticeDao.selectById(id);
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
|
||||
}
|
||||
noticeManage.delete(entity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,7 +137,7 @@ public class NoticeService {
|
||||
*/
|
||||
public ResponseDTO<NoticeDetailVO> detail(Long id) {
|
||||
NoticeDetailVO noticeDTO = noticeDao.detail(id);
|
||||
return ResponseDTO.succData(noticeDTO);
|
||||
return ResponseDTO.ok(noticeDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -160,11 +160,11 @@ public class NoticeService {
|
||||
public ResponseDTO<NoticeDetailVO> send(Long id, Long employeeId) {
|
||||
NoticeEntity entity = noticeDao.selectById(id);
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
|
||||
}
|
||||
noticeManage.send(entity, employeeId);
|
||||
this.sendMessage(employeeId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -206,10 +206,10 @@ public class NoticeService {
|
||||
|
||||
NoticeReceiveRecordEntity recordEntity = noticeReceiveRecordDao.selectByEmployeeAndNotice(employeeId, id);
|
||||
if (recordEntity != null) {
|
||||
return ResponseDTO.succData(noticeDTO);
|
||||
return ResponseDTO.ok(noticeDTO);
|
||||
}
|
||||
noticeManage.saveReadRecord(id, employeeId);
|
||||
this.sendMessage(employeeId);
|
||||
return ResponseDTO.succData(noticeDTO);
|
||||
return ResponseDTO.ok(noticeDTO);
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,8 @@ package net.lab1024.smartadmin.service.module.support.captcha;
|
||||
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.EmployeeResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.RedisKeyConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
@ -51,7 +51,7 @@ public class CaptchaService {
|
||||
base64Code = Base64Utils.encodeToString(os.toByteArray());
|
||||
} catch (Exception e) {
|
||||
log.error("verificationCode exception:", e);
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "generate captcha error" );
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "generate captcha error" );
|
||||
}
|
||||
// uuid 唯一标识
|
||||
String uuid = UUID.randomUUID().toString().replace("-", CommonConst.EMPTY_STR);
|
||||
@ -65,7 +65,7 @@ public class CaptchaService {
|
||||
captchaVO.setCaptchaId(uuid);
|
||||
captchaVO.setCaptchaImg("data:image/png;base64," + base64Code);
|
||||
redisService.set(buildCaptchaRedisKey(uuid), captchaText, 80L);
|
||||
return ResponseDTO.succData(captchaVO);
|
||||
return ResponseDTO.ok(captchaVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,19 +77,19 @@ public class CaptchaService {
|
||||
*/
|
||||
public ResponseDTO<String> checkCaptcha(String captchaId, String captcha) {
|
||||
if (StringUtils.isBlank(captchaId) || StringUtils.isBlank(captcha)) {
|
||||
return ResponseDTO.wrapMsg(EmployeeResponseCodeConst.ERROR_PARAM, "请输入正确验证码" );
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请输入正确验证码" );
|
||||
}
|
||||
String redisKey = buildCaptchaRedisKey(captchaId);
|
||||
String redisCode = redisService.get(redisKey);
|
||||
if (StringUtils.isBlank(redisCode)) {
|
||||
return ResponseDTO.wrapMsg(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
|
||||
return ResponseDTO.error(UserErrorCode.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
|
||||
}
|
||||
if (!Objects.equals(redisCode, captcha)) {
|
||||
return ResponseDTO.wrapMsg(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
|
||||
return ResponseDTO.error(UserErrorCode.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
|
||||
}
|
||||
// 校验通过 移除
|
||||
redisService.del(redisKey);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
private String buildCaptchaRedisKey(String codeId) {
|
||||
|
@ -111,6 +111,6 @@ public class DataTracerService {
|
||||
Page page = SmartPageUtil.convert2PageQuery(queryForm);
|
||||
List<DataTracerVO> list = dataTracerDao.query(page, queryForm);
|
||||
PageResultDTO<DataTracerVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
|
||||
return ResponseDTO.succData(pageResult);
|
||||
return ResponseDTO.ok(pageResult);
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package net.lab1024.smartadmin.service.module.support.file.service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.FileResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.NumberLimitConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.RedisKeyConst;
|
||||
@ -78,7 +78,7 @@ public class FileService {
|
||||
MockMultipartFile file = new MockMultipartFile(fileKey, fileKey, contentType, urlConnection.getInputStream());
|
||||
return this.fileUpload(file, urlUploadDTO.getFolder(), urlUploadDTO.getUserId(), urlUploadDTO.getUserName());
|
||||
} catch (IOException e) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,26 +92,26 @@ public class FileService {
|
||||
public ResponseDTO<FileUploadVO> fileUpload(MultipartFile file, Integer folderType, Long userId, String userName) {
|
||||
FileFolderTypeEnum folderTypeEnum = SmartBaseEnumUtil.getEnumByValue(folderType, FileFolderTypeEnum.class);
|
||||
if (null == folderTypeEnum) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_MODULE_ERROR);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "文件夹错误");
|
||||
}
|
||||
if (null == file || file.getSize() == 0) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_EMPTY);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件不能为空");
|
||||
}
|
||||
// 校验文件名称
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (StringUtils.isBlank(originalFilename) || originalFilename.length() > NumberLimitConst.FILE_NAME) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NAME_ERROR);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件名称不能为空");
|
||||
}
|
||||
// 校验文件大小
|
||||
String maxSizeStr = maxFileSize.toLowerCase().replace("mb", "");
|
||||
long maxSize = Integer.parseInt(maxSizeStr) * 1024 * 1024L;
|
||||
if (file.getSize() > maxSize) {
|
||||
return ResponseDTO.wrapMsg(FileResponseCodeConst.FILE_SIZE_ERROR, String.format(FileResponseCodeConst.FILE_SIZE_ERROR.getMsg(), maxSize));
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件最大:" + maxSize);
|
||||
}
|
||||
// 获取文件服务
|
||||
ResponseDTO<FileUploadVO> response = fileStorageService.fileUpload(file, folderTypeEnum.getFolder());
|
||||
|
||||
if (response.isSuccess()) {
|
||||
if (response.getOk()) {
|
||||
// 上传成功 保存记录数据库
|
||||
FileUploadVO uploadVO = response.getData();
|
||||
|
||||
@ -174,13 +174,13 @@ public class FileService {
|
||||
*/
|
||||
public ResponseDTO<String> getFileUrl(String fileKey) {
|
||||
if (StringUtils.isBlank(fileKey)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
|
||||
}
|
||||
// 处理逗号分隔的字符串
|
||||
List<String> stringList = Arrays.asList(fileKey.split(CommonConst.SEPARATOR));
|
||||
stringList = stringList.stream().map(e -> this.getCacheUrl(e)).collect(Collectors.toList());
|
||||
String result = StringUtils.join(stringList, CommonConst.SEPARATOR_CHAR);
|
||||
return ResponseDTO.succData(result);
|
||||
return ResponseDTO.ok(result);
|
||||
}
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ public class FileService {
|
||||
return fileUrl;
|
||||
}
|
||||
ResponseDTO<String> responseDTO = fileStorageService.getFileUrl(fileKey);
|
||||
if (!responseDTO.isSuccess()) {
|
||||
if (!responseDTO.getOk()) {
|
||||
return null;
|
||||
}
|
||||
fileUrl = responseDTO.getData();
|
||||
@ -218,7 +218,7 @@ public class FileService {
|
||||
return new FileUrlResultDTO(fileKey, result);
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return ResponseDTO.succData(resultDTOList);
|
||||
return ResponseDTO.ok(resultDTOList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -237,7 +237,7 @@ public class FileService {
|
||||
});
|
||||
}
|
||||
PageResultDTO<FileVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, fileList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +250,7 @@ public class FileService {
|
||||
public ResponseEntity<Object> downloadByFileKey(String fileKey, String userAgent) {
|
||||
// 根据文件服务类 获取对应文件服务 查询 url
|
||||
ResponseDTO<FileDownloadDTO> responseDTO = fileStorageService.fileDownload(fileKey);
|
||||
if (!responseDTO.isSuccess()) {
|
||||
if (!responseDTO.getOk()) {
|
||||
HttpHeaders heads = new HttpHeaders();
|
||||
heads.add(HttpHeaders.CONTENT_TYPE, "text/html;charset=UTF-8");
|
||||
return new ResponseEntity<>(responseDTO.getMsg() + ":" + fileKey, heads, HttpStatus.OK);
|
||||
@ -295,13 +295,13 @@ public class FileService {
|
||||
*/
|
||||
public ResponseDTO<String> deleteByFileKey(String fileKey) {
|
||||
if (StringUtils.isBlank(fileKey)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
|
||||
}
|
||||
FileEntity fileEntity = new FileEntity();
|
||||
fileEntity.setFileKey(fileKey);
|
||||
fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity));
|
||||
if (null == fileEntity) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
// 根据文件服务类 获取对应文件服务 删除文件
|
||||
return fileStorageService.delete(fileKey);
|
||||
@ -315,14 +315,14 @@ public class FileService {
|
||||
*/
|
||||
public ResponseDTO<FileMetadataDTO> queryFileMetadata(String fileKey) {
|
||||
if (StringUtils.isBlank(fileKey)) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
// 查询数据库文件记录
|
||||
FileEntity fileEntity = new FileEntity();
|
||||
fileEntity.setFileKey(fileKey);
|
||||
fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity));
|
||||
if (null == fileEntity) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 返回 meta
|
||||
@ -330,6 +330,6 @@ public class FileService {
|
||||
metadataDTO.setFileSize(fileEntity.getFileSize());
|
||||
metadataDTO.setFileName(fileEntity.getFileName());
|
||||
metadataDTO.setFileFormat(fileEntity.getFileType());
|
||||
return ResponseDTO.succData(metadataDTO);
|
||||
return ResponseDTO.ok(metadataDTO);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,8 @@ import com.amazonaws.services.s3.model.CannedAccessControlList;
|
||||
import com.amazonaws.services.s3.model.ObjectMetadata;
|
||||
import com.amazonaws.services.s3.model.S3Object;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.FileResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.config.FileCloudConfig;
|
||||
import net.lab1024.smartadmin.service.module.support.file.domain.FileFolderTypeEnum;
|
||||
@ -74,7 +73,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
urlEncoderFilename = URLEncoder.encode(originalFilename, StandardCharsets.UTF_8.name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("阿里云文件上传服务URL ENCODE-发生异常:", e);
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"上传失败");
|
||||
}
|
||||
ObjectMetadata meta = new ObjectMetadata();
|
||||
meta.setContentEncoding(StandardCharsets.UTF_8.name());
|
||||
@ -90,7 +89,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
amazonS3.putObject(cloudConfig.getBucketName(), fileKey, file.getInputStream(), meta);
|
||||
} catch (IOException e) {
|
||||
log.error("文件上传-发生异常:", e);
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"上传失败");
|
||||
}
|
||||
// 根据文件路径获取并设置访问权限
|
||||
CannedAccessControlList acl = this.getACL(path);
|
||||
@ -108,7 +107,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
uploadVO.setFileUrl(url);
|
||||
uploadVO.setFileKey(fileKey);
|
||||
uploadVO.setFileSize(file.getSize());
|
||||
return ResponseDTO.succData(uploadVO);
|
||||
return ResponseDTO.ok(uploadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,16 +119,16 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
@Override
|
||||
public ResponseDTO<String> getFileUrl(String fileKey) {
|
||||
if (StringUtils.isBlank(fileKey)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
|
||||
}
|
||||
if (!fileKey.startsWith(FileFolderTypeEnum.FOLDER_PRIVATE)) {
|
||||
// 不是私有的 都公共读
|
||||
return ResponseDTO.succData(cloudConfig.getPublicUrl() + fileKey);
|
||||
return ResponseDTO.ok(cloudConfig.getPublicUrl() + fileKey);
|
||||
}
|
||||
Date expiration = new Date(System.currentTimeMillis() + cloudConfig.getUrlExpire());
|
||||
URL url = amazonS3.generatePresignedUrl(cloudConfig.getBucketName(), fileKey, expiration);
|
||||
String urlStr = url.toString().replace("http://", "https://");
|
||||
return ResponseDTO.succData(urlStr);
|
||||
return ResponseDTO.ok(urlStr);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,10 +160,10 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
FileDownloadDTO fileDownloadDTO = new FileDownloadDTO();
|
||||
fileDownloadDTO.setData(buffer);
|
||||
fileDownloadDTO.setMetadata(metadataDTO);
|
||||
return ResponseDTO.succData(fileDownloadDTO);
|
||||
return ResponseDTO.ok(fileDownloadDTO);
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载-发生异常:", e);
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.DOWNLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"下载失败");
|
||||
} finally {
|
||||
try {
|
||||
// 关闭输入流
|
||||
@ -202,7 +201,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
||||
@Override
|
||||
public ResponseDTO<String> delete(String fileKey) {
|
||||
amazonS3.deleteObject(cloudConfig.getBucketName(), fileKey);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
package net.lab1024.smartadmin.service.module.support.file.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.FileResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.support.file.domain.dto.FileDownloadDTO;
|
||||
import net.lab1024.smartadmin.service.module.support.file.domain.vo.FileUploadVO;
|
||||
@ -32,13 +33,14 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||
|
||||
@Value("${file.storage.local.path}")
|
||||
private String localPath;
|
||||
|
||||
@Autowired
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Override
|
||||
public ResponseDTO<FileUploadVO> fileUpload(MultipartFile multipartFile, String path) {
|
||||
if (null == multipartFile) {
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.FILE_EMPTY);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件不能为空");
|
||||
}
|
||||
String filePath = localPath + path;
|
||||
File directory = new File(filePath);
|
||||
@ -70,9 +72,9 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||
fileTemp.delete();
|
||||
}
|
||||
log.error("", e);
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
||||
}
|
||||
return ResponseDTO.succData(fileUploadVO);
|
||||
return ResponseDTO.ok(fileUploadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -89,17 +91,19 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||
|
||||
/**
|
||||
* 获取文件Url
|
||||
*
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ResponseDTO<String> getFileUrl(String fileKey) {
|
||||
String fileUrl = this.generateFileUrl(fileKey);
|
||||
return ResponseDTO.succData(fileUrl);
|
||||
return ResponseDTO.ok(fileUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件下载
|
||||
*
|
||||
* @param fileKey
|
||||
* @return
|
||||
*/
|
||||
@ -114,10 +118,10 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||
byte[] buffer = FileCopyUtils.copyToByteArray(in);
|
||||
FileDownloadDTO fileDownloadDTO = new FileDownloadDTO();
|
||||
fileDownloadDTO.setData(buffer);
|
||||
return ResponseDTO.succData(fileDownloadDTO);
|
||||
return ResponseDTO.ok(fileDownloadDTO);
|
||||
} catch (IOException e) {
|
||||
log.error("文件下载-发生异常:", e);
|
||||
return ResponseDTO.wrap(FileResponseCodeConst.DOWNLOAD_ERROR);
|
||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "文件下载失败");
|
||||
} finally {
|
||||
try {
|
||||
// 关闭输入流
|
||||
@ -139,6 +143,6 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||
} catch (IOException e) {
|
||||
log.error("删除本地文件失败:{}", e);
|
||||
}
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,6 @@ public class HeartBeatService {
|
||||
Page pageQueryInfo = SmartPageUtil.convert2PageQuery(pageBaseDTO);
|
||||
List<HeartBeatRecordVO> recordVOList = heartBeatRecordDao.pageQuery(pageQueryInfo);
|
||||
PageResultDTO<HeartBeatRecordVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageQueryInfo, recordVOList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package net.lab1024.smartadmin.service.module.support.idgenerator;
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.swagger.SwaggerTagConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.common.controller.SupportBaseController;
|
||||
import net.lab1024.smartadmin.service.module.support.idgenerator.constant.IdGeneratorEnum;
|
||||
import net.lab1024.smartadmin.service.util.SmartBaseEnumUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.controller.SupportBaseController;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.common.swagger.SwaggerTagConst;
|
||||
import net.lab1024.smartadmin.service.module.support.idgenerator.constant.IdGeneratorEnum;
|
||||
import net.lab1024.smartadmin.service.util.SmartBaseEnumUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -31,7 +31,7 @@ public class IdGeneratorController extends SupportBaseController {
|
||||
public ResponseDTO<String> generate(@PathVariable Integer generatorId) {
|
||||
IdGeneratorEnum idGeneratorEnum = SmartBaseEnumUtil.getEnumByValue(generatorId, IdGeneratorEnum.class);
|
||||
if (null == idGeneratorEnum) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "IdGenerator,不存在" + generatorId);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "IdGenerator,不存在" + generatorId);
|
||||
}
|
||||
return idGeneratorService.generate(idGeneratorEnum);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.lab1024.smartadmin.service.module.support.idgenerator;
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.code.UnexpectedErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.RedisKeyConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.support.idgenerator.constant.IdGeneratorEnum;
|
||||
@ -9,7 +11,6 @@ import net.lab1024.smartadmin.service.module.support.idgenerator.domain.IdGenera
|
||||
import net.lab1024.smartadmin.service.module.support.idgenerator.domain.IdGeneratorRecordDTO;
|
||||
import net.lab1024.smartadmin.service.third.SmartRedisService;
|
||||
import net.lab1024.smartadmin.service.util.SmartRandomUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -61,7 +62,7 @@ public class IdGeneratorService {
|
||||
int generatorId = idGeneratorEnum.getValue();
|
||||
IdGeneratorEntity idGeneratorEntity = this.idGeneratorMap.get(generatorId);
|
||||
if (null == idGeneratorEntity) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "IdGenerator, 生成器 不存在" + generatorId);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "IdGenerator, 生成器 不存在" + generatorId);
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
@ -88,7 +89,7 @@ public class IdGeneratorService {
|
||||
}
|
||||
|
||||
if (!lock) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.BUSINESS_HANDING);
|
||||
return ResponseDTO.error(UnexpectedErrorCode.BUSINESS_HANDING);
|
||||
}
|
||||
|
||||
long beginTime = System.currentTimeMillis();
|
||||
@ -127,7 +128,7 @@ public class IdGeneratorService {
|
||||
String prefix = StringUtils.isBlank(idGeneratorEntity.getPrefix()) ? StringUtils.EMPTY : idGeneratorEntity.getPrefix();
|
||||
|
||||
lastSleepMilliSeconds = System.currentTimeMillis() - beginTime + 100;
|
||||
return ResponseDTO.succData(prefix + nowFormat + finalId);
|
||||
return ResponseDTO.ok(prefix + nowFormat + finalId);
|
||||
} catch (Throwable e) {
|
||||
log.error(e.getMessage(), e);
|
||||
throw e;
|
||||
|
@ -34,7 +34,7 @@ public class OperateLogService {
|
||||
Page page = SmartPageUtil.convert2PageQuery(queryDTO);
|
||||
List<OperateLogEntity> logEntityList = operateLogDao.queryByPage(page, queryDTO);
|
||||
PageResultDTO<OperateLogDTO> pageResultDTO = SmartPageUtil.convert2PageResult(page, logEntityList, OperateLogDTO.class);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +45,7 @@ public class OperateLogService {
|
||||
public ResponseDTO<String> add(OperateLogDTO addDTO) {
|
||||
OperateLogEntity entity = SmartBeanUtil.copy(addDTO, OperateLogEntity.class);
|
||||
operateLogDao.insert(entity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,7 +57,7 @@ public class OperateLogService {
|
||||
public ResponseDTO<String> update(OperateLogDTO updateDTO) {
|
||||
OperateLogEntity entity = SmartBeanUtil.copy(updateDTO, OperateLogEntity.class);
|
||||
operateLogDao.updateById(entity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ public class OperateLogService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> delete(Long id) {
|
||||
operateLogDao.deleteById(id);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,6 +79,6 @@ public class OperateLogService {
|
||||
public ResponseDTO<OperateLogDTO> detail(Long id) {
|
||||
OperateLogEntity entity = operateLogDao.selectById(id);
|
||||
OperateLogDTO dto = SmartBeanUtil.copy(entity, OperateLogDTO.class);
|
||||
return ResponseDTO.succData(dto);
|
||||
return ResponseDTO.ok(dto);
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,12 @@ package net.lab1024.smartadmin.service.module.support.repeatsubmit;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
@ -71,7 +70,7 @@ public class SmartRepeatSubmitAspect {
|
||||
int interval = Math.min(annotation.value(), RepeatSubmit.MAX_INTERVAL);
|
||||
if (System.currentTimeMillis() < (long) value + interval) {
|
||||
// 提交频繁
|
||||
return ResponseDTO.wrap(ResponseCodeConst.REPEAT_SUBMIT);
|
||||
return ResponseDTO.error(UserErrorCode.REPEAT_SUBMIT);
|
||||
}
|
||||
}
|
||||
cache.put(key, System.currentTimeMillis());
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.system.datascope.service;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.system.datascope.DataScopeRoleDao;
|
||||
import net.lab1024.smartadmin.service.module.system.datascope.constant.DataScopeTypeEnum;
|
||||
@ -40,7 +40,7 @@ public class DataScopeService {
|
||||
dataScopeAndTypeList.forEach(e -> {
|
||||
e.setViewTypeList(typeList);
|
||||
});
|
||||
return ResponseDTO.succData(dataScopeAndTypeList);
|
||||
return ResponseDTO.ok(dataScopeAndTypeList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,10 +85,10 @@ public class DataScopeService {
|
||||
|
||||
List<DataScopeRoleEntity> dataScopeRoleEntityList = dataScopeRoleDao.listByRoleId(roleId);
|
||||
if (CollectionUtils.isEmpty(dataScopeRoleEntityList)) {
|
||||
return ResponseDTO.succData(Lists.newArrayList());
|
||||
return ResponseDTO.ok(Lists.newArrayList());
|
||||
}
|
||||
List<DataScopeSelectVO> dataScopeSelects = SmartBeanUtil.copyList(dataScopeRoleEntityList, DataScopeSelectVO.class);
|
||||
return ResponseDTO.succData(dataScopeSelects);
|
||||
return ResponseDTO.ok(dataScopeSelects);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,13 +101,13 @@ public class DataScopeService {
|
||||
public ResponseDTO<String> dataScopeBatchSet(DataScopeBatchSetRoleDTO batchSetRoleDTO) {
|
||||
List<DataScopeBatchSetDTO> batchSetList = batchSetRoleDTO.getBatchSetList();
|
||||
if (CollectionUtils.isEmpty(batchSetList)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "缺少配置信息");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "缺少配置信息");
|
||||
}
|
||||
List<DataScopeRoleEntity> dataScopeRoleEntityList = SmartBeanUtil.copyList(batchSetList, DataScopeRoleEntity.class);
|
||||
dataScopeRoleEntityList.forEach(e -> e.setRoleId(batchSetRoleDTO.getRoleId()));
|
||||
dataScopeRoleDao.deleteByRoleId(batchSetRoleDTO.getRoleId());
|
||||
dataScopeRoleDao.batchInsert(dataScopeRoleEntityList);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.lab1024.smartadmin.service.module.system.department;
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CacheModuleConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
@ -56,7 +56,7 @@ public class DepartmentService {
|
||||
public ResponseDTO<List<DepartmentTreeVO>> departmentTree() {
|
||||
String cacheKey = CacheKey.cacheKey(CacheModuleConst.Department.DEPARTMENT_TREE_CACHE);
|
||||
List<DepartmentTreeVO> treeVOList = beanCache.get(cacheKey);
|
||||
return ResponseDTO.succData(treeVOList);
|
||||
return ResponseDTO.ok(treeVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,18 +79,18 @@ public class DepartmentService {
|
||||
String cacheKey = CacheKey.cacheKey(CacheModuleConst.Department.DEPARTMENT_TREE_CACHE);
|
||||
List<DepartmentTreeVO> treeVOList = beanCache.get(cacheKey);
|
||||
if (CollectionUtils.isEmpty(treeVOList)) {
|
||||
return ResponseDTO.succData(Lists.newArrayList());
|
||||
return ResponseDTO.ok(Lists.newArrayList());
|
||||
}
|
||||
// 获取全部员工列表
|
||||
List<EmployeeDTO> employeeList = employeeDao.listAll();
|
||||
if (CollectionUtils.isEmpty(employeeList)) {
|
||||
return ResponseDTO.succData(SmartBeanUtil.copyList(treeVOList, DepartmentEmployeeTreeVO.class));
|
||||
return ResponseDTO.ok(SmartBeanUtil.copyList(treeVOList, DepartmentEmployeeTreeVO.class));
|
||||
}
|
||||
Map<Long, List<EmployeeDTO>> employeeMap = employeeList.stream().collect(Collectors.groupingBy(EmployeeDTO::getDepartmentId));
|
||||
//构建各部门的员工信息
|
||||
List<DepartmentEmployeeTreeVO> departmentEmployeeTreeVOList = this.buildTreeEmployee(treeVOList, employeeMap);
|
||||
|
||||
return ResponseDTO.succData(departmentEmployeeTreeVOList);
|
||||
return ResponseDTO.ok(departmentEmployeeTreeVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +130,7 @@ public class DepartmentService {
|
||||
departmentVOList = this.filterDepartment(departmentVOList, departmentName);
|
||||
}
|
||||
List<DepartmentTreeVO> result = departmentTreeService.buildTree(departmentVOList);
|
||||
return ResponseDTO.succData(result);
|
||||
return ResponseDTO.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -194,7 +194,7 @@ public class DepartmentService {
|
||||
departmentService.addDepartmentHandle(departmentEntity);
|
||||
this.clearTreeCache();
|
||||
this.clearSelfAndChildrenIdCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,17 +219,17 @@ public class DepartmentService {
|
||||
*/
|
||||
public ResponseDTO<String> updateDepartment(DepartmentUpdateDTO updateDTO) {
|
||||
if (updateDTO.getParentId() == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "父级部门id不能为空");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "父级部门id不能为空");
|
||||
}
|
||||
DepartmentEntity entity = departmentDao.selectById(updateDTO.getId());
|
||||
if (entity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentEntity departmentEntity = SmartBeanUtil.copy(updateDTO, DepartmentEntity.class);
|
||||
departmentEntity.setSort(entity.getSort());
|
||||
departmentDao.updateById(departmentEntity);
|
||||
this.clearTreeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -243,24 +243,24 @@ public class DepartmentService {
|
||||
public ResponseDTO<String> delDepartment(Long deptId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(deptId);
|
||||
if (null == departmentEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
// 是否有子级部门
|
||||
int subDepartmentNum = departmentDao.countSubDepartment(deptId);
|
||||
if (subDepartmentNum > 0) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "请先删除子级部门");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请先删除子级部门");
|
||||
}
|
||||
|
||||
// 是否有未删除员工
|
||||
int employeeNum = employeeDao.countByDepartmentId(deptId, false);
|
||||
if (employeeNum > 0) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "请先删除部门员工");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请先删除部门员工");
|
||||
}
|
||||
departmentDao.deleteById(deptId);
|
||||
// 清除缓存
|
||||
this.clearTreeCache();
|
||||
this.clearSelfAndChildrenIdCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -272,10 +272,10 @@ public class DepartmentService {
|
||||
public ResponseDTO<DepartmentVO> getDepartmentById(Long departmentId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
if (departmentEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentVO departmentVO = SmartBeanUtil.copy(departmentEntity, DepartmentVO.class);
|
||||
return ResponseDTO.succData(departmentVO);
|
||||
return ResponseDTO.ok(departmentVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -285,7 +285,7 @@ public class DepartmentService {
|
||||
*/
|
||||
public ResponseDTO<List<DepartmentVO>> listAll() {
|
||||
List<DepartmentVO> departmentVOList = departmentDao.listAll();
|
||||
return ResponseDTO.succData(departmentVOList);
|
||||
return ResponseDTO.ok(departmentVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -298,11 +298,11 @@ public class DepartmentService {
|
||||
public ResponseDTO<String> upOrDown(Long departmentId, Long swapId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
if (departmentEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentEntity swapEntity = departmentDao.selectById(swapId);
|
||||
if (swapEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentEntity updateEntity = new DepartmentEntity();
|
||||
updateEntity.setId(departmentId);
|
||||
@ -315,7 +315,7 @@ public class DepartmentService {
|
||||
departmentService.upOrDownUpdate(updateEntity, swapEntity);
|
||||
//清除缓存
|
||||
this.clearTreeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -339,10 +339,10 @@ public class DepartmentService {
|
||||
public ResponseDTO<String> upgrade(Long departmentId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
if (departmentEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
if (departmentEntity.getParentId() == null || departmentEntity.getParentId().equals(CommonConst.DEFAULT_PARENT_ID)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此部门已经是根节点无法移动");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此部门已经是根节点无法移动");
|
||||
}
|
||||
DepartmentEntity parentEntity = departmentDao.selectById(departmentEntity.getParentId());
|
||||
|
||||
@ -352,7 +352,7 @@ public class DepartmentService {
|
||||
departmentDao.updateById(updateEntity);
|
||||
//清除缓存
|
||||
this.clearTreeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -365,11 +365,11 @@ public class DepartmentService {
|
||||
public ResponseDTO<String> downgrade(Long departmentId, Long preId) {
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
if (departmentEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentEntity preEntity = departmentDao.selectById(preId);
|
||||
if (preEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
DepartmentEntity updateEntity = new DepartmentEntity();
|
||||
updateEntity.setId(departmentId);
|
||||
@ -377,7 +377,7 @@ public class DepartmentService {
|
||||
departmentDao.updateById(updateEntity);
|
||||
//清除缓存
|
||||
this.clearTreeCache();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
|
||||
@ -414,8 +414,8 @@ public class DepartmentService {
|
||||
*/
|
||||
public ResponseDTO<List<DepartmentVO>> querySchoolList() {
|
||||
ResponseDTO<List<DepartmentTreeVO>> res = departmentTree();
|
||||
if (!res.isSuccess()) {
|
||||
return ResponseDTO.wrap(res);
|
||||
if (!res.getOk()) {
|
||||
return ResponseDTO.error(res);
|
||||
}
|
||||
List<DepartmentTreeVO> data = res.getData();
|
||||
// 拿到第二级部门列表
|
||||
@ -426,7 +426,7 @@ public class DepartmentService {
|
||||
resList.addAll(SmartBeanUtil.copyList(children, DepartmentVO.class));
|
||||
}
|
||||
}
|
||||
return ResponseDTO.succData(resList);
|
||||
return ResponseDTO.ok(resList);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,7 +2,7 @@ package net.lab1024.smartadmin.service.module.system.employee;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CacheModuleConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.constant.SystemConst;
|
||||
@ -119,7 +119,7 @@ public class EmployeeService {
|
||||
List<EmployeeVO> employeeList = employeeDao.queryEmployee(pageParam, queryDTO);
|
||||
if (CollectionUtils.isEmpty(employeeList)) {
|
||||
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageParam, employeeList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
// 查询员工角色
|
||||
List<Long> employeeIdList = employeeList.stream().map(EmployeeVO::getId).collect(Collectors.toList());
|
||||
@ -130,7 +130,7 @@ public class EmployeeService {
|
||||
e.setRoleIdList(employeeRoleIdListMap.getOrDefault(e.getId(), Lists.newArrayList()));
|
||||
});
|
||||
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageParam, employeeList);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,18 +143,18 @@ public class EmployeeService {
|
||||
// 校验名称是否重复
|
||||
EmployeeDTO employeeDTO = employeeDao.getByLoginName(addDTO.getLoginName(), false, false);
|
||||
if (null != employeeDTO) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "员工名称重复");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "员工名称重复");
|
||||
}
|
||||
// 校验电话是否存在
|
||||
employeeDTO = employeeDao.getByPhone(addDTO.getPhone(), false);
|
||||
if (null != employeeDTO) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "手机号已存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "手机号已存在");
|
||||
}
|
||||
// 部门是否存在
|
||||
Long departmentId = addDTO.getDepartmentId();
|
||||
DepartmentEntity department = departmentDao.selectById(departmentId);
|
||||
if (department == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "部门不存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "部门不存在");
|
||||
}
|
||||
|
||||
EmployeeEntity entity = SmartBeanUtil.copy(addDTO, EmployeeEntity.class);
|
||||
@ -166,7 +166,7 @@ public class EmployeeService {
|
||||
|
||||
this.clearCacheByDepartmentId(departmentId);
|
||||
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,20 +179,20 @@ public class EmployeeService {
|
||||
Long employeeId = updateDTO.getId();
|
||||
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
|
||||
if (null == employeeEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
Long departmentId = updateDTO.getDepartmentId();
|
||||
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
|
||||
if (departmentEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
EmployeeDTO employeeDTO = employeeDao.getByLoginName(updateDTO.getLoginName(), false, false);
|
||||
if (null != employeeDTO && !Objects.equals(employeeDTO.getId(), employeeId)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ALREADY_EXIST);
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST);
|
||||
}
|
||||
employeeDTO = employeeDao.getByPhone(updateDTO.getLoginName(), false);
|
||||
if (null != employeeDTO && !Objects.equals(employeeDTO.getId(), employeeId)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 不更新密码
|
||||
@ -206,7 +206,7 @@ public class EmployeeService {
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
this.clearCacheByDepartmentId(departmentId);
|
||||
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -217,18 +217,18 @@ public class EmployeeService {
|
||||
*/
|
||||
public ResponseDTO<String> updateDisableFlag(Long employeeId) {
|
||||
if (null == employeeId) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
|
||||
if (null == employeeEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
employeeDao.updateDisableFlag(employeeId, !employeeEntity.getDisabledFlag());
|
||||
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
this.clearCacheByDepartmentId(employeeEntity.getDepartmentId());
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,7 +241,7 @@ public class EmployeeService {
|
||||
List<Long> employeeIdList = batchUpdateStatusDTO.getEmployeeIdList();
|
||||
List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList);
|
||||
if (employeeIdList.size() != employeeEntityList.size()) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
employeeDao.batchUpdateDisableFlag(employeeIdList, batchUpdateStatusDTO.getDisabledFlag());
|
||||
@ -251,7 +251,7 @@ public class EmployeeService {
|
||||
this.clearCacheByEmployeeId(e.getId());
|
||||
this.clearCacheByDepartmentId(e.getDepartmentId());
|
||||
});
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,11 +262,11 @@ public class EmployeeService {
|
||||
*/
|
||||
public ResponseDTO<String> batchUpdateDeleteFlag(List<Long> employeeIdList) {
|
||||
if (CollectionUtils.isEmpty(employeeIdList)) {
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
List<EmployeeEntity> employeeEntityList = employeeManager.listByIds(employeeIdList);
|
||||
if (CollectionUtils.isEmpty(employeeEntityList)) {
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
List<EmployeeEntity> deleteList = employeeIdList.stream().map(e -> {
|
||||
// 更新删除
|
||||
@ -282,7 +282,7 @@ public class EmployeeService {
|
||||
this.clearCacheByEmployeeId(e.getId());
|
||||
this.clearCacheByDepartmentId(e.getDepartmentId());
|
||||
});
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +294,7 @@ public class EmployeeService {
|
||||
public ResponseDTO<String> deleteEmployeeById(Long employeeId) {
|
||||
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
|
||||
if (null == employeeEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
// 更新删除
|
||||
EmployeeEntity updateEmployee = new EmployeeEntity();
|
||||
@ -304,7 +304,7 @@ public class EmployeeService {
|
||||
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
this.clearCacheByDepartmentId(employeeEntity.getDepartmentId());
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -317,7 +317,7 @@ public class EmployeeService {
|
||||
List<Long> employeeIdList = updateDto.getEmployeeIdList();
|
||||
List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList);
|
||||
if (employeeIdList.size() != employeeEntityList.size()) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
List<EmployeeEntity> updateList = employeeIdList.stream().map(e -> {
|
||||
@ -334,7 +334,7 @@ public class EmployeeService {
|
||||
this.clearCacheByEmployeeId(e.getId());
|
||||
this.clearCacheByDepartmentId(e.getDepartmentId());
|
||||
});
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -357,7 +357,7 @@ public class EmployeeService {
|
||||
|
||||
// 更新数据
|
||||
employeeManager.updateEmployeeRole(employeeId, roleEmployeeList);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -370,18 +370,18 @@ public class EmployeeService {
|
||||
Long employeeId = updatePwdDTO.getEmployeeId();
|
||||
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
|
||||
if (employeeEntity == null) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
// 校验原始密码
|
||||
String encryptPwd = getEncryptPwd(updatePwdDTO.getOldPwd());
|
||||
if (!Objects.equals(encryptPwd, employeeEntity.getLoginPwd())) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 新旧密码相同
|
||||
String newPwd = updatePwdDTO.getPwd();
|
||||
if (Objects.equals(updatePwdDTO.getOldPwd(), newPwd)) {
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
// 更新密码
|
||||
@ -390,7 +390,7 @@ public class EmployeeService {
|
||||
updateEntity.setLoginPwd(getEncryptPwd(newPwd));
|
||||
employeeDao.updateById(updateEntity);
|
||||
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -403,10 +403,10 @@ public class EmployeeService {
|
||||
String cacheKey = CacheKey.cacheKey(CacheModuleConst.Employee.DEPARTMENT_EMPLOYEE_CACHE, departmentId.toString());
|
||||
List<EmployeeEntity> employeeEntityList = beanCache.get(cacheKey);
|
||||
if (CollectionUtils.isEmpty(employeeEntityList)) {
|
||||
return ResponseDTO.succData(CommonConst.EMPTY_LIST);
|
||||
return ResponseDTO.ok(CommonConst.EMPTY_LIST);
|
||||
}
|
||||
List<EmployeeVO> voList = SmartBeanUtil.copyList(employeeEntityList, EmployeeVO.class);
|
||||
return ResponseDTO.succData(voList);
|
||||
return ResponseDTO.ok(voList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -425,7 +425,7 @@ public class EmployeeService {
|
||||
// 进入递归
|
||||
List<EmployeeVO> employeeList = Lists.newArrayList(schoolEmployeeList);
|
||||
recursionFindEmployee(employeeList, departmentList, departmentId);
|
||||
return ResponseDTO.succData(employeeList);
|
||||
return ResponseDTO.ok(employeeList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -457,7 +457,7 @@ public class EmployeeService {
|
||||
public ResponseDTO<String> resetPassword(Integer employeeId) {
|
||||
String md5Password = getEncryptPwd(null);
|
||||
employeeDao.updatePassword(employeeId, md5Password);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -510,6 +510,6 @@ public class EmployeeService {
|
||||
queryDTO.setDisabledFlag(disabledFlag);
|
||||
}
|
||||
List<EmployeeVO> employeeList = employeeDao.queryEmployee(queryDTO);
|
||||
return ResponseDTO.succData(employeeList);
|
||||
return ResponseDTO.ok(employeeList);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class EmployeeLoginController extends AdminBaseController {
|
||||
@ApiOperation("获取登录信息")
|
||||
public ResponseDTO<EmployeeLoginVO> getSession() {
|
||||
EmployeeLoginInfoDTO requestEmployee = SmartEmployeeTokenUtil.getRequestEmployee();
|
||||
return ResponseDTO.succData(employeeLoginService.getSession(requestEmployee));
|
||||
return ResponseDTO.ok(employeeLoginService.getSession(requestEmployee));
|
||||
}
|
||||
|
||||
@GetMapping("/logout")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.system.login;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.EmployeeResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.support.captcha.CaptchaService;
|
||||
@ -63,19 +63,19 @@ public class EmployeeLoginService {
|
||||
CaptchaDTO captcha = loginDTO.getCaptcha();
|
||||
if (null != captcha) {
|
||||
ResponseDTO<String> res = captchaService.checkCaptcha(captcha.getCaptchaId(), captcha.getCaptcha());
|
||||
if (!res.isSuccess()) {
|
||||
return ResponseDTO.wrap(res);
|
||||
if (!res.getOk()) {
|
||||
return ResponseDTO.error(res);
|
||||
}
|
||||
}
|
||||
|
||||
String loginPwd = EmployeeService.getEncryptPwd(loginDTO.getLoginPwd());
|
||||
EmployeeEntity employeeEntity = employeeDao.selectByLoginNameAndPwd(loginDTO.getLoginName(), loginPwd, false);
|
||||
if (null == employeeEntity) {
|
||||
return ResponseDTO.wrap(EmployeeResponseCodeConst.LOGIN_FAILED);
|
||||
return ResponseDTO.error(UserErrorCode.LOGIN_FAILED);
|
||||
}
|
||||
|
||||
if (employeeEntity.getDisabledFlag()) {
|
||||
return ResponseDTO.wrap(EmployeeResponseCodeConst.STATUS_ERROR);
|
||||
return ResponseDTO.error(UserErrorCode.USER_STATUS_ERROR);
|
||||
}
|
||||
|
||||
// 生成 登录token
|
||||
@ -107,7 +107,7 @@ public class EmployeeLoginService {
|
||||
loginResultDTO.setSchoolId(schoolIdByDepartment.getId());
|
||||
loginResultDTO.setSchoolName(schoolIdByDepartment.getName());
|
||||
}
|
||||
return ResponseDTO.succData(loginResultDTO);
|
||||
return ResponseDTO.ok(loginResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -118,7 +118,7 @@ public class EmployeeLoginService {
|
||||
*/
|
||||
public ResponseDTO<String> logoutByToken(Long employeeId) {
|
||||
employeeService.clearCacheByEmployeeId(employeeId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,7 +48,7 @@ public class MenuController extends AdminBaseController {
|
||||
@ApiOperation(value = "查询菜单列表")
|
||||
@GetMapping("/menu/query")
|
||||
public ResponseDTO<List<MenuVO>> queryMenuList() {
|
||||
return ResponseDTO.succData(menuService.queryMenuList(null));
|
||||
return ResponseDTO.ok(menuService.queryMenuList(null));
|
||||
}
|
||||
|
||||
@ApiOperation(value = "查询菜单详情")
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.system.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.system.menu.constant.MenuTypeEnum;
|
||||
@ -47,7 +47,7 @@ public class MenuService {
|
||||
public ResponseDTO<String> addMenu(MenuAddForm menuAddForm) {
|
||||
// 校验菜单名称
|
||||
if (this.validateMenuName(menuAddForm)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单名称已存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单名称已存在");
|
||||
}
|
||||
MenuEntity menuEntity = SmartBeanUtil.copy(menuAddForm, MenuEntity.class);
|
||||
// 处理接口权限
|
||||
@ -62,17 +62,17 @@ public class MenuService {
|
||||
menuDao.insert(menuEntity);
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
// 若功能点列表不为空
|
||||
ResponseDTO<List<MenuEntity>> responseDTO = this.validateBuildPointList(menuAddForm.getMenuType(), pointList);
|
||||
if (!responseDTO.isSuccess()) {
|
||||
return ResponseDTO.wrap(responseDTO);
|
||||
if (!responseDTO.getOk()) {
|
||||
return ResponseDTO.error(responseDTO);
|
||||
}
|
||||
menuManager.addMenu(menuEntity, responseDTO.getData());
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,17 +85,17 @@ public class MenuService {
|
||||
//校验菜单是否存在
|
||||
MenuEntity selectMenu = menuDao.selectById(menuUpdateForm.getMenuId());
|
||||
if (selectMenu == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单不存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单不存在");
|
||||
}
|
||||
if (selectMenu.getDeleteFlag()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单已被删除");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单已被删除");
|
||||
}
|
||||
//校验菜单名称
|
||||
if (this.validateMenuName(menuUpdateForm)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单名称已存在");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单名称已存在");
|
||||
}
|
||||
if (menuUpdateForm.getMenuId().equals(menuUpdateForm.getParentId())) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "上级菜单不能为自己");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上级菜单不能为自己");
|
||||
}
|
||||
MenuEntity menuEntity = SmartBeanUtil.copy(menuUpdateForm, MenuEntity.class);
|
||||
// 处理接口权限
|
||||
@ -110,12 +110,12 @@ public class MenuService {
|
||||
menuDao.updateById(menuEntity);
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
//若功能点列表不为空
|
||||
ResponseDTO<List<MenuEntity>> validateBuildPointList = this.validateBuildPointList(menuUpdateForm.getMenuType(), pointList);
|
||||
if (!validateBuildPointList.isSuccess()) {
|
||||
return ResponseDTO.wrap(validateBuildPointList);
|
||||
if (!validateBuildPointList.getOk()) {
|
||||
return ResponseDTO.error(validateBuildPointList);
|
||||
}
|
||||
List<MenuEntity> pointEntityList = validateBuildPointList.getData();
|
||||
//查询当前菜单下的功能点列表
|
||||
@ -151,7 +151,7 @@ public class MenuService {
|
||||
menuManager.updateMenu(menuEntity, savePointList, deletePointList, updatePointList);
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,7 +164,7 @@ public class MenuService {
|
||||
private ResponseDTO<List<MenuEntity>> validateBuildPointList(Integer menuType, List<MenuPointsOperateForm> pointList) {
|
||||
//判断 目录/功能点不能添加功能点
|
||||
if (!MenuTypeEnum.MENU.equalsValue(menuType)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "目录/功能点不能添加子功能点");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "目录/功能点不能添加子功能点");
|
||||
}
|
||||
//构建功能点对象
|
||||
List<MenuEntity> pointEntityList = pointList.stream().map(e -> {
|
||||
@ -181,9 +181,9 @@ public class MenuService {
|
||||
Map<String, Long> nameGroupBy = pointEntityList.stream().collect(Collectors.groupingBy(MenuEntity::getMenuName, Collectors.counting()));
|
||||
List<String> repeatName = nameGroupBy.entrySet().stream().filter(e -> e.getValue() > 1).map(e -> e.getKey()).collect(Collectors.toList());
|
||||
if (!CollectionUtils.isEmpty(repeatName)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "功能点:" + String.join("、", repeatName) + ",名称重复");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "功能点:" + String.join("、", repeatName) + ",名称重复");
|
||||
}
|
||||
return ResponseDTO.succData(pointEntityList);
|
||||
return ResponseDTO.ok(pointEntityList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -195,12 +195,12 @@ public class MenuService {
|
||||
*/
|
||||
public ResponseDTO<String> batchDeleteMenu(List<Long> menuIdList, Long employeeId) {
|
||||
if (CollectionUtils.isEmpty(menuIdList)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "所选菜单不能为空");
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "所选菜单不能为空");
|
||||
}
|
||||
menuDao.deleteByMenuIdList(menuIdList, employeeId, Boolean.TRUE);
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -276,7 +276,7 @@ public class MenuService {
|
||||
//根据ParentId进行分组
|
||||
Map<Long, List<MenuVO>> parentMap = menuVOList.stream().collect(Collectors.groupingBy(MenuVO::getParentId, Collectors.toList()));
|
||||
List<MenuTreeVO> menuTreeVOList = this.buildMenuTree(parentMap, CommonConst.DEFAULT_PARENT_ID);
|
||||
return ResponseDTO.succData(menuTreeVOList);
|
||||
return ResponseDTO.ok(menuTreeVOList);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -311,10 +311,10 @@ public class MenuService {
|
||||
//校验菜单是否存在
|
||||
MenuEntity selectMenu = menuDao.selectById(menuId);
|
||||
if (selectMenu == null) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "菜单不存在");
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "菜单不存在");
|
||||
}
|
||||
if (selectMenu.getDeleteFlag()) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "菜单已被删除");
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "菜单已被删除");
|
||||
}
|
||||
MenuVO menuVO = SmartBeanUtil.copy(selectMenu, MenuVO.class);
|
||||
//处理接口权限
|
||||
@ -323,7 +323,7 @@ public class MenuService {
|
||||
List<String> permsList = Lists.newArrayList(StringUtils.split(perms, ","));
|
||||
menuVO.setPermsList(permsList);
|
||||
}
|
||||
return ResponseDTO.succData(menuVO);
|
||||
return ResponseDTO.ok(menuVO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -333,6 +333,6 @@ public class MenuService {
|
||||
*/
|
||||
public ResponseDTO<List<RequestUrlVO>> getPrivilegeUrlDTOList() {
|
||||
List<RequestUrlVO> privilegeUrlList = requestUrlService.getPrivilegeList();
|
||||
return ResponseDTO.succData(privilegeUrlList);
|
||||
return ResponseDTO.ok(privilegeUrlList);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package net.lab1024.smartadmin.service.module.system.role.basic;
|
||||
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.system.role.basic.domain.dto.RoleAddDTO;
|
||||
import net.lab1024.smartadmin.service.module.system.role.basic.domain.dto.RoleUpdateDTO;
|
||||
@ -43,11 +43,11 @@ public class RoleService {
|
||||
public ResponseDTO addRole(RoleAddDTO roleAddDTO) {
|
||||
RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleAddDTO.getRoleName());
|
||||
if (null != employeeRoleEntity) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "角色名称重复");
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "角色名称重复");
|
||||
}
|
||||
RoleEntity roleEntity = SmartBeanUtil.copy(roleAddDTO, RoleEntity.class);
|
||||
roleDao.insert(roleEntity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,12 +60,12 @@ public class RoleService {
|
||||
public ResponseDTO deleteRole(Long roleId) {
|
||||
RoleEntity roleEntity = roleDao.selectById(roleId);
|
||||
if (null == roleEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
roleDao.deleteById(roleId);
|
||||
roleMenuDao.deleteByRoleId(roleId);
|
||||
roleEmployeeDao.deleteByRoleId(roleId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,15 +78,15 @@ public class RoleService {
|
||||
public ResponseDTO<String> updateRole(RoleUpdateDTO roleUpdateDTO) {
|
||||
Long roleId = roleUpdateDTO.getId();
|
||||
if (null == roleDao.selectById(roleId)) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleUpdateDTO.getRoleName());
|
||||
if (null != employeeRoleEntity && !Objects.equals(employeeRoleEntity.getId(), roleId)) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "角色名称重复");
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "角色名称重复");
|
||||
}
|
||||
RoleEntity roleEntity = SmartBeanUtil.copy(roleUpdateDTO, RoleEntity.class);
|
||||
roleDao.updateById(roleEntity);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,10 +98,10 @@ public class RoleService {
|
||||
public ResponseDTO<RoleVO> getRoleById(Long roleId) {
|
||||
RoleEntity roleEntity = roleDao.selectById(roleId);
|
||||
if (null == roleEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
RoleVO role = SmartBeanUtil.copy(roleEntity, RoleVO.class);
|
||||
return ResponseDTO.succData(role);
|
||||
return ResponseDTO.ok(role);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -112,6 +112,6 @@ public class RoleService {
|
||||
public ResponseDTO<List<RoleVO>> getAllRole() {
|
||||
List<RoleEntity> roleEntityList = roleDao.selectList(null);
|
||||
List<RoleVO> roleList = SmartBeanUtil.copyList(roleEntityList, RoleVO.class);
|
||||
return ResponseDTO.succData(roleList);
|
||||
return ResponseDTO.ok(roleList);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.system.role.roleemployee;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CacheModuleConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
@ -65,13 +65,13 @@ public class RoleEmployeeService {
|
||||
employeeDTO.setDepartmentName(departmentEntity.getName());
|
||||
});
|
||||
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, employeeDTOS, EmployeeVO.class);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
public ResponseDTO<List<EmployeeVO>> getAllEmployeeByRoleId(Long roleId) {
|
||||
List<EmployeeDTO> employeeDTOS = roleEmployeeDao.selectEmployeeByRoleId(roleId);
|
||||
List<EmployeeVO> list = SmartBeanUtil.copyList(employeeDTOS, EmployeeVO.class);
|
||||
return ResponseDTO.succData(list);
|
||||
return ResponseDTO.ok(list);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,11 +84,11 @@ public class RoleEmployeeService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResponseDTO<String> removeEmployeeRole(Long employeeId, Long roleId) {
|
||||
if (null == employeeId || null == roleId) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM);
|
||||
return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
|
||||
}
|
||||
roleEmployeeDao.deleteByEmployeeIdRoleId(employeeId, roleId);
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,7 +102,7 @@ public class RoleEmployeeService {
|
||||
for (Long employeeId : removeDTO.getEmployeeIdList()) {
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
}
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +126,7 @@ public class RoleEmployeeService {
|
||||
for (Long employeeId : employeeIdList) {
|
||||
this.clearCacheByEmployeeId(employeeId);
|
||||
}
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,7 +140,7 @@ public class RoleEmployeeService {
|
||||
List<RoleEntity> roleList = roleDao.selectList(null);
|
||||
List<RoleSelectedVO> result = SmartBeanUtil.copyList(roleList, RoleSelectedVO.class);
|
||||
result.stream().forEach(item -> item.setSelected(roleIds.contains(item.getId())));
|
||||
return ResponseDTO.succData(result);
|
||||
return ResponseDTO.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.lab1024.smartadmin.service.module.system.role.rolemenu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.constant.CommonConst;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.system.menu.MenuDao;
|
||||
@ -52,7 +52,7 @@ public class RoleMenuService {
|
||||
Long roleId = updateDTO.getRoleId();
|
||||
RoleEntity roleEntity = roleDao.selectById(roleId);
|
||||
if (null == roleEntity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
List<RoleMenuEntity> roleMenuEntityList = Lists.newArrayList();
|
||||
RoleMenuEntity roleMenuEntity;
|
||||
@ -65,7 +65,7 @@ public class RoleMenuService {
|
||||
roleMenuManager.updateRoleMenu(updateDTO.getRoleId(), roleMenuEntityList);
|
||||
// 更新角色权限缓存
|
||||
menuEmployeeService.initRoleMenuListMap();
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,7 +85,7 @@ public class RoleMenuService {
|
||||
Map<Long, List<MenuVO>> parentMap = menuVOList.stream().collect(Collectors.groupingBy(MenuVO::getParentId, Collectors.toList()));
|
||||
List<MenuSimpleTreeVO> menuTreeList = this.buildMenuTree(parentMap, CommonConst.DEFAULT_PARENT_ID);
|
||||
res.setMenuTreeList(menuTreeList);
|
||||
return ResponseDTO.succData(res);
|
||||
return ResponseDTO.ok(res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ public class SystemConfigController extends SupportBaseController {
|
||||
public ResponseDTO<SystemConfigVO> queryByKey(@RequestParam String configKey) {
|
||||
SystemConfigDTO configDTO = systemConfigService.getConfig(configKey);
|
||||
SystemConfigVO configVO = SmartBeanUtil.copy(configDTO, SystemConfigVO.class);
|
||||
return ResponseDTO.succData(configVO);
|
||||
return ResponseDTO.ok(configVO);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package net.lab1024.smartadmin.service.module.system.systemconfig;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst;
|
||||
import net.lab1024.smartadmin.service.common.code.UserErrorCode;
|
||||
import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
|
||||
import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
|
||||
import net.lab1024.smartadmin.service.module.support.reload.core.anno.SmartReload;
|
||||
@ -85,7 +85,7 @@ public class SystemConfigService {
|
||||
Page page = SmartPageUtil.convert2PageQuery(queryDTO);
|
||||
List<SystemConfigEntity> entityList = systemConfigDao.queryByPage(page, queryDTO);
|
||||
PageResultDTO<SystemConfigVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, entityList, SystemConfigVO.class);
|
||||
return ResponseDTO.succData(pageResultDTO);
|
||||
return ResponseDTO.ok(pageResultDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -146,14 +146,14 @@ public class SystemConfigService {
|
||||
public ResponseDTO<String> add(SystemConfigAddDTO configAddDTO) {
|
||||
SystemConfigEntity entity = systemConfigDao.selectByKey(configAddDTO.getConfigKey());
|
||||
if (null != entity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.ALREADY_EXIST);
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST);
|
||||
}
|
||||
entity = SmartBeanUtil.copy(configAddDTO, SystemConfigEntity.class);
|
||||
systemConfigDao.insert(entity);
|
||||
|
||||
// 刷新缓存
|
||||
this.refreshConfigCache(entity.getConfigId());
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -166,11 +166,11 @@ public class SystemConfigService {
|
||||
Long configId = updateDTO.getConfigId();
|
||||
SystemConfigEntity entity = systemConfigDao.selectById(configId);
|
||||
if (null == entity) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
SystemConfigEntity alreadyEntity = systemConfigDao.selectByKey(updateDTO.getConfigKey());
|
||||
if (null != alreadyEntity && !Objects.equals(configId, alreadyEntity.getConfigId())) {
|
||||
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "config key 已存在");
|
||||
return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "config key 已存在");
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
@ -179,7 +179,7 @@ public class SystemConfigService {
|
||||
|
||||
// 刷新缓存
|
||||
this.refreshConfigCache(configId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -192,7 +192,7 @@ public class SystemConfigService {
|
||||
public ResponseDTO<String> updateValueByKey(SystemConfigKeyEnum key, String value) {
|
||||
SystemConfigDTO config = this.getConfig(key);
|
||||
if (null == config) {
|
||||
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
|
||||
return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
|
||||
}
|
||||
|
||||
// 更新数据
|
||||
@ -204,6 +204,6 @@ public class SystemConfigService {
|
||||
|
||||
// 刷新缓存
|
||||
this.refreshConfigCache(configId);
|
||||
return ResponseDTO.succ();
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user