package com.tofly.scada.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.scada.common.BaseController;
import com.tofly.scada.common.FlowConstant;
import com.tofly.scada.entity.ScadaReport;
import com.tofly.scada.service.ScadaReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author haiqiu
 * 报警类型
 */
@Api(tags = "报警类型")
@RestController
@RequestMapping("/report")
public class ScadaReportController extends BaseController {

    @Autowired
    private ScadaReportService scadaReportService;

    @ToFlyAppLog(title = "报警类型-新增")
    @PostMapping
    @ApiOperation(value = "报警类型-新增")
    public ResultRespone insert(@RequestBody @Validated ScadaReport dto){
        scadaReportService.insert(dto);
        return decide(FlowConstant.ADD_SUCCESS);
    }

    @ToFlyAppLog(title = "报警类型-修改")
    @PutMapping
    @ApiOperation(value = "报警类型-修改")
    public  ResultRespone edit(@RequestBody @Validated(value = ScadaReport.Update.class) ScadaReport dto){
        scadaReportService.edit(dto);
        return decide(FlowConstant.UPDATE_SUCCESS);
    }

    @ToFlyAppLog(title = "报警类型-删除")
    @ApiOperation(value = "报警类型-批量删除")
    @DeleteMapping
    public ResultRespone delete(@ApiParam(value ="多个ID以数组形式进行传入") @RequestBody List<Long> ids){
        scadaReportService.delete(ids);
        return decide(FlowConstant.DELETE_SUCCESS);
    }

    @ToFlyAppLog(title = "报警类型-模糊-分页查询")
    @ApiOperation(value = "报警类型-模糊-分页查询")
    @GetMapping("/list")
    public ResultRespone pageList(Page page, ScadaReport query){
        return decide(scadaReportService.pageList(page,query));
    }

    @ToFlyAppLog(title = "报警类型-模糊-查询所有")
    @ApiOperation(value = "报警类型-模糊-查询所有")
    @PostMapping("/all")
    public ResultRespone all(ScadaReport query){
        return decide(scadaReportService.all(query));
    }


    @ToFlyAppLog(title = "报警类型-根据ID查询")
    @ApiOperation(value = "报警类型-根据ID查询")
    @GetMapping("/get")
    public ResultRespone get(@ApiParam(value = "报警类型-ID") @RequestParam Long id){
        return decide(scadaReportService.get(id));
    }

}
