mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-31 11:42:41 +08:00
@ -105,6 +105,9 @@ export default function BaseSetting() {
|
|||||||
|
|
||||||
function changeLang(e: any) {
|
function changeLang(e: any) {
|
||||||
setLangLocalStorage(e.target.value);
|
setLangLocalStorage(e.target.value);
|
||||||
|
//切换语言时,需要设置cookie,用来改变后台服务的Locale
|
||||||
|
const date = new Date('2030-12-30 12:30:00').toUTCString();
|
||||||
|
document.cookie = `CHAT2DB.LOCALE=${e.target.value};Expires=${date}`;
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,14 +21,9 @@ public class CopyTemplate {
|
|||||||
/**
|
/**
|
||||||
* 模板文件
|
* 模板文件
|
||||||
**/
|
**/
|
||||||
public static final List<String> TEMPLATE_FILE = Arrays.asList("template.html", "template_diy.docx", "sub_template_diy.docx");
|
private static final List<String> TEMPLATE_FILE = Arrays.asList("template.html", "template_diy.docx", "sub_template_diy.docx");
|
||||||
|
|
||||||
static {
|
public void copyTemplateFile() {
|
||||||
//复制模板
|
|
||||||
copyTemplateFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void copyTemplateFile() {
|
|
||||||
String templateDir = ConfigUtils.CONFIG_BASE_PATH + File.separator + "template";
|
String templateDir = ConfigUtils.CONFIG_BASE_PATH + File.separator + "template";
|
||||||
File file = new File(templateDir);
|
File file = new File(templateDir);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
@ -39,7 +34,7 @@ public class CopyTemplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void saveFile(String dir, String path, boolean isOverride) {
|
public void saveFile(String dir, String path, boolean isOverride) {
|
||||||
if (!isOverride) {
|
if (!isOverride) {
|
||||||
File file = new File(dir + File.separator + path);
|
File file = new File(dir + File.separator + path);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
@ -49,7 +44,7 @@ public class CopyTemplate {
|
|||||||
try (// 模板文件输入输出地址 读取resources下文件
|
try (// 模板文件输入输出地址 读取resources下文件
|
||||||
FileOutputStream outputStream = new FileOutputStream(dir + File.separator + path);
|
FileOutputStream outputStream = new FileOutputStream(dir + File.separator + path);
|
||||||
//返回读取指定资源的输入流
|
//返回读取指定资源的输入流
|
||||||
InputStream inputStream = ConfigUtils.class.getClassLoader().getResourceAsStream("template" + File.separator + path)) {
|
InputStream inputStream = CopyTemplate.class.getClassLoader().getResourceAsStream("template/" + path)) {
|
||||||
byte[] buffer = new byte[4096];
|
byte[] buffer = new byte[4096];
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (-1 != (n = inputStream.read(buffer))) {
|
while (-1 != (n = inputStream.read(buffer))) {
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package ai.chat2db.server.start.listener;
|
||||||
|
|
||||||
|
import ai.chat2db.server.start.config.util.CopyTemplate;
|
||||||
|
import ai.chat2db.server.web.api.controller.rdb.doc.event.TemplateEvent;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TemplateListener
|
||||||
|
*
|
||||||
|
* @author lzy
|
||||||
|
**/
|
||||||
|
@Component
|
||||||
|
public class TemplateListener {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CopyTemplate copyTemplate;
|
||||||
|
|
||||||
|
@EventListener(classes = TemplateEvent.class)
|
||||||
|
public void copyTemplate() {
|
||||||
|
//复制模板
|
||||||
|
copyTemplate.copyTemplateFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -11,6 +11,7 @@ import ai.chat2db.server.web.api.aspect.ConnectionInfoAspect;
|
|||||||
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
|
import ai.chat2db.server.web.api.controller.rdb.converter.RdbWebConverter;
|
||||||
import ai.chat2db.server.web.api.controller.rdb.doc.DatabaseExportService;
|
import ai.chat2db.server.web.api.controller.rdb.doc.DatabaseExportService;
|
||||||
import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions;
|
import ai.chat2db.server.web.api.controller.rdb.doc.conf.ExportOptions;
|
||||||
|
import ai.chat2db.server.web.api.controller.rdb.doc.event.TemplateEvent;
|
||||||
import ai.chat2db.server.web.api.controller.rdb.factory.ExportServiceFactory;
|
import ai.chat2db.server.web.api.controller.rdb.factory.ExportServiceFactory;
|
||||||
import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest;
|
import ai.chat2db.server.web.api.controller.rdb.request.DataExportRequest;
|
||||||
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
|
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
|
||||||
@ -20,6 +21,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
@ -48,6 +50,9 @@ public class RdbDocController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RdbWebConverter rdbWebConverter;
|
private RdbWebConverter rdbWebConverter;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationContext applicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* export data
|
* export data
|
||||||
*
|
*
|
||||||
@ -55,6 +60,8 @@ public class RdbDocController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception {
|
public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
//复制模板
|
||||||
|
applicationContext.publishEvent(new TemplateEvent("copy"));
|
||||||
ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType());
|
ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType());
|
||||||
response.setCharacterEncoding("utf-8");
|
response.setCharacterEncoding("utf-8");
|
||||||
String fileName = URLEncoder.encode(
|
String fileName = URLEncoder.encode(
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package ai.chat2db.server.web.api.controller.rdb.doc.event;
|
||||||
|
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TemplateEvent
|
||||||
|
*
|
||||||
|
* @author lzy
|
||||||
|
**/
|
||||||
|
public class TemplateEvent extends ApplicationEvent {
|
||||||
|
public TemplateEvent(String key) {
|
||||||
|
super(key);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user