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
afc0fb54
Commit
afc0fb54
authored
Jul 24, 2020
by
v_vjyjiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log
parent
c36dc90b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
116 additions
and
10 deletions
+116
-10
center-taskexecutor/app/base/system.js
+80
-10
center-taskexecutor/app/base/utils/logClient.js
+27
-0
center-taskexecutor/app/config/settings.js
+9
-0
No files found.
center-taskexecutor/app/base/system.js
View file @
afc0fb54
var
fs
=
require
(
"fs"
);
var
objsettings
=
require
(
"../config/objsettings"
);
var
settings
=
require
(
"../config/settings"
);
const
request
=
require
(
'request'
);
class
System
{
static
declare
(
ns
)
{
static
declare
(
ns
)
{
var
ar
=
ns
.
split
(
'.'
);
var
root
=
System
;
for
(
var
i
=
0
,
len
=
ar
.
length
;
i
<
len
;
++
i
)
{
...
...
@@ -15,7 +16,7 @@ class System {
}
}
}
static
register
(
key
,
ClassObj
)
{
static
register
(
key
,
ClassObj
)
{
if
(
System
.
objTable
[
key
]
!=
null
)
{
throw
new
Error
(
"相同key的对象已经存在"
);
}
else
{
...
...
@@ -31,7 +32,7 @@ class System {
* @param {*} okmsg 操作成功的描述
* @param {*} req 请求头信息
*/
static
getResult
(
data
,
opmsg
=
"操作成功"
,
req
)
{
static
getResult
(
data
,
opmsg
=
"操作成功"
,
req
)
{
return
{
status
:
!
data
?
-
1
:
0
,
msg
:
opmsg
,
...
...
@@ -44,7 +45,7 @@ class System {
* @param {*} data 操作成功返回的数据
* @param {*} okmsg 操作成功的描述
*/
static
getResultSuccess
(
data
,
okmsg
=
"success"
)
{
static
getResultSuccess
(
data
,
okmsg
=
"success"
)
{
return
{
status
:
0
,
msg
:
okmsg
,
...
...
@@ -57,7 +58,7 @@ class System {
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultFail
(
status
=
-
1
,
errmsg
=
"fail"
,
data
=
null
)
{
static
getResultFail
(
status
=
-
1
,
errmsg
=
"fail"
,
data
=
null
)
{
return
{
status
:
status
,
msg
:
errmsg
,
...
...
@@ -69,14 +70,14 @@ class System {
* @param {*} errmsg 操作失败的描述,默认为fail
* @param {*} data 操作失败返回的数据
*/
static
getResultError
(
errmsg
=
"fail"
,
data
=
null
)
{
static
getResultError
(
errmsg
=
"fail"
,
data
=
null
)
{
return
{
status
:
-
200
,
msg
:
errmsg
,
data
:
data
,
};
}
static
getObject
(
objpath
)
{
static
getObject
(
objpath
)
{
var
pathArray
=
objpath
.
split
(
"."
);
var
packageName
=
pathArray
[
0
];
var
groupName
=
pathArray
[
1
];
...
...
@@ -97,7 +98,7 @@ class System {
return
System
.
register
(
objabspath
,
ClassObj
);
}
}
static
getUiConfig
(
appid
)
{
static
getUiConfig
(
appid
)
{
var
configPath
=
settings
.
basepath
+
"/app/base/db/metadata/"
+
appid
+
"/index.js"
;
if
(
settings
.
env
==
"dev"
)
{
delete
require
.
cache
[
configPath
];
...
...
@@ -105,7 +106,7 @@ class System {
var
configValue
=
require
(
configPath
);
return
configValue
;
}
static
getUiConfig2
(
appid
)
{
static
getUiConfig2
(
appid
)
{
var
configPath
=
settings
.
basepath
+
"/app/base/db/metadata/index.js"
;
// if(settings.env=="dev"){
// console.log("delete "+configPath+"cache config");
...
...
@@ -115,7 +116,7 @@ class System {
var
configValue
=
require
(
configPath
);
return
configValue
[
appid
];
}
static
get_client_ip
(
req
)
{
static
get_client_ip
(
req
)
{
var
ip
=
req
.
headers
[
'x-forwarded-for'
]
||
req
.
ip
||
req
.
connection
.
remoteAddress
||
...
...
@@ -129,6 +130,75 @@ class System {
}
};
static
async
postJsonTypeReq
(
url
,
data
,
md
=
"POST"
)
{
let
rtn
=
{}
let
promise
=
new
Promise
(
function
(
resv
,
rej
)
{
request
({
url
:
url
,
method
:
md
,
json
:
true
,
headers
:
{
"content-type"
:
"application/json"
,
},
body
:
data
},
function
(
error
,
response
,
body
)
{
console
.
log
(
error
)
if
(
!
error
)
{
rtn
.
statusCode
=
response
.
statusCode
if
(
body
)
{
rtn
.
data
=
body
}
else
{
rtn
.
data
=
null
}
resv
(
rtn
);
}
else
{
rej
(
error
)
}
});
})
return
promise
;
}
/**
* 记录日志信息
* @param {*} opTitle 操作的标题
* @param {*} params 参数
* @param {*} identifyCode 业务标识
* @param {*} resultInfo 返回结果
* @param {*} errorInfo 错误信息
*/
static
execLogs
(
opTitle
,
params
,
identifyCode
,
resultInfo
,
errorInfo
)
{
var
reqUrl
=
settings
.
logUrl
();
let
isLogData
=
true
if
(
params
.
method
&&
(
params
.
method
.
indexOf
(
"find"
)
>=
0
||
params
.
method
.
indexOf
(
"get"
)
>=
0
))
{
isLogData
=
false
}
var
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
:
errorInfo
,
//错误信息
requestId
:
resultInfo
.
requestId
||
""
}
};
console
.
log
(
"写入日志内容:"
)
console
.
log
(
JSON
.
stringify
(
param
))
let
P
=
new
Promise
((
resv
,
rej
)
=>
{
this
.
postJsonTypeReq
(
reqUrl
,
param
).
then
(
res
=>
{
if
(
res
.
statusCode
==
200
)
{
resv
(
res
.
data
)
}
else
{
rej
(
null
)
}
});
})
return
P
}
}
Date
.
prototype
.
Format
=
function
(
fmt
)
{
//author: meizz
var
o
=
{
...
...
center-taskexecutor/app/base/utils/logClient.js
0 → 100644
View file @
afc0fb54
// var log4js = require('log4js');
var
settings
=
require
(
"../../config/settings"
);
const
uuidv4
=
require
(
'uuid/v4'
);
const
system
=
require
(
"../system"
);
class
LogClient
{
constructor
()
{
}
getUUID
()
{
var
uuid
=
uuidv4
();
var
u
=
uuid
.
replace
(
/
\-
/g
,
""
);
return
u
;
}
async
log
(
pobj
,
rtninfo
,
errinfo
)
{
rtninfo
.
requestId
=
this
.
getUUID
()
//第三个字段应该存公司id{status:0}
system
.
execLogs
(
settings
.
appname
,
pobj
,
"_"
+
pobj
.
company_id
+
"_"
,
rtninfo
,
errinfo
).
then
(
res
=>
{
if
(
res
&&
res
.
status
==
1
)
{
console
.
log
(
"log.....success"
)
}
else
{
console
.
log
(
"log.....fail"
)
}
}).
catch
(
e
=>
{
console
.
log
(
"log.....fail"
)
})
}
}
module
.
exports
=
LogClient
;
center-taskexecutor/app/config/settings.js
View file @
afc0fb54
...
...
@@ -14,6 +14,15 @@ var ENVINPUT = {
var
settings
=
{
env
:
ENVINPUT
.
APP_ENV
,
basepath
:
path
.
normalize
(
path
.
join
(
__dirname
,
'../..'
)),
logindex
:
"center_manage"
,
appname
:
"center-taskexecutor"
,
logUrl
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
return
"http://43.247.184.94:7200/api/queueAction/producer/springBoard"
;
}
else
{
return
"http://logs-sytxpublic-msgq-service/api/queueAction/producer/springBoard"
;
}
},
fkweb
:
function
()
{
if
(
this
.
env
==
"dev"
)
{
return
"http://localhost:3003/api/rpt/rptApi/saveRptHistory"
;
...
...
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