package com.cool.store.dao;

import com.cool.store.entity.InvoicingDO;
import com.cool.store.mapper.InvoicingMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

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

/**
 * @Author suzhuhong
 * @Date 2024/12/31 13:37
 * @Version 1.0
 */
@Repository
public class InvoicingDAO {

    @Resource
    InvoicingMapper invoicingMapper;

    public Integer add(InvoicingDO invoicingDO){
        return  invoicingMapper.insertSelective(invoicingDO);
    }

    public Integer update(InvoicingDO invoicingDO){
        invoicingDO.setUpdateTime(new Date());
        return invoicingMapper.updateByPrimaryKey(invoicingDO);
    }

    public InvoicingDO getByShopId(Long shopId){
        if (shopId == null){
            return null;
        }
        return invoicingMapper.selectByShopId(shopId);
    }

    public InvoicingDO getById(Long id){
        if (id == null){
            return null;
        }
        return invoicingMapper.selectByPrimaryKey(id);
    }

    public List<InvoicingDO> listByShopIds(List<Long> shopIds){
        if (CollectionUtils.isEmpty(shopIds)){
            return new ArrayList<>();
        }
        Example example = new Example(InvoicingDO.class);
        example.createCriteria().andIn("shopId", shopIds);
        return invoicingMapper.selectByExample(example);
    }


}
