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

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.gpsboot.service.maintain.DetonatorService;
import com.tofly.pojo.maintain.Detonator;
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 admin
 * @date Mon Sep 19 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/detonator")
@Api(tags = "爆管原因配置表接口")
public class DetonatorController {

    private final DetonatorService detonatorService;

    /**
     * 分页查询
     *
     * @param page      分页对象
     * @param detonator 爆管原因配置表
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultRespone getDetonatorPage(Page page, @ModelAttribute Detonator detonator) {
        return ResultRespone.success(detonatorService.page(page, Wrappers.query(detonator)));
    }


    /**
     * 通过id查询爆管原因配置表
     *
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
    })
    public ResultRespone getById(@PathVariable("id") Long id) {
        return ResultRespone.success(detonatorService.getById(id));
    }

    /**
     * 新增爆管原因配置表
     *
     * @param detonator 爆管原因配置表
     * @return ResultRespone
     */
    @ApiOperation(value = "新增爆管原因配置表")
    @PostMapping
    public ResultRespone save(@RequestBody Detonator detonator) {
        return ResultRespone.success(detonatorService.save(detonator));
    }

    /**
     * 修改爆管原因配置表
     *
     * @param detonator 爆管原因配置表
     * @return ResultRespone
     */
    @ApiOperation(value = "修改爆管原因配置表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Detonator detonator) {
        return ResultRespone.success(detonatorService.updateById(detonator));
    }

    /**
     * 通过id批量删除爆管原因配置表
     *
     * @param ids id
     * @return ResultRespone
     */
    @ApiOperation(value = "通过ID批量删除爆管原因配置表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
    })
    @DeleteMapping("/deleteByIds")
    public ResultRespone removeById(String ids) {
        return ResultRespone.success(detonatorService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
