package com.usoftchina.uas.office.qywx.service;

import com.usoftchina.uas.office.qywx.entity.Meeting;
import com.usoftchina.uas.office.service.AbstractService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yingp
 * @date 2020/2/16
 */
@Service
public class UasMeetingService extends AbstractService {

    public Meeting getById(Integer id) {
        Meeting meeting = queryForBean("select Meetingroomapply.*,em_qywx from Meetingroomapply,employee where ma_recorder=em_name and ma_id=? and em_qywx is not null",
                Meeting.class, id);
        if (null != meeting) {
            Meeting.MeetingRoom room = queryForBean("select * from Meetingroom where mr_code=?",
                    Meeting.MeetingRoom.class, meeting.getMa_mrcode());
            meeting.setRoom(room);
            List<Meeting.MeetingAttendee> attendees = queryForBeanList("select MeetingDetail.*,em_qywx from MeetingDetail,employee where md_emcode=em_code and md_maid=? and em_qywx is not null and md_participants<>?",
                    Meeting.MeetingAttendee.class, id, meeting.getMa_recorder());
            meeting.setAttendees(attendees);
        }
        return meeting;
    }

    public String getScheduleId(Integer id) {
        return queryForObject("select ma_scheduleid from Meetingroomapply where ma_id=?", String.class, id);
    }

    public void setScheduleId(Meeting meeting) {
        jdbcTemplate.update("update Meetingroomapply set ma_scheduleid=? where ma_id=?", meeting.getMa_scheduleid(), meeting.getMa_id());
    }
}
