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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.project.sems.domain.TReportYlrq;
import com.ruoyi.project.sems.domain.TSpecdevCc;
import com.ruoyi.project.sems.domain.TSpecdevYlrq;
import com.ruoyi.project.sems.mapper.TReportYlrqMapper;
import com.ruoyi.project.sems.mapper.TSpecdevCcMapper;
import com.ruoyi.project.sems.mapper.TSpecdevYlrqMapper;
import com.ruoyi.project.sems.service.ITReportYlrqService;
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("tReportYlrqService")
public class TReportYlrqServiceImpl extends ServiceImpl<TReportYlrqMapper, TReportYlrq> implements ITReportYlrqService {
    @Resource
    private TReportYlrqMapper tReportYlrqMapper;

    @Resource
    private TSpecdevYlrqMapper tSpecdevYlrqMapper;

    @Override
    public int insertByTSpecdevYlrq() {
        List<Long> longs = this.tReportYlrqMapper.queryNeedInsertIds();
        if (longs.size() > 0) {
            List<TSpecdevYlrq> tSpecdevYlrqs = this.tSpecdevYlrqMapper.selectTSpecdevYlrqByIds(longs);
            ExecutorService executorService = Executors.newFixedThreadPool(30);
            for (TSpecdevYlrq specdevYlrq : tSpecdevYlrqs) {
                executorService.execute(()->{
                    this.tReportYlrqMapper.insertByTSpecdevYlrq(specdevYlrq);
                });
            }
            executorService.shutdown();
        }
        return 0;
    }

    @Override
    public int updateByTSpecdevYlrq() {
        List<Long> longs = this.tReportYlrqMapper.queryNeedUpdateIds();
        if (longs.size() > 0) {
            List<TSpecdevYlrq> tSpecdevYlrqs = this.tSpecdevYlrqMapper.selectTSpecdevYlrqByIds(longs);
            ExecutorService executorService = Executors.newFixedThreadPool(30);
            for (TSpecdevYlrq tSpecdevYlrq : tSpecdevYlrqs) {
                executorService.execute(()->{
                    this.tReportYlrqMapper.updateByTSpecdevYlrq(tSpecdevYlrq);
                });
            }
            executorService.shutdown();
        }
        return 0;
    }

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

    @Override
    public int updateForImport(TReportYlrq tReportYlrq) {
        return this.tReportYlrqMapper.updateForImport(tReportYlrq);
    }

    /**
     * 查询压力容器年检报告
     *
     * @param id 压力容器年检报告ID
     * @return 压力容器年检报告
     */
    @Override
    public TReportYlrq selectTReportYlrqById(Long id) {
        return tReportYlrqMapper.selectTReportYlrqById(id);
    }

    /**
     * 查询压力容器年检报告列表
     *
     * @param tReportYlrq 压力容器年检报告
     * @return 压力容器年检报告
     */
    @Override
    public List<TReportYlrq> selectTReportYlrqList(TReportYlrq tReportYlrq) {
        return tReportYlrqMapper.selectTReportYlrqList(tReportYlrq);
    }

    /**
     * 新增压力容器年检报告
     *
     * @param tReportYlrq 压力容器年检报告
     * @return 结果
     */
    @Override
    public int insertTReportYlrq(TReportYlrq tReportYlrq) {
        return tReportYlrqMapper.insertTReportYlrq(tReportYlrq);
    }

    /**
     * 修改压力容器年检报告
     *
     * @param tReportYlrq 压力容器年检报告
     * @return 结果
     */
    @Override
    public int updateTReportYlrq(TReportYlrq tReportYlrq) {
        return tReportYlrqMapper.updateTReportYlrq(tReportYlrq);
    }

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

    /**
     * 删除压力容器年检报告信息
     *
     * @param id 压力容器年检报告ID
     * @return 结果
     */
    @Override
    public int deleteTReportYlrqById(Long id) {
        return tReportYlrqMapper.deleteTReportYlrqById(id);
    }
}
