初始化项目

This commit is contained in:
2026-04-21 16:12:04 +08:00
parent 4541af2c63
commit f9d96473da
443 changed files with 36365 additions and 19 deletions

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xujun</groupId>
<artifactId>xtools-app-sys</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>xtools-app-sys-file-web</artifactId>
<!-- 依赖 -->
<dependencies>
<!-- xtools begin -->
<!-- xtools-boot-web-base -->
<dependency>
<groupId>org.xujun</groupId>
<artifactId>xtools-boot-web-base</artifactId>
</dependency>
<!-- xtools end -->
<!-- 项目模块 begin -->
<dependency>
<groupId>org.xujun</groupId>
<artifactId>xtools-app-sys-file</artifactId>
</dependency>
<!-- 项目模块 end -->
</dependencies>
</project>

View File

@@ -0,0 +1,76 @@
package xtools.app.sys.file.web.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xtools.app.sys.file.enums.FilePermissionType;
import xtools.app.sys.file.service.SysFileDownloadCallback;
import xtools.app.sys.file.service.SysFileOptService;
import xtools.app.sys.model.dto.resp.SysFileResp;
import xtools.boot.api.exection.BizError;
import xtools.core.extend.TemplateUtils;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
* <p>Title : SysCommonFileController</p>
* <p>Description : SysCommonFileController</p>
* <p>DevelopTools : Idea_x64_v2026.1</p>
* <p>DevelopSystem : Windows11</p>
* <p>Company : org.xujun</p>
*
* @author : XuJun
* @version : 1.0.0
* @date : 2026/4/11 13:23
*/
@Slf4j
@Tag(name = "系统通用")
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/common")
public class SysCommonFileController {
private final SysFileOptService sysFileOptService;
@Operation(summary = "获取公用文件")
@GetMapping("/get/{id}/file")
public void getFile(
@NotNull(message = "不能为空")
@PathVariable Long id,
HttpServletResponse response
) {
try (ServletOutputStream outputStream = response.getOutputStream()) {
response.setHeader("Cache-Control", "max-age=604800");
sysFileOptService.download(id, outputStream, new SysFileDownloadCallback() {
@Override
public boolean before(SysFileResp fileInfo) {
// 判断文件权限
FilePermissionType permissionType = FilePermissionType.valueOfCode(fileInfo.getPermission());
if (!FilePermissionType.PUBLIC.equals(permissionType)) {
return false;
}
String fileName = URLEncoder.encode(fileInfo.getFileName(), StandardCharsets.UTF_8).replaceAll("\\+", "%20");
String contentDisposition = "attachment; filename=\"{}\"; filename*=UTF-8''{}";
response.setHeader("Content-Disposition", TemplateUtils.format(contentDisposition, fileName, fileName));
response.setContentLengthLong(fileInfo.getFileSize());
return true;
}
});
} catch (IOException e) {
log.error("文件下载失败", e);
throw new BizError("文件下载失败");
}
}
}