package com.ruoyi.spider.ie;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import cn.hutool.core.lang.Dict;
import cn.hutool.db.Entity;

/**
 * 院校
 *
 * @author duzj
 *
 */
public class SubjectService extends AuthService {
    private String tableName = "csdhe_subject";

    public void syncAll(Integer provinceId) {
        Dict params = commonParams();
        params.set("province_id", provinceId).set("high_school_type_id", 1).set("exam_type_id", 0);
        params.set("cate_id", 1399);
        JSONObject json = getJson("/api/v1.6.5/college/set-subject", params, authorization);
        JSONArray arr = json.getJSONObject("data").getJSONArray("user_subject_list");
        for (int i = 0; i < arr.size(); i++) {
            JSONObject row = arr.getJSONObject(i);
            Entity record = Entity.create(tableName);
            record.set("id", row.get("subject_id"));
            record.set("name", row.get("subject_name"));
            record.set("sort", row.get("sort"));
            record.set("type_id", row.get("type_id"));
            record.set("type_name", row.get("type_name"));
            insertOrUpdate(record, "id");
        }
    }

    public static void main(String[] args) {
        // 湖南省 5604，河南 5310
        Integer provinceId = 5310;
        SubjectService service = new SubjectService();
        service.syncAll(provinceId);
    }

}
