图标库

This commit is contained in:
ZZX9599
2025-09-26 13:46:24 +08:00
parent 8479d174be
commit 26af321271
37 changed files with 751 additions and 23 deletions

View File

@ -34,7 +34,7 @@ public class CodeUtil {
}
// 传入需要生成代码的表名
Generation("military_library");
Generation("icon_library");
}
public static void Generation(String... tableName) {

View File

@ -41,7 +41,8 @@ public class JsonUtil {
}
try {
return objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {});
return objectMapper.readValue(json, new TypeReference<Map<String, Object>>() {
});
} catch (Exception e) {
log.error("JSON转Map失败、JSON内容: {}", json, e);
return new HashMap<>(0);
@ -67,7 +68,7 @@ public class JsonUtil {
}
try {
// 使用ObjectMapperMap转换为指定类型对象
// 使用 ObjectMapperMap 转换为指定类型对象
return objectMapper.convertValue(map, clazz);
} catch (IllegalArgumentException e) {
log.error("Map转对象失败、目标类型: {}, Map内容: {}", clazz.getName(), map, e);
@ -86,4 +87,49 @@ public class JsonUtil {
return null;
}
}
/**
* 修改JSON字符串中指定键的值
*/
public static String modifyJsonValue(String json, String key, Object value) {
if (json == null || json.trim().isEmpty() || key == null || key.trim().isEmpty()) {
return json;
}
// 将JSON转换为Map
Map<String, Object> map = jsonToMap(json);
if (map == null) {
return json;
}
// 解析键、支持嵌套
String[] keyParts = key.split("\\.");
Map<String, Object> currentMap = map;
// 遍历键的各个部分、处理嵌套结构
for (int i = 0; i < keyParts.length; i++) {
String part = keyParts[i];
// 如果是最后一个部分、直接设置值
if (i == keyParts.length - 1) {
currentMap.put(part, value);
break;
}
// 如果不是最后一个部分、检查是否存在该键且对应的值是Map
Object nextObj = currentMap.get(part);
if (nextObj instanceof Map) {
currentMap = (Map<String, Object>) nextObj;
} else {
// 如果不存在或不是 Map、创建新的 Map
Map<String, Object> newMap = new HashMap<>();
currentMap.put(part, newMap);
currentMap = newMap;
}
}
// 将修改后的 Map 转换回 JSON
String result = mapToJson(map);
return result != null ? result : json;
}
}

View File

@ -305,6 +305,7 @@ public class SQLiteUtil {
"id" TEXT,
"name" TEXT,
"parent_id" TEXT,
"tree_index" INTEGER,
"created_at" TEXT,
"updated_at" TEXT,
PRIMARY KEY ("id")
@ -341,6 +342,7 @@ public class SQLiteUtil {
"id" TEXT,
"name" TEXT,
"parent_id" TEXT,
"tree_index" INTEGER,
"created_at" TEXT,
"updated_at" TEXT,
PRIMARY KEY ("id")
@ -365,4 +367,35 @@ public class SQLiteUtil {
executeDDL(modelPath, sql);
}
public static void initializationIcon(String iconPath) {
// 创建图标类型表
String sql = """
CREATE TABLE "icon_type" (
"id" TEXT,
"name" TEXT,
"parent_id" TEXT,
"tree_index" INTEGER,
"created_at" TEXT,
"updated_at" TEXT,
PRIMARY KEY ("id")
);
""";
executeDDL(iconPath, sql);
// 创建图标表
sql = """
CREATE TABLE "icon" (
"id" TEXT,
"icon_type_id" TEXT,
"icon_name" TEXT,
"icon_type" TEXT,
"data" TEXT,
"view" TEXT,
"created_at" TEXT,
"updated_at" TEXT,
PRIMARY KEY ("id")
);
""";
executeDDL(iconPath, sql);
}
}