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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;

import net.northking.cctp.device.api.pcDevice.service.CdPcDeviceApiService;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceAddDto;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceDetailDto;
import net.northking.cctp.device.dto.pcDevice.CdPcDeviceUpdateDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * PC设备管理 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "PC设备管理")
@RequestMapping("/v1/device/pc")
@RestController
public class CdPcDeviceRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(CdPcDeviceRestfulCtrl.class);

  @Autowired
  private CdPcDeviceApiService apiService;

  /**
   * Restful接口-post： 新增PC设备管理
   *
   * @param inputDto         接口数据传输对象
   * @return 数据库主键
   */
  @ApiOperation(value = "新增：PC设备管理")
  @RequiredPermissions({"ui-sassPCAdd"})
  @PostMapping(
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Map<String,String>> add(
      @RequestBody @Validated CdPcDeviceAddDto inputDto, HttpServletRequest request)
  {
    ResultWrapper<Map<String,String>> wrapper = new ResultWrapper<>();
    Map<String,String> map = apiService.add(inputDto,request);
    return wrapper.success(map);
  }

  /**
   * Restful接口-put： 更新PC设备管理
   *
   * @param inputDto         接口数据传输对象
   * @return 修改的记录数量
   */
  @ApiOperation(value = "更新：PC设备管理")
  @RequiredPermissions({"ui-updatePCDevice","ui-PCedit"})
  @PutMapping(
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> update(
      @RequestBody @Validated CdPcDeviceUpdateDto inputDto) throws IllegalAccessException
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.updateByPK(inputDto);
    return wrapper.success(count);
  }

  /**
   * Restful接口-get： 获取PC设备管理
   *
   * @param uuid       数据库主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "获取：PC设备管理")
  @GetMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<CdPcDeviceDetailDto> findByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<CdPcDeviceDetailDto> wrapper = new ResultWrapper<>();
    CdPcDeviceDetailDto user = apiService.findByPK(uuid);
    return wrapper.success(user);
  }

  /**
   * Restful接口-delete： 删除PC设备管理
   *
   * @param uuid       数据库主键
   * @return 删除的记录数量
   */
  @ApiOperation(value = "删除：PC设备管理")
  @DeleteMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.deleteByPK(uuid);
    return wrapper.success(count);
  }
}
