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

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.base.entity.Car;
import com.tofly.base.service.CarService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
/**
 * 车辆管理测试
 *
 * @author wangjian
 * @date Mon Jul 06 00:00:00 CST 2020
 */
@RestController
@AllArgsConstructor
@RequestMapping("/car")
@Api(tags="车辆管理测试接口")
public class CarController {

    private final  CarService carService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param car 车辆管理测试
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    public ResultRespone getCarPage(Page page, @ModelAttribute Car car) {
      return ResultRespone.success(carService.page(page, Wrappers.query(car)));
    }


    /**
     * 通过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(carService.getById(id));
    }

    /**
     * 新增车辆管理测试
     * @param car 车辆管理测试
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增车辆管理测试" )
    @ApiOperation(value = "新增车辆管理测试")
    @PostMapping
    public ResultRespone save(@RequestBody Car car) {
      return ResultRespone.success(carService.save(car));
    }

    /**
     * 修改车辆管理测试
     * @param car 车辆管理测试
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改车辆管理测试" )
    @ApiOperation(value = "修改车辆管理测试")
    @PutMapping
    public ResultRespone updateById(@RequestBody Car car) {
      return ResultRespone.success(carService.updateById(car));
    }

    /**
     * 通过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(carService.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(carService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
