package com.liang.service.impl;

import com.liang.entity.StaOutexpense;
import com.liang.dao.StaOutexpenseDao;
import com.liang.service.StaOutexpenseService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

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

/**
 * 外委研究支出(StaOutexpense)表服务实现类
 *
 * @author makejava
 * @since 2023-07-18 21:54:40
 */
@Service("staOutexpenseService")
public class StaOutexpenseServiceImpl implements StaOutexpenseService {
    @Resource
    private StaOutexpenseDao staOutexpenseDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public StaOutexpense queryById(Integer id) {
        return this.staOutexpenseDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param staOutexpense 筛选条件
     * @param pageRequest   分页对象
     * @return 查询结果
     */
    @Override
    public Page<StaOutexpense> queryByPage(StaOutexpense staOutexpense, PageRequest pageRequest) {
        long total = this.staOutexpenseDao.count(staOutexpense);
        return new PageImpl<>(this.staOutexpenseDao.queryAllByLimit(staOutexpense, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param staOutexpense 实例对象
     * @return 实例对象
     */
    @Override
    public StaOutexpense insert(StaOutexpense staOutexpense) {
        this.staOutexpenseDao.insert(staOutexpense);
        return staOutexpense;
    }

    /**
     * 修改数据
     *
     * @param staOutexpense 实例对象
     * @return 实例对象
     */
    @Override
    public StaOutexpense update(StaOutexpense staOutexpense) {
        this.staOutexpenseDao.update(staOutexpense);
        return this.queryById(staOutexpense.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.staOutexpenseDao.deleteById(id) > 0;
    }

    @Override
    public List<StaOutexpense> getWwyjzcList(Integer zb) {
        return this.staOutexpenseDao.getWwyjzcList(zb);
    }

    @Override
    public int deleteByZb(Integer zb) {
        return this.staOutexpenseDao.deleteByZb(zb);
    }

    @Override
    public int batchDeleteByZb(List<Integer> zbList) {
        return this.staOutexpenseDao.batchDeleteByZb(zbList);
    }

    @Override
    public int insertBatch(List<StaOutexpense> expenseList) {
        return this.staOutexpenseDao.insertBatch(expenseList);
    }
}
