package com.mosty.yjzl.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.common.base.domain.ResponseResult;
import com.mosty.common.base.entity.log.BusinessType;
import com.mosty.common.base.entity.log.Log;
import com.mosty.common.token.JwtSysUser;
import com.mosty.base.model.query.yjzl.TbYjxxSjQuery;
import com.mosty.base.model.vo.yjzl.TbYjxxSjVo;
import com.mosty.yjzl.service.TbYjxxSjService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  预警信息-事件表 前端控制器
 * </p>
 *
 * @author zengbo
 * @since 2022-07-19
 */
@Api(tags = "预警信息事件表接口")
@AllArgsConstructor
@RestController
@RequestMapping("/tbYjxxSj")
public class TbYjxxSjController {

    private TbYjxxSjService tbYjxxSjService;


    @ApiOperation("通过ID查询单条数据")
    @JwtSysUser
    @GetMapping("{id}")
    @Log(title = "预警事件数据", businessType = BusinessType.OTHER)
    @ApiImplicitParam(name = "id", value = "配置ID", paramType = "path", required = true, dataType="String")
    public ResponseResult<TbYjxxSjVo> queryById(@PathVariable String id){
        return ResponseResult.success(tbYjxxSjService.queryById(id));
    }


    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbYjxxSjVo>> paginQuery(TbYjxxSjQuery tbYjxxSjQuery){
        try {
            return ResponseResult.success(tbYjxxSjService.queryByPage(tbYjxxSjQuery));
        }catch (Exception e){
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "预警事件新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbYjxxSjVo yjsj){
        return ResponseResult.success(tbYjxxSjService.insert(yjsj));
    }

    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "预警事件更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbYjxxSjVo yjsj){
        return ResponseResult.success(tbYjxxSjService.update(yjsj));
    }

    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/bacth")
    @Log(title = "预警事件删除", businessType = BusinessType.UPDATE)
    @ApiImplicitParam(name = "list", value = "标签主键", paramType = "path", required = true, dataType="String")
    public ResponseResult<Integer> deleteByIds(@RequestParam List<String> list){
        return ResponseResult.success(tbYjxxSjService.deleteById(list));
    }

}

