mirror of
https://github.com/dataease/dataease.git
synced 2026-05-20 19:48:18 +08:00
feat: 字体管理
This commit is contained in:
@@ -9,12 +9,21 @@ import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.FileUtils;
|
||||
import io.dataease.utils.IDUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import jakarta.servlet.ServletOutputStream;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -25,6 +34,8 @@ public class FontManage {
|
||||
private static String path = "/opt/dataease2.0/data/font/";
|
||||
@Resource
|
||||
private CoreFontMapper coreFontMapper;
|
||||
@Autowired
|
||||
private ResourceLoader resourceLoader;
|
||||
|
||||
public List<FontDto> list(FontDto fontDto) {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
@@ -82,6 +93,38 @@ public class FontManage {
|
||||
return saveFile(file, fileUuid);
|
||||
}
|
||||
|
||||
public void download(Long id, HttpServletResponse response) {
|
||||
CoreFont coreFont = coreFontMapper.selectById(id);
|
||||
try {
|
||||
response.setContentType("application/x-download");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + coreFont.getFileTransName());
|
||||
try (ServletOutputStream out = response.getOutputStream();
|
||||
InputStream stream = new FileInputStream(path + coreFont.getFileTransName())) {
|
||||
byte buff[] = new byte[1024];
|
||||
int length;
|
||||
while ((length = stream.read(buff)) > 0) {
|
||||
out.write(buff, 0, length);
|
||||
}
|
||||
out.flush();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
DEException.throwException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public List<FontDto> defaultFont() {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("isDefault", 1);
|
||||
List<CoreFont> coreFonts = coreFontMapper.selectList(queryWrapper);
|
||||
List<FontDto> fontDtos = new ArrayList<>();
|
||||
for (CoreFont coreFont : coreFonts) {
|
||||
FontDto dto = new FontDto();
|
||||
BeanUtils.copyBean(dto, coreFont);
|
||||
fontDtos.add(dto);
|
||||
}
|
||||
return fontDtos;
|
||||
}
|
||||
|
||||
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||
String fileTransName = "";
|
||||
try {
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.dataease.api.font.dto.FontDto;
|
||||
import io.dataease.exception.DEException;
|
||||
import jakarta.annotation.Resource;
|
||||
import io.dataease.font.manage.FontManage;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@@ -47,4 +48,14 @@ public class FontServer implements FontApi {
|
||||
public String upload(MultipartFile file) throws DEException {
|
||||
return fontManage.upload(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(Long id, HttpServletResponse response) throws DEException {
|
||||
fontManage.download(id, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FontDto> defaultFont() throws DEException {
|
||||
return fontManage.defaultFont();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user