Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
9cf1636a
Commit
9cf1636a
authored
Oct 20, 2020
by
Sxy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 代码规范
parent
e9c9dddf
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
415 additions
and
437 deletions
+415
-437
icp-deliver/app/base/api/impl/meta/oss.js
+1
-1
icp-deliver/app/base/controller/impl/common/uploadCtl.js
+5
-3
icp-deliver/app/base/db/cache/CacheLocker.js
+0
-22
icp-deliver/app/base/db/cache/vcodeCache.js
+1
-3
icp-deliver/app/base/db/dao.base.js
+15
-6
icp-deliver/app/base/db/impl/auth/roleDao.js
+2
-2
icp-deliver/app/base/service/impl/auth/orgSve.js
+1
-1
icp-deliver/app/base/system.js
+356
-356
icp-deliver/app/base/utils/redisClient.js
+2
-1
icp-deliver/app/base/utils/restClient.js
+25
-31
icp-deliver/dochelp/imghandle.js
+6
-10
icp-deliver/main.js
+1
-1
No files found.
icp-deliver/app/base/api/impl/meta/oss.js
View file @
9cf1636a
...
...
@@ -42,7 +42,7 @@ class OSSAPI extends APIBase {
}
async
downfile
(
srckey
)
{
const
oss
=
System
.
getObject
(
'util.ossClient'
);
le
t
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
cons
t
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
return
`/tmp/
${
srckey
}
`
;
});
return
downfile
;
...
...
icp-deliver/app/base/controller/impl/common/uploadCtl.js
View file @
9cf1636a
...
...
@@ -46,7 +46,8 @@ class UploadCtl extends CtlBase {
}
async
downfile
(
srckey
)
{
const
oss
=
system
.
getObject
(
'util.ossClient'
);
var
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
let
downfile
;
downfile
=
await
oss
.
downfile
(
srckey
).
then
(()
=>
{
downfile
=
`/tmp/
${
srckey
}
`
;
return
downfile
;
});
...
...
@@ -64,8 +65,9 @@ class UploadCtl extends CtlBase {
return
result
.
url
;
}
async
insertToFile
(
path
)
{
const
cmd
=
`
${
this
.
cmdInsertToFilePattern
}
${
path
}
`
;
return
await
this
.
restS
.
exec
(
cmd
);
const
cmd
=
`
${
this
.
cmdInsertToFilePattern
}${
path
}
`
;
const
result
=
await
this
.
restS
.
exec
(
cmd
);
return
result
;
}
}
module
.
exports
=
UploadCtl
;
icp-deliver/app/base/db/cache/CacheLocker.js
deleted
100644 → 0
View file @
e9c9dddf
const
CacheBase
=
require
(
'../cache.base'
);
const
system
=
require
(
'../../system'
);
// 缓存首次登录的赠送的宝币数量
class
CacheLocker
extends
CacheBase
{
constructor
()
{
super
();
this
.
prefix
=
'locker_'
;
}
async
init
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpushWithEx
(
key
,
'1'
,
1800
);
}
async
enter
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpop
(
key
);
}
async
release
(
tradekey
)
{
const
key
=
this
.
prefix
+
tradekey
;
return
this
.
redisClient
.
rpushWithEx
(
key
,
'1'
,
1800
);
}
}
module
.
exports
=
CacheLocker
;
icp-deliver/app/base/db/cache/vcodeCache.js
View file @
9cf1636a
...
...
@@ -24,9 +24,7 @@ class VCodeCache extends CacheBase {
const
vcode
=
await
this
.
smsUtil
.
getUidStr
(
6
,
10
);
if
(
!
tmplCode
&&
!
signName
)
{
this
.
smsUtil
.
sendMsg
(
mobile
,
vcode
);
}
// tmplCode为发送短信编码,需在阿里开通,signName为短信头描述信息,二者没有传递则用默认的发送验证码
else
{
}
else
{
this
.
smsUtil
.
aliSendMsg
(
mobile
,
tmplCode
,
signName
,
JSON
.
stringify
({
code
:
vcode
}));
}
return
JSON
.
stringify
({
vcode
});
...
...
icp-deliver/app/base/db/dao.base.js
View file @
9cf1636a
...
...
@@ -48,9 +48,13 @@ class Dao {
const
en
=
null
;
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
whereParam
.
transaction
=
t
;
return
await
this
.
model
.
destroy
(
whereParam
);
const
result
=
await
this
.
model
.
destroy
(
whereParam
);
return
result
}
return
await
this
.
model
.
destroy
(
whereParam
);
const
result
=
await
this
.
model
.
destroy
(
whereParam
);
return
result
}
async
delete
(
qobj
,
t
)
{
let
en
=
null
;
...
...
@@ -177,9 +181,12 @@ class Dao {
}
async
bulkCreate
(
ids
,
t
)
{
if
(
t
!=
null
&&
t
!=
'undefined'
)
{
return
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
const
result
=
await
this
.
model
.
bulkCreate
(
ids
,
{
transaction
:
t
});
return
result
;
}
return
await
this
.
model
.
bulkCreate
(
ids
);
const
result
=
await
this
.
model
.
bulkCreate
(
ids
);
return
result
;
}
async
updateByWhere
(
setObj
,
whereObj
,
t
)
{
...
...
@@ -200,7 +207,7 @@ class Dao {
return
this
.
db
.
query
(
sql
,
paras
);
}
async
customQuery
(
sql
,
paras
,
t
)
{
let
tmpParas
=
null
;
// ||paras=='undefined'?{type: this.db.QueryTypes.SELECT }:{ replacements: paras, type: this.db.QueryTypes.SELECT };
let
tmpParas
=
null
;
if
(
t
&&
t
!=
'undefined'
)
{
if
(
paras
==
null
||
paras
==
'undefined'
)
{
tmpParas
=
{
type
:
this
.
db
.
QueryTypes
.
SELECT
};
...
...
@@ -239,7 +246,9 @@ class Dao {
}
else
{
tmpWhere
.
raw
=
true
;
}
return
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
const
result
=
await
this
.
model
.
findAndCountAll
(
tmpWhere
);
return
result
;
}
async
findOne
(
obj
,
attributes
=
[])
{
if
(
attributes
.
length
>
0
)
{
...
...
icp-deliver/app/base/db/impl/auth/roleDao.js
View file @
9cf1636a
...
...
@@ -38,10 +38,10 @@ class RoleDao extends Dao {
const
self
=
this
;
const
u2
=
await
this
.
preCreate
(
u
);
if
(
t
)
{
le
t
role
=
await
this
.
model
.
create
(
u2
,
{
transaction
:
t
});
cons
t
role
=
await
this
.
model
.
create
(
u2
,
{
transaction
:
t
});
return
role
;
}
else
{
le
t
role
=
await
this
.
model
.
create
(
u2
);
cons
t
role
=
await
this
.
model
.
create
(
u2
);
return
role
;
}
}
...
...
icp-deliver/app/base/service/impl/auth/orgSve.js
View file @
9cf1636a
...
...
@@ -55,7 +55,7 @@ class OrgService extends ServiceBase {
const
roles
=
await
self
.
db
.
models
.
role
.
findAll
({
where
:
{
id
:
{
[
self
.
db
.
Op
.
in
]:
p
.
Roles
}
}
});
await
orgupdate
.
setRoles
(
roles
,
{
transaction
:
t
});
// 同时要给这个岗位下的user,更新角色 todo
for
(
le
t
ud
of
usersupdate
)
{
for
(
cons
t
ud
of
usersupdate
)
{
await
ud
.
setRoles
(
roles
,
{
transaction
:
t
});
}
}
...
...
icp-deliver/app/base/system.js
View file @
9cf1636a
...
...
@@ -5,346 +5,346 @@ const request = require('request');
const
cryptoJS
=
require
(
'crypto-js'
);
class
System
{
static
declare
(
ns
)
{
const
ar
=
ns
.
split
(
'.'
);
let
root
=
System
;
for
(
let
i
=
0
,
len
=
ar
.
length
;
i
<
len
;
++
i
)
{
const
n
=
ar
[
i
];
if
(
!
root
[
n
])
{
root
[
n
]
=
{};
root
=
root
[
n
];
}
else
{
root
=
root
[
n
];
}
}
}
static
async
delReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
del
({
url
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
getReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
get
({
url
,
json
:
true
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
rtn
.
data
=
body
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
postJsonTypeReq
(
url
,
data
,
md
=
'POST'
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
({
url
,
method
:
md
,
json
:
true
,
headers
:
{
'Content-type'
:
'application/json'
,
// 'Authorization': 'Basic YWRtaW5lczphZG1pbkdTQmVzLg=='
},
body
:
data
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
rtn
.
data
=
body
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
post3wFormTypeReq
(
url
,
data
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
url
,
form
:
data
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
postMpFormTypeReq
(
url
,
formdata
)
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
url
,
formData
:
formdata
,
},
(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
resv
(
body
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
declare
(
ns
)
{
const
ar
=
ns
.
split
(
'.'
);
let
root
=
System
;
for
(
let
i
=
0
,
len
=
ar
.
length
;
i
<
len
;
++
i
)
{
const
n
=
ar
[
i
];
if
(
!
root
[
n
])
{
root
[
n
]
=
{};
root
=
root
[
n
];
}
else
{
root
=
root
[
n
];
}
}
}
static
async
delReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
del
({
url
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
getReq
(
url
,
qdata
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
get
({
url
,
json
:
true
,
qs
:
qdata
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
rtn
.
data
=
body
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
postJsonTypeReq
(
url
,
data
,
md
=
'POST'
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
({
url
,
method
:
md
,
json
:
true
,
headers
:
{
'Content-type'
:
'application/json'
,
// 'Authorization': 'Basic YWRtaW5lczphZG1pbkdTQmVzLg=='
},
body
:
data
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
if
(
body
)
{
rtn
.
data
=
body
;
}
else
{
rtn
.
data
=
null
;
}
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
post3wFormTypeReq
(
url
,
data
)
{
const
rtn
=
{};
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
url
,
form
:
data
,
},
(
error
,
response
,
body
)
=>
{
rtn
.
statusCode
=
response
.
statusCode
;
if
(
!
error
)
{
const
data
=
JSON
.
parse
(
body
);
rtn
.
data
=
data
;
resv
(
rtn
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
static
async
postMpFormTypeReq
(
url
,
formdata
)
{
const
promise
=
new
Promise
(((
resv
,
rej
)
=>
{
request
.
post
({
url
,
formData
:
formdata
,
},
(
error
,
response
,
body
)
=>
{
if
(
!
error
&&
response
.
statusCode
==
200
)
{
resv
(
body
);
}
else
{
rej
(
error
);
}
});
}));
return
promise
;
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
static
getResult
(
data
,
opmsg
=
'操作成功'
,
req
)
{
return
{
status
:
!
data
?
-
1
:
0
,
msg
:
opmsg
,
data
,
bizmsg
:
req
&&
req
.
session
&&
req
.
session
.
bizmsg
?
req
.
session
.
bizmsg
:
'empty'
,
};
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
static
getResultSuccess
(
data
,
okmsg
=
'success'
)
{
return
{
status
:
0
,
msg
:
okmsg
,
data
,
};
}
/**
* 请求返回失败
* @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultFail
(
status
=
-
1
,
errmsg
=
'fail'
,
data
=
null
)
{
return
{
status
,
msg
:
errmsg
,
data
,
};
}
/**
* 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultError
(
errmsg
=
'fail'
,
data
=
null
)
{
return
{
status
:
-
200
,
msg
:
errmsg
,
data
,
};
}
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
'相同key的对象已经存在'
);
}
else
{
let
obj
;
if
(
ClassObj
.
name
===
'ServiceBase'
)
{
obj
=
new
ClassObj
(
groupName
,
filename
.
replace
(
'Sve'
,
'Dao'
));
}
else
{
obj
=
new
ClassObj
(
groupName
,
filename
);
}
System
.
objTable
[
key
]
=
obj
;
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据,有值为成功,无值为失败
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
static
getResult
(
data
,
opmsg
=
'操作成功'
,
req
)
{
return
{
status
:
!
data
?
-
1
:
0
,
msg
:
opmsg
,
data
,
bizmsg
:
req
&&
req
.
session
&&
req
.
session
.
bizmsg
?
req
.
session
.
bizmsg
:
'empty'
,
};
}
/**
* 请求返回成功
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
static
getResultSuccess
(
data
,
okmsg
=
'success'
)
{
return
{
status
:
0
,
msg
:
okmsg
,
data
,
};
}
/**
* 请求返回失败
* @param {*} status 操作失败状态,默认为-1
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultFail
(
status
=
-
1
,
errmsg
=
'fail'
,
data
=
null
)
{
return
{
status
,
msg
:
errmsg
,
data
,
};
}
/**
* 请求处理异常
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultError
(
errmsg
=
'fail'
,
data
=
null
)
{
return
{
status
:
-
200
,
msg
:
errmsg
,
data
,
};
}
static
register
(
key
,
ClassObj
,
groupName
,
filename
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
'相同key的对象已经存在'
);
}
else
{
let
obj
;
if
(
ClassObj
.
name
===
'ServiceBase'
)
{
obj
=
new
ClassObj
(
groupName
,
filename
.
replace
(
'Sve'
,
'Dao'
));
}
else
{
obj
=
new
ClassObj
(
groupName
,
filename
);
}
System
.
objTable
[
key
]
=
obj
;
}
return
System
.
objTable
[
key
];
}
static
getObject
(
objpath
)
{
const
pathArray
=
objpath
.
split
(
'.'
);
const
packageName
=
pathArray
[
0
];
const
groupName
=
pathArray
[
1
];
let
filename
=
pathArray
[
2
];
let
classpath
=
''
;
if
(
filename
)
{
classpath
=
`
${
objsettings
[
packageName
]}
/
${
groupName
}
`
;
}
else
{
classpath
=
objsettings
[
packageName
];
filename
=
groupName
;
}
return
System
.
objTable
[
key
];
}
static
getObject
(
objpath
)
{
const
pathArray
=
objpath
.
split
(
'.'
);
const
packageName
=
pathArray
[
0
];
const
groupName
=
pathArray
[
1
];
let
filename
=
pathArray
[
2
];
let
classpath
=
''
;
if
(
filename
)
{
classpath
=
`
${
objsettings
[
packageName
]}
/
${
groupName
}
`
;
}
else
{
classpath
=
objsettings
[
packageName
];
filename
=
groupName
;
}
const
objabspath
=
`
${
classpath
}
/
${
filename
}
.js`
;
const
objabspath
=
`
${
classpath
}
/
${
filename
}
.js`
;
// 判断文件的存在性
// 如果不存在,需要查看packageName
// 如果packageName=web.service,dao
// 判断文件的存在性
// 如果不存在,需要查看packageName
// 如果packageName=web.service,dao
if
(
System
.
objTable
[
objabspath
]
!=
null
)
{
return
System
.
objTable
[
objabspath
];
}
let
ClassObj
=
null
;
try
{
ClassObj
=
require
(
objabspath
);
}
catch
(
e
)
{
// console.log(e)
if
(
System
.
objTable
[
objabspath
]
!=
null
)
{
return
System
.
objTable
[
objabspath
];
}
let
ClassObj
=
null
;
try
{
ClassObj
=
require
(
objabspath
);
}
catch
(
e
)
{
// console.log(e)
const
fname
=
objsettings
[
`
${
packageName
}
base`
];
ClassObj
=
require
(
fname
);
}
if
(
ClassObj
.
name
==
'Dao'
)
{
const
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
'Dao'
));
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
}
if
(
ClassObj
.
name
.
indexOf
(
'Ctl'
)
>=
0
)
{
console
.
log
(
ClassObj
.
name
);
}
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
}
const
fname
=
objsettings
[
`
${
packageName
}
base`
];
ClassObj
=
require
(
fname
);
}
if
(
ClassObj
.
name
==
'Dao'
)
{
const
modelname
=
filename
.
substring
(
0
,
filename
.
lastIndexOf
(
'Dao'
));
return
System
.
register
(
objabspath
,
ClassObj
,
modelname
);
}
if
(
ClassObj
.
name
.
indexOf
(
'Ctl'
)
>=
0
)
{
console
.
log
(
ClassObj
.
name
);
}
return
System
.
register
(
objabspath
,
ClassObj
,
groupName
,
filename
);
}
static
getSysConfig
()
{
const
configPath
=
`
${
settings
.
basepath
}
/app/base/db/metadata/index.js`
;
// if(settings.env=="dev"){
// console.log("delete "+configPath+"cache config");
// delete require.cache[configPath];
// }
delete
require
.
cache
[
configPath
];
const
configValue
=
require
(
configPath
);
return
configValue
.
config
;
}
static
getClientIp
(
req
)
{
const
ip
=
req
.
headers
[
'x-forwarded-for'
]
||
req
.
ip
||
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
||
(
req
.
connection
.
socket
&&
req
.
connection
.
socket
.
remoteAddress
)
||
''
;
const
x
=
ip
.
match
(
/
(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
])\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
0-9
])
$/
);
if
(
x
)
{
return
x
[
0
];
}
return
'localhost'
;
};
static
getSysConfig
()
{
const
configPath
=
`
${
settings
.
basepath
}
/app/base/db/metadata/index.js`
;
// if(settings.env=="dev"){
// console.log("delete "+configPath+"cache config");
// delete require.cache[configPath];
// }
delete
require
.
cache
[
configPath
];
const
configValue
=
require
(
configPath
);
return
configValue
.
config
;
}
static
getClientIp
(
req
)
{
const
ip
=
req
.
headers
[
'x-forwarded-for'
]
||
req
.
ip
||
req
.
connection
.
remoteAddress
||
req
.
socket
.
remoteAddress
||
(
req
.
connection
.
socket
&&
req
.
connection
.
socket
.
remoteAddress
)
||
''
;
const
x
=
ip
.
match
(
/
(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
])\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
1-9
]
|0
)\.(
25
[
0-5
]
|2
[
0-4
][
0-9
]
|
[
0-1
]{1}[
0-9
]{2}
|
[
1-9
]{1}[
0-9
]{1}
|
[
0-9
])
$/
);
if
(
x
)
{
return
x
[
0
];
}
return
'localhost'
;
}
/**
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
const
reqUrl
=
settings
.
logUrl
();
let
isLogData
=
true
;
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
'find'
)
>=
0
||
params
.
method
.
indexOf
(
'get'
)
>=
0
))
{
isLogData
=
false
;
}
const
param
=
{
actionType
:
'produceLogsData'
,
// Y 功能名称
actionBody
:
{
opTitle
:
opTitle
||
''
,
// N 操作的业务标题
identifyCode
:
identifyCode
||
'brg-center-manage'
,
// Y 操作的业务标识
indexName
:
settings
.
logindex
,
// Y es索引值,同一个项目用一个值
messageBody
:
params
,
// 日志的描述信息
resultInfo
:
isLogData
?
resultInfo
:
{
status
:
resultInfo
.
status
},
// 返回信息
errorInfo
,
// 错误信息
requestId
:
resultInfo
.
requestId
||
''
,
},
};
console
.
log
(
JSON
.
stringify
(
param
));
const
P
=
new
Promise
((
resv
,
rej
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
((
res
)
=>
{
if
(
res
.
statusCode
==
200
)
{
resv
(
res
.
data
);
}
else
{
rej
(
null
);
}
});
});
return
P
;
}
/**
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
const
reqUrl
=
settings
.
logUrl
();
let
isLogData
=
true
;
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
'find'
)
>=
0
||
params
.
method
.
indexOf
(
'get'
)
>=
0
))
{
isLogData
=
false
;
}
const
param
=
{
actionType
:
'produceLogsData'
,
// Y 功能名称
actionBody
:
{
opTitle
:
opTitle
||
''
,
// N 操作的业务标题
identifyCode
:
identifyCode
||
'brg-center-manage'
,
// Y 操作的业务标识
indexName
:
settings
.
logindex
,
// Y es索引值,同一个项目用一个值
messageBody
:
params
,
// 日志的描述信息
resultInfo
:
isLogData
?
resultInfo
:
{
status
:
resultInfo
.
status
},
// 返回信息
errorInfo
,
// 错误信息
requestId
:
resultInfo
.
requestId
||
''
,
},
};
console
.
log
(
JSON
.
stringify
(
param
));
const
P
=
new
Promise
((
resv
,
rej
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
((
res
)
=>
{
if
(
res
.
statusCode
==
200
)
{
resv
(
res
.
data
);
}
else
{
rej
(
null
);
}
});
});
return
P
;
}
/**
* 加密信息
* @param {*} opStr
*/
static
encryptStr
(
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
}
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
cipherStr
=
cryptoJS
.
TripleDES
.
encrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
}).
toString
();
return
cipherStr
;
}
/**
* 解密信息
* @param {*} opStr
*/
static
decryptStr
(
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
}
try
{
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
bytes
=
cryptoJS
.
TripleDES
.
decrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
,
});
const
plaintext
=
bytes
.
toString
(
cryptoJS
.
enc
.
Utf8
);
return
plaintext
||
opStr
;
}
catch
(
err
)
{
return
opStr
;
}
}
/**
* 加密信息
* @param {*} opStr
*/
static
encryptStr
(
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
}
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
cipherStr
=
cryptoJS
.
TripleDES
.
encrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
}).
toString
();
return
cipherStr
;
}
/**
* 解密信息
* @param {*} opStr
*/
static
decryptStr
(
opStr
)
{
if
(
!
opStr
)
{
return
opStr
;
}
try
{
const
keyHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_key
);
const
ivHex
=
cryptoJS
.
enc
.
Utf8
.
parse
(
settings
.
encrypt_secret
.
substring
(
0
,
8
));
const
bytes
=
cryptoJS
.
TripleDES
.
decrypt
(
opStr
,
keyHex
,
{
iv
:
ivHex
,
});
const
plaintext
=
bytes
.
toString
(
cryptoJS
.
enc
.
Utf8
);
return
plaintext
||
opStr
;
}
catch
(
err
)
{
return
opStr
;
}
}
}
Date
.
prototype
.
Format
=
function
(
fmt
)
{
// author: meizz
const
o
=
{
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'd+'
:
this
.
getDate
(),
// 日
'h+'
:
this
.
getHours
(),
// 小时
'm+'
:
this
.
getMinutes
(),
// 分
's+'
:
this
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
S
:
this
.
getMilliseconds
(),
// 毫秒
};
if
(
/
(
y+
)
/
.
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
`
${
this
.
getFullYear
()}
`
).
substr
(
4
-
RegExp
.
$1
.
length
));
for
(
const
k
in
o
)
if
(
new
RegExp
(
`(
${
k
}
)`
).
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
`00
${
o
[
k
]}
`
).
substr
((
`
${
o
[
k
]}
`
).
length
)));
return
fmt
;
const
o
=
{
'M+'
:
this
.
getMonth
()
+
1
,
// 月份
'd+'
:
this
.
getDate
(),
// 日
'h+'
:
this
.
getHours
(),
// 小时
'm+'
:
this
.
getMinutes
(),
// 分
's+'
:
this
.
getSeconds
(),
// 秒
'q+'
:
Math
.
floor
((
this
.
getMonth
()
+
3
)
/
3
),
// 季度
S
:
this
.
getMilliseconds
(),
// 毫秒
};
if
(
/
(
y+
)
/
.
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
`
${
this
.
getFullYear
()}
`
).
substr
(
4
-
RegExp
.
$1
.
length
));
for
(
const
k
in
o
)
if
(
new
RegExp
(
`(
${
k
}
)`
).
test
(
fmt
))
fmt
=
fmt
.
replace
(
RegExp
.
$1
,
(
RegExp
.
$1
.
length
==
1
)
?
(
o
[
k
])
:
((
`00
${
o
[
k
]}
`
).
substr
((
`
${
o
[
k
]}
`
).
length
)));
return
fmt
;
};
/**
...
...
@@ -353,57 +353,57 @@ Date.prototype.Format = function (fmt) { // author: meizz
// 表分类
System
.
FLOWCODE
=
{
BIZ
:
'BIZ'
,
// 商机表
SCHEME
:
'SCHEME'
,
// 方案表
DELIVERY
:
'DELIVERY'
,
// 服务单表
ANNUALREPORT
:
'ANNUALREPORT'
,
// 年报表
BIZ
:
'BIZ'
,
// 商机表
SCHEME
:
'SCHEME'
,
// 方案表
DELIVERY
:
'DELIVERY'
,
// 服务单表
ANNUALREPORT
:
'ANNUALREPORT'
,
// 年报表
};
// 服务名称
System
.
SERVICECODE
=
{
ICP
:
'ICP'
,
EDI
:
'EDI'
,
ICPANNUALREPORT
:
'ICPANNUALREPORT'
,
EDIANNUALREPORT
:
'EDIANNUALREPORT'
,
ICP
:
'ICP'
,
EDI
:
'EDI'
,
ICPANNUALREPORT
:
'ICPANNUALREPORT'
,
EDIANNUALREPORT
:
'EDIANNUALREPORT'
,
};
// 商机状态
System
.
BUSSTATUS
=
{
WAITINGSCHEME
:
'beforeSubmission'
,
// 待提交方案
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认
SUCCESS
:
'isFinished'
,
// 已成交
CLOSED
:
'isClosed'
,
// 需求关闭
WAITINGSCHEME
:
'beforeSubmission'
,
// 待提交方案
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认
SUCCESS
:
'isFinished'
,
// 已成交
CLOSED
:
'isClosed'
,
// 需求关闭
};
// 方案状态
System
.
SCHEMESTATUS
=
{
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认.
CLOSED
:
'isClosed'
,
// 方案关闭
REJECT
:
'isReject'
,
// 方案被拒绝
WAITINGCONFIRM
:
'beforeConfirmation'
,
// 待用户确认.
CLOSED
:
'isClosed'
,
// 方案关闭
REJECT
:
'isReject'
,
// 方案被拒绝
};
// 资质服务单状态
System
.
SERVERSESTATUS
=
{
RECEIVED
:
'received'
,
// 已接单
COLLECTING
:
'collecting'
,
// 收集材料中
SUBMITING
:
'submiting'
,
// 递交材料中
DISPOSEING
:
'disposeing'
,
// 工信部处理中
POSTING
:
'posting'
,
// 证书已邮寄
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
RECEIVED
:
'received'
,
// 已接单
COLLECTING
:
'collecting'
,
// 收集材料中
SUBMITING
:
'submiting'
,
// 递交材料中
DISPOSEING
:
'disposeing'
,
// 工信部处理中
POSTING
:
'posting'
,
// 证书已邮寄
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
};
// 年报服务单状态
System
.
ANNUALREPORT
=
{
RECEIVED
:
'received'
,
// 已接单
WAITDECLARE
:
'waitdeclare'
,
// 待申报
DECLARESUCCESS
:
'declaresuccess'
,
// 申报成功
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
TAKEEFFECT
:
'takeeffect'
,
// 生效
RECEIVED
:
'received'
,
// 已接单
WAITDECLARE
:
'waitdeclare'
,
// 待申报
DECLARESUCCESS
:
'declaresuccess'
,
// 申报成功
SUCCESS
:
'success'
,
// 服务已完成
CLOSED
:
'closed'
,
// 已关闭
TAKEEFFECT
:
'takeeffect'
,
// 生效
};
// 渠道名
System
.
SOURCENAME
=
{
tencentCloud
:
'腾讯云'
,
tencentCloud
:
'腾讯云'
,
};
/*
...
...
icp-deliver/app/base/utils/redisClient.js
View file @
9cf1636a
...
...
@@ -248,7 +248,8 @@ module.exports = RedisClient;
// client.sismember("h","ok").then(function(r){
// console.log(r);
// });
// console.dir(client);ti.exec( callback )回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误
// console.dir(client);ti.exec( callback )
//回调函数参数err:返回null或者Array,出错则返回对应命令序列链中发生错误的错误信息,这个数组中最后一个元素是源自exec本身的一个EXECABORT类型的错误
// r.set("hello","oooo").then(function(result){
// console.log(result);
// });
...
...
icp-deliver/app/base/utils/restClient.js
View file @
9cf1636a
...
...
@@ -10,52 +10,46 @@ class RestClient {
this
.
cmdDownLoadFilePattern
=
'curl -G -o {fileName} {url}'
;
this
.
cmdPostPattern2
=
'curl -k -H
\'
Content-type: application/x-www-form-urlencoded
\'
-d
\'
{data}
\'
{url}'
;
this
.
cmdPostPatternWithAK
=
'curl -k -H
\'
Content-type: application/json
\'
-H
\'
AccessKey:{ak}
\'
-d
\'
{data}
\'
{url}'
;
// 云帐户
// this.cmdPostPattern3="curl -k -H 'Content-type: application/x-www-form-urlencoded' -H 'dealer-id:"+settings.apiconfig.yunzhanghuDealer_id()+"' -H 'request-id:"+parseInt(Date.now() / 1000)+"_gsb"+"' -d '{data}' {url}";
// this.cmdGetPattern3 = "curl {-G} -k {url} --header 'dealer-id:"+settings.apiconfig.yunzhanghuDealer_id()+"'";
// e签宝
// this.cmdPostPattern4="curl -k -H 'Content-type: application/json' -H 'X-Tsign-Open-App-Id:"+settings.apiconfig.eSignBaoAppId()+"' -H 'X-Tsign-Open-App-Secret:"+settings.apiconfig.eSignBaoAppKey()+"' -d '{data}' {url}";
// form-data形式post data参数类型 md5=2&data=1
this
.
cmdPostPattern5
=
'curl -k --data
\'
{data}
\'
{url}'
;
}
FetchGetCmd
(
subData
,
url
)
{
const
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
data
\}
/g
,
subData
)
const
cmd
=
this
.
cmdGetPattern
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
data
\}
/g
,
subData
)
.
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
}
return
cmd
;
}
FetchPostCmd
(
subData
,
url
)
{
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPattern
.
replace
(
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPattern
.
replace
(
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
FetchPostCmdWithAK
(
subData
,
url
,
acck
)
{
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPatternWithAK
.
replace
(
const
data
=
JSON
.
stringify
(
subData
);
const
cmd
=
this
.
cmdPostPatternWithAK
.
replace
(
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
)
.
replace
(
/
\{
ak
\}
/g
,
acck
);
return
cmd
;
}
return
cmd
;
}
FetchPostCmd2
(
subData
,
url
)
{
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern2
.
replace
(
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern2
.
replace
(
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
}
return
cmd
;
}
FetchPostCmd3
(
subData
,
url
)
{
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern3
.
replace
(
const
data
=
subData
;
const
cmd
=
this
.
cmdPostPattern3
.
replace
(
/
\{
data
\}
/g
,
data
,
data
,
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
return
cmd
;
}
FetchGetCmd3
(
url
)
{
const
cmd
=
this
.
cmdGetPattern3
.
replace
(
/
\{\-
G
\}
/g
,
'-G'
).
replace
(
/
\{
url
\}
/g
,
url
);
...
...
@@ -78,10 +72,10 @@ class RestClient {
return
cmd
;
}
FetchDownLoadCmd
(
outfname
,
url
)
{
// console.log(this.cmdPattern);
const
cmd
=
this
.
cmdDownLoadFilePattern
.
replace
(
/
\{
fileName
\}
/g
,
outfname
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
}
// console.log(this.cmdPattern);
const
cmd
=
this
.
cmdDownLoadFilePattern
.
replace
(
/
\{
fileName
\}
/g
,
outfname
).
replace
(
/
\{
url
\}
/g
,
url
);
return
cmd
;
}
async
exec
(
cmd
)
{
// await后面表达式返回的promise对象,是then的语法糖,await返回then函数的返回值
// 异常需要try/catch自己捕获或外部catch捕获
...
...
icp-deliver/dochelp/imghandle.js
View file @
9cf1636a
const
fs
=
require
(
'fs'
);
// function to encode file data to base64 encoded string
function
base64
_e
ncode
(
file
)
{
function
base64
E
ncode
(
file
)
{
// read binary data
const
bitmap
=
fs
.
readFileSync
(
"./imgs/sp.png"
);
// convert binary data to base64 encoded string
...
...
@@ -10,8 +10,7 @@ function base64_encode(file) {
}
// function to create file from base64 encoded string
function
base64_decode
(
base64str
,
file
)
{
// create buffer object from base64 encoded string, it is important to tell the constructor that the string is base64 encoded
function
base64Decode
(
base64str
,
file
)
{
const
bitmap
=
new
Buffer
(
base64str
,
'base64'
);
// write buffer to file
fs
.
writeFileSync
(
file
,
bitmap
);
...
...
@@ -19,7 +18,7 @@ function base64_decode(base64str, file) {
}
function
getDataUrl
(
filepath
)
{
const
str
=
base64
_e
ncode
(
filepath
);
const
str
=
base64
E
ncode
(
filepath
);
let
mime
=
""
;
if
(
filepath
.
indexOf
(
"png"
)
>=
0
)
{
mime
=
"image/png"
;
...
...
@@ -30,9 +29,6 @@ function getDataUrl(filepath) {
if
(
filepath
.
indexOf
(
"gif"
)
>=
0
)
{
mime
=
"image/gif"
;
}
const
dataurl
=
`data:
${
mime
}
;base64,
`
+
str
;
const
dataurl
=
`data:
${
mime
}
;base64,
${
str
}
`
;
return
dataurl
;
}
const
str
=
getDataUrl
(
"./imgs/sp.png"
);
console
.
log
(
str
);
\ No newline at end of file
}
\ No newline at end of file
icp-deliver/main.js
View file @
9cf1636a
...
...
@@ -29,6 +29,6 @@ environment(app);//初始化环境
const
server
=
http
.
createServer
(
app
);
//const socketServer = new SocketServer(server);
server
.
listen
(
setttings
.
port
,
function
()
{
console
.
log
(
'Express server listening on port '
+
app
.
get
(
'port'
)
);
console
.
log
(
`Express server listening on port
${
app
.
get
(
'port'
)}
`
);
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment