package com.elephant.framework.galaxy.aroad.module.szgl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.bigdata.*;
import com.elephant.framework.galaxy.aroad.module.codegen.response.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/szgl")
public class SzglController {
    /**
     *  全局搜索路段、收费站、桥梁、隧道
     * @Param keyword 搜索条件
     */
    @GetMapping("/bigdata")
    public R getBigData(String keyword, Page page) throws Exception {
        List<Map<String,Object>> responseList = new ArrayList<>();
        long total = 0;
        // 桥梁
        Map<String,Object> luKeBridges = EsUtil_fanshe.queryBridge(keyword, "basebridgealldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basebridgealldata lnKeBridge : (List<Basebridgealldata>)luKeBridges.get("list")){
            responseList.add(new HashMap<String,Object>(){{
                put("name",lnKeBridge.getQiaoliangmingcheng());
                put("iden","qiaoliang");
                put("idenVal", "桥梁");
                put("data", lnKeBridge);
            }});
        }
        total+=(long)luKeBridges.get("total");
        // 路线
//        ArrayList<Basehighwayalldata> basehighwayalldataList = EsUtil_fanshe.queryHighWayLXBH(keyword, "basehighwayalldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        Map<String,Object> lukehighways = EsUtil_fanshe.queryHighWay(keyword, "basehighwayalldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basehighwayalldata basehighwayalldata : (List<Basehighwayalldata>)lukehighways.get("list")){
            responseList.add(new HashMap<String,Object>(){{
                put("name",basehighwayalldata.getLuxianmingcheng());
                put("iden","luxian");
                put("idenVal", "路线");
                put("data", basehighwayalldata);
                put("total", lukehighways.get("total"));
            }});
        }
        total+=(long)lukehighways.get("total");
        // 隧道
        Map<String,Object> basicTunnels = EsUtil_fanshe.queryTunnel(keyword, "basetunnelalldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basetunnelalldata basicTunnel : (List<Basetunnelalldata>)basicTunnels.get("list")){
            responseList.add(new HashMap<String,Object>(){{
                put("name",basicTunnel.getSuidaomingcheng());
                put("iden","suidao");
                put("idenVal", "隧道");
                put("data", basicTunnel);
                put("total", basicTunnels.get("total"));
            }});
        }
        total+=(long)basicTunnels.get("total");
        // 收费站
        Map<String,Object> baseRoadTollStrings = EsUtil_fanshe.queryBaseRoadTollString(keyword, "baseroadtolldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(BaseRoadToll_String baseRoadToll_String : (List<BaseRoadToll_String>)baseRoadTollStrings.get("list")){
            responseList.add(new HashMap<String,Object>(){{
                put("name",baseRoadToll_String.getShortName());
                put("iden","shoufeizhan");
                put("idenVal", "收费站");
                put("data", baseRoadToll_String);
                put("total", baseRoadTollStrings.get("total"));
            }});
        }
        total+=(long)baseRoadTollStrings.get("total");
        // 服务区
        Map<String,Object> baseHighWayServices = EsUtil_fanshe.queryBaseHighWayService(keyword, "basehighwayservice", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(BaseHighWayService baseHighWayService : (List<BaseHighWayService>)baseHighWayServices.get("list")){
            responseList.add(new HashMap<String,Object>(){{
                put("name",baseHighWayService.getFwssmc());
                put("iden","fuwuqu");
                put("idenVal", "服务区");
                put("data", baseHighWayService);
            }});
        }
        total+=(long)baseHighWayServices.get("total");
        Map<String,Object> responseMap = new HashMap<>();
        responseMap.put("result",responseList);
        responseMap.put("total",total);
        return new R<>(responseMap);
    }
//    /**
//     * 查询桥梁
//     * @Param keyword 搜索条件
//     */
//    @GetMapping("/bridge")
//    public R getBridge(@RequestParam("keyword") String keyword) throws Exception {
//        ArrayList<Basebridgealldata> basebridgealldataList = EsUtil_fanshe.queryBridge(keyword, "basicbridgedata", "2018", 0, 2000000000);
//        return new R<>(basebridgealldataList);
//    }
//    /**
//     * 查询路段
//     * @Param keyword 搜索条件
//     */
//    @GetMapping("/highWay")
//    public R getHighWay(@RequestParam("keyword") String keyword) throws Exception {
//        ArrayList<Basehighwayalldata> basehighwayalldataList = EsUtil_fanshe.queryHighWay(keyword, "basichighwaydata", "2018", 0, 2000000000);
//        return new R<>(basehighwayalldataList);
//    }
//    /**
//     * 查询隧道
//     * @Param keyword 搜索条件
//     */
//    @GetMapping("/tunnel")
//    public R getTunnel(@RequestParam("keyword") String keyword) throws Exception {
//        List<Basetunnelalldata> basetunnelalldataList = EsUtil_fanshe.queryTunnel("广州桥", "basictunneldata", "2018", 0, 2000000000);
//        return new R<>(basetunnelalldataList);
//    }
//    /**
//     * 查询收费站
//     * @Param keyword 搜索条件
//     */
//    @GetMapping("/baseRoadToll")
//    public R getBaseRoadToll(@RequestParam("keyword") String keyword) throws Exception {
//        ArrayList<BaseRoadToll_String> baseRoadTollStrings = EsUtil_fanshe.queryBaseRoadTollString(keyword, "baseroadtolldata", "2018", 0, 2000000000);
//        return new R<>(baseRoadTollStrings);
//    }
}
