2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cn.iocoder.yudao.module.promotion.dal.mysql.point;
 
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.promotion.dal.dataobject.point.PointProductDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;
 
import java.util.Collection;
import java.util.List;
 
/**
 * 积分商城商品 Mapper
 *
 * @author HUIHUI
 */
@Mapper
public interface PointProductMapper extends BaseMapperX<PointProductDO> {
 
    default List<PointProductDO> selectListByActivityId(Collection<Long> activityIds) {
        return selectList(PointProductDO::getActivityId, activityIds);
    }
 
    default List<PointProductDO> selectListByActivityId(Long activityId) {
        return selectList(PointProductDO::getActivityId, activityId);
    }
 
    default void updateByActivityId(PointProductDO pointProductDO) {
        update(pointProductDO, new LambdaUpdateWrapper<PointProductDO>()
                .eq(PointProductDO::getActivityId, pointProductDO.getActivityId()));
    }
 
    default PointProductDO selectListByActivityIdAndSkuId(Long activityId, Long skuId) {
        return selectOne(PointProductDO::getActivityId, activityId,
                PointProductDO::getSkuId, skuId);
    }
 
    /**
     * 更新活动库存(减少)
     *
     * @param id    活动编号
     * @param count 扣减的库存数量(减少库存)
     * @return 影响的行数
     */
    default int updateStockDecr(Long id, int count) {
        Assert.isTrue(count > 0);
        return update(null, new LambdaUpdateWrapper<PointProductDO>()
                .eq(PointProductDO::getId, id)
                .ge(PointProductDO::getStock, count)
                .setSql("stock = stock - " + count));
    }
 
    /**
     * 更新活动库存(增加)
     *
     * @param id    活动编号
     * @param count 需要增加的库存(增加库存)
     * @return 影响的行数
     */
    default int updateStockIncr(Long id, int count) {
        Assert.isTrue(count > 0);
        return update(null, new LambdaUpdateWrapper<PointProductDO>()
                .eq(PointProductDO::getId, id)
                .setSql("stock = stock + " + count));
    }
}