Merge remote-tracking branch 'origin/master'

This commit is contained in:
wangw 2025-03-24 10:26:32 +08:00
commit 78df4662ed
1 changed files with 32 additions and 0 deletions

View File

@ -1,9 +1,12 @@
package com.czg.controller.admin;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.NumberUtil;
import com.czg.account.dto.points.PointsBasicSettingDTO;
import com.czg.account.entity.PointsBasicSetting;
import com.czg.account.service.PointsBasicSettingService;
import com.czg.exception.CzgException;
import com.czg.log.annotation.OperationLog;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
@ -13,6 +16,8 @@ import com.czg.validator.group.InsertGroup;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
/**
* 积分基本设置
@ -50,6 +55,7 @@ public class PointsBasicSettingController {
Long shopId = StpKit.USER.getShopId(0L);
dto.setShopId(shopId);
ValidatorUtil.validateEntity(dto, InsertGroup.class, DefaultGroup.class);
validateDTO(dto);
PointsBasicSetting entity = BeanUtil.copyProperties(dto, PointsBasicSetting.class);
PointsBasicSetting record = pointsBasicSettingService.getById(shopId);
if (record == null) {
@ -60,5 +66,31 @@ public class PointsBasicSettingController {
return CzgResult.success();
}
private void validateDTO(PointsBasicSettingDTO dto) {
try {
Assert.notNull(dto.getShopId(), "{}({})不能为空", "店铺id", "shopId");
Assert.notNull(dto.getEnableRewards(), "{}({})不能为空", "开启消费赠送积分", "enableRewards");
Assert.notEmpty(dto.getRewardsGroup(), "{}({})不能为空", "赠积分适用群体", "rewardsGroup");
Assert.notNull(dto.getConsumeAmount(), "{}({})不能为空", "每消费xx元赠送1积分", "consumeAmount");
Assert.notNull(dto.getEnableDeduction(), "{}({})不能为空", "开启下单积分抵扣", "enableDeduction");
Assert.notEmpty(dto.getDeductionGroup(), "{}({})不能为空", "抵扣适用群体", "deductionGroup");
Assert.notNull(dto.getMinPaymentAmount(), "{}({})不能为空", "下单实付抵扣门槛", "minPaymentAmount");
Assert.notNull(dto.getMaxDeductionRatio(), "{}({})不能为空", "下单最高抵扣比例", "maxDeductionRatio");
Assert.notNull(dto.getEquivalentPoints(), "{}({})不能为空", "下单抵扣积分比例", "equivalentPoints");
Assert.notNull(dto.getEnablePointsMall(), "{}({})不能为空", "开启积分商城", "enablePointsMall");
Assert.notEmpty(dto.getBrowseMode(), "{}({})不能为空", "浏览模式", "browseMode");
} catch (IllegalArgumentException e) {
throw new CzgException(e.getMessage());
}
if (NumberUtil.isLessOrEqual(dto.getMinPaymentAmount(), BigDecimal.ZERO)) {
throw new CzgException("下单实付抵扣门槛不能小于等于0");
}
if (NumberUtil.isLessOrEqual(dto.getMaxDeductionRatio(), BigDecimal.ZERO)) {
throw new CzgException("下单最高抵扣比例不能小于等于0");
}
if (NumberUtil.isGreater(dto.getMaxDeductionRatio(), new BigDecimal("100"))) {
throw new CzgException("下单最高抵扣比例不能大于100");
}
}
}