package com.live.xmutils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.live.enums.ApiModele;
import com.live.enums.Terminal;
import com.live.utils.XMBaseTest;


public class GetStudentId extends XMBaseTest {

    //private Object JSONArray;

    public String getFinishLiveCourseId() {

        dataApi.setApiModule(ApiModele.CloudClass_B)
                .setApiName("API_queryStudentVisitData")
                .setTerminal(Terminal.B);
        super.beforeDataRequest();

//        JSONObject obj = new JSONObject();
//        obj.put("courseState", "FINISH");
//        obj.put("instId", dataApi.getLoginInfo().getInstId());
//
//        dataApi.doRequest(com.live.enums.RequestType.JSON, dataparams, obj.toJSONString(), dataheadrs).assetsSuccess(true);
//
//        String liveCourseId = dataApi.getBodyInJSON().getJSONObject("result").getJSONArray("records").getJSONObject(0).getString("liveCourseId");


        //dataApi.setApiName("API_queryStudentVisitData");
        //super.beforeDataRequest();

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("liveCourseId", "1334309884730617857");

        dataApi.doRequest(com.live.enums.RequestType.JSON, dataparams, jsonObject.toJSONString(), dataheadrs).assetsSuccess(true);
        JSONObject responseRes = dataApi.getBodyInJSON();

        JSONArray jsonArray =responseRes.getJSONObject("result").getJSONArray("records");
        System.out.println("数组是"+jsonArray);


        String liveSId = null;
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            String createdReport = (String) object.get("createdReport");
            String liveStudentId = (String) object.get("liveStudentId");
//            if (createdReport.equals("VALID")) {
//                System.out.println("if语句");
//                LiveSId = liveStudentId;
//                break;
//            }
            //return liveStudentId;
            System.out.println(liveStudentId+"学生id");
        }
        return liveSId;
    }

}
