许鹏程
2023-05-24 7baf145ac8ca6cff9177c50c8862ba38d274b484
表单缓存、列表模糊搜索
已添加4个文件
已修改4个文件
909 ■■■■ 文件已修改
src/main/java/com/product/face/config/FaceConst.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/entity/FaceEntity.java 36 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/entity/FaceListEntity.java 346 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/service/FaceApplyService.java 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/service/FaceCacheService.java 173 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/service/FaceDesignService.java 112 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/service/FaceListSearchService.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/util/FaceUtil.java 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/face/config/FaceConst.java
@@ -44,4 +44,12 @@
    //控件排序属性
    public static final String CONTROL_SEQUENCE = "control_sequence";
    /**
     * ç¼“存起始Key
     */
    public static final String FACE_LIST_KEY = "face:fieldList:";
    public static final String FACE_FORM_CACHE_KEY = "face:form:";
}
src/main/java/com/product/face/entity/FaceEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,36 @@
package com.product.face.entity;
import com.alibaba.fastjson.JSONObject;
import java.io.Serializable;
import java.util.List;
/**
 * @Author cheng
 * @Date 2023/5/24 10:31
 * @Desc
 */
public class FaceEntity implements Serializable {
    private static final long serialVersionUID = 2740417254150550879L;
    private JSONObject data;
    private List<JSONObject>  drawingList;
    public JSONObject getData() {
        return data;
    }
    public void setData(JSONObject data) {
        this.data = data;
    }
    public List<JSONObject> getDrawingList() {
        return drawingList;
    }
    public void setDrawingList(List<JSONObject> drawingList) {
        this.drawingList = drawingList;
    }
}
src/main/java/com/product/face/entity/FaceListEntity.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,346 @@
package com.product.face.entity;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.product.admin.config.CmnConst;
import com.product.admin.service.DictService;
import com.product.admin.service.SystemFaceService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.cache.util.RedisUtil;
import com.product.core.config.CoreConst;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.spring.context.SpringBeanUtil;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
/**
 * @Author cheng
 * @Description åˆ—表字段操作类
 * @Date 2021/9/7 14:34
 * @Version 1.0
 */
