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

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.dataPool.api.dataRule.service.DataResourcePackageApiService;
import net.northking.cctp.dataPool.db.entity.DataResourcePackage;
import net.northking.cctp.dataPool.dto.dataRule.DataResourcePackageDetailDto;
import net.northking.cctp.dataPool.dto.dataRule.DataResourcePackageQueryDto;
import net.northking.cctp.dataPool.dto.dataRule.DataResourcePackageUpdateDto;
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;

/**
 * 资源包 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "资源包")
@RequestMapping("/v1")
@RestController
public class DataResourcePackageRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(DataResourcePackageRestfulCtrl.class);

  @Autowired
  private DataResourcePackageApiService apiService;

  @ApiOperation("上传资源包")
  @PostMapping("/dataResourcePackage/uploadResource")
  public ResultWrapper<DataResourcePackage> uploadResource(@RequestParam("file") MultipartFile file,
          @RequestParam("proId") String proId,@RequestParam(name = "memo",required = false) String memo) {
    ResultWrapper<DataResourcePackage> wrapper = new ResultWrapper<>();
    DataResourcePackage result = apiService.uploadResource(file,proId,memo);
    return wrapper.success(result);
  }

  @ApiOperation(value = "分页查询列表：公共资源表")
  @PostMapping(value = "/paging/query/dataResourcePackages",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<DataResourcePackageDetailDto>> pagingQuery(
          @RequestBody @Validated QueryByPage<DataResourcePackageQueryDto> queryByPage)
  {
    ResultWrapper<Pagination<DataResourcePackageDetailDto>> wrapper = new ResultWrapper<>();
    Pagination<DataResourcePackageDetailDto> page = apiService.pagingQuery(queryByPage);
    return wrapper.success(page);
  }

  @ApiOperation("修改资源包说明")
  @PostMapping("/dataResourcePackage/updateResource")
  public ResultWrapper<Integer> updateResource(@RequestBody @Validated DataResourcePackageUpdateDto update) throws IllegalAccessException {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer result = apiService.updateByPK(update);
    return wrapper.success(result);
  }

  @ApiOperation("删除资源包")
  @DeleteMapping("/dataResourcePackage/deleteResource")
  public ResultWrapper<Integer> deleteResource(@RequestParam("resourceId") String resourceId){
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer result = apiService.deleteByPK(resourceId);
    return wrapper.success(result);
  }

}
