许鹏程
2025-01-22 84c71e0c4d89cd15d8b85cfc2d2ea7ba0aa251f7
src/main/java/com/product/face/util/FaceUtil.java
@@ -23,7 +23,7 @@
public class FaceUtil {
   public static List<JSONObject> getFaceControlList(DataTableEntity faceControlDt) {
   public static List<JSONObject> getFaceControlList(FieldSetEntity face, DataTableEntity faceControlDt) {
      List<JSONObject> result = new ArrayList<>();
      List<FieldSetEntity> data = faceControlDt.getData();
      Map<String, List<FieldSetEntity>> collect = data.stream()
@@ -33,15 +33,39 @@
      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))); //分组
      int maxFormId = 100;
      for (Map.Entry<String, List<FieldSetEntity>> entry : collect.entrySet()) {
         List<FieldSetEntity> propertyList = entry.getValue();
         result.add(getPropertyJson(propertyList, groupContainer));
         JSONObject propertyJson = getPropertyJson(propertyList, groupContainer);
         Integer o = propertyJson.getInteger("~formId~");
         if (o != null && o > maxFormId) {
            maxFormId = o;
         }
         propertyJson.remove("~formId~");
         Boolean eventProperty = propertyJson.getBoolean("event_property");
         if (eventProperty != null && eventProperty && propertyJson.get("event_array") != null) {
            JSONArray eventArray = propertyJson.getJSONArray("event_array");
            for (int i = 0; i < eventArray.size(); i++) {
               String params = eventArray.getJSONObject(i).getString("params");
               String[] paramsArray;
               if (StringUtils.isEmpty(params)) {
                  paramsArray = new String[]{};
               } else {
                  paramsArray = params.split(",");
               }
               eventArray.getJSONObject(i).put("params", paramsArray);
            }
            face.setValue("events", eventArray);
            continue;
         }
         result.add(propertyJson);
      }
      result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE)));
      face.setValue("maxFormId", maxFormId);
      return result;
   }
   private static JSONObject getPropertyJson(List<FieldSetEntity> propertyList, Map<String, List<FieldSetEntity>> groupContainer) {
   public static JSONObject getPropertyJson(List<FieldSetEntity> propertyList, Map<String, List<FieldSetEntity>> groupContainer) {
      JSONObject property = new JSONObject();
      String propertyValue = null;
      if (!CollectionUtil.isEmpty(propertyList)) {
@@ -71,6 +95,16 @@
                  try {
                     JSONObject propertyJson = getPropertyJson(groupContainer.get(groupUuid), groupContainer);
                     property.put(propertyName, propertyJson);
                     if ("__config__".equals(propertyName)) {
                        String o = propertyJson.getString("formId");
                        if (NumberUtil.isNumber(o)) {
                           Integer formId = property.getInteger("formId");
                           if (formId == null || formId < NumberUtil.parseInt(o)) {
                              property.put("~formId~", NumberUtil.parseInt(o));
                           }
                        }
                        propertyJson.remove("~formId~");
                     }
                  } catch (Exception e) {
                     e.printStackTrace();
                     throw e;
@@ -81,7 +115,19 @@
                  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());
                           .values().stream().map(item -> {
                              JSONObject propertyJson = getPropertyJson(item, groupContainer);
                              String o = propertyJson.getString("~formId~");
                              if (NumberUtil.isNumber(o)) {
                                 Integer formId = property.getInteger("formId");
                                 if (formId == null || formId < NumberUtil.parseInt(o)) {
                                    property.put("~formId~", NumberUtil.parseInt(o));
                                 }
                              }
                              propertyJson.remove("~formId~");
                              return propertyJson;
                           }).sorted(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE))).collect(Collectors.toList());
                     property.put(propertyName, new JSONArray(array));
                  }