package com.weaver.seconddev.njwebservice;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weaver.seconddev.njwebservice.entity.MeetingReq;
import com.weaver.seconddev.njwebservice.entity.MeetingRes;
import com.weaver.seconddev.njwebservice.entity.MeetingReturn;
import com.weaver.seconddev.njwebservice.util.SecondUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("meetingService")
public class MeetingService {

    private final static Logger log = LoggerFactory.getLogger(MeetingService.class);

    public MeetingRes getMeeting(MeetingReq param) {
        String loginname = param.getDATAS().getLoginname();
        String password = param.getDATAS().getPassword();
        String companyIds = param.getDATAS().getCompanyIds();
        String startdate = param.getDATAS().getStartdate();
        String enddate = param.getDATAS().getEnddate();
        String sysid = param.getSYSID();
        String sendId = param.getSENDID();
        String itfid = param.getITFID();

        String message = SecondUtil.getMeetingInfo(loginname, password, companyIds, startdate, enddate);
        MeetingRes res = new MeetingRes();
        res.setSYSID(sysid);
        res.setITFID(itfid);
        res.setSENDID(sendId);
        JSONObject object = JSONObject.parseObject(message);
        String status = object.getString("status");
        String msg = object.getString("msg");
        if ("success".equals(status)) {
            res.setISTAT("S");
            res.setMESSAGE("获取成功");
            res.setDATAS((MeetingReturn[]) JSONArray.parseObject(msg, MeetingReturn[].class));
           log.error("获取公司ID为" + companyIds + ",开始时间为" + startdate + ",结束时间为" + enddate + "的会议室信息成功!");
        } else {
            res.setISTAT("F");
            res.setMESSAGE(msg);
            res.setDATAS((MeetingReturn[])null);
            log.error("获取公司ID为" + companyIds + ",开始时间为" + startdate + ",结束时间为" + enddate + "的会议室信息失败:" + msg);
        }

        return res;
    }

}
