数据迁移

This commit is contained in:
Github_lizhw 2025-12-13 23:18:14 +08:00
parent 292fda421d
commit 6e51aaf06f
3 changed files with 30 additions and 17 deletions

View File

@ -27,6 +27,7 @@
preview_height
FROM h5_project
<where>
type = 'web_page'
<if test="queryDTO.title != null and queryDTO.title != ''">
AND MATCH(title) AGAINST(#{queryDTO.title} IN NATURAL LANGUAGE MODE)
</if>

View File

@ -25,6 +25,8 @@ public class ImportH5Project {
@Autowired
private H5ProjectService h5ProjectService;
private static Set<String> types = new HashSet<>();
@Test
public void batchImportH5Projects() {
// 创建测试项目列表
@ -74,8 +76,8 @@ public class ImportH5Project {
List<H5Project> projects = new ArrayList<>();
for (Map<String, Object> data : dataList) {
String htmlContent = (String) data.get("html");
if("[]".equals(htmlContent)){
continue;
if ("[]".equals(htmlContent)) {
continue;
}
List<JSONObject> list1 = JSONUtil.toList(htmlContent, JSONObject.class);
@ -93,7 +95,7 @@ public class ImportH5Project {
continue;
}
if("101097300".equals(obj1.getStr("id"))){
if ("101097300".equals(obj1.getStr("id"))) {
continue;
}
@ -116,7 +118,7 @@ public class ImportH5Project {
project.setType(obj1.getStr("type")); // 设置类型为知乎相关
// typeToLowerCase(obj2.getBeanList("layouts", JSONObject.class));
getType(obj2.getJSONObject("content").getBeanList("layouts", JSONObject.class));
H5ProjectContentDTO ddd = null;
try {
@ -127,20 +129,22 @@ public class ImportH5Project {
project.setContent(objectMapper.writeValueAsString(ddd));
project.setContentUpdatedAt(obj2.getLong("content_updated_at"));
project.setDescription(obj2.getStr("description"));
project.setPreviewUrl(obj2.getByPath("preview.url",String.class)); // 可以根据需要设置预览图URL
project.setPreviewUrlWatermark(obj2.getByPath("preview.url_watermark",String.class)); // 可以根据需要设置水印预览图URL
project.setPreviewWidth(obj2.getByPath("preview.width",Integer.class)); // 默认预览图宽度
project.setPreviewHeight(obj2.getByPath("preview.height",Integer.class)); // 默认预览图高度
project.setPreviewUrl(obj2.getByPath("preview.url", String.class)); // 可以根据需要设置预览图URL
project.setPreviewUrlWatermark(obj2.getByPath("preview.url_watermark", String.class)); // 可以根据需要设置水印预览图URL
project.setPreviewWidth(obj2.getByPath("preview.width", Integer.class)); // 默认预览图宽度
project.setPreviewHeight(obj2.getByPath("preview.height", Integer.class)); // 默认预览图高度
project.setStatus(1); // 设置为启用状态
log.info("开始保存 {}", project.getId());
try {
h5ProjectService.saveOrUpdate(project);
}catch (Exception e){
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
log.info("打印所有" +
"types : {}", types);
// 保存项目
boolean result = h5ProjectService.saveBatchH5ProjectsWithContent(projects);
@ -149,19 +153,27 @@ public class ImportH5Project {
/**
*便利全部的元素typeToLowerCase(content.getBeanList("layouts", JSONObject.class));
* 便利全部的元素typeToLowerCase(content.getBeanList("layouts", JSONObject.class));
*
* @param layouts
*/
private void typeToLowerCase(List<JSONObject> layouts) {
private void getType(List<JSONObject> layouts) {
if (layouts == null) {
return;
}
for (JSONObject layout : layouts) {
dg(layout.getBeanList("elements", JSONObject.class));
deep(layout.getBeanList("elements", JSONObject.class));
}
}
private void dg(List<JSONObject> elements) {
private void deep(List<JSONObject> elements) {
elements.forEach(item -> {
item.set("type", item.getStr("type").toLowerCase(Locale.ROOT));
types.add(item.getStr("type"));
if (H5ProjectContentDTO.ElementType.fromValue(item.getStr("type")) == null) {
log.info("item : {}", item);
}
if (item.getStr("type").equals("group")) {
dg(item.getBeanList("elements", JSONObject.class));
deep(item.getBeanList("elements", JSONObject.class));
}
});
}

View File

@ -16,8 +16,8 @@ services:
volumes:
- rustfs_data_volume:/data
environment:
- RUSTFS_ROOT_USER=admin
- RUSTFS_ROOT_PASSWORD=admin123
- RUSTFS_ACCESS_KEY=admin
- RUSTFS_SECRET_KEY=admin123
restart: unless-stopped
volumes: