package com.mosty.bkzx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mosty.base.model.dto.bkzx.TbBkRyInsertDto;
import com.mosty.base.model.dto.bkzx.TbBkRyJudgeDto;
import com.mosty.base.model.entity.bkzx.TbBkRy;
import com.mosty.base.model.query.bkzx.TbBkRySearchDto;
import com.mosty.bkzx.service.TbBkRyService;
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("/tbBkRy")
public class TbBkRyController {

    private final TbBkRyService tbBkRyService;

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

    @ApiOperation("分页查询人员布控列表")
    @JwtSysUser
    @GetMapping
    public ResponseResult<IPage<TbBkRy>> getPageList(TbBkRySearchDto dto) {
        return ResponseResult.success(this.tbBkRyService.getPageList(dto));
    }

    @ApiOperation("查询布控人员详情")
    @JwtSysUser
    @GetMapping("{id}")
    public ResponseResult<TbBkRy> getInfo(@PathVariable("id") String id) {
        return ResponseResult.success(this.tbBkRyService.getInfo(id));
    }

    @ApiOperation("修改布控人员")
    @JwtSysUser
    @PutMapping
    @Log(title = "修改布控人员", businessType = BusinessType.UPDATE)
    public ResponseResult<Integer> editPerson(@RequestBody TbBkRyInsertDto dto) {
        return ResponseResult.success(this.tbBkRyService.editPerson(dto));
    }

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

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

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

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