优化
This commit is contained in:
		| @ -0,0 +1,36 @@ | ||||
| package cn.iocoder.yudao.module.member.api.card; | ||||
|  | ||||
| import cn.hutool.core.util.ObjectUtil; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.card.CardDO; | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.rechargeamount.RechargeAmountDO; | ||||
| import cn.iocoder.yudao.module.member.service.card.CardService; | ||||
| import cn.iocoder.yudao.module.member.service.rechargeamount.RechargeAmountService; | ||||
| import org.springframework.stereotype.Service; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
| import java.math.BigDecimal; | ||||
|  | ||||
| /** | ||||
|  * @author zt | ||||
|  * @description <description class purpose> | ||||
|  * @since 2024/10/9 | ||||
|  */ | ||||
| @Service | ||||
| public class CardApiImpl implements CardApi{ | ||||
|     @Resource | ||||
|     private CardService cardService; | ||||
|     @Resource | ||||
|     private RechargeAmountService rechargeAmountService; | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     public Boolean recharge(BigDecimal money){ | ||||
|         RechargeAmountDO recharge = rechargeAmountService.getRecharge(money); | ||||
|         BigDecimal giftMoney = BigDecimal.ZERO; | ||||
|         if(ObjectUtil.isNotEmpty(recharge.getDonateMoney())){ | ||||
|             giftMoney = giftMoney.add(recharge.getDonateMoney()); | ||||
|         } | ||||
|         money = money.divide(new BigDecimal("100")); | ||||
|         return cardService.recharge(money, CardDO.ADD,giftMoney); | ||||
|     } | ||||
| } | ||||
| @ -100,7 +100,8 @@ public class AppCardController { | ||||
|     //@PreAuthorize("@ss.hasPermission('member:card:update')") | ||||
|     public CommonResult<Boolean> recharge(BigDecimal money,BigDecimal giftMoney) { | ||||
|         //BigDecimal bigDecimal = money.divide(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP); | ||||
|         return success(cardService.recharge(money,CardDO.ADD,giftMoney)); | ||||
|         //cardService.recharge(money,CardDO.ADD,giftMoney); | ||||
|         return success(true); | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
| @ -6,6 +6,7 @@ import cn.iocoder.yudao.module.member.controller.admin.rechargeamount.vo.Recharg | ||||
| import cn.iocoder.yudao.module.member.dal.dataobject.rechargeamount.RechargeAmountDO; | ||||
|  | ||||
| import javax.validation.Valid; | ||||
| import java.math.BigDecimal; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
| @ -55,4 +56,5 @@ public interface RechargeAmountService { | ||||
|  | ||||
|     List<RechargeAmountDO> getAmount(); | ||||
|  | ||||
|     RechargeAmountDO getRecharge(BigDecimal money); | ||||
| } | ||||
| @ -1,5 +1,6 @@ | ||||
| package cn.iocoder.yudao.module.member.service.rechargeamount; | ||||
|  | ||||
| import cn.hutool.core.collection.CollectionUtil; | ||||
| import cn.iocoder.yudao.framework.common.pojo.PageResult; | ||||
| import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||||
| import cn.iocoder.yudao.module.member.controller.admin.rechargeamount.vo.RechargeAmountPageReqVO; | ||||
| @ -11,10 +12,11 @@ import org.springframework.stereotype.Service; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
|  | ||||
| import javax.annotation.Resource; | ||||
|  | ||||
| import java.math.BigDecimal; | ||||
| import java.util.List; | ||||
|  | ||||
| import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||||
| import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.RECHARGE_AMOUNT_ALREADY_EXISTS; | ||||
| import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.RECHARGE_AMOUNT_NOT_EXISTS; | ||||
|  | ||||
| /** | ||||
| @ -34,6 +36,7 @@ public class RechargeAmountServiceImpl implements RechargeAmountService { | ||||
|         // 插入 | ||||
|         RechargeAmountDO rechargeAmount = BeanUtils.toBean(createReqVO, RechargeAmountDO.class); | ||||
|         rechargeAmountMapper.insert(rechargeAmount); | ||||
|         check(rechargeAmount.getMoney()); | ||||
|         // 返回 | ||||
|         return rechargeAmount.getId(); | ||||
|     } | ||||
| @ -78,4 +81,25 @@ public class RechargeAmountServiceImpl implements RechargeAmountService { | ||||
|                 .orderByAsc(RechargeAmountDO::getMoney)); | ||||
|         return list; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public RechargeAmountDO getRecharge(BigDecimal money) { | ||||
|         List<RechargeAmountDO> rechargeAmountDOS = rechargeAmountMapper.selectList(Wrappers.<RechargeAmountDO>lambdaQuery() | ||||
|                 .eq(RechargeAmountDO::getMoney, money) | ||||
|                 .eq(RechargeAmountDO::getStatus, RechargeAmountDO.ON) | ||||
|                 .orderByDesc(RechargeAmountDO::getCreateTime)); | ||||
|         if(CollectionUtil.isNotEmpty(rechargeAmountDOS)){ | ||||
|             return rechargeAmountDOS.get(0); | ||||
|         } | ||||
|         return new RechargeAmountDO(); | ||||
|     } | ||||
|  | ||||
|     public void check(BigDecimal money){ | ||||
|  | ||||
|         List<RechargeAmountDO> list =rechargeAmountMapper.selectList(Wrappers.<RechargeAmountDO>lambdaQuery() | ||||
|                 .eq(RechargeAmountDO::getMoney, money)); | ||||
|         if(CollectionUtil.isNotEmpty(list)){ | ||||
|             throw exception(RECHARGE_AMOUNT_ALREADY_EXISTS); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 zengtao01
					zengtao01