yanderong
2026-09-16 d4d70fe3a3a20f5fc29c9f37a1f89854a376597f
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
package com.ruoyi.account.mapper;
 
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.dto.ChargingCardExcelDTO;
import com.ruoyi.account.api.dto.ChargingCardQueryDTO;
import com.ruoyi.account.api.model.TChargingCard;
import org.apache.ibatis.annotations.Param;
 
import java.math.BigDecimal;
import java.util.List;
 
public interface TChargingCardMapper extends BaseMapper<TChargingCard> {
 
    IPage<TChargingCard> selectCardPage(Page<TChargingCard> page,
                                        @Param("query") ChargingCardQueryDTO query);
 
    List<ChargingCardExcelDTO> selectExportList(@Param("query") ChargingCardQueryDTO query);
 
    int countByCardNo(@Param("cardNo") String cardNo, @Param("excludeId") Long excludeId);
 
    int adjustBalance(@Param("ids") List<Long> ids,
                      @Param("amount") BigDecimal amount,
                      @Param("type") Integer type,
                      @Param("maxAmount") BigDecimal maxAmount,
                      @Param("updateBy") Long updateBy);
 
    int insertBalanceRecord(@Param("cardId") Long cardId,
                            @Param("type") Integer type,
                            @Param("amount") BigDecimal amount,
                            @Param("remark") String remark,
                            @Param("createBy") Long createBy);
 
    /**
     * 锁定卡片为充电中(条件更新:仅空闲卡可锁定,用于防止同卡并发多单)
     */
    int lockCardForCharging(@Param("cardId") Long cardId, @Param("orderCode") String orderCode);
 
    /**
     * 解锁卡片(带订单号比对,防止误释放其他订单)
     */
    int unlockCardForCharging(@Param("cardId") Long cardId, @Param("orderCode") String orderCode);
 
    /**
     * 订单结算原子扣款:仅按卡 ID 扣减,不限制余额下限,允许扣成负数(V0.2 定稿)
     */
    int deductBalanceByCardId(@Param("cardId") Long cardId, @Param("amount") BigDecimal amount);
 
    /**
     * 写入订单结算扣款流水并占用幂等键(charging_order_code 唯一索引)
     */
    int insertOrderDeductRecord(@Param("cardId") Long cardId,
                                @Param("amount") BigDecimal amount,
                                @Param("orderCode") String orderCode,
                                @Param("createBy") Long createBy);
 
    /**
     * 批量查询已存在的充电扣款流水订单号。
     */
    List<String> selectDeductedOrderCodes(@Param("orderCodes") List<String> orderCodes);
}