package com.xjrsoft.module.job;

import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.xjrsoft.XjrSoftApplication;
import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.common.mybatis.SqlRunnerAdapter;
import com.xjrsoft.common.utils.DatasourceUtil;
import com.xjrsoft.common.utils.SqlRunnerAdapterUtil;
import com.xjrsoft.module.base.entity.BaseClass;
import com.xjrsoft.module.base.entity.BaseGrade;
import com.xjrsoft.module.schedule.entity.JianyueData;
import com.xjrsoft.module.schedule.util.DataUtil;
import com.xjrsoft.module.schedule.util.ScheduleUtil;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author dzx
 * @date 2024/4/30
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = XjrSoftApplication.class)
class JianyuekbBaseDataTaskTest {


    @Test
    public void RefreshConnectionPool() {
        try {
            String sql = "SELECT distinct table_name FROM jianyue_data WHERE 1 = 1";
            List<Map<String, Object>> query = SqlRunnerAdapter.db().selectList(sql, JianyueData.class);
            Set<String> tables = new HashSet<>();
            for (Map<String, Object> queryMap : query) {
                String[] strings = SqlRunnerAdapterUtil.convertMapToStringArray(queryMap);
                tables.add(strings[0]);
            }
            sql = "SELECT * FROM jianyue_data WHERE 0 = 0";
            List<Map<String, Object>> list = SqlRunnerAdapter.db().selectList(sql, JianyueData.class);
            Map<String, Map<String, String>> dataMap = new HashMap<>();
            for (String table : tables) {
                Map<String, String> tableData = new HashMap<>();
                for (Map<String, Object> queryMap : list) {
                    JianyueData jianyueData = SqlRunnerAdapterUtil.convertMapToEntity(queryMap, JianyueData.class);
                    if(!table.equals(jianyueData.getTableName())){
                        continue;
                    }
                    tableData.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
                }
                dataMap.put(table, tableData);
            }

        } catch (Exception e) {
        }
    }

    @Test
    public void RefreshConnectionPool2() {
        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
        try {
            Db use = Db.use(datasource);
            String sql = "SELECT distinct table_name FROM jianyue_data WHERE 1 = 1";
            List<JianyueData> query = use.query(sql, JianyueData.class);
            Set<String> tables = new HashSet<>();
            for (JianyueData jianyueData : query) {
                tables.add(jianyueData.getTableName());
            }
            sql = "SELECT * FROM jianyue_data WHERE 0 = 0";
            List<JianyueData> list = use.query(sql, JianyueData.class);
            Map<String, Map<String, String>> dataMap = new HashMap<>();
            for (String table : tables) {
                Map<String, String> tableData = new HashMap<>();
                for (JianyueData jianyueData : list) {
                    if(!table.equals(jianyueData.getTableName())){
                        continue;
                    }
                    tableData.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
                }
                dataMap.put(table, tableData);
            }
            DataUtil dataUtil = new DataUtil();
            //查询校区
            String tableName = "xjr_department";

            //推送年级
            JsonArray schoolDistrictData = dataUtil.getSchoolDistrictData();
            tableName = "base_grade";
            Map<String, String> gradeMap = dataMap.get(tableName);
            //推送教职工
            tableName = "base_teacher";
            Map<String, String> teacherMap = dataMap.get(tableName);
            //推送教室
            tableName = "base_classroom";
            Map<String, String> classroomMap = dataMap.get(tableName);
            //推送行政班，先查询当前学期id
            String currenSemeter = dataUtil.getCurrenSemeter();
            tableName = "base_class";
            sql = "SELECT * FROM base_class WHERE delete_mark = 0" +
                " and id not in (SELECT source_id FROM jianyue_data WHERE table_name = 'base_class' AND source_id IS NOT NULL)";

            List<Map<String, Object>> dataList = SqlRunnerAdapter.db().selectList(sql, BaseClass.class);
            String semesterSerialNo = dataUtil.getCurrenSemeter();
            Map<String, String> idMap = new HashMap<>();
            JsonParser jsonParser = new JsonParser();
            for (Map<String, Object> baseClassMap : dataList) {
                BaseClass baseClass = SqlRunnerAdapterUtil.convertMapToEntity(baseClassMap, BaseClass.class);
                String url  = ScheduleUtil.apiUrl + "class/create";
                JsonObject paramJson = new JsonObject();
                if(baseClass.getTeacherId() != null && teacherMap.get(baseClass.getTeacherId().toString()) != null){
                    paramJson.addProperty("teacherSerialNo", teacherMap.get(baseClass.getTeacherId().toString()));
                }
                paramJson.addProperty("name", baseClass.getName());

                paramJson.addProperty("semesterSerialNo", semesterSerialNo);
                paramJson.addProperty("eduYearSerialNo", gradeMap.get(baseClass.getOrgId() + "_" + baseClass.getGradeId().toString()));
                paramJson.addProperty("extendId", baseClass.getId());
                if(baseClass.getClassroomId() != null && classroomMap.get(baseClass.getClassroomId().toString()) != null){
                    paramJson.addProperty("classRoomSerialNo", classroomMap.get(baseClass.getClassroomId().toString()));
                }
//                if(ids != null && ids.get(baseClass.getId().toString()) != null){
//                    url  = ScheduleUtil.apiUrl + "class/update";
//                    paramJson.addProperty("serialNo", ids.get(baseClass.getId().toString()));
//                    long timestamp = System.currentTimeMillis();
//                    //生成签名
//                    String sign = ScheduleUtil.createSign(timestamp);
//                    ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
//                    continue;
//                }

                //获取时间戳
                long timestamp = System.currentTimeMillis();
                //生成签名
                String sign = ScheduleUtil.createSign(timestamp);
                String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
                if(result == null){
                    continue;
                }
                JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
                idMap.put(baseClass.getId().toString(), resultJson.get("data").getAsString());
            }
            dataUtil.insertRecord("base_class", idMap);
        } catch (Exception e) {
        }
    }

