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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<?xml version="1.0" encoding="UTF-8"?>
<!--
$Author: gaoyang
$Date: 2016-5-10 上午10:24:11
$Revision: 1.0
$Purpose:
-->
<a:service xmlns:ns1="leaf.application.action" xmlns:p="uncertain.proc" xmlns:a="http://www.leaf-framework.org/application" xmlns:s="leaf.plugin.script" trace="true">
<a:init-procedure>
<a:model-update model="gps.con_contract_gps_data_check"/>
<s:server-script import="gps/gps.js"><![CDATA[
importPackage(Packages.rd.gps.tokenkey);
importPackage(Packages.java.util);
importPackage(Packages.rd.gps.newveh);
importPackage(Packages.rd.gps.findveh);
importPackage(Packages.rd.gps.newaxbveh);
var getTokenUrl = gps_config.getTokenUrl,
userName = gps_config.userName,
password = gps_config.password;
var bm = $bm('gps.con_contract_add_gps_password');
var bm_result = bm.queryAsMap({
password: password
});
var childs = bm_result.getChildren();
var child = childs[0];
function post_get_name(name) {
var name_arr = {
"NAME": "name",
"STANDNO": "standNo",
"USERTEL": "userTel",
"NOTICEUSER": "noticeUser",
"USERSEX": "userSex",
"COMPANYID": "companyId",
"IDNUM": "idNum",
"ENGINE": "engine",
"DISPLACEMENT": "displacement",
"STROELINKMAN": "stroeLinkman",
"STROETEL": "stroeTel",
"FIXTIME": "fixTime",
"INSTRUCTION": "instruction",
"REMARK": "remark",
"OPERATOR": "operator",
"HOMEADDRESS": "homeAddress",
"WORKADDRESS": "workAddress",
"ORIGINADDRESS": "originAddress",
"GROUPNAME": "groupName",
"GROUPVAL": "groupVal",
"GROUPEMAIL": "groupEmail",
"MANAGERPHONE": "managerPhone",
"MANAGERNAME": "managerName",
"DEVICENUMBER": "deviceNumber",
"TIMESTAMP": "timestamp",
"SIGN": "sign",
"CARDID": "cardId",
"ADDRESS": "address",
"BRANDTYPE": "brandType",
"TYPE": "type",
"USETYPE": "useType",
"CARCOLOUR": "carColour",
"STARTDATE": "startDate",
"ENDDATE": "endDate",
"CARAGE": "carAge",
"SN": "SN"
};
if (name_arr[name]) {
return name_arr[name];
} else {
return name;
}
}
function save_gps_resp(savetype, vehWorId, SN, address, axb_url) {
var saveBm = $bm('gps.con_contract_update_gps_response');
if (axb_url && savetype == 'AXB_GPS') {
$ctx.parameter.axb_url = String(axb_url);
}
saveBm.update({
contract_id: $ctx.parameter.contract_id,
vehworid: vehWorId,
sn: SN,
address: address,
axb_url: axb_url,
savetype: savetype
});
}
function new_axb_gps() {
var infoBm = $bm('gps.con_contract_add_axb_gps_info');
var infoResult = infoBm.queryAsMap({
contract_id: $ctx.parameter.contract_id,
token_key: $ctx.parameter.token_key
});
var infoChilds = infoResult.getChildren();
if (infoChilds.length) {
var infoChild = infoChilds[0];
var axbGpsUrl = gps_config.axbGpsUrl;
var infoMap = new HashMap();
for (var name in infoChild) {
if (post_get_name(name)) {
if (infoChild[name] || infoChild[name] === 0) {
if (infoChild[name] == 'NO_LICENSE_NUMBER') {
infoMap.put(post_get_name(name), null);
} else {
infoMap.put(post_get_name(name), infoChild[name]);
}
} else {
infoMap.put(post_get_name(name), null);
}
}
}
try {
// if (infoChild.AXB_URL) {
// raise_app_error("该GPS工单对应的安心保合同已存在!");
// } else {
var nav = new NewAxbVeh(axbGpsUrl, infoMap, "UTF-8");
var axb_url = nav.run();
save_gps_resp('AXB_GPS', null, null, null, String(axb_url));
// }
} catch (e) {
raise_app_error("新增安心保合同工单失败:" + e);
}
} else {
raise_app_error("未获取到安心保对应的合同工单信息");
}
}
function new_con_gps() {
var infoBm = $bm('gps.con_contract_add_gps_info');
var infoResult = infoBm.queryAsMap({
contract_id: $ctx.parameter.contract_id,
token_key: $ctx.parameter.token_key
});
var infoChilds = infoResult.getChildren();
if (infoChilds.length) {
var infoChild = infoChilds[0];
var newGpsUrl = gps_config.newGpsUrl;
var infoMap = new HashMap();
for (var name in infoChild) {
if (post_get_name(name)) {
if (infoChild[name] || infoChild[name] === 0) {
infoMap.put(post_get_name(name), infoChild[name]);
} else {
infoMap.put(post_get_name(name), null);
}
}
}
try {
if (!infoChild.SN) {
var nv = new NewVeh(newGpsUrl, infoMap, "UTF-8");
var vehWorId = nv.run();
save_gps_resp('NEW_GPS', vehWorId);
}
} catch (e) {
raise_app_error("新增工单失败:" + e);
}
} else {
raise_app_error("未获取到对应的合同工单信息");
}
}
function find_con_gps(type) {
var infoBm = $bm('gps.con_contract_find_gps_info');
var infoResult = infoBm.queryAsMap({
contract_id: $ctx.parameter.contract_id,
token_key: $ctx.parameter.token_key
});
var infoChilds = infoResult.getChildren();
if (infoChilds.length) {
var infoChild = infoChilds[0];
var findGpsUrl = gps_config.findGpsUrl;
var infoMap = new HashMap();
for (var name in infoChild) {
if (post_get_name(name)) {
if (infoChild[name] || infoChild[name] === 0) {
infoMap.put(post_get_name(name), infoChild[name]);
} else {
infoMap.put(post_get_name(name), null);
}
}
}
try {
var fv = new FindVeh(findGpsUrl, infoMap, "UTF-8");
var arr = fv.run();
var SN = arr[0],
address = arr[1];
var error_message = null;
if (type == 'FIND' && !SN) {
error_message = "该工单尚未激活";
raise_app_error(message);
}
if (infoChild.SN) {
save_gps_resp('FIND_GPS', null, SN, address);
return true;
} else {
if (SN) {
save_gps_resp('FIND_GPS', null, SN, address);
return true;
} else {
return false;
}
}
} catch (e) {
var message = null;
if (error_message) {
message = error_message;
} else {
message = "查找工单失败:" + e;
}
raise_app_error(message);
}
} else {
raise_app_error("未获取到对应的合同工单信息");
}
}
try {
var tokenKeyObj = new GetTokenKey(getTokenUrl, userName, child.PASSWORD, "UTF-8");
var token_key = tokenKeyObj.run();
$ctx.parameter.token_key = token_key;
} catch (e) {
raise_app_error("获取tokenKey失败:" + e);
}
var gps_type = $ctx.parameter.gps_type;
if (gps_type == 'NEW_GPS') {
var flag = find_con_gps("NEW");
if (!flag) {
new_con_gps();
}
} else if (gps_type == 'FIND_GPS') {
find_con_gps("FIND");
} else if (gps_type == 'AXB_GPS') {
var flag = find_con_gps();
if (flag) {
new_axb_gps("AXB");
} else {
raise_app_error("该GPS设备尚未激活!");
}
}
]]></s:server-script>
</a:init-procedure>
<a:service-output output="/parameter"/>
</a:service>