package com.mosty.bkzx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.bkzx.TbBkClInsertDto;
import com.mosty.base.model.dto.bkzx.TbBkClJudgeDto;
import com.mosty.base.model.entity.bkzx.TbBkCl;
import com.mosty.base.model.query.bkzx.TbBkClSearchDto;
import com.mosty.bkzx.service.TbBkClService;
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.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dw
 * @since 2022/7/13
 * 布控车辆接口
 **/
@Api(tags = "布控车辆接口")
@RestController
@AllArgsConstructor
@RequestMapping("/tbBkCl")
public class TbBkClController {

    private final TbBkClService tbBkClService;

    @ApiOperation("新增布控车辆")
    @JwtSysUser
    @PostMapping
    @Log(title = "新增布控车辆", businessType = BusinessType.INSERT)
    public ResponseResult<Integer> addEntity(@RequestBody TbBkClInsertDto dto) {
        return ResponseResult.success(this.tbBkClService.addEntity(dto));
    }

    @ApiOperation("分页查询车辆布控列表")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbBkCl>> getPageList(TbBkClSearchDto dto) {
        return ResponseResult.success(this.tbBkClService.getPageList(dto));
    }

    @ApiOperation("查询布控车辆详情")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbBkCl> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbBkClService.getInfo(id));
    }

    @ApiOperation("修改布控车辆")
    @JwtSysUser
    @PutMapping
    @Log(title = "修改布控车辆", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> editCar(@RequestBody TbBkClInsertDto dto) {
        return ResponseResult.success(this.tbBkClService.editCar(dto));
    }

    @ApiOperation("删除和批量删除布控车辆")
    @JwtSysUser
    @DeleteMapping
    @Log(title = "删除和批量删除布控车辆", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> delCar(@RequestBody List<String> ids) {
        return ResponseResult.success(this.tbBkClService.delCar(ids));
    }

    @ApiOperation("结束布控")
    @JwtSysUser
    @PostMapping("endBk/{id}")
    @Log(title = "结束布控", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> endBk(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbBkClService.endBk(id));
    }

    @ApiOperation("重新布控")
    @JwtSysUser
    @PostMapping("startBk/{id}")
    @Log(title = "重新布控", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> startBk(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbBkClService.startBk(id));
    }

    @ApiOperation("布控车辆审批")
    @JwtSysUser
    @PostMapping("judge")
    @Log(title = "布控车辆审批", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> judge(@RequestBody TbBkClJudgeDto dto) {
        return ResponseResult.success(this.tbBkClService.judge(dto));
    }
}
