package com.tofly.gpsboot.controller.es;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.es.CarGpsUpload;
import com.tofly.es.dto.EsCarGpsUploadQueryDto;
import com.tofly.es.dto.EsQueryDto;
import com.tofly.gpsboot.service.es.ICarGpsUploadService;
import io.swagger.annotations.Api;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * ES存储汽车GPS信息
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/carGps")
@Api(tags = "ES存储汽车GPS信息")
public class CarGpsUploadController {
    @Autowired
    private ICarGpsUploadService iCarGpsUploadService;

    @ApiOperation(value = "新增汽车GPS信息")
    @PostMapping
    public ResultRespone<Boolean> save(@RequestBody CarGpsUpload carGpsUpload) {
        return ResultRespone.success(iCarGpsUploadService.carGpsSave(carGpsUpload));
    }

    @ApiOperation(value = "修改汽车GPS信息")
    @PutMapping
    public ResultRespone<Boolean> update(@RequestBody CarGpsUpload carGpsUpload) {
        return ResultRespone.success(iCarGpsUploadService.updateGpsCarInfo(carGpsUpload));
    }


    @ApiOperation(value = "根据ID获取汽车GPS信息")
    @GetMapping("/findone")
    public ResultRespone<CarGpsUpload> get(String id) {
        return ResultRespone.success(iCarGpsUploadService.getByIdGpsCarInfo(id));
    }

    /**
     * 通过id删除GPS信息表
     *
     * @param id id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过id删除汽车GPS信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}")
    public ResultRespone<Boolean> removeById(@PathVariable String id) {
        return ResultRespone.success(iCarGpsUploadService.removeByIdGpsCarInfo(id));
    }


    @ApiOperation(value = "分页获取汽车GPS信息")
    @GetMapping("/page")
    public ResultRespone<Page<List<CarGpsUpload>>> get(Page page, @ModelAttribute EsQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getPageGpsCarInfo(page,dto));
    }

    @ApiOperation(value = "获取所有index的汽车GPS信息")
    @GetMapping("/getAllPage")
    public ResultRespone<Page<List<CarGpsUpload>>> getAllPage(Page page, @ModelAttribute EsQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getAllPage(page,dto));
    }

    @ApiOperation(value = "获取所有index的汽车GPS信息（非分页）")
    @GetMapping("/getAll")
    public ResultRespone<List<CarGpsUpload>> getAllpage(@ModelAttribute EsQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getAll(dto));
    }

    @ApiOperation(value = "获取汽车GPS最新位置信息")
    @GetMapping("/getCarLocation")
    public ResultRespone<Map<String,Object>> getCarLocation(@ModelAttribute EsCarGpsUploadQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getCarLocation(dto));

    }

    @ApiOperation(value = "获取所有的汽车GPS信息（非分页orderby gpstime）")
    @GetMapping("/getList")
    public ResultRespone<List<CarGpsUpload>> getList(@ModelAttribute EsCarGpsUploadQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getGpsCarList(dto));
    }

    @ApiOperation(value = "获取所有的汽车GPS信息（分页orderby gpstime）")
    @GetMapping("/getListPage")
    public ResultRespone<Page<List<CarGpsUpload>>> getListPage(Page page, @ModelAttribute EsCarGpsUploadQueryDto dto) {
        return ResultRespone.success(iCarGpsUploadService.getGpsCarListPage(page,dto));
    }
}
