Ver código fonte

添加飞书表格通知

DevYK 2 anos atrás
pai
commit
c2c238befd
2 arquivos alterados com 68 adições e 7 exclusões
  1. 24 3
      config/test_config.js
  2. 44 4
      model/server_data_statisticsv2.js

+ 24 - 3
config/test_config.js

@@ -12,7 +12,8 @@ const account_config = {
     TRANSFER_GAS: true,
     FEISHU_URL: 'https://open.feishu.cn/open-apis/bot/v2/hook/18dfe21f-b1bd-46ca-a8c7-c85e1c84f02d',
     CZZ_BASEURL: "https://internal-block-payout-test.denet.me",
-    STATISTICS_URL:'https://testapi.denetme.net/denet/wallet/stat/getMoneyStat?date='
+    // CZZ_BASEURL: "https://internal-block-payout.denet.me",
+    STATISTICS_URL: 'https://testapi.denetme.net/denet/wallet/stat/getMoneyStat?date='
 }
 
 const cryppt_config = {
@@ -32,8 +33,8 @@ const reids_token_config = {
     COLLECT_CONIS_QUEUE_KEY: 'COLLECT_CONIS_QUEUE_KEY',
     LAST_COLLECT_PUBLIC_KEY: 'LAST_COLLECT_PUBLIC_LEY',
     LAST_COLLECT_TIME: 'LAST_COLLECT_TIME',
-    CHECK_CZZ_WITHDRAW_STATUS_QUEUE:'CHECK_CZZ_WITHDRAW_STATUS_QUEUE',
-    BSC_LOG_MONITORING_KEY:'BSC_LOG_MONITORING_KEY'
+    CHECK_CZZ_WITHDRAW_STATUS_QUEUE: 'CHECK_CZZ_WITHDRAW_STATUS_QUEUE',
+    BSC_LOG_MONITORING_KEY: 'BSC_LOG_MONITORING_KEY'
 }
 
 
@@ -64,6 +65,26 @@ const db_config = {
         USERNAME: null, // needs Redis >= 6
         PASSWORD: null,
     },
+
+    // // 线上数据库配置
+    // mysql: {
+    //     DATABASE: 'denet_chain',   //数据库名称
+    //     DATABASE_MY_NODE: 'bnb_block_sync',   //自建 node 存储
+    //     TABLENAME: 'user_key_manage',   //表名
+    //     USERNAME: 'denet',   //用户名
+    //     PASSWORD: 'cyber#Together_2022', //密码
+    //     PORT: '3306', //连接的端口
+    //     HOST: 'denet-chain-prod.csi2lctklqzg.us-east-1.rds.amazonaws.com', //host
+    //     OPEN_POOL: true,
+    //     POOL_SIZE: 5,
+    // },
+
+    // redis: {
+    //     PORT: 6379, // Redis port
+    //     HOST: "denet-chain-prod.y2slbl.clustercfg.memorydb.us-east-1.amazonaws.com", // Redis host
+    //     USERNAME: null,
+    //     PASSWORD: null,
+    // },
 }
 
 // 设置 moralis sdk 配置文件

+ 44 - 4
model/server_data_statisticsv2.js

@@ -562,7 +562,27 @@ async function getStatisticsInfoV2(day) {
 }
 
 
-
+const request = async (url, app_token, data) => {
+    logger.info('request', url, app_token, data)
+    return new Promise(resolve => {
+        axios.post(url,
+            JSON.stringify(data),
+            {
+                timeout: 1 * 60 * 1000,
+                headers: {
+                    'Content-Type': "application/json; charset=utf-8",
+                    'Authorization': 'Bearer ' + app_token
+                }
+            })
+            .then(res => {
+                console.log('res=>', res.status, res.data);
+                resolve(res.data)
+            }).catch(err => {
+                logger.error('error ', JSON.stringify(err));
+                resolve(JSON.stringify(err))
+            });
+    })
+}
 
 
 
@@ -797,11 +817,24 @@ async function addTableRows(app_token, sheetId, endIndex) {
     })
 }
 
-async function exec(data) {
-    var app = await getFeishuToken()
+async function exec(data, app) {
+
 
     await insertTableRows(app.app_access_token, 'BMjMDr', 2, 3)
     return await writeTable(app.app_access_token, data)
+
+
+}
+
+
+async function notify(app,chain_id) {
+    var content = "{\"zh_cn\":{\"title\":\"出入金数据更新成功\",\"content\":[[{\"tag\":\"text\",\"text\":\"更新时间:\"},{\"tag\":\"text\",\"text\":\"" + utils.getCurrentDate() + "\"}],[{\"tag\":\"text\",\"text\":\"https://st94nif1cq.feishu.cn/sheets/shtcnp6zbrsep1Sz3Cvk7NXRpDg?sheet=BMjMDr:\"}]]}}"
+    var data = {
+        "receive_id": chain_id,
+        "content": content,
+        "msg_type": "post"
+    }
+    await request('https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=chat_id', app.app_access_token, data)
 }
 
 async function report2FeishuTable(day) {
@@ -811,7 +844,9 @@ async function report2FeishuTable(day) {
         var data = await getStatisticsInfoV2(day);
         // data = ''
         logger.info('getStatisticsInfo', data)
-        var ret = await exec(data)
+        var app = await getFeishuToken()
+        var ret = await exec(data, app)
+        notify(app,'oc_9770d283cd81df887e96795ddfcd9dcd')
         logger.error('数据统计完成:', 'https://st94nif1cq.feishu.cn/sheets/shtcnp6zbrsep1Sz3Cvk7NXRpDg?sheet=BMjMDr')
         mTokenPriceCache.clear()
     } catch (error) {
@@ -819,6 +854,10 @@ async function report2FeishuTable(day) {
     }
 }
 
+async function testNotify() {
+    var app = await getFeishuToken()
+    notify(app,'oc_b159b9a53dd52206c5cf75677d0cf0ca')
+}
 
 async function test() {
     // var ret = await getStatisticsInfoV2(2)
@@ -830,6 +869,7 @@ async function test() {
 }
 // test()
 // exec()
+// testNotify()
 module.exports = {
     getStatisticsInfoV2
 }