package com.liang.service.impl;

import com.liang.dao.PrjDivisioncompanyDao;
import com.liang.entity.PrjSubtopic;
import com.liang.dao.PrjSubtopicDao;
import com.liang.service.PrjSubtopicService;
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;
import java.util.Map;

/**
 * (PrjSubtopic)表服务实现类
 *
 * @author makejava
 * @since 2023-03-20 16:25:07
 */
@Service("prjSubtopicService")
public class PrjSubtopicServiceImpl implements PrjSubtopicService {
    @Resource
    private PrjSubtopicDao prjSubtopicDao;
    @Resource
    private PrjDivisioncompanyDao divisioncompanyDao;
    @Resource
    private PrjSubtopicplanService subtopicplanService;

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

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

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

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

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        //删除子课题单位分工
        divisioncompanyDao.deleteByZkt(id);
        //删除子课题计划
        subtopicplanService.deleteByZkt(id);
        return this.prjSubtopicDao.deleteById(id) > 0;
    }

    @Override
    public List<PrjSubtopic> getSubtopicList(Integer xm) {
        return this.prjSubtopicDao.getSubtopicList(xm);
    }

    @Override
    public int batchDelete(List<Integer> idList) {
        //删除子课题单位分工
        divisioncompanyDao.batchDeleteByZkt(idList);
        //删除子课题计划
        subtopicplanService.batchDeleteByZkt(idList);
        return this.prjSubtopicDao.batchDelete(idList);
    }

    @Override
    public int deleteByXm(Integer xm) {
        return this.prjSubtopicDao.deleteByXm(xm);
    }

    @Override
    public int batchDeleteByXm(List<Integer> xmList) {
        return this.prjSubtopicDao.batchDeleteByXm(xmList);
    }

    @Override
    public List<Map<String, Object>> queryProjectDate(int id) {
        return prjSubtopicDao.queryProjectDate(id);
    }
}
