first commit
This commit is contained in:
42
src/main/java/com/example/sso/util/DataBatchUtil.java
Normal file
42
src/main/java/com/example/sso/util/DataBatchUtil.java
Normal file
@ -0,0 +1,42 @@
|
||||
package com.example.sso.util;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class DataBatchUtil {
|
||||
/**
|
||||
* 批量新增数据
|
||||
* @param appId 应用ID
|
||||
* @param entryId 表单ID
|
||||
* @param apiKey 秘钥
|
||||
* @param datas 原始数据源
|
||||
* @param fields 简道云字段别名
|
||||
* @param fields_data data里面的字段值key,需要与fields一一对应起来。
|
||||
*/
|
||||
public static Map<String, String> dataBatchCreate(String appId, String entryId, String apiKey, JSONArray datas, JSONArray fields, JSONArray fields_data){
|
||||
try {
|
||||
APIUtils apiUtils=new APIUtils(appId,entryId,apiKey);
|
||||
JSONArray data_list=new JSONArray();//封装修饰好的数据
|
||||
for (Object o1:datas){
|
||||
JSONObject o=(JSONObject)o1;
|
||||
Map<String,Object> map1=new HashMap<String,Object>(){
|
||||
{
|
||||
for (int i=0;i<fields.size();i++){
|
||||
int finalI = i;
|
||||
put(fields.getString(i),new HashMap<String, Object>() {{ put("value",o.get(fields_data.getString(finalI)));}});
|
||||
}
|
||||
}
|
||||
};
|
||||
data_list.add(map1);
|
||||
}
|
||||
return apiUtils.dataBatchCreate(data_list,false);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user