package com.artfess.rescue.common.controller;

import com.artfess.base.annotation.ApiGroup;
import com.artfess.base.constants.ApiGroupConsts;
import com.artfess.base.model.CommonResult;
import com.artfess.rescue.common.util.PointUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/common/v1/")
@Api(tags = "通用管理")
@ApiGroup(group = {ApiGroupConsts.GROUP_BIZ_RESCUE})
public class RescueCommonController {
    @Resource
    PointUtil pointUtil;

    @RequestMapping(value = "route/pointMapping", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "经纬度转桩号", httpMethod = "GET", notes = "经纬度转桩号")
    public CommonResult<String> point(@RequestParam("lat") double lat,
                                      @RequestParam("lon")double lon,
                                      @RequestParam("pointType")String pointType,
                                      @RequestParam("routeCode")String routeCode,
                                      @RequestParam(value = "upDown",required = false)String upDown){

        return new CommonResult(true,"", pointUtil.pointMapping(lat, lon, pointType, routeCode, upDown));
    }

    @RequestMapping(value = "route/mappingPoint", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "桩号转经纬度", httpMethod = "GET", notes = "桩号转经纬度")
    public CommonResult<String> mappingPoint(@ApiParam(name = "pointType", value = "点位坐标类型，例如：02或者84", required = true)
                                                 @RequestParam("pointType") String pointType,
                                             @ApiParam(name = "routeCode", value = "路线编码，例如：G35", required = true)
                                             @RequestParam("routeCode")String routeCode,
                                             @ApiParam(name = "stakeNum", value = "百米桩，例如402.607", required = true)
                                                 @RequestParam("stakeNum")double stakeNum,
                                             @ApiParam(name = "upDown", value = "方向，上行1，下行2", required = false)
                                                 @RequestParam(value = "upDown")String upDown){

        return new CommonResult(true,"", pointUtil.mappingPoint(pointType, routeCode,stakeNum,upDown));
    }

    @RequestMapping(value = "route/lineSpace", method = RequestMethod.GET, produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "两点间获取距离", httpMethod = "GET", notes = "两点间获取距离")
    public CommonResult<String> distancePoint(@RequestParam("qdLat") double qdLat,
                                              @RequestParam("qdLon")double qdLon,
                                              @RequestParam("zdLat") double zdLat,
                                              @RequestParam("zdLon")double zdLon){
        return new CommonResult(true,"", pointUtil.distancePoint(qdLat, qdLon, zdLat, zdLon));
    }
}
