src/main/java/com/product/face/config/FaceConst.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/entity/FaceEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/entity/FaceListEntity.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/service/FaceApplyService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/service/FaceCacheService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/service/FaceDesignService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/service/FaceListSearchService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/product/face/util/FaceUtil.java | ●●●●● 补丁 | 查看 | 原始文档 | 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; } }