public class FaceListEntity implements Serializable {
    private static final long serialVersionUID = -6777140406080679771L;
    /**
     * è¡¨uuid
     */
    private String tableUuid;
    /**
     * face_uuid
     */
    private String uuid;
    /**
     * è¡¨å•名
     */
    private String faceName;
    /**
     * åŠŸèƒ½uuid
     */
    @Deprecated
    private String functionUuid;
    /**
     * å­—段集合
     */
    private List<FaceField> faceFields;
    /**
     * è¡¨å
     */
    private String tableName;
    /**
     * èŽ·å–è¡¨å
     *
     * @return
     */
    public String getTableName() {
        if (this.tableName == null && this.tableUuid != null) {
            //从缓存中获取
            DataTableEntity cacheData = DataPoolCacheImpl.getInstance().getCacheData("所有表信息(uuid)", new String[]{this.tableUuid});
            if (cacheData != null && cacheData.getRows() > 0) {
                String table_name = cacheData.getString(0, "table_name");
                this.tableName = table_name;
            }
        }
        return tableName;
    }
    /**
     * æ¡ä»¶å­—段
     *
     * @param fieldName      å­—段名称
     * @param faceUuid       å­—段uuid
     * @param columnName     åˆ—名
     * @param columnWidth    åˆ—宽
     * @param sequence       æŽ’序
     * @param fieldReference å‚ç…§
     */
    public void addField(String fieldName, String faceUuid, String columnName, String columnWidth, Integer sequence, String fieldReference) {
        FaceField faceField = new FaceField();
        faceField.setFieldName(fieldName);
        faceField.setFieldUuid(faceUuid);
        faceField.setColumnName(columnName);
        faceField.setColumnWidth(columnWidth);
        faceField.setSequence(sequence);
        faceField.setFieldReference(fieldReference);
        if (this.faceFields == null) {
            this.faceFields = Lists.newArrayList();
        }
        this.faceFields.add(faceField);
    }
    /**
     * å­—段排序方法
     */
    public void sortField() {
        if (this.faceFields != null && this.faceFields.size() > 0) {
            this.faceFields.sort((a, b) -> {
                return a.getSequence().compareTo(b.getSequence());
            });
        }
    }
    public String getTableUuid() {
        return tableUuid;
    }
    public void setTableUuid(String tableUuid) {
        this.tableUuid = tableUuid;
    }
    public String getUuid() {
        return uuid;
    }
    public void setUuid(String uuid) {
        this.uuid = uuid;
    }
    public String getFaceName() {
        return faceName;
    }
    public void setFaceName(String faceName) {
        this.faceName = faceName;
    }
    public String getFunctionUuid() {
        return functionUuid;
    }
    public void setFunctionUuid(String functionUuid) {
        this.functionUuid = functionUuid;
    }
    public List<FaceField> getFaceFields() {
        return faceFields;
    }
    public void setFaceFields(List<FaceField> faceFields) {
        this.faceFields = faceFields;
    }
    /**
     * èŽ·å–å‚ç…§æ¡ä»¶
     *
     * @param fieldName
     * @param dictName
     * @return
     */
    private String getDictFilter(String fieldName, String dictName) {
        StringBuilder filter = new StringBuilder();
        DictService bean = SpringBeanUtil.getBean(DictService.class);
        String manager_type = null;
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser != null && currentUser.getCurrentManager() != null) {
            manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE);
        } else {
            manager_type = null;
        }
        //拼装普通参照查询所需参数
        FieldSetEntity fse = new FieldSetEntity();
        fse.setTableName(CmnConst.PRODUCT_SYS_DICT);
        fse.setValue(CmnConst.DICT_NAME, dictName);
        fse.setValue(CoreConst.SYSTEM_CLIENT_TYPE_, currentUser.getClientType());
        //获取参照集合
        DataTableEntity dataTableEntity = bean.listDictByname(fse, manager_type);
        if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
            //组成条件
            Object[] uuids = dataTableEntity.getUuids();
            filter.append(fieldName);
            filter.append(" in  (SELECT  dict_value FROM product_sys_dict where ");
            filter.append(BaseUtil.buildQuestionMarkFilter("uuid", uuids, true));
            filter.append(" and dict_label like concat('%','~val~','%') ) ");
        }
        return filter.toString();
    }
    /**
     * èŽ·å–æ¡ä»¶
     *
     * @param tableAlias è¡¨åˆ«å
     * @param aliasField å­—段别名
     * @return
     */
    public Map<String, List<String>> getFilters(String tableAlias, Map<String, List<String>> aliasField) {
        DataPoolCacheImpl poolCache = null;
        //所有字段集合
        List<FaceField> faceFields = this.getFaceFields();
        //普通模糊查询字段集合
        List<String> fieldNames = Lists.newArrayList();
        //参照模糊查询条件集合
        List<String> filters = Lists.newArrayList();
        //返回的结果集
        Map<String, List<String>> maps = Maps.newHashMap();
        maps.put("fields", fieldNames);
        maps.put("filter", filters);
        for (int i = 0; i < faceFields.size(); i++) {
            FaceField faceField = faceFields.get(i);
            if (StringUtils.isEmpty(faceField.getFieldName()) || StringUtils.isEmpty(faceField.getFieldReference())) {
                if (poolCache == null) {
                    poolCache = DataPoolCacheImpl.getInstance();
                }
                DataTableEntity dt = poolCache.getCacheData("表字段信息", new String[]{getTableUuid(), faceField.getFieldName()});
                if (BaseUtil.dataTableIsEmpty(dt)) {
                } else {
                    FieldSetEntity f = dt.getFieldSetEntity(0);
                    faceField.setFieldName(f.getString(CmnConst.FIELD_NAME));
                    faceField.setFieldReference(f.getString("field_reference"));
                }
            }
            //字段名称
            String fieldName = faceField.getFieldName();
            if (aliasField != null && !StringUtils.isEmpty(fieldName)) {
                List<String> fieldAlias = aliasField.get(getTableName() + "." + fieldName);
                if (fieldAlias != null && fieldAlias.size() > 0) {
                    String alias = fieldAlias.get(0);
                    if (!StringUtils.isEmpty(alias)) {
                        fieldName = alias;
                    }
                }
            }
            //参照处理
            String field_reference = faceField.getFieldReference();
            if (!StringUtils.isEmpty(field_reference)) {
                if (field_reference.indexOf("《") == 0 && field_reference.indexOf("》") > 0) {
                    //普通参照
                    filters.add(getDictFilter(fieldName, field_reference.replace("《", "").replace("》", "")));
                    continue;
                } else {
                    if (poolCache == null) {
                        poolCache = DataPoolCacheImpl.getInstance();
                    }
                    //高级参照
                    DataTableEntity prompt = poolCache.getCacheData("高级参照配置信息", new String[]{field_reference});
                    if (BaseUtil.dataTableIsEmpty(prompt)) {
                        continue;
                    }
                    FieldSetEntity ff = prompt.getFieldSetEntity(0);
                    StringBuilder p = new StringBuilder();
                    p.append(fieldName).append(" in ").append(" ( SELECT ").append(ff.getString("value_field")).append(" FROM ").append(ff.getString("source_table"));
                    p.append(" WHERE ").append(ff.getString("view_fields")).append(" like concat('%','~val~','%') )");
                    filters.add(p.toString());
                    continue;
                }
            }
            if (!StringUtils.isEmpty(faceField.getFieldName())) {
                fieldNames.add(StringUtils.isEmpty(tableAlias) ? faceField.getFieldName() : ("`" + tableAlias + "`.`" + fieldName + "`"));
            }
        }
        //获取redis èµ·å§‹key
        String faceListKey = SystemFaceService.FACE_LIST_KEY;
        //重新放入redis
        RedisUtil.set(faceListKey + getUuid(), this);
        return maps;
    }
    /**
     * å­—段实体类
     */
    public class FaceField implements Serializable {
        private static final long serialVersionUID = 3154509166818911568L;
        /**
         * å­—段名称
         */
        private String fieldName;
        /**
         * å­—段uuid
         */
        private String fieldUuid;
        /**
         * åˆ—名
         */
        private String columnName;
        /**
         * åˆ—宽
         */
        private String columnWidth;
        /**
         * æŽ’序
         */
        private Integer sequence;
        /**
         * å­—段参照
         */
        private String fieldReference;
        public String getFieldReference() {
            return fieldReference;
        }
        public void setFieldReference(String fieldReference) {
            this.fieldReference = fieldReference;
        }
        public String getFieldName() {
            return fieldName;
        }
        public void setFieldName(String fieldName) {
            this.fieldName = fieldName;
        }
        public String getFieldUuid() {
            return fieldUuid;
        }
        public void setFieldUuid(String fieldUuid) {
            this.fieldUuid = fieldUuid;
        }
        public String getColumnName() {
            return columnName;
        }
        public void setColumnName(String columnName) {
            this.columnName = columnName;
        }
        public String getColumnWidth() {
            return columnWidth;
        }
        public void setColumnWidth(String columnWidth) {
            this.columnWidth = columnWidth;
        }
        public Integer getSequence() {
            return sequence;
        }
        public void setSequence(Integer sequence) {
            this.sequence = sequence;
        }
    }
}
src/main/java/com/product/face/service/FaceApplyService.java
@@ -3,8 +3,10 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.admin.entity.FaceListEntity;
import com.product.admin.service.SystemFaceService;
import com.product.common.lang.StringUtils;
import com.product.core.cache.util.RedisUtil;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
@@ -12,6 +14,7 @@
import com.product.face.config.ErrorCode;
import com.product.face.config.FaceConst;
import com.product.face.entity.TableColumn;
import com.product.face.util.FaceUtil;
import com.product.util.BaseUtil;
import org.springframework.stereotype.Service;
@@ -19,7 +22,6 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @Author cheng
@@ -33,8 +35,7 @@
    private SystemFaceService systemFaceService;
    @Resource
    private FaceDesignService designService;
    private FaceCacheService faceCacheService;
    public Object getFaceListConf(FieldSetEntity fse) {
        String faceUuid = fse.getString(FaceConst.FIELD_FACE_UUID);
@@ -46,41 +47,13 @@
        if (!StringUtils.isEmpty(faceUuid) && StringUtils.isEmpty(faceNumber)) {
            return systemFaceService.getFaceFieldList(faceUuid);
        }
        //根据表单号查询
        FieldSetEntity faceConf = getBaseDao().getFieldSetByFilter(FaceConst.TABLE_FACE_CONFIG, "face_number=?", new Object[]{faceNumber}, true);
        DataTableEntity fieldPropertyDt = faceConf.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY);
        if (DataTableEntity.isEmpty(fieldPropertyDt)) {
            throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
        }
        List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt);
        JSONObject jsonObject = faceControlList.get(0);
        if (jsonObject == null || jsonObject.isEmpty()) {
            throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
        }
        //表格列
        JSONArray tableColumns = jsonObject.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG).getJSONArray(FaceConst.CHILDREN);
        if (tableColumns == null || tableColumns.isEmpty()) {
            throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
        }
        List<TableColumn> result = Lists.newArrayList();
        for (int i = 0; i < tableColumns.size(); i++) {
            TableColumn tableColumn = new TableColumn();
            JSONObject columnJson = tableColumns.getJSONObject(i);
            String fieldName = columnJson.getString(FaceConst.FIELD_PROPERTY_VMODEL);
            if (StringUtils.isEmpty(fieldName)) {
                continue;
            }
            JSONObject config = columnJson.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG);
            Object setWidth = config.get("setWidth");
            if (!StringUtils.isEmpty(setWidth)) {
                tableColumn.setColumnWidth(setWidth + "%");
            }
            tableColumn.setField(fieldName);
            tableColumn.setTitle(config.getString(FaceConst.FIELD_PROPERTY_LABEL));
            result.add(tableColumn);
        final String redisKey = FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber;
        if (RedisUtil.exists(redisKey)) {
            return RedisUtil.get(redisKey);
        }
        return result;
        return null;
    }
    /**
@@ -101,7 +74,7 @@
        if (DataTableEntity.isEmpty(fieldPropertyDt)) {
            throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
        }
        List<JSONObject> faceControlList = designService.getFaceControlList(fieldPropertyDt);
        List<JSONObject> faceControlList = FaceUtil.getFaceControlList(fieldPropertyDt);
        Map<String, Object> other = new HashMap<>();
        other.put("drawingList", faceControlList);
        faceConf.getSubData().clear();
src/main/java/com/product/face/service/FaceCacheService.java
@@ -1,7 +1,23 @@
package com.product.face.service;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.common.lang.StringUtils;
import com.product.core.cache.util.RedisUtil;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.service.support.AbstractBaseService;
import com.product.face.config.FaceConst;
import com.product.face.entity.FaceEntity;
import com.product.face.entity.FaceListEntity;
import com.product.face.entity.TableColumn;
import com.product.face.util.FaceUtil;
import com.product.util.BaseUtil;
import org.springframework.stereotype.Service;
import java.util.List;
/**
 * @Author cheng
@@ -11,13 +27,162 @@
@Service
public class FaceCacheService extends AbstractBaseService {
    public final static String FACE_CACHE_KEY = "system:face:";
    /**
     * åˆ·æ–°è¡¨å•缓存(core调用)
     */
    public void refreshCache() {
        this.loadingCache(null);
    }
    /**
     * åˆ·æ–°è¡¨å•缓存(core调用)
     *
     * @param uuid
     */
    public void refreshCache(String uuid) {
        this.loadingCache(uuid);
    }
    /**
     * ç³»ç»ŸåŠ è½½è¡¨å•ç¼“å­˜
     *
     * @param uuid
     */
    private void loadingCache(String uuid) {
        String filter = BaseUtil.ifNotNull(uuid, (val) -> "uuid=?");
        Object[] objects = null;
        if (!StringUtils.isEmpty(uuid)) {
            objects = new Object[]{uuid};
        }
        DataTableEntity dt = getBaseDao().listTable(FaceConst.TABLE_FACE_CONFIG, filter, objects);
        if (!DataTableEntity.isEmpty(dt)) {
            return;
        }
        for (FieldSetEntity fs : dt.getData()) {
            String faceType = fs.getString(FaceConst.FIELD_FACE_TYPE);
            if (StringUtils.isEmpty(faceType)) {
                continue;
            }
            String faceNumber = fs.getString(FaceConst.FIELD_FACE_NUMBER);
            if (StringUtils.isEmpty(faceNumber)) {
                continue;
            }
            if ("2".equals(faceType)) {
                //表单
                loadingFormCache(fs);
            } else if ("1".equals(faceType)) {
                //列表
                loadingListCache(fs);
            }
        }
    }
    /**
     * èŽ·å–åˆ—è¡¨ç¼“å­˜
     *
     * @param faceNumber
     * @return
     */
    public FaceListEntity getFaceListCache(String faceNumber) {
        if (StringUtils.isEmpty(faceNumber)) {
            return null;
        }
        final String faceListKey = FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber;
        return (FaceListEntity) RedisUtil.get(faceListKey);
    }
    /**
     * èŽ·å–è¡¨å•ç¼“å­˜
     *
     * @param faceNumber
     * @return
     */
    public FaceEntity getFaceFormCache(String faceNumber) {
        if (StringUtils.isEmpty(faceNumber)) {
            return null;
        }
        final String faceFormKey = FaceConst.FACE_FORM_CACHE_KEY + ":face-number" + faceNumber;
        return (FaceEntity) RedisUtil.get(faceFormKey);
    }
    /**
     * åŠ è½½è¡¨å•ç¼“å­˜
     *
     * @param fse
     */
    public void loadingFormCache(FieldSetEntity fse) {
        DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY);
        if (DataTableEntity.isEmpty(fieldPropertyDt)) {
            return;
        }
        fse.getSubData().clear();
        String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
        List<JSONObject> faceControlList = FaceUtil.getFaceControlList(fieldPropertyDt);
        if (faceControlList != null) {
            FaceEntity face = new FaceEntity();
            face.setData(BaseUtil.fieldSetEntityToJson(fse));
            face.setDrawingList(faceControlList);
            RedisUtil.set(FaceConst.FACE_FORM_CACHE_KEY + faceNumber, face);
        }
    }
    /**
     * åŠ è½½åˆ—è¡¨ç¼“å­˜
     *
     * @param fse
     */
    public void loadingListCache(FieldSetEntity fse) {
        DataTableEntity fieldPropertyDt = fse.getSubDataTable(FaceConst.TABLE_FACE_FIELD_CONTROL_PROPERTY);
        if (DataTableEntity.isEmpty(fieldPropertyDt)) {
            return;
        }
        List<JSONObject> faceControlList = FaceUtil.getFaceControlList(fieldPropertyDt);
        JSONObject jsonObject = faceControlList.get(0);
        if (jsonObject == null || jsonObject.isEmpty()) {
            return;
        }
        //表格列
        JSONArray tableColumns = jsonObject.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG).getJSONArray(FaceConst.CHILDREN);
        if (tableColumns == null || tableColumns.isEmpty()) {
            return;
        }
        String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
        String tableUuid = fse.getString(FaceConst.FIELD_TABLE_UUID);
        List<TableColumn> result = Lists.newArrayList();
        FaceListEntity faceListEntity = new FaceListEntity();
        faceListEntity.setFaceName(faceNumber);
        faceListEntity.setTableUuid(tableUuid);
        faceListEntity.setUuid(fse.getUUID());
        for (int i = 0; i < tableColumns.size(); i++) {
            TableColumn tableColumn = new TableColumn();
            JSONObject columnJson = tableColumns.getJSONObject(i);
            String fieldName = columnJson.getString(FaceConst.FIELD_PROPERTY_VMODEL);
            if (StringUtils.isEmpty(fieldName)) {
                continue;
            }
            JSONObject config = columnJson.getJSONObject(FaceConst.FIELD_PROPERTY_CONFIG);
            Object setWidth = config.get("setWidth");
            if (!StringUtils.isEmpty(setWidth)) {
                tableColumn.setColumnWidth(setWidth + "%");
            }
            FieldSetEntity fieldInfo = BaseUtil.getSingleInfoByCache("表字段信息", new String[]{tableUuid, fieldName});
            String label = config.getString(FaceConst.FIELD_PROPERTY_LABEL);
            if (!FieldSetEntity.isEmpty(fieldInfo)) {
                String fieldUuid = fieldInfo.getString(FaceConst.UUID);
                String fieldReference = fieldInfo.getString(FaceConst.FIELD_FIELD_REFERENCE);
                faceListEntity.addField(fieldName, fieldUuid, label, tableColumn.getColumnWidth(), i, fieldReference);
            }
            tableColumn.setField(fieldName);
            tableColumn.setTitle(config.getString(FaceConst.FIELD_PROPERTY_LABEL));
            result.add(tableColumn);
        }
        //验证表单中的字段是否存在
        if (faceListEntity != null && !CollectionUtil.isEmpty(faceListEntity.getFaceFields())) {
            RedisUtil.set(FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber, faceListEntity);
        }
    }
}
src/main/java/com/product/face/service/FaceDesignService.java
@@ -1,13 +1,9 @@
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.config.CoreConst;
@@ -16,18 +12,15 @@
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.util.BaseUtil;
import org.apache.logging.log4j.core.Core;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
/**
 * @Author cheng
@@ -55,112 +48,11 @@
        if (DataTableEntity.isEmpty(fieldPropertyDt)) {
            throw new BaseException(ErrorCode.GET_FACE_CONFIG_FAIL);
        }
        List<JSONObject> result = getFaceControlList(fieldPropertyDt);
        List<JSONObject> result = FaceUtil.getFaceControlList(fieldPropertyDt);
        Map<String, Object> other = new HashMap<>();
        other.put("drawingList", result);
        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));
        }
        result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE)));
        return result;
    }
    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);
                if (StringUtils.equalsAny(propertyName, "renderKey", "formId")) {
                    propertyValue = fs.getString("id");
                }
                if ("componentType".equals(propertyName) && "design".equals(propertyValue)) {
                    continue;
                }
                if ("layout".equals(propertyName)) {
                    property.put("defaultValue", null);
                }
                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;
    }
src/main/java/com/product/face/service/FaceListSearchService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,59 @@
package com.product.face.service;
import com.product.common.lang.StringUtils;
import com.product.core.cache.util.RedisUtil;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.face.config.FaceConst;
import com.product.face.entity.FaceListEntity;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
/**
 * @Author cheng
 * @Date 2023/5/23 17:41
 * @Desc è¡¨å•列表搜索
 */
