许鹏程
2024-09-23 6aa3771424b2b947446ec679aa5648712e4742ae
移动端获取表单组件字段,修正子表获取字段
已修改3个文件
258 ■■■■ 文件已修改
src/main/java/com/product/mobile/core/config/MobileCoreConst.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/mobile/core/entity/FaceFieldEntity.java 58 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/mobile/core/service/FaceMobileService.java 196 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/mobile/core/config/MobileCoreConst.java
@@ -1,5 +1,7 @@
package com.product.mobile.core.config;
import com.product.core.config.CoreConst;
/**
 * Copyright  LX-BASE
 *
@@ -9,7 +11,7 @@
 * @Author: LiuChao
 * @Description: 文件管理-常量
 */
public class MobileCoreConst {
public class MobileCoreConst extends CoreConst {
    //公共常量定义
    public static final String UUID = "uuid";
    public static final String UPDATED_BY = "updated_by"; // 修改者
src/main/java/com/product/mobile/core/entity/FaceFieldEntity.java
@@ -1,5 +1,8 @@
package com.product.mobile.core.entity;
import java.util.List;
import java.util.Map;
/**
 * @Author cheng
 * @Date 2024/8/15 11:12
@@ -67,6 +70,21 @@
    private String serialNumber;
    private String organizationType;
    /**
     * 子表允许新增
     */
    private Boolean allowAdd;
    /**
     * 子表允许删除
     */
    private Boolean allowDelete;
    /**
     * 子表表名  当 component = 'subTable' 的时候有值
     */
    private String subTableName;
    private List<FaceFieldEntity> subField;
    public String getFieldName() {
@@ -172,4 +190,44 @@
    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }
    public String getOrganizationType() {
        return organizationType;
    }
    public void setOrganizationType(String organizationType) {
        this.organizationType = organizationType;
    }
    public Boolean getAllowAdd() {
        return allowAdd;
    }
    public void setAllowAdd(Boolean allowAdd) {
        this.allowAdd = allowAdd;
    }
    public Boolean getAllowDelete() {
        return allowDelete;
    }
    public void setAllowDelete(Boolean allowDelete) {
        this.allowDelete = allowDelete;
    }
    public String getSubTableName() {
        return subTableName;
    }
    public void setSubTableName(String subTableName) {
        this.subTableName = subTableName;
    }
    public List<FaceFieldEntity> getSubField() {
        return subField;
    }
    public void setSubField(List<FaceFieldEntity> subField) {
        this.subField = subField;
    }
}
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;
            }
            FieldSetEntity parent = fieldSetEntity.get(0);
            String groupUuid1 = parent.getString("group_uuid");
            if (StringUtils.isEmpty(groupUuid1)) {
                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;
            }
            List<FieldSetEntity> parentGroup = groupMap.get(groupUuid1);
            FaceFieldEntity faceFieldEntity = new FaceFieldEntity();
        }
        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)) {
            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 ("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,28 +267,45 @@
                }
            }
            if (StringUtils.isEmpty(faceFieldEntity.getFieldName())) {
                result.remove(faceFieldEntity);
                continue;
                return;
            }
            List<FieldSetEntity> configGroup = groupMap.get(groupUuid);
            for (FieldSetEntity setEntity : configGroup) {
                //找到属性名称= __vModel__
                String propertyName = setEntity.getString("property_name");
                if ("tag".equals(propertyName)) {
                    propertyName = "component_type";
                } else if ("field".equals(propertyName)) {
                    propertyName = "fileField";
                } else if ("tableName".equals(propertyName)) {
                    propertyName = "fileTableName";
                }
                propertyName = StrUtil.toCamelCase(propertyName);
                if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) {
                    ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
                }
            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);
            }
        }
        return result;
        parentGroup = groupMap.get(groupUuid1);
        if (configGroup != null && parentGroup != null) {
            configGroup.addAll(parentGroup);
        }
        for (FieldSetEntity setEntity : configGroup) {
            //找到属性名称= __vModel__
            String propertyName = setEntity.getString("property_name");
            if ("tag".equals(propertyName)) {
                propertyName = "component_type";
            } else if ("field".equals(propertyName)) {
                propertyName = "fileField";
            } else if ("tableName".equals(propertyName)) {
                propertyName = "fileTableName";
            }
            propertyName = StrUtil.toCamelCase(propertyName);
            if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) {
                ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
            }
        }
    }
}