---
title: "4.2.4.3、表单数据导入：FormDataImportAPIService"
docId: "954968248724660224"
source: "https://weapp.eteams.cn/build/techdoc/wdoc/index.html#/public/repository/9c2e5f92-03b4-4207-9b22-a0c1dd79ac56/doc/954968248724660224"
---
> 所属包：weaver-common-form-extend
> 
> 所属类：com.weaver.common.form.formapi.FormDataImportAPIService

#### 1 根据formId获取可导入自定义字段集合

**方法名：**

```java
/**
 * @Description: 根据formId获取可导入自定义字段集合
 * @param entity 数据导入实体类
 * @param employee 用户信息（必须包含id和tenantKey）
 * @return List<EditableComponent> 可以导入的字段集合
 */
List<EditableComponent> listImportComponentByFormId(FormDataImportEntity entity, SimpleEmployee employee);
```

**参数：**

> FormDataImportEntity 中相关属性

| 参数名 | 必传 | 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- | --- | --- |
| formId | 是 | Long | java.lang.Long | 表单Id |
| splitStr | 否 | String | java.lang.String | 导入设置-自定义分隔符（默认","） |
| required | 否 | boolean | java.lang.boolean | 导入设置-是否进行必填值校验（默认false） |

**返回值：**

| 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- |
| `List<EditableComponent>` | java.util.List / com.weaver.common.form.component.base.EditableComponent | 可导入的自定义字段集合 |

**对接示例：**

```java
FormDataImportEntity entity=new FormDataImportEntity();
entity.setFormId(formId);
entity.setSplitStr(splitStr);
entity.setRequired(isRequired);

formDataImportAPIService.listImportComponentByFormId(entity, employee);
```

**出参示例：**

```json
[
    {
        "componentKey":"Text",
        "order":0,
        "index":0,
        "isMust":false,
        "title":"文本输入框",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":false,
        "fieldId":"7833515199587891125",
        "tempId":"7833515199587891125",
        "subFormId":"",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "size":"medium",
        "maxlen":200,
        "regular":{

        }
    },
    {
        "componentKey":"NumberComponent",
        "order":1,
        "index":0,
        "isMust":false,
        "title":"数字输入框",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":false,
        "fieldId":"7833515199587891126",
        "tempId":"7833515199587891126",
        "subFormId":"",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "size":"medium",
        "numberType":"number",
        "minNum":"",
        "maxNum":"",
        "pointSize":""
    },
    {
        "componentKey":"Task",
        "order":2,
        "index":0,
        "isMust":false,
        "title":"关联任务",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":false,
        "fieldId":"7833515199587891127",
        "tempId":"7833515199587891127",
        "subFormId":"",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "isUnique":false
    },
    {
        "componentKey":"Mainline",
        "order":3,
        "index":0,
        "isMust":false,
        "title":"关联项目",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":false,
        "fieldId":"7833515222826390703",
        "tempId":"7833515222826390703",
        "subFormId":"",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "isUnique":false
    },
    {
        "componentKey":"Text",
        "order":0,
        "index":0,
        "isMust":false,
        "title":"文本输入框-dtb",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":true,
        "fieldId":"7833515201632491130",
        "tempId":"7833515201632491130",
        "subFormId":"7833515199587891129",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "size":"medium",
        "maxlen":200,
        "regular":{

        }
    },
    {
        "componentKey":"Money",
        "order":1,
        "index":0,
        "isMust":false,
        "title":"金额-dtb",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":true,
        "fieldId":"7833515201632491131",
        "tempId":"7833515201632491131",
        "subFormId":"7833515199587891129",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "size":"medium",
        "type":"人民币",
        "minNum":"",
        "maxNum":"",
        "pointSize":""
    },
    {
        "componentKey":"AgendaComponent",
        "order":2,
        "index":0,
        "isMust":false,
        "title":"关联日程-dtb",
        "titleLayout":"field-hoz",
        "describe":"",
        "required":true,
        "fieldId":"7833515222826490704",
        "tempId":"7833515222826490704",
        "subFormId":"7833515199587891129",
        "unique":false,
        "isReadOnly":false,
        "isDefault":false,
        "templateId":"",
        "splitStr":",",
        "express":{

        },
        "componentLevel":1,
        "isSingle":false,
        "isUnique":false,
        "showfields":[

        ],
        "newSortColumn":[

        ],
        "selectColumn":[

        ]
    }
]
```

