forked from github/dataease
feat: 字体管理
This commit is contained in:
parent
0762fa2819
commit
d3fce1d203
@ -0,0 +1,108 @@
|
||||
package io.dataease.font.dao.auto.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-23
|
||||
*/
|
||||
@TableName("core_font")
|
||||
public class CoreFont implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字体名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件转换名称
|
||||
*/
|
||||
private String fileTransName;
|
||||
|
||||
/**
|
||||
* 是否默认
|
||||
*/
|
||||
private Boolean isDefault;
|
||||
|
||||
/**
|
||||
* 是否内置
|
||||
*/
|
||||
private Boolean isBuiltin;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileTransName() {
|
||||
return fileTransName;
|
||||
}
|
||||
|
||||
public void setFileTransName(String fileTransName) {
|
||||
this.fileTransName = fileTransName;
|
||||
}
|
||||
|
||||
public Boolean getIsDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void setIsDefault(Boolean isDefault) {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
public Boolean getIsBuiltin() {
|
||||
return isBuiltin;
|
||||
}
|
||||
|
||||
public void setIsBuiltin(Boolean isBuiltin) {
|
||||
this.isBuiltin = isBuiltin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CoreFont{" +
|
||||
"id = " + id +
|
||||
", name = " + name +
|
||||
", fileName = " + fileName +
|
||||
", fileTransName = " + fileTransName +
|
||||
", isDefault = " + isDefault +
|
||||
", isBuiltin = " + isBuiltin +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package io.dataease.font.dao.auto.mapper;
|
||||
|
||||
import io.dataease.font.dao.auto.entity.CoreFont;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreFontMapper extends BaseMapper<CoreFont> {
|
||||
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package io.dataease.font.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import io.dataease.api.font.dto.FontDto;
|
||||
import io.dataease.exception.DEException;
|
||||
import io.dataease.font.dao.auto.entity.CoreFont;
|
||||
import io.dataease.font.dao.auto.mapper.CoreFontMapper;
|
||||
import io.dataease.utils.BeanUtils;
|
||||
import io.dataease.utils.IDUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class FontManage {
|
||||
|
||||
private static String path = "/opt/dataease2.0/data/font/";
|
||||
@Resource
|
||||
private CoreFontMapper coreFontMapper;
|
||||
|
||||
public List<FontDto> list(FontDto fontDto) {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
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;
|
||||
}
|
||||
|
||||
public FontDto create(FontDto fontDto) {
|
||||
fontDto.setId(IDUtils.snowID());
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
coreFontMapper.insert(coreFont);
|
||||
return fontDto;
|
||||
}
|
||||
|
||||
|
||||
public FontDto edit(FontDto fontDto) {
|
||||
fontDto.setId(IDUtils.snowID());
|
||||
CoreFont coreFont = new CoreFont();
|
||||
BeanUtils.copyBean(coreFont, fontDto);
|
||||
coreFontMapper.updateById(coreFont);
|
||||
return fontDto;
|
||||
}
|
||||
|
||||
public void delete(Long id) {
|
||||
coreFontMapper.deleteById(id);
|
||||
//TODO delete file
|
||||
}
|
||||
|
||||
public void changeDefault(FontDto fontDto) {
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", fontDto.getId());
|
||||
CoreFont record = new CoreFont();
|
||||
record.setIsDefault(fontDto.getIsDefault());
|
||||
coreFontMapper.update(record, queryWrapper);
|
||||
}
|
||||
|
||||
public void upload(MultipartFile file, long fontID) {
|
||||
String filename = file.getOriginalFilename();
|
||||
QueryWrapper<CoreFont> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("id", fontID);
|
||||
CoreFont record = new CoreFont();
|
||||
record.setFileName(filename);
|
||||
record.setFileTransName(filename);
|
||||
coreFontMapper.update(record, queryWrapper);
|
||||
String fileUuid = UUID.randomUUID().toString();
|
||||
saveFile(file, fileUuid);
|
||||
}
|
||||
|
||||
private static String saveFile(MultipartFile file, String fileNameUUID) throws DEException {
|
||||
String fileTransName = "";
|
||||
try {
|
||||
String filename = file.getOriginalFilename();
|
||||
String suffix = filename.substring(filename.lastIndexOf(".") + 1);
|
||||
String filePath = path + fileNameUUID + "." + suffix;
|
||||
File f = new File(filePath);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(f);
|
||||
fileOutputStream.write(file.getBytes());
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
fileTransName = fileNameUUID + "." + suffix;
|
||||
} catch (Exception e) {
|
||||
DEException.throwException(e);
|
||||
}
|
||||
return fileTransName;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package io.dataease.font.server;
|
||||
|
||||
import io.dataease.api.font.api.FontApi;
|
||||
import io.dataease.api.font.dto.FontDto;
|
||||
import io.dataease.exception.DEException;
|
||||
import jakarta.annotation.Resource;
|
||||
import io.dataease.font.manage.FontManage;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/typeface")
|
||||
public class FontServer implements FontApi {
|
||||
|
||||
@Resource
|
||||
private FontManage fontManage;
|
||||
|
||||
@Override
|
||||
public List<FontDto> list(FontDto fontDto) {
|
||||
return fontManage.list(fontDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontDto create(FontDto fontDto) {
|
||||
return fontManage.create(fontDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FontDto edit(FontDto fontDto) {
|
||||
return fontManage.edit(fontDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
fontManage.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeDefault(FontDto fontDto) {
|
||||
fontManage.changeDefault(fontDto);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void upload(MultipartFile file, long fontID) throws DEException {
|
||||
fontManage.upload(file, fontID);
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package io.dataease.system.dao.auto.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-08
|
||||
*/
|
||||
@TableName("core_typeface")
|
||||
public class CoreTypeface implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 字体名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 文件名称
|
||||
*/
|
||||
private String fileName;
|
||||
|
||||
/**
|
||||
* 文件转换名称
|
||||
*/
|
||||
private String fileTransName;
|
||||
|
||||
/**
|
||||
* 是否默认
|
||||
*/
|
||||
private Boolean isDefault;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFileTransName() {
|
||||
return fileTransName;
|
||||
}
|
||||
|
||||
public void setFileTransName(String fileTransName) {
|
||||
this.fileTransName = fileTransName;
|
||||
}
|
||||
|
||||
public Boolean getIsDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
public void setIsDefault(Boolean isDefault) {
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CoreTypeface{" +
|
||||
"id = " + id +
|
||||
", name = " + name +
|
||||
", fileName = " + fileName +
|
||||
", fileTransName = " + fileTransName +
|
||||
", isDefault = " + isDefault +
|
||||
"}";
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package io.dataease.system.dao.auto.mapper;
|
||||
|
||||
import io.dataease.system.dao.auto.entity.CoreTypeface;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author fit2cloud
|
||||
* @since 2024-08-08
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoreTypefaceMapper extends BaseMapper<CoreTypeface> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user