update error code

This commit is contained in:
Turbolisten 2021-10-01 13:31:26 +08:00
parent da7ef2b641
commit 664309804a
49 changed files with 643 additions and 862 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,9 +3,10 @@ package net.lab1024.smartadmin.service.common.domain;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.Max; import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
@ -22,11 +23,12 @@ public class PageBaseDTO {
@ApiModelProperty(value = "页码(不能为空)", required = true, example = "1") @ApiModelProperty(value = "页码(不能为空)", required = true, example = "1")
@NotNull(message = "分页参数不能为空") @NotNull(message = "分页参数不能为空")
@Min(value = 1, message = "分页参数最小1")
private Integer pageNum; private Integer pageNum;
@ApiModelProperty(value = "每页数量(不能为空)", required = true, example = "10") @ApiModelProperty(value = "每页数量(不能为空)", required = true, example = "10")
@NotNull(message = "每页数量不能为空") @NotNull(message = "每页数量不能为空")
@Max(value = 200, message = "每页最大为200") @Range(min = 1, max = 200, message = "每页数量1-200")
private Integer pageSize; private Integer pageSize;
@ApiModelProperty("排序字段集合") @ApiModelProperty("排序字段集合")

View File

@ -1,150 +1,82 @@
package net.lab1024.smartadmin.service.common.domain; 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 * @author 1024lab
*/ */
@Data
public class ResponseDTO<T> { 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) { private Boolean ok;
this.code = responseCodeConst.getCode();
this.msg = msg;
this.success = responseCodeConst.issucc();
}
public ResponseDTO(ResponseCodeConst responseCodeConst, T data) { private T data;
super();
this.code = responseCodeConst.getCode();
this.msg = responseCodeConst.getMsg();
this.data = data;
this.success = responseCodeConst.issucc();
}
public ResponseDTO(ResponseCodeConst responseCodeConst, T data, String msg) { public ResponseDTO(Integer code, String level, boolean ok, String msg, T data) {
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) {
this.code = code; this.code = code;
this.level = level;
this.ok = ok;
this.msg = msg; 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; this.data = data;
return this;
} }
public boolean isSuccess() { public ResponseDTO(ErrorCode errorCode, boolean ok, String msg, T data) {
return success; 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) { public static <T> ResponseDTO<T> ok() {
this.success = success; return new ResponseDTO<>(OK_CODE, null, true, OK_MSG, null);
} }
@Override public static <T> ResponseDTO<T> ok(T data) {
public String toString() { return new ResponseDTO<>(OK_CODE, null, true, OK_MSG, data);
return "ResponseDTO{" + "code=" + code + ", msg='" + msg + '\'' + ", success=" + success + ", data=" + 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);
}
} }

View File

@ -1,44 +1,27 @@
package net.lab1024.smartadmin.service.common.domain; package net.lab1024.smartadmin.service.common.domain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum; import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum;
/** /**
*
* 系统环境 * 系统环境
* *
* @author zhuoda * @author zhuoda
* @Date 2021/8/13 * @Date 2021/8/13
*/ */
@AllArgsConstructor
@Getter
public class SystemEnvironmentBO { public class SystemEnvironmentBO {
/** /**
* 是否位生产环境 * 是否位生产环境
*/ */
private boolean isProd; private Boolean isProd;
/** /**
* 当前环境 * 当前环境
*/ */
private SystemEnvironmentEnum currentEnvironment; 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;
}
} }

View File

