ExtK3CloudApi.java
4.93 KB
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
package com.huaheng.api.erp;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.utils.bean.BeanUtils;
import com.kingdee.bos.webapi.sdk.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* 新增处理erp数据字段 方法
*/
public class ExtK3CloudApi extends K3CloudApi {
/**
* 下推表单
* @param param
* @return
* @throws Exception
*/
public OperatorResult pushOperator(String formId,String type,ExtOperateParam param) throws Exception {
return (OperatorResult)this.execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExcuteOperation", new Object[]{formId,type, param.toJson()}, OperatorResult.class);
}
Method[] getMethodsByFields(Method[] pes, String pre, String[] fields) {
Method[] rets = new Method[fields.length];
for(int i = 0; i < fields.length; ++i) {
for(int j = 0; j < pes.length; ++j) {
if (pes[j].getName().toLowerCase().equals(pre + fields[i].toLowerCase())) {
rets[i] = pes[j];
}
}
}
return rets;
}
Object convertToDest(Type type, Object val) {
if (val == null) {
return null;
} else if (type.getTypeName().equals(String.class.getTypeName())) {
return val.toString();
} else if (!type.getTypeName().equals(Integer.TYPE.getTypeName()) && !type.getTypeName().equals(Short.TYPE.getTypeName()) && !type.getTypeName().equals(Long.TYPE.getTypeName())) {
if (type.getTypeName().equals(BigDecimal.class.getTypeName())) {
return new BigDecimal(val.toString());
} else if (type.getTypeName().equals(Date.class.getTypeName())) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
try {
return sdf.parse(val.toString());
} catch (ParseException var5) {
var5.printStackTrace();
return null;
}
} else {
return val;
}
} else {
String v = val.toString();
if (v.toString().indexOf(".") > -1) {
v = v.substring(0, v.toString().indexOf("."));
}
return new Integer(v.toString());
}
}
@Override
public <T> SaveResult save(String formId, SaveParam<T> param, InvokeMode mode) throws Exception {
return super.save(formId, param, mode);
}
@Override
protected <T> List<T> loadDataList(String fieldKeys, Class type, String json) throws InstantiationException, IllegalAccessException, InvocationTargetException {
List<T> rets = new ArrayList();
Gson gson = new Gson();
List rows = JSON.parseObject(json, rets.getClass());
// List<ArrayList<Object>> rows = (List)gson.fromJson(json, rets.getClass());
Method[] pes = type.getMethods();
String[] fields = fieldKeys.split(",");
for (int i = 0; i < fields.length; i++) {
String field = fields[i];
/* 去掉最后一个 _ 前面的字符 */
field = BeanUtils.cutBeforeStr(field, "_");
/* 去掉F */
field = BeanUtils.cutHeader(field);
//这里是发货通知单 辅助属性 格式加的验证
//FAuxpropID.FF100001.FNumber 等级
String str = field;
int first = str.indexOf(".");
if(first!=-1){
str = str.substring(0,first);
str = str.toUpperCase();
if("AUXPROPID".equals(str)){
int last = field.lastIndexOf(".");
field = field.substring(first+1,last);
/* 去掉F */
field = BeanUtils.cutHeader(field);
}
}
/* 去掉.后面的字符*/
fields[i] = BeanUtils.convertToFormat(field);
}
Method[] setPes = this.getMethodsByFields(pes, "set", fields);
Method[] getPes = this.getMethodsByFields(pes, "get", fields);
Iterator var12 = rows.iterator();
while(var12.hasNext()) {
List<Object> darray = (List)var12.next();
T ret = (T) type.newInstance();
for(int i = 0; i < fields.length; ++i) {
if (setPes[i] != null && getPes[i] != null) {
Object v = this.convertToDest(getPes[i].getReturnType(), darray.get(i));
if (v != null) {
setPes[i].invoke(ret, v);
}
}
}
rets.add(ret);
}
return rets;
}
}