代码提交
This commit is contained in:
parent
7395ad621b
commit
662f1eecb9
|
|
@ -21,6 +21,7 @@ import com.bonus.web.service.ProjectService;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
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.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
@ -34,9 +35,11 @@ import javax.validation.Validator;
|
||||||
import javax.validation.ValidatorFactory;
|
import javax.validation.ValidatorFactory;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.ArrayList;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.nio.file.Files;
|
||||||
import java.util.Set;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.bonus.common.utils.SecurityUtils.getLoginUser;
|
import static com.bonus.common.utils.SecurityUtils.getLoginUser;
|
||||||
|
|
@ -176,6 +179,8 @@ public class FileManagementController extends BaseController {
|
||||||
dto.setSourceFileName(upload.getSourceFileName());
|
dto.setSourceFileName(upload.getSourceFileName());
|
||||||
dto.setFileType(upload.getFileType());
|
dto.setFileType(upload.getFileType());
|
||||||
dto.setSuffixName(upload.getSuffixName());
|
dto.setSuffixName(upload.getSuffixName());
|
||||||
|
dto.setSourceType("1");
|
||||||
|
|
||||||
dto.setUpdateUserId(getLoginUser().getUserId());
|
dto.setUpdateUserId(getLoginUser().getUserId());
|
||||||
dto.setUpdateUserName(getLoginUser().getUsername());
|
dto.setUpdateUserName(getLoginUser().getUsername());
|
||||||
dto.setCreateUserId(getLoginUser().getUserId());
|
dto.setCreateUserId(getLoginUser().getUserId());
|
||||||
|
|
@ -240,6 +245,7 @@ public class FileManagementController extends BaseController {
|
||||||
dto.setSourceFileName(upload.getSourceFileName());
|
dto.setSourceFileName(upload.getSourceFileName());
|
||||||
dto.setFileType(upload.getFileType());
|
dto.setFileType(upload.getFileType());
|
||||||
dto.setSuffixName(upload.getSuffixName());
|
dto.setSuffixName(upload.getSuffixName());
|
||||||
|
dto.setSourceType("1");
|
||||||
fileManageMapper.updateFileSource(dto);
|
fileManageMapper.updateFileSource(dto);
|
||||||
}
|
}
|
||||||
return fileManageService.updateFileManage(dto);
|
return fileManageService.updateFileManage(dto);
|
||||||
|
|
@ -347,4 +353,32 @@ public class FileManagementController extends BaseController {
|
||||||
}
|
}
|
||||||
return R.ok(num);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,4 +45,6 @@ public interface FileManageMapper {
|
||||||
Integer getSortById(String id);
|
Integer getSortById(String id);
|
||||||
|
|
||||||
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
|
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
|
||||||
|
|
||||||
|
DaKyProFilesContentsVo getFileById(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,6 @@ public interface FileManageService {
|
||||||
List<DaKyProFilesContentsDto> getFileManageTree(DaKyProFilesContentsDto dto);
|
List<DaKyProFilesContentsDto> getFileManageTree(DaKyProFilesContentsDto dto);
|
||||||
|
|
||||||
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
|
DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto);
|
||||||
|
|
||||||
|
DaKyProFilesContentsVo getFileById(Long id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -129,4 +129,9 @@ public class FileManageServiceImpl implements FileManageService {
|
||||||
public DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto) {
|
public DaKyProFilesContentsDto getFileManageById(DaKyProFilesContentsDto dto) {
|
||||||
return fileManageMapper.getFileManageById(dto);
|
return fileManageMapper.getFileManageById(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DaKyProFilesContentsVo getFileById(Long id) {
|
||||||
|
return fileManageMapper.getFileById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ server:
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
level:
|
level:
|
||||||
com.bonus: info
|
com.bonus: debug
|
||||||
org.springframework: warn
|
org.springframework: warn
|
||||||
|
|
||||||
# 用户配置
|
# 用户配置
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="sourceFileName != null and sourceFileName != ''">source_file_name,</if>
|
<if test="sourceFileName != null and sourceFileName != ''">source_file_name,</if>
|
||||||
<if test="fileName != null and fileName != ''">file_name,</if>
|
<if test="fileName != null and fileName != ''">file_name,</if>
|
||||||
<if test="fileType != null and fileType != ''">file_type,</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="fileSize != null and fileSize != ''">file_size,</if>
|
||||||
<if test="sourceType != null and sourceType != ''">source_type,</if>
|
<if test="sourceType != null and sourceType != ''">source_type,</if>
|
||||||
<if test="createUserId != null">create_user_id,</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="sourceFileName != null and sourceFileName != ''">#{sourceFileName},</if>
|
||||||
<if test="fileName != null and fileName != ''">#{fileName},</if>
|
<if test="fileName != null and fileName != ''">#{fileName},</if>
|
||||||
<if test="fileType != null and fileType != ''">#{fileType},</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="fileSize != null and fileSize != ''">#{fileSize},</if>
|
||||||
<if test="sourceType != null and sourceType != ''">#{sourceType},</if>
|
<if test="sourceType != null and sourceType != ''">#{sourceType},</if>
|
||||||
<if test="createUserId != null">#{createUserId},</if>
|
<if test="createUserId != null">#{createUserId},</if>
|
||||||
|
|
@ -107,6 +109,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
source_file_name = #{sourceFileName},
|
source_file_name = #{sourceFileName},
|
||||||
file_name = #{fileName},
|
file_name = #{fileName},
|
||||||
file_type = #{fileType},
|
file_type = #{fileType},
|
||||||
|
suffix_name = #{suffixName},
|
||||||
file_size = #{fileSize},
|
file_size = #{fileSize},
|
||||||
source_type = #{sourceType},
|
source_type = #{sourceType},
|
||||||
update_user_id = #{updateUserId},
|
update_user_id = #{updateUserId},
|
||||||
|
|
@ -245,4 +248,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
WHERE
|
WHERE
|
||||||
dkpfc.id = #{id}
|
dkpfc.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getFileById" resultType="com.bonus.web.domain.vo.DaKyProFilesContentsVo">
|
||||||
|
SELECT * from da_ky_sys_file_source where id = #{id}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue