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

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.testbug.api.service.OverallViewIndex2ApiService;
import net.northking.cctp.testbug.db.entity.OverallViewIndex2;
import net.northking.cctp.testbug.dto.OverallViewIndex2DetailDto;
import net.northking.cctp.testbug.dto.OverallViewIndex2QueryDto;
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 org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "跨项目级视图索引信息表2")
@RequestMapping("/v1")
@RestController
public class OverallViewIndex2QueryCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(OverallViewIndex2QueryCtrl.class);

  @Autowired
  private OverallViewIndex2ApiService apiService;

  /**
   * 分页查询 跨项目级视图索引信息表2 列表
   *
   * @param queryByPage  查询条件
   * @return 数据列表
   */
  @ApiOperation(value = "分页查询列表：跨项目级视图索引信息表2")
  @PostMapping(value = "/paging/query/OverallViewIndex2s",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<OverallViewIndex2DetailDto>> pagingQuery(
      @RequestBody @Validated QueryByPage<OverallViewIndex2QueryDto> queryByPage)
  {
    ResultWrapper<Pagination<OverallViewIndex2DetailDto>> wrapper = new ResultWrapper<>();
    Pagination<OverallViewIndex2DetailDto> page = apiService.pagingQuery(queryByPage);

    return wrapper.success(page);
  }

  @ApiOperation(value = "导出Excel：跨项目级视图索引信息表2")
  @PostMapping(value = "/excel/export/OverallViewIndex2s",
      produces = MediaType.APPLICATION_OCTET_STREAM_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public void exportExcel(
      @RequestBody @Validated QueryByPage<OverallViewIndex2QueryDto> queryByPage,
      HttpServletResponse response)
  {
    // 定义导出的Excel在客户端浏览器上提示下载的文件名，不写后缀
    String fileName = "CCTP-跨项目级视图索引信息表2";
    apiService.exportExcel(response, queryByPage, fileName);
  }

  @ApiOperation(value = "下载Excel模板：跨项目级视图索引信息表2")
  @PostMapping(value = "/excel/template/OverallViewIndex2s",
      produces = MediaType.APPLICATION_OCTET_STREAM_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public void downloadTemplate(HttpServletResponse response)
  {
    String fileName = "CCTP模板-跨项目级视图索引信息表2";
    apiService.downloadTemplate(response, fileName);
  }

  @ApiOperation(value = "导入Excel：跨项目级视图索引信息表2")
  @PostMapping(value = "/excel/import/OverallViewIndex2s",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
  public ResultWrapper<Integer> importExcel(
      @RequestParam("file") MultipartFile file)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int count = apiService.importExcel(file);

    return wrapper.success(count);
  }

  /**
   * 查询 跨项目级视图索引信息表
   *
   * @param
   * @return 数据列表
   */
  @ApiOperation(value = "用户id：跨项目级视图索引信息表")
  @PostMapping(value = "/query/OverallViewIndex2",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<OverallViewIndex2>> oneQuery(
          @RequestBody OverallViewIndex2QueryDto queryDto)
  {
    ResultWrapper<List<OverallViewIndex2>> wrapper = new ResultWrapper<>();
    List<OverallViewIndex2> overallViewIndex2 = apiService.oneQuery(NKSecurityContext.getUserId(),queryDto);

    return wrapper.success(overallViewIndex2);
  }
}


