Commit 9fbc8275 authored by mqf_0707's avatar mqf_0707

wnf

parent baa55e12
No preview for this file type
...@@ -119,3 +119,8 @@ export const sellerId = '1234' ...@@ -119,3 +119,8 @@ export const sellerId = '1234'
// C端的APP NAME // C端的APP NAME
export const C_APP_NAME: string = `promotioncenter-${appId}` export const C_APP_NAME: string = `promotioncenter-${appId}`
// 钉钉告警 活动名称
export const activityName = ''
// 开发者手机号
export const phone = ''
...@@ -7,6 +7,7 @@ import { CODE_TYPES } from '../../errorCode' ...@@ -7,6 +7,7 @@ import { CODE_TYPES } from '../../errorCode'
import { formatUpdatedDataByProjection, formatUpdateUserProjection } from '../../utils/common/format' import { formatUpdatedDataByProjection, formatUpdateUserProjection } from '../../utils/common/format'
import { dbUpdate } from '../../utils/common/mongodb' import { dbUpdate } from '../../utils/common/mongodb'
import { USER_DB_NAME } from '../../db' import { USER_DB_NAME } from '../../db'
import { cloundAlarm } from '../../utils/common/dingTalk'
// 前置更新 // 前置更新
export default function preUpdate(checks: IFunction[]) { export default function preUpdate(checks: IFunction[]) {
...@@ -40,6 +41,8 @@ export default function preUpdate(checks: IFunction[]) { ...@@ -40,6 +41,8 @@ export default function preUpdate(checks: IFunction[]) {
} catch (error) { } catch (error) {
console.log(error, 'preUpdateUser-error') console.log(error, 'preUpdateUser-error')
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警
cloundAlarm(context, error.toString())
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
return method.apply(target, [context, { ...baseInfos }, services, preCheckData]) return method.apply(target, [context, { ...baseInfos }, services, preCheckData])
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../constants' import { CODE_TYPES } from '../../constants'
import { logFn, recordErrorLog } from '../../utils' import { logFn, recordErrorLog } from '../../utils'
import { cloundAlarm } from '../../utils/common/dingTalk'
/** /**
* 限制单位时间接口请求次数 * 限制单位时间接口请求次数
...@@ -56,6 +57,8 @@ export default function requestCountLimit(limitCount: number, limitTime: number) ...@@ -56,6 +57,8 @@ export default function requestCountLimit(limitCount: number, limitTime: number)
} catch (error) { } catch (error) {
console.log('error', error) console.log('error', error)
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警
cloundAlarm(context, error.toString())
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
......
...@@ -3,6 +3,7 @@ import { resultsModel } from '../../sdk' ...@@ -3,6 +3,7 @@ import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../constants' import { CODE_TYPES } from '../../constants'
import { logFn, recordErrorLog } from '../../utils' import { logFn, recordErrorLog } from '../../utils'
import { formatDate } from '../../utils/common/date' import { formatDate } from '../../utils/common/date'
import { cloundAlarm } from '../../utils/common/dingTalk'
// 限制请求频率 rate单位 ms // 限制请求频率 rate单位 ms
export default function requestRateLimit(rate = 500) { export default function requestRateLimit(rate = 500) {
...@@ -45,6 +46,8 @@ export default function requestRateLimit(rate = 500) { ...@@ -45,6 +46,8 @@ export default function requestRateLimit(rate = 500) {
} catch (error) { } catch (error) {
console.log('error', error) console.log('error', error)
recordErrorLog(context, baseInfos, error.toString(), error.stack) recordErrorLog(context, baseInfos, error.toString(), error.stack)
// 云告警
cloundAlarm(context, error.toString())
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR) return resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
......
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
}
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { recordErrorLog } from './logger' import { recordErrorLog } from './logger'
import { CODE_TYPES } from '../../errorCode' import { CODE_TYPES } from '../../errorCode'
import { cloundAlarm } from '../../utils/common/dingTalk'
/** @format */ /** @format */
export async function doHandler(target: Object, method: IFunction, args: any[]) { export async function doHandler(target: Object, method: IFunction, args: any[]) {
...@@ -12,6 +13,9 @@ 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) { } catch (error) {
console.log('error', error) console.log('error', error)
recordErrorLog(args[0], args[1], error.toString(), error.stack) recordErrorLog(args[0], args[1], error.toString(), error.stack)
// 云告警
cloundAlarm(args[0], error.toString())
ret = resultsModel.error(CODE_TYPES.SYSTEM_ERROR) ret = resultsModel.error(CODE_TYPES.SYSTEM_ERROR)
} }
return ret return ret
......
...@@ -66,7 +66,8 @@ export function formatUpdatedDataByProjection(dbData: any, projection: IPreUpdat ...@@ -66,7 +66,8 @@ export function formatUpdatedDataByProjection(dbData: any, projection: IPreUpdat
if (!isEmpty(projection.$push)) { if (!isEmpty(projection.$push)) {
Object.keys(projection.$push).forEach(key => { Object.keys(projection.$push).forEach(key => {
const originValue = get(key, updatedDbData) || [] 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 return updatedDbData
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment