package com.product.mobile.core.service; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ReflectUtil; 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; import com.product.util.BaseUtil; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.*; /** * @Author cheng * @Date 2024/8/15 10:21 * @Desc */ @Service public class FaceMobileService extends AbstractBaseService { @Resource FlowDetailService flowDetailService; public List getFaceFieldByTable(FieldSetEntity fse) { String tableUuid = fse.getString("table_uuid"); 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"); } } if (StringUtils.isEmpty(tableUuid)) { throw new BaseException(MobileCoreCode.SYSTEM_FORM_COUNT); } FieldSetEntity faceFse = getBaseDao().getFieldSetByFilter("product_sys_face", "table_uuid=?", new Object[]{tableUuid}, true); return getFaceField(faceFse); } public List getFlowFaceField(FieldSetEntity fse) throws BaseException { String flowBusinessForm = flowDetailService.getFlowBusinessForm(fse); JSONObject jsonObject = JSON.parseObject(flowBusinessForm); JSONObject data = jsonObject.getJSONObject("data"); FieldSetEntity faceFse = null; if (data != null && !StringUtils.isEmpty(data.getString("face_number"))) { if (!StringUtils.isEmpty(data.getString("face_number"))) { faceFse = getBaseDao().getFieldSetEntityByFilter("product_sys_face", "face_number=?", new Object[]{data.getString("face_number")}, true); } } else { do { //根据流程获取表名 FieldSetEntity detailFse; if (CmnConst.TABLE_FLOW_TASK.equals(fse.getTableName())) { detailFse = getBaseDao().getFieldSetEntityByFilter(CmnConst.TABLE_FLOW_DETAIL, "task_uuid=? and source_uuid is null", new Object[]{fse.getUUID()}, false); } else { detailFse = getBaseDao().getFieldSetEntity(CmnConst.TABLE_FLOW_DETAIL, fse.getString(CmnConst.FIELD_UUID), false); } if (FieldSetEntity.isEmpty(detailFse)) { break; } //获取表名 String tableName = detailFse.getString("table_name"); FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{tableName}); if (FieldSetEntity.isEmpty(tableInfo)) { break; } String tableUuid = tableInfo.getString("uuid"); faceFse = getBaseDao().getFieldSetByFilter("product_sys_face", "table_uuid=?", new Object[]{tableUuid}, true); } while (false); } return getFaceField(faceFse); } private List getFaceField(FieldSetEntity faceFse) { if (FieldSetEntity.isEmpty(faceFse) || DataTableEntity.isEmpty(faceFse.getSubDataTable("product_sys_face_control_property"))) { throw new BaseException(MobileCoreCode.GET_FACE_CONFIG_FAIL); } DataTableEntity productSysFaceControlProperty = faceFse.getSubDataTable("product_sys_face_control_property"); List tagFieldSetEntityList = new ArrayList<>(); //根据group_uuid 分组 Map> groupMap = new HashMap<>(); Map> 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 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); } if (StringUtils.isEmpty(groupUuid)) { continue; } if (!groupMap.containsKey(groupUuid)) { groupMap.put(groupUuid, new ArrayList<>()); } groupMap.get(groupUuid).add(fieldSetEntity); } if (CollectionUtil.isEmpty(groupMap)) { throw new BaseException(MobileCoreCode.GET_FACE_CONFIG_FAIL); } List result = new ArrayList<>(); List> subTableField = new ArrayList<>(); for (FieldSetEntity fs : tagFieldSetEntityList) { String groupUuid = fs.getString("group_uuid"); String parentUuid = fs.getString("parent_uuid"); if (StringUtils.isEmpty(groupUuid) || StringUtils.isEmpty(parentUuid)) { continue; } List fieldSetEntity = productSysFaceControlProperty.getFieldSetEntity(parentUuid); if (CollectionUtil.isEmpty(fieldSetEntity)) { continue; } to(groupMap, fieldSetEntity, subTableField, result, parentMap); } if (!CollectionUtil.isEmpty(subTableField)) { //根据子表表名装载 Map tableByFaceField = new HashMap<>(); for (List fieldSetEntities : subTableField) { String parentUuid = fieldSetEntities.get(0).getString("parent_uuid"); //先找到children List 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 childrenGroup = groupMap.get(cGroupUuid); List 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 subFieldList = faceFieldEntity.getSubField(); if (CollectionUtil.isEmpty(subFieldList)) { subFieldList = new ArrayList<>(); faceFieldEntity.setSubField(subFieldList); } for (List setEntities : subTableField) { to(groupMap, setEntities, null, subFieldList, parentMap); } if (!tableByFaceField.containsKey(uuid)) { tableByFaceField.put(uuid, faceFieldEntity); result.add(faceFieldEntity); } break; } } return result; } private void to(Map> groupMap, List fieldSetEntity, List> subTableField, List result, Map> parentMap) { FieldSetEntity parent = fieldSetEntity.get(0); String groupUuid1 = parent.getString("group_uuid"); if (StringUtils.isEmpty(groupUuid1)) { return; } List parentGroup = groupMap.get(groupUuid1); FaceFieldEntity faceFieldEntity = new FaceFieldEntity(); String __config__ = null; List other = null; do { for (FieldSetEntity setEntity : parentGroup) { //找到属性名称= __vModel__ String propertyName = setEntity.getString("property_name"); if ("parentType".equals(propertyName) && "subTable".equals(setEntity.getString("property_value")) && subTableField != null) { //子表字段 subTableField.add(parentGroup); result.remove(faceFieldEntity); break; } if ("__vModel__".equals(setEntity.getString("property_name"))) { result.add(faceFieldEntity); propertyName = "fieldName"; } else if ("defaultNow".equals(propertyName)) { propertyName = "defaultValue"; } else if ("__config__".equals(propertyName)) { __config__ = setEntity.getUUID(); } if (!StringUtils.isAnyEmpty(__config__)) { //读取子表属性 if (parentMap != null) { other = parentMap.get(__config__); } } propertyName = StrUtil.toCamelCase(propertyName); if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) { if ("defaultValue".equals(propertyName)) { ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getBoolean("property_value")); } else { ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value")); } } else if (!StringUtils.isEmpty(setEntity.getObject("property_value"))) { //判断是否 faceFieldEntity.putOtherParam(propertyName, setEntity.getObject("property_value")); } } if (StringUtils.isEmpty(faceFieldEntity.getFieldName())) { return; } if (parentGroup == other) { break; } if (other != null) { parentGroup = other; parentMap = null; } } while (other != null); Set configGroup = Sets.newHashSet(groupMap.get(fieldSetEntity.get(0).getString("group_uuid"))); if (other != null) { if (configGroup == null) { configGroup = Sets.newHashSet(other); } else { configGroup.addAll(other); } } parentGroup = groupMap.get(groupUuid1); if (configGroup != null && parentGroup != null) { configGroup.addAll(parentGroup); } for (FieldSetEntity setEntity : configGroup) { //找到属性名称= __vModel__ String propertyName = setEntity.getString("property_name"); 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")); } } } }