package com.cool.store.dao;

import com.cool.store.entity.TallyBookDO;
import com.cool.store.mapper.TallyBookMapper;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

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

/**
 * @Author: WangShuo
 * @Date: 2025/03/28/09:50
 * @Version 1.0
 * @注释:
 */
@Repository
public class TallyBookDAO {
    @Resource
    private TallyBookMapper tallyBookMapper;
    public Long insertSelective(TallyBookDO tallyBookDO) {
        tallyBookMapper.insertSelective(tallyBookDO);
        return tallyBookDO.getId();
    }
    public Long updateByPrimaryKeySelective(TallyBookDO tallyBookDO) {
        tallyBookMapper.updateByPrimaryKeySelective(tallyBookDO);
        return tallyBookDO.getId();
    }
    public List<TallyBookDO> getTallyBookListByShopIdAndYear(Long shopId,Integer year) {
        Example example = new Example(TallyBookDO.class);
        example.createCriteria().andEqualTo("shopId",shopId).andEqualTo("year",year);
        return tallyBookMapper.selectByExample(example);
    }

    public TallyBookDO getById(Long id){
        if(id == null){
            return null;
        }
        return tallyBookMapper.selectByPrimaryKey(id);
    }


}
