/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.gpsboot.controller.car;

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.service.car.CarOilService;
import com.tofly.gpsboot.service.car.MeiCunCarOilService;
import com.tofly.pojo.car.CarOil;
import com.tofly.pojo.car.dto.CarOilSaveDTO;
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.Arrays;

/**
 * 车辆油耗信息管理
 *
 * @author Zhangyu
 * @date Thu Apr 23 00:00:00 GMT+08:00 2020
 */
@RestController
@AllArgsConstructor
@RequestMapping("/caroil")
@Api(tags = "车辆油耗信息管理接口")
public class CarOilController {

    private final MeiCunCarOilService meiCunCarOilService;

    @ApiOperation(value = "车辆油耗保存")
    @PostMapping("/save")
    public ResultRespone save(@RequestBody @Validated CarOilSaveDTO dto) {
        return ResultRespone.success(meiCunCarOilService.customSave(dto));
    }

    /**
     * 分页查询
     *
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getCarOilPage(Page page) {
        return ResultRespone.success(meiCunCarOilService.cutomPage(page));
    }


    /**
     * 通过id查询车辆油耗信息管理
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(meiCunCarOilService.getDetailById(id));
    }

    /**
     * 通过id删除车辆油耗信息管理
     * @param id id
     * @return ResultRespone
     */
    @ToFlyAppLog(title="通过id删除车辆油耗信息管理" )
    @ApiOperation(value = "通过ID删除车辆油耗信息管理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @DeleteMapping("/{id}" )
    public ResultRespone removeById(@PathVariable Long id) {
      return ResultRespone.success(meiCunCarOilService.removeById(id));
    }

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