#### 2 自定义字段校验（格式校验、必填校验）

**方法名：**

```java
/**
 * @Description: 自定义字段校验（格式校验、必填校验）
 * @param entity 数据导入实体类
 * @param employee 用户信息（必须包含id和tenantKey）
 * @return List<FormDataImportCheckEntity> 校验不通过数据信息集合
 */
List<FormDataImportCheckEntity> checkImportRowData(FormDataImportEntity entity, SimpleEmployee employee);
```

**参数：**

> FormDataImportEntity 中相关属性

| 参数名 | 必传 | 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- | --- | --- |
| formId | 是 | Long | java.lang.Long | 表单Id |
| splitStr | 否 | String | java.lang.String | 导入设置-自定义分隔符（默认","） |
| groupRowDataList | 是 | `List<List<Map<String, String>>>` | java.util.List / java.util.Map | 解析Excel文件后，获取的自定义字段数据集合 |
| components | 是 | `List<EditableComponent>` | java.util.List / com.weaver.common.form.component.base.EditableComponent | 可导入的自定义字段集合 |

**groupRowDataList 说明：**

> List<Map<String, String>>
> 
> - 仅包含主表数据：List中只有1条数据
> - 包含明细表数据：List中有多条数据
> - 老ET中解析Excel表格时，根据是否有【标题】判断一组数据
> - Map<String, String> : key - 字段Id; value - 字段内容
> 
> 如果单元格未填写内容，也需要封装到Map中（"fieldId": ""）

**返回值：**

| 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- |
| `List<FormDataImportCheckEntity>` | java.util.List / com.weaver.common.form.formdataimport.FormDataImportCheckEntity | 表单数据校验信息集合 |

**对接示例：**

```java
FormDataImportEntity entity=new FormDataImportEntity();
entity.setFormId(formId);
entity.setSplitStr(splitStr);
entity.setGroupRowDataList(groupRowDataList);
entity.setComponents(components);

List<FormDataImportCheckEntity> checkEntityList = formDataImportAPIService.checkImportRowData(entity, employee);
```

**Demo表单说明：**

| 字段名称 | 字段Id(fieldId) | 是否在明细表中 | 是否必填 |
| --- | --- | --- | --- |
| 文本输入框 | 7833515199587891125 | 否 | 否 |
| 数字输入框 | 7833515199587891126 | 否 | 否 |
| 关联任务 | 7833515199587891127 | 否 | 否 |
| 关联项目 | 7833515222826390703 | 否 | 否 |
| 文本输入框-dtb | 7833515201632491130 | 是 | 是 |
| 金额-dtb | 7833515201632491131 | 是 | 是 |
| 关联日程-dtb | 7833515222826490704 | 是 | 是 |

**入参示例：**

