许鹏程
2023-05-17 07f6af85516f68ba6943c1e4823fc0be4f851be6
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
package com.product.face.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.admin.service.SystemFaceService;
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.config.ErrorCode;
import com.product.face.config.FaceConst;
import com.product.face.entity.TableColumn;
import com.product.util.BaseUtil;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @Author cheng
 * @Date 2023/5/16 18:36
 * @Desc 表单使用
 */
@Service
public class FaceApplyService extends AbstractBaseService {
 
    @Resource
    private SystemFaceService systemFaceService;
 
    @Resource
    private FaceDesignService designService;
 
 
    public Object getFaceListConf(FieldSetEntity fse) {
        String faceUuid = fse.getString(FaceConst.FIELD_FACE_UUID);
        String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
        if (StringUtils.isEmpty(faceNumber) && StringUtils.isEmpty(faceUuid)) {
            throw new BaseException(ErrorCode.REQUEST_PARAM_ERROR);
 
        }
        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);
        }
 
        return result;
    }
 
    /**
     * 录入表单获取表单配置
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public String getFaceFormConfig(FieldSetEntity fse) throws BaseException {
        String faceNumber = fse.getString(FaceConst.FIELD_FACE_NUMBER);
        if (StringUtils.isEmpty(faceNumber)) {
            throw new BaseException(ErrorCode.REQUEST_PARAM_ERROR);
        }
        //根据表单号查询
        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);
        Map<String, Object> other = new HashMap<>();
        other.put("drawingList", faceControlList);
        faceConf.getSubData().clear();
        return BaseUtil.success(faceConf, other);
    }
 
}