许鹏程
2024-10-08 aa3f814a84a1ef346ede9d016bb7671acedb7ae3
根据表单配置查询字段
已修改1个文件
139 ■■■■■ 文件已修改
src/main/java/com/product/mobile/core/service/FaceMobileService.java 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/mobile/core/service/FaceMobileService.java
@@ -1,6 +1,8 @@
package com.product.mobile.core.service;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
@@ -22,6 +24,8 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.nio.charset.Charset;
import java.util.*;
/**
@@ -34,115 +38,114 @@
    @Resource
    FlowDetailService flowDetailService;
    ///获取表单总入口
    /**
     *
     * @param fse传入表名,或 表UUID
     * @return
     */
    public List<FaceFieldEntity> getFaceConfig(FieldSetEntity fse) {
        String tableUuid=fse.getString("table_uuid");
        if (tableUuid==null && StringUtils.isNotEmpty(fse.getString("uuid"))
        String tableUuid = fse.getString("table_uuid");
        if (tableUuid == null && StringUtils.isNotEmpty(fse.getString("uuid"))
                && StringUtils.isEmpty(fse.getString("table_name"))) {
            //通过业务表信息查表单信息
            FieldSetEntity detailFse = getBaseDao().getFieldSetEntity(CmnConst.TABLE_FLOW_DETAIL, fse.getString(CmnConst.FIELD_UUID), false);
            if(detailFse!=null) {
            if (detailFse != null) {
                //获取表名
                fse.setValue("table_name", detailFse.getString("table_name"));
            }
        }
        //通过审批任务的uuid来查表单信息
        if (tableUuid==null && StringUtils.isNotEmpty(fse.getString("table_name"))) {
        if (tableUuid == null && StringUtils.isNotEmpty(fse.getString("table_name"))) {
            FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{fse.getString("table_name")});
            if (!FieldSetEntity.isEmpty(tableInfo)) {
                tableUuid = tableInfo.getString("uuid");
                fse.setValue("table_uuid", tableUuid);
            }
        }
        if(tableUuid!=null) {
        if (tableUuid != null) {
            FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息(uuid)", new String[]{tableUuid});
            if (!FieldSetEntity.isEmpty(tableInfo)) {
                //获取表名
                fse.setValue("table_name", tableInfo.getString("table_name"));
            }
        }
        List<FaceFieldEntity> ls=getFaceFieldByTable(fse);
        addproperty(tableUuid,fse.getString("table_name"),ls);
        List<FaceFieldEntity> ls = getFaceFieldByTable(fse);
        addproperty(tableUuid, fse.getString("table_name"), ls);
        //所有表单uuid自动添加,并为hidden
        return ls;
    }
    //递归把主表和子表的字段属性添加进去,如果没有配表单,则取表数据结构进行展示
    /**
     *
     * @param ls查出来的表单信息
     * @param tables 记录的所有表,对应的表单信息
     * @param tables     记录的所有表,对应的表单信息
     */
    private void  addproperty(String table_uuid,String table_name,List<FaceFieldEntity> ls) {
        if(ls==null) {
            ls=new ArrayList<FaceFieldEntity>();
    private void addproperty(String table_uuid, String table_name, List<FaceFieldEntity> ls) {
        if (ls == null) {
            ls = new ArrayList<FaceFieldEntity>();
        }
        if(ls.size()>0) {
            for(int i=0;i<ls.size();i++) {
                String subTableName=ls.get(i).getSubTableName();///可能是子表
                if(StringUtils.isEmpty(subTableName)) {///主表字段
        if (ls.size() > 0) {
            for (int i = 0; i < ls.size(); i++) {
                String subTableName = ls.get(i).getSubTableName();///可能是子表
                if (StringUtils.isEmpty(subTableName)) {///主表字段
                    DataTableEntity dt = DataPoolCacheImpl.getInstance().getCacheData("表字段信息"
                            ,new String[] {table_uuid,ls.get(i).getField()});
                    if(!DataTableEntity.isEmpty(dt)) {
                            , new String[]{table_uuid, ls.get(i).getField()});
                    if (!DataTableEntity.isEmpty(dt)) {
//                        if(StringUtils.isEmpty(ls.get(i).getType())) {
//                            ls.get(i).setType(dt.getFieldSetEntity(0).getString("field_type"));
//                        }
                        if(StringUtils.isEmpty(ls.get(i).getPrompt()) &&
                        if (StringUtils.isEmpty(ls.get(i).getPrompt()) &&
                                !StringUtils.isEmpty(dt.getFieldSetEntity(0).getString("field_reference"))) {
                            ls.get(i).setPrompt(dt.getFieldSetEntity(0).getString("field_reference"));
                        }
                        if(StringUtils.isEmpty(ls.get(i).getRequired()) &&
                        if (StringUtils.isEmpty(ls.get(i).getRequired()) &&
                                !StringUtils.isEmpty(dt.getFieldSetEntity(0).getString("is_required"))) {
                            ls.get(i).setRequired(dt.getFieldSetEntity(0).getString("is_required"));
                        }
                        if(StringUtils.isEmpty(ls.get(i).getName()) &&
                        if (StringUtils.isEmpty(ls.get(i).getName()) &&
                                !StringUtils.isEmpty(dt.getFieldSetEntity(0).getString("field_show_name"))) {
                            ls.get(i).setName(dt.getFieldSetEntity(0).getString("field_show_name"));
                        }
                    }
                    ls.get(i).setTable(table_name);
                }else {
                } else {
                    //============把子表字段也处理一下
                    //子表
                    FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{subTableName});
                    if (!FieldSetEntity.isEmpty(tableInfo)) {
                        addproperty(tableInfo.getString("uuid"),tableInfo.getString("table_name"),ls.get(i).getSubField());
                        addproperty(tableInfo.getString("uuid"), tableInfo.getString("table_name"), ls.get(i).getSubField());
                    }
                }
            }
            DataTableEntity dt = DataPoolCacheImpl.getInstance().getCacheData("表字段信息",new String[] {table_uuid,"uuid"});
            if(!DataTableEntity.isEmpty(dt)) {
                FaceFieldEntity uuid=new FaceFieldEntity();
            DataTableEntity dt = DataPoolCacheImpl.getInstance().getCacheData("表字段信息", new String[]{table_uuid, "uuid"});
            if (!DataTableEntity.isEmpty(dt)) {
                FaceFieldEntity uuid = new FaceFieldEntity();
                uuid.setField("uuid");
                uuid.setType("String");
                uuid.setTable(table_name);
                uuid.setDisabled("0");
                ls.add(uuid);
            }
        }else {///以表单设计为准,如果没有配置表单,则以数据表为准,全部保留
            DataTableEntity dte = DataPoolCacheImpl.getInstance().getCacheData("所有字段信息并按表分组",new String[] {table_uuid});
            for(int j=0;j<dte.getRows();j++) {
                FaceFieldEntity uuid=new FaceFieldEntity();
                FieldSetEntity f=dte.getFieldSetEntity(j);
                if("pk".equals(f.getString("field_type"))
                        ||"updated_by".equals(f.getString("field_name"))
                        ||"uuid".equals(f.getString("field_name"))
                        ||"updated_utc_datetime".equals(f.getString("field_name"))) {
        } else {///以表单设计为准,如果没有配置表单,则以数据表为准,全部保留
            DataTableEntity dte = DataPoolCacheImpl.getInstance().getCacheData("所有字段信息并按表分组", new String[]{table_uuid});
            for (int j = 0; j < dte.getRows(); j++) {
                FaceFieldEntity uuid = new FaceFieldEntity();
                FieldSetEntity f = dte.getFieldSetEntity(j);
                if ("pk".equals(f.getString("field_type"))
                        || "updated_by".equals(f.getString("field_name"))
                        || "uuid".equals(f.getString("field_name"))
                        || "updated_utc_datetime".equals(f.getString("field_name"))) {
                    continue;
                }
                uuid.setPrompt(f.getString("field_reference"));
@@ -154,9 +157,8 @@
            }
        }
    }
    public List<FaceFieldEntity> getFaceFieldByTable(FieldSetEntity fse) {
        String tableUuid = fse.getString("table_uuid");
        String tableName = fse.getString("table_name");
@@ -169,7 +171,7 @@
        if (StringUtils.isEmpty(tableUuid)) {
            throw new BaseException(MobileCoreCode.SYSTEM_FORM_COUNT);
        }
        FieldSetEntity faceFse = getBaseDao().getFieldSetByFilter("product_sys_face", "table_uuid=?", new Object[]{tableUuid}, true);
        FieldSetEntity faceFse = getBaseDao().getFieldSetByFilter("product_sys_face", "table_uuid=? and face_type=2", new Object[]{tableUuid}, true);
        faceFse.setTableName(tableName);
        return getFaceField(faceFse);
    }
@@ -342,6 +344,32 @@
        return result;
    }
    public static void main(String[] args) {
        String textFilePath = "d:\\Desktop\\新建 文本文档 (2).txt";
        List<String> lines = FileUtil.readLines(new File(textFilePath), CharsetUtil.defaultCharset());
        for (int i = 0; i < lines.size(); i++) {
            //UPDATE `product_db_lift`.`product_sys_datamodel_table` SET `uuid` = '4503ea5c-1e10-40b6-a2b4-79760eea6474', `table_name` = 'product_deivce_failure_level_config', `table_description` = '设备故障等级配置', `table_primary_key` = NULL, `container_name` = NULL, `table_base_view` = NULL, `view_sql` = NULL, `org_level_uuid` = NULL, `is_international` = NULL, `table_type` = '1', `created_by` = '1', `created_utc_datetime` = '2024-08-09 00:00:00', `updated_by` = '1', `updated_utc_datetime` = '2024-08-09 00:00:00', `produce_msg` = NULL, `sequence` = 2, `view_status` = NULL WHERE `table_id` = 5300;
            String line = lines.get(i);
            line = line.replaceAll("`", "");
            String start = line.substring(line.indexOf("SET") + 3, line.indexOf("WHERE"));
            String[] split = start.split(",");
            Map<String, String> map = new HashMap<>();
            for (String s : split) {
                String[] split1 = s.split("=");
                String value = split1.length == 1 ? null : split1[1].trim();
                if ("null".equalsIgnoreCase(value)) {
                    value = null;
                }
                map.put(split1[0].trim(), value);
            }
            lines.set(i, lines.get(i).substring(0, lines.get(i).indexOf("WHERE")) + " WHERE `uuid`=" + map.get("uuid")+";");
        }
        FileUtil.writeLines(lines, textFilePath, CharsetUtil.defaultCharset());
    }
    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);
@@ -366,8 +394,6 @@
                if ("__vModel__".equals(setEntity.getString("property_name"))) {
                    result.add(faceFieldEntity);
                    propertyName = "field";
                } else if ("defaultNow".equals(propertyName)) {
                    propertyName = "defaultValue";
                } else if ("__config__".equals(propertyName)) {
                    __config__ = setEntity.getUUID();
                }
@@ -379,11 +405,7 @@
                }
                propertyName = StrUtil.toCamelCase(propertyName);
                if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) {
                    if ("defaultValue".equals(propertyName)) {
                        ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getBoolean("property_value"));
                    } else {
                        ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
                    }
                    ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
                } else if (!StringUtils.isEmpty(setEntity.getObject("property_value"))) {
                    //判断是否
@@ -429,7 +451,6 @@
                ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
            }
        }
    }
}