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.product.common.lang.StringUtils; 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.face.util.FaceUtil; import com.product.mobile.core.config.MobileCoreCode; import com.product.mobile.core.entity.FaceFieldEntity; import com.product.tool.flow.config.CmnConst; import com.product.tool.flow.config.FlowCode; 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 getFaceField(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); } 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<>(); for (FieldSetEntity fieldSetEntity : productSysFaceControlProperty.getData()) { String groupUuid = fieldSetEntity.getString("group_uuid"); 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<>(); 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; } FieldSetEntity parent = fieldSetEntity.get(0); String groupUuid1 = parent.getString("group_uuid"); if (StringUtils.isEmpty(groupUuid1)) { continue; } List parentGroup = groupMap.get(groupUuid1); FaceFieldEntity faceFieldEntity = new FaceFieldEntity(); for (FieldSetEntity setEntity : parentGroup) { //找到属性名称= __vModel__ String propertyName = setEntity.getString("property_name"); if ("__vModel__".equals(setEntity.getString("property_name"))) { result.add(faceFieldEntity); propertyName = "fieldName"; } propertyName = StrUtil.toCamelCase(propertyName); if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) { ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value")); } } List configGroup = groupMap.get(groupUuid); for (FieldSetEntity setEntity : configGroup) { //找到属性名称= __vModel__ String propertyName = setEntity.getString("property_name"); if ("tag".equals(propertyName)) { result.add(faceFieldEntity); 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")); } } } return result; } }