@ -1,6 +1,6 @@
package net.lab1024.smartadmin.service.common.exception; 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 ] * [ 业务逻辑异常,全局异常拦截后统一返回ResponseCodeConst.SYSTEM_ERROR ]
@ -13,8 +13,8 @@ public class SmartBusinessException extends RuntimeException {
public SmartBusinessException() { public SmartBusinessException() {
} }
public SmartBusinessException(ResponseCodeConst responseCodeConst) { public SmartBusinessException(ErrorCode errorCode) {
super(responseCodeConst.getMsg()); super(errorCode.getMsg());
} }
public SmartBusinessException(String message) { public SmartBusinessException(String message) {

View File

@ -1,12 +1,11 @@
package net.lab1024.smartadmin.service.common.security; package net.lab1024.smartadmin.service.common.security;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import net.lab1024.smartadmin.service.common.codeconst.LoginResponseCodeConst; import net.lab1024.smartadmin.service.common.code.ErrorCode;
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.common.domain.ResponseDTO;
import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -23,18 +22,18 @@ public class SmartSecurityAuthenticationFailHandler implements AuthenticationEnt
@Override @Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException e) throws IOException { 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 response
* @param respCode * @param errorCode
* @throws IOException * @throws IOException
*/ */
private void outputResult(HttpServletResponse response, ResponseCodeConst respCode) throws IOException { private void outputResult(HttpServletResponse response, ErrorCode errorCode) throws IOException {
String msg = JSONObject.toJSONString(ResponseDTO.wrap(respCode)); String msg = JSONObject.toJSONString(ResponseDTO.error(errorCode));
response.setContentType("application/json;charset=UTF-8"); response.setContentType("application/json;charset=UTF-8");
response.getWriter().write(msg); response.getWriter().write(msg);
response.flushBuffer(); response.flushBuffer();

View File

@ -33,7 +33,7 @@ public class FileKeySerializer extends JsonSerializer<String> {
return; return;
} }
ResponseDTO<String> responseDTO = fileService.getFileUrl(value); ResponseDTO<String> responseDTO = fileService.getFileUrl(value);
if(responseDTO.isSuccess()){ if(responseDTO.getOk()){
jsonGenerator.writeString(responseDTO.getData()); jsonGenerator.writeString(responseDTO.getData());
return; return;
} }

View File

@ -1,10 +1,11 @@
package net.lab1024.smartadmin.service.handler; package net.lab1024.smartadmin.service.handler;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.lab1024.smartadmin.service.common.codeconst.ResponseCodeConst; import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
import net.lab1024.smartadmin.service.common.enumconst.SystemEnvironmentEnum; import net.lab1024.smartadmin.service.common.code.UserErrorCode;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.common.domain.SystemEnvironmentBO; 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 net.lab1024.smartadmin.service.common.exception.SmartBusinessException;
import org.springframework.beans.TypeMismatchException; import org.springframework.beans.TypeMismatchException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -50,7 +51,7 @@ public class SmartGlobalExceptionHandler {
// json 格式错误 // json 格式错误
if (e instanceof HttpMessageNotReadableException) { if (e instanceof HttpMessageNotReadableException) {
return ResponseDTO.wrap(ResponseCodeConst.JSON_FORMAT_ERROR); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请求参数JSON格式错误");
} }
String uri = null; String uri = null;
@ -62,45 +63,44 @@ public class SmartGlobalExceptionHandler {
// http 请求方式错误 // http 请求方式错误
if (e instanceof HttpRequestMethodNotSupportedException) { if (e instanceof HttpRequestMethodNotSupportedException) {
return ResponseDTO.wrap(ResponseCodeConst.REQUEST_METHOD_ERROR); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请求方式错误");
} }
// 参数类型错误 // 参数类型错误
if (e instanceof TypeMismatchException) { if (e instanceof TypeMismatchException) {
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM); return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
} }
// 参数校验未通过 // 参数校验未通过
if (e instanceof MethodArgumentNotValidException) { if (e instanceof MethodArgumentNotValidException) {
List<FieldError> fieldErrors = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors(); List<FieldError> fieldErrors = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors();
List<String> msgList = fieldErrors.stream().map(FieldError::getDefaultMessage).collect(Collectors.toList()); 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) { if (e instanceof BindException) {
List<FieldError> fieldErrors = ((BindException) e).getFieldErrors(); List<FieldError> fieldErrors = ((BindException) e).getFieldErrors();
List<String> error = fieldErrors.stream().map(field -> field.getField() + ":" + field.getRejectedValue()).collect(Collectors.toList()); List<String> error = fieldErrors.stream().map(field -> field.getField() + ":" + field.getRejectedValue()).collect(Collectors.toList());
String errorMsg = ResponseCodeConst.ERROR_PARAM.getMsg() + ":" + error.toString(); String errorMsg = UserErrorCode.PARAM_ERROR.getMsg() + ":" + error.toString();
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, errorMsg); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, errorMsg);
} }
if (e instanceof SmartBusinessException) { if (e instanceof SmartBusinessException) {
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, e.getMessage()); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, e.getMessage());
} }
if (e instanceof AccessDeniedException) { if (e instanceof AccessDeniedException) {
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "您暂无权限"); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "您暂无权限");
} }
log.error("捕获全局异常,URL:{}", uri, e); log.error("捕获全局异常,URL:{}", uri, e);
// 正式环境 不返回错误信息 // 正式环境 不返回错误信息
SystemEnvironmentEnum currentEnvironment = systemEnvironmentBO.getCurrentEnvironment(); if (SystemEnvironmentEnum.PROD == systemEnvironmentBO.getCurrentEnvironment()) {
if (SystemEnvironmentEnum.PROD == currentEnvironment) { return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR);
return ResponseDTO.wrap(ResponseCodeConst.SYSTEM_ERROR);
} }
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, e.toString()); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, e.toString());
} }
} }

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.listener; package net.lab1024.smartadmin.service.listener;
import lombok.extern.slf4j.Slf4j; 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.boot.CommandLineRunner;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -22,7 +22,7 @@ public class SmartAdminStartupRunner implements CommandLineRunner {
log.info("###################### init start ######################"); log.info("###################### init start ######################");
// 初始化状态码 // 初始化状态码
ResponseCodeRegister.init(); ErrorCodeRegister.init();
log.info("###################### init complete ######################"); log.info("###################### init complete ######################");
} }

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.business.category; package net.lab1024.smartadmin.service.module.business.category;
import com.google.common.collect.Lists; 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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.business.category.domain.*; import net.lab1024.smartadmin.service.module.business.category.domain.*;
@ -39,7 +39,7 @@ public class CategoryService {
// 校验类目 // 校验类目
CategoryEntity categoryEntity = SmartBeanUtil.copy(addDTO, CategoryEntity.class); CategoryEntity categoryEntity = SmartBeanUtil.copy(addDTO, CategoryEntity.class);
ResponseDTO<String> res = this.checkCategory(categoryEntity, false); ResponseDTO<String> res = this.checkCategory(categoryEntity, false);
if (!res.isSuccess()) { if (!res.getOk()) {
return res; return res;
} }
// 没有父类则使用默认父类 // 没有父类则使用默认父类
@ -53,7 +53,7 @@ public class CategoryService {
// 更新缓存 // 更新缓存
categoryQueryService.removeCache(); categoryQueryService.removeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -68,7 +68,7 @@ public class CategoryService {
Long categoryId = updateDTO.getCategoryId(); Long categoryId = updateDTO.getCategoryId();
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId); Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
if (!optional.isPresent()) { if (!optional.isPresent()) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
CategoryEntity categoryEntity = SmartBeanUtil.copy(updateDTO, CategoryEntity.class); CategoryEntity categoryEntity = SmartBeanUtil.copy(updateDTO, CategoryEntity.class);
@ -81,14 +81,14 @@ public class CategoryService {
categoryEntity.setParentId(optional.get().getParentId()); categoryEntity.setParentId(optional.get().getParentId());
ResponseDTO<String> responseDTO = this.checkCategory(categoryEntity, true); ResponseDTO<String> responseDTO = this.checkCategory(categoryEntity, true);
if (!responseDTO.isSuccess()) { if (!responseDTO.getOk()) {
return responseDTO; return responseDTO;
} }
categoryDao.updateById(categoryEntity); categoryDao.updateById(categoryEntity);
// 更新缓存 // 更新缓存
categoryQueryService.removeCache(); categoryQueryService.removeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -104,17 +104,17 @@ public class CategoryService {
Integer categoryType = categoryEntity.getCategoryType(); Integer categoryType = categoryEntity.getCategoryType();
if (null != parentId) { if (null != parentId) {
if (Objects.equals(categoryEntity.getCategoryId(), 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)) { if (!Objects.equals(parentId, CommonConst.DEFAULT_PARENT_ID)) {
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(parentId); Optional<CategoryEntity> optional = categoryQueryService.queryCategory(parentId);
if (!optional.isPresent()) { if (!optional.isPresent()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.NOT_EXISTS, "父级类目不存在~"); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "父级类目不存在~");
} }
CategoryEntity parent = optional.get(); CategoryEntity parent = optional.get();
if (!Objects.equals(categoryType, parent.getCategoryType())) { 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 (null != queryEntity) {
if (isUpdate) { if (isUpdate) {
if (!Objects.equals(queryEntity.getCategoryId(), categoryEntity.getCategoryId())) { if (!Objects.equals(queryEntity.getCategoryId(), categoryEntity.getCategoryId())) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "同级下已存在相同类目~"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "同级下已存在相同类目~");
} }
} else { } 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) { public ResponseDTO<CategoryVO> queryDetail(Long categoryId) {
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId); Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
if (!optional.isPresent()) { if (!optional.isPresent()) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
CategoryVO adminVO = SmartBeanUtil.copy(optional.get(), CategoryVO.class); 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) { public ResponseDTO<List<CategoryTreeVO>> queryTree(CategoryTreeQueryDTO queryDTO) {
if (null == queryDTO.getParentId()) { if (null == queryDTO.getParentId()) {
if (null == queryDTO.getCategoryType()) { if (null == queryDTO.getCategoryType()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "类目类型不能为空"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "类目类型不能为空");
} }
queryDTO.setParentId(CommonConst.DEFAULT_PARENT_ID); queryDTO.setParentId(CommonConst.DEFAULT_PARENT_ID);
} }
List<CategoryTreeVO> treeList = categoryQueryService.queryCategoryTree(queryDTO); 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) { public ResponseDTO<String> delete(Long categoryId) {
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId); Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
if (!optional.isPresent()) { if (!optional.isPresent()) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
List<Long> categorySubId = categoryQueryService.queryCategorySubId(Lists.newArrayList(categoryId)); List<Long> categorySubId = categoryQueryService.queryCategorySubId(Lists.newArrayList(categoryId));
if (CollectionUtils.isNotEmpty(categorySubId)) { 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(); categoryQueryService.removeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
} }

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.business.goods; package net.lab1024.smartadmin.service.module.business.goods;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.PageResultDTO;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.business.category.CategoryQueryService; import net.lab1024.smartadmin.service.module.business.category.CategoryQueryService;
@ -46,13 +46,13 @@ public class GoodsService {
public ResponseDTO<String> add(GoodsAddDTO addDTO) { public ResponseDTO<String> add(GoodsAddDTO addDTO) {
// 商品校验 // 商品校验
ResponseDTO<String> res = this.checkGoods(addDTO, null); ResponseDTO<String> res = this.checkGoods(addDTO, null);
if (!res.isSuccess()) { if (!res.getOk()) {
return res; return res;
} }
GoodsEntity goodsEntity = SmartBeanUtil.copy(addDTO, GoodsEntity.class); GoodsEntity goodsEntity = SmartBeanUtil.copy(addDTO, GoodsEntity.class);
goodsDao.insert(goodsEntity); goodsDao.insert(goodsEntity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -64,13 +64,13 @@ public class GoodsService {
public ResponseDTO<String> update(GoodsUpdateDTO updateDTO) { public ResponseDTO<String> update(GoodsUpdateDTO updateDTO) {
// 商品校验 // 商品校验
ResponseDTO<String> res = this.checkGoods(updateDTO, updateDTO.getGoodsId()); ResponseDTO<String> res = this.checkGoods(updateDTO, updateDTO.getGoodsId());
if (!res.isSuccess()) { if (!res.getOk()) {
return res; return res;
} }
GoodsEntity goodsEntity = SmartBeanUtil.copy(updateDTO, GoodsEntity.class); GoodsEntity goodsEntity = SmartBeanUtil.copy(updateDTO, GoodsEntity.class);
goodsDao.updateById(goodsEntity); goodsDao.updateById(goodsEntity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -92,17 +92,17 @@ public class GoodsService {
GoodsEntity goodsEntity = goodsDao.selectOne(goodsBO); GoodsEntity goodsEntity = goodsDao.selectOne(goodsBO);
if (null != goodsEntity) { if (null != goodsEntity) {
if (null == goodsId || !Objects.equals(goodsEntity.getGoodsId(), goodsId)) { if (null == goodsId || !Objects.equals(goodsEntity.getGoodsId(), goodsId)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "商品名称不能重复~"); return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "商品名称不能重复~");
} }
} }
// 校验类目id // 校验类目id
Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId); Optional<CategoryEntity> optional = categoryQueryService.queryCategory(categoryId);
if (!optional.isPresent() || !CategoryTypeEnum.GOODS.equalsValue(optional.get().getCategoryType())) { 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; return goodsEntity;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
goodsManager.updateBatchById(goodsList); goodsManager.updateBatchById(goodsList);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -135,12 +135,12 @@ public class GoodsService {
List<GoodsAdminVO> list = goodsDao.query(page, queryDTO); List<GoodsAdminVO> list = goodsDao.query(page, queryDTO);
PageResultDTO<GoodsAdminVO> pageResult = SmartPageUtil.convert2PageResult(page, list); PageResultDTO<GoodsAdminVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
if (pageResult.getEmptyFlag()) { if (pageResult.getEmptyFlag()) {
return ResponseDTO.succData(pageResult); return ResponseDTO.ok(pageResult);
} }
// 查询分类名称 // 查询分类名称
List<Long> categoryIdList = list.stream().map(GoodsAdminVO::getCategoryId).distinct().collect(Collectors.toList()); List<Long> categoryIdList = list.stream().map(GoodsAdminVO::getCategoryId).distinct().collect(Collectors.toList());
Map<Long, CategoryEntity> categoryMap = categoryQueryService.queryCategoryList(categoryIdList); Map<Long, CategoryEntity> categoryMap = categoryQueryService.queryCategoryList(categoryIdList);
list.forEach(e -> e.setCategoryName(categoryMap.get(e.getCategoryId()).getCategoryName())); list.forEach(e -> e.setCategoryName(categoryMap.get(e.getCategoryId()).getCategoryName()));
return ResponseDTO.succData(pageResult); return ResponseDTO.ok(pageResult);
} }
} }

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.business.notice; package net.lab1024.smartadmin.service.module.business.notice;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.PageBaseDTO;
import net.lab1024.smartadmin.service.common.domain.PageResultDTO; import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
@ -47,7 +47,7 @@ public class NoticeService {
Page page = SmartPageUtil.convert2PageQuery(queryDTO); Page page = SmartPageUtil.convert2PageQuery(queryDTO);
List<NoticeVO> dtoList = noticeDao.queryByPage(page, queryDTO); List<NoticeVO> dtoList = noticeDao.queryByPage(page, queryDTO);
PageResultDTO<NoticeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList); 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); e.setReadStatus(e.getReceiveTime() != null);
}); });
PageResultDTO<NoticeReceiveDTO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList); 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); Page page = SmartPageUtil.convert2PageQuery(queryDTO);
List<NoticeVO> dtoList = noticeDao.queryUnreadByPage(page, employeeId, true); List<NoticeVO> dtoList = noticeDao.queryUnreadByPage(page, employeeId, true);
PageResultDTO<NoticeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, dtoList); 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.setSendStatus(false);
entity.setDeletedFlag(true); entity.setDeletedFlag(true);
noticeDao.insert(entity); noticeDao.insert(entity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -104,16 +104,16 @@ public class NoticeService {
public ResponseDTO<String> update(NoticeUpdateDTO updateDTO) { public ResponseDTO<String> update(NoticeUpdateDTO updateDTO) {
NoticeEntity entity = noticeDao.selectById(updateDTO.getId()); NoticeEntity entity = noticeDao.selectById(updateDTO.getId());
if (entity == null) { if (entity == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
} }
if (entity.getDeletedFlag()) { if (entity.getDeletedFlag()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知已删除"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知已删除");
} }
if (entity.getSendStatus()) { if (entity.getSendStatus()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知已发送无法修改"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知已发送无法修改");
} }
noticeManage.update(updateDTO); noticeManage.update(updateDTO);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -124,10 +124,10 @@ public class NoticeService {
public ResponseDTO<String> delete(Long id) { public ResponseDTO<String> delete(Long id) {
NoticeEntity entity = noticeDao.selectById(id); NoticeEntity entity = noticeDao.selectById(id);
if (entity == null) { if (entity == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
} }
noticeManage.delete(entity); noticeManage.delete(entity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -137,7 +137,7 @@ public class NoticeService {
*/ */
public ResponseDTO<NoticeDetailVO> detail(Long id) { public ResponseDTO<NoticeDetailVO> detail(Long id) {
NoticeDetailVO noticeDTO = noticeDao.detail(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) { public ResponseDTO<NoticeDetailVO> send(Long id, Long employeeId) {
NoticeEntity entity = noticeDao.selectById(id); NoticeEntity entity = noticeDao.selectById(id);
if (entity == null) { if (entity == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "此系统通知不存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "此系统通知不存在");
} }
noticeManage.send(entity, employeeId); noticeManage.send(entity, employeeId);
this.sendMessage(employeeId); this.sendMessage(employeeId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -206,10 +206,10 @@ public class NoticeService {
NoticeReceiveRecordEntity recordEntity = noticeReceiveRecordDao.selectByEmployeeAndNotice(employeeId, id); NoticeReceiveRecordEntity recordEntity = noticeReceiveRecordDao.selectByEmployeeAndNotice(employeeId, id);
if (recordEntity != null) { if (recordEntity != null) {
return ResponseDTO.succData(noticeDTO); return ResponseDTO.ok(noticeDTO);
} }
noticeManage.saveReadRecord(id, employeeId); noticeManage.saveReadRecord(id, employeeId);
this.sendMessage(employeeId); this.sendMessage(employeeId);
return ResponseDTO.succData(noticeDTO); return ResponseDTO.ok(noticeDTO);
} }
} }

View File

@ -2,8 +2,8 @@ package net.lab1024.smartadmin.service.module.support.captcha;
import com.google.code.kaptcha.impl.DefaultKaptcha; import com.google.code.kaptcha.impl.DefaultKaptcha;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.lab1024.smartadmin.service.common.codeconst.EmployeeResponseCodeConst; import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.constant.RedisKeyConst; import net.lab1024.smartadmin.service.common.constant.RedisKeyConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
@ -51,7 +51,7 @@ public class CaptchaService {
base64Code = Base64Utils.encodeToString(os.toByteArray()); base64Code = Base64Utils.encodeToString(os.toByteArray());
} catch (Exception e) { } catch (Exception e) {
log.error("verificationCode 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 唯一标识 // uuid 唯一标识
String uuid = UUID.randomUUID().toString().replace("-", CommonConst.EMPTY_STR); String uuid = UUID.randomUUID().toString().replace("-", CommonConst.EMPTY_STR);
@ -65,7 +65,7 @@ public class CaptchaService {
captchaVO.setCaptchaId(uuid); captchaVO.setCaptchaId(uuid);
captchaVO.setCaptchaImg("data:image/png;base64," + base64Code); captchaVO.setCaptchaImg("data:image/png;base64," + base64Code);
redisService.set(buildCaptchaRedisKey(uuid), captchaText, 80L); 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) { public ResponseDTO<String> checkCaptcha(String captchaId, String captcha) {
if (StringUtils.isBlank(captchaId) || StringUtils.isBlank(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 redisKey = buildCaptchaRedisKey(captchaId);
String redisCode = redisService.get(redisKey); String redisCode = redisService.get(redisKey);
if (StringUtils.isBlank(redisCode)) { if (StringUtils.isBlank(redisCode)) {
return ResponseDTO.wrapMsg(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" ); return ResponseDTO.error(UserErrorCode.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
} }
if (!Objects.equals(redisCode, captcha)) { if (!Objects.equals(redisCode, captcha)) {
return ResponseDTO.wrapMsg(EmployeeResponseCodeConst.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" ); return ResponseDTO.error(UserErrorCode.VERIFICATION_CODE_INVALID, "验证码错误或已过期,请刷新重试" );
} }
// 校验通过 移除 // 校验通过 移除
redisService.del(redisKey); redisService.del(redisKey);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
private String buildCaptchaRedisKey(String codeId) { private String buildCaptchaRedisKey(String codeId) {

View File

@ -111,6 +111,6 @@ public class DataTracerService {
Page page = SmartPageUtil.convert2PageQuery(queryForm); Page page = SmartPageUtil.convert2PageQuery(queryForm);
List<DataTracerVO> list = dataTracerDao.query(page, queryForm); List<DataTracerVO> list = dataTracerDao.query(page, queryForm);
PageResultDTO<DataTracerVO> pageResult = SmartPageUtil.convert2PageResult(page, list); PageResultDTO<DataTracerVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
return ResponseDTO.succData(pageResult); return ResponseDTO.ok(pageResult);
} }
} }

View File

@ -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.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.lab1024.smartadmin.service.common.codeconst.FileResponseCodeConst; import net.lab1024.smartadmin.service.common.code.SystemErrorCode;
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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.constant.NumberLimitConst; import net.lab1024.smartadmin.service.common.constant.NumberLimitConst;
import net.lab1024.smartadmin.service.common.constant.RedisKeyConst; import net.lab1024.smartadmin.service.common.constant.RedisKeyConst;
@ -78,7 +78,7 @@ public class FileService {
MockMultipartFile file = new MockMultipartFile(fileKey, fileKey, contentType, urlConnection.getInputStream()); MockMultipartFile file = new MockMultipartFile(fileKey, fileKey, contentType, urlConnection.getInputStream());
return this.fileUpload(file, urlUploadDTO.getFolder(), urlUploadDTO.getUserId(), urlUploadDTO.getUserName()); return this.fileUpload(file, urlUploadDTO.getFolder(), urlUploadDTO.getUserId(), urlUploadDTO.getUserName());
} catch (IOException e) { } 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) { public ResponseDTO<FileUploadVO> fileUpload(MultipartFile file, Integer folderType, Long userId, String userName) {
FileFolderTypeEnum folderTypeEnum = SmartBaseEnumUtil.getEnumByValue(folderType, FileFolderTypeEnum.class); FileFolderTypeEnum folderTypeEnum = SmartBaseEnumUtil.getEnumByValue(folderType, FileFolderTypeEnum.class);
if (null == folderTypeEnum) { if (null == folderTypeEnum) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_MODULE_ERROR); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "文件夹错误");
} }
if (null == file || file.getSize() == 0) { if (null == file || file.getSize() == 0) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_EMPTY); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件不能为空");
} }
// 校验文件名称 // 校验文件名称
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
if (StringUtils.isBlank(originalFilename) || originalFilename.length() > NumberLimitConst.FILE_NAME) { 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", ""); String maxSizeStr = maxFileSize.toLowerCase().replace("mb", "");
long maxSize = Integer.parseInt(maxSizeStr) * 1024 * 1024L; long maxSize = Integer.parseInt(maxSizeStr) * 1024 * 1024L;
if (file.getSize() > maxSize) { 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()); ResponseDTO<FileUploadVO> response = fileStorageService.fileUpload(file, folderTypeEnum.getFolder());
if (response.isSuccess()) { if (response.getOk()) {
// 上传成功 保存记录数据库 // 上传成功 保存记录数据库
FileUploadVO uploadVO = response.getData(); FileUploadVO uploadVO = response.getData();
@ -174,13 +174,13 @@ public class FileService {
*/ */
public ResponseDTO<String> getFileUrl(String fileKey) { public ResponseDTO<String> getFileUrl(String fileKey) {
if (StringUtils.isBlank(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)); List<String> stringList = Arrays.asList(fileKey.split(CommonConst.SEPARATOR));
stringList = stringList.stream().map(e -> this.getCacheUrl(e)).collect(Collectors.toList()); stringList = stringList.stream().map(e -> this.getCacheUrl(e)).collect(Collectors.toList());
String result = StringUtils.join(stringList, CommonConst.SEPARATOR_CHAR); 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; return fileUrl;
} }
ResponseDTO<String> responseDTO = fileStorageService.getFileUrl(fileKey); ResponseDTO<String> responseDTO = fileStorageService.getFileUrl(fileKey);
if (!responseDTO.isSuccess()) { if (!responseDTO.getOk()) {
return null; return null;
} }
fileUrl = responseDTO.getData(); fileUrl = responseDTO.getData();
@ -218,7 +218,7 @@ public class FileService {
return new FileUrlResultDTO(fileKey, result); return new FileUrlResultDTO(fileKey, result);
}).collect(Collectors.toList()); }).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); 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) { public ResponseEntity<Object> downloadByFileKey(String fileKey, String userAgent) {
// 根据文件服务类 获取对应文件服务 查询 url // 根据文件服务类 获取对应文件服务 查询 url
ResponseDTO<FileDownloadDTO> responseDTO = fileStorageService.fileDownload(fileKey); ResponseDTO<FileDownloadDTO> responseDTO = fileStorageService.fileDownload(fileKey);
if (!responseDTO.isSuccess()) { if (!responseDTO.getOk()) {
HttpHeaders heads = new HttpHeaders(); HttpHeaders heads = new HttpHeaders();
heads.add(HttpHeaders.CONTENT_TYPE, "text/html;charset=UTF-8"); heads.add(HttpHeaders.CONTENT_TYPE, "text/html;charset=UTF-8");
return new ResponseEntity<>(responseDTO.getMsg() + "" + fileKey, heads, HttpStatus.OK); return new ResponseEntity<>(responseDTO.getMsg() + "" + fileKey, heads, HttpStatus.OK);
@ -295,13 +295,13 @@ public class FileService {
*/ */
public ResponseDTO<String> deleteByFileKey(String fileKey) { public ResponseDTO<String> deleteByFileKey(String fileKey) {
if (StringUtils.isBlank(fileKey)) { if (StringUtils.isBlank(fileKey)) {
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM); return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
} }
FileEntity fileEntity = new FileEntity(); FileEntity fileEntity = new FileEntity();
fileEntity.setFileKey(fileKey); fileEntity.setFileKey(fileKey);
fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity)); fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity));
if (null == fileEntity) { if (null == fileEntity) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 根据文件服务类 获取对应文件服务 删除文件 // 根据文件服务类 获取对应文件服务 删除文件
return fileStorageService.delete(fileKey); return fileStorageService.delete(fileKey);
@ -315,14 +315,14 @@ public class FileService {
*/ */
public ResponseDTO<FileMetadataDTO> queryFileMetadata(String fileKey) { public ResponseDTO<FileMetadataDTO> queryFileMetadata(String fileKey) {
if (StringUtils.isBlank(fileKey)) { if (StringUtils.isBlank(fileKey)) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 查询数据库文件记录 // 查询数据库文件记录
FileEntity fileEntity = new FileEntity(); FileEntity fileEntity = new FileEntity();
fileEntity.setFileKey(fileKey); fileEntity.setFileKey(fileKey);
fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity)); fileEntity = fileDao.selectOne(new QueryWrapper<>(fileEntity));
if (null == fileEntity) { if (null == fileEntity) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_NOT_EXIST); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 返回 meta // 返回 meta
@ -330,6 +330,6 @@ public class FileService {
metadataDTO.setFileSize(fileEntity.getFileSize()); metadataDTO.setFileSize(fileEntity.getFileSize());
metadataDTO.setFileName(fileEntity.getFileName()); metadataDTO.setFileName(fileEntity.getFileName());
metadataDTO.setFileFormat(fileEntity.getFileType()); metadataDTO.setFileFormat(fileEntity.getFileType());
return ResponseDTO.succData(metadataDTO); return ResponseDTO.ok(metadataDTO);
} }
} }

View File

@ -5,9 +5,8 @@ import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.S3Object; import com.amazonaws.services.s3.model.S3Object;
import lombok.extern.slf4j.Slf4j; 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.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.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.config.FileCloudConfig; import net.lab1024.smartadmin.service.config.FileCloudConfig;
import net.lab1024.smartadmin.service.module.support.file.domain.FileFolderTypeEnum; 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()); urlEncoderFilename = URLEncoder.encode(originalFilename, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
log.error("阿里云文件上传服务URL ENCODE-发生异常:", e); log.error("阿里云文件上传服务URL ENCODE-发生异常:", e);
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"上传失败");
} }
ObjectMetadata meta = new ObjectMetadata(); ObjectMetadata meta = new ObjectMetadata();
meta.setContentEncoding(StandardCharsets.UTF_8.name()); meta.setContentEncoding(StandardCharsets.UTF_8.name());
@ -90,7 +89,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
amazonS3.putObject(cloudConfig.getBucketName(), fileKey, file.getInputStream(), meta); amazonS3.putObject(cloudConfig.getBucketName(), fileKey, file.getInputStream(), meta);
} catch (IOException e) { } catch (IOException e) {
log.error("文件上传-发生异常:", e); log.error("文件上传-发生异常:", e);
return ResponseDTO.wrap(FileResponseCodeConst.UPLOAD_ERROR); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"上传失败");
} }
// 根据文件路径获取并设置访问权限 // 根据文件路径获取并设置访问权限
CannedAccessControlList acl = this.getACL(path); CannedAccessControlList acl = this.getACL(path);
@ -108,7 +107,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
uploadVO.setFileUrl(url); uploadVO.setFileUrl(url);
uploadVO.setFileKey(fileKey); uploadVO.setFileKey(fileKey);
uploadVO.setFileSize(file.getSize()); uploadVO.setFileSize(file.getSize());
return ResponseDTO.succData(uploadVO); return ResponseDTO.ok(uploadVO);
} }
/** /**
@ -120,16 +119,16 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
@Override @Override
public ResponseDTO<String> getFileUrl(String fileKey) { public ResponseDTO<String> getFileUrl(String fileKey) {
if (StringUtils.isBlank(fileKey)) { if (StringUtils.isBlank(fileKey)) {
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM); return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
} }
if (!fileKey.startsWith(FileFolderTypeEnum.FOLDER_PRIVATE)) { 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()); Date expiration = new Date(System.currentTimeMillis() + cloudConfig.getUrlExpire());
URL url = amazonS3.generatePresignedUrl(cloudConfig.getBucketName(), fileKey, expiration); URL url = amazonS3.generatePresignedUrl(cloudConfig.getBucketName(), fileKey, expiration);
String urlStr = url.toString().replace("http://", "https://"); 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 fileDownloadDTO = new FileDownloadDTO();
fileDownloadDTO.setData(buffer); fileDownloadDTO.setData(buffer);
fileDownloadDTO.setMetadata(metadataDTO); fileDownloadDTO.setMetadata(metadataDTO);
return ResponseDTO.succData(fileDownloadDTO); return ResponseDTO.ok(fileDownloadDTO);
} catch (IOException e) { } catch (IOException e) {
log.error("文件下载-发生异常:", e); log.error("文件下载-发生异常:", e);
return ResponseDTO.wrap(FileResponseCodeConst.DOWNLOAD_ERROR); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR,"下载失败");
} finally { } finally {
try { try {
// 关闭输入流 // 关闭输入流
@ -202,7 +201,7 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
@Override @Override
public ResponseDTO<String> delete(String fileKey) { public ResponseDTO<String> delete(String fileKey) {
amazonS3.deleteObject(cloudConfig.getBucketName(), fileKey); amazonS3.deleteObject(cloudConfig.getBucketName(), fileKey);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }

View File

@ -1,7 +1,8 @@
package net.lab1024.smartadmin.service.module.support.file.service; package net.lab1024.smartadmin.service.module.support.file.service;
import lombok.extern.slf4j.Slf4j; 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.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.support.file.domain.dto.FileDownloadDTO; import net.lab1024.smartadmin.service.module.support.file.domain.dto.FileDownloadDTO;
import net.lab1024.smartadmin.service.module.support.file.domain.vo.FileUploadVO; 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}") @Value("${file.storage.local.path}")
private String localPath; private String localPath;
@Autowired @Autowired
private SystemConfigService systemConfigService; private SystemConfigService systemConfigService;
@Override @Override
public ResponseDTO<FileUploadVO> fileUpload(MultipartFile multipartFile, String path) { public ResponseDTO<FileUploadVO> fileUpload(MultipartFile multipartFile, String path) {
if (null == multipartFile) { if (null == multipartFile) {
return ResponseDTO.wrap(FileResponseCodeConst.FILE_EMPTY); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "上传文件不能为空");
} }
String filePath = localPath + path; String filePath = localPath + path;
File directory = new File(filePath); File directory = new File(filePath);
@ -70,9 +72,9 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
fileTemp.delete(); fileTemp.delete();
} }
log.error("", e); 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 * 获取文件Url
*
* @param fileKey * @param fileKey
* @return * @return
*/ */
@Override @Override
public ResponseDTO<String> getFileUrl(String fileKey) { public ResponseDTO<String> getFileUrl(String fileKey) {
String fileUrl = this.generateFileUrl(fileKey); String fileUrl = this.generateFileUrl(fileKey);
return ResponseDTO.succData(fileUrl); return ResponseDTO.ok(fileUrl);
} }
/** /**
* 文件下载 * 文件下载
*
* @param fileKey * @param fileKey
* @return * @return
*/ */
@ -114,10 +118,10 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
byte[] buffer = FileCopyUtils.copyToByteArray(in); byte[] buffer = FileCopyUtils.copyToByteArray(in);
FileDownloadDTO fileDownloadDTO = new FileDownloadDTO(); FileDownloadDTO fileDownloadDTO = new FileDownloadDTO();
fileDownloadDTO.setData(buffer); fileDownloadDTO.setData(buffer);
return ResponseDTO.succData(fileDownloadDTO); return ResponseDTO.ok(fileDownloadDTO);
} catch (IOException e) { } catch (IOException e) {
log.error("文件下载-发生异常:", e); log.error("文件下载-发生异常:", e);
return ResponseDTO.wrap(FileResponseCodeConst.DOWNLOAD_ERROR); return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "文件下载失败");
} finally { } finally {
try { try {
// 关闭输入流 // 关闭输入流
@ -139,6 +143,6 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
} catch (IOException e) { } catch (IOException e) {
log.error("删除本地文件失败:{}", e); log.error("删除本地文件失败:{}", e);
} }
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
} }

View File

@ -28,6 +28,6 @@ public class HeartBeatService {
Page pageQueryInfo = SmartPageUtil.convert2PageQuery(pageBaseDTO); Page pageQueryInfo = SmartPageUtil.convert2PageQuery(pageBaseDTO);
List<HeartBeatRecordVO> recordVOList = heartBeatRecordDao.pageQuery(pageQueryInfo); List<HeartBeatRecordVO> recordVOList = heartBeatRecordDao.pageQuery(pageQueryInfo);
PageResultDTO<HeartBeatRecordVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageQueryInfo, recordVOList); PageResultDTO<HeartBeatRecordVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageQueryInfo, recordVOList);
return ResponseDTO.succData(pageResultDTO); return ResponseDTO.ok(pageResultDTO);
} }
} }

View File

@ -1,13 +1,13 @@
package net.lab1024.smartadmin.service.module.support.idgenerator; 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.Api;
import io.swagger.annotations.ApiOperation; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -31,7 +31,7 @@ public class IdGeneratorController extends SupportBaseController {
public ResponseDTO<String> generate(@PathVariable Integer generatorId) { public ResponseDTO<String> generate(@PathVariable Integer generatorId) {
IdGeneratorEnum idGeneratorEnum = SmartBaseEnumUtil.getEnumByValue(generatorId, IdGeneratorEnum.class); IdGeneratorEnum idGeneratorEnum = SmartBaseEnumUtil.getEnumByValue(generatorId, IdGeneratorEnum.class);
if (null == idGeneratorEnum) { if (null == idGeneratorEnum) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "IdGenerator不存在" + generatorId); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "IdGenerator不存在" + generatorId);
} }
return idGeneratorService.generate(idGeneratorEnum); return idGeneratorService.generate(idGeneratorEnum);
} }

