package com.tofly.gpsboot.custom.controller;

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.gpsboot.custom.service.CustomCarBaseinfoService;
import com.tofly.gpsboot.service.car.CarBaseinfoService;
import com.tofly.pojo.car.dto.CarBaseinfoSaveDTO;
import com.tofly.pojo.car.vo.CarMochaitomVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/carbaseinfo")
@Api(tags="车辆基本信息管理接口-自定义")
public class CustomCarBaseinfoController {

    private final CarBaseinfoService carBaseinfoService;

    private final CustomCarBaseinfoService customCarBaseinfoService;

    @ToFlyAppLog(title = "车辆基本信息管理保存")
    @ApiOperation(tags = "车辆基本信息管理保存", value = "车辆基本信息管理保存")
    @PostMapping("/save")
    public ResultRespone save(@RequestBody @Validated CarBaseinfoSaveDTO dto) {
        return ResultRespone.success(carBaseinfoService.customSave(dto));
    }

    @ApiOperation(tags = "车辆基本信息管理接口", value = "根据车牌号模糊分页查询")
    @GetMapping("/numberpage")
    public ResultRespone pageByCarNumber(Page page, String number) {
        return ResultRespone.success(customCarBaseinfoService.pageByCarNumber(page, number));
    }

    @ApiOperation(tags = "获取车辆详情ID", value = "车辆详情")
    @GetMapping("/carDetail")
    public ResultRespone carDetail(Long id) {
        return ResultRespone.success(customCarBaseinfoService.GetDetailById(id));
    }

    /**
     * 通过id批量删除车辆基本信息管理
     *
     * @param ids id
     * @return ResultRespone
     */
    @ToFlyAppLog(title = "通过id批量删除车辆基本信息管理")
    @ApiOperation(tags = "车辆基本信息管理接口", value = "通过ID批量删除车辆基本信息管理")
    @ApiImplicitParams({@ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")})
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(customCarBaseinfoService.removeById(ids));
    }

    @ToFlyAppLog(title = "查询车辆使用情况")
    @ApiOperation(tags = "查询车辆使用情况", value = "查询车辆使用情况")
    @GetMapping("/getCarUseInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "statisticsType", value = "统计类型（0小时统计;1天统计;2月统计;3年统计）", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "startDate", value = "开始时间（yyyy-MM-dd HH:mm:ss）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endDate", value = "结束时间（yyyy-MM-dd HH:mm:ss）", required = true, dataType = "String"),
    })
    public ResultRespone<List<CarMochaitomVo>> getCarUseInfo(Integer statisticsType, String startDate, String endDate) {
        return ResultRespone.success(customCarBaseinfoService.getCarUseInfo(statisticsType, startDate, endDate));
    }

}
