admin
2025-04-20 24b1d8e38de30063e2fc8008265455da32e959b2
积分功能完善
1个文件已删除
2 文件已重命名
12个文件已修改
18个文件已添加
1355 ■■■■ 已修改文件
src/main/java/com/taoke/autopay/controller/admin/AdminAgentController.java 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/credit/CreditExchangeRecordMapper.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/credit/CreditSettingMapper.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/credit/ExchangeRateMapper.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/credit/UserCreditBalanceMapper.java 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/dao/credit/UserCreditRecordMapper.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/entity/credit/CreditExchangeRecord.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/entity/credit/CreditSetting.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/entity/credit/UserCreditBalance.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/entity/credit/UserCreditRecord.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/exception/UserCreditExchangeException.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/manager/ChannelAgentManager.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/manager/UserCreditExchangeManager.java 211 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/manager/UserCreditManager.java 57 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/CreditExchangeRecordService.java 50 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/CreditSettingService.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/ExchangeRateService.java 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/UserAlipayBindingService.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/UserCreditBalanceService.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/credit/UserCreditRecordService.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/WxUserSettingServiceImpl.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/CreditExchangeRecordServiceImpl.java 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/CreditSettingServiceImpl.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/ExchangeRateServiceImpl.java 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/UserAlipayBindingServiceImpl.java 45 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/UserCreditBalanceServiceImpl.java 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/service/impl/credit/UserCreditRecordServiceImpl.java 35 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/ehcache.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/CreditSettingMapper.xml 149 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ExchangeRateMapper.xml 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserAlipayBindingMapper.xml 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserCreditBalanceMapper.xml 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/credit/UserCreditBalanceMapper.xml 65 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/taoke/autopay/controller/admin/AdminAgentController.java
@@ -134,7 +134,7 @@
    public String addAgent(AdminChannelAgentVO vo) {
        try {
          ChannelAgent agent=  channelAgentManager.addAgent(vo);
            ChannelAgent agent=  channelAgentManager.addAgent(vo);
            return JsonUtil.loadTrueResult(agent);
        } catch (ChannelAgentException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
@@ -154,28 +154,28 @@
                .alipayName(StringUtil.isNullOrEmpty(vo.getAlipayName()) ? null : vo.getAlipayName())
                .shieldedAreas(vo.getShieldedAreas())
                .build();
            channelAgentService.updateSelective(agent);
            // 添加设置
            ChannelAgentSettings settings = ChannelAgentSettings.builder()
                    .id(agent.getId())
                    .startSubmitTime(StringUtil.isNullOrEmpty(vo.getStartSubmitTime()) ? null : vo.getStartSubmitTime())
                    .endSubmitTime(StringUtil.isNullOrEmpty(vo.getEndSubmitTime()) ? null : vo.getEndSubmitTime())
                    .maxKeyCountPerDay(StringUtil.isNullOrEmpty(vo.getMaxKeyCountPerDay()) ? null : Long.parseLong(vo.getMaxKeyCountPerDay()))
                    .maxPayMoneyPerDay(StringUtil.isNullOrEmpty(vo.getMaxPayMoneyPerDay()) ? null : new BigDecimal(vo.getMaxPayMoneyPerDay()))
                    .build();
            channelAgentSettingService.add(settings);
            // 添加分成比例设置
            if (!StringUtil.isNullOrEmpty(vo.getShareRatioInfos())) {
                JSONObject shareRatioData = JSONObject.fromObject(vo.getShareRatioInfos());
                for (Object key : shareRatioData.keySet()) {
                    String value = shareRatioData.optString(key.toString());
                    OrderChannelEnum channel = OrderChannelEnum.valueOf(key.toString());
                    if (!StringUtil.isNullOrEmpty(value)) {
                        channelAgentSharingRatioService.setShareRatio(ChannelAgentSharingRatio.builder().agengId(agent.getId()).orderChannel(channel).shareType(ChannelAgentSharingRatio.SHARE_TYPE_MONEY).shareValue(new BigDecimal(value)).build());
                    }
        channelAgentService.updateSelective(agent);
        // 添加设置
        ChannelAgentSettings settings = ChannelAgentSettings.builder()
                .id(agent.getId())
                .startSubmitTime(StringUtil.isNullOrEmpty(vo.getStartSubmitTime()) ? null : vo.getStartSubmitTime())
                .endSubmitTime(StringUtil.isNullOrEmpty(vo.getEndSubmitTime()) ? null : vo.getEndSubmitTime())
                .maxKeyCountPerDay(StringUtil.isNullOrEmpty(vo.getMaxKeyCountPerDay()) ? null : Long.parseLong(vo.getMaxKeyCountPerDay()))
                .maxPayMoneyPerDay(StringUtil.isNullOrEmpty(vo.getMaxPayMoneyPerDay()) ? null : new BigDecimal(vo.getMaxPayMoneyPerDay()))
                .build();
        channelAgentSettingService.add(settings);
        // 添加分成比例设置
        if (!StringUtil.isNullOrEmpty(vo.getShareRatioInfos())) {
            JSONObject shareRatioData = JSONObject.fromObject(vo.getShareRatioInfos());
            for (Object key : shareRatioData.keySet()) {
                String value = shareRatioData.optString(key.toString());
                OrderChannelEnum channel = OrderChannelEnum.valueOf(key.toString());
                if (!StringUtil.isNullOrEmpty(value)) {
                    channelAgentSharingRatioService.setShareRatio(ChannelAgentSharingRatio.builder().agengId(agent.getId()).orderChannel(channel).shareType(ChannelAgentSharingRatio.SHARE_TYPE_MONEY).shareValue(new BigDecimal(value)).build());
                }
            }
            return JsonUtil.loadTrueResult(agent);
        }
        return JsonUtil.loadTrueResult(agent);
    }
src/main/java/com/taoke/autopay/dao/credit/CreditExchangeRecordMapper.java
@@ -1,16 +1,18 @@
package com.taoke.autopay.dao.credit;
import java.lang.Long;
import java.lang.String;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.taoke.autopay.entity.credit.CreditExchangeRecord;
import lombok.Builder;
import org.yeshi.utils.mybatis.BaseMapper;
import java.util.Date;
import org.apache.ibatis.annotations.Param;
import com.taoke.autopay.entity.credit.CreditExchangeRecord;
import java.lang.Long;
import java.math.BigDecimal;
import java.util.List;
import org.springframework.stereotype.Repository;
@Repository
public interface CreditExchangeRecordMapper extends BaseMapper<CreditExchangeRecord> {
    CreditExchangeRecord selectByPrimaryKeyForUpdate(@Param("id") Long id);
@@ -19,6 +21,7 @@
    long count(@Param("query") DaoQuery query);
    @Builder
    public static class DaoQuery {
        public Long id;
        public Long uid;
src/main/java/com/taoke/autopay/dao/credit/CreditSettingMapper.java
New file
@@ -0,0 +1,43 @@
package com.taoke.autopay.dao.credit;
import java.util.Date;
import java.util.List;
import com.taoke.autopay.entity.credit.ExchangeRate;
import lombok.Builder;
import org.apache.ibatis.annotations.Param;
import com.taoke.autopay.entity.credit.CreditSetting;
import com.taoke.autopay.entity.credit.CreditSetting.CreditSettingType;
import org.springframework.stereotype.Repository;
import org.yeshi.utils.mybatis.BaseMapper;
@Repository
public interface CreditSettingMapper extends BaseMapper<CreditSetting> {
    int updateByPrimaryKeySelective(CreditSetting creditSetting);
    List<CreditSetting> selectByType(@Param("type") CreditSettingType type);
    List<CreditSetting> list(@Param("query") DaoQuery query);
    long count(@Param("query") DaoQuery query);
    @Builder
    public static class DaoQuery {
        public Long id;
        public CreditSettingType type;
        public String name;
        public String value;
        public Date minStartTime;
        public Date maxStartTime;
        public Date minEndTime;
        public Date maxEndTime;
        public Date minCreateTime;
        public Date maxCreateTime;
        public Date minUpdateTime;
        public Date maxUpdateTime;
        public long start;
        public int count;
        public List<String> sortList;
    }
}
src/main/java/com/taoke/autopay/dao/credit/ExchangeRateMapper.java
@@ -2,13 +2,15 @@
import java.lang.Long;
import java.util.Date;
import java.util.List;
import lombok.Builder;
import org.apache.ibatis.annotations.Param;
import com.taoke.autopay.entity.credit.ExchangeRate;
import org.yeshi.utils.mybatis.BaseMapper;
import java.util.List;
import org.springframework.stereotype.Repository;
@Repository
public interface ExchangeRateMapper extends BaseMapper<ExchangeRate> {
    ExchangeRate selectByPrimaryKeyForUpdate(@Param("id") Long id);
@@ -17,6 +19,7 @@
    long count(@Param("query") DaoQuery query);
    @Builder
    public static class DaoQuery {
        public Long id;
        public ExchangeRate.ExchangeType exchangeType;
src/main/java/com/taoke/autopay/dao/credit/UserCreditBalanceMapper.java
@@ -1,14 +1,14 @@
package com.taoke.autopay.dao.credit;
import java.lang.Long;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.taoke.autopay.entity.credit.UserCreditBalance;
import org.yeshi.utils.mybatis.BaseMapper;
import java.util.Date;
import java.lang.Long;
import com.taoke.autopay.entity.credit.UserCreditBalance;
import org.springframework.stereotype.Repository;
@Repository
public interface UserCreditBalanceMapper extends BaseMapper<UserCreditBalance> {
    UserCreditBalance selectByPrimaryKeyForUpdate(@Param("id") Long id);
@@ -19,7 +19,6 @@
    public static class DaoQuery {
        public Long id;
        public Long uid;
        public Integer creditBalance;
        public Date minCreateTime;
        public Date maxCreateTime;
@@ -29,4 +28,4 @@
        public int count;
        public List<String> sortList;
    }
}
}
src/main/java/com/taoke/autopay/dao/credit/UserCreditRecordMapper.java
@@ -1,13 +1,13 @@
package com.taoke.autopay.dao.credit;
import java.util.Date;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import com.taoke.autopay.entity.credit.UserCreditRecord;
import org.yeshi.utils.mybatis.BaseMapper;
import org.springframework.stereotype.Repository;
@Repository
public interface UserCreditRecordMapper extends BaseMapper<UserCreditRecord> {
    UserCreditRecord selectByPrimaryKeyForUpdate(@Param("id") Long id);
src/main/java/com/taoke/autopay/entity/credit/CreditExchangeRecord.java
@@ -1,16 +1,23 @@
package com.taoke.autopay.entity.credit;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.yeshi.utils.generater.mybatis.Column;
import org.yeshi.utils.generater.mybatis.Table;
import java.math.BigDecimal;
import lombok.Data;
import lombok.Builder;
import java.util.Date;
import org.yeshi.utils.generater.mybatis.Column;
@Data
@Builder
@Table(value = "table_credit_exchange_record")
public class CreditExchangeRecord {
    //未审核
    public final static int STATUS_NOT_VERIFY = 0;
    //已通过
    public final static int STATUS_PASSED = 1;
    //已拒绝
    public final static int STATUS_REJECT = 2;
    @Id
    @Column(name = "id")
@@ -50,6 +57,10 @@
    @Column(name = "update_time")
    private Date updateTime; // 更新时间
    // 新增默认构造函数
    public CreditExchangeRecord() {
    }
    public enum ExchangeType {
        FUND_EXCHANGE // 资金兑换
    }
src/main/java/com/taoke/autopay/entity/credit/CreditSetting.java
@@ -1,13 +1,14 @@
package com.taoke.autopay.entity.credit;
import lombok.Data;
import lombok.Builder;
import org.springframework.data.annotation.Id;
import org.yeshi.utils.generater.mybatis.Column;
import java.util.Date;
import org.yeshi.utils.generater.mybatis.Table;
import java.util.Date;
@Data
@Builder
@Table(value = "table_credit_setting")
public class CreditSetting {
@@ -46,6 +47,7 @@
    @Column(name = "update_time")
    private Date updateTime; // 更新时间
    // 新增默认构造函数
    public CreditSetting() {
    }
}
src/main/java/com/taoke/autopay/entity/credit/UserCreditBalance.java
@@ -1,14 +1,16 @@
package com.taoke.autopay.entity.credit;
import lombok.Data;
import org.springframework.data.annotation.Id;
import lombok.experimental.Tolerate;
import org.yeshi.utils.generater.mybatis.Column;
import org.yeshi.utils.generater.mybatis.Table;
import java.math.BigDecimal;
import lombok.Data;
import lombok.Builder;
import org.springframework.data.annotation.Id;
import org.yeshi.utils.generater.mybatis.Table;
import java.util.Date;
@Data
@Builder
@Table(value = "table_user_credit_balance")
public class UserCreditBalance {
@@ -17,11 +19,16 @@
    private Long id;
    @Column(name = "credit_balance")
    private BigDecimal creditBalance;
    private Integer creditBalance;
    @Column(name = "create_time")
    private Date createTime;
    @Column(name = "update_time")
    private Date updateTime;
    @Tolerate
    // 新增默认构造函数
    public UserCreditBalance() {
    }
}
src/main/java/com/taoke/autopay/entity/credit/UserCreditRecord.java
@@ -1,14 +1,15 @@
package com.taoke.autopay.entity.credit;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.yeshi.utils.generater.mybatis.Column;
import org.yeshi.utils.generater.mybatis.Table;
import org.springframework.data.annotation.Id;
import java.math.BigDecimal;
import org.yeshi.utils.generater.mybatis.Table;
import java.util.Date;
import lombok.Data;
import lombok.Builder;
@Data
@Builder
@Table(value = "table_user_credit_record")
public class UserCreditRecord {
@@ -50,11 +51,15 @@
    @Column(name = "update_time")
    private Date updateTime; // 更新时间
    // 新增默认构造函数
    public UserCreditRecord() {
    }
    // 新增:获取方式枚举
    public enum AcquisitionMethod {
        COMMAND_PAYMENT("口令代付");
        COMMAND_PAYMENT("口令代付"),
        EXCHANGE_RETURN("兑换退回")
        ;
        private final String description;
src/main/java/com/taoke/autopay/exception/UserCreditExchangeException.java
New file
@@ -0,0 +1,28 @@
package com.taoke.autopay.exception;
/**
 * @author hxh
 * @title: 兑换异常
 * @description: 兑换异常
 * @date 2024/6/14 18:46
 */
public class UserCreditExchangeException extends  Exception{
    public final static int CODE_COMMON =1;
    // 余额不足
    public final static int CODE_BALANCE_NOT_ENOUGH =10;
    // 兑换频次受限
    public final static int CODE_EXCHANGE_FREQUENCY_LIMIT =20;
    // 没有绑定支付宝
    public final static int CODE_NOT_BIND_ALIPAY_ACCOUNT =30;
    private int code;
    public int getCode() {
        return code;
    }
    public UserCreditExchangeException(int code, String msg){
        super(msg);
    }
}
src/main/java/com/taoke/autopay/manager/ChannelAgentManager.java
@@ -12,9 +12,6 @@
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
import javax.annotation.Resource;
src/main/java/com/taoke/autopay/manager/UserCreditExchangeManager.java
New file
@@ -0,0 +1,211 @@
package com.taoke.autopay.manager;
import com.taoke.autopay.dao.credit.CreditExchangeRecordMapper;
import com.taoke.autopay.dao.credit.ExchangeRateMapper;
import com.taoke.autopay.entity.credit.*;
import com.taoke.autopay.exception.UserCreditExchangeException;
import com.taoke.autopay.service.credit.*;
import com.taoke.autopay.utils.TimeUtil;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;
@Component
public class UserCreditExchangeManager {
    @Resource
    private UserCreditBalanceService userCreditBalanceService;
    @Resource
    private CreditExchangeRecordService userCreditExchangeRecordService;
    @Resource
    private UserAlipayBindingService userAlipayBindingService;
    @Resource
    private ExchangeRateService exchangeRateService;
    @Resource
    private CreditSettingService creditSettingService;
    @Resource
    private UserCreditRecordService userCreditRecordService;
    /**
     * 用户积分兑换
     *
     * @param request 兑换请求实体
     * @return 兑换记录ID
     */
    @Transactional(rollbackFor = Exception.class)
    public Long exchangeCredit(CreditExchangeRecord request) throws UserCreditExchangeException {
        Long userId = request.getUid();
        CreditExchangeRecord.ExchangeType exchangeType = request.getExchangeType();
        if(exchangeType!=CreditExchangeRecord.ExchangeType.FUND_EXCHANGE){
            throw  new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,"只支持红包兑换");
        }
        // 检查用户积分余额是否足够
        UserCreditBalance balance = userCreditBalanceService.getCreditBalanceByUserId(userId);
        if (balance == null || balance.getCreditBalance() <request.getConsumedCredits()) {
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_BALANCE_NOT_ENOUGH, "用户积分不足");
        }
        // 如果是红包兑换,判断用户兑换频率
        if (exchangeType == CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) {
            checkRedPacketExchangeFrequency(userId);
        }
        // 查询用户绑定的支付宝账户
        List<UserAlipayBinding> alipayBindings = userAlipayBindingService.getBindingsByUid(userId);
        if (alipayBindings == null|| alipayBindings.isEmpty()) {
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_NOT_BIND_ALIPAY_ACCOUNT, "用户未绑定支付宝账户");
        }
        CreditExchangeRecord exchangeRecord = new CreditExchangeRecord();
        if (exchangeType == CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) {
            // 计算可兑换金额(如果是红包兑换)
            BigDecimal exchangeAmount = calculateExchangeAmount(request.getUid(), request.getConsumedCredits());
            exchangeRecord.setExchangeValue(exchangeAmount);
        }
        // 扣减用户积分
        userCreditBalanceService.decreaseCreditBalance(userId, request.getConsumedCredits());
        // 记录兑换记录
        exchangeRecord.setUid(userId);
        exchangeRecord.setExchangeType(exchangeType);
        exchangeRecord.setConsumedCredits(request.getConsumedCredits());
        exchangeRecord.setCreditBalance(balance.getCreditBalance()-request.getConsumedCredits());
        exchangeRecord.setExchangeStatus(CreditExchangeRecord.STATUS_NOT_VERIFY);
        exchangeRecord.setExchangeStatusDescription("未审核");
        exchangeRecord.setExchangeInfo1(alipayBindings.get(0).getAlipayName()); // 设置支付宝账户
        exchangeRecord.setExchangeInfo2(alipayBindings.get(0).getAlipayAccount());
        exchangeRecord.setCreateTime(new Date());
        exchangeRecord.setUpdateTime(new Date());
        return userCreditExchangeRecordService.addExchangeRecord(exchangeRecord);
    }
    /**
     * 通过兑换
     *
     * @param exchangeRecordId 兑换记录ID
     */
    @Transactional(rollbackFor = Exception.class)
    public void approveExchange(Long exchangeRecordId) throws UserCreditExchangeException{
        CreditExchangeRecord exchangeRecord = userCreditExchangeRecordService.getExchangeRecordByIdForUpdate(exchangeRecordId);
        if (exchangeRecord == null) {
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_NOT_BIND_ALIPAY_ACCOUNT, "兑换记录不存在");
        }
        // 如果是红包兑换,调用通过兑换逻辑(TODO)
        if (exchangeRecord.getExchangeType() == CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) {
            // TODO: 调用通过兑换逻辑
        }
        // 改变兑换记录状态
        userCreditExchangeRecordService.updateExchangeRecord(CreditExchangeRecord.builder()
                        .id(exchangeRecordId)
                        .exchangeStatus(CreditExchangeRecord.STATUS_PASSED)
                        .exchangeStatusDescription("兑换已通过")
                        .updateTime(new Date())
                .build());
    }
    /**
     * 驳回兑换
     *
     * @param exchangeRecordId 兑换记录ID
     */
    @Transactional(rollbackFor = Exception.class)
    public void rejectExchange(Long exchangeRecordId) throws UserCreditExchangeException{
        CreditExchangeRecord exchangeRecord = userCreditExchangeRecordService.getExchangeRecordByIdForUpdate(exchangeRecordId);
        if (exchangeRecord == null) {
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_NOT_BIND_ALIPAY_ACCOUNT, "兑换记录不存在");
        }
        // 退回用户积分余额
        userCreditBalanceService.increaseCreditBalance(exchangeRecord.getUid(), exchangeRecord.getConsumedCredits());
        // 添加积分记录
        userCreditRecordService.addCreditRecord(UserCreditRecord.builder()
                .uid(exchangeRecord.getUid())
                .creditAmount(exchangeRecord.getConsumedCredits())
                .direction(UserCreditRecord.DIRECTION_GAIN)
                .identifierId(exchangeRecord.getId().toString())
                .acquisitionMethod(UserCreditRecord.AcquisitionMethod.EXCHANGE_RETURN)
                .description("兑换退回")
               .createTime(new Date())
                .updateTime(new Date()).build());
        userCreditExchangeRecordService.updateExchangeRecord(CreditExchangeRecord.builder()
                .id(exchangeRecordId)
                .exchangeStatus(CreditExchangeRecord.STATUS_REJECT)
                .exchangeStatusDescription("兑换已驳回")
                .updateTime(new Date())
                .build());
    }
    /**
     * 检查红包兑换频率
     *
     * @param userId 用户ID
     */
    private void checkRedPacketExchangeFrequency(Long userId) throws UserCreditExchangeException{
        //实现红包兑换频率检查逻辑
        // 获取今日兑换的次数
        long nowTimeStamp=System.currentTimeMillis();
        long count =  userCreditExchangeRecordService.countExchangeRecords(CreditExchangeRecordMapper.DaoQuery.builder()
                        .uid(userId)
                        .minCreateTime(new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(nowTimeStamp,"yyyyMMdd"),"yyyyMMdd")))
                        .maxCreateTime(new Date(nowTimeStamp))
                .build());
        CreditSetting setting =  creditSettingService.getSettingCacheByType(CreditSetting.CreditSettingType.DAILY_EXCHANGE_LIMIT, new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(nowTimeStamp,"yyyyMMddHHmm"),"yyyyMMddHHmm")));
        if(setting==null){
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_EXCHANGE_FREQUENCY_LIMIT,"兑换频率未设置");
        }
        if(count>=Integer.parseInt(setting.getValue())){
            throw new UserCreditExchangeException(UserCreditExchangeException.CODE_EXCHANGE_FREQUENCY_LIMIT, String.format("每天只能兑换%s次", setting.getValue()));
        }
    }
    /**
     * 计算兑换金额
     * @param uid
     * @param credit
     * @return
     */
    private BigDecimal calculateExchangeAmount(Long uid, int credit) throws UserCreditExchangeException{
        long count =  userCreditExchangeRecordService.countExchangeRecords(CreditExchangeRecordMapper.DaoQuery.builder()
                .uid(uid).build());
        Date nowDate =  new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMddHHmm"),"yyyyMMddHHmm"));
        BigDecimal money =null;
        if(count<=0){
            // 新人兑换
            List<ExchangeRate>  rates =  exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder()
                            .exchangeType(ExchangeRate.ExchangeType.NEW_USER_EXCHANGE)
                            .minStartTime(nowDate)
                            .maxEndTime(nowDate)
                    .build());
            if(rates.isEmpty()) {
                throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,"新人兑换汇率未设置");
            }
            money = new BigDecimal(credit).multiply(rates.get(0).getRate()).setScale(2, RoundingMode.HALF_UP);
        }else{
            // 老用户兑换
            List<ExchangeRate>  rates =  exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder()
                    .exchangeType(ExchangeRate.ExchangeType.GENERAL_EXCHANGE)
                    .minStartTime(nowDate)
                    .maxEndTime(nowDate)
                    .build());
            if(rates.isEmpty()) {
                throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,"老用户兑换汇率未设置");
            }
            money = new BigDecimal(credit).multiply(rates.get(0).getRate()).setScale(2, RoundingMode.HALF_UP);
        }
        return money;
    }
}
src/main/java/com/taoke/autopay/manager/UserCreditManager.java
New file
@@ -0,0 +1,57 @@
package com.taoke.autopay.manager;
import com.taoke.autopay.entity.credit.UserCreditBalance;
import com.taoke.autopay.entity.credit.UserCreditRecord;
import com.taoke.autopay.service.credit.UserCreditBalanceService;
import com.taoke.autopay.service.credit.UserCreditRecordService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@Component
public class UserCreditManager {
    @Resource
    private UserCreditBalanceService userCreditBalanceService;
    @Resource
    private UserCreditRecordService userCreditRecordService;
    /**
     * 增加积分(事务性)
     *
     * @param creditRecord 积分记录实体
     */
    @Transactional(rollbackFor = Exception.class)
    public void increaseCredit(UserCreditRecord creditRecord) {
        int amount = creditRecord.getCreditAmount();
        // 增加积分
        userCreditBalanceService.increaseCreditBalance(creditRecord.getUid(), amount);
        // 增加记录
        userCreditRecordService.addCreditRecord(creditRecord);
    }
    /**
     * 扣除积分(事务性)
     *
     * @param creditRecord 积分记录实体
     */
    @Transactional(rollbackFor = Exception.class)
    public void decreaseCredit(UserCreditRecord creditRecord) {
        Long userId = creditRecord.getUid();
        int amount = creditRecord.getCreditAmount();
        // 判断用户积分余额是否足够
        UserCreditBalance balance = userCreditBalanceService.getCreditBalanceByUserId(userId);
        if (balance == null || balance.getCreditBalance() < amount) {
            throw new RuntimeException("用户积分不足");
        }
        // 减少积分
        userCreditBalanceService.decreaseCreditBalance(userId, amount);
       // 增加积分记录
        userCreditRecordService.addCreditRecord(creditRecord);
    }
}
src/main/java/com/taoke/autopay/service/credit/CreditExchangeRecordService.java
New file
@@ -0,0 +1,50 @@
package com.taoke.autopay.service.credit;
import java.util.List;
import com.taoke.autopay.entity.credit.CreditExchangeRecord;
import com.taoke.autopay.dao.credit.CreditExchangeRecordMapper.DaoQuery;
public interface CreditExchangeRecordService {
    /**
     * 添加兑换记录
     * @param record 兑换记录
     * @return 影响的行数
     */
    Long addExchangeRecord(CreditExchangeRecord record);
    /**
     * 获取详情
     * @param id
     * @return
     */
    CreditExchangeRecord getExchangeRecordById(Long id);
    /**
     * 获取详情用于锁定
     * @param id
     * @return
     */
    CreditExchangeRecord getExchangeRecordByIdForUpdate(Long id);
    /**
     * 根据查询条件获取兑换记录列表
     * @param query 查询条件
     * @return 兑换记录列表
     */
    List<CreditExchangeRecord> listExchangeRecords(DaoQuery query);
    /**
     * 根据查询条件获取兑换记录总数
     * @param query 查询条件
     * @return 兑换记录总数
     */
    long countExchangeRecords(DaoQuery query);
    /**
     * 更新
     * @param record
     * @return
     */
    int updateExchangeRecord(CreditExchangeRecord record);
}
src/main/java/com/taoke/autopay/service/credit/CreditSettingService.java
New file
@@ -0,0 +1,46 @@
package com.taoke.autopay.service.credit;
import java.util.Date;
import java.util.List;
import com.taoke.autopay.entity.credit.CreditSetting;
import com.taoke.autopay.dao.credit.CreditSettingMapper.DaoQuery;
public interface CreditSettingService {
    /**
     * 添加设置
     * @param creditSetting 设置信息
     * @return 影响的行数
     */
    int addSetting(CreditSetting creditSetting);
    /**
     * 修改设置
     * @param creditSetting 设置信息
     * @return 影响的行数
     */
    int updateSetting(CreditSetting creditSetting);
    /**
     * 根据类型获取设置
     * @param type 设置类型
     * @return 设置列表
     */
    List<CreditSetting> getSettingByType(CreditSetting.CreditSettingType type);
    /**
     * 获取所有设置列表
     * @return 设置列表
     */
    List<CreditSetting> listAllSettings();
    /**
     * 获取设置缓存
     * @param type
     * @param date
     * @return
     */
    CreditSetting  getSettingCacheByType(CreditSetting.CreditSettingType type, Date date);
}
src/main/java/com/taoke/autopay/service/credit/ExchangeRateService.java
New file
@@ -0,0 +1,43 @@
package com.taoke.autopay.service.credit;
import java.util.List;
import com.taoke.autopay.entity.credit.ExchangeRate;
import com.taoke.autopay.dao.credit.ExchangeRateMapper.DaoQuery;
public interface ExchangeRateService {
    /**
     * 添加汇率记录
     * @param exchangeRate 汇率记录
     * @return 影响的行数
     */
    int addExchangeRate(ExchangeRate exchangeRate);
    /**
     * 修改汇率记录
     * @param exchangeRate 汇率记录
     * @return 影响的行数
     */
    int updateExchangeRate(ExchangeRate exchangeRate);
    /**
     * 删除汇率记录
     * @param id 汇率记录ID
     * @return 影响的行数
     */
    int deleteExchangeRate(Long id);
    /**
     * 根据查询条件获取汇率记录列表
     * @param query 查询条件
     * @return 汇率记录列表
     */
    List<ExchangeRate> listExchangeRates(DaoQuery query);
    /**
     * 根据查询条件获取汇率记录总数
     * @param query 查询条件
     * @return 汇率记录总数
     */
    long countExchangeRates(DaoQuery query);
}
src/main/java/com/taoke/autopay/service/credit/UserAlipayBindingService.java
New file
@@ -0,0 +1,35 @@
package com.taoke.autopay.service.credit;
import com.taoke.autopay.entity.credit.UserAlipayBinding;
import java.util.List;
public interface UserAlipayBindingService {
    /**
     * 添加支付宝绑定
     * @param binding 绑定信息
     * @return 影响的行数
     */
    int addBinding(UserAlipayBinding binding);
    /**
     * 删除绑定
     * @param id 绑定ID
     * @return 影响的行数
     */
    int deleteBinding(Long id);
    /**
     * 更改绑定信息
     * @param binding 绑定信息
     * @return 影响的行数
     */
    int updateBinding(UserAlipayBinding binding);
    /**
     * 根据用户ID查询绑定信息
     * @param uid 用户ID
     * @return 绑定信息列表
     */
    List<UserAlipayBinding> getBindingsByUid(Long uid);
}
src/main/java/com/taoke/autopay/service/credit/UserCreditBalanceService.java
New file
@@ -0,0 +1,25 @@
package com.taoke.autopay.service.credit;
import com.taoke.autopay.entity.credit.UserCreditBalance;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
public interface UserCreditBalanceService {
    // 1. 初始化用户余额为0
    void initializeCreditBalance(Long userId);
    // 2. 查询单个用户的余额
    UserCreditBalance getCreditBalanceByUserId(Long userId);
    // 3. 根据用户ID批量查询用户余额
    Map<Long, UserCreditBalance> getCreditBalancesByUserIds(List<Long> userIds);
    // 4. 增加用户余额
    void increaseCreditBalance(Long userId, int amount);
    // 5. 减少用户余额
    void decreaseCreditBalance(Long userId, int amount);
}
src/main/java/com/taoke/autopay/service/credit/UserCreditRecordService.java
New file
@@ -0,0 +1,29 @@
package com.taoke.autopay.service.credit;
import java.util.List;
import com.taoke.autopay.entity.credit.UserCreditRecord;
import com.taoke.autopay.dao.credit.UserCreditRecordMapper.DaoQuery;
public interface UserCreditRecordService {
    /**
     * 添加用户积分记录
     * @param record 用户积分记录
     * @return 影响的行数
     */
    int addCreditRecord(UserCreditRecord record);
    /**
     * 根据查询条件获取用户积分记录列表
     * @param query 查询条件
     * @return 用户积分记录列表
     */
    List<UserCreditRecord> listCreditRecords(DaoQuery query);
    /**
     * 根据查询条件获取用户积分记录总数
     * @param query 查询条件
     * @return 用户积分记录总数
     */
    long countCreditRecords(DaoQuery query);
}
src/main/java/com/taoke/autopay/service/impl/WxUserSettingServiceImpl.java
@@ -1,25 +1,14 @@
package com.taoke.autopay.service.impl;
import com.taoke.autopay.dao.WxUserSettingsMapper;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.WxUserSettingService;
import com.taoke.autopay.utils.StringUtil;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.taoke.autopay.dao.WxUserSettingsMapper;
import com.taoke.autopay.entity.WxUserSettings;
import com.taoke.autopay.service.SystemConfigService;
import com.taoke.autopay.service.WxUserSettingService;
/**
 * @author hxh
 * @title: WxUserSettingServiceImpl
 * @description: TODO
 * @date 2024/6/28 19:10
 */
