package com.mosty.base.manager.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.manager.service.TbJcglXfclSbService;
import com.mosty.base.model.entity.jcgl.TbJcglXfclSb;
import com.mosty.base.model.query.jcgl.TbJcglXfclSbQuery;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "巡防车辆设备接口")
@RestController
@AllArgsConstructor
@RequestMapping("/xfclSb")
public class TbJcglXfclSbController {

    private final TbJcglXfclSbService tbJcglXfclSbService;

    @ApiOperation("添加巡防车辆设备")
    @JwtSysUser
    @PostMapping
    @Log(title = "添加巡防车辆设备", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> addEntity(@RequestBody TbJcglXfclSb dto) {
        return ResponseResult.success(this.tbJcglXfclSbService.addEntity(dto));
    }

    @ApiOperation("修改巡防车辆设备")
    @JwtSysUser
    @PutMapping
    @Log(title = "修改巡防车辆设备", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> editEntity(@RequestBody TbJcglXfclSb dto) {
        return ResponseResult.success(this.tbJcglXfclSbService.editEntity(dto));
    }

    @ApiOperation("批量删除巡防车辆设备")
    @JwtSysUser
    @DeleteMapping
    @Log(title = "批量删除巡防车辆设备", businessType = BusinessType.DELETE)
    public ResponseResult<Integer> deleteEntity(@RequestBody List<String> ids) {
        if(CollectionUtils.isEmpty(ids)){ return ResponseResult.fail("参数不能为空！");}
        return ResponseResult.success(this.tbJcglXfclSbService.delEntity(ids));
    }

    @ApiOperation("分页查询车辆设备列表")
    @JwtSysUser
    @PostMapping("getPageList")
    public ResponseResult<IPage<TbJcglXfclSb>> getPageList(@RequestBody TbJcglXfclSbQuery dto) {
        return ResponseResult.success(this.tbJcglXfclSbService.getXfclSbPage(dto));
    }

    @ApiOperation("查询车辆设备列表")
    @JwtSysUser
    @PostMapping("getXfclSbList")
    public ResponseResult<List<TbJcglXfclSb>> getXfclSbList(@RequestBody TbJcglXfclSbQuery dto) {
        return ResponseResult.success(this.tbJcglXfclSbService.getXfclSbList(dto));
    }

    @ApiOperation("查询巡防车辆设备详情")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbJcglXfclSb> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbJcglXfclSbService.getInfo(id));
    }
}
