package com.cool.store.dao;

import com.cool.store.entity.ExpenseMappingDO;
import com.cool.store.mapper.ExpenseMappingMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Repository;

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

/**
 * 费用单流水调整单映射表 DAO
 */
@Repository
public class ExpenseMappingDAO {

    @Resource
    private ExpenseMappingMapper expenseMappingMapper;

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

    /**
     * 根据网商交易流水号查询
     */
    public ExpenseMappingDO getByTradeNo(String trandNo) {
        if (StringUtils.isBlank(trandNo)) {
            return null;
        }
        return expenseMappingMapper.getByTradeNo(trandNo);
    }

    /**
     * 根据费用单号查询
     */
    public ExpenseMappingDO getByRelatedAdjustmentNo(String relatedAdjustmentNo) {
        if (StringUtils.isBlank(relatedAdjustmentNo)) {
            return null;
        }
        return expenseMappingMapper.getByRelatedAdjustmentNo(relatedAdjustmentNo);
    }

    /**
     * 新增
     */
    public int insert(ExpenseMappingDO record) {
        if (record == null) {
            return 0;
        }
        return expenseMappingMapper.insertSelective(record);
    }

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

    /**
     * 删除
     */
    public int delete(Long id) {
        if (id == null) {
            return 0;
        }
        return expenseMappingMapper.deleteByPrimaryKey(id);
    }

    /**
     * 批量插入
     */
    public int batchInsert(List<ExpenseMappingDO> list) {
        if (CollectionUtils.isEmpty(list)) {
            return 0;
        }
        return expenseMappingMapper.batchInsert(list);
    }

    /**
     * 根据交易流水号列表批量查询
     */
    public List<ExpenseMappingDO> listByTradeNos(List<String> tradeNos) {
        if (CollectionUtils.isEmpty(tradeNos)) {
            return Collections.emptyList();
        }
        return expenseMappingMapper.listByTradeNos(tradeNos);
    }

    /**
     * 根据费用单号查询列表
     */
    public List<ExpenseMappingDO> listByRelatedAdjustmentNo(String relatedAdjustmentNo) {
        if (StringUtils.isBlank(relatedAdjustmentNo)) {
            return Collections.emptyList();
        }
        return expenseMappingMapper.listByRelatedAdjustmentNo(relatedAdjustmentNo);
    }

    /**
     * 根据费用单号列表批量查询
     */
    public List<ExpenseMappingDO> listByRelatedAdjustmentNoList(List<String> relatedAdjustmentNos) {
        if (CollectionUtils.isEmpty(relatedAdjustmentNos)) {
            return Collections.emptyList();
        }
        return expenseMappingMapper.listByRelatedAdjustmentNoList(relatedAdjustmentNos);
    }
}
