package com.ruoyi.project.sems.service.impl;

import com.ruoyi.framework.config.ThreadPoolConfig;
import com.ruoyi.project.sems.domain.TReportYlgd;
import com.ruoyi.project.sems.domain.TSpecdevYlgd;
import com.ruoyi.project.sems.mapper.TReportYlgdMapper;
import com.ruoyi.project.sems.mapper.TSpecdevYlgdMapper;
import com.ruoyi.project.sems.service.ITReportYlgdService;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 压力管道年检报告Service业务层处理
 *
 * @author ruoyi
 * @date 2021-09-02
 */
@Service("tReportYlgdService")
class TReportYlgdServiceImpl implements ITReportYlgdService {
    @Resource
    private TReportYlgdMapper tReportYlgdMapper;

    @Resource
    private TSpecdevYlgdMapper tSpecdevYlgdMapper;


    @Override
    public int insertByTSpecdevYlgd() {
        List<Long> longs = this.tReportYlgdMapper.queryNeedInsertIds();
        if (longs.size() > 0) {
            List<TSpecdevYlgd> tSpecdevYlgds = this.tSpecdevYlgdMapper.selectTSpecdevYlgdByIds(longs);
            ExecutorService executorService = Executors.newFixedThreadPool(30);
            for (TSpecdevYlgd specdevYlgd : tSpecdevYlgds) {
                executorService.execute(() -> {
                    this.tReportYlgdMapper.insertByTSpecdevYlgd(specdevYlgd);
                });
            }
            executorService.shutdown();
        }
        return 0;
    }

    @Override
    public int updateByTSpecdevYlgd() {
        List<Long> longs = this.tReportYlgdMapper.queryNeedUpdateIds();
        if (longs.size() > 0) {
            List<TSpecdevYlgd> tSpecdevYlgds = this.tSpecdevYlgdMapper.selectTSpecdevYlgdByIds(longs);
            ExecutorService executorService = Executors.newFixedThreadPool(30);
            for (TSpecdevYlgd tSpecdevYlgd : tSpecdevYlgds) {
                executorService.execute(() -> {
                    this.tReportYlgdMapper.updateByTSpecdevYlgd(tSpecdevYlgd);
                });
            }
            executorService.shutdown();
        }
        return 0;
    }


    @Override
    public int deleteTReportYlgdByIds() {
        List<Long> longs = this.tReportYlgdMapper.queryNeedDeleteIds();
        if (longs.size() > 0) {
            Long[] longs1 = longs.stream().toArray(Long[]::new);
            return this.tReportYlgdMapper.deleteTReportYlgdByIds(longs1);
        }
        return 0;
    }

    @Override
    public int updateForImport(TReportYlgd tReportYlgd) {
        return this.tReportYlgdMapper.updateForImport(tReportYlgd);
    }

    /**
     * 查询压力管道年检报告
     *
     * @param id 压力管道年检报告ID
     * @return 压力管道年检报告
     */
    @Override
    public TReportYlgd selectTReportYlgdById(Long id) {
        return tReportYlgdMapper.selectTReportYlgdById(id);
    }

    /**
     * 查询压力管道年检报告列表
     *
     * @param tReportYlgd 压力管道年检报告
     * @return 压力管道年检报告
     */
    @Override
    public List<TReportYlgd> selectTReportYlgdList(TReportYlgd tReportYlgd) {
        return tReportYlgdMapper.selectTReportYlgdList(tReportYlgd);
    }

    /**
     * 新增压力管道年检报告
     *
     * @param tReportYlgd 压力管道年检报告
     * @return 结果
     */
    @Override
    public int insertTReportYlgd(TReportYlgd tReportYlgd) {
        return tReportYlgdMapper.insertTReportYlgd(tReportYlgd);
    }

    /**
     * 修改压力管道年检报告
     *
     * @param tReportYlgd 压力管道年检报告
     * @return 结果
     */
    @Override
    public int updateTReportYlgd(TReportYlgd tReportYlgd) {
        return tReportYlgdMapper.updateTReportYlgd(tReportYlgd);
    }

    /**
     * 批量删除压力管道年检报告
     *
     * @param ids 需要删除的压力管道年检报告ID
     * @return 结果
     */
    @Override
    public int deleteTReportYlgdByIds(Long[] ids) {
        return tReportYlgdMapper.deleteTReportYlgdByIds(ids);
    }

    /**
     * 删除压力管道年检报告信息
     *
     * @param id 压力管道年检报告ID
     * @return 结果
     */
    @Override
    public int deleteTReportYlgdById(Long id) {
        return tReportYlgdMapper.deleteTReportYlgdById(id);
    }
}
