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.TbYjxxClQuery;
import com.mosty.base.model.vo.yjzl.TbYjxxClVo;
import com.mosty.yjzl.service.TbYjxxClService;
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("/tbYjxxCl")
public class TbYjxxClController {

    private TbYjxxClService tbYjxxClService;

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

    @ApiOperation("分页查询")
    @JwtSysUser
    @GetMapping("/paginQuery")
    public ResponseResult<IPage<TbYjxxClVo>> paginQuery(TbYjxxClQuery tbYjxxClQuery){
        try {
            return ResponseResult.success(tbYjxxClService.queryByPage(tbYjxxClQuery));
        }catch (Exception e){
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @ApiOperation("不分页查询")
    @JwtSysUser
    @GetMapping("/queryListNoPager")
    public ResponseResult<List<TbYjxxClVo>> queryListNoPager(TbYjxxClQuery tbYjxxClQuery){
        try {
            return ResponseResult.success(tbYjxxClService.queryList(tbYjxxClQuery));
        }catch (Exception e){
            return ResponseResult.fail(500, e.getMessage());
        }
    }

    @ApiOperation("新增数据")
    @JwtSysUser
    @PostMapping
    @Log(title = "预警车辆信息新增", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> add(@RequestBody TbYjxxClVo ryVo){
        return ResponseResult.success(tbYjxxClService.insert(ryVo));
    }

    @ApiOperation("更新数据")
    @JwtSysUser
    @PutMapping
    @Log(title = "预警信息人员更新", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> edit(@RequestBody TbYjxxClVo clVo){
        return ResponseResult.success(tbYjxxClService.update(clVo));
    }

    @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(tbYjxxClService.deleteById(list));
    }

}