    @Test
    void test3() throws Exception {
        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);

        System.out.println(timestamp);

        System.out.println(sign);
    }

    @Test
    void deleteData() throws Exception {
        long timestamp = System.currentTimeMillis();
        String sign = ScheduleUtil.createSign(timestamp);
        String url  = ScheduleUtil.apiUrl + "Class/page";

        JsonObject pageJson = new JsonObject();
        pageJson.addProperty("pageSize", 120);
        pageJson.addProperty("pageIndex", 1);
        JsonParser parser = new JsonParser();
        String doPost = ScheduleUtil.doPost(url, pageJson.toString(), sign, timestamp);
        JsonArray dataList = parser.parse(doPost).getAsJsonObject().get("data").getAsJsonObject().get("dataList").getAsJsonArray();
        List<String> ids = new ArrayList<>();
        Map<String, String> classIdNameMap = new HashMap<>();
        for (JsonElement jsonElement : dataList) {
            JsonObject object = jsonElement.getAsJsonObject();
            classIdNameMap.put(object.get("serialNo").getAsString(), object.get("name").getAsString());
        }

        String sql = "SELECT * FROM base_class WHERE delete_mark = 0";
        List<Map<String, Object>> classList = SqlRunnerAdapter.db().selectList(sql);
        Map<String, String> map = new HashMap<>();
        for (Map<String, Object> objectMap : classList) {
            map.put(objectMap.get("name").toString(), objectMap.get("id").toString());
        }

        String tableName = "jianyue_data";
        List<Entity> insertList = new ArrayList<>();
        for (String jianyueId : classIdNameMap.keySet()) {
            String className = classIdNameMap.get(jianyueId);
            String classId = map.get(className);
            Entity entity = Entity.create(tableName);
            entity.set("create_date", "2024-08-17 16:59:18");
            entity.set("table_name", "base_class");
            entity.set("source_id", classId);
            entity.set("jianyue_id", jianyueId);
            insertList.add(entity);
        }
        SqlRunnerAdapter.db().dynamicInsertBatch(tableName, insertList);
    }

    @Test
    void updateGrade() throws Exception {
        String url  = ScheduleUtil.apiUrl + "EduYear/page";
        JsonObject paramJson = new JsonObject();
        paramJson.addProperty("pageSize", 40);
        paramJson.addProperty("pageIndex", 1);

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);

        String doPost = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
        System.out.println(doPost);

