package com.hfkj.service.rebate.impl;

import com.hfkj.dao.BsRebateMerAccountRecordMapper;
import com.hfkj.entity.BsRebateMerAccountRecord;
import com.hfkj.entity.BsRebateMerAccountRecordExample;
import com.hfkj.service.rebate.BsRebateMerAccountRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className: BsRebateMerAccountRecordServiceImpl
 * @author: HuRui
 * @date: 2023/10/11
 **/
@Service("rebateMerAccountRecordService")
public class BsRebateMerAccountRecordServiceImpl implements BsRebateMerAccountRecordService {

    @Resource
    public BsRebateMerAccountRecordMapper rebateMerAccountRecordMapper;

    @Override
    public void insert(BsRebateMerAccountRecord record) {
        record.setCreateTime(new Date());
        record.setStatus(1);
        rebateMerAccountRecordMapper.insert(record);
    }

    @Override
    public List<BsRebateMerAccountRecord> getRecordList(Long accountNumber) {
        BsRebateMerAccountRecordExample example = new BsRebateMerAccountRecordExample();
        example.createCriteria().andAccountNumberEqualTo(accountNumber).andStatusNotEqualTo(0);
        example.setOrderByClause("create_time desc");
        return rebateMerAccountRecordMapper.selectByExample(example);
    }

    @Override
    public BsRebateMerAccountRecord getDetailByTradeNumber(String tradeNumber) {
        BsRebateMerAccountRecordExample example = new BsRebateMerAccountRecordExample();
        example.createCriteria().andTradeNumberEqualTo(tradeNumber).andStatusNotEqualTo(0);
        List<BsRebateMerAccountRecord> list = rebateMerAccountRecordMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

}
