fix:参数类型查询权限

dev
wangxy 12 months ago
parent b380d7860e
commit 7ba1e8dea5

@ -218,6 +218,16 @@ public class FileRelationManager {
} }
/**
*
*
* @return java.util.List<com.hyp.system.domain.RewFileRelation>
*/
public RewFileRelation getRewFileRelation(String fileId){
return fileRelationService.getById(fileId);
}
} }

@ -5,19 +5,23 @@ import com.hyp.common.config.HypConfig;
import com.hyp.common.core.controller.BaseController; import com.hyp.common.core.controller.BaseController;
import com.hyp.common.core.domain.AjaxResult; import com.hyp.common.core.domain.AjaxResult;
import com.hyp.common.enums.BusinessType; import com.hyp.common.enums.BusinessType;
import com.hyp.common.exception.ServiceException;
import com.hyp.common.utils.file.FileUploadUtils; import com.hyp.common.utils.file.FileUploadUtils;
import com.hyp.common.utils.file.FileUtils; import com.hyp.common.utils.file.FileUtils;
import com.hyp.framework.config.ServerConfig; import com.hyp.framework.config.ServerConfig;
import com.hyp.system.domain.RewFileRelation;
import com.hyp.web.controller.manager.FileRelationManager; import com.hyp.web.controller.manager.FileRelationManager;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -25,6 +29,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.util.List; import java.util.List;
import java.util.Objects;
/** /**
@ -162,4 +167,31 @@ public class FileRelationController extends BaseController {
} }
/**
*
*
*/
@ApiOperation("文件下载")
@GetMapping("/download")
public void fileDownload(String fileId, HttpServletResponse response, HttpServletRequest request) {
try {
RewFileRelation rewFileRelation = fileRelationManager.getRewFileRelation(fileId);
if(Objects.isNull(rewFileRelation)){
throw new ServiceException("下载文件不存在");
}
String fileName = rewFileRelation.getFileName();
if (!FileUtils.checkAllowDownload(fileName)) {
throw new Exception(com.hyp.common.utils.StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
}
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
String filePath = HypConfig.getDownloadPath() + fileName;
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
FileUtils.setAttachmentResponseHeader(response, realFileName);
FileUtils.writeBytes(filePath, response.getOutputStream());
} catch (Exception e) {
log.error("下载文件失败", e);
}
}
} }

Loading…
Cancel
Save