package com.cool.store.dao;

import com.cool.store.dto.wallet.WithdrawApplicationDTO;
import com.cool.store.entity.WithdrawApplicationDO;
import com.cool.store.mapper.WithdrawApplicationMapper;
import com.cool.store.request.WithdrawApplicationPageRequest;
import com.cool.store.response.WithdrawApplicationResponse;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

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

/**
 * 提现申请 DAO
 */
@Repository
public class WithdrawApplicationDAO {

    @Resource
    private WithdrawApplicationMapper withdrawApplicationMapper;

    /**
     * 根据ID查询
     */
    public WithdrawApplicationDO getById(Long id) {
        if (id == null) {
            return null;
        }
        return withdrawApplicationMapper.selectByPrimaryKey(id);
    }

    /**
     * 插入
     */
    public int insert(WithdrawApplicationDO record) {
        if (record == null) {
            return 0;
        }
        return withdrawApplicationMapper.insertSelective(record);
    }

    /**
     * 更新
     */
    public int update(WithdrawApplicationDO record) {
        if (record == null || record.getId() == null) {
            return 0;
        }
        return withdrawApplicationMapper.updateByPrimaryKeySelective(record);
    }

    /**
     * 分页查询
     */
    public List<WithdrawApplicationDTO> pageQuery(WithdrawApplicationPageRequest request) {
        return withdrawApplicationMapper.pageQuery(request);
    }

    /**
     * 根据提现单号查询
     */
    public WithdrawApplicationDO getByWithdrawNo(String withdrawNo) {
        if (withdrawNo == null) {
            return null;
        }
        return withdrawApplicationMapper.selectOne(WithdrawApplicationDO.builder().withdrawNo(withdrawNo).build());
    }
}
