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

import java.util.List;

import com.ruoyi.project.plant.domain.TMtActionlist;
import com.ruoyi.project.plant.domain.TMtEhsopenitem;
import com.ruoyi.project.plant.domain.TMtKeymaintenance;
import com.ruoyi.project.plant.mapper.TMtActionlistMapper;
import com.ruoyi.project.plant.mapper.TMtEhsopenitemMapper;
import com.ruoyi.project.plant.mapper.TMtKeymaintenanceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.plant.mapper.TMtMeetingMapper;
import com.ruoyi.project.plant.domain.TMtMeeting;
import com.ruoyi.project.plant.service.ITMtMeetingService;

import javax.annotation.Resource;

/**
 * 装置会议Service业务层处理
 *
 * @author ruoyi
 * @date 2020-12-30
 */
@Service
public class TMtMeetingServiceImpl implements ITMtMeetingService
{
    @Resource
    private TMtMeetingMapper tMtMeetingMapper;
    @Resource
    private TMtActionlistMapper tMtActionlistMapper;
    @Resource
    private TMtKeymaintenanceMapper tMtKeymaintenanceMapper;
    @Resource
    private TMtEhsopenitemMapper tMtEhsopenitemMapper;
    /**
     * 查询装置会议
     *
     * @param id 装置会议ID
     * @return 装置会议
     */
    @Override
    public TMtMeeting selectTMtMeetingById(Long id)
    {
        return tMtMeetingMapper.selectTMtMeetingById(id);
    }

    /**
     * 查询装置会议列表
     *
     * @param tMtMeeting 装置会议
     * @return 装置会议
     */
    @Override
    public List<TMtMeeting> selectTMtMeetingList(TMtMeeting tMtMeeting)
    {
        return tMtMeetingMapper.selectTMtMeetingList(tMtMeeting);
    }

    /**
     * 新增装置会议
     *
     * @param tMtMeeting 装置会议
     * @return 结果
     */
    @Override
    public int insertTMtMeeting(TMtMeeting tMtMeeting)
    {
        tMtMeetingMapper.insertTMtMeeting(tMtMeeting);
        TMtActionlist t = new TMtActionlist();
        t.setIsHis(0l);

        List<TMtActionlist> actionlists =  tMtActionlistMapper.selectTMtActionlistList(t);
        for (TMtActionlist a : actionlists
             ) {
            a.setMeetingId(tMtMeeting.getId());
            a.setIsHis(1l);
            tMtActionlistMapper.insertTMtActionlist(a);
        }

        TMtEhsopenitem tMtEhsopenitem = new TMtEhsopenitem();
        tMtEhsopenitem.setIsHis(0l);
        List<TMtEhsopenitem> ehsopenitemList = tMtEhsopenitemMapper.selectTMtEhsopenitemList(tMtEhsopenitem);
        for (TMtEhsopenitem m : ehsopenitemList
        ) {
            m.setMeetingId(tMtMeeting.getId());
            m.setIsHis(1l);
            tMtEhsopenitemMapper.insertTMtEhsopenitem(m);
        }

        TMtKeymaintenance tk = new TMtKeymaintenance();
        tk.setIsHis(0l);
        List<TMtKeymaintenance> tMtKeymaintenanceList = tMtKeymaintenanceMapper.selectTMtKeymaintenanceList(tk);
        for (TMtKeymaintenance m : tMtKeymaintenanceList
             ) {
            m.setMeetingId(tMtMeeting.getId());
            m.setIsHis(1l);
            tMtKeymaintenanceMapper.insertTMtKeymaintenance(m);
        }
        return 1;
    }

    /**
     * 修改装置会议
     *
     * @param tMtMeeting 装置会议
     * @return 结果
     */
    @Override
    public int updateTMtMeeting(TMtMeeting tMtMeeting)
    {
        return tMtMeetingMapper.updateTMtMeeting(tMtMeeting);
    }

    /**
     * 批量删除装置会议
     *
     * @param ids 需要删除的装置会议ID
     * @return 结果
     */
    @Override
    public int deleteTMtMeetingByIds(Long[] ids)
    {
        return tMtMeetingMapper.deleteTMtMeetingByIds(ids);
    }

    /**
     * 删除装置会议信息
     *
     * @param id 装置会议ID
     * @return 结果
     */
    @Override
    public int deleteTMtMeetingById(Long id)
    {
        return tMtMeetingMapper.deleteTMtMeetingById(id);
    }
}
