rev:代码规范:去掉未使用的import与格式化
This commit is contained in:
@@ -61,7 +61,7 @@ public class RedisKeyDefine {
|
||||
private final KeyTypeEnum keyType;
|
||||
/**
|
||||
* Value 类型
|
||||
*
|
||||
* <p>
|
||||
* 如果是使用分布式锁,设置为 {@link java.util.concurrent.locks.Lock} 类型
|
||||
*/
|
||||
private final Class<?> valueType;
|
||||
@@ -100,7 +100,7 @@ public class RedisKeyDefine {
|
||||
|
||||
/**
|
||||
* 格式化 Key
|
||||
*
|
||||
* <p>
|
||||
* 注意,内部采用 {@link String#format(String, Object...)} 实现
|
||||
*
|
||||
* @param args 格式化的参数
|
||||
|
||||
@@ -37,31 +37,32 @@ public class BaseQuery<T> {
|
||||
|
||||
/**
|
||||
* 字段映射Map:指定字段对应QueryWrapper的查询类型
|
||||
* 字段与数据库字段对应,不支持驼峰
|
||||
* @see QueryTEnum
|
||||
* 字段与数据库字段对应,不支持驼峰
|
||||
*
|
||||
* @see QueryTEnum
|
||||
* 通过buid构建
|
||||
*/
|
||||
public Map<String, QParam> doP = MapOf.of("blurry", QParam.builder().k(new String[]{"name"}).type(QueryTEnum.LK).build()
|
||||
,"startTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LT).build()
|
||||
,"endTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LE).build()
|
||||
,"sort", QParam.builder().k(new String[]{"sort"}).type(QueryTEnum.BY).build()
|
||||
, "startTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LT).build()
|
||||
, "endTime", QParam.builder().k(new String[]{"create_time"}).type(QueryTEnum.LE).build()
|
||||
, "sort", QParam.builder().k(new String[]{"sort"}).type(QueryTEnum.BY).build()
|
||||
);
|
||||
|
||||
public QueryWrapper<T> build(){
|
||||
public QueryWrapper<T> build() {
|
||||
this.paramMapping();
|
||||
QueryWrapper<T> wrapper = new QueryWrapper<>();
|
||||
JSONObject json = (JSONObject)JSONObject.toJSON(this);
|
||||
JSONObject json = (JSONObject) JSONObject.toJSON(this);
|
||||
Type[] types = ((ParameterizedTypeImpl) this.getClass().getGenericSuperclass()).getActualTypeArguments();
|
||||
Map<String, ColumnCache> columnMap = LambdaUtils.getColumnMap((Class<?>) types[0]);
|
||||
json.forEach((key, vel) -> {
|
||||
if (vel != null && !key.equals("doP")){
|
||||
if (vel != null && !key.equals("doP")) {
|
||||
QParam qParam = doP.get(key);
|
||||
if (qParam != null){
|
||||
QueryTEnum.build(qParam.type,wrapper,qParam.k,vel);
|
||||
}else {
|
||||
if (qParam != null) {
|
||||
QueryTEnum.build(qParam.type, wrapper, qParam.k, vel);
|
||||
} else {
|
||||
ColumnCache columnCache = columnMap.get(LambdaUtils.formatKey(key));
|
||||
if (columnCache!=null){
|
||||
wrapper.eq(columnCache.getColumn(),vel);
|
||||
if (columnCache != null) {
|
||||
wrapper.eq(columnCache.getColumn(), vel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,5 +70,8 @@ public class BaseQuery<T> {
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
public void paramMapping(){};
|
||||
public void paramMapping() {
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/*
|
||||
* @author ZZQ
|
||||
* @Date 2022/12/14 8:40 下午
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LConsumer<X,Y,Z> {
|
||||
public interface LConsumer<X, Y, Z> {
|
||||
|
||||
void accept(X x,Y y,Z z);
|
||||
void accept(X x, Y y, Z z);
|
||||
|
||||
}
|
||||
|
||||
@@ -57,37 +57,37 @@ public class PageQuery implements Serializable {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
if (StringUtils.isNotEmpty(sort)) {
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
for (int i = 0; i < (split.length & ~1); i = i + 2) {
|
||||
String col = split[i];
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
item.setAsc(split[i + 1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public <R,T> Page<T> build(Class<R> r) {
|
||||
public <R, T> Page<T> build(Class<R> r) {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
if (StringUtils.isNotEmpty(sort)) {
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
for (int i = 0; i < (split.length & ~1); i = i + 2) {
|
||||
String col = split[i];
|
||||
if ("id".equals(col)){
|
||||
if ("id".equals(col)) {
|
||||
String mId = mappingId(r);
|
||||
col = StringUtils.isNotEmpty(mId)?mId:col;
|
||||
col = StringUtils.isNotEmpty(mId) ? mId : col;
|
||||
}
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
item.setAsc(split[i + 1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
|
||||
@@ -95,12 +95,12 @@ public class PageQuery implements Serializable {
|
||||
return page;
|
||||
}
|
||||
|
||||
private <R> String mappingId(R r){
|
||||
if (r instanceof Class){
|
||||
private <R> String mappingId(R r) {
|
||||
if (r instanceof Class) {
|
||||
Field[] fields = ((Class) r).getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
TableId[] byType = field.getAnnotationsByType(TableId.class);
|
||||
if (byType !=null && byType.length>0){
|
||||
if (byType != null && byType.length > 0) {
|
||||
TableId tableId = byType[0];
|
||||
return tableId.value();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package org.nl.common.domain.query;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.nl.common.enums.QueryTEnum;
|
||||
|
||||
/*
|
||||
|
||||
@@ -2,19 +2,21 @@ package org.nl.common.enums;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum LevelEnum{
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR;
|
||||
public static LevelEnum checkLevel(String level){
|
||||
if (!StringUtils.isEmpty(level)){
|
||||
for (LevelEnum value : LevelEnum.values()) {
|
||||
if (value.name().equals(level)){
|
||||
return value;
|
||||
};
|
||||
public enum LevelEnum {
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR;
|
||||
|
||||
public static LevelEnum checkLevel(String level) {
|
||||
if (!StringUtils.isEmpty(level)) {
|
||||
for (LevelEnum value : LevelEnum.values()) {
|
||||
if (value.name().equals(level)) {
|
||||
return value;
|
||||
}
|
||||
;
|
||||
}
|
||||
return LevelEnum.DEBUG;
|
||||
}
|
||||
return LevelEnum.DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,22 +14,46 @@ import java.util.Collection;
|
||||
@Getter
|
||||
public enum QueryTEnum {
|
||||
//
|
||||
EQ((q, k, v) -> { q.eq(k[0],v); }),
|
||||
IN((q, key, o) -> { if (o instanceof Collection){ q.in(key[0],(Collection) o); } }),
|
||||
LK((q, keys, o) -> { for (String key : keys) { q.like(key,o); } }),
|
||||
LE((q, k, v) -> { q.le(k[0],v); }),
|
||||
BY((q, k, v) -> { q.orderByDesc(k[0],v); }),
|
||||
NO((q, k, v) -> { q.isNull(k[0]); }),
|
||||
LT((q, k, v) -> { q.lt(k[0],v); }),
|
||||
OREQ((q, k, v) -> { if (StringUtils.isBlank((String)v)){ q.isNull(k[0]); }else { q.eq(k[0],v); } });
|
||||
EQ((q, k, v) -> {
|
||||
q.eq(k[0], v);
|
||||
}),
|
||||
IN((q, key, o) -> {
|
||||
if (o instanceof Collection) {
|
||||
q.in(key[0], (Collection) o);
|
||||
}
|
||||
}),
|
||||
LK((q, keys, o) -> {
|
||||
for (String key : keys) {
|
||||
q.like(key, o);
|
||||
}
|
||||
}),
|
||||
LE((q, k, v) -> {
|
||||
q.le(k[0], v);
|
||||
}),
|
||||
BY((q, k, v) -> {
|
||||
q.orderByDesc(k[0], v);
|
||||
}),
|
||||
NO((q, k, v) -> {
|
||||
q.isNull(k[0]);
|
||||
}),
|
||||
LT((q, k, v) -> {
|
||||
q.lt(k[0], v);
|
||||
}),
|
||||
OREQ((q, k, v) -> {
|
||||
if (StringUtils.isBlank((String) v)) {
|
||||
q.isNull(k[0]);
|
||||
} else {
|
||||
q.eq(k[0], v);
|
||||
}
|
||||
});
|
||||
|
||||
private LConsumer<QueryWrapper,String[], Object> doP;
|
||||
private LConsumer<QueryWrapper, String[], Object> doP;
|
||||
|
||||
QueryTEnum(LConsumer<QueryWrapper,String[], Object> doP) {
|
||||
QueryTEnum(LConsumer<QueryWrapper, String[], Object> doP) {
|
||||
this.doP = doP;
|
||||
}
|
||||
|
||||
public static void build(QueryTEnum type, QueryWrapper q, String[] k , Object v){
|
||||
type.getDoP().accept(q,k,v);
|
||||
public static void build(QueryTEnum type, QueryWrapper q, String[] k, Object v) {
|
||||
type.getDoP().accept(q, k, v);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,40 +24,54 @@ public class AsyncHttpRequest {
|
||||
private String url;
|
||||
|
||||
public AsyncHttpRequest(String url) {
|
||||
this.url=url;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public static AsyncHttpRequest post(String url,String body){
|
||||
return new AsyncHttpRequest(url).body(body);
|
||||
};
|
||||
public static AsyncHttpRequest post(String url, String body) {
|
||||
return new AsyncHttpRequest(url).body(body);
|
||||
}
|
||||
|
||||
public static AsyncHttpRequest get(String url){
|
||||
;
|
||||
|
||||
public static AsyncHttpRequest get(String url) {
|
||||
return new AsyncHttpRequest(url).getEntity();
|
||||
};
|
||||
private AsyncHttpRequest getEntity(){
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private AsyncHttpRequest getEntity() {
|
||||
HttpGet httpGet = new HttpGet(this.url);
|
||||
this.httpbase = httpGet;
|
||||
return this;
|
||||
};
|
||||
private AsyncHttpRequest body(String body){
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private AsyncHttpRequest body(String body) {
|
||||
this.entity = new StringEntity(body, "UTF-8");
|
||||
this.entity.setContentType("application/json");
|
||||
HttpPost httpPost = new HttpPost(this.url);
|
||||
httpPost.setEntity(entity);
|
||||
this.httpbase = httpPost;
|
||||
return this;
|
||||
};
|
||||
public Future<HttpResponse> execute(FutureCallback<HttpResponse> callback){
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
public Future<HttpResponse> execute(FutureCallback<HttpResponse> callback) {
|
||||
CloseableHttpAsyncClient client = SpringContextHolder.getBean(CloseableHttpAsyncClient.class);
|
||||
Future<HttpResponse> execute = client.execute(httpbase, callback);
|
||||
return execute;
|
||||
};
|
||||
}
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
@Component
|
||||
class HttpAsyncClientInit{
|
||||
class HttpAsyncClientInit {
|
||||
|
||||
@Bean
|
||||
public CloseableHttpAsyncClient closeableHttpAsyncClient(){
|
||||
public CloseableHttpAsyncClient closeableHttpAsyncClient() {
|
||||
CloseableHttpAsyncClient aDefault = HttpAsyncClients.createDefault();
|
||||
aDefault.start();
|
||||
return aDefault;
|
||||
|
||||
@@ -6,15 +6,15 @@ package org.nl.common.utils;
|
||||
*/
|
||||
public class BaseCode {
|
||||
|
||||
static final char[] MySerials = new char[]{
|
||||
static final char[] MySerials = new char[]{
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
|
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p','q','r','s','t','u','v','w','x','y','z',
|
||||
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P','Q','R','S','T','U','V','W','X','Y','Z'};
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
|
||||
|
||||
public static final String intToChars(long n){
|
||||
public static final String intToChars(long n) {
|
||||
String s = "";
|
||||
if (n == 0) {
|
||||
s = "0";
|
||||
@@ -25,8 +25,8 @@ public class BaseCode {
|
||||
s = c + s;
|
||||
n = n / MySerials.length;
|
||||
}
|
||||
for (int x = s.length();x<5;x++){
|
||||
s="0"+s;
|
||||
for (int x = s.length(); x < 5; x++) {
|
||||
s = "0" + s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class CopyUtil {
|
||||
List<T> list = new ArrayList(sources.size());
|
||||
Iterator var3 = sources.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
while (var3.hasNext()) {
|
||||
Object source = var3.next();
|
||||
|
||||
try {
|
||||
|
||||
@@ -10,10 +10,10 @@ import java.util.HashMap;
|
||||
*/
|
||||
public class MapOf implements Serializable {
|
||||
|
||||
public static <K> HashMap of(K... key){
|
||||
public static <K> HashMap of(K... key) {
|
||||
HashMap map = new HashMap<>();
|
||||
for (int i = 0; i < (key.length & ~1); i=i+2) {
|
||||
map.put(key[i],key[i+1]);
|
||||
for (int i = 0; i < (key.length & ~1); i = i + 2) {
|
||||
map.put(key[i], key[i + 1]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ public class SecurityUtils {
|
||||
|
||||
/**
|
||||
* 获取系统用户部门Id
|
||||
*
|
||||
* @return 用户部门现在1:n,该方法禁用
|
||||
*/
|
||||
@Deprecated
|
||||
|
||||
Reference in New Issue
Block a user