package org.security.imagePlatformDock.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.security.ht.vo.common.UploadVO;
import org.security.imagePlatformDock.service.IUploadFileService;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @author ：wzf
 * @apiNote ：上传文件致银行影像平台及相关附件预览
 * @since ：Created in 2022/9/6 16:19
 */
@RestController
@AllArgsConstructor
@RequestMapping("/upload")
@Api(value = "上传附件至银行影像平台", tags = "上传附件至银行影像平台接口")
public class UploadFileController {

	private final IUploadFileService uploadFileService;

	/**
	 * 上传单个文件
	 * @param file 文件
	 * @param groupName 文件标识
	 * @param fileType 文件类型
	 * @return
	 */
	@PostMapping("/single")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "上传单个文件")
	public R<UploadVO> uploadSingleFile (@RequestParam MultipartFile file,
										  @RequestParam String groupName,
										  @RequestParam String fileType,
										 @RequestParam(required = false) Boolean encrypt) {
		return uploadFileService.sendImagePlateFormDock(file,groupName,fileType,encrypt);
	}

	/**
	 * 获取影像平台文件链接
	 * @param busiBeginDate 业务开始时间
	 * @param contentId 文件在影像平台存储标识id
	 * @return
	 */
	@GetMapping("/detail")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "获取影像平台文件链接")
	public R<String> getFileData(@RequestParam String busiBeginDate, @RequestParam String contentId,  @RequestParam String fileName) throws IOException {
		return R.data(uploadFileService.getData(busiBeginDate,contentId,fileName));
	}


	/**
	 * 删除影像平台文件
	 * @param busiBeginDate 业务开始时间
	 * @param contentId 文件在影像平台存储标识id
	 * @return
	 */
	@GetMapping("/remove")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "删除影像平台文件")
	public R removeFileData(@RequestParam String busiBeginDate, @RequestParam String contentId) {
		return R.data(uploadFileService.removeFileData(busiBeginDate,contentId));
	}

	/**
	 * 上传多个文件
	 * @param files 文件list
	 * @param groupName 文件标识
	 * @param fileType 文件类型
	 * @return
	 */
	@PostMapping("/list")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "上传多个文件")
	public R<List<UploadVO>> uploadListFile (@RequestParam List<MultipartFile> files,
										 @RequestParam String groupName,
										 @RequestParam String fileType,
											 @RequestParam(required = false) Boolean encrypt) {
		return R.data(uploadFileService.sendImagesPlateFormDock(files,groupName,fileType,encrypt));
	}
}
