ApiNotPrintException 改为 CzgException

This commit is contained in:
2025-11-13 17:15:11 +08:00
parent d05a52f98e
commit 134a7aae85
45 changed files with 199 additions and 385 deletions

View File

@@ -4,7 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.czg.constant.TableValueConstant;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkConsumeDiscountDTO;
import com.czg.market.entity.MkConsumeDiscountRandom;
import com.czg.market.vo.MkConsumeDiscountVO;
@@ -55,26 +55,26 @@ public class MkConsumeDiscountServiceImpl extends ServiceImpl<MkConsumeDiscountM
@CacheEvict(key = "#shopId")
public Boolean edit(Long shopId, MkConsumeDiscountDTO consumeDiscountDTO) {
if (consumeDiscountDTO.getRandomDiscountList() == null && consumeDiscountDTO.getDiscountAmount() == null) {
throw new ApiNotPrintException("优惠金额和随机优惠金额不能同时为空");
throw new CzgException("优惠金额和随机优惠金额不能同时为空");
}
MkConsumeDiscount consumeDiscount = getOne(new QueryWrapper().eq(MkConsumeDiscount::getShopId, shopId));
BeanUtil.copyProperties(consumeDiscountDTO, consumeDiscount);
if (TableValueConstant.ConsumeDiscount.DiscountType.RANDOM.getCode().equals(consumeDiscountDTO.getDiscountType())) {
if (consumeDiscountDTO.getRandomDiscountList() == null || consumeDiscountDTO.getRandomDiscountList().isEmpty()) {
throw new ApiNotPrintException("随机优惠金额不能为空");
throw new CzgException("随机优惠金额不能为空");
}
if (consumeDiscountDTO.getRandomDiscountList().stream().map(MkConsumeDiscountRandom::getProbability).reduce(BigDecimal.ZERO, BigDecimal::add).compareTo(new BigDecimal("100")) != 0) {
throw new ApiNotPrintException("随机概率综合必须为100%");
throw new CzgException("随机概率综合必须为100%");
}
consumeDiscount.setRandomDiscountList(JSONArray.toJSONString(consumeDiscountDTO.getRandomDiscountList()));
} else {
if (consumeDiscountDTO.getDiscountAmount() == null) {
throw new ApiNotPrintException("减免金额不能为空");
throw new CzgException("减免金额不能为空");
}
if (consumeDiscountDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0) {
throw new ApiNotPrintException("减免金额不能等于0");
throw new CzgException("减免金额不能等于0");
}
}

View File

@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
import com.czg.account.entity.ShopUser;
import com.czg.account.service.ShopUserService;
import com.czg.constant.TableValueConstant;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.market.entity.MkConsumeDiscountRandom;
import com.czg.market.service.MkConsumeDiscountService;
import com.czg.market.vo.MkConsumeDiscountVO;
@@ -20,10 +20,8 @@ import com.czg.market.service.MkShopConsumeDiscountRecordService;
import com.czg.service.market.mapper.MkShopConsumeDiscountRecordMapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.auth.v1alpha1.Ca;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@@ -56,19 +54,19 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
private MkConsumeDiscountVO canUse(Long shopId, Long userId) {
MkConsumeDiscountVO consumeDiscountVO = consumeDiscountService.detail(shopId);
if (consumeDiscountVO.getIsEnable() != 1) {
throw new ApiNotPrintException("新客立减未开启");
throw new CzgException("新客立减未开启");
}
DateTime now = DateUtil.date();
if (!now.isAfterOrEquals(DateUtil.date(consumeDiscountVO.getStartTime())) || !now.isBeforeOrEquals(DateUtil.date(consumeDiscountVO.getEndTime()))) {
throw new ApiNotPrintException("此时间段未开启新客立减");
throw new CzgException("此时间段未开启新客立减");
}
// 随机金额概率加起来是100
List<MkConsumeDiscountRandom> randomList = consumeDiscountVO.getRandomDiscountList();
if ("RANDOM".equals(consumeDiscountVO.getDiscountType()) && (randomList == null || randomList.isEmpty()) ){
throw new ApiNotPrintException("随机立减配置错误");
throw new CzgException("随机立减配置错误");
}
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
boolean exists = orderInfoService.exists(new QueryWrapper().eq(OrderInfo::getUserId, shopUser.getUserId())
@@ -117,7 +115,7 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
ShopUser shopUser = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getUserId, userId).eq(ShopUser::getSourceShopId, shopId));
boolean newUser = isNewUser(shopUser, shopId);
if (!newUser) {
// throw new ApiNotPrintException("新客立减仅新用户可用");
// throw new CzgException("新客立减仅新用户可用");
log.info("新客立减仅限新用户使用");
return null;
}
@@ -158,7 +156,7 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
// 随机金额概率加起来是100
List<MkConsumeDiscountRandom> randomList = consumeDiscountVO.getRandomDiscountList();
if (randomList == null || randomList.isEmpty()) {
throw new ApiNotPrintException("随机立减配置错误");
throw new CzgException("随机立减配置错误");
}
// 生成 1~100 的随机数
@@ -175,7 +173,7 @@ public class MkShopConsumeDiscountRecordServiceImpl extends ServiceImpl<MkShopCo
}
}
throw new ApiNotPrintException("随机立减计算失败");
throw new CzgException("随机立减计算失败");
} catch (Exception e) {
log.info(e.getMessage());
return null;

View File

@@ -7,7 +7,6 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.czg.constant.TableValueConstant;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.market.dto.*;
import com.czg.account.entity.*;
@@ -19,14 +18,12 @@ import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.sa.StpKit;
import com.czg.service.market.enums.OrderStatusEnums;
import com.czg.service.market.mapper.TbMemberConfigMapper;
import com.czg.utils.AssertUtil;
import com.czg.validator.ValidatorUtil;
import com.czg.validator.group.member.MemberLevelCycleRewardGroup;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
@@ -157,14 +154,14 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
BeanUtil.copyProperties(memberDTO, memberConfig);
if ((memberDTO.getConfigList() == null || memberDTO.getConfigList().isEmpty()) &&
(memberDTO.getConditionList() == null || memberDTO.getConditionList().isEmpty())) {
throw new ApiNotPrintException("会员开通方式必须选择一个");
throw new CzgException("会员开通方式必须选择一个");
}
if (memberDTO.getConfigList() != null && !memberDTO.getConfigList().isEmpty()) {
memberDTO.getConfigList().forEach(item -> {
if (item.getReward() == null && (item.getCouponList() == null || item.getCouponList().isEmpty())) {
throw new ApiNotPrintException("方案列表中赠送成长值和赠送优惠券不能同时为空");
throw new CzgException("方案列表中赠送成长值和赠送优惠券不能同时为空");
}
});
memberConfig.setConfigList(JSONObject.toJSONString(memberDTO.getConfigList()));
@@ -172,14 +169,14 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
// if (memberConfig.getConfigList() != null && !memberConfig.getConfigList().isEmpty() &&
// (memberConfig.getConditionList() != null || !memberConfig.getConditionList().isEmpty())) {
// throw new ApiNotPrintException("会员开通方式为单选条件");
// throw new CzgException("会员开通方式为单选条件");
// }
if (memberDTO.getConditionList() != null && !memberDTO.getConditionList().isEmpty()) {
// ArrayList<String> conditionList = CollUtil.newArrayList(conditionMap);
memberDTO.getConditionList().forEach(item -> {
if (!conditionMap.contains(item.getCode())) {
throw new ApiNotPrintException("条件列表中code值错误");
throw new CzgException("条件列表中code值错误");
}
});
// conditionList.forEach(item -> {
@@ -205,21 +202,21 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
private void checkLevelDto(Long shopId, MemberLevelDTO levelDTO) {
long count = levelConfigService.count(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId).eq(MemberLevelConfig::getName, levelDTO.getName()).ne(MemberLevelConfig::getId, levelDTO.getId()));
if (count > 0) {
throw new ApiNotPrintException("会员等级名称已存在");
throw new CzgException("会员等级名称已存在");
}
MemberLevelConfig lastConfig = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getShopId, shopId)
.lt(MemberLevelConfig::getId, levelDTO.getId())
.limit(1).orderBy(MemberLevelConfig::getExperienceValue, true).ne(MemberLevelConfig::getId, levelDTO.getId()));
if (lastConfig == null && levelDTO.getExperienceValue() > 0) {
throw new ApiNotPrintException("1级时本字段必须为0");
throw new CzgException("1级时本字段必须为0");
} else if (lastConfig != null && levelDTO.getExperienceValue() <= lastConfig.getExperienceValue()) {
throw new ApiNotPrintException("会员等级经验值必须大于上一等级经验值");
throw new CzgException("会员等级经验值必须大于上一等级经验值");
}
if (levelDTO.getIsCycleReward() == 1) {
if (levelDTO.getCycleRewardPoints() == null && (levelDTO.getCycleRewardCouponList() == null || levelDTO.getCycleRewardCouponList().isEmpty())) {
throw new ApiNotPrintException("周期奖励成长值和优惠券不能同时为空");
throw new CzgException("周期奖励成长值和优惠券不能同时为空");
}
ValidatorUtil.validateEntity(levelDTO, MemberLevelCycleRewardGroup.class);
@@ -242,7 +239,7 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
@Override
public Boolean editLevel(Long shopId, MemberLevelDTO levelDTO) {
MemberLevelConfig levelConfig = levelConfigService.getOne(new QueryWrapper().eq(MemberLevelConfig::getId, levelDTO.getId()).eq(MemberLevelConfig::getShopId, shopId));
Optional.ofNullable(levelConfig).orElseThrow(() -> new ApiNotPrintException("会员等级不存在"));
Optional.ofNullable(levelConfig).orElseThrow(() -> new CzgException("会员等级不存在"));
Integer oldVal = levelConfig.getExperienceValue();
checkLevelDto(shopId, levelDTO);
BeanUtil.copyProperties(levelDTO, levelConfig);
@@ -493,7 +490,7 @@ public class TbMemberConfigServiceImpl extends ServiceImpl<TbMemberConfigMapper,
shopUser.setEndTime(shopUser.getEndTime().plusYears(memberOrder.getCircleTime()));
break;
default:
throw new ApiNotPrintException("周期单位错误");
throw new CzgException("周期单位错误");
}
shopUser.setMemberName(memberOrder.getName());