package com.zcloud.controller.positioning;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.util.Jurisdiction;
import com.zcloud.util.PLSUtil;
import com.zcloud.util.ReturnMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 说明：定位管理-告警管理
 * 作者：wangxuan
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/positAlarm")
public class MapSettingController extends BaseController {
    /**
     * @Description: 创建图层
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public ReturnMap list(Page page) throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.getLayerList(
                Jurisdiction.getCORPINFO_ID(), Integer.parseInt(pageData.getString("currentPage")), Integer.parseInt(pageData.getString("showCount")), pageData.getString("str"));
        if (body != null) {
            List<JSONObject> list = body.getJSONArray("rows").toJavaList(JSONObject.class);
            returnMap.put("varList", list);
            page.setTotalResult(body.getIntValue("total"));
            returnMap.put("page", page);
        }
        return returnMap;
    }

    /**
     * @Description: 处理告警
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/save")
    @ResponseBody
    public ReturnMap save() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("list"));
        pageData.put("list", list);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/region/layer", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 详情
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/goEdit")
    @ResponseBody
    public ReturnMap goEdit() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralGetById("/region/layer/", Integer.parseInt(pageData.getString("layId")), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 修改
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/edit")
    @ResponseBody
    public ReturnMap edit() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray list = JSONObject.parseArray(pageData.getString("list"));
        pageData.put("list", list);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPut("/region/layer", pageData, Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 修改
     * @Author: dearLin
     * @Date: 2024/1/26/026 16:43
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/remove")
    @ResponseBody
    public ReturnMap remove() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralDelete("/region/layer/", pageData.getString("DATA_IDS"), Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    // 作业票区域
    @RequestMapping(value = "/region/list")
    @ResponseBody
    public ReturnMap getFenceList() throws Exception {
        PageData pageData = this.getPageData();
        return ReturnMap.ok().put("data", PLSUtil.getRyRegionList(Jurisdiction.getCORPINFO_ID(), pageData.getString("str"),
                Integer.parseInt(pageData.getString("currentPage")), Integer.parseInt(pageData.getString("showCount")),
                Integer.parseInt(pageData.getString("type"))));
    }


    // 路径规划
    @RequestMapping(value = "/coordinateLine/tree")
    @ResponseBody
    public ReturnMap coordinateLineTree() throws Exception {
        PageData pageData = this.getPageData();
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralList("/location/coordinateLine/tree", pageData);
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 新建路径规划
     * @Author: dearLin
     * @Date: 2024/2/22/022 15:48
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/coordinateLine/addCoordinateLine")
    @ResponseBody
    public ReturnMap addCoordinateLine() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray coordinateGroup = JSONObject.parseArray(pageData.getString("coordinateGroup"));
        pageData.put("coordinateGroup", coordinateGroup);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralPost("/location/coordinateLine/addCoordinateLine", pageData,Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }

    /**
     * @Description: 路径规划批量删除
     * @Author: dearLin
     * @Date: 2024/2/22/022 15:48
     * @Param: [] []
     * @Return: com.zcloud.util.ReturnMap
     */
    @RequestMapping(value = "/coordinateLine/batchDelete")
    @ResponseBody
    public ReturnMap batchDelete() throws Exception {
        PageData pageData = this.getPageData();
        JSONArray coordinateGroup = JSONObject.parseArray(pageData.getString("coordinateGroup"));
        pageData.put("coordinateGroup", coordinateGroup);
        ReturnMap returnMap = new ReturnMap();
        JSONObject body = PLSUtil.GeneralDelete("/location/coordinateLine/", pageData.getString("DATA_IDS"),Jurisdiction.getCORPINFO_ID());
        if (body != null) {
            returnMap.putAll(body);
        }
        return returnMap;
    }



}