```json
{
    "formId":7833515198283026783,
    "splitStr":",",
    "groupRowDataList":[
        [
            {
                "7833515199587891125":"主表",
                "7833515199587891126":"1AVADASADE",
                "7833515199587891127":"E10-0001",
                "7833515201632491130":"明细表1",
                "7833515201632491131":"11.00AAAAA",
                "7833515222826490704":"E10-0720"
            },
            {
                "7833515201632491130":"明细表2",
                "7833515201632491131":"22.00AAAA",
                "7833515222826490704":"本版本11111"
            },
            {
                "7833515201632491130":"",
                "7833515201632491131":"33.00",
                "7833515222826490704":"啊啊啊"
            }
        ]
    ],
    "components":[
        {
            "componentKey":"Text",
            "order":0,
            "index":0,
            "isMust":false,
            "title":"文本输入框",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891125",
            "tempId":"7833515199587891125",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "maxlen":200,
            "regular":{

            }
        },
        {
            "componentKey":"NumberComponent",
            "order":1,
            "index":0,
            "isMust":false,
            "title":"数字输入框",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891126",
            "tempId":"7833515199587891126",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "numberType":"number",
            "minNum":"",
            "maxNum":"",
            "pointSize":""
        },
        {
            "componentKey":"Task",
            "order":2,
            "index":0,
            "isMust":false,
            "title":"关联任务",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891127",
            "tempId":"7833515199587891127",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false
        },
        {
            "componentKey":"Mainline",
            "order":3,
            "index":0,
            "isMust":false,
            "title":"关联项目",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515222826390703",
            "tempId":"7833515222826390703",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false
        },
        {
            "componentKey":"Text",
            "order":0,
            "index":0,
            "isMust":false,
            "title":"文本输入框-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515201632491130",
            "tempId":"7833515201632491130",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "maxlen":200,
            "regular":{

            }
        },
        {
            "componentKey":"Money",
            "order":1,
            "index":0,
            "isMust":false,
            "title":"金额-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515201632491131",
            "tempId":"7833515201632491131",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "type":"人民币",
            "minNum":"",
            "maxNum":"",
            "pointSize":""
        },
        {
            "componentKey":"AgendaComponent",
            "order":2,
            "index":0,
            "isMust":false,
            "title":"关联日程-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515222826490704",
            "tempId":"7833515222826490704",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false,
            "showfields":[

            ],
            "newSortColumn":[

            ],
            "selectColumn":[

            ]
        }
    ]
}
```

**出参示例：**

```json
[
    {
        "index":0,
        "subFormIndex":0,
        "fieldId":7833515199587891126,
        "message":"此项格式不正确"
    },
    {
        "index":0,
        "subFormIndex":0,
        "fieldId":7833515201632491131,
        "message":"此项格式不正确"
    },
    {
        "index":0,
        "subFormIndex":1,
        "fieldId":7833515201632491131,
        "message":"此项格式不正确"
    },
    {
        "index":0,
        "subFormIndex":1,
        "fieldId":7833515222826490704,
        "message":"此项数据不存在"
    },
    {
        "index":0,
        "subFormIndex":2,
        "fieldId":7833515201632491130,
        "message":"此项不能为空"
    },
    {
        "index":0,
        "subFormIndex":2,
        "fieldId":7833515222826490704,
        "message":"此项数据不存在"
    }
]
```

#### 3 自定义字段数据保存

**方法名：**

```java
/**
 * @Description: 自定义字段数据保存
 * @param entity 数据导入实体类
 * @param employee 用户信息（必须包含id和tenantKey）
 * @return List<Long> 返回导入成功的formdata id集合
 */
List<Long> saveImportRowData(FormDataImportEntity entity, SimpleEmployee employee);
```

**参数：**

> FormDataImportEntity 中相关属性

| 参数名 | 必传 | 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- | --- | --- |
| module | 是 | ModuleSource | com.weaver.common.form.metadata.ModuleSource | 模块标识符 |
| formId | 是 | Long | java.lang.Long | 表单Id |
| splitStr | 否 | String | java.lang.String | 导入设置-自定义分隔符（默认","） |
| groupRowDataList | 是 | `List<List<Map<String, String>>>` | java.util.List / java.util.Map | 解析Excel文件后，获取的自定义字段数据集合 |
| components | 是 | `List<EditableComponent>` | java.util.List / com.weaver.common.form.component.base.EditableComponent | 可导入的自定义字段集合 |
| ip | 是 | String | java.lang.String | 当前用户Ip |

**返回值：**

| 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- |
| `List<Long>` | java.util.List / java.lang.Long | 导入成功数据formdata id集合 |

