package com.ruoyi.spider.ie;

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

import cn.hutool.core.io.FileUtil;
import cn.hutool.db.Entity;

public class ProvinceService extends AbstraceService {
    public void load() {
        JSONObject json = JSON.parseObject(FileUtil.readUtf8String("./ie/province.json"));
        JSONArray arr = json.getJSONObject("data").getJSONArray("area");
        for (int i = 0; i < arr.size(); i++) {
            JSONObject bean = arr.getJSONObject(i);
            Entity entity = Entity.create("csdhe_area").parseBean(bean);
            entity.set("parent_id", entity.remove("pid"));
            insertOrUpdate(entity, "id");
        }
        System.out.println("加载地区信息成功!");
    }

    public static void main(String[] args) {

        new ProvinceService().load();
    }

}
