From d85c2d896228b88dab49386af1478ed2d3eadde2 Mon Sep 17 00:00:00 2001
From: taojinlong
Date: Wed, 28 Aug 2024 17:42:24 +0800
Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AD=97=E5=BA=93=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../font/dao/auto/entity/CoreFont.java | 24 +++++++-
.../font/dao/auto/mapper/CoreFontMapper.java | 2 +-
.../io/dataease/font/manage/FontManage.java | 59 ++++++++++++++++---
.../io/dataease/font/server/FontServer.java | 6 +-
.../resources/db/migration/V2.10__ddl.sql | 2 +
.../src/views/system/font/UploadDetail.vue | 18 +++---
.../io/dataease/api/font/api/FontApi.java | 6 +-
.../io/dataease/api/font/dto/FontDto.java | 2 +
8 files changed, 92 insertions(+), 27 deletions(-)
diff --git a/core/core-backend/src/main/java/io/dataease/font/dao/auto/entity/CoreFont.java b/core/core-backend/src/main/java/io/dataease/font/dao/auto/entity/CoreFont.java
index 8ee19df45f..afd4d9da3e 100644
--- a/core/core-backend/src/main/java/io/dataease/font/dao/auto/entity/CoreFont.java
+++ b/core/core-backend/src/main/java/io/dataease/font/dao/auto/entity/CoreFont.java
@@ -9,7 +9,7 @@ import java.io.Serializable;
*
*
* @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 +
"}";
}
}
diff --git a/core/core-backend/src/main/java/io/dataease/font/dao/auto/mapper/CoreFontMapper.java b/core/core-backend/src/main/java/io/dataease/font/dao/auto/mapper/CoreFontMapper.java
index d136049a63..8e7ef7c341 100644
--- a/core/core-backend/src/main/java/io/dataease/font/dao/auto/mapper/CoreFontMapper.java
+++ b/core/core-backend/src/main/java/io/dataease/font/dao/auto/mapper/CoreFontMapper.java
@@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Mapper;
*
*
* @author fit2cloud
- * @since 2024-08-26
+ * @since 2024-08-28
*/
@Mapper
public interface CoreFontMapper extends BaseMapper {
diff --git a/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java b/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java
index 48d021d73b..54b4b6a9c8 100644
--- a/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java
+++ b/core/core-backend/src/main/java/io/dataease/font/manage/FontManage.java
@@ -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 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 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 queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("file_trans_name", file);
+ List 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;
}
}
diff --git a/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java b/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java
index 422fa19cfa..764266ba6e 100644
--- a/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java
+++ b/core/core-backend/src/main/java/io/dataease/font/server/FontServer.java
@@ -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
diff --git a/core/core-backend/src/main/resources/db/migration/V2.10__ddl.sql b/core/core-backend/src/main/resources/db/migration/V2.10__ddl.sql
index 54087fabc7..cc7d1370b4 100644
--- a/core/core-backend/src/main/resources/db/migration/V2.10__ddl.sql
+++ b/core/core-backend/src/main/resources/db/migration/V2.10__ddl.sql
@@ -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`;
diff --git a/core/core-frontend/src/views/system/font/UploadDetail.vue b/core/core-frontend/src/views/system/font/UploadDetail.vue
index c5b01edcb6..fdc3e88529 100644
--- a/core/core-frontend/src/views/system/font/UploadDetail.vue
+++ b/core/core-frontend/src/views/system/font/UploadDetail.vue
@@ -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 = () => {
defaultFont() throws DEException;
diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/font/dto/FontDto.java b/sdk/api/api-base/src/main/java/io/dataease/api/font/dto/FontDto.java
index c9a2c1ffbd..aa80e5927b 100644
--- a/sdk/api/api-base/src/main/java/io/dataease/api/font/dto/FontDto.java
+++ b/sdk/api/api-base/src/main/java/io/dataease/api/font/dto/FontDto.java
@@ -30,5 +30,7 @@ public class FontDto {
private Boolean isDefault;
private Long updateTime;
private Boolean isBuiltin;
+ private Double size;
+ private String sizeType;
}