From ac070bd08ba4cb6c1e3bf670db75b6a8e801b84b Mon Sep 17 00:00:00 2001
From: 杜洪波 <1074825718@qq.com>
Date: 星期一, 17 十一月 2025 18:00:30 +0800
Subject: [PATCH] 表单建模树优化
---
src/main/java/com/product/face/service/FaceDesignService.java | 158 ++++++++++++++++++----------------------------------
1 files changed, 54 insertions(+), 104 deletions(-)
diff --git a/src/main/java/com/product/face/service/FaceDesignService.java b/src/main/java/com/product/face/service/FaceDesignService.java
index 2fc74e1..3480f04 100644
--- a/src/main/java/com/product/face/service/FaceDesignService.java
+++ b/src/main/java/com/product/face/service/FaceDesignService.java
@@ -1,33 +1,30 @@
package com.product.face.service;
-import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.IdUtil;
-import cn.hutool.core.util.NumberUtil;
-import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-import com.drew.metadata.Face;
import com.product.admin.service.PublicService;
import com.product.common.lang.StringUtils;
+import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.config.CoreConst;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.transfer.Transactional;
-import com.product.core.util.JsonUtil;
import com.product.face.config.ErrorCode;
import com.product.face.config.FaceConst;
import com.product.face.service.ide.IFaceDesignService;
+import com.product.face.util.FaceUtil;
+import com.product.file.config.CmnConst;
import com.product.util.BaseUtil;
-import org.apache.logging.log4j.core.Core;
+import org.apache.poi.hdgf.pointers.Pointer;
+import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
-import java.io.File;
import java.util.*;
-import java.util.stream.Collectors;
/**
* @Author cheng
@@ -41,6 +38,14 @@
@Resource
public PublicService publicService;
+ public DataTableEntity listAllTable(){
+ return getBaseDao().listTable("product_sys_datamodel_table", null, "table_type ASC");
+ }
+
+ public DataTableEntity listAllDesignFace(){
+ return getBaseDao().listTable(FaceConst.TABLE_FACE_CONFIG);
+ }
+
/**
* 鑾峰彇琛ㄥ崟閰嶇疆璇︽儏
*
@@ -55,105 +60,34 @@
if (DataTableEntity.isEmpty(fieldPropertyDt)) {
throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
}
- List<JSONObject> result = getFaceControlList(fieldPropertyDt);
+ List<JSONObject> result = FaceUtil.getFaceControlList(fse, fieldPropertyDt);
Map<String, Object> other = new HashMap<>();
other.put("drawingList", result);
+ DataTableEntity faceCustomField = fse.getSubDataTable("product_sys_face_custom_field");
+ if (!DataTableEntity.isEmpty(faceCustomField)) {
+ for (int i = 0; i < faceCustomField.getRows(); i++) {
+ faceCustomField.setFieldValue(i, "customField", true);
+ faceCustomField.setFieldValue(i, "added", true);
+ }
+ other.put("product_sys_face_custom_field", BaseUtil.dataTableEntityToJson(faceCustomField));
+ } else {
+ other.put("product_sys_face_custom_field", new String[]{});
+ }
fse.getSubData().clear();
return BaseUtil.success(fse, other);
}
- public List<JSONObject> getFaceControlList(DataTableEntity faceControlDt) {
- List<JSONObject> result = new ArrayList<>();
- List<FieldSetEntity> data = faceControlDt.getData();
- Map<String, List<FieldSetEntity>> collect = data.stream()
- .filter(item -> StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栫埗绾�
-// .sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))) //鎺掑簭
- .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID))); //鍒嗙粍
- Map<String, List<FieldSetEntity>> groupContainer = data.stream()
- .filter(item -> !StringUtils.isEmpty(item.getString(FaceConst.FIELD_PARENT_UUID))) //杩囨护 鍙栧瓙绾�
- .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_PARENT_UUID))); //鍒嗙粍
- for (Map.Entry<String, List<FieldSetEntity>> entry : collect.entrySet()) {
- List<FieldSetEntity> propertyList = entry.getValue();
- result.add(getPropertyJson(propertyList, groupContainer));
+ public class Pointer {
+ int data = 0;
+
+ public int getData() {
+ return ++data;
}
- result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE)));
- return result;
+
+ public void setData(int data) {
+ this.data = data;
+ }
}
-
- private JSONObject getPropertyJson(List<FieldSetEntity> propertyList, Map<String, List<FieldSetEntity>> groupContainer) {
- JSONObject property = new JSONObject();
- String propertyValue = null;
- if (!CollectionUtil.isEmpty(propertyList)) {
- for (FieldSetEntity fs : propertyList) {
- //灞炴�х被鍨� 1
- String groupUuid = fs.getUUID();
- String propertyType = fs.getString(FaceConst.FIELD_PROPERTY_TYPE);
- String propertyName = fs.getString(FaceConst.FIELD_PROPERTY_NAME);
- propertyValue = fs.getString(FaceConst.FIELD_PROPERTY_VALUE);
- switch (propertyType) {
- case "1"://瀛楃涓�
- property.put(propertyName, propertyValue);
- break;
- case "2"://鏁扮粍
- property.put(propertyName, propertyValue.split(","));
- break;
- case "3"://瀛愮骇瀵硅薄
- try {
- JSONObject propertyJson = getPropertyJson(groupContainer.get(groupUuid), groupContainer);
- property.put(propertyName, propertyJson);
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
- }
- break;
- case "4"://瀛愮骇鏁扮粍瀵硅薄
- List<FieldSetEntity> propertyListChild = groupContainer.get(groupUuid);
- if (propertyListChild != null && !propertyListChild.isEmpty()) {
- List<Object> array = propertyListChild.stream()
- .collect(Collectors.groupingBy(item -> item.getString(FaceConst.FIELD_GROUP_UUID)))
- .values().stream().map(item -> getPropertyJson(item, groupContainer)).sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))).collect(Collectors.toList());
- property.put(propertyName, new JSONArray(array));
- }
-
-// groupContainer.put(groupUuid, array);
- break;
- case "5": //boolean 绫诲瀷
- Boolean value = null;
- if ("1".equals(propertyValue)) {
- value = true;
- } else if ("0".equals(propertyValue)) {
- value = false;
- }
- property.put(propertyName, value);
- break;
- case "6":// int 绫诲瀷
- if (NumberUtil.isNumber(propertyValue)) {
- property.put(propertyName, NumberUtil.parseInt(propertyValue));
- }
- break;
- case "7"://double 绫诲瀷
- if (NumberUtil.isDouble(propertyValue)) {
- property.put(propertyName, NumberUtil.parseDouble(propertyValue));
- }
- break;
- }
- }
- }
-
- if (!StringUtils.isEmpty(propertyValue)) {
- Object o = groupContainer.get(propertyValue);
- if (o != null) {
- if (o instanceof JSONArray) {
- ((JSONArray) o).add(property);
- } else {
- ((JSONObject) o).putAll(property);
- groupContainer.remove(propertyValue);
- }
- }
- }
- return property;
- }
-
/**
* 淇濆瓨琛ㄥ崟鍐呭鏁版嵁
@@ -170,8 +104,17 @@
ErrorCode.SAVE_EMPTY_FACE_FAIL.throwException();
}
List<FieldSetEntity> fieldSetEntityList = new ArrayList<>();
+ //澹版槑涓�涓甫鎸囬拡鐨刬nt鍙橀噺
+ Pointer pointer = new Pointer();
for (int i = 0; i < fields.getRows(); i++) {
- fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i));
+ if (fields.getBoolean(i, "event_property")) {
+ DataTableEntity subDataTable = fields.getFieldSetEntity(i).getSubDataTable("event_array");
+ if (DataTableEntity.isEmpty(subDataTable)) {
+ continue;
+ }
+ fields.setFieldValue(i, "event_array", BaseUtil.dataTableEntityToJson(subDataTable));
+ }
+ fieldSetEntityList.addAll(controlTraverse(new JSONObject((Map) fields.getFieldSetEntity(i).getValues()), null, i, pointer));
}
fse.removeSubData(FaceConst.FACE_FIELD);
BaseUtil.createCreatorAndCreationTime(fse);
@@ -181,12 +124,15 @@
if (!StringUtils.isEmpty(fse.getUUID())) {
getBaseDao().delete(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY, "master_uuid=?", new Object[]{fse.getUUID()});
}
+ if (StringUtils.isEmpty(fse.getString("terminal_type"))) {
+ fse.setValue("terminal_type", 1);
+ }
getBaseDao().saveFieldSetEntity(fse);
fse.getSubData().clear();
return fse;
}
- public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence) {
+ public List<FieldSetEntity> controlTraverse(Object o, String parentUuid, Integer sequence, Pointer pointer) {
List<FieldSetEntity> fieldSetList = new ArrayList<>();
try {
if (o instanceof JSONArray) {
@@ -195,7 +141,7 @@
try {
for (int i = 0; i < jsonArray.size(); i++) {
Object obj = jsonArray.get(i);
- fieldSetList.addAll(controlTraverse(obj, parentUuid, i));
+ fieldSetList.addAll(controlTraverse(obj, parentUuid, i, pointer));
}
} catch (Exception e) {
e.printStackTrace();
@@ -210,9 +156,13 @@
FieldSetEntity fs = getTemplateFieldSet(entry.getKey(), entry.getValue(), groupUuid);
if (fs != null) {
int propertyType = fs.getInteger(FaceConst.FIELD_PROPERTY_TYPE).intValue();
+ // 2025骞�6鏈�16鏃� 14:28:39 绉诲姩绔� 浜哄憳閫夋嫨瀛楁鏈�夛紝榛樿涓�0 bug瑙e喅锛堟湰韬槸false锛屼絾鏄暟鎹簱淇濆瓨涓�0锛�
+ if (5 == propertyType && "defaultValue".equals(fs.getString("property_name")) && !fs.getBoolean("property_value")) {
+ continue;
+ }
if ((4 == propertyType || 3 == propertyType) && (entry.getValue() instanceof JSONArray || entry.getValue() instanceof JSONObject)) {
try {
- fieldSetList.addAll(controlTraverse(entry.getValue(), fs.getUUID(), null));
+ fieldSetList.addAll(controlTraverse(entry.getValue(), fs.getUUID(), null, pointer));
fs.remove(FaceConst.FIELD_PROPERTY_VALUE);
} catch (Exception e) {
e.printStackTrace();
@@ -224,7 +174,7 @@
}
}
if (sequence != null) {
- FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, sequence, groupUuid);
+ FieldSetEntity fs = getTemplateFieldSet(FaceConst.CONTROL_SEQUENCE, pointer.getData(), groupUuid);
fs.setValue(FaceConst.FIELD_PARENT_UUID, parentUuid);
fieldSetList.add(fs);
}
--
Gitblit v1.9.2