1、充值赠送金值更新错误修复;2、组织余额接口新增查询可开票金额;

This commit is contained in:
gaoqr
2025-08-20 18:43:17 +08:00
parent 3f9cc7640a
commit a3371b691d
6 changed files with 55 additions and 19 deletions
@@ -4,9 +4,18 @@ import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.module.system.dal.dataobject.funds.purchase.PurchaseRecordDO;
import org.apache.ibatis.annotations.Mapper;
import java.math.BigDecimal;
/**
* 购买记录 Mapper
*/
@Mapper
public interface PurchaseRecordMapper extends BaseMapperX<PurchaseRecordDO> {
/**
* 查询机构下可开票的金额
*
* @param organId
* @return
*/
BigDecimal getInvoicingAmount(Long organId);
}
@@ -13,7 +13,7 @@ import com.cf.imes.module.executor.api.funds.ExecutorFundsApi;
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.AllOrganAmountRespVO;
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganAmountRespVO;
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO;
import com.cf.imes.module.system.controller.admin.funds.purchase.PurchaseService;
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
import com.cf.imes.module.system.controller.admin.funds.purchase.vo.OrgEarliestPurchaseProductRespVO;
import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO;
import com.cf.imes.module.system.dal.dataobject.funds.products.ProductsDetailDO;
@@ -63,38 +63,38 @@ public class OrganAmountServiceImpl implements OrganAmountService {
@Override
public OrganRechargeAmountRespVO recharge(Long organId, BigDecimal price, BigDecimal gift) {
OrganAmountDO organAmountDO = organAmountMapper.selectOne(new LambdaQueryWrapper<OrganAmountDO>().eq(OrganAmountDO::getOrganId, organId));
BigDecimal newAmount = organAmountDO.getAmount().add(price);
BigDecimal newGift = null;
if (ObjectUtil.isNotNull(gift)) {
newGift = organAmountDO.getGiftAmount().add(gift);
}
int updated = organAmountMapper.update(new LambdaUpdateWrapperX<OrganAmountDO>()
.eq(OrganAmountDO::getOrganId, organId)
.eq(OrganAmountDO::getVersion, organAmountDO.getVersion())
.setIfPresent(OrganAmountDO::getGiftAmount, gift)
.set(OrganAmountDO::getAmount, organAmountDO.getAmount().add(price))
.set(OrganAmountDO::getGiftAmount, newGift)
.set(OrganAmountDO::getAmount, newAmount)
.set(OrganAmountDO::getVersion, organAmountDO.getVersion() + 1));
// 1. 首次更新失败,认为出现并发,再查一次再更新
if (updated == 0) {
organAmountDO = organAmountMapper.selectOne(new LambdaQueryWrapper<OrganAmountDO>().eq(OrganAmountDO::getOrganId, organId));
newAmount = organAmountDO.getAmount().add(price);
newGift = organAmountDO.getGiftAmount().add(gift);
updated = organAmountMapper.update(new LambdaUpdateWrapperX<OrganAmountDO>()
.eq(OrganAmountDO::getOrganId, organId)
.eq(OrganAmountDO::getVersion, organAmountDO.getVersion())
.setIfPresent(OrganAmountDO::getGiftAmount, gift)
.set(OrganAmountDO::getAmount, organAmountDO.getAmount().add(price))
.set(OrganAmountDO::getGiftAmount, newGift)
.set(OrganAmountDO::getAmount, newAmount)
.set(OrganAmountDO::getVersion, organAmountDO.getVersion() + 1));
// 2. 第二次更新失败,资金表可能不存在
if (updated == 0) {
throw exception(ORGAN_RECHARGE_AMOUNT_UPDATE_ERROR);
} else {
// 可用余额:现金+赠送金+支付价格
BigDecimal availableAmount = organAmountDO.getAmount().add(price).add(organAmountDO.getGiftAmount());
// 现金余额:现金+支付价格
BigDecimal amount = organAmountDO.getAmount().add(price);
return new OrganRechargeAmountRespVO(availableAmount, amount, organAmountDO.getGiftAmount());
return new OrganRechargeAmountRespVO(newAmount.add(newGift), newAmount, newGift);
}
} else {
// 可用余额:现金+赠送金+支付价格
BigDecimal availableAmount = organAmountDO.getAmount().add(price).add(organAmountDO.getGiftAmount());
// 现金余额:现金+支付价格
BigDecimal amount = organAmountDO.getAmount().add(price);
return new OrganRechargeAmountRespVO(availableAmount, amount, organAmountDO.getGiftAmount());
return new OrganRechargeAmountRespVO(newAmount.add(newGift), newAmount, newGift);
}
}
@@ -169,6 +169,9 @@ public class OrganAmountServiceImpl implements OrganAmountService {
organAmountRespVO.setGiftDuration(productsDetailDO.getGiftDuration());
organAmountRespVO.setGiftDurationUnit(productsDetailDO.getGiftDurationUnit());
}
// 查询可开票金额
organAmountRespVO.setInvoiceableAmount(purchaseService.getInvoicingAmount(organId));
return organAmountRespVO;
}
@@ -1,8 +1,10 @@
package com.cf.imes.module.system.controller.admin.funds.purchase;
package com.cf.imes.module.system.service.funds.purchase;
import com.cf.imes.module.system.controller.admin.funds.purchase.vo.OrgEarliestPurchaseProductRespVO;
import com.cf.imes.module.system.dal.dataobject.funds.purchase.PurchaseRecordDO;
import java.math.BigDecimal;
/**
* @author 软件购买接口
*/
@@ -37,4 +39,12 @@ public interface PurchaseService {
* @return
*/
OrgEarliestPurchaseProductRespVO getOrgEarliestProductDetail(Long organId);
/**
* 查询可开票金额
*
* @param organId
* @return
*/
BigDecimal getInvoicingAmount(Long organId);
}
@@ -1,4 +1,4 @@
package com.cf.imes.module.system.controller.admin.funds.purchase;
package com.cf.imes.module.system.service.funds.purchase;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -12,6 +12,7 @@ import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
@@ -58,4 +59,9 @@ public class PurchaseServiceImpl implements PurchaseService {
}
return null;
}
@Override
public BigDecimal getInvoicingAmount(Long organId) {
return purchaseRecordMapper.getInvoicingAmount(organId);
}
}
@@ -26,7 +26,7 @@ import com.cf.imes.framework.pay.core.enums.order.PayOrderStatusRespEnum;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.system.controller.admin.funds.organamount.vo.OrganRechargeAmountRespVO;
import com.cf.imes.module.system.controller.admin.funds.products.vo.product.ProductProcessorRespVO;
import com.cf.imes.module.system.controller.admin.funds.purchase.PurchaseService;
import com.cf.imes.module.system.service.funds.purchase.PurchaseService;
import com.cf.imes.module.system.controller.admin.pay.vo.PayProductOrderUnifiedReqVO;
import com.cf.imes.module.system.controller.admin.pay.vo.PayRechargeOrderReqVO;
import com.cf.imes.module.system.dal.dataobject.funds.organamount.OrganAmountDO;
@@ -272,7 +272,7 @@ public class PayOrderServiceImpl implements PayOrderService {
* @return
*/
private BigDecimal calcGiftAmount(Long rechargeActivityId, BigDecimal rechargeAmount) {
BigDecimal totalGift = BigDecimal.ZERO;
BigDecimal totalGift = null;
if (ObjectUtil.isNull(rechargeActivityId)) {
return totalGift;
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.cf.imes.module.system.dal.mysql.funds.purchase.PurchaseRecordMapper">
<select id="getInvoicingAmount" resultType="java.math.BigDecimal">
select sum(account_balance_spent) from purchase_record
where organ_id = #{organId} and is_invocing = '${@com.cf.imes.module.system.enums.pay.InvoiceStatusEnum@INVOICABLE.status}';
</select>
</mapper>