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