/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
*
*/
package net.northking.cctp.device.api.ctrl;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.device.api.ctrl.service.CdDeviceCtrlApiService;
import net.northking.cctp.device.dto.ctrl.CdDeviceCtrlDetailDto;
import net.northking.cctp.device.dto.ctrl.CdDeviceCtrlQueryDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(tags = "上位机管理表")
@RequestMapping("/v1")
@RestController
public class CdDeviceCtrlQueryCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(CdDeviceCtrlQueryCtrl.class);

  @Autowired
  private CdDeviceCtrlApiService apiService;

  /**
   * 查询用户列表
   *
   * @param queryByPage  查询条件
   * @return 数据列表
   */
  @ApiOperation(value = "分页查询列表")
  @RequiredPermissions({"mobileDeviceCtrl","sassDeviceCtrl"})
  @PostMapping(value = "/paging/query/ctrls",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<CdDeviceCtrlDetailDto>> pagingQuery(
      @RequestBody QueryByPage<CdDeviceCtrlQueryDto> queryByPage)
  {
    ResultWrapper<Pagination<CdDeviceCtrlDetailDto>> wrapper = new ResultWrapper<>();
    Pagination<CdDeviceCtrlDetailDto> page = apiService.pagingQuery(queryByPage);

    return wrapper.success(page);
  }



  @ApiOperation(value = "重启上位机")
  @RequiredPermissions({"ui-restartCtrls","ui-restartCtrls2"})
  @GetMapping(
          value = "/ctrls/restart/{id}",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<String> restartCtrl(@PathVariable("id")String id){
    ResultWrapper<String> wrapper = new ResultWrapper<>();
    String result = this.apiService.restartCtrl(id);
    return wrapper.success(result);
  }




}


