|
@@ -0,0 +1,63 @@
|
|
|
|
+package nckd.jimin.jyyy.fi.common.util;
|
|
|
|
+
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import kd.bos.algo.DataSet;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.HashSet;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+public class CommonUtils {
|
|
|
|
+
|
|
|
|
+ public static Set getFiledFromDataSet(DataSet dt , String field){
|
|
|
|
+ DataSet copy = dt.copy();
|
|
|
|
+ Set datas = new HashSet();
|
|
|
|
+ List<String> fileds = Arrays.stream(copy.getRowMeta().getFieldNames()).collect(Collectors.toList());
|
|
|
|
+ while (copy.hasNext()){
|
|
|
|
+ if(fileds.contains(field)){
|
|
|
|
+ datas.add(copy.next().get(field));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static JSONArray transDataSetJson(DataSet dt , String... selectFiled){
|
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
|
+ List<String> fileds = Arrays.stream(dt.getRowMeta().getFieldNames()).collect(Collectors.toList());
|
|
|
|
+ while (dt.hasNext()){
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ for(String field : selectFiled){
|
|
|
|
+ if(fileds.contains(field)){
|
|
|
|
+ obj.put(field,dt.next().get(field));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return jsonArray;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static Set getFieldFormArray(JSONArray jsonArray , String filed){
|
|
|
|
+ Set datas = new HashSet(jsonArray.size());
|
|
|
|
+ for(int i = 0 ; i < jsonArray.size(); i++){
|
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
+ datas.add(jsonObject.get(filed));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return datas;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static DataSet joinDataSetList(List<DataSet> dataSetList){
|
|
|
|
+ DataSet dataSet = null;
|
|
|
|
+ for(DataSet dt : dataSetList){
|
|
|
|
+ if(dataSet == null){
|
|
|
|
+ dataSet = dt;
|
|
|
|
+ }else{
|
|
|
|
+ dataSet = dt.union(dataSet);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return dataSet;
|
|
|
|
+ }
|
|
|
|
+}
|