cheng
2024-08-25 96c2e1b2442fa35b2a819e6c7e4ee524651828b2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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.mobile.core.config.MobileCoreCode;
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<FaceFieldEntity> getFaceFieldByTable(FieldSetEntity fse) {
        String tableUuid = fse.getString("table_uuid");
        if (StringUtils.isEmpty(tableUuid)) {
            FieldSetEntity tableInfo = BaseUtil.getSingleInfoByCache("所有表信息", new String[]{fse.getString("table_name")});
            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<FaceFieldEntity> 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<FaceFieldEntity> 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<FieldSetEntity> tagFieldSetEntityList = new ArrayList<>();
        //根据group_uuid 分组
        Map<String, List<FieldSetEntity>> 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<FaceFieldEntity> 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> 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<FieldSetEntity> 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";
                }else if ("defaultNow".equals(propertyName)){
                    propertyName="defaultValue";
                }
                propertyName = StrUtil.toCamelCase(propertyName);
                if (ReflectUtil.hasField(FaceFieldEntity.class, propertyName)) {
                    if ("defaultValue".equals(propertyName)) {
                        ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getBoolean("property_value"));
                        continue;
                    } else {
                        ReflectUtil.setFieldValue(faceFieldEntity, propertyName, setEntity.getObject("property_value"));
                    }
 
                }
            }
            if (StringUtils.isEmpty(faceFieldEntity.getFieldName())) {
                result.remove(faceFieldEntity);
                continue;
            }
            List<FieldSetEntity> configGroup = groupMap.get(groupUuid);
            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"));
                }
            }
 
        }
        return result;
    }
 
}