package com.liang.service.impl;

import com.liang.entity.PrjDivisioncompany;
import com.liang.dao.PrjDivisioncompanyDao;
import com.liang.service.PrjDivisioncompanyService;
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;

/**
 * 单位分工：子课题单位(PrjDivisioncompany)表服务实现类
 *
 * @author makejava
 * @since 2023-04-01 19:05:33
 */
@Service("prjDivisioncompanyService")
public class PrjDivisioncompanyServiceImpl implements PrjDivisioncompanyService {
    @Resource
    private PrjDivisioncompanyDao prjDivisioncompanyDao;

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

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

    /**
     * 新增数据
     *
     * @param prjDivisioncompany 实例对象
     * @return 实例对象
     */
    @Override
    public PrjDivisioncompany insert(PrjDivisioncompany prjDivisioncompany) {
        this.prjDivisioncompanyDao.insert(prjDivisioncompany);
        return prjDivisioncompany;
    }

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

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

    @Override
    public int deleteByZkt(Integer zkt) {
        return this.prjDivisioncompanyDao.deleteByZkt(zkt);
    }

    @Override
    public int insertBatch(List<PrjDivisioncompany> companyList) {
        return this.prjDivisioncompanyDao.insertBatch(companyList);
    }

    @Override
    public List<PrjDivisioncompany> getCompanyList(Integer zkt) {
        return this.prjDivisioncompanyDao.getCompanyList(zkt);
    }
}
