package com.liang.service.impl;

import com.liang.entity.StaDirector;
import com.liang.dao.StaDirectorDao;
import com.liang.service.StaDirectorService;
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;

/**
 * 负责人(StaDirector)表服务实现类
 *
 * @author makejava
 * @since 2023-04-09 21:54:44
 */
@Service("staDirectorService")
public class StaDirectorServiceImpl implements StaDirectorService {
    @Resource
    private StaDirectorDao staDirectorDao;

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

    /**
     * 通过主表ID查询数据
     *
     * @param zb 主表
     * @return 实例对象
     */
    @Override
    public List<StaDirector> queryByZbId(Integer zb) {
        return this.staDirectorDao.queryByZbId(zb);
    }

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

    /**
     * 新增数据
     *
     * @param staDirector 实例对象
     * @return 实例对象
     */
    @Override
    public StaDirector insert(StaDirector staDirector) {
        this.staDirectorDao.insert(staDirector);
        return staDirector;
    }

    @Override
    public int insertBatch(List<StaDirector> list) {
        return this.staDirectorDao.insertBatch(list);
    }

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

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

    /**
     * 批量删除系统用户
     *
     * @param idList
     * @return
     */
    @Override
    public int batchDelete(List<Integer> idList, Integer zb) {
        return this.staDirectorDao.batchDelete(idList, zb);
    }

    /**
     * 根据主表id删除记录
     *
     * @param zbId
     * @return
     */
    @Override
    public boolean deleteByZbId(Integer zbId) {
        return this.staDirectorDao.deleteByZbId(zbId) > 0;
    }
}
