通用校验
This commit is contained in:
@@ -2,7 +2,6 @@ package com.czg.account.service;
|
|||||||
|
|
||||||
import com.czg.account.entity.ShopConfig;
|
import com.czg.account.entity.ShopConfig;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import com.czg.exception.CzgException;
|
|||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.service.IService;
|
import com.mybatisflex.core.service.IService;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -24,10 +24,10 @@ public interface ShopInfoService extends IService<ShopInfo> {
|
|||||||
/**
|
/**
|
||||||
* 检测开关
|
* 检测开关
|
||||||
* @param shopId 店铺id
|
* @param shopId 店铺id
|
||||||
* @param column ShopInfo的某列 开关
|
* @param switchGetter ShopInfo的某列 开关
|
||||||
* @return true:开启 false:关闭
|
* @return true:开启 false:关闭
|
||||||
*/
|
*/
|
||||||
<T> boolean checkSwitch(Long shopId, LambdaGetter<T> column) throws ValidateException;
|
<T> boolean checkSwitch(Long shopId, Function<ShopInfo, T> switchGetter) throws ValidateException;
|
||||||
|
|
||||||
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,16 @@
|
|||||||
package com.czg.utils;
|
package com.czg.utils;
|
||||||
|
|
||||||
import cn.hutool.core.text.NamingCase;
|
import cn.hutool.core.text.NamingCase;
|
||||||
import com.mybatisflex.annotation.Column;
|
|
||||||
import com.mybatisflex.core.constant.SqlConnector;
|
import com.mybatisflex.core.constant.SqlConnector;
|
||||||
import com.mybatisflex.core.query.*;
|
import com.mybatisflex.core.query.*;
|
||||||
import com.mybatisflex.core.table.TableInfo;
|
import com.mybatisflex.core.table.TableInfo;
|
||||||
import com.mybatisflex.core.table.TableInfoFactory;
|
import com.mybatisflex.core.table.TableInfoFactory;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
import com.mybatisflex.core.util.LambdaUtil;
|
|
||||||
import com.mybatisflex.core.util.MapUtil;
|
|
||||||
import com.mybatisflex.core.util.StringUtil;
|
import com.mybatisflex.core.util.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.lang.annotation.Annotation;
|
|
||||||
import java.lang.invoke.SerializedLambda;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|||||||
@@ -11,14 +11,9 @@ import com.czg.service.account.mapper.ShopConfigMapper;
|
|||||||
import com.czg.service.account.mapper.ShopInfoMapper;
|
import com.czg.service.account.mapper.ShopInfoMapper;
|
||||||
import com.czg.utils.PageUtil;
|
import com.czg.utils.PageUtil;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
import com.mybatisflex.core.util.LambdaGetter;
|
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.apache.dubbo.config.annotation.DubboService;
|
import org.apache.dubbo.config.annotation.DubboService;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,17 +101,17 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> boolean checkSwitch(Long shopId, LambdaGetter<T> column) throws ValidateException {
|
public <T> boolean checkSwitch(Long shopId, Function<ShopInfo, T> switchGetter) throws ValidateException {
|
||||||
AssertUtil.isNull(shopId, "店铺ID不能为空");
|
AssertUtil.isNull(shopId, "店铺ID不能为空");
|
||||||
ShopInfo shopInfo = getById(shopId);
|
ShopInfo shopInfo = getById(shopId);
|
||||||
AssertUtil.isNull(shopInfo, "店铺不存在");
|
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||||
|
T switchValue = switchGetter.apply(shopInfo);
|
||||||
|
|
||||||
String fieldName = LambdaUtil.getFieldName(column);
|
if (switchValue == null) {
|
||||||
Object fieldValue = ReflectUtil.getFieldValue(shopInfo, fieldName);
|
|
||||||
if (fieldValue == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return convertToBoolean(fieldValue, fieldName);
|
|
||||||
|
return convertToBoolean(switchValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShopInfo getShopInfo(Long shopId) {
|
private ShopInfo getShopInfo(Long shopId) {
|
||||||
@@ -496,7 +497,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean convertToBoolean(Object fieldValue, String fieldName) throws ValidateException {
|
private boolean convertToBoolean(Object fieldValue) throws ValidateException {
|
||||||
if (fieldValue instanceof Boolean) {
|
if (fieldValue instanceof Boolean) {
|
||||||
// Boolean 类型直接返回
|
// Boolean 类型直接返回
|
||||||
return (Boolean) fieldValue;
|
return (Boolean) fieldValue;
|
||||||
@@ -511,7 +512,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 不支持的类型抛异常
|
// 不支持的类型抛异常
|
||||||
throw new ValidateException("字段[" + fieldName + "]类型不支持,仅支持Boolean/Integer,当前类型:" + fieldValue.getClass().getSimpleName());
|
throw new ValidateException("字段类型不支持,仅支持Boolean/Integer,当前类型:" + fieldValue.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user