-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path042d7f0e4dcf4d5eb5278acb45ce6c7e_peg9tmty.js
78 lines (78 loc) · 3.12 KB
/
042d7f0e4dcf4d5eb5278acb45ce6c7e_peg9tmty.js
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
let AbstractAPIHandler = require("AbstractAPIHandler");
class MyAPIHandler extends AbstractAPIHandler {
execute(request) {
if (
request.enterprise.收货客户编号 == null ||
request.enterprise.收货客户名称 == null ||
request.enterprise["经营许可证/备案凭证号"] == null ||
request.enterprise["许可证/备案凭证效期至"] == null
) {
return { err: "有必填项为空,需要维护后再进行导入" };
}
var BuyersCode = "" + request.enterprise.收货客户编号;
var BuyersName = "" + request.enterprise.收货客户名称;
var LicenseOperation = "" + request.enterprise["经营许可证/备案凭证号"];
var LicenseValidity = request.enterprise["许可证/备案凭证效期至"];
if (LicenseValidity != "/") {
//判断获取的日期是什么类型是number的话就处理日期
var hasNumber = typeof LicenseValidity;
if (hasNumber == "number") {
var format = "-";
let time = new Date((LicenseValidity - 25567) * 24 * 3600000 - 5 * 60 * 1000 - 43 * 1000 - 24 * 3600000 - 8 * 3600000);
let year = time.getFullYear() + "";
let month = time.getMonth() + 1 + "";
let date = time.getDate() + "";
const hours = time.getHours().toLocaleString();
const minutes = time.getMinutes();
if (format && format.length === 1) {
LicenseValidity = year + format + month + format + date + " " + hours + ":" + minutes;
}
LicenseValidity = year + format + (month < 10 ? "0" + month : month) + format + (date < 10 ? "0" + date : date);
var IsEarlywarning = 1;
if (time < new Date().getTime()) {
IsEarlywarning = 2;
}
}
} else {
LicenseValidity = "";
}
var enterpriseSql = "select * from AT161E5DFA09D00001.AT161E5DFA09D00001.Buyers where BuyersCode = '" + BuyersCode + "'";
var enterpriseRes = ObjectStore.queryByYonQL(enterpriseSql, "developplatform");
if (enterpriseRes.length == 0) {
//新增
var insertTable = {
BuyersCode: "" + BuyersCode,
BuyersName: "" + BuyersName,
LicenseOperation: LicenseOperation,
LicenseValidity: LicenseValidity,
enable: 0,
IsEarlywarning: IsEarlywarning
};
var insertTableRes = ObjectStore.insert("AT161E5DFA09D00001.AT161E5DFA09D00001.Buyers", insertTable, "31ae1c7b");
if (insertTableRes != null) {
return { type: "add" };
} else {
return { insertTableRes };
}
} else {
//修改
var updateTable = {
id: enterpriseRes[0].id,
BuyersCode: "" + BuyersCode,
BuyersName: "" + BuyersName,
LicenseOperation: LicenseOperation,
LicenseValidity: LicenseValidity,
enable: 0,
IsEarlywarning: IsEarlywarning
};
var updateTableRes = ObjectStore.updateById("AT161E5DFA09D00001.AT161E5DFA09D00001.Buyers", updateTable, "31ae1c7b");
if (updateTableRes != null) {
return { type: "change" };
} else {
return { updateTableRes };
}
}
return { request };
}
}
exports({ entryPoint: MyAPIHandler });