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

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.paln.HydrantrecordService;
import com.tofly.pojo.build.dto.BuildDto;
import com.tofly.pojo.plan.Hydrantrecord;
import lombok.AllArgsConstructor;
import org.springframework.validation.BindingResult;
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 org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 消防栓记录上报表
 *
 * @author admin
 * @date Fri Sep 10 00:00:00 CST 2021
 */
@RestController
@AllArgsConstructor
@RequestMapping("/hydrantrecord")
@Api(tags="消防栓记录上报表接口")
public class HydrantrecordController {

    private final HydrantrecordService hydrantrecordService;

    /**
    * 分页查询
    * @param page 分页对象
    * @param hydrantrecord 消防栓记录上报表
    * @return
    */
    @GetMapping("/page" )
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询消防栓记录上报")
    public ResultRespone getHydrantrecordPage(Page page, @ModelAttribute Hydrantrecord hydrantrecord) {
      return ResultRespone.success(hydrantrecordService.page(page, Wrappers.query(hydrantrecord)));
    }


    /**
     * 通过id查询消防栓记录上报表
     * @param id id
     * @return ResultRespone
     */
    @GetMapping("/{id}" )
    @ApiOperation(value = "通过ID查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long")
    })
    @ToFlyAppLog(title = "通过ID查询消防栓记录上报")
    public ResultRespone getById(@PathVariable("id" ) Long id) {
      return ResultRespone.success(hydrantrecordService.getById(id));
    }

    /**
     * 新增消防栓记录上报表
     * @param hydrantrecord 消防栓记录上报表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="新增消防栓记录上报表" )
    @ApiOperation(value = "新增消防栓记录上报表")
    @PostMapping
    public ResultRespone save(@RequestParam(value = "fileList", required = false) List<MultipartFile> fileList,Hydrantrecord hydrantrecord) {
      return ResultRespone.success(hydrantrecordService.savaHydrantRecordInfo(fileList,hydrantrecord));
    }

    /**
     * 修改消防栓记录上报表
     * @param hydrantrecord 消防栓记录上报表
     * @return ResultRespone
     */
    @ToFlyAppLog(title="修改消防栓记录上报表" )
    @ApiOperation(value = "修改消防栓记录上报表")
    @PutMapping
    public ResultRespone updateById(@RequestBody Hydrantrecord hydrantrecord) {
      return ResultRespone.success(hydrantrecordService.updateById(hydrantrecord));
    }


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