package com.liang.service.impl;

import com.liang.dao.StaMaterialDao;
import com.liang.entity.StaMaterial;
import com.liang.service.StaMaterialService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

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

/**
 * 材料费(StaMaterial)表服务实现类
 */
@Service("staMaterialService")
public class StaMaterialServiceImpl implements StaMaterialService {
    @Resource
    private StaMaterialDao staMaterialDao;

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

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

    /**
     * 新增数据
     *
     * @param staMaterial 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(StaMaterial staMaterial) {
        return this.staMaterialDao.insert(staMaterial);
    }

    /**
     * 修改数据
     *
     * @param staMaterial 实例对象
     * @return 实例对象
     */
    @Override
    public int update(StaMaterial staMaterial) {
        return this.staMaterialDao.update(staMaterial);
    }

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

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

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

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

    @Override
    public List<StaMaterial> getList(Integer zb) {
        return this.staMaterialDao.getList(zb);
    }

    @Override
    public List<HashMap<String, Object>> searchMaterialCost(Map map) {
        return this.staMaterialDao.searchMaterialCost(map);
    }
}