**对接示例：**

```java
FormDataImportEntity entity=new FormDataImportEntity();
entity.setModule(module);
entity.setFormId(formId);
entity.setSplitStr(splitStr);
entity.setGroupRowDataList(groupRowDataList);
entity.setComponents(components);
entity.setIp(ip);

formDataImportAPIService.saveImportRowData(entity, employee);
```

**入参示例：**

```json
{
    "module":"formdatareport",
    "formId":7833515198283026783,
    "splitStr":",",
    "groupRowDataList":[
        [
            {
                "7833515199587891125":"主表",
                "7833515199587891126":"1",
                "7833515199587891127":"E10-0001",
                "7833515222826390703":"",
                "7833515201632491130":"明细表1",
                "7833515201632491131":"11.00",
                "7833515222826490704":"E10-0720"
            },
            {
                "7833515201632491130":"明细表2",
                "7833515201632491131":"22.00",
                "7833515222826490704":""
            },
            {
                "7833515201632491130":"明细表3",
                "7833515201632491131":"33.00",
                "7833515222826490704":""
            }
        ]
    ],
    "components":[
        {
            "componentKey":"Text",
            "order":0,
            "index":0,
            "isMust":false,
            "title":"文本输入框",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891125",
            "tempId":"7833515199587891125",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "maxlen":200,
            "regular":{

            }
        },
        {
            "componentKey":"NumberComponent",
            "order":1,
            "index":0,
            "isMust":false,
            "title":"数字输入框",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891126",
            "tempId":"7833515199587891126",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "numberType":"number",
            "minNum":"",
            "maxNum":"",
            "pointSize":""
        },
        {
            "componentKey":"Task",
            "order":2,
            "index":0,
            "isMust":false,
            "title":"关联任务",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515199587891127",
            "tempId":"7833515199587891127",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false
        },
        {
            "componentKey":"Mainline",
            "order":3,
            "index":0,
            "isMust":false,
            "title":"关联项目",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":false,
            "fieldId":"7833515222826390703",
            "tempId":"7833515222826390703",
            "subFormId":"",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false
        },
        {
            "componentKey":"Text",
            "order":0,
            "index":0,
            "isMust":false,
            "title":"文本输入框-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515201632491130",
            "tempId":"7833515201632491130",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "maxlen":200,
            "regular":{

            }
        },
        {
            "componentKey":"Money",
            "order":1,
            "index":0,
            "isMust":false,
            "title":"金额-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515201632491131",
            "tempId":"7833515201632491131",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "size":"medium",
            "type":"人民币",
            "minNum":"",
            "maxNum":"",
            "pointSize":""
        },
        {
            "componentKey":"AgendaComponent",
            "order":2,
            "index":0,
            "isMust":false,
            "title":"关联日程-dtb",
            "titleLayout":"field-hoz",
            "describe":"",
            "required":true,
            "fieldId":"7833515222826490704",
            "tempId":"7833515222826490704",
            "subFormId":"7833515199587891129",
            "unique":false,
            "isReadOnly":false,
            "isDefault":false,
            "templateId":"",
            "splitStr":",",
            "express":{

            },
            "componentLevel":1,
            "isSingle":false,
            "isUnique":false,
            "showfields":[

            ],
            "newSortColumn":[

            ],
            "selectColumn":[

            ]
        }
    ],
    "ip":"222.64.108.113"
}
```

#### 4 是否单选校验

**方法名：**

```java
/**
 * @Description: 判断是否是单选
 * @param componentKey 需要进行判断组件的componentKey
 * @return 返回校验结果
 */
boolean checkSingleSelect(String componentKey);
```

**参数：**

| 参数名 | 必传 | 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- | --- | --- |
| componentKey | 是 | String | java.lang.String | 组件componentKey |

**返回值：**

| 类型 | 类型所属包路径 | 描述 |
| --- | --- | --- |
| `boolean` | java.lang.boolean | 校验结果 |
