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<>();
//        //查询匹配桥梁名称
//        Boolean bridgeOne = EsUtil_fanshe.queryBridgeOne(keyword, "basicbridgedata", "2018", 0, 2000000000);
//        if(bridgeOne){
//            responseList.add(new HashMap<String,Object>(){{
//                put("label","桥梁");
//                put("name","qiaoliang");
//            }});
//        }
//        //查询匹配路段名称
//        Boolean highWayOne = EsUtil_fanshe.queryHighWayOne(keyword ,"basichighwaydata", "2018", 0, 2000000000);
//        if(highWayOne){
//            responseList.add(new HashMap<String,Object>(){{
//                put("label","路段");
//                put("name","luduan");
//            }});
//        }
//        //查询匹配隧道名称
//        Boolean tunnelOne = EsUtil_fanshe.queryTunnelOne(keyword, "basictunneldata", "2018", 0, 2000000000);
//        if(tunnelOne){
//            responseList.add(new HashMap<String,Object>(){{
//                put("label","隧道");
//                put("name","suidao");
//            }});
//        }
//        //查询匹配收费站名称
//        Boolean baseRoadTollOne = EsUtil_fanshe.queryBaseRoadTollOne(keyword, "baseroadtolldata", "2018", 0, 2000000000);
//        if(baseRoadTollOne){
//            responseList.add(new HashMap<String,Object>(){{
//                put("label","收费站");
//                put("name","shoufeizhan");
//            }});
//        }
        // 桥梁
        List<Basebridgealldata> luKeBridges = EsUtil_fanshe.queryBridge(keyword, "basicbridgedata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basebridgealldata lnKeBridge : luKeBridges){
            responseList.add(new HashMap<String,Object>(){{
                put("name",lnKeBridge.getQiaoliangmingcheng());
                put("iden","qiaoliang");
                put("idenVal", "桥梁");
                put("data", lnKeBridge);
            }});
        }
        // 路线
//        ArrayList<Basehighwayalldata> basehighwayalldataList = EsUtil_fanshe.queryHighWayLXBH(keyword, "basehighwayalldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        List<Basehighwayalldata> lukehighways = EsUtil_fanshe.queryHighWay(keyword, "basichighwaydata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basehighwayalldata basehighwayalldata : lukehighways){
            responseList.add(new HashMap<String,Object>(){{
                put("name",basehighwayalldata.getLuxianmingcheng());
                put("iden","luxian");
                put("idenVal", "路线");
                put("data", basehighwayalldata);
            }});
        }
        // 隧道
        List<Basetunnelalldata> basicTunnels = EsUtil_fanshe.queryTunnel(keyword, "basictunneldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(Basetunnelalldata basicTunnel : basicTunnels){
            responseList.add(new HashMap<String,Object>(){{
                put("name",basicTunnel.getSuidaomingcheng());
                put("iden","suidao");
                put("idenVal", "隧道");
                put("data", basicTunnel);
            }});
        }
        // 收费站
        List<BaseRoadToll_String> baseRoadTollStrings = EsUtil_fanshe.queryBaseRoadTollString(keyword, "baseroadtolldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(BaseRoadToll_String baseRoadToll_String : baseRoadTollStrings){
            responseList.add(new HashMap<String,Object>(){{
                put("name",baseRoadToll_String.getShortName());
                put("iden","shoufeizhan");
                put("idenVal", "收费站");
                put("data", baseRoadToll_String);
            }});
        }
        // 服务区
        List<BaseHighWayService> baseHighWayServices = EsUtil_fanshe.queryBaseHighWayService(keyword, "baseroadtolldata", "2018", (int)((page.getCurrent()-1)*page.getSize()), (int)page.getSize());
        for(BaseHighWayService baseHighWayService : baseHighWayServices){
            responseList.add(new HashMap<String,Object>(){{
                put("name",baseHighWayService.getFwssmc());
                put("iden","fuwuqu");
                put("idenVal", "服务区");
                put("data", baseHighWayService);
            }});
        }
        return new R<>(responseList);
    }
    /**
     * 查询桥梁
     * @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);
    }
}
