package com.ruoyi.cai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.cai.domain.AccountChangeLog;
import com.ruoyi.cai.enums.AccountChangeEnum;
import com.ruoyi.cai.mapper.AccountChangeLogMapper;
import com.ruoyi.cai.pay.RechargeTypeEnum;
import com.ruoyi.cai.service.AccountChangeLogService;
import org.springframework.stereotype.Service;

/**
 * 账户明细Service业务层处理
 *
 * @author 77
 * @date 2024-01-05
 */
@Service
public class AccountChangeLogServiceImpl extends ServiceImpl<AccountChangeLogMapper,AccountChangeLog> implements AccountChangeLogService {


    @Override
    public AccountChangeLog saveLogNoAdmin(Long userId, String usercode, RechargeTypeEnum rechargeTypeEnum, AccountChangeEnum accountChangeEnum, Long price,Long traceId){
        return this.saveLog(userId,usercode,rechargeTypeEnum,accountChangeEnum,price,traceId,0);
    }

    @Override
    public AccountChangeLog saveLog(Long userId,String usercode, RechargeTypeEnum rechargeTypeEnum,
                                    AccountChangeEnum accountChangeEnum, Long price, Long traceId,Integer admin){
        AccountChangeLog log = new AccountChangeLog();
        log.setUserId(userId);
        log.setUsercode(usercode);
        log.setTraceId(traceId);
        log.setAccountType(rechargeTypeEnum.getCode());
        log.setCateId(accountChangeEnum.getCode());
        log.setCateAppName(accountChangeEnum.getAppName());
        log.setCateAdminName(accountChangeEnum.getAdminName());
        log.setTraceLinkType(accountChangeEnum.getTraceIdLink());
        log.setRemark(accountChangeEnum.getDesc());
        log.setChangeValue(price);
        log.setIsAdmin(admin);
        this.save(log);
        return log;
    }

    @Override
    public AccountChangeLog saveLogAdmin(Long userId, String usercode, RechargeTypeEnum rechargeTypeEnum, AccountChangeEnum accountChangeEnum, Long price,Long traceId) {
        return this.saveLog(userId,usercode,rechargeTypeEnum,accountChangeEnum,price,traceId,1);
    }


}
