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

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.common.security.authentication.NKSecurityContext;
import net.northking.cctp.device.api.model.service.CdDeviceModelApiService;
import net.northking.cctp.device.dto.model.CdDeviceModelDetailDto;
import net.northking.cctp.device.dto.model.CdDeviceModelQueryDto;
import net.northking.cctp.device.dto.model.DeviceSelectDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "设备型号管理表")
@RequestMapping("/v1")
@RestController
public class CdDeviceModelQueryCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(CdDeviceModelQueryCtrl.class);

  @Autowired
  private CdDeviceModelApiService apiService;

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

    return wrapper.success(page);
  }

  @ApiOperation(value = "查询设备搜索条件")
  @PostMapping("/device/getDevicecondition")
  public ResultWrapper<DeviceSelectDto> getDeviceCondition2(@RequestParam(name = "platform",required = false) String platform){
    Map<String, Object> queryMap = new HashMap<>();
    queryMap.put("tenantId", NKSecurityContext.getTenantId());
    if (StringUtils.hasText(platform)) {
      queryMap.put("platform", platform);
    }
    DeviceSelectDto data = apiService.getDeviceCondition(queryMap);
    return new ResultWrapper<DeviceSelectDto>().success(data);
  }
}


