Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinhaitao
taobao-mini-template
Commits
9fbc8275
Commit
9fbc8275
authored
Aug 03, 2021
by
mqf_0707
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wnf
parent
baa55e12
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
50 additions
and
1 deletion
+50
-1
.DS_Store
.DS_Store
+0
-0
constants.ts
v2.0/src/constants.ts
+5
-0
preUpdate.ts
v2.0/src/decorator/common/preUpdate.ts
+3
-0
requestCountLimit.ts
v2.0/src/decorator/common/requestCountLimit.ts
+3
-0
requestRateLimit.ts
v2.0/src/decorator/common/requestRateLimit.ts
+3
-0
dingTalk.ts
v2.0/src/utils/common/dingTalk.ts
+30
-0
doHandler.ts
v2.0/src/utils/common/doHandler.ts
+4
-0
format.ts
v2.0/src/utils/common/format.ts
+2
-1
No files found.
.DS_Store
View file @
9fbc8275
No preview for this file type
v2.0/src/constants.ts
View file @
9fbc8275
...
...
@@ -119,3 +119,8 @@ export const sellerId = '1234'
// C端的APP NAME
export
const
C_APP_NAME
:
string
=
`promotioncenter-
${
appId
}
`
// 钉钉告警 活动名称
export
const
activityName
=
''
// 开发者手机号
export
const
phone
=
''
v2.0/src/decorator/common/preUpdate.ts
View file @
9fbc8275
...
...
@@ -7,6 +7,7 @@ import { CODE_TYPES } from '../../errorCode'
import
{
formatUpdatedDataByProjection
,
formatUpdateUserProjection
}
from
'../../utils/common/format'
import
{
dbUpdate
}
from
'../../utils/common/mongodb'
import
{
USER_DB_NAME
}
from
'../../db'
import
{
cloundAlarm
}
from
'../../utils/common/dingTalk'
// 前置更新
export
default
function
preUpdate
(
checks
:
IFunction
[])
{
...
...
@@ -40,6 +41,8 @@ export default function preUpdate(checks: IFunction[]) {
}
catch
(
error
)
{
console
.
log
(
error
,
'preUpdateUser-error'
)
recordErrorLog
(
context
,
baseInfos
,
error
.
toString
(),
error
.
stack
)
// 云告警
cloundAlarm
(
context
,
error
.
toString
())
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
)
}
return
method
.
apply
(
target
,
[
context
,
{
...
baseInfos
},
services
,
preCheckData
])
...
...
v2.0/src/decorator/common/requestCountLimit.ts
View file @
9fbc8275
...
...
@@ -2,6 +2,7 @@
import
{
resultsModel
}
from
'../../sdk'
import
{
CODE_TYPES
}
from
'../../constants'
import
{
logFn
,
recordErrorLog
}
from
'../../utils'
import
{
cloundAlarm
}
from
'../../utils/common/dingTalk'
/**
* 限制单位时间接口请求次数
...
...
@@ -56,6 +57,8 @@ export default function requestCountLimit(limitCount: number, limitTime: number)
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
recordErrorLog
(
context
,
baseInfos
,
error
.
toString
(),
error
.
stack
)
// 云告警
cloundAlarm
(
context
,
error
.
toString
())
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
)
}
...
...
v2.0/src/decorator/common/requestRateLimit.ts
View file @
9fbc8275
...
...
@@ -3,6 +3,7 @@ import { resultsModel } from '../../sdk'
import
{
CODE_TYPES
}
from
'../../constants'
import
{
logFn
,
recordErrorLog
}
from
'../../utils'
import
{
formatDate
}
from
'../../utils/common/date'
import
{
cloundAlarm
}
from
'../../utils/common/dingTalk'
// 限制请求频率 rate单位 ms
export
default
function
requestRateLimit
(
rate
=
500
)
{
...
...
@@ -45,6 +46,8 @@ export default function requestRateLimit(rate = 500) {
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
recordErrorLog
(
context
,
baseInfos
,
error
.
toString
(),
error
.
stack
)
// 云告警
cloundAlarm
(
context
,
error
.
toString
())
return
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
)
}
...
...
v2.0/src/utils/common/dingTalk.ts
0 → 100644
View file @
9fbc8275
import
{
phone
,
activityName
}
from
'../../constants'
/**
* 告警信息
* @param message
*/
export
const
cloundAlarm
=
async
(
context
:
IContext
<
IParams
>
,
message
:
string
)
=>
{
// https://oapi.dingtalk.com/robot/send?access_token=f6d0d8ecdab3ad77dc51b5173f630f1c0e0fcbe90e994d0a642fb0b516dfd24c
const
text
=
{
"msgtype"
:
"markdown"
,
"markdown"
:
{
"title"
:
"云告警"
,
"text"
:
`### 活动名称:
${
activityName
}
\n ### 告警内容 \n ####
${
message
}
\n @
${
phone
}
`
},
"at"
:
{
"isAtAll"
:
false
,
"atMobiles"
:
[
phone
],
"atUserIds"
:
[]
}
}
const
result
=
await
context
.
cloud
.
httpApi
.
invoke
(
{
'domain'
:
'https://oapi.dingtalk.com'
,
'path'
:
'/robot/send'
,
'params'
:
{
'access_token'
:
'f6d0d8ecdab3ad77dc51b5173f630f1c0e0fcbe90e994d0a642fb0b516dfd24c'
},
'method'
:
'POST'
,
'headers'
:
{
'Content-Type'
:
'application/json;charset=UTF-8'
,
},
'body'
:
text
});
return
result
}
v2.0/src/utils/common/doHandler.ts
View file @
9fbc8275
...
...
@@ -3,6 +3,7 @@
import
{
resultsModel
}
from
'../../sdk'
import
{
recordErrorLog
}
from
'./logger'
import
{
CODE_TYPES
}
from
'../../errorCode'
import
{
cloundAlarm
}
from
'../../utils/common/dingTalk'
/** @format */
export
async
function
doHandler
(
target
:
Object
,
method
:
IFunction
,
args
:
any
[])
{
...
...
@@ -12,6 +13,9 @@ export async function doHandler(target: Object, method: IFunction, args: any[])
}
catch
(
error
)
{
console
.
log
(
'error'
,
error
)
recordErrorLog
(
args
[
0
],
args
[
1
],
error
.
toString
(),
error
.
stack
)
// 云告警
cloundAlarm
(
args
[
0
],
error
.
toString
())
ret
=
resultsModel
.
error
(
CODE_TYPES
.
SYSTEM_ERROR
)
}
return
ret
...
...
v2.0/src/utils/common/format.ts
View file @
9fbc8275
...
...
@@ -66,7 +66,8 @@ export function formatUpdatedDataByProjection(dbData: any, projection: IPreUpdat
if
(
!
isEmpty
(
projection
.
$push
))
{
Object
.
keys
(
projection
.
$push
).
forEach
(
key
=>
{
const
originValue
=
get
(
key
,
updatedDbData
)
||
[]
set
(
key
,
[
originValue
,
projection
.
$push
?.[
key
]],
updatedDbData
)
if
(
originValue
.
length
)
set
(
key
,
[
originValue
,
projection
.
$push
?.[
key
]],
updatedDbData
)
else
set
(
key
,
[
projection
.
$push
?.[
key
]],
updatedDbData
)
})
}
return
updatedDbData
...
...
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