@Service
public class WxUserSettingServiceImpl implements WxUserSettingService {
src/main/java/com/taoke/autopay/service/impl/credit/CreditExchangeRecordServiceImpl.java
New file
@@ -0,0 +1,52 @@
package com.taoke.autopay.service.impl.credit;
import javax.annotation.Resource;
import java.util.List;
import com.taoke.autopay.service.credit.CreditExchangeRecordService;
import com.taoke.autopay.dao.credit.CreditExchangeRecordMapper.DaoQuery;
import java.util.Date;
import org.springframework.stereotype.Service;
import com.taoke.autopay.entity.credit.CreditExchangeRecord;
import com.taoke.autopay.dao.credit.CreditExchangeRecordMapper;
import org.springframework.transaction.annotation.Transactional;
@Service
public class CreditExchangeRecordServiceImpl implements CreditExchangeRecordService {
    @Resource
    private CreditExchangeRecordMapper creditExchangeRecordMapper;
    @Override
    public Long addExchangeRecord(CreditExchangeRecord record) {
        if (record.getCreateTime() == null) {
            record.setCreateTime(new Date());
        }
        creditExchangeRecordMapper.insertSelective(record);
        return  record.getId();
    }
    @Override
    public CreditExchangeRecord getExchangeRecordById(Long id) {
        return creditExchangeRecordMapper.selectByPrimaryKey(id);
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public CreditExchangeRecord getExchangeRecordByIdForUpdate(Long id) {
        return creditExchangeRecordMapper.selectByPrimaryKeyForUpdate(id);
    }
    @Override
    public List<CreditExchangeRecord> listExchangeRecords(DaoQuery query) {
        return creditExchangeRecordMapper.list(query);
    }
    @Override
    public long countExchangeRecords(DaoQuery query) {
        return creditExchangeRecordMapper.count(query);
    }
    @Override
    public int updateExchangeRecord(CreditExchangeRecord record) {
        return creditExchangeRecordMapper.updateByPrimaryKeySelective(record);
    }
}
src/main/java/com/taoke/autopay/service/impl/credit/CreditSettingServiceImpl.java
New file
@@ -0,0 +1,54 @@
package com.taoke.autopay.service.impl.credit;
import com.taoke.autopay.dao.credit.CreditSettingMapper;
import com.taoke.autopay.entity.credit.CreditSetting;
import com.taoke.autopay.service.credit.CreditSettingService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class CreditSettingServiceImpl implements CreditSettingService {
    @Resource
    private CreditSettingMapper creditSettingMapper;
    @Override
    public int addSetting(CreditSetting creditSetting) {
        return creditSettingMapper.insertSelective(creditSetting);
    }
    @Override
    public int updateSetting(CreditSetting creditSetting) {
        return creditSettingMapper.updateByPrimaryKeySelective(creditSetting);
    }
    @Override
    public List<CreditSetting> getSettingByType(CreditSetting.CreditSettingType type) {
        return creditSettingMapper.selectByType(type);
    }
    @Override
    public List<CreditSetting> listAllSettings() {
        return creditSettingMapper.list(CreditSettingMapper.DaoQuery.builder()
                        .count(Integer.MAX_VALUE)
                .build());
    }
    @Cacheable(value = "creditSettingCache", key = "'getCache-'+#type+'-'+#date")
    @Override
    public CreditSetting getSettingCacheByType(CreditSetting.CreditSettingType type, Date date) {
        List<CreditSetting> settings =  creditSettingMapper.list(CreditSettingMapper.DaoQuery.builder()
                        .type(type)
                        .maxStartTime(date)
                        .minEndTime(date)
                .count(Integer.MAX_VALUE)
                .build());
        if(settings.isEmpty()){
            return null;
        }
        return settings.get(0);
    }
}
src/main/java/com/taoke/autopay/service/impl/credit/ExchangeRateServiceImpl.java
New file
@@ -0,0 +1,41 @@
package com.taoke.autopay.service.impl.credit;
import com.taoke.autopay.dao.credit.ExchangeRateMapper;
import com.taoke.autopay.entity.credit.ExchangeRate;
import com.taoke.autopay.dao.credit.ExchangeRateMapper.DaoQuery;
import com.taoke.autopay.service.credit.ExchangeRateService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
@Service
public class ExchangeRateServiceImpl implements ExchangeRateService {
    @Resource
    private ExchangeRateMapper exchangeRateMapper;
    @Override
    public int addExchangeRate(ExchangeRate exchangeRate) {
        return exchangeRateMapper.insertSelective(exchangeRate);
    }
    @Override
    public int updateExchangeRate(ExchangeRate exchangeRate) {
        return exchangeRateMapper.updateByPrimaryKeySelective(exchangeRate);
    }
    @Override
    public int deleteExchangeRate(Long id) {
        return exchangeRateMapper.deleteByPrimaryKey(id);
    }
    @Override
    public List<ExchangeRate> listExchangeRates(DaoQuery query) {
        return exchangeRateMapper.list(query);
    }
    @Override
    public long countExchangeRates(DaoQuery query) {
        return exchangeRateMapper.count(query);
    }
}
src/main/java/com/taoke/autopay/service/impl/credit/UserAlipayBindingServiceImpl.java
New file
@@ -0,0 +1,45 @@
package com.taoke.autopay.service.impl.credit;
import com.taoke.autopay.dao.credit.UserAlipayBindingMapper;
import com.taoke.autopay.entity.credit.UserAlipayBinding;
import com.taoke.autopay.service.credit.UserAlipayBindingService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Service
public class UserAlipayBindingServiceImpl implements UserAlipayBindingService {
    @Resource
    private UserAlipayBindingMapper userAlipayBindingMapper;
    @Override
    public int addBinding(UserAlipayBinding binding) {
        if(binding.getCreateTime()==null){
            binding.setCreateTime(new Date());
        }
        return userAlipayBindingMapper.insertSelective(binding);
    }
    @Override
    public int deleteBinding(Long id) {
        return userAlipayBindingMapper.deleteByPrimaryKey(id);
    }
    @Override
    public int updateBinding(UserAlipayBinding binding) {
        if(binding.getUpdateTime()==null){
            binding.setUpdateTime(new Date());
        }
        return userAlipayBindingMapper.updateByPrimaryKeySelective(binding);
    }
    @Override
    public List<UserAlipayBinding> getBindingsByUid(Long uid) {
        UserAlipayBindingMapper.DaoQuery query = new UserAlipayBindingMapper.DaoQuery();
        query.uid = uid;
        query.count =Integer.MAX_VALUE;
        return userAlipayBindingMapper.list(query);
    }
}
src/main/java/com/taoke/autopay/service/impl/credit/UserCreditBalanceServiceImpl.java
New file
@@ -0,0 +1,68 @@
package com.taoke.autopay.service.impl.credit;
import com.taoke.autopay.dao.credit.UserCreditBalanceMapper;
import com.taoke.autopay.entity.credit.UserCreditBalance;
import com.taoke.autopay.service.credit.UserCreditBalanceService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class UserCreditBalanceServiceImpl implements UserCreditBalanceService {
    @Resource
    private UserCreditBalanceMapper userCreditBalanceMapper;
    @Override
    public void initializeCreditBalance(Long userId) {
        UserCreditBalance userCreditBalance = new UserCreditBalance();
        userCreditBalance.setId(userId);
        userCreditBalance.setCreditBalance(BigDecimal.ZERO);
        userCreditBalance.setCreateTime(new Date());
        userCreditBalance.setUpdateTime(new Date());
        userCreditBalanceMapper.insert(userCreditBalance);
    }
    @Override
    public UserCreditBalance getCreditBalanceByUserId(Long userId) {
        return userCreditBalanceMapper.selectByPrimaryKey(userId);
    }
    @Override
    public Map<Long, UserCreditBalance> getCreditBalancesByUserIds(List<Long> userIds) {
        List<UserCreditBalance> userCreditBalances = userCreditBalanceMapper.selectByIds(userIds);
        Map<Long, UserCreditBalance> balanceMap = new HashMap<>();
        for (UserCreditBalance balance : userCreditBalances) {
            balanceMap.put(balance.getId(), balance);
        }
        return balanceMap;
    }
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void increaseCreditBalance(Long userId, int amount) {
        UserCreditBalance userCreditBalance = userCreditBalanceMapper.selectByPrimaryKeyForUpdate(userId);
        if (userCreditBalance != null) {
            userCreditBalance.setCreditBalance(userCreditBalance.getCreditBalance().add(amount));
            userCreditBalance.setUpdateTime(new Date());
            userCreditBalanceMapper.updateByPrimaryKeySelective(userCreditBalance);
        }
    }
    @Override
    public void decreaseCreditBalance(Long userId, int amount) {
        UserCreditBalance userCreditBalance = userCreditBalanceMapper.selectByPrimaryKeyForUpdate(userId);
        if (userCreditBalance != null) {
            userCreditBalance.setCreditBalance(userCreditBalance.getCreditBalance().subtract(amount));
            userCreditBalance.setUpdateTime(new Date());
            userCreditBalanceMapper.updateByPrimaryKeySelective(userCreditBalance);
        }
    }
}
src/main/java/com/taoke/autopay/service/impl/credit/UserCreditRecordServiceImpl.java
New file
@@ -0,0 +1,35 @@
package com.taoke.autopay.service.impl.credit;
import javax.annotation.Resource;
import java.util.List;
import com.taoke.autopay.service.credit.UserCreditRecordService;
import com.taoke.autopay.dao.credit.UserCreditRecordMapper.DaoQuery;
import java.util.Date;
import org.springframework.stereotype.Service;
import com.taoke.autopay.entity.credit.UserCreditRecord;
import com.taoke.autopay.dao.credit.UserCreditRecordMapper;
@Service
public class UserCreditRecordServiceImpl implements UserCreditRecordService {
    @Resource
    private UserCreditRecordMapper userCreditRecordMapper;
    @Override
    public int addCreditRecord(UserCreditRecord record) {
        if(record.getCreateTime()==null){
            record.setCreateTime(new Date());
        }
        return userCreditRecordMapper.insertSelective(record);
    }
    @Override
    public List<UserCreditRecord> listCreditRecords(DaoQuery query) {
        return userCreditRecordMapper.list(query);
    }
    @Override
    public long countCreditRecords(DaoQuery query) {
        return userCreditRecordMapper.count(query);
    }
}
src/main/resources/ehcache.xml
@@ -26,4 +26,10 @@
           timeToLiveSeconds="120" overflowToDisk="true"
           memoryStoreEvictionPolicy="LRU" />
    <!-- 配置文件缓存 -->
    <cache name="creditSettingCache" maxElementsInMemory="1000"
           maxElementsOnDisk="10000" eternal="false" timeToIdleSeconds="120"
           timeToLiveSeconds="120" overflowToDisk="true"
           memoryStoreEvictionPolicy="LRU" />
</ehcache>
src/main/resources/mapper/CreditSettingMapper.xml
New file
@@ -0,0 +1,149 @@
<?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.taoke.autopay.dao.credit.CreditSettingMapper">
    <resultMap id="BaseResultMap" type="com.taoke.autopay.entity.credit.CreditSetting">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="type" property="type" jdbcType="VARCHAR"/>
        <result column="name" property="name" jdbcType="VARCHAR"/>
        <result column="value" property="value" jdbcType="VARCHAR"/>
        <result column="start_time" property="startTime" jdbcType="TIMESTAMP"/>
        <result column="end_time" property="endTime" jdbcType="TIMESTAMP"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">
        id, type, name, value, start_time, end_time, create_time, update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from table_credit_setting
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from table_credit_setting
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.taoke.autopay.entity.credit.CreditSetting" useGeneratedKeys="true" keyProperty="id">
        insert into table_credit_setting (id, type, name, value, start_time, end_time, create_time, update_time)
        values (#{id,jdbcType=BIGINT}, #{type,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{value,jdbcType=VARCHAR}, #{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.taoke.autopay.entity.credit.CreditSetting" useGeneratedKeys="true" keyProperty="id">
        insert into table_credit_setting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="type != null">type,</if>
            <if test="name != null">name,</if>
            <if test="value != null">value,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="type != null">#{type,jdbcType=VARCHAR},</if>
            <if test="name != null">#{name,jdbcType=VARCHAR},</if>
            <if test="value != null">#{value,jdbcType=VARCHAR},</if>
            <if test="startTime != null">#{startTime,jdbcType=TIMESTAMP},</if>
            <if test="endTime != null">#{endTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.taoke.autopay.entity.credit.CreditSetting">
        update table_credit_setting
        <set>
            <if test="type != null">type = #{type,jdbcType=VARCHAR},</if>
            <if test="name != null">name = #{name,jdbcType=VARCHAR},</if>
            <if test="value != null">value = #{value,jdbcType=VARCHAR},</if>
            <if test="startTime != null">start_time = #{startTime,jdbcType=TIMESTAMP},</if>
            <if test="endTime != null">end_time = #{endTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.taoke.autopay.entity.credit.CreditSetting">
        update table_credit_setting
        set type = #{type,jdbcType=VARCHAR},
            name = #{name,jdbcType=VARCHAR},
            value = #{value,jdbcType=VARCHAR},
            start_time = #{startTime,jdbcType=TIMESTAMP},
            end_time = #{endTime,jdbcType=TIMESTAMP},
            create_time = #{createTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <select id="selectByType" resultMap="BaseResultMap" parameterType="com.taoke.autopay.entity.credit.CreditSetting.CreditSettingType">
        select
        <include refid="Base_Column_List" />
        from table_credit_setting
        where type = #{type,jdbcType=VARCHAR}
    </select>
    <select id="list" resultMap="BaseResultMap" parameterType="com.taoke.autopay.dao.credit.CreditSettingMapper.DaoQuery">
        select
        <include refid="Base_Column_List" />
        from table_credit_setting
        <where>
            <if test="id != null">and id = #{id,jdbcType=BIGINT}</if>
            <if test="type != null">and type = #{type,jdbcType=VARCHAR}</if>
            <if test="name != null">and name = #{name,jdbcType=VARCHAR}</if>
            <if test="value != null">and value = #{value,jdbcType=VARCHAR}</if>
            <if test="minStartTime != null">and start_time &gt;= #{minStartTime,jdbcType=TIMESTAMP}</if>
            <if test="maxStartTime != null">and start_time &lt; #{maxStartTime,jdbcType=TIMESTAMP}</if>
            <if test="minEndTime != null">and end_time &gt;= #{minEndTime,jdbcType=TIMESTAMP}</if>
            <if test="maxEndTime != null">and end_time &lt; #{maxEndTime,jdbcType=TIMESTAMP}</if>
            <if test="minCreateTime != null">and create_time &gt;= #{minCreateTime,jdbcType=TIMESTAMP}</if>
            <if test="maxCreateTime != null">and create_time &lt; #{maxCreateTime,jdbcType=TIMESTAMP}</if>
            <if test="minUpdateTime != null">and update_time &gt;= #{minUpdateTime,jdbcType=TIMESTAMP}</if>
            <if test="maxUpdateTime != null">and update_time &lt; #{maxUpdateTime,jdbcType=TIMESTAMP}</if>
        </where>
        <if test="sortList != null and sortList.size() > 0">
            order by
            <foreach collection="sortList" item="sort" separator=",">
                ${sort}
            </foreach>
        </if>
        <if test="start != null and count != null">
            limit #{start,jdbcType=BIGINT}, #{count,jdbcType=INTEGER}
        </if>
    </select>
    <select id="count" resultType="long" parameterType="com.taoke.autopay.dao.credit.CreditSettingMapper.DaoQuery">
        select count(*)
        from table_credit_setting
        <where>
            <if test="id != null">and id = #{id,jdbcType=BIGINT}</if>
            <if test="type != null">and type = #{type,jdbcType=VARCHAR}</if>
            <if test="name != null">and name = #{name,jdbcType=VARCHAR}</if>
            <if test="value != null">and value = #{value,jdbcType=VARCHAR}</if>
            <if test="minStartTime != null">and start_time &gt;= #{minStartTime,jdbcType=TIMESTAMP}</if>
            <if test="maxStartTime != null">and start_time &lt; #{maxStartTime,jdbcType=TIMESTAMP}</if>
            <if test="minEndTime != null">and end_time &gt;= #{minEndTime,jdbcType=TIMESTAMP}</if>
            <if test="maxEndTime != null">and end_time &lt; #{maxEndTime,jdbcType=TIMESTAMP}</if>
            <if test="minCreateTime != null">and create_time &gt;= #{minCreateTime,jdbcType=TIMESTAMP}</if>
            <if test="maxCreateTime != null">and create_time &lt; #{maxCreateTime,jdbcType=TIMESTAMP}</if>
            <if test="minUpdateTime != null">and update_time &gt;= #{minUpdateTime,jdbcType=TIMESTAMP}</if>
            <if test="maxUpdateTime != null">and update_time &lt; #{maxUpdateTime,jdbcType=TIMESTAMP}</if>
        </where>
    </select>
    <select id="selectAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from table_credit_setting
    </select>
</mapper>
src/main/resources/mapper/ExchangeRateMapper.xml
src/main/resources/mapper/UserAlipayBindingMapper.xml
src/main/resources/mapper/UserCreditBalanceMapper.xml
New file
@@ -0,0 +1,103 @@
<?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.taoke.autopay.dao.credit.UserCreditBalanceMapper">
    <resultMap id="BaseResultMap" type="com.taoke.autopay.entity.credit.UserCreditBalance">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="credit_balance" property="creditBalance" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    <sql id="Base_Column_List">id,credit_balance,create_time,update_time</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from table_user_credit_balance
        where id = #{id,jdbcType=BIGINT}
    </select>
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from table_user_credit_balance
        where id = #{id,jdbcType=BIGINT} for update
    </select>
    <sql id="listWhereSQL">
        <if test="query.id!=null">AND id = #{query.id}</if>
        <if test="query.creditBalance!=null">AND credit_balance = #{query.creditBalance}</if>
        <if test="query.minCreateTime!=null">AND create_time >= #{query.minCreateTime}</if>
        <if test="query.maxCreateTime!=null">AND create_time < #{query.maxCreateTime}</if>
        <if test="query.minUpdateTime!=null">AND update_time >= #{query.minUpdateTime}</if>
        <if test="query.maxUpdateTime!=null">AND update_time < #{query.maxUpdateTime}</if>
    </sql>
    <select id="list" resultMap="BaseResultMap" parameterType="com.taoke.autopay.dao.credit.UserCreditBalanceMapper.DaoQuery">
        select
        <include refid="Base_Column_List" />
        from table_user_credit_balance
        where 1=1
        <include refid="listWhereSQL"/>
        <if test="query.sortList!=null">
            order by
            <foreach collection="query.sortList" item="item" separator=",">
                ${item}
            </foreach>
        </if>
        limit #{query.start},#{query.count}
    </select>
    <select id="count" resultType="java.lang.Long" parameterType="com.taoke.autopay.dao.credit.UserCreditBalanceMapper.DaoQuery">
        select count(*)
        from table_user_credit_balance
        where 1=1
        <include refid="listWhereSQL"/>
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from table_user_credit_balance
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.taoke.autopay.entity.credit.UserCreditBalance" useGeneratedKeys="true" keyProperty="id">
        insert into table_user_credit_balance (id,credit_balance,create_time,update_time)
        values (#{id,jdbcType=BIGINT},#{creditBalance,jdbcType=INTEGER},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.taoke.autopay.entity.credit.UserCreditBalance" useGeneratedKeys="true" keyProperty="id">
        insert into table_user_credit_balance
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="creditBalance != null">credit_balance,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="creditBalance != null">#{creditBalance,jdbcType=INTEGER},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.taoke.autopay.entity.credit.UserCreditBalance">
        update table_user_credit_balance
        set credit_balance = #{creditBalance,jdbcType=INTEGER},
            create_time = #{createTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.taoke.autopay.entity.credit.UserCreditBalance">
        update table_user_credit_balance
        <set>
            <if test="creditBalance != null">credit_balance = #{creditBalance,jdbcType=INTEGER},</if>
            <if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
</mapper>
src/main/resources/mapper/credit/UserCreditBalanceMapper.xml
File was deleted