@Component
public class FaceListSearchService extends AbstractBaseService {
    public String getFaceListSearchFilter(Map<String, List<String>> aliasTable, Map<String, List<String>> aliasField, String faceUuid, String faceNumber, String val) throws BaseException {
        if (StringUtils.isEmpty(val)) {
            return "";
        }
        FaceListEntity face = null;
        if (!StringUtils.isEmpty(faceNumber)) {
            face = (FaceListEntity) RedisUtil.get(FaceConst.FACE_LIST_KEY + ":face-number" + faceNumber);
        } else if (!StringUtils.isEmpty(faceUuid)){
            face = (FaceListEntity) RedisUtil.get(FaceConst.FACE_LIST_KEY + faceUuid);
        }
        if (face != null) {
            String tableAlias = null;
            String tableName = face.getTableName();
            List<String> t = aliasTable.get(tableName);
            if (t != null && t.size() > 0) {
                tableAlias = t.get(0);
            }
            Map<String, List<String>> params = face.getFilters(tableAlias, aliasField);
            List<String> fieldNames = params.get("fields");
            List<String> filters = params.get("filter");
            String filter = "";
            for (int i = 0; i < fieldNames.size(); i++) {
                if (i > 0) {
                    filter += " or ";
                }
                filter += " " + fieldNames.get(i) + " LIKE BINARY concat('%','" + val + "','%')";
            }
            for (int i = 0; i < filters.size(); i++) {
                if (!"".equals(filter)) {
                    filter += " or ";
                }
                filter += filters.get(i).replace("~val~", val);
            }
            return "".equals(filter) ? "" : "( " + filter + " )";
        }
        return "";
    }
}
src/main/java/com/product/face/util/FaceUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,128 @@
package com.product.face.util;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.NumberUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.common.lang.StringUtils;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.face.config.FaceConst;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * @Author cheng
 * @Date 2023/5/24 10:42
 * @Desc
 */
public class FaceUtil {
    public static 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));
        }
        result.sort(Comparator.comparing(item -> item.getInteger(FaceConst.CONTROL_SEQUENCE)));
        return result;
    }
    private static 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);
                if (StringUtils.equalsAny(propertyName, "renderKey", "formId")) {
                    propertyValue = fs.getString("id");
                }
                if ("componentType".equals(propertyName) && "design".equals(propertyValue)) {
                    continue;
                }
                if ("layout".equals(propertyName)) {
                    property.put("defaultValue", null);
                }
                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;
    }
}