review code.
This commit is contained in:
@@ -47,6 +47,8 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
ROLE_PRESENT(703, "角色 [{}] 不存在"),
|
||||
|
||||
DATA_ALTER(704, "数据发生改变, 请刷新后重试"),
|
||||
|
||||
// -------------------- 自定义 - 通用 --------------------
|
||||
|
||||
NETWORK_FLUCTUATION(900, "当前环境网路波动"),
|
||||
|
||||
@@ -17,6 +17,8 @@ public interface ErrorMessage {
|
||||
|
||||
String INVALID_PARAM = "参数验证失败";
|
||||
|
||||
String DATA_ABSENT = "数据不存在";
|
||||
|
||||
String DATA_PRESENT = "数据已存在";
|
||||
|
||||
String NAME_PRESENT = "名称已存在";
|
||||
@@ -33,16 +35,10 @@ public interface ErrorMessage {
|
||||
|
||||
String PARENT_MENU_ABSENT = "父菜单不存在";
|
||||
|
||||
String DATA_ABSENT = "数据不存在";
|
||||
|
||||
String USERNAME_PASSWORD_ERROR = "用户名或密码错误";
|
||||
|
||||
String MAX_LOGIN_FAILED = "登陆失败次数已上限";
|
||||
|
||||
String USER_ABSENT = "用户不存在";
|
||||
|
||||
String USER_DISABLED = "用户已被禁用";
|
||||
|
||||
String USER_LOCKED = "用户已被锁定";
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.orion.ops.framework.mybatis.core.query;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.orion.ops.framework.common.constant.ErrorMessage;
|
||||
import com.orion.ops.framework.common.utils.Valid;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -38,16 +40,31 @@ public class Conditions {
|
||||
}
|
||||
|
||||
/**
|
||||
* id list
|
||||
* eq
|
||||
*
|
||||
* @param idMapping idMapping
|
||||
* @param ids ids
|
||||
* @param <T> T
|
||||
* @param <ID> ID
|
||||
* @param mapping mapping
|
||||
* @param e e
|
||||
* @param <T> T
|
||||
* @param <E> E
|
||||
* @return wrapper
|
||||
*/
|
||||
public static <T, ID> LambdaQueryWrapper<T> id(SFunction<T, ID> idMapping, Collection<ID> ids) {
|
||||
return new ValidateLambdaWrapper<T>().in(idMapping, ids);
|
||||
public static <T, E> LambdaQueryWrapper<T> eq(SFunction<T, E> mapping, E e) {
|
||||
Valid.notNull(e, ErrorMessage.INVALID_PARAM);
|
||||
return new LambdaQueryWrapper<T>().eq(mapping, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* in
|
||||
*
|
||||
* @param mapping mapping
|
||||
* @param es es
|
||||
* @param <T> T
|
||||
* @param <E> E
|
||||
* @return wrapper
|
||||
*/
|
||||
public static <T, E> LambdaQueryWrapper<T> in(SFunction<T, E> mapping, Collection<E> es) {
|
||||
Valid.notEmpty(es, ErrorMessage.INVALID_PARAM);
|
||||
return new LambdaQueryWrapper<T>().in(mapping, es);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.lang.define.wrapper.IPageRequest;
|
||||
import com.orion.lang.define.wrapper.Pager;
|
||||
import com.orion.lang.utils.Objects1;
|
||||
import com.orion.lang.utils.Valid;
|
||||
import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.ops.framework.common.constant.Const;
|
||||
@@ -60,7 +61,7 @@ public class DataQuery<T> {
|
||||
}
|
||||
|
||||
public DataQuery<T> only() {
|
||||
this.wrapper.last(Const.LIMIT_1);
|
||||
wrapper.last(Const.LIMIT_1);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -68,29 +69,28 @@ public class DataQuery<T> {
|
||||
return dao.selectOne(wrapper);
|
||||
}
|
||||
|
||||
public Optional<T> optional() {
|
||||
return Optional.ofNullable(dao.selectOne(wrapper));
|
||||
public <R> R get(Function<T, R> mapper) {
|
||||
Valid.notNull(mapper, "convert function is null");
|
||||
return Objects1.map(dao.selectOne(wrapper), mapper);
|
||||
}
|
||||
|
||||
public <R> Optional<R> optional(Function<T, R> mapper) {
|
||||
Valid.notNull(mapper, "convert function is null");
|
||||
return Optional.ofNullable(dao.selectOne(wrapper))
|
||||
.map(mapper);
|
||||
public Optional<T> optional() {
|
||||
return Optional.ofNullable(dao.selectOne(wrapper));
|
||||
}
|
||||
|
||||
public List<T> list() {
|
||||
return dao.selectList(wrapper);
|
||||
}
|
||||
|
||||
public Stream<T> stream() {
|
||||
return dao.selectList(wrapper).stream();
|
||||
}
|
||||
|
||||
public <R> List<R> stream(Function<T, R> mapper) {
|
||||
public <R> List<R> list(Function<T, R> mapper) {
|
||||
Valid.notNull(mapper, "convert function is null");
|
||||
return Lists.map(dao.selectList(wrapper), mapper);
|
||||
}
|
||||
|
||||
public Stream<T> stream() {
|
||||
return dao.selectList(wrapper).stream();
|
||||
}
|
||||
|
||||
public Long count() {
|
||||
return dao.selectCount(wrapper);
|
||||
}
|
||||
|
||||
@@ -56,4 +56,6 @@ DELETE {{baseUrl}}/${package.ModuleName}/${typeHyphen}/delete-batch?idList=1,2,3
|
||||
Authorization: {{token}}
|
||||
|
||||
|
||||
${httpComment}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ${package.Controller};
|
||||
|
||||
import com.orion.lang.define.wrapper.DataGrid;
|
||||
import com.orion.ops.framework.common.annotation.IgnoreLog;
|
||||
import com.orion.ops.framework.common.annotation.RestWrapper;
|
||||
import ${package.Service}.*;
|
||||
#foreach($pkg in ${customFilePackages})
|
||||
@@ -57,6 +58,7 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.update${type}(request);
|
||||
}
|
||||
|
||||
@IgnoreLog
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "${apiComment.get}")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@@ -65,6 +67,7 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.get${type}(id);
|
||||
}
|
||||
|
||||
@IgnoreLog
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "${apiComment.list}")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@@ -73,6 +76,7 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.get${type}List(idList);
|
||||
}
|
||||
|
||||
@IgnoreLog
|
||||
@PostMapping("/query")
|
||||
@Operation(summary = "${apiComment.query}")
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:query')")
|
||||
@@ -80,7 +84,7 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.get${type}Page(request);
|
||||
}
|
||||
|
||||
@PutMapping("/delete")
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "${apiComment.delete}")
|
||||
@Parameter(name = "id", description = "id", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||
@@ -88,7 +92,7 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.delete${type}(id);
|
||||
}
|
||||
|
||||
@PutMapping("/delete-batch")
|
||||
@DeleteMapping("/delete-batch")
|
||||
@Operation(summary = "${apiComment.batchDelete}")
|
||||
@Parameter(name = "idList", description = "idList", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('${package.ModuleName}:${typeHyphen}:delete')")
|
||||
|
||||
@@ -122,7 +122,7 @@ public class GlobalExceptionHandler {
|
||||
IllegalArgumentException.class
|
||||
})
|
||||
public HttpWrapper<?> invalidArgumentExceptionHandler(Exception ex) {
|
||||
log.error("invalidArgumentExceptionHandler {}", ex.getMessage());
|
||||
log.error("invalidArgumentExceptionHandler {}", ex.getMessage(), ex);
|
||||
return ErrorCode.BAD_REQUEST.wrapper().msg(ex.getMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user