package com.cool.store.dao;

import com.cool.store.entity.plan.ShopDeliveryPlanItemDO;
import com.cool.store.mapper.ShopDeliveryPlanItemMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;

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

@Repository
public class ShopDeliveryPlanItemDAO {

    @Resource
    private ShopDeliveryPlanItemMapper shopDeliveryPlanItemMapper;

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

    /**
     * 根据主表ID查询明细列表
     */
    public List<ShopDeliveryPlanItemDO> listByPlanId(Long planId) {
        if (planId == null) {
            return null;
        }
        return shopDeliveryPlanItemMapper.listByPlanId(planId);
    }

    /**
     * 根据主表ID和类型查询明细
     */
    public ShopDeliveryPlanItemDO getByPlanIdAndItemType(Long planId, Integer itemType) {
        if (planId == null || itemType == null) {
            return null;
        }
        return shopDeliveryPlanItemMapper.getByPlanIdAndItemType(planId, itemType);
    }

    /**
     * 插入
     */
    public int insert(ShopDeliveryPlanItemDO record) {
        record.setCreateTime(new Date());
        record.setUpdateTime(new Date());
        return shopDeliveryPlanItemMapper.insert(record);
    }


    public int batchInsert(List<ShopDeliveryPlanItemDO> recordList) {
        if (CollectionUtils.isEmpty(recordList)){
            return 0;
        }
        return shopDeliveryPlanItemMapper.batchInsert(recordList);
    }

    /**
     * 更新
     */
    public int update(ShopDeliveryPlanItemDO record) {
        record.setUpdateTime(new Date());
        return shopDeliveryPlanItemMapper.update(record);
    }

    /**
     * 删除
     */
    public int deleteById(Long id) {
        if (id == null) {
            return 0;
        }
        return shopDeliveryPlanItemMapper.deleteById(id);
    }

    /**
     * 根据主表ID删除明细
     */
    public int deleteByPlanId(Long planId) {
        if (planId == null) {
            return 0;
        }
        return shopDeliveryPlanItemMapper.deleteByPlanId(planId);
    }
}