package com.liang.service.impl;

import com.liang.entity.PrjSubtopicplan;
import com.liang.dao.PrjSubtopicplanDao;
import com.liang.service.PrjSubtopicplanService;
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;

/**
 * (PrjSubtopicplan)表服务实现类
 *
 * @author makejava
 * @since 2023-04-05 09:15:19
 */
@Service("prjSubtopicplanService")
public class PrjSubtopicplanServiceImpl implements PrjSubtopicplanService {
    @Resource
    private PrjSubtopicplanDao prjSubtopicplanDao;

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

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

    /**
     * 新增数据
     *
     * @param prjSubtopicplan 实例对象
     * @return 实例对象
     */
    @Override
    public PrjSubtopicplan insert(PrjSubtopicplan prjSubtopicplan) {
        this.prjSubtopicplanDao.insert(prjSubtopicplan);
        return prjSubtopicplan;
    }

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

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

    @Override
    public List<PrjSubtopicplan> getSubtopicPlanList(Integer zkt) {
        return this.prjSubtopicplanDao.getSubtopicPlanList(zkt);
    }

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

    @Override
    public int batchDeleteByZkt(List<Integer> zktList) {
        return this.prjSubtopicplanDao.batchDeleteByZkt(zktList);
    }

    @Override
    public int insertBatch(List<PrjSubtopicplan> planList) {
        return this.prjSubtopicplanDao.insertBatch(planList);
    }
}