//        JsonParser parser = new JsonParser();
//        JsonObject jsonObject = parser.parse(doPost).getAsJsonObject();
//        JsonArray jsonArray = jsonObject.get("data").getAsJsonObject().get("dataList").getAsJsonArray();
//
//        url = ScheduleUtil.apiUrl + "eduyear/update";
//        for (JsonElement jsonElement : jsonArray) {
//            JsonObject dataOne = jsonElement.getAsJsonObject();
//            dataOne.addProperty("schoolDistrictId", "48e0a5ae-6d0b-34dd-f31a-3a12feca72d1");
//
//            timestamp = System.currentTimeMillis();
//            //生成签名
//            sign = ScheduleUtil.createSign(timestamp);
//            String result = ScheduleUtil.doPost(url, dataOne.toString(), sign, timestamp);
//
//            System.out.println(result);
//        }
    }

    @Test
    void insertGrade() throws Exception {
        String url  = ScheduleUtil.apiUrl + "eduyear/create";
        JsonObject paramJson = new JsonObject();
        paramJson.addProperty("pageSize", 40);
        paramJson.addProperty("pageIndex", 1);

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);

        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
        Db use = Db.use(datasource);

        JsonParser jsonParser = new JsonParser();

        Map<String, String> idMap = new HashMap<>();
        //删除学生
        String sql = "SELECT * FROM jianyue_data WHERE table_name = 'xjr_department'";
        List<JianyueData> gradeList = use.query(sql, JianyueData.class);
        for (JianyueData jianyueData : gradeList) {
            if("48e0a5ae-6d0b-34dd-f31a-3a12feca72d1".equals(jianyueData.getJianyueId())){
                continue;
            }
            if(!"1684107782861680016".equals(jianyueData.getSourceId())){
                continue;
            }

            sql = "select * from base_grade where delete_mark = 0 and status = 1";
            List<BaseGrade> list = use.query(sql, BaseGrade.class);
            for (BaseGrade baseGrade : list) {
                url = ScheduleUtil.apiUrl + "eduyear/create";
                JsonObject dataJson = new JsonObject();
                dataJson.addProperty("schoolDistrictId", jianyueData.getJianyueId());
                dataJson.addProperty("period", 4);
                dataJson.addProperty("startYear", baseGrade.getTitle().replaceAll("年", ""));
                dataJson.addProperty("extendId", baseGrade.getId().toString());
                dataJson.addProperty("year", 3);

                //获取时间戳
                timestamp = System.currentTimeMillis();
                //生成签名
                sign = ScheduleUtil.createSign(timestamp);

                String result = ScheduleUtil.doPost(url, dataJson.toString(), sign, timestamp);

                JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();

                idMap.put(jianyueData.getSourceId() + "_" + baseGrade.getId().toString(), resultJson.get("data").getAsString());
            }
        }
        DataUtil dataUtil = new DataUtil();
        dataUtil.insertRecord("base_grade", idMap);
    }

    @Test
    void selectSchoolDistrict() throws Exception {
        String url  = ScheduleUtil.apiUrl + "SchoolDistrict/page";
        JsonObject paramJson = new JsonObject();
        paramJson.addProperty("pageSize", 40);
        paramJson.addProperty("pageIndex", 1);

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);

        String doPost = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);
        System.out.println(doPost);

    }

    @Test
    void updateClass() throws Exception {
        String url  = ScheduleUtil.apiUrl + "EduYear/page";
        JsonObject paramJson = new JsonObject();
        paramJson.addProperty("pageSize", 40);
        paramJson.addProperty("pageIndex", 1);

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);

        String doPost = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);


        JsonParser parser = new JsonParser();
        JsonObject jsonObject = parser.parse(doPost).getAsJsonObject();
        JsonArray jsonArray = jsonObject.get("data").getAsJsonObject().get("dataList").getAsJsonArray();

        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
        Db use = Db.use(datasource);
        String sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_grade'";
        List<JianyueData> gradeList = use.query(sql, JianyueData.class);
        Map<String, String> gradeMap = new HashMap<>();
        for (JianyueData jianyueData : gradeList) {
            gradeMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        url  = ScheduleUtil.apiUrl + "class/update";
        paramJson = new JsonObject();
        paramJson.addProperty("pageSize", 200);
        paramJson.addProperty("pageIndex", 1);

        timestamp = System.currentTimeMillis();
        //生成签名
        sign = ScheduleUtil.createSign(timestamp);

        doPost = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);

        sql = "SELECT * FROM base_class WHERE delete_mark = 0 and is_graduate = 1";
        List<BaseClass> dataList = use.query(sql, BaseClass.class);
        Map<String, BaseClass> classMap = new HashMap<>();
        for (BaseClass baseClass : dataList) {
            classMap.put(baseClass.getId().toString(), baseClass);
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_class'";
        List<JianyueData> classList = use.query(sql, JianyueData.class);
        Map<String, BaseClass> classMap2 = new HashMap<>();
        Map<String, String> classMap3 = new HashMap<>();
        for (JianyueData jianyueData : classList) {
            classMap2.put(jianyueData.getJianyueId(), classMap.get(jianyueData.getSourceId()));
            classMap3.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_classroom'";
        List<JianyueData> classroomList = use.query(sql, JianyueData.class);
        Map<String, String> classroomMap = new HashMap<>();
        for (JianyueData jianyueData : classroomList) {
            classroomMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_teacher'";
        List<JianyueData> teacherList = use.query(sql, JianyueData.class);
        Map<String, String> teacherMap = new HashMap<>();
        for (JianyueData jianyueData : teacherList) {
            teacherMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        url  = ScheduleUtil.apiUrl + "class/update";
        DataUtil dataUtil = new DataUtil();
        String currenSemeter = dataUtil.getCurrenSemeter();

        for (BaseClass baseClass : classMap2.values()) {
            if(baseClass == null){
                continue;
            }
            paramJson = new JsonObject();
            paramJson.addProperty("name", baseClass.getName());

            paramJson.addProperty("semesterSerialNo", currenSemeter);
            paramJson.addProperty("eduYearSerialNo", gradeMap.get(baseClass.getOrgId() + "_" + baseClass.getGradeId().toString()));
            paramJson.addProperty("extendId", baseClass.getId());
            paramJson.addProperty("classRoomSerialNo", classroomMap.get(baseClass.getClassroomId().toString()));
            paramJson.addProperty("serialNo", classMap3.get(baseClass.getId().toString()));
            paramJson.addProperty("teacherSerialNo", teacherMap.get(baseClass.getTeacherId().toString()));

            timestamp = System.currentTimeMillis();
            //生成签名
            sign = ScheduleUtil.createSign(timestamp);
            String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);

            System.out.println(baseClass.getName() + " -> " + result);
        }
    }


    @Test
    void updateClass2() throws Exception {

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);


        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
        Db use = Db.use(datasource);
        String sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_grade'";
        List<JianyueData> gradeList = use.query(sql, JianyueData.class);
        Map<String, String> gradeMap = new HashMap<>();
        for (JianyueData jianyueData : gradeList) {
            gradeMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM base_class WHERE delete_mark = 0 AND org_id = 1684107782861680016";
        List<BaseClass> dataList = use.query(sql, BaseClass.class);
        Map<String, BaseClass> classMap = new HashMap<>();
        for (BaseClass baseClass : dataList) {
            classMap.put(baseClass.getId().toString(), baseClass);
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_class'";
        List<JianyueData> classList = use.query(sql, JianyueData.class);
        Map<String, BaseClass> classMap2 = new HashMap<>();
        Map<String, String> classMap3 = new HashMap<>();
        for (JianyueData jianyueData : classList) {
            classMap2.put(jianyueData.getJianyueId(), classMap.get(jianyueData.getSourceId()));
            classMap3.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_classroom'";
        List<JianyueData> classroomList = use.query(sql, JianyueData.class);
        Map<String, String> classroomMap = new HashMap<>();
        for (JianyueData jianyueData : classroomList) {
            classroomMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_teacher'";
        List<JianyueData> teacherList = use.query(sql, JianyueData.class);
        Map<String, String> teacherMap = new HashMap<>();
        for (JianyueData jianyueData : teacherList) {
            teacherMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        String url  = ScheduleUtil.apiUrl + "class/create";
        DataUtil dataUtil = new DataUtil();
        String currenSemeter = dataUtil.getCurrenSemeter();
        Map<String, String> idMap = new HashMap<>();
        JsonParser jsonParser = new JsonParser();
        for (BaseClass baseClass : classMap.values()) {
            if(baseClass == null){
                continue;
            }
            JsonObject paramJson = new JsonObject();
            paramJson.addProperty("name", baseClass.getName());

            paramJson.addProperty("semesterSerialNo", currenSemeter);
            paramJson.addProperty("eduYearSerialNo", gradeMap.get(baseClass.getOrgId() + "_" + baseClass.getGradeId().toString()));
            paramJson.addProperty("extendId", baseClass.getId());
            if(baseClass.getClassroomId() != null && classroomMap.get(baseClass.getClassroomId().toString()) != null){
                paramJson.addProperty("classRoomSerialNo", classroomMap.get(baseClass.getClassroomId().toString()));
            }
            if(baseClass.getTeacherId() != null && teacherMap.get(baseClass.getTeacherId().toString()) != null){
                paramJson.addProperty("teacherSerialNo", teacherMap.get(baseClass.getTeacherId().toString()));
            }
            paramJson.addProperty("serialNo", classMap3.get(baseClass.getId().toString()));

            timestamp = System.currentTimeMillis();
            //生成签名
            sign = ScheduleUtil.createSign(timestamp);
            String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);

            System.out.println(baseClass.getName() + " -> " + result);
            if(result == null){
                continue;
            }
            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
            idMap.put(baseClass.getId().toString(), resultJson.get("data").getAsString());
        }
        dataUtil.insertRecord("base_class", idMap);
    }

    @Test
    void updateClass3() throws Exception {

        long timestamp = System.currentTimeMillis();
        //生成签名
        String sign = ScheduleUtil.createSign(timestamp);


        DataSource datasource = DatasourceUtil.getDataSource(GlobalConstant.DEFAULT_DATASOURCE_KEY);
        Db use = Db.use(datasource);
        String sql = "SELECT * FROM base_class WHERE delete_mark = 0 and is_graduate = 1" +
                " and id in (SELECT source_id FROM jianyue_data WHERE table_name = 'base_class' AND jianyue_id = '')";
        List<JianyueData> gradeList = use.query(sql, JianyueData.class);
        Map<String, String> gradeMap = new HashMap<>();
        for (JianyueData jianyueData : gradeList) {
            gradeMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM base_class WHERE delete_mark = 0 AND org_id = 1684107782861680016";
        List<BaseClass> dataList = use.query(sql, BaseClass.class);
        Map<String, BaseClass> classMap = new HashMap<>();
        for (BaseClass baseClass : dataList) {
            classMap.put(baseClass.getId().toString(), baseClass);
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_class'";
        List<JianyueData> classList = use.query(sql, JianyueData.class);
        Map<String, BaseClass> classMap2 = new HashMap<>();
        Map<String, String> classMap3 = new HashMap<>();
        for (JianyueData jianyueData : classList) {
            classMap2.put(jianyueData.getJianyueId(), classMap.get(jianyueData.getSourceId()));
            classMap3.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_classroom'";
        List<JianyueData> classroomList = use.query(sql, JianyueData.class);
        Map<String, String> classroomMap = new HashMap<>();
        for (JianyueData jianyueData : classroomList) {
            classroomMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        sql = "SELECT * FROM jianyue_data WHERE table_name = 'base_teacher'";
        List<JianyueData> teacherList = use.query(sql, JianyueData.class);
        Map<String, String> teacherMap = new HashMap<>();
        for (JianyueData jianyueData : teacherList) {
            teacherMap.put(jianyueData.getSourceId(), jianyueData.getJianyueId());
        }

        String url  = ScheduleUtil.apiUrl + "class/create";
        DataUtil dataUtil = new DataUtil();
        String currenSemeter = dataUtil.getCurrenSemeter();
        Map<String, String> idMap = new HashMap<>();
        JsonParser jsonParser = new JsonParser();
        for (BaseClass baseClass : classMap.values()) {
            if(baseClass == null){
                continue;
            }
            JsonObject paramJson = new JsonObject();
            paramJson.addProperty("name", baseClass.getName());

            paramJson.addProperty("semesterSerialNo", currenSemeter);
            paramJson.addProperty("eduYearSerialNo", gradeMap.get(baseClass.getOrgId() + "_" + baseClass.getGradeId().toString()));
            paramJson.addProperty("extendId", baseClass.getId());
            if(baseClass.getClassroomId() != null && classroomMap.get(baseClass.getClassroomId().toString()) != null){
                paramJson.addProperty("classRoomSerialNo", classroomMap.get(baseClass.getClassroomId().toString()));
            }
            if(baseClass.getTeacherId() != null && teacherMap.get(baseClass.getTeacherId().toString()) != null){
                paramJson.addProperty("teacherSerialNo", teacherMap.get(baseClass.getTeacherId().toString()));
            }
            paramJson.addProperty("serialNo", classMap3.get(baseClass.getId().toString()));

            timestamp = System.currentTimeMillis();
            //生成签名
            sign = ScheduleUtil.createSign(timestamp);
            String result = ScheduleUtil.doPost(url, paramJson.toString(), sign, timestamp);

            System.out.println(baseClass.getName() + " -> " + result);
            if(result == null){
                continue;
            }
            JsonObject resultJson = jsonParser.parse(result).getAsJsonObject();
            idMap.put(baseClass.getId().toString(), resultJson.get("data").getAsString());
        }
        dataUtil.insertRecord("base_class", idMap);
    }
}