feat(gift): 修复赠礼事务并补充租户隔离
Some checks failed
Build and Push Backend / docker (push) Failing after 6s
Some checks failed
Build and Push Backend / docker (push) Failing after 6s
This commit is contained in:
@@ -2,6 +2,8 @@ package com.starry.admin.modules.custom.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.starry.admin.modules.custom.module.entity.PlayCustomGiftInfoEntity;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 顾客和礼物关系Mapper接口
|
||||
@@ -11,4 +13,20 @@ import com.starry.admin.modules.custom.module.entity.PlayCustomGiftInfoEntity;
|
||||
*/
|
||||
public interface PlayCustomGiftInfoMapper extends MPJBaseMapper<PlayCustomGiftInfoEntity> {
|
||||
|
||||
/**
|
||||
* 原子递增顾客礼物数量
|
||||
*
|
||||
* @param customId 顾客ID
|
||||
* @param giftId 礼物ID
|
||||
* @param tenantId 租户ID
|
||||
* @param delta 增量
|
||||
* @return 受影响行数
|
||||
*/
|
||||
@Update("UPDATE play_custom_gift_info "
|
||||
+ "SET giff_number = giff_number + #{delta} "
|
||||
+ "WHERE custom_id = #{customId} AND giff_id = #{giftId} "
|
||||
+ "AND (tenant_id = #{tenantId} OR tenant_id IS NULL)")
|
||||
int incrementGiftCount(@Param("customId") String customId, @Param("giftId") String giftId,
|
||||
@Param("tenantId") String tenantId, @Param("delta") long delta);
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public interface IPlayCustomGiftInfoService extends IService<PlayCustomGiftInfoE
|
||||
* 顾客IF
|
||||
* @return 顾客已点亮礼物列表
|
||||
*/
|
||||
List<PlayCustomGiftInfoEntity> selectBtyCustomId(String customId);
|
||||
List<PlayCustomGiftInfoEntity> selectByCustomId(String customId, String tenantId);
|
||||
|
||||
/**
|
||||
* 查询顾客和礼物关系
|
||||
@@ -69,6 +69,16 @@ public interface IPlayCustomGiftInfoService extends IService<PlayCustomGiftInfoE
|
||||
*/
|
||||
boolean update(PlayCustomGiftInfoEntity playCustomGiftInfo);
|
||||
|
||||
/**
|
||||
* 原子递增顾客礼物数量,无记录时按增量初始化
|
||||
*
|
||||
* @param customId 顾客ID
|
||||
* @param giftId 礼物ID
|
||||
* @param tenantId 租户ID
|
||||
* @param delta 增量
|
||||
*/
|
||||
void incrementGiftCount(String customId, String giftId, String tenantId, long delta);
|
||||
|
||||
/**
|
||||
* 批量删除顾客和礼物关系
|
||||
*
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.starry.common.utils.IdUtils;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -43,9 +44,12 @@ public class PlayCustomGiftInfoServiceImpl extends ServiceImpl<PlayCustomGiftInf
|
||||
* @return 店员活动礼物列表
|
||||
*/
|
||||
@Override
|
||||
public List<PlayCustomGiftInfoEntity> selectBtyCustomId(String customId) {
|
||||
public List<PlayCustomGiftInfoEntity> selectByCustomId(String customId, String tenantId) {
|
||||
LambdaQueryWrapper<PlayCustomGiftInfoEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(PlayCustomGiftInfoEntity::getCustomId, customId);
|
||||
if (StrUtil.isNotBlank(tenantId)) {
|
||||
lambdaQueryWrapper.eq(PlayCustomGiftInfoEntity::getTenantId, tenantId);
|
||||
}
|
||||
return this.baseMapper.selectList(lambdaQueryWrapper);
|
||||
}
|
||||
|
||||
@@ -101,6 +105,39 @@ public class PlayCustomGiftInfoServiceImpl extends ServiceImpl<PlayCustomGiftInf
|
||||
return updateById(playCustomGiftInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 原子递增顾客礼物数量,无记录时按增量初始化
|
||||
*
|
||||
* @param customId 顾客ID
|
||||
* @param giftId 礼物ID
|
||||
* @param tenantId 租户ID
|
||||
* @param delta 增量
|
||||
*/
|
||||
@Override
|
||||
public void incrementGiftCount(String customId, String giftId, String tenantId, long delta) {
|
||||
if (delta <= 0) {
|
||||
throw new IllegalArgumentException("delta must be positive");
|
||||
}
|
||||
int updated = playCustomGiftInfoMapper.incrementGiftCount(customId, giftId, tenantId, delta);
|
||||
if (updated == 0) {
|
||||
PlayCustomGiftInfoEntity entity = new PlayCustomGiftInfoEntity();
|
||||
entity.setId(IdUtils.getUuid());
|
||||
entity.setCustomId(customId);
|
||||
entity.setTenantId(tenantId);
|
||||
entity.setGiffId(giftId);
|
||||
entity.setGiffNumber(delta);
|
||||
boolean inserted = false;
|
||||
try {
|
||||
inserted = this.save(entity);
|
||||
} catch (DuplicateKeyException ex) {
|
||||
// ignore and retry update below
|
||||
}
|
||||
if (!inserted) {
|
||||
playCustomGiftInfoMapper.incrementGiftCount(customId, giftId, tenantId, delta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除顾客和礼物关系
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user