package com.tofly.gpsboot.controller.es;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.es.PdaDeviceUpload;
import com.tofly.es.dto.EsQueryDto;
import com.tofly.gpsboot.service.es.IPdaDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author tuonbed
 * @date 2020/5/6  15:38
 */
@RestController
@RequestMapping("/pda")
@Api(tags="ES存储移动设备信息")
@Slf4j
public class PdaDeviceUploadController {

    @Autowired
    private IPdaDeviceService iPdaDeviceService;

    @ApiOperation(value = "新增移动设备信息")
    @PostMapping
    public ResultRespone<Boolean> save(@RequestBody PdaDeviceUpload pdaDeviceUpload) {
       return ResultRespone.success(iPdaDeviceService.savePdaDeviceInfo(pdaDeviceUpload));
    }


    @ToFlyAppLog(title="修改移动设备信息" )
    @ApiOperation(value = "修改移动设备信息")
    @PutMapping
    public ResultRespone<Boolean> update(@RequestBody PdaDeviceUpload pdaDeviceUpload) {
        return ResultRespone.success(iPdaDeviceService.updatePdaDeviceInfo(pdaDeviceUpload));
    }


    @ApiOperation(value = "根据ID获取移动设备信息")
    @GetMapping("/findone")
    public ResultRespone<PdaDeviceUpload> get(String id){
        return ResultRespone.success(iPdaDeviceService.getByIdPdaDeviceInfo(id));
    }


    /**
     * 通过id删除GPS信息表
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除移动设备信息" )
    @ApiOperation(value = "通过id删除移动设备信息表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone<Boolean> removeById(@PathVariable String id) {
        return ResultRespone.success(iPdaDeviceService.removeByIdPdaDeviceInfo(id));
    }


    @ApiOperation(value = "分页获取移动设备信息")
    @GetMapping("/page")
    public ResultRespone<Page<List<PdaDeviceUpload>>> get(Page page, @ModelAttribute EsQueryDto dto){
        Page<List<PdaDeviceUpload>> pageGpsInfo = iPdaDeviceService.getPageGpsInfo(page, dto);
        return ResultRespone.success(pageGpsInfo);
    }

    @ApiOperation(value = "获取所有index的移动设备信息")
    @GetMapping("/getAllPage")
    public ResultRespone<Page<List<PdaDeviceUpload>>> getAllPage(Page page, @ModelAttribute EsQueryDto dto){
        return ResultRespone.success(iPdaDeviceService.getAllPage(page,dto));
    }


    @ApiOperation(value = "获取所有index的移动设备信息（非分页）")
    @GetMapping("/getAll")
    public ResultRespone<List<PdaDeviceUpload>> getAllpage(@ModelAttribute EsQueryDto dto){
        return ResultRespone.success(iPdaDeviceService.getAll(dto));
    }



}
