代码提交

This commit is contained in:
liang.chao 2025-09-18 10:59:09 +08:00
parent 7395ad621b
commit 662f1eecb9
6 changed files with 53 additions and 4 deletions

View File

@ -21,6 +21,7 @@ import com.bonus.web.service.ProjectService;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
@ -34,9 +35,11 @@ import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Collectors;
import static com.bonus.common.utils.SecurityUtils.getLoginUser;
@ -176,6 +179,8 @@ public class FileManagementController extends BaseController {
dto.setSourceFileName(upload.getSourceFileName());
dto.setFileType(upload.getFileType());
dto.setSuffixName(upload.getSuffixName());
dto.setSourceType("1");
dto.setUpdateUserId(getLoginUser().getUserId());
dto.setUpdateUserName(getLoginUser().getUsername());
dto.setCreateUserId(getLoginUser().getUserId());
@ -240,6 +245,7 @@ public class FileManagementController extends BaseController {
dto.setSourceFileName(upload.getSourceFileName());
dto.setFileType(upload.getFileType());
dto.setSuffixName(upload.getSuffixName());
dto.setSourceType("1");
fileManageMapper.updateFileSource(dto);
}
return fileManageService.updateFileManage(dto);
@ -347,4 +353,32 @@ public class FileManagementController extends BaseController {
}
return R.ok(num);
}
@GetMapping("/getFileAsBase64}")
public R getFileAsBase64(@PathVariable Long id) throws IOException {
Map<String, Object> response = new HashMap<>();
DaKyProFilesContentsVo record = fileManageService.getFileById(id);
if (record == null || StringUtils.isBlank(record.getFilePath())) {
return R.fail("文件未找到");
}
String filePath = record.getFilePath();
String fileName = record.getFileName();
Path path = Paths.get(filePath);
// 2. 读取文件为字节数组
byte[] fileBytes = Files.readAllBytes(path);
// 3. 转为 Base64 编码字符串
String base64String = Base64.getEncoder().encodeToString(fileBytes);
// 4. 设置响应数据
response.put("fileName", fileName);
response.put("suffix_name", record.getSuffixName());
// Base64 内容可直接用于前端
response.put("fileBase64", base64String);
return R.ok(response);
}
}

View File

@ -45,4 +45,6 @@ public interface FileManageMapper {
Integer getSortById(String id);
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
DaKyProFilesContentsVo getFileById(Long id);
}

View File

@ -32,4 +32,6 @@ public interface FileManageService {
List<DaKyProFilesContentsDto> getFileManageTree(DaKyProFilesContentsDto dto);
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
DaKyProFilesContentsVo getFileById(Long id);
}

View File

@ -129,4 +129,9 @@ public class FileManageServiceImpl implements FileManageService {
public DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto) {
return fileManageMapper.getFileManageById(dto);
}
@Override
public DaKyProFilesContentsVo getFileById(Long id) {
return fileManageMapper.getFileById(id);
}
}

View File

@ -38,7 +38,7 @@ server:
# 日志配置
logging:
level:
com.bonus: info
com.bonus: debug
org.springframework: warn
# 用户配置

View File

@ -59,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sourceFileName != null and sourceFileName != ''">source_file_name,</if>
<if test="fileName != null and fileName != ''">file_name,</if>
<if test="fileType != null and fileType != ''">file_type,</if>
<if test="suffixName != null and suffixName != ''">suffix_name,</if>
<if test="fileSize != null and fileSize != ''">file_size,</if>
<if test="sourceType != null and sourceType != ''">source_type,</if>
<if test="createUserId != null">create_user_id,</if>
@ -72,6 +73,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="sourceFileName != null and sourceFileName != ''">#{sourceFileName},</if>
<if test="fileName != null and fileName != ''">#{fileName},</if>
<if test="fileType != null and fileType != ''">#{fileType},</if>
<if test="suffixName != null and suffixName != ''">#{suffixName},</if>
<if test="fileSize != null and fileSize != ''">#{fileSize},</if>
<if test="sourceType != null and sourceType != ''">#{sourceType},</if>
<if test="createUserId != null">#{createUserId},</if>
@ -107,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
source_file_name = #{sourceFileName},
file_name = #{fileName},
file_type = #{fileType},
suffix_name = #{suffixName},
file_size = #{fileSize},
source_type = #{sourceType},
update_user_id = #{updateUserId},
@ -245,4 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE
dkpfc.id = #{id}
</select>
<select id="getFileById" resultType="com.bonus.web.domain.vo.DaKyProFilesContentsVo">
SELECT * from da_ky_sys_file_source where id = #{id}
</select>
</mapper>