许鹏程
2024-09-23 6aa3771424b2b947446ec679aa5648712e4742ae
src/main/java/com/product/mobile/core/service/FaceMobileService.java
@@ -5,12 +5,16 @@
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.drew.metadata.Face;
import com.google.common.collect.Sets;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
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.mobile.core.config.MobileCoreCode;
import com.product.mobile.core.config.MobileCoreConst;
import com.product.mobile.core.entity.FaceFieldEntity;
import com.product.tool.flow.config.CmnConst;
import com.product.tool.flow.service.FlowDetailService;
@@ -33,8 +37,9 @@
   public List<FaceFieldEntity> getFaceFieldByTable(FieldSetEntity fse) {
      String tableUuid = fse.getString("table_uuid");
      if (StringUtils.isEmpty(tableUuid)) {
         FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{fse.getString("table_name")});
      String tableName = fse.getString("table_name");
      if (StringUtils.isEmpty(tableUuid) && !StringUtils.isEmpty(tableName)) {
         FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{tableName});
         if (!FieldSetEntity.isEmpty(tableInfo)) {
            tableUuid = tableInfo.getString("uuid");
         }
@@ -91,8 +96,18 @@
      List<FieldSetEntity> tagFieldSetEntityList = new ArrayList<>();
      //根据group_uuid 分组
      Map<String, List<FieldSetEntity>> groupMap = new HashMap<>();
      Map<String, List<FieldSetEntity>> parentMap = new HashMap<>();
      for (FieldSetEntity fieldSetEntity : productSysFaceControlProperty.getData()) {
         String groupUuid = fieldSetEntity.getString("group_uuid");
         String parentUuid = fieldSetEntity.getString("parent_uuid");
         if (!StringUtils.isEmpty(parentUuid)) {
            List<FieldSetEntity> fieldSetEntities = parentMap.get(parentUuid);
            if (fieldSetEntities == null) {
               fieldSetEntities = new ArrayList<>();
               parentMap.put(parentUuid, fieldSetEntities);
            }
            fieldSetEntities.add(fieldSetEntity);
         }
         if ("tag".equals(fieldSetEntity.getString("property_name"))) {
            tagFieldSetEntityList.add(fieldSetEntity);
         }
@@ -110,6 +125,7 @@
      }
      List<FaceFieldEntity> result = new ArrayList<>();
      List<List<FieldSetEntity>> subTableField = new ArrayList<>();
      for (FieldSetEntity fs : tagFieldSetEntityList) {
         String groupUuid = fs.getString("group_uuid");
         String parentUuid = fs.getString("parent_uuid");
@@ -120,27 +136,130 @@
         if (CollectionUtil.isEmpty(fieldSetEntity)) {
            continue;
         }
         to(groupMap, fieldSetEntity, subTableField, result,parentMap);
      }
      if (!CollectionUtil.isEmpty(subTableField)) {
         //根据子表表名装载
         Map<String, FaceFieldEntity> tableByFaceField = new HashMap<>();
         for (List<FieldSetEntity> fieldSetEntities : subTableField) {
            String parentUuid = fieldSetEntities.get(0).getString("parent_uuid");
            //先找到children
            List<FieldSetEntity> fieldSetEntity = productSysFaceControlProperty.getFieldSetEntity(parentUuid);
            if (CollectionUtil.isEmpty(fieldSetEntities)) {
               continue;
            }
            //找到了children
            FieldSetEntity fieldSetEntity1 = fieldSetEntity.get(0);
            String p = fieldSetEntity1.getString("parent_uuid");
            String cGroupUuid = fieldSetEntity1.getString("group_uuid");
            if (StringUtils.isEmpty(p) || StringUtils.isEmpty(cGroupUuid)) {
               continue;
            }
            List<FieldSetEntity> childrenGroup = groupMap.get(cGroupUuid);
            List<FieldSetEntity> fieldSetEntity2 = productSysFaceControlProperty.getFieldSetEntity(p);
            if (CollectionUtil.isEmpty(fieldSetEntity2) || CollectionUtil.isEmpty(childrenGroup)) {
               continue;
            }
            //找到了 __config__
            FieldSetEntity fieldSetEntity3 = fieldSetEntity2.get(0);
            String groupUuid = fieldSetEntity3.getString("group_uuid");
            if (StringUtils.isEmpty(groupUuid)) {
               continue;
            }
            String uuid = fieldSetEntity3.getUUID();
            FaceFieldEntity faceFieldEntity = tableByFaceField.get(uuid);
            if (faceFieldEntity == null) {
               faceFieldEntity = new FaceFieldEntity();
            }
            faceFieldEntity.setComponentType("subTable");
            boolean isSub = CollectionUtil.isNotEmpty(faceFieldEntity.getSubField());
            if (!isSub) {
               for (FieldSetEntity setEntity : childrenGroup) {
                  String propertyName = setEntity.getString("property_name");
                  if ("tag".equals(propertyName) && "lx-form-sub-table".equals(setEntity.getString("property_value"))) {
                     isSub = true;
                     break;
                  }
               }
            }
            if (!isSub) {
               //不是子表组件
               continue;
            }
            for (FieldSetEntity setEntity : groupMap.get(groupUuid)) {
               String propertyName = setEntity.getString("property_name");
               if ("subTableName".equals(propertyName)) {
                  faceFieldEntity.setSubTableName(setEntity.getString("property_value"));
                  tableByFaceField.put(faceFieldEntity.getSubTableName(), faceFieldEntity);
               } else if ("add".equals(propertyName)) {
                  faceFieldEntity.setAllowAdd(setEntity.getBoolean("property_value"));
               } else if ("delete".equals(propertyName)) {
                  faceFieldEntity.setAllowDelete(setEntity.getBoolean("property_value"));
               }
            }
            List<FaceFieldEntity> subFieldList = faceFieldEntity.getSubField();
            if (CollectionUtil.isEmpty(subFieldList)) {
               subFieldList = new ArrayList<>();
               faceFieldEntity.setSubField(subFieldList);
            }
            for (List<FieldSetEntity> setEntities : subTableField) {
               to(groupMap, setEntities, null, subFieldList, parentMap);
            }
            if (!tableByFaceField.containsKey(uuid)) {
               tableByFaceField.put(uuid, faceFieldEntity);
               result.add(faceFieldEntity);
            }
            break;
         }
      }
      return result;
   }
   private void to(Map<String, List<FieldSetEntity>> groupMap, List<FieldSetEntity> fieldSetEntity, List<List<FieldSetEntity>> subTableField, List<FaceFieldEntity> result, Map<String, List<FieldSetEntity>> parentMap) {
         FieldSetEntity parent = fieldSetEntity.get(0);
         String groupUuid1 = parent.getString("group_uuid");
         if (StringUtils.isEmpty(groupUuid1)) {
            continue;
         return;
         }
         List<FieldSetEntity> parentGroup = groupMap.get(groupUuid1);
         FaceFieldEntity faceFieldEntity = new FaceFieldEntity();
      boolean parentType = false;
      String __config__ = null;
      List<FieldSetEntity> other = null;
      do {
         for (FieldSetEntity setEntity : parentGroup) {
            //找到属性名称= __vModel__
            String propertyName = setEntity.getString("property_name");
            if ("parentType".equals(propertyName) && "subTable".equals(setEntity.getString("property_value")) && subTableField != null) {
               //子表字段
               subTableField.add(parentGroup);
               result.remove(faceFieldEntity);
               break;
            }
            if ("__vModel__".equals(setEntity.getString("property_name"))) {
               result.add(faceFieldEntity);
               propertyName = "fieldName";
            }else if ("defaultNow".equals(propertyName)){
               propertyName="defaultValue";
            } else if ("__config__".equals(propertyName)) {
               __config__ = setEntity.getUUID();
            }
            if (!StringUtils.isAnyEmpty(__config__) ) {
               //读取子表属性
               if (parentMap != null) {
                  other = parentMap.get(__config__);
               }
            }
            propertyName = StrUtil.toCamelCase(propertyName);
            if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) {
               if ("defaultValue".equals(propertyName)) {
                  ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getBoolean("property_value"));
                  continue;
               } else {
                  ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
               }
@@ -148,10 +267,29 @@
            }
         }
         if (StringUtils.isEmpty(faceFieldEntity.getFieldName())) {
            result.remove(faceFieldEntity);
            continue;
            return;
         }
         List<FieldSetEntity> configGroup = groupMap.get(groupUuid);
         if (parentGroup == other) {
            break;
         }
         if (other != null) {
            parentGroup = other;
            parentMap = null;
         }
      } while (other != null);
      Set<FieldSetEntity> configGroup = Sets.newHashSet(groupMap.get(fieldSetEntity.get(0).getString("group_uuid")));
      if (other != null) {
         if (configGroup == null) {
            configGroup = Sets.newHashSet(other);
         } else {
            configGroup.addAll(other);
         }
      }
      parentGroup = groupMap.get(groupUuid1);
      if (configGroup != null && parentGroup != null) {
         configGroup.addAll(parentGroup);
      }
         for (FieldSetEntity setEntity : configGroup) {
            //找到属性名称= __vModel__
            String propertyName = setEntity.getString("property_name");
@@ -168,8 +306,6 @@
            }
         }
      }
      return result;
   }
}