forked from github/dataease
fix: 字库设置
This commit is contained in:
parent
550258e06a
commit
d85c2d8962
@ -9,7 +9,7 @@ import java.io.Serializable;
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-26
|
||||
* @since 2024-08-28
|
||||
*/
|
||||
@TableName("core_font")
|
||||
public class CoreFont implements Serializable {
|
||||
@ -51,6 +51,10 @@ public class CoreFont implements Serializable {
|
||||
*/
|
||||
private Boolean isBuiltin;
|
||||
|
||||
private Double size;
|
||||
|
||||
private String sizeType;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -107,6 +111,22 @@ public class CoreFont implements Serializable {
|
||||
this.isBuiltin = isBuiltin;
|
||||
}
|
||||
|
||||
public Double getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public void setSize(Double size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public String getSizeType() {
|
||||
return sizeType;
|
||||
}
|
||||
|
||||
public void setSizeType(String sizeType) {
|
||||
this.sizeType = sizeType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CoreFont{" +
|
||||
@ -117,6 +137,8 @@ public class CoreFont implements Serializable {
|
||||
", isDefault = " + isDefault +
|
||||
", updateTime = " + updateTime +
|
||||
", isBuiltin = " + isBuiltin +
|
||||
", size = " + size +
|
||||
", sizeType = " + sizeType +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-26
|
||||
* @since 2024-08-28
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreFontMapper extends BaseMapper<CoreFont> {
|
||||
|
@ -1,7 +1,9 @@
|
||||
package io.dataease.font.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import io.dataease.api.font.dto.FontDto;
|
||||
import io.dataease.chart.dao.auto.entity.CoreChartView;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.font.dao.auto.entity.CoreFont;
|
||||
import io.dataease.font.dao.auto.mapper.CoreFontMapper;
|
||||
@ -10,6 +12,7 @@ import io.dataease.utils.FileUtils;
|
||||
import io.dataease.utils.IDUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -25,6 +28,7 @@ import java.nio.charset.StandardCharsets;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -51,6 +55,11 @@ public class FontManage {
|
||||
}
|
||||
|
||||
public FontDto create(FontDto fontDto) {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("name", fontDto.getName());
|
||||
if (CollectionUtils.isNotEmpty(coreFontMapper.selectList(queryWrapper))) {
|
||||
DEException.throwException("存在重名字库");
|
||||
}
|
||||
fontDto.setId(IDUtils.snowID());
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
@ -64,6 +73,13 @@ public class FontManage {
|
||||
if (ObjectUtils.isEmpty(fontDto.getId())) {
|
||||
return create(fontDto);
|
||||
}
|
||||
if (fontDto.getIsDefault()) {
|
||||
UpdateWrapper<CoreFont> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.ne("id", fontDto.getId());
|
||||
CoreFont record = new CoreFont();
|
||||
record.setIsDefault(false);
|
||||
coreFontMapper.update(record, updateWrapper);
|
||||
}
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
coreFont.setUpdateTime(System.currentTimeMillis());
|
||||
@ -88,18 +104,25 @@ public class FontManage {
|
||||
coreFontMapper.update(record, queryWrapper);
|
||||
}
|
||||
|
||||
public String upload(MultipartFile file) {
|
||||
public FontDto upload(MultipartFile file) {
|
||||
String fileUuid = UUID.randomUUID().toString();
|
||||
return saveFile(file, fileUuid);
|
||||
}
|
||||
|
||||
public void download(Long id, HttpServletResponse response) {
|
||||
CoreFont coreFont = coreFontMapper.selectById(id);
|
||||
public void download(String file, HttpServletResponse response) {
|
||||
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("file_trans_name", file);
|
||||
List<CoreFont> coreFonts = coreFontMapper.selectList(queryWrapper);
|
||||
if (CollectionUtils.isNotEmpty(coreFonts)) {
|
||||
DEException.throwException("不存在的字库文件");
|
||||
}
|
||||
|
||||
try {
|
||||
response.setContentType("application/x-download");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + coreFont.getFileTransName());
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + coreFonts.get(0).getFileTransName());
|
||||
try (ServletOutputStream out = response.getOutputStream();
|
||||
InputStream stream = new FileInputStream(path + coreFont.getFileTransName())) {
|
||||
InputStream stream = new FileInputStream(path + coreFonts.get(0).getFileTransName())) {
|
||||
byte buff[] = new byte[1024];
|
||||
int length;
|
||||
while ((length = stream.read(buff)) > 0) {
|
||||
@ -125,8 +148,8 @@ public class FontManage {
|
||||
return fontDtos;
|
||||
}
|
||||
|
||||
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||
String fileTransName = "";
|
||||
private static FontDto saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||
FontDto fontDto = new FontDto();
|
||||
try {
|
||||
String filename = file.getOriginalFilename();
|
||||
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
|
||||
@ -136,11 +159,29 @@ public class FontManage {
|
||||
fileOutputStream.write(file.getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
fileTransName = fileNameUUID + "." + suffix;
|
||||
fontDto.setFileTransName(fileNameUUID + "." + suffix);
|
||||
|
||||
long length = file.getSize();
|
||||
String unit = "MB";
|
||||
Double size = 0.0;
|
||||
if ((double) length / 1024 / 1024 > 1) {
|
||||
if ((double) length / 1024 / 1024 / 1024 > 1) {
|
||||
unit = "GB";
|
||||
size = Double.valueOf(String.format("%.2f", (double) length / 1024 / 1024 / 1024));
|
||||
} else {
|
||||
size = Double.valueOf(String.format("%.2f", (double) length / 1024 / 1024));
|
||||
}
|
||||
} else {
|
||||
unit = "KB";
|
||||
size = Double.valueOf(String.format("%.2f", (double) length / 1024));
|
||||
}
|
||||
fontDto.setSize(size);
|
||||
fontDto.setSizeType(unit);
|
||||
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(e);
|
||||
}
|
||||
return fileTransName;
|
||||
return fontDto;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ public class FontServer implements FontApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(MultipartFile file) throws DEException {
|
||||
public FontDto upload(MultipartFile file) throws DEException {
|
||||
return fontManage.upload(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(Long id, HttpServletResponse response) throws DEException {
|
||||
fontManage.download(id, response);
|
||||
public void download(String file, HttpServletResponse response) throws DEException {
|
||||
fontManage.download(file, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,3 +84,5 @@ CREATE TABLE `core_font`
|
||||
`is_BuiltIn` tinyint(1) default 0 COMMENT '是否内置',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
ALTER TABLE `core_font` ADD COLUMN `size` DOUBLE NULL AFTER `is_BuiltIn`;
|
||||
ALTER TABLE `core_font` ADD COLUMN `size_type` varchar(255) NULL AFTER `size`;
|
||||
|
@ -10,16 +10,15 @@ const state = reactive({
|
||||
})
|
||||
const loading = ref(false)
|
||||
const upload = ref()
|
||||
const uploadFile = ref('')
|
||||
const fileName = ref('')
|
||||
const uploadExcel = () => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', state.fileList.raw)
|
||||
fileName.value = state.fileList.raw.name
|
||||
ruleForm.fileName = state.fileList.raw.name
|
||||
loading.value = true
|
||||
return uploadFontFile(formData)
|
||||
.then(res => {
|
||||
uploadFile.value = res.data
|
||||
ruleForm.size = res.data.size
|
||||
ruleForm.fileTransName = res.data.fileTransName
|
||||
upload.value?.clearFiles()
|
||||
loading.value = false
|
||||
})
|
||||
@ -42,6 +41,8 @@ const defaultForm = {
|
||||
name: '',
|
||||
fileName: '',
|
||||
fileTransName: '',
|
||||
size: 0,
|
||||
sizeType: '',
|
||||
isDefault: 0,
|
||||
isBuiltin: 0,
|
||||
updateTime: 0
|
||||
@ -86,12 +87,9 @@ const confirm = () => {
|
||||
ruleFormRef.value.validate(val => {
|
||||
if (val) {
|
||||
if (action.value === 'uploadFile') {
|
||||
if (uploadFile.value === '') {
|
||||
if (ruleForm.fileTransName === '') {
|
||||
ElMessage.error('请上传字库文件')
|
||||
return
|
||||
} else {
|
||||
ruleForm.fileTransName = uploadFile.value
|
||||
ruleForm.fileName = fileName.value
|
||||
}
|
||||
}
|
||||
edit(ruleForm).then(res => {
|
||||
@ -144,8 +142,8 @@ const confirm = () => {
|
||||
<FontInfo
|
||||
@del="fontDel"
|
||||
v-show="state.fileList"
|
||||
size="52.2M"
|
||||
name="OsakaMono.ttf"
|
||||
:size="ruleForm.size + ruleForm.sizeType"
|
||||
:name="ruleForm.fileName"
|
||||
></FontInfo>
|
||||
<el-upload
|
||||
action=""
|
||||
|
@ -42,10 +42,10 @@ public interface FontApi {
|
||||
public void changeDefault(@RequestBody FontDto fontDto);
|
||||
|
||||
@PostMapping("/uploadFile")
|
||||
String upload(@RequestParam("file") MultipartFile file) throws DEException;
|
||||
FontDto upload(@RequestParam("file") MultipartFile file) throws DEException;
|
||||
|
||||
@GetMapping("/download/{id}")
|
||||
void download(@PathVariable("id") Long id, HttpServletResponse response) throws DEException;
|
||||
@GetMapping("/download/{file}")
|
||||
void download(@PathVariable("file") String file, HttpServletResponse response) throws DEException;
|
||||
|
||||
@GetMapping("/defaultFont")
|
||||
List<FontDto> defaultFont() throws DEException;
|
||||
|
@ -30,5 +30,7 @@ public class FontDto {
|
||||
private Boolean isDefault;
|
||||
private Long updateTime;
|
||||
private Boolean isBuiltin;
|
||||
private Double size;
|
||||
private String sizeType;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user