/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.dispatch.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.dispatch.common.BaseController;
import com.tofly.dispatch.common.FlowConstant;
import com.tofly.dispatch.dto.HazardDTO;
import com.tofly.dispatch.dto.HazardQuery;
import com.tofly.dispatch.service.HazardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Set;

/**
 * 危险源
 *
 * @author qf
 * @date Thu Apr 21 00:00:00 CST 2022
 */
@RestController
@AllArgsConstructor
@RequestMapping("/hazard")
@Api(tags = "危险源基础数据接口")
public class HazardController extends BaseController {

    private final HazardService hazardService;

    @ToFlyAppLog(title = "危险源新增")
    @PostMapping
    @ApiOperation(value = "危险源新增")
    public ResultRespone insert(@Validated HazardDTO hazardDto, @RequestPart List<MultipartFile> fileList) {
        hazardService.insert(hazardDto, fileList);
        return decide(FlowConstant.ADD_SUCCESS);
    }

    @ToFlyAppLog(title = "危险源修改")
    @PutMapping
    @ApiOperation(value = "危险源修改")
    public ResultRespone edit(@Validated(value = HazardDTO.update.class) HazardDTO hazardDto,
                              @RequestPart List<MultipartFile> fileList) {
        hazardService.edit(hazardDto,fileList);
        return decide(FlowConstant.UPDATE_SUCCESS);
    }

    @ToFlyAppLog(title = "危险源删除")
    @ApiOperation(value = "危险源批量删除")
    @DeleteMapping
    public ResultRespone delete(@ApiParam(value = "多个ID以数组形式进行传入") @RequestBody Set<Long> ids) {
        hazardService.delete(ids);
        return decide(FlowConstant.DELETE_SUCCESS);
    }

    @ToFlyAppLog(title = "危险源模糊-分页查询")
    @ApiOperation(value = "危险源模糊-分页查询")
    @GetMapping("/list")
    public ResultRespone pageList(Page page, HazardQuery query) {
        return decide(hazardService.pageList(page, query));
    }

    @ToFlyAppLog(title = "危险源模糊-查询所有")
    @ApiOperation(value = "危险源模糊-查询所有")
    @PostMapping("/all")
    public ResultRespone all(HazardQuery query) {
        return decide(hazardService.all(query));
    }

    @ToFlyAppLog(title = "危险源根据ID查询")
    @ApiOperation(value = "危险源根据ID查询")
    @GetMapping("/get")
    public ResultRespone all(@ApiParam(value = "危险源ID") @RequestParam Long id) {
        return decide(hazardService.getById(id));
    }
}
