package com.yx.face.controller.admin;

import com.github.pagehelper.PageInfo;
import com.yx.face.boot.core.BaseController;
import com.yx.face.boot.restful.RestDTO;
import com.yx.face.boot.restful.RestResponse;
import com.yx.face.boot.restful.RestResult;
import com.yx.face.model.query.FaceDeviceQu;
import com.yx.face.model.query.SysLongTermDocumentsQu;
import com.yx.face.model.vo.SystemLongTermDocumentsVO;
import com.yx.face.service.SystemLongTermDocumentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @ClassName UserWhitelistController
 * @Author WXG
 * @Date 2021/11/5 14:12
 */
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "B 简道云长期通信证员工 API")
@RestController
@RequestMapping("admin/jdy")
public class SystemLongTermDocumentsController extends BaseController {

    private final SystemLongTermDocumentsService systemLongTermDocumentsService;

    @ApiOperation("查询人员")
    @PostMapping("/getList")
    public RestResult<PageInfo<SystemLongTermDocumentsVO>> getList(@RequestBody RestDTO<SysLongTermDocumentsQu> dto) {
        PageInfo<SystemLongTermDocumentsVO> list = systemLongTermDocumentsService.getList(dto);
        return RestResponse.ok(list);
    }

    @ApiOperation("添加设备")
    @PostMapping("/add")
    public RestResult<Boolean> add(@RequestBody FaceDeviceQu qu) {
        Integer insert = systemLongTermDocumentsService.add(qu);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("添加失败");
    }

    @ApiOperation("删除设备")
    @GetMapping("delete")
    public RestResult<Boolean> delete(String sn) {
        Integer insert = systemLongTermDocumentsService.delete(sn);
        if (insert == 1) return RestResponse.ok(true);
        else return RestResponse.error("删除失败");
    }
    @ApiOperation("人员单个下发")
    @GetMapping("/singleIssue")
    public RestResult<String> singleIssue(Integer id) {
        if (id == null){
            return RestResponse.error("缺少参数");
        }
        RestResult<String> restResult  = systemLongTermDocumentsService.singleIssue(id);
        return restResult;
    }
}
