package com.xinelu.manage.controller.signpatientinformed;

import com.xinelu.common.constant.Constants;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.manage.service.signpatientinformed.IFileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Objects;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description: 文件上传控制器
 * @author: haown
 * @create: 2024-03-01 10:30
 **/
@Api(tags = "文件上传控制器")
@RestController
@RequestMapping("/manage/file")
public class FileUploadController {

	@Resource
	private IFileUploadService fileUploadService;
	/**
	 * 文件上传
	 */
	@ApiOperation(value = "文件上传", notes = "type:signInformedFileUrl:签约知情书上传,propagandaCoverUrl:宣教库封面上传,"
		+ "materialsCoverUrl:素材库封面上传,materialsVideoUrl:素材库视频上传，commonVideoUrl：富文本框视频上传")
	@PostMapping("/uploadFile")
	public AjaxResult uploadFile(@RequestParam("file") MultipartFile multipartFile, @RequestParam(value = "type") String type) throws Exception {
		if (Objects.isNull(multipartFile) || StringUtils.isBlank(multipartFile.getOriginalFilename())) {
			return AjaxResult.error("当前文件不存在，无法上传！");
		}
		if (multipartFile.getOriginalFilename().contains(Constants.EMPTY)) {
			return AjaxResult.error("当前文件名含有空格，请先去除空格在上传！");
		}
		if (StringUtils.isBlank(type)) {
			return AjaxResult.error("请选择所要上传的路径类型！");
		}
		return fileUploadService.uploadFile(multipartFile, type);
	}

}
