package edu.neusoft.project.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import edu.neusoft.project.model.vo.ProvinceAdd;

import java.util.ArrayList;
import java.util.List;

public class EchartsMapValue {
    private Object[] data[];
    private Object[] toolTipData[]; //eq cell[ cell[cell[],cell[]] .....]

    private Object basicStr[];  // eq cell[];
    private Object detailStr[]; // eq cell[cell[],cell[]]

    private Object cell[];      // cell[name:""(String),value: (Integer)]

    static JSONArray arrayBasic = new JSONArray();

    static JSONArray arrayDetail = new JSONArray();

//    int i = 0 ;

    public static JSONObject mapJSONRefactor(List<ProvinceAdd> list){
        arrayBasic.clear();
        arrayDetail.clear();
        for (ProvinceAdd p:list) {
            //basic
            JSONObject line1 = new JSONObject();
            line1.clear();
            p.getPName();
            p.getNum();
            p.getPc();
            p.getPhone();
            line1.put("name",p.getPName());line1.put("value",p.getNum());
            System.out.println(line1);
            arrayBasic.add(line1);
            System.out.println("*****************************");

            //detail

            JSONObject line2 = new JSONObject();
            line2.clear();
            line2.put("name",p.getPName());

                    JSONArray array =new JSONArray();
                    JSONObject little1 = new JSONObject();
                    little1.clear();
                    little1.clear();
                    little1.put("name","PC");
                    little1.put("value",p.getPc());
//                    little1=little1.replaceAll("\"(\\w+)\"(\\s*:\\s*)", "$1$2");
                    array.add(little1);
                    JSONObject little2 = new JSONObject();
                    little2.clear();
                    little2.put("name","Phone");
                    little2.put("value",p.getPhone());
                    array.add(little2);

            line2.put("value",array);
            System.out.println(line2);
            arrayDetail.add(line2);

        }
//        System.out.println(arrayBasic.toJSONString());
//        System.out.println(arrayDetail.toJSONString());
//        List<JSONArray> arrayList= new ArrayList<>();
        JSONObject arrayList = new JSONObject();
        arrayList.clear();
//        arrayBasic=arrayBasic.replaceAll("\"(\\w+)\"(\\s*:\\s*)", "$1$2");
        arrayList.put("basic",arrayBasic);
        arrayList.put("detail",arrayDetail);

        return arrayList;
    }




}
