/**
 * Copyright 2019 DH
 * All right reserved.
 * 项目名称: 运维系统
 * 创建日期:2023/9/12
 */
package org.springblade.modules.test;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/***
 * Date:2023/9/12
 * Title:文件所属模块（必须填写）
 * Description：对本文件的详细描述，原则上不能少于30字
 * @author dylan
 * @version 1.0
 * Remark：认为有必要的其他信息
 */
@RestController
@Slf4j
@RequestMapping("galaxy-test/test")
@AllArgsConstructor
@Api(value = "运维单位管理", tags = "运维单位管理")
public class TestController extends BladeController {

	@GetMapping("/map/json")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "获取配置项", notes = "获取配置项")
	public R<List<JSONObject>> getMapJson() {
		List<JSONObject> area = new ArrayList<>();

		JSONObject jsonObject = null;
		try {
			jsonObject = JSONObject.parseObject(new FileInputStream("D:\\tmp\\sh.json"), JSONObject.class);
			log.info(jsonObject.toJSONString());
			JSONArray features = jsonObject.getJSONArray("features");
			for (int j = 0; j < features.size(); j++) {
				JSONObject d = new JSONObject();
				List<JSONObject> datas = new ArrayList<>();
				JSONObject d1 = features.getJSONObject(j);
				JSONObject geometry = d1.getJSONObject("geometry");
				JSONObject pp = d1.getJSONObject("properties");
				JSONArray center = pp.getJSONArray("center");
				JSONArray coordinates = geometry.getJSONArray("coordinates");
				JSONArray locations = coordinates.getJSONArray(0).getJSONArray(0);
				for (int i = 0; i < locations.size(); i++) {
					JSONArray l = locations.getJSONArray(i);
					JSONObject p = new JSONObject();
					p.put("longitude", l.getDoubleValue(0));
					p.put("latitude", l.getDoubleValue(1));
					datas.add(p);
				}
				log.info(coordinates.toJSONString());
				d.put("data", datas);
				d.put("center", center);
				d.put("name", pp.getString("name"));
				d.put("id",j);
				area.add(d);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return R.data(area);
	}
}
