|
@@ -10,10 +10,7 @@ import cn.hutool.db.ds.pooled.DbConfig;
|
|
|
import cn.hutool.db.ds.pooled.PooledDataSource;
|
|
import cn.hutool.db.ds.pooled.PooledDataSource;
|
|
|
import lombok.SneakyThrows;
|
|
import lombok.SneakyThrows;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import mingsoft.client.Info;
|
|
|
|
|
-import mingsoft.client.MingsoftClient;
|
|
|
|
|
-import mingsoft.client.MingsoftData;
|
|
|
|
|
-import mingsoft.client.MingsoftPreView;
|
|
|
|
|
|
|
+import mingsoft.client.*;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
import java.util.Comparator;
|
|
import java.util.Comparator;
|
|
@@ -31,7 +28,7 @@ import java.util.stream.Collectors;
|
|
|
* @date 2025-12-24
|
|
* @date 2025-12-24
|
|
|
*/
|
|
*/
|
|
|
@Slf4j(topic = "Service")
|
|
@Slf4j(topic = "Service")
|
|
|
-public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> codes) {
|
|
|
|
|
|
|
+public record MingsoftService(MingsoftClient client, Map<MingsoftDataType, MingsoftData> codes) {
|
|
|
public MingsoftService {
|
|
public MingsoftService {
|
|
|
Assert.notNull(client, "客户端不能为空");
|
|
Assert.notNull(client, "客户端不能为空");
|
|
|
}
|
|
}
|
|
@@ -64,7 +61,7 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
*
|
|
*
|
|
|
* @param dbFile 备份代码的SQLite文件
|
|
* @param dbFile 备份代码的SQLite文件
|
|
|
*/
|
|
*/
|
|
|
- public static Optional<Map<Info, MingsoftData>> loadLocalCodeBackup(String dbFile) throws Exception {
|
|
|
|
|
|
|
+ public static Optional<Map<MingsoftDataType, MingsoftData>> loadLocalCodeBackup(String dbFile) throws Exception {
|
|
|
DbConfig config = new DbConfig();
|
|
DbConfig config = new DbConfig();
|
|
|
config.setUrl("jdbc:sqlite:" + dbFile);
|
|
config.setUrl("jdbc:sqlite:" + dbFile);
|
|
|
config.setMaxActive(2);
|
|
config.setMaxActive(2);
|
|
@@ -89,7 +86,7 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
/**
|
|
/**
|
|
|
* 查服务器上的代码
|
|
* 查服务器上的代码
|
|
|
*/
|
|
*/
|
|
|
- public Optional<Map<Info, MingsoftData>> queryCodes() {
|
|
|
|
|
|
|
+ public Optional<Map<MingsoftDataType, MingsoftData>> queryCodes() {
|
|
|
return Optional.of(client.list()
|
|
return Optional.of(client.list()
|
|
|
.map(json -> json.toBean(MingsoftData.class))
|
|
.map(json -> json.toBean(MingsoftData.class))
|
|
|
.collect(Collectors.toMap(MingsoftData::toInfo, v -> v)))
|
|
.collect(Collectors.toMap(MingsoftData::toInfo, v -> v)))
|
|
@@ -100,15 +97,15 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 复制代码,永远还原到{@link Info#FORM_ID}这个表单ID
|
|
|
|
|
|
|
+ * 复制代码,永远还原到{@link Constant#FORM_ID}这个表单ID
|
|
|
* <p>
|
|
* <p>
|
|
|
- * {@link #copy(Info, Info, String)}
|
|
|
|
|
|
|
+ * {@link #copy(MingsoftDataType, MingsoftDataType, String)}
|
|
|
*
|
|
*
|
|
|
* @param old 旧的
|
|
* @param old 旧的
|
|
|
* @param news 新的
|
|
* @param news 新的
|
|
|
*/
|
|
*/
|
|
|
- public boolean copy(Info old, Info news) {
|
|
|
|
|
- return copy(old, news, Info.FORM_ID);
|
|
|
|
|
|
|
+ public boolean copy(MingsoftDataType old, MingsoftDataType news) {
|
|
|
|
|
+ return copy(old, news, Constant.FORM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -124,19 +121,19 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
* @param news 新的
|
|
* @param news 新的
|
|
|
* @param id 表单ID
|
|
* @param id 表单ID
|
|
|
*/
|
|
*/
|
|
|
- public boolean copy(Info old, Info news, String id) {
|
|
|
|
|
|
|
+ public boolean copy(MingsoftDataType old, MingsoftDataType news, String id) {
|
|
|
return update(id, codes.get(old).clone().info(news));
|
|
return update(id, codes.get(old).clone().info(news));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 还原代码,永远还原到{@link Info#FORM_ID}这个表单ID
|
|
|
|
|
|
|
+ * 还原代码,永远还原到{@link Constant#FORM_ID}这个表单ID
|
|
|
* <p>
|
|
* <p>
|
|
|
- * {@link #restore(Info, String)}
|
|
|
|
|
|
|
+ * {@link #restore(MingsoftDataType, String)}
|
|
|
*
|
|
*
|
|
|
* @param old 旧的
|
|
* @param old 旧的
|
|
|
*/
|
|
*/
|
|
|
- public boolean restore(Info old) {
|
|
|
|
|
- return restore(old, Info.FORM_ID);
|
|
|
|
|
|
|
+ public boolean restore(MingsoftDataType old) {
|
|
|
|
|
+ return restore(old, Constant.FORM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -149,7 +146,7 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
* @param old 旧的
|
|
* @param old 旧的
|
|
|
* @param id 表单ID
|
|
* @param id 表单ID
|
|
|
*/
|
|
*/
|
|
|
- public boolean restore(Info old, String id) {
|
|
|
|
|
|
|
+ public boolean restore(MingsoftDataType old, String id) {
|
|
|
return update(id, codes.get(old));
|
|
return update(id, codes.get(old));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -165,10 +162,10 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 下载{@link Info#FORM_ID}代码
|
|
|
|
|
|
|
+ * 下载{@link Constant#FORM_ID}代码
|
|
|
*/
|
|
*/
|
|
|
public Optional<byte[]> downloadCode() {
|
|
public Optional<byte[]> downloadCode() {
|
|
|
- return downloadCode(Info.FORM_ID);
|
|
|
|
|
|
|
+ return downloadCode(Constant.FORM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -187,12 +184,12 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 保存下载{@link Info#FORM_ID}代码
|
|
|
|
|
|
|
+ * 保存下载{@link Constant#FORM_ID}代码
|
|
|
*
|
|
*
|
|
|
* @param saveFile 保存的文件,如果已经存在,则不会保存
|
|
* @param saveFile 保存的文件,如果已经存在,则不会保存
|
|
|
*/
|
|
*/
|
|
|
public Optional<File> saveDownloadCode(File saveFile) {
|
|
public Optional<File> saveDownloadCode(File saveFile) {
|
|
|
- return saveDownloadCode(saveFile, Info.FORM_ID);
|
|
|
|
|
|
|
+ return saveDownloadCode(saveFile, Constant.FORM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -217,10 +214,10 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 预览{@link Info#FORM_ID}代码
|
|
|
|
|
|
|
+ * 预览{@link Constant#FORM_ID}代码
|
|
|
*/
|
|
*/
|
|
|
- public Optional<Map<String, MingsoftPreView>> previewCode() {
|
|
|
|
|
- return previewCode(Info.FORM_ID);
|
|
|
|
|
|
|
+ public Optional<Map<MingsoftPreViewType, String>> previewCode() {
|
|
|
|
|
+ return previewCode(Constant.FORM_ID);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -228,10 +225,10 @@ public record MingsoftService(MingsoftClient client, Map<Info, MingsoftData> cod
|
|
|
*
|
|
*
|
|
|
* @param id 表单ID
|
|
* @param id 表单ID
|
|
|
*/
|
|
*/
|
|
|
- public Optional<Map<String, MingsoftPreView>> previewCode(String id) {
|
|
|
|
|
|
|
+ public Optional<Map<MingsoftPreViewType, String>> previewCode(String id) {
|
|
|
return Optional.of(client.preview(id)
|
|
return Optional.of(client.preview(id)
|
|
|
.map(item -> item.toBean(MingsoftPreView.class))
|
|
.map(item -> item.toBean(MingsoftPreView.class))
|
|
|
- .collect(Collectors.toMap(MingsoftPreView::getCode, v -> v)))
|
|
|
|
|
|
|
+ .collect(Collectors.toMap(MingsoftPreView::toType, MingsoftPreView::getCode)))
|
|
|
.map(map -> {
|
|
.map(map -> {
|
|
|
log.info("预览代码 Size:{}", map.size());
|
|
log.info("预览代码 Size:{}", map.size());
|
|
|
return map;
|
|
return map;
|