View File

@ -1,6 +1,8 @@
package net.lab1024.smartadmin.service.module.support.idgenerator; 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.constant.RedisKeyConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.support.idgenerator.constant.IdGeneratorEnum; 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.module.support.idgenerator.domain.IdGeneratorRecordDTO;
import net.lab1024.smartadmin.service.third.SmartRedisService; import net.lab1024.smartadmin.service.third.SmartRedisService;
import net.lab1024.smartadmin.service.util.SmartRandomUtil; import net.lab1024.smartadmin.service.util.SmartRandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -61,7 +62,7 @@ public class IdGeneratorService {
int generatorId = idGeneratorEnum.getValue(); int generatorId = idGeneratorEnum.getValue();
IdGeneratorEntity idGeneratorEntity = this.idGeneratorMap.get(generatorId); IdGeneratorEntity idGeneratorEntity = this.idGeneratorMap.get(generatorId);
if (null == idGeneratorEntity) { if (null == idGeneratorEntity) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "IdGenerator 生成器 不存在" + generatorId); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "IdGenerator 生成器 不存在" + generatorId);
} }
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
@ -88,7 +89,7 @@ public class IdGeneratorService {
} }
if (!lock) { if (!lock) {
return ResponseDTO.wrap(ResponseCodeConst.BUSINESS_HANDING); return ResponseDTO.error(UnexpectedErrorCode.BUSINESS_HANDING);
} }
long beginTime = System.currentTimeMillis(); long beginTime = System.currentTimeMillis();
@ -127,7 +128,7 @@ public class IdGeneratorService {
String prefix = StringUtils.isBlank(idGeneratorEntity.getPrefix()) ? StringUtils.EMPTY : idGeneratorEntity.getPrefix(); String prefix = StringUtils.isBlank(idGeneratorEntity.getPrefix()) ? StringUtils.EMPTY : idGeneratorEntity.getPrefix();
lastSleepMilliSeconds = System.currentTimeMillis() - beginTime + 100; lastSleepMilliSeconds = System.currentTimeMillis() - beginTime + 100;
return ResponseDTO.succData(prefix + nowFormat + finalId); return ResponseDTO.ok(prefix + nowFormat + finalId);
} catch (Throwable e) { } catch (Throwable e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
throw e; throw e;

View File

@ -34,7 +34,7 @@ public class OperateLogService {
Page page = SmartPageUtil.convert2PageQuery(queryDTO); Page page = SmartPageUtil.convert2PageQuery(queryDTO);
List<OperateLogEntity> logEntityList = operateLogDao.queryByPage(page, queryDTO); List<OperateLogEntity> logEntityList = operateLogDao.queryByPage(page, queryDTO);
PageResultDTO<OperateLogDTO> pageResultDTO = SmartPageUtil.convert2PageResult(page, logEntityList, OperateLogDTO.class); 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) { public ResponseDTO<String> add(OperateLogDTO addDTO) {
OperateLogEntity entity = SmartBeanUtil.copy(addDTO, OperateLogEntity.class); OperateLogEntity entity = SmartBeanUtil.copy(addDTO, OperateLogEntity.class);
operateLogDao.insert(entity); operateLogDao.insert(entity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -57,7 +57,7 @@ public class OperateLogService {
public ResponseDTO<String> update(OperateLogDTO updateDTO) { public ResponseDTO<String> update(OperateLogDTO updateDTO) {
OperateLogEntity entity = SmartBeanUtil.copy(updateDTO, OperateLogEntity.class); OperateLogEntity entity = SmartBeanUtil.copy(updateDTO, OperateLogEntity.class);
operateLogDao.updateById(entity); operateLogDao.updateById(entity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -68,7 +68,7 @@ public class OperateLogService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public ResponseDTO<String> delete(Long id) { public ResponseDTO<String> delete(Long id) {
operateLogDao.deleteById(id); operateLogDao.deleteById(id);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -79,6 +79,6 @@ public class OperateLogService {
public ResponseDTO<OperateLogDTO> detail(Long id) { public ResponseDTO<OperateLogDTO> detail(Long id) {
OperateLogEntity entity = operateLogDao.selectById(id); OperateLogEntity entity = operateLogDao.selectById(id);
OperateLogDTO dto = SmartBeanUtil.copy(entity, OperateLogDTO.class); OperateLogDTO dto = SmartBeanUtil.copy(entity, OperateLogDTO.class);
return ResponseDTO.succData(dto); return ResponseDTO.ok(dto);
} }
} }

View File

@ -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.Cache;
import com.github.benmanes.caffeine.cache.Caffeine; 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 net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature; 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.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
@ -71,7 +70,7 @@ public class SmartRepeatSubmitAspect {
int interval = Math.min(annotation.value(), RepeatSubmit.MAX_INTERVAL); int interval = Math.min(annotation.value(), RepeatSubmit.MAX_INTERVAL);
if (System.currentTimeMillis() < (long) value + interval) { if (System.currentTimeMillis() < (long) value + interval) {
// 提交频繁 // 提交频繁
return ResponseDTO.wrap(ResponseCodeConst.REPEAT_SUBMIT); return ResponseDTO.error(UserErrorCode.REPEAT_SUBMIT);
} }
} }
cache.put(key, System.currentTimeMillis()); cache.put(key, System.currentTimeMillis());

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.system.datascope.service; package net.lab1024.smartadmin.service.module.system.datascope.service;
import com.google.common.collect.Lists; 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.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.system.datascope.DataScopeRoleDao; import net.lab1024.smartadmin.service.module.system.datascope.DataScopeRoleDao;
import net.lab1024.smartadmin.service.module.system.datascope.constant.DataScopeTypeEnum; import net.lab1024.smartadmin.service.module.system.datascope.constant.DataScopeTypeEnum;
@ -40,7 +40,7 @@ public class DataScopeService {
dataScopeAndTypeList.forEach(e -> { dataScopeAndTypeList.forEach(e -> {
e.setViewTypeList(typeList); e.setViewTypeList(typeList);
}); });
return ResponseDTO.succData(dataScopeAndTypeList); return ResponseDTO.ok(dataScopeAndTypeList);
} }
/** /**
@ -85,10 +85,10 @@ public class DataScopeService {
List<DataScopeRoleEntity> dataScopeRoleEntityList = dataScopeRoleDao.listByRoleId(roleId); List<DataScopeRoleEntity> dataScopeRoleEntityList = dataScopeRoleDao.listByRoleId(roleId);
if (CollectionUtils.isEmpty(dataScopeRoleEntityList)) { if (CollectionUtils.isEmpty(dataScopeRoleEntityList)) {
return ResponseDTO.succData(Lists.newArrayList()); return ResponseDTO.ok(Lists.newArrayList());
} }
List<DataScopeSelectVO> dataScopeSelects = SmartBeanUtil.copyList(dataScopeRoleEntityList, DataScopeSelectVO.class); 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) { public ResponseDTO<String> dataScopeBatchSet(DataScopeBatchSetRoleDTO batchSetRoleDTO) {
List<DataScopeBatchSetDTO> batchSetList = batchSetRoleDTO.getBatchSetList(); List<DataScopeBatchSetDTO> batchSetList = batchSetRoleDTO.getBatchSetList();
if (CollectionUtils.isEmpty(batchSetList)) { if (CollectionUtils.isEmpty(batchSetList)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "缺少配置信息"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "缺少配置信息");
} }
List<DataScopeRoleEntity> dataScopeRoleEntityList = SmartBeanUtil.copyList(batchSetList, DataScopeRoleEntity.class); List<DataScopeRoleEntity> dataScopeRoleEntityList = SmartBeanUtil.copyList(batchSetList, DataScopeRoleEntity.class);
dataScopeRoleEntityList.forEach(e -> e.setRoleId(batchSetRoleDTO.getRoleId())); dataScopeRoleEntityList.forEach(e -> e.setRoleId(batchSetRoleDTO.getRoleId()));
dataScopeRoleDao.deleteByRoleId(batchSetRoleDTO.getRoleId()); dataScopeRoleDao.deleteByRoleId(batchSetRoleDTO.getRoleId());
dataScopeRoleDao.batchInsert(dataScopeRoleEntityList); dataScopeRoleDao.batchInsert(dataScopeRoleEntityList);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
} }

View File

@ -1,6 +1,6 @@
package net.lab1024.smartadmin.service.module.system.department; 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.CacheModuleConst;
import net.lab1024.smartadmin.service.common.constant.CommonConst; import net.lab1024.smartadmin.service.common.constant.CommonConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
@ -56,7 +56,7 @@ public class DepartmentService {
public ResponseDTO<List<DepartmentTreeVO>> departmentTree() { public ResponseDTO<List<DepartmentTreeVO>> departmentTree() {
String cacheKey = CacheKey.cacheKey(CacheModuleConst.Department.DEPARTMENT_TREE_CACHE); String cacheKey = CacheKey.cacheKey(CacheModuleConst.Department.DEPARTMENT_TREE_CACHE);
List<DepartmentTreeVO> treeVOList = beanCache.get(cacheKey); 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); String cacheKey = CacheKey.cacheKey(CacheModuleConst.Department.DEPARTMENT_TREE_CACHE);
List<DepartmentTreeVO> treeVOList = beanCache.get(cacheKey); List<DepartmentTreeVO> treeVOList = beanCache.get(cacheKey);
if (CollectionUtils.isEmpty(treeVOList)) { if (CollectionUtils.isEmpty(treeVOList)) {
return ResponseDTO.succData(Lists.newArrayList()); return ResponseDTO.ok(Lists.newArrayList());
} }
// 获取全部员工列表 // 获取全部员工列表
List<EmployeeDTO> employeeList = employeeDao.listAll(); List<EmployeeDTO> employeeList = employeeDao.listAll();
if (CollectionUtils.isEmpty(employeeList)) { 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)); Map<Long, List<EmployeeDTO>> employeeMap = employeeList.stream().collect(Collectors.groupingBy(EmployeeDTO::getDepartmentId));
//构建各部门的员工信息 //构建各部门的员工信息
List<DepartmentEmployeeTreeVO> departmentEmployeeTreeVOList = this.buildTreeEmployee(treeVOList, employeeMap); 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); departmentVOList = this.filterDepartment(departmentVOList, departmentName);
} }
List<DepartmentTreeVO> result = departmentTreeService.buildTree(departmentVOList); List<DepartmentTreeVO> result = departmentTreeService.buildTree(departmentVOList);
return ResponseDTO.succData(result); return ResponseDTO.ok(result);
} }
/** /**
@ -194,7 +194,7 @@ public class DepartmentService {
departmentService.addDepartmentHandle(departmentEntity); departmentService.addDepartmentHandle(departmentEntity);
this.clearTreeCache(); this.clearTreeCache();
this.clearSelfAndChildrenIdCache(); this.clearSelfAndChildrenIdCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -219,17 +219,17 @@ public class DepartmentService {
*/ */
public ResponseDTO<String> updateDepartment(DepartmentUpdateDTO updateDTO) { public ResponseDTO<String> updateDepartment(DepartmentUpdateDTO updateDTO) {
if (updateDTO.getParentId() == null) { if (updateDTO.getParentId() == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "父级部门id不能为空"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "父级部门id不能为空");
} }
DepartmentEntity entity = departmentDao.selectById(updateDTO.getId()); DepartmentEntity entity = departmentDao.selectById(updateDTO.getId());
if (entity == null) { if (entity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentEntity departmentEntity = SmartBeanUtil.copy(updateDTO, DepartmentEntity.class); DepartmentEntity departmentEntity = SmartBeanUtil.copy(updateDTO, DepartmentEntity.class);
departmentEntity.setSort(entity.getSort()); departmentEntity.setSort(entity.getSort());
departmentDao.updateById(departmentEntity); departmentDao.updateById(departmentEntity);
this.clearTreeCache(); this.clearTreeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -243,24 +243,24 @@ public class DepartmentService {
public ResponseDTO<String> delDepartment(Long deptId) { public ResponseDTO<String> delDepartment(Long deptId) {
DepartmentEntity departmentEntity = departmentDao.selectById(deptId); DepartmentEntity departmentEntity = departmentDao.selectById(deptId);
if (null == departmentEntity) { if (null == departmentEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 是否有子级部门 // 是否有子级部门
int subDepartmentNum = departmentDao.countSubDepartment(deptId); int subDepartmentNum = departmentDao.countSubDepartment(deptId);
if (subDepartmentNum > 0) { if (subDepartmentNum > 0) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "请先删除子级部门"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请先删除子级部门");
} }
// 是否有未删除员工 // 是否有未删除员工
int employeeNum = employeeDao.countByDepartmentId(deptId, false); int employeeNum = employeeDao.countByDepartmentId(deptId, false);
if (employeeNum > 0) { if (employeeNum > 0) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "请先删除部门员工"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "请先删除部门员工");
} }
departmentDao.deleteById(deptId); departmentDao.deleteById(deptId);
// 清除缓存 // 清除缓存
this.clearTreeCache(); this.clearTreeCache();
this.clearSelfAndChildrenIdCache(); this.clearSelfAndChildrenIdCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -272,10 +272,10 @@ public class DepartmentService {
public ResponseDTO<DepartmentVO> getDepartmentById(Long departmentId) { public ResponseDTO<DepartmentVO> getDepartmentById(Long departmentId) {
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId); DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
if (departmentEntity == null) { if (departmentEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentVO departmentVO = SmartBeanUtil.copy(departmentEntity, DepartmentVO.class); 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() { public ResponseDTO<List<DepartmentVO>> listAll() {
List<DepartmentVO> departmentVOList = departmentDao.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) { public ResponseDTO<String> upOrDown(Long departmentId, Long swapId) {
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId); DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
if (departmentEntity == null) { if (departmentEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentEntity swapEntity = departmentDao.selectById(swapId); DepartmentEntity swapEntity = departmentDao.selectById(swapId);
if (swapEntity == null) { if (swapEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentEntity updateEntity = new DepartmentEntity(); DepartmentEntity updateEntity = new DepartmentEntity();
updateEntity.setId(departmentId); updateEntity.setId(departmentId);
@ -315,7 +315,7 @@ public class DepartmentService {
departmentService.upOrDownUpdate(updateEntity, swapEntity); departmentService.upOrDownUpdate(updateEntity, swapEntity);
//清除缓存 //清除缓存
this.clearTreeCache(); this.clearTreeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -339,10 +339,10 @@ public class DepartmentService {
public ResponseDTO<String> upgrade(Long departmentId) { public ResponseDTO<String> upgrade(Long departmentId) {
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId); DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
if (departmentEntity == null) { 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)) { 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()); DepartmentEntity parentEntity = departmentDao.selectById(departmentEntity.getParentId());
@ -352,7 +352,7 @@ public class DepartmentService {
departmentDao.updateById(updateEntity); departmentDao.updateById(updateEntity);
//清除缓存 //清除缓存
this.clearTreeCache(); this.clearTreeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -365,11 +365,11 @@ public class DepartmentService {
public ResponseDTO<String> downgrade(Long departmentId, Long preId) { public ResponseDTO<String> downgrade(Long departmentId, Long preId) {
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId); DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
if (departmentEntity == null) { if (departmentEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentEntity preEntity = departmentDao.selectById(preId); DepartmentEntity preEntity = departmentDao.selectById(preId);
if (preEntity == null) { if (preEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
DepartmentEntity updateEntity = new DepartmentEntity(); DepartmentEntity updateEntity = new DepartmentEntity();
updateEntity.setId(departmentId); updateEntity.setId(departmentId);
@ -377,7 +377,7 @@ public class DepartmentService {
departmentDao.updateById(updateEntity); departmentDao.updateById(updateEntity);
//清除缓存 //清除缓存
this.clearTreeCache(); this.clearTreeCache();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
@ -414,8 +414,8 @@ public class DepartmentService {
*/ */
public ResponseDTO<List<DepartmentVO>> querySchoolList() { public ResponseDTO<List<DepartmentVO>> querySchoolList() {
ResponseDTO<List<DepartmentTreeVO>> res = departmentTree(); ResponseDTO<List<DepartmentTreeVO>> res = departmentTree();
if (!res.isSuccess()) { if (!res.getOk()) {
return ResponseDTO.wrap(res); return ResponseDTO.error(res);
} }
List<DepartmentTreeVO> data = res.getData(); List<DepartmentTreeVO> data = res.getData();
// 拿到第二级部门列表 // 拿到第二级部门列表
@ -426,7 +426,7 @@ public class DepartmentService {
resList.addAll(SmartBeanUtil.copyList(children, DepartmentVO.class)); resList.addAll(SmartBeanUtil.copyList(children, DepartmentVO.class));
} }
} }
return ResponseDTO.succData(resList); return ResponseDTO.ok(resList);
} }
/** /**

View File

@ -2,7 +2,7 @@ package net.lab1024.smartadmin.service.module.system.employee;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists; 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.CacheModuleConst;
import net.lab1024.smartadmin.service.common.constant.CommonConst; import net.lab1024.smartadmin.service.common.constant.CommonConst;
import net.lab1024.smartadmin.service.common.constant.SystemConst; import net.lab1024.smartadmin.service.common.constant.SystemConst;
@ -119,7 +119,7 @@ public class EmployeeService {
List<EmployeeVO> employeeList = employeeDao.queryEmployee(pageParam, queryDTO); List<EmployeeVO> employeeList = employeeDao.queryEmployee(pageParam, queryDTO);
if (CollectionUtils.isEmpty(employeeList)) { if (CollectionUtils.isEmpty(employeeList)) {
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageParam, 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()); 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())); e.setRoleIdList(employeeRoleIdListMap.getOrDefault(e.getId(), Lists.newArrayList()));
}); });
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(pageParam, employeeList); 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); EmployeeDTO employeeDTO = employeeDao.getByLoginName(addDTO.getLoginName(), false, false);
if (null != employeeDTO) { if (null != employeeDTO) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "员工名称重复"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "员工名称重复");
} }
// 校验电话是否存在 // 校验电话是否存在
employeeDTO = employeeDao.getByPhone(addDTO.getPhone(), false); employeeDTO = employeeDao.getByPhone(addDTO.getPhone(), false);
if (null != employeeDTO) { if (null != employeeDTO) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "手机号已存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "手机号已存在");
} }
// 部门是否存在 // 部门是否存在
Long departmentId = addDTO.getDepartmentId(); Long departmentId = addDTO.getDepartmentId();
DepartmentEntity department = departmentDao.selectById(departmentId); DepartmentEntity department = departmentDao.selectById(departmentId);
if (department == null) { if (department == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "部门不存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "部门不存在");
} }
EmployeeEntity entity = SmartBeanUtil.copy(addDTO, EmployeeEntity.class); EmployeeEntity entity = SmartBeanUtil.copy(addDTO, EmployeeEntity.class);
@ -166,7 +166,7 @@ public class EmployeeService {
this.clearCacheByDepartmentId(departmentId); this.clearCacheByDepartmentId(departmentId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -179,20 +179,20 @@ public class EmployeeService {
Long employeeId = updateDTO.getId(); Long employeeId = updateDTO.getId();
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId); EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
if (null == employeeEntity) { if (null == employeeEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
Long departmentId = updateDTO.getDepartmentId(); Long departmentId = updateDTO.getDepartmentId();
DepartmentEntity departmentEntity = departmentDao.selectById(departmentId); DepartmentEntity departmentEntity = departmentDao.selectById(departmentId);
if (departmentEntity == null) { if (departmentEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
EmployeeDTO employeeDTO = employeeDao.getByLoginName(updateDTO.getLoginName(), false, false); EmployeeDTO employeeDTO = employeeDao.getByLoginName(updateDTO.getLoginName(), false, false);
if (null != employeeDTO && !Objects.equals(employeeDTO.getId(), employeeId)) { 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); employeeDTO = employeeDao.getByPhone(updateDTO.getLoginName(), false);
if (null != employeeDTO && !Objects.equals(employeeDTO.getId(), employeeId)) { 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.clearCacheByEmployeeId(employeeId);
this.clearCacheByDepartmentId(departmentId); this.clearCacheByDepartmentId(departmentId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -217,18 +217,18 @@ public class EmployeeService {
*/ */
public ResponseDTO<String> updateDisableFlag(Long employeeId) { public ResponseDTO<String> updateDisableFlag(Long employeeId) {
if (null == employeeId) { if (null == employeeId) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId); EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
if (null == employeeEntity) { if (null == employeeEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
employeeDao.updateDisableFlag(employeeId, !employeeEntity.getDisabledFlag()); employeeDao.updateDisableFlag(employeeId, !employeeEntity.getDisabledFlag());
this.clearCacheByEmployeeId(employeeId); this.clearCacheByEmployeeId(employeeId);
this.clearCacheByDepartmentId(employeeEntity.getDepartmentId()); this.clearCacheByDepartmentId(employeeEntity.getDepartmentId());
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -241,7 +241,7 @@ public class EmployeeService {
List<Long> employeeIdList = batchUpdateStatusDTO.getEmployeeIdList(); List<Long> employeeIdList = batchUpdateStatusDTO.getEmployeeIdList();
List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList); List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList);
if (employeeIdList.size() != employeeEntityList.size()) { if (employeeIdList.size() != employeeEntityList.size()) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
employeeDao.batchUpdateDisableFlag(employeeIdList, batchUpdateStatusDTO.getDisabledFlag()); employeeDao.batchUpdateDisableFlag(employeeIdList, batchUpdateStatusDTO.getDisabledFlag());
@ -251,7 +251,7 @@ public class EmployeeService {
this.clearCacheByEmployeeId(e.getId()); this.clearCacheByEmployeeId(e.getId());
this.clearCacheByDepartmentId(e.getDepartmentId()); this.clearCacheByDepartmentId(e.getDepartmentId());
}); });
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -262,11 +262,11 @@ public class EmployeeService {
*/ */
public ResponseDTO<String> batchUpdateDeleteFlag(List<Long> employeeIdList) { public ResponseDTO<String> batchUpdateDeleteFlag(List<Long> employeeIdList) {
if (CollectionUtils.isEmpty(employeeIdList)) { if (CollectionUtils.isEmpty(employeeIdList)) {
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
List<EmployeeEntity> employeeEntityList = employeeManager.listByIds(employeeIdList); List<EmployeeEntity> employeeEntityList = employeeManager.listByIds(employeeIdList);
if (CollectionUtils.isEmpty(employeeEntityList)) { if (CollectionUtils.isEmpty(employeeEntityList)) {
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
List<EmployeeEntity> deleteList = employeeIdList.stream().map(e -> { List<EmployeeEntity> deleteList = employeeIdList.stream().map(e -> {
// 更新删除 // 更新删除
@ -282,7 +282,7 @@ public class EmployeeService {
this.clearCacheByEmployeeId(e.getId()); this.clearCacheByEmployeeId(e.getId());
this.clearCacheByDepartmentId(e.getDepartmentId()); this.clearCacheByDepartmentId(e.getDepartmentId());
}); });
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -294,7 +294,7 @@ public class EmployeeService {
public ResponseDTO<String> deleteEmployeeById(Long employeeId) { public ResponseDTO<String> deleteEmployeeById(Long employeeId) {
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId); EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
if (null == employeeEntity) { if (null == employeeEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 更新删除 // 更新删除
EmployeeEntity updateEmployee = new EmployeeEntity(); EmployeeEntity updateEmployee = new EmployeeEntity();
@ -304,7 +304,7 @@ public class EmployeeService {
this.clearCacheByEmployeeId(employeeId); this.clearCacheByEmployeeId(employeeId);
this.clearCacheByDepartmentId(employeeEntity.getDepartmentId()); this.clearCacheByDepartmentId(employeeEntity.getDepartmentId());
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -317,7 +317,7 @@ public class EmployeeService {
List<Long> employeeIdList = updateDto.getEmployeeIdList(); List<Long> employeeIdList = updateDto.getEmployeeIdList();
List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList); List<EmployeeEntity> employeeEntityList = employeeDao.selectBatchIds(employeeIdList);
if (employeeIdList.size() != employeeEntityList.size()) { 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 -> { List<EmployeeEntity> updateList = employeeIdList.stream().map(e -> {
@ -334,7 +334,7 @@ public class EmployeeService {
this.clearCacheByEmployeeId(e.getId()); this.clearCacheByEmployeeId(e.getId());
this.clearCacheByDepartmentId(e.getDepartmentId()); this.clearCacheByDepartmentId(e.getDepartmentId());
}); });
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -357,7 +357,7 @@ public class EmployeeService {
// 更新数据 // 更新数据
employeeManager.updateEmployeeRole(employeeId, roleEmployeeList); employeeManager.updateEmployeeRole(employeeId, roleEmployeeList);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -370,18 +370,18 @@ public class EmployeeService {
Long employeeId = updatePwdDTO.getEmployeeId(); Long employeeId = updatePwdDTO.getEmployeeId();
EmployeeEntity employeeEntity = employeeDao.selectById(employeeId); EmployeeEntity employeeEntity = employeeDao.selectById(employeeId);
if (employeeEntity == null) { if (employeeEntity == null) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 校验原始密码 // 校验原始密码
String encryptPwd = getEncryptPwd(updatePwdDTO.getOldPwd()); String encryptPwd = getEncryptPwd(updatePwdDTO.getOldPwd());
if (!Objects.equals(encryptPwd, employeeEntity.getLoginPwd())) { if (!Objects.equals(encryptPwd, employeeEntity.getLoginPwd())) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
// 新旧密码相同 // 新旧密码相同
String newPwd = updatePwdDTO.getPwd(); String newPwd = updatePwdDTO.getPwd();
if (Objects.equals(updatePwdDTO.getOldPwd(), newPwd)) { if (Objects.equals(updatePwdDTO.getOldPwd(), newPwd)) {
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
// 更新密码 // 更新密码
@ -390,7 +390,7 @@ public class EmployeeService {
updateEntity.setLoginPwd(getEncryptPwd(newPwd)); updateEntity.setLoginPwd(getEncryptPwd(newPwd));
employeeDao.updateById(updateEntity); 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()); String cacheKey = CacheKey.cacheKey(CacheModuleConst.Employee.DEPARTMENT_EMPLOYEE_CACHE, departmentId.toString());
List<EmployeeEntity> employeeEntityList = beanCache.get(cacheKey); List<EmployeeEntity> employeeEntityList = beanCache.get(cacheKey);
if (CollectionUtils.isEmpty(employeeEntityList)) { if (CollectionUtils.isEmpty(employeeEntityList)) {
return ResponseDTO.succData(CommonConst.EMPTY_LIST); return ResponseDTO.ok(CommonConst.EMPTY_LIST);
} }
List<EmployeeVO> voList = SmartBeanUtil.copyList(employeeEntityList, EmployeeVO.class); 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); List<EmployeeVO> employeeList = Lists.newArrayList(schoolEmployeeList);
recursionFindEmployee(employeeList, departmentList, departmentId); 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) { public ResponseDTO<String> resetPassword(Integer employeeId) {
String md5Password = getEncryptPwd(null); String md5Password = getEncryptPwd(null);
employeeDao.updatePassword(employeeId, md5Password); employeeDao.updatePassword(employeeId, md5Password);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -510,6 +510,6 @@ public class EmployeeService {
queryDTO.setDisabledFlag(disabledFlag); queryDTO.setDisabledFlag(disabledFlag);
} }
List<EmployeeVO> employeeList = employeeDao.queryEmployee(queryDTO); List<EmployeeVO> employeeList = employeeDao.queryEmployee(queryDTO);
return ResponseDTO.succData(employeeList); return ResponseDTO.ok(employeeList);
} }
} }

View File

@ -42,7 +42,7 @@ public class EmployeeLoginController extends AdminBaseController {
@ApiOperation("获取登录信息") @ApiOperation("获取登录信息")
public ResponseDTO<EmployeeLoginVO> getSession() { public ResponseDTO<EmployeeLoginVO> getSession() {
EmployeeLoginInfoDTO requestEmployee = SmartEmployeeTokenUtil.getRequestEmployee(); EmployeeLoginInfoDTO requestEmployee = SmartEmployeeTokenUtil.getRequestEmployee();
return ResponseDTO.succData(employeeLoginService.getSession(requestEmployee)); return ResponseDTO.ok(employeeLoginService.getSession(requestEmployee));
} }
@GetMapping("/logout") @GetMapping("/logout")

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.system.login; package net.lab1024.smartadmin.service.module.system.login;
import lombok.extern.slf4j.Slf4j; 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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.support.captcha.CaptchaService; import net.lab1024.smartadmin.service.module.support.captcha.CaptchaService;
@ -63,19 +63,19 @@ public class EmployeeLoginService {
CaptchaDTO captcha = loginDTO.getCaptcha(); CaptchaDTO captcha = loginDTO.getCaptcha();
if (null != captcha) { if (null != captcha) {
ResponseDTO<String> res = captchaService.checkCaptcha(captcha.getCaptchaId(), captcha.getCaptcha()); ResponseDTO<String> res = captchaService.checkCaptcha(captcha.getCaptchaId(), captcha.getCaptcha());
if (!res.isSuccess()) { if (!res.getOk()) {
return ResponseDTO.wrap(res); return ResponseDTO.error(res);
} }
} }
String loginPwd = EmployeeService.getEncryptPwd(loginDTO.getLoginPwd()); String loginPwd = EmployeeService.getEncryptPwd(loginDTO.getLoginPwd());
EmployeeEntity employeeEntity = employeeDao.selectByLoginNameAndPwd(loginDTO.getLoginName(), loginPwd, false); EmployeeEntity employeeEntity = employeeDao.selectByLoginNameAndPwd(loginDTO.getLoginName(), loginPwd, false);
if (null == employeeEntity) { if (null == employeeEntity) {
return ResponseDTO.wrap(EmployeeResponseCodeConst.LOGIN_FAILED); return ResponseDTO.error(UserErrorCode.LOGIN_FAILED);
} }
if (employeeEntity.getDisabledFlag()) { if (employeeEntity.getDisabledFlag()) {
return ResponseDTO.wrap(EmployeeResponseCodeConst.STATUS_ERROR); return ResponseDTO.error(UserErrorCode.USER_STATUS_ERROR);
} }
// 生成 登录token // 生成 登录token
@ -107,7 +107,7 @@ public class EmployeeLoginService {
loginResultDTO.setSchoolId(schoolIdByDepartment.getId()); loginResultDTO.setSchoolId(schoolIdByDepartment.getId());
loginResultDTO.setSchoolName(schoolIdByDepartment.getName()); 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) { public ResponseDTO<String> logoutByToken(Long employeeId) {
employeeService.clearCacheByEmployeeId(employeeId); employeeService.clearCacheByEmployeeId(employeeId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**

View File

@ -48,7 +48,7 @@ public class MenuController extends AdminBaseController {
@ApiOperation(value = "查询菜单列表") @ApiOperation(value = "查询菜单列表")
@GetMapping("/menu/query") @GetMapping("/menu/query")
public ResponseDTO<List<MenuVO>> queryMenuList() { public ResponseDTO<List<MenuVO>> queryMenuList() {
return ResponseDTO.succData(menuService.queryMenuList(null)); return ResponseDTO.ok(menuService.queryMenuList(null));
} }
@ApiOperation(value = "查询菜单详情") @ApiOperation(value = "查询菜单详情")

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.system.menu; package net.lab1024.smartadmin.service.module.system.menu;
import com.google.common.collect.Lists; 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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.system.menu.constant.MenuTypeEnum; import net.lab1024.smartadmin.service.module.system.menu.constant.MenuTypeEnum;
@ -47,7 +47,7 @@ public class MenuService {
public ResponseDTO<String> addMenu(MenuAddForm menuAddForm) { public ResponseDTO<String> addMenu(MenuAddForm menuAddForm) {
// 校验菜单名称 // 校验菜单名称
if (this.validateMenuName(menuAddForm)) { if (this.validateMenuName(menuAddForm)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单名称已存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单名称已存在");
} }
MenuEntity menuEntity = SmartBeanUtil.copy(menuAddForm, MenuEntity.class); MenuEntity menuEntity = SmartBeanUtil.copy(menuAddForm, MenuEntity.class);
// 处理接口权限 // 处理接口权限
@ -62,17 +62,17 @@ public class MenuService {
menuDao.insert(menuEntity); menuDao.insert(menuEntity);
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); menuEmployeeService.initRoleMenuListMap();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
// 若功能点列表不为空 // 若功能点列表不为空
ResponseDTO<List<MenuEntity>> responseDTO = this.validateBuildPointList(menuAddForm.getMenuType(), pointList); ResponseDTO<List<MenuEntity>> responseDTO = this.validateBuildPointList(menuAddForm.getMenuType(), pointList);
if (!responseDTO.isSuccess()) { if (!responseDTO.getOk()) {
return ResponseDTO.wrap(responseDTO); return ResponseDTO.error(responseDTO);
} }
menuManager.addMenu(menuEntity, responseDTO.getData()); menuManager.addMenu(menuEntity, responseDTO.getData());
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); menuEmployeeService.initRoleMenuListMap();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -85,17 +85,17 @@ public class MenuService {
//校验菜单是否存在 //校验菜单是否存在
MenuEntity selectMenu = menuDao.selectById(menuUpdateForm.getMenuId()); MenuEntity selectMenu = menuDao.selectById(menuUpdateForm.getMenuId());
if (selectMenu == null) { if (selectMenu == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单不存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单不存在");
} }
if (selectMenu.getDeleteFlag()) { if (selectMenu.getDeleteFlag()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单已被删除"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单已被删除");
} }
//校验菜单名称 //校验菜单名称
if (this.validateMenuName(menuUpdateForm)) { if (this.validateMenuName(menuUpdateForm)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "菜单名称已存在"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "菜单名称已存在");
} }
if (menuUpdateForm.getMenuId().equals(menuUpdateForm.getParentId())) { 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); MenuEntity menuEntity = SmartBeanUtil.copy(menuUpdateForm, MenuEntity.class);
// 处理接口权限 // 处理接口权限
@ -110,12 +110,12 @@ public class MenuService {
menuDao.updateById(menuEntity); menuDao.updateById(menuEntity);
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); menuEmployeeService.initRoleMenuListMap();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
//若功能点列表不为空 //若功能点列表不为空
ResponseDTO<List<MenuEntity>> validateBuildPointList = this.validateBuildPointList(menuUpdateForm.getMenuType(), pointList); ResponseDTO<List<MenuEntity>> validateBuildPointList = this.validateBuildPointList(menuUpdateForm.getMenuType(), pointList);
if (!validateBuildPointList.isSuccess()) { if (!validateBuildPointList.getOk()) {
return ResponseDTO.wrap(validateBuildPointList); return ResponseDTO.error(validateBuildPointList);
} }
List<MenuEntity> pointEntityList = validateBuildPointList.getData(); List<MenuEntity> pointEntityList = validateBuildPointList.getData();
//查询当前菜单下的功能点列表 //查询当前菜单下的功能点列表
@ -151,7 +151,7 @@ public class MenuService {
menuManager.updateMenu(menuEntity, savePointList, deletePointList, updatePointList); menuManager.updateMenu(menuEntity, savePointList, deletePointList, updatePointList);
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); 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) { private ResponseDTO<List<MenuEntity>> validateBuildPointList(Integer menuType, List<MenuPointsOperateForm> pointList) {
//判断 目录/功能点不能添加功能点 //判断 目录/功能点不能添加功能点
if (!MenuTypeEnum.MENU.equalsValue(menuType)) { if (!MenuTypeEnum.MENU.equalsValue(menuType)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "目录/功能点不能添加子功能点"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "目录/功能点不能添加子功能点");
} }
//构建功能点对象 //构建功能点对象
List<MenuEntity> pointEntityList = pointList.stream().map(e -> { 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())); 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()); List<String> repeatName = nameGroupBy.entrySet().stream().filter(e -> e.getValue() > 1).map(e -> e.getKey()).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(repeatName)) { 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) { public ResponseDTO<String> batchDeleteMenu(List<Long> menuIdList, Long employeeId) {
if (CollectionUtils.isEmpty(menuIdList)) { if (CollectionUtils.isEmpty(menuIdList)) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ERROR_PARAM, "所选菜单不能为空"); return ResponseDTO.error(UserErrorCode.PARAM_ERROR, "所选菜单不能为空");
} }
menuDao.deleteByMenuIdList(menuIdList, employeeId, Boolean.TRUE); menuDao.deleteByMenuIdList(menuIdList, employeeId, Boolean.TRUE);
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); menuEmployeeService.initRoleMenuListMap();
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -276,7 +276,7 @@ public class MenuService {
//根据ParentId进行分组 //根据ParentId进行分组
Map<Long, List<MenuVO>> parentMap = menuVOList.stream().collect(Collectors.groupingBy(MenuVO::getParentId, Collectors.toList())); Map<Long, List<MenuVO>> parentMap = menuVOList.stream().collect(Collectors.groupingBy(MenuVO::getParentId, Collectors.toList()));
List<MenuTreeVO> menuTreeVOList = this.buildMenuTree(parentMap, CommonConst.DEFAULT_PARENT_ID); 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); MenuEntity selectMenu = menuDao.selectById(menuId);
if (selectMenu == null) { if (selectMenu == null) {
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "菜单不存在"); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "菜单不存在");
} }
if (selectMenu.getDeleteFlag()) { if (selectMenu.getDeleteFlag()) {
return ResponseDTO.wrapMsg(ResponseCodeConst.SYSTEM_ERROR, "菜单已被删除"); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST, "菜单已被删除");
} }
MenuVO menuVO = SmartBeanUtil.copy(selectMenu, MenuVO.class); MenuVO menuVO = SmartBeanUtil.copy(selectMenu, MenuVO.class);
//处理接口权限 //处理接口权限
@ -323,7 +323,7 @@ public class MenuService {
List<String> permsList = Lists.newArrayList(StringUtils.split(perms, ",")); List<String> permsList = Lists.newArrayList(StringUtils.split(perms, ","));
menuVO.setPermsList(permsList); menuVO.setPermsList(permsList);
} }
return ResponseDTO.succData(menuVO); return ResponseDTO.ok(menuVO);
} }
/** /**
@ -333,6 +333,6 @@ public class MenuService {
*/ */
public ResponseDTO<List<RequestUrlVO>> getPrivilegeUrlDTOList() { public ResponseDTO<List<RequestUrlVO>> getPrivilegeUrlDTOList() {
List<RequestUrlVO> privilegeUrlList = requestUrlService.getPrivilegeList(); List<RequestUrlVO> privilegeUrlList = requestUrlService.getPrivilegeList();
return ResponseDTO.succData(privilegeUrlList); return ResponseDTO.ok(privilegeUrlList);
} }
} }

View File

@ -1,6 +1,6 @@
package net.lab1024.smartadmin.service.module.system.role.basic; 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.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.RoleAddDTO;
import net.lab1024.smartadmin.service.module.system.role.basic.domain.dto.RoleUpdateDTO; import net.lab1024.smartadmin.service.module.system.role.basic.domain.dto.RoleUpdateDTO;
@ -43,11 +43,11 @@ public class RoleService {
public ResponseDTO addRole(RoleAddDTO roleAddDTO) { public ResponseDTO addRole(RoleAddDTO roleAddDTO) {
RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleAddDTO.getRoleName()); RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleAddDTO.getRoleName());
if (null != employeeRoleEntity) { if (null != employeeRoleEntity) {
return ResponseDTO.wrapMsg(ResponseCodeConst.ALREADY_EXIST, "角色名称重复"); return ResponseDTO.error(UserErrorCode.ALREADY_EXIST, "角色名称重复");
} }
RoleEntity roleEntity = SmartBeanUtil.copy(roleAddDTO, RoleEntity.class); RoleEntity roleEntity = SmartBeanUtil.copy(roleAddDTO, RoleEntity.class);
roleDao.insert(roleEntity); roleDao.insert(roleEntity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -60,12 +60,12 @@ public class RoleService {
public ResponseDTO deleteRole(Long roleId) { public ResponseDTO deleteRole(Long roleId) {
RoleEntity roleEntity = roleDao.selectById(roleId); RoleEntity roleEntity = roleDao.selectById(roleId);
if (null == roleEntity) { if (null == roleEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
roleDao.deleteById(roleId); roleDao.deleteById(roleId);
roleMenuDao.deleteByRoleId(roleId); roleMenuDao.deleteByRoleId(roleId);
roleEmployeeDao.deleteByRoleId(roleId); roleEmployeeDao.deleteByRoleId(roleId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -78,15 +78,15 @@ public class RoleService {
public ResponseDTO<String> updateRole(RoleUpdateDTO roleUpdateDTO) { public ResponseDTO<String> updateRole(RoleUpdateDTO roleUpdateDTO) {
Long roleId = roleUpdateDTO.getId(); Long roleId = roleUpdateDTO.getId();
if (null == roleDao.selectById(roleId)) { if (null == roleDao.selectById(roleId)) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleUpdateDTO.getRoleName()); RoleEntity employeeRoleEntity = roleDao.getByRoleName(roleUpdateDTO.getRoleName());
if (null != employeeRoleEntity && !Objects.equals(employeeRoleEntity.getId(), roleId)) { 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); RoleEntity roleEntity = SmartBeanUtil.copy(roleUpdateDTO, RoleEntity.class);
roleDao.updateById(roleEntity); roleDao.updateById(roleEntity);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -98,10 +98,10 @@ public class RoleService {
public ResponseDTO<RoleVO> getRoleById(Long roleId) { public ResponseDTO<RoleVO> getRoleById(Long roleId) {
RoleEntity roleEntity = roleDao.selectById(roleId); RoleEntity roleEntity = roleDao.selectById(roleId);
if (null == roleEntity) { if (null == roleEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
RoleVO role = SmartBeanUtil.copy(roleEntity, RoleVO.class); 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() { public ResponseDTO<List<RoleVO>> getAllRole() {
List<RoleEntity> roleEntityList = roleDao.selectList(null); List<RoleEntity> roleEntityList = roleDao.selectList(null);
List<RoleVO> roleList = SmartBeanUtil.copyList(roleEntityList, RoleVO.class); List<RoleVO> roleList = SmartBeanUtil.copyList(roleEntityList, RoleVO.class);
return ResponseDTO.succData(roleList); return ResponseDTO.ok(roleList);
} }
} }

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.system.role.roleemployee; package net.lab1024.smartadmin.service.module.system.role.roleemployee;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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.constant.CacheModuleConst;
import net.lab1024.smartadmin.service.common.domain.PageResultDTO; import net.lab1024.smartadmin.service.common.domain.PageResultDTO;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
@ -65,13 +65,13 @@ public class RoleEmployeeService {
employeeDTO.setDepartmentName(departmentEntity.getName()); employeeDTO.setDepartmentName(departmentEntity.getName());
}); });
PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, employeeDTOS, EmployeeVO.class); PageResultDTO<EmployeeVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, employeeDTOS, EmployeeVO.class);
return ResponseDTO.succData(pageResultDTO); return ResponseDTO.ok(pageResultDTO);
} }
public ResponseDTO<List<EmployeeVO>> getAllEmployeeByRoleId(Long roleId) { public ResponseDTO<List<EmployeeVO>> getAllEmployeeByRoleId(Long roleId) {
List<EmployeeDTO> employeeDTOS = roleEmployeeDao.selectEmployeeByRoleId(roleId); List<EmployeeDTO> employeeDTOS = roleEmployeeDao.selectEmployeeByRoleId(roleId);
List<EmployeeVO> list = SmartBeanUtil.copyList(employeeDTOS, EmployeeVO.class); 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) @Transactional(rollbackFor = Exception.class)
public ResponseDTO<String> removeEmployeeRole(Long employeeId, Long roleId) { public ResponseDTO<String> removeEmployeeRole(Long employeeId, Long roleId) {
if (null == employeeId || null == roleId) { if (null == employeeId || null == roleId) {
return ResponseDTO.wrap(ResponseCodeConst.ERROR_PARAM); return ResponseDTO.error(UserErrorCode.PARAM_ERROR);
} }
roleEmployeeDao.deleteByEmployeeIdRoleId(employeeId, roleId); roleEmployeeDao.deleteByEmployeeIdRoleId(employeeId, roleId);
this.clearCacheByEmployeeId(employeeId); this.clearCacheByEmployeeId(employeeId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -102,7 +102,7 @@ public class RoleEmployeeService {
for (Long employeeId : removeDTO.getEmployeeIdList()) { for (Long employeeId : removeDTO.getEmployeeIdList()) {
this.clearCacheByEmployeeId(employeeId); this.clearCacheByEmployeeId(employeeId);
} }
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -126,7 +126,7 @@ public class RoleEmployeeService {
for (Long employeeId : employeeIdList) { for (Long employeeId : employeeIdList) {
this.clearCacheByEmployeeId(employeeId); this.clearCacheByEmployeeId(employeeId);
} }
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -140,7 +140,7 @@ public class RoleEmployeeService {
List<RoleEntity> roleList = roleDao.selectList(null); List<RoleEntity> roleList = roleDao.selectList(null);
List<RoleSelectedVO> result = SmartBeanUtil.copyList(roleList, RoleSelectedVO.class); List<RoleSelectedVO> result = SmartBeanUtil.copyList(roleList, RoleSelectedVO.class);
result.stream().forEach(item -> item.setSelected(roleIds.contains(item.getId()))); result.stream().forEach(item -> item.setSelected(roleIds.contains(item.getId())));
return ResponseDTO.succData(result); return ResponseDTO.ok(result);
} }
/** /**

View File

@ -1,7 +1,7 @@
package net.lab1024.smartadmin.service.module.system.role.rolemenu; package net.lab1024.smartadmin.service.module.system.role.rolemenu;
import com.google.common.collect.Lists; 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.constant.CommonConst;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.system.menu.MenuDao; import net.lab1024.smartadmin.service.module.system.menu.MenuDao;
@ -52,7 +52,7 @@ public class RoleMenuService {
Long roleId = updateDTO.getRoleId(); Long roleId = updateDTO.getRoleId();
RoleEntity roleEntity = roleDao.selectById(roleId); RoleEntity roleEntity = roleDao.selectById(roleId);
if (null == roleEntity) { if (null == roleEntity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
List<RoleMenuEntity> roleMenuEntityList = Lists.newArrayList(); List<RoleMenuEntity> roleMenuEntityList = Lists.newArrayList();
RoleMenuEntity roleMenuEntity; RoleMenuEntity roleMenuEntity;
@ -65,7 +65,7 @@ public class RoleMenuService {
roleMenuManager.updateRoleMenu(updateDTO.getRoleId(), roleMenuEntityList); roleMenuManager.updateRoleMenu(updateDTO.getRoleId(), roleMenuEntityList);
// 更新角色权限缓存 // 更新角色权限缓存
menuEmployeeService.initRoleMenuListMap(); 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())); Map<Long, List<MenuVO>> parentMap = menuVOList.stream().collect(Collectors.groupingBy(MenuVO::getParentId, Collectors.toList()));
List<MenuSimpleTreeVO> menuTreeList = this.buildMenuTree(parentMap, CommonConst.DEFAULT_PARENT_ID); List<MenuSimpleTreeVO> menuTreeList = this.buildMenuTree(parentMap, CommonConst.DEFAULT_PARENT_ID);
res.setMenuTreeList(menuTreeList); res.setMenuTreeList(menuTreeList);
return ResponseDTO.succData(res); return ResponseDTO.ok(res);
} }
/** /**

View File

@ -51,7 +51,7 @@ public class SystemConfigController extends SupportBaseController {
public ResponseDTO<SystemConfigVO> queryByKey(@RequestParam String configKey) { public ResponseDTO<SystemConfigVO> queryByKey(@RequestParam String configKey) {
SystemConfigDTO configDTO = systemConfigService.getConfig(configKey); SystemConfigDTO configDTO = systemConfigService.getConfig(configKey);
SystemConfigVO configVO = SmartBeanUtil.copy(configDTO, SystemConfigVO.class); SystemConfigVO configVO = SmartBeanUtil.copy(configDTO, SystemConfigVO.class);
return ResponseDTO.succData(configVO); return ResponseDTO.ok(configVO);
} }
} }

View File

@ -3,7 +3,7 @@ package net.lab1024.smartadmin.service.module.system.systemconfig;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j; 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.PageResultDTO;
import net.lab1024.smartadmin.service.common.domain.ResponseDTO; import net.lab1024.smartadmin.service.common.domain.ResponseDTO;
import net.lab1024.smartadmin.service.module.support.reload.core.anno.SmartReload; import net.lab1024.smartadmin.service.module.support.reload.core.anno.SmartReload;
@ -85,7 +85,7 @@ public class SystemConfigService {
Page page = SmartPageUtil.convert2PageQuery(queryDTO); Page page = SmartPageUtil.convert2PageQuery(queryDTO);
List<SystemConfigEntity> entityList = systemConfigDao.queryByPage(page, queryDTO); List<SystemConfigEntity> entityList = systemConfigDao.queryByPage(page, queryDTO);
PageResultDTO<SystemConfigVO> pageResultDTO = SmartPageUtil.convert2PageResult(page, entityList, SystemConfigVO.class); 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) { public ResponseDTO<String> add(SystemConfigAddDTO configAddDTO) {
SystemConfigEntity entity = systemConfigDao.selectByKey(configAddDTO.getConfigKey()); SystemConfigEntity entity = systemConfigDao.selectByKey(configAddDTO.getConfigKey());
if (null != entity) { if (null != entity) {
return ResponseDTO.wrap(ResponseCodeConst.ALREADY_EXIST); return ResponseDTO.error(UserErrorCode.ALREADY_EXIST);
} }
entity = SmartBeanUtil.copy(configAddDTO, SystemConfigEntity.class); entity = SmartBeanUtil.copy(configAddDTO, SystemConfigEntity.class);
systemConfigDao.insert(entity); systemConfigDao.insert(entity);
// 刷新缓存 // 刷新缓存
this.refreshConfigCache(entity.getConfigId()); this.refreshConfigCache(entity.getConfigId());
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -166,11 +166,11 @@ public class SystemConfigService {
Long configId = updateDTO.getConfigId(); Long configId = updateDTO.getConfigId();
SystemConfigEntity entity = systemConfigDao.selectById(configId); SystemConfigEntity entity = systemConfigDao.selectById(configId);
if (null == entity) { if (null == entity) {
return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS); return ResponseDTO.error(UserErrorCode.DATA_NOT_EXIST);
} }
SystemConfigEntity alreadyEntity = systemConfigDao.selectByKey(updateDTO.getConfigKey()); SystemConfigEntity alreadyEntity = systemConfigDao.selectByKey(updateDTO.getConfigKey());
if (null != alreadyEntity && !Objects.equals(configId, alreadyEntity.getConfigId())) { 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); this.refreshConfigCache(configId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
/** /**
@ -192,7 +192,7 @@ public class SystemConfigService {
public ResponseDTO<String> updateValueByKey(SystemConfigKeyEnum key, String value) { public ResponseDTO<String> updateValueByKey(SystemConfigKeyEnum key, String value) {
SystemConfigDTO config = this.getConfig(key); SystemConfigDTO config = this.getConfig(key);
if (null == config) { 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); this.refreshConfigCache(configId);
return ResponseDTO.succ(); return ResponseDTO.ok();
} }
} }