通用校验
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
package com.czg.account.service;
|
package com.czg.account.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import com.czg.account.dto.PageDTO;
|
import com.czg.account.dto.PageDTO;
|
||||||
import com.czg.account.dto.shopinfo.*;
|
import com.czg.account.dto.shopinfo.*;
|
||||||
import com.czg.account.entity.ShopInfo;
|
import com.czg.account.entity.ShopInfo;
|
||||||
import com.czg.exception.CzgException;
|
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 java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
@@ -18,6 +20,15 @@ public interface ShopInfoService extends IService<ShopInfo> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
ShopInfo getById(Serializable id) throws CzgException;
|
ShopInfo getById(Serializable id) throws CzgException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测开关
|
||||||
|
* @param shopId 店铺id
|
||||||
|
* @param column ShopInfo的某列 开关
|
||||||
|
* @return true:开启 false:关闭
|
||||||
|
*/
|
||||||
|
<T> boolean checkSwitch(Long shopId, LambdaGetter<T> column) throws ValidateException;
|
||||||
|
|
||||||
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
Page<ShopInfo> get(PageDTO pageDTO, String shopName, Integer status, Integer isHeadShop);
|
||||||
|
|
||||||
Page<ShopInfo> getShopByMainId(PageDTO pageDTO, String shopName, Integer status);
|
Page<ShopInfo> getShopByMainId(PageDTO pageDTO, String shopName, Integer status);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.czg.service.account.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
|
import cn.hutool.core.util.ReflectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
import com.czg.account.dto.PageDTO;
|
import com.czg.account.dto.PageDTO;
|
||||||
@@ -30,6 +32,10 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
import com.mybatisflex.core.query.QueryWrapper;
|
import com.mybatisflex.core.query.QueryWrapper;
|
||||||
|
import com.mybatisflex.core.table.TableInfo;
|
||||||
|
import com.mybatisflex.core.table.TableInfoFactory;
|
||||||
|
import com.mybatisflex.core.util.LambdaGetter;
|
||||||
|
import com.mybatisflex.core.util.LambdaUtil;
|
||||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -41,6 +47,7 @@ import org.springframework.cache.annotation.Cacheable;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.invoke.SerializedLambda;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -84,7 +91,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
@Cacheable(key = "#id")
|
@Cacheable(key = "#id")
|
||||||
public ShopInfo getById(Serializable id) throws CzgException {
|
public ShopInfo getById(Serializable id) throws CzgException {
|
||||||
ShopInfo shopInfo = super.getById(id);
|
ShopInfo shopInfo = super.getById(id);
|
||||||
if(shopInfo == null){
|
if (shopInfo == null) {
|
||||||
throw new CzgException("店铺不存在");
|
throw new CzgException("店铺不存在");
|
||||||
}
|
}
|
||||||
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
|
ShopConfig shopConfig = shopConfigService.getById(shopInfo.getId());
|
||||||
@@ -92,6 +99,20 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
return shopInfo;
|
return shopInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> boolean checkSwitch(Long shopId, LambdaGetter<T> column) throws ValidateException {
|
||||||
|
AssertUtil.isNull(shopId, "店铺ID不能为空");
|
||||||
|
ShopInfo shopInfo = getById(shopId);
|
||||||
|
AssertUtil.isNull(shopInfo, "店铺不存在");
|
||||||
|
|
||||||
|
String fieldName = LambdaUtil.getFieldName(column);
|
||||||
|
Object fieldValue = ReflectUtil.getFieldValue(shopInfo, fieldName);
|
||||||
|
if (fieldValue == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return convertToBoolean(fieldValue, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
private ShopInfo getShopInfo(Long shopId) {
|
private ShopInfo getShopInfo(Long shopId) {
|
||||||
ShopInfo shopInfo = getById(shopId);
|
ShopInfo shopInfo = getById(shopId);
|
||||||
if (shopInfo == null) {
|
if (shopInfo == null) {
|
||||||
@@ -446,7 +467,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
q1.eq(ShopInfo::getId, mainShopId);
|
q1.eq(ShopInfo::getId, mainShopId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}else {
|
} else {
|
||||||
shopIdList.add(mainShopId);
|
shopIdList.add(mainShopId);
|
||||||
queryWrapper.in(ShopInfo::getId, shopIdList);
|
queryWrapper.in(ShopInfo::getId, shopIdList);
|
||||||
}
|
}
|
||||||
@@ -473,4 +494,24 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
|
|||||||
public List<Long> getShopIdList() {
|
public List<Long> getShopIdList() {
|
||||||
return mapper.getShopIdList();
|
return mapper.getShopIdList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private boolean convertToBoolean(Object fieldValue, String fieldName) throws ValidateException {
|
||||||
|
if (fieldValue instanceof Boolean) {
|
||||||
|
// Boolean 类型直接返回
|
||||||
|
return (Boolean) fieldValue;
|
||||||
|
} else if (fieldValue instanceof Integer intValue) {
|
||||||
|
// Integer 类型按 1/0 规则转换
|
||||||
|
if (intValue == 1) {
|
||||||
|
return true;
|
||||||
|
} else if (intValue == 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不支持的类型抛异常
|
||||||
|
throw new ValidateException("字段[" + fieldName + "]类型不支持,仅支持Boolean/Integer,当前类型:" + fieldValue.getClass().getSimpleName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.czg.service.market.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.czg.account.entity.ShopInfo;
|
||||||
import com.czg.account.service.ShopInfoService;
|
import com.czg.account.service.ShopInfoService;
|
||||||
import com.czg.market.dto.GbWareDTO;
|
import com.czg.market.dto.GbWareDTO;
|
||||||
import com.czg.market.dto.GbWareQueryParamDTO;
|
import com.czg.market.dto.GbWareQueryParamDTO;
|
||||||
@@ -30,6 +31,9 @@ public class GbWareServiceImpl extends ServiceImpl<GbWareMapper, GbWare> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) {
|
public Page<GbWare> getGbWarePage(GbWareQueryParamDTO param, Long shopId) {
|
||||||
|
if (!shopInfoService.checkSwitch(shopId, ShopInfo::getIsGroupBuy)) {
|
||||||
|
return new Page<>();
|
||||||
|
}
|
||||||
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
Long mainShopId = shopInfoService.getMainIdByShopId(shopId);
|
||||||
QueryWrapper queryWrapper = new QueryWrapper();
|
QueryWrapper queryWrapper = new QueryWrapper();
|
||||||
queryWrapper.eq(GbWare::getIsDel, 0)
|
queryWrapper.eq(GbWare::getIsDel, 0)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package com.czg.service.market.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.czg.BaseQueryParam;
|
import com.czg.BaseQueryParam;
|
||||||
|
import com.czg.account.entity.ShopInfo;
|
||||||
|
import com.czg.account.service.ShopInfoService;
|
||||||
import com.czg.market.entity.MkPointsGoods;
|
import com.czg.market.entity.MkPointsGoods;
|
||||||
import com.czg.market.entity.MkPointsUser;
|
import com.czg.market.entity.MkPointsUser;
|
||||||
import com.czg.market.entity.ShopCoupon;
|
import com.czg.market.entity.ShopCoupon;
|
||||||
@@ -15,6 +17,7 @@ import com.github.pagehelper.PageInfo;
|
|||||||
import com.mybatisflex.core.paginate.Page;
|
import com.mybatisflex.core.paginate.Page;
|
||||||
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.DubboReference;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -33,6 +36,8 @@ public class MkPointsGoodsServiceImpl extends ServiceImpl<MkPointsGoodsMapper, M
|
|||||||
private MkPointsUserService pointsUserService;
|
private MkPointsUserService pointsUserService;
|
||||||
@Resource
|
@Resource
|
||||||
private ShopCouponService shopCouponService;
|
private ShopCouponService shopCouponService;
|
||||||
|
@DubboReference
|
||||||
|
private ShopInfoService shopInfoService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<MkPointsGoods> getPointsGoodsPage(BaseQueryParam param, Long shopId) {
|
public Page<MkPointsGoods> getPointsGoodsPage(BaseQueryParam param, Long shopId) {
|
||||||
@@ -57,6 +62,7 @@ public class MkPointsGoodsServiceImpl extends ServiceImpl<MkPointsGoodsMapper, M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getPointsGoodsPageByUser(Integer page, Integer size, Long shopId, String goodsCategory, Long userId) {
|
public Map<String, Object> getPointsGoodsPageByUser(Integer page, Integer size, Long shopId, String goodsCategory, Long userId) {
|
||||||
|
// shopInfoService.checkSwitch(shopId, )
|
||||||
Map<String, Object> result = new HashMap<>(2);
|
Map<String, Object> result = new HashMap<>(2);
|
||||||
MkPointsUser pointsUser = pointsUserService.getPointsUser(shopId, null, userId);
|
MkPointsUser pointsUser = pointsUserService.getPointsUser(shopId, null, userId);
|
||||||
PageHelper.startPage(page, size);
|
PageHelper.startPage(page, size);
|
||||||
|
|||||||
Reference in New Issue
Block a user