package com.liang.service.impl;

import com.liang.entity.StaMaterialcost;
import com.liang.dao.StaMaterialcostDao;
import com.liang.service.StaMaterialcostService;
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;

/**
 * 材料费(StaMaterialcost)表服务实现类
 *
 * @author makejava
 * @since 2023-07-18 21:55:35
 */
@Service("staMaterialcostService")
public class StaMaterialcostServiceImpl implements StaMaterialcostService {
    @Resource
    private StaMaterialcostDao staMaterialcostDao;

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

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

    /**
     * 新增数据
     *
     * @param staMaterialcost 实例对象
     * @return 实例对象
     */
    @Override
    public StaMaterialcost insert(StaMaterialcost staMaterialcost) {
        this.staMaterialcostDao.insert(staMaterialcost);
        return staMaterialcost;
    }

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

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

    @Override
    public List<StaMaterialcost> getClfList(Integer zb) {
        return this.staMaterialcostDao.getClfList(zb);
    }

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

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

    @Override
    public int insertBatch(List<StaMaterialcost> costList) {
        return this.staMaterialcostDao.insertBatch(costList);
    }
}
