mirror of
https://github.com/CodePhiliaX/Chat2DB.git
synced 2025-07-30 19:22:58 +08:00
服务启动时减少io操作
This commit is contained in:
@ -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 {
|
||||
//复制模板
|
||||
copyTemplateFile();
|
||||
}
|
||||
|
||||
public static void copyTemplateFile() {
|
||||
public void copyTemplateFile() {
|
||||
String templateDir = ConfigUtils.CONFIG_BASE_PATH + File.separator + "template";
|
||||
File file = new File(templateDir);
|
||||
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) {
|
||||
File file = new File(dir + File.separator + path);
|
||||
if (file.exists()) {
|
||||
|
@ -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.doc.DatabaseExportService;
|
||||
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.request.DataExportRequest;
|
||||
import ai.chat2db.server.web.api.controller.rdb.vo.TableVO;
|
||||
@ -20,6 +21,7 @@ import jakarta.servlet.http.HttpServletResponse;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@ -48,6 +50,9 @@ public class RdbDocController {
|
||||
@Autowired
|
||||
private RdbWebConverter rdbWebConverter;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
/**
|
||||
* export data
|
||||
*
|
||||
@ -55,6 +60,8 @@ public class RdbDocController {
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void export(@Valid @RequestBody DataExportRequest request, HttpServletResponse response) throws Exception {
|
||||
//复制模板
|
||||
applicationContext.publishEvent(new TemplateEvent("copy"));
|
||||
ExportTypeEnum exportType = EasyEnumUtils.getEnum(ExportTypeEnum.class, request.getExportType());
|
||||
response.setCharacterEncoding("utf-8");
|
||||
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