Skip to content

Commit 3fa6973

Browse files
committed
新增定时推送打卡的能力
Signed-off-by: wss <[email protected]>
1 parent ac31e98 commit 3fa6973

File tree

10 files changed

+218
-0
lines changed

10 files changed

+218
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.s
3+
.env

dingding-attendance/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
webhook='https://oapi.dingtalk.com/robot/send?access_token=xxx'
2+
secret='xxxxx'

dingding-attendance/code/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
const { default: DingTalk } = require('@serverless-cd/ding-talk');
3+
const { getNeedWork } = require('./utile');
4+
5+
exports.handler = async (event, context, callback) => {
6+
const needWork = getNeedWork();
7+
console.log('needWork: ', needWork);
8+
if (!needWork) {
9+
return callback();
10+
}
11+
const { payload: content } = JSON.parse(event.toString());
12+
const webhook = process.env.webhook;
13+
14+
const dingTalk = new DingTalk({
15+
webhook,
16+
msgtype: 'text',
17+
at: { isAtAll: true },
18+
secret: process.env.secret,
19+
payload: { content }
20+
});
21+
22+
await dingTalk.send();
23+
callback(null, content);
24+
}

dingding-attendance/code/package-lock.json

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dingding-attendance/code/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@serverless-cd/ding-talk": "^0.0.5",
4+
"dayjs": "^1.11.7"
5+
}
6+
}

dingding-attendance/code/utile.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const dayjs = require('dayjs');
2+
const years = require('./years');
3+
4+
function getNationalRegulations(today = dayjs().format('MM.DD')) {
5+
const currentYear = years[dayjs().get('year')];
6+
7+
if (currentYear) {
8+
const { work, holiday } = currentYear;
9+
if (work.includes(today)) {
10+
return 'work';
11+
}
12+
if (holiday.includes(today)) {
13+
return 'holiday';
14+
}
15+
} else {
16+
console.log('没有找到假期安排表');
17+
}
18+
return '';
19+
}
20+
21+
function getNeedWork(timeStamp) {
22+
if (!timeStamp) {
23+
timeStamp = dayjs().valueOf();
24+
}
25+
const nationalRegulations = getNationalRegulations(dayjs(timeStamp).format('MM.DD'));
26+
console.log('nationalRegulations: ', nationalRegulations);
27+
if (nationalRegulations === 'holiday') {
28+
return false;
29+
} else if (nationalRegulations === 'work') {
30+
return true;
31+
}
32+
33+
const d = dayjs().get('day');
34+
console.log('周: ', d + 1);
35+
return ![0, 6].includes(d);
36+
}
37+
38+
module.exports = {
39+
getNeedWork,
40+
getNationalRegulations,
41+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
module.exports = {
2+
work: [
3+
'01.28',
4+
'01.29',
5+
'04.23',
6+
'05.06',
7+
'06.25',
8+
'10.07',
9+
'10.08',
10+
],
11+
holiday: [
12+
'01.01',
13+
'01.02',
14+
'01.21',
15+
'01.22',
16+
'01.23',
17+
'01.24',
18+
'01.25',
19+
'01.26',
20+
'01.27',
21+
'04.05',
22+
'04.29',
23+
'04.30',
24+
'05.01',
25+
'05.02',
26+
'05.03',
27+
'06.22',
28+
'06.23',
29+
'06.24',
30+
'09.29',
31+
'09.30',
32+
'10.01',
33+
'10.02',
34+
'10.03',
35+
'10.04',
36+
'10.05',
37+
'10.06',
38+
],
39+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
2023: require('./2023'),
3+
}

dingding-attendance/readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## 需要新建 .env 文件
2+
3+
webhook:钉钉机器人的 webhook 地址
4+
secret:钉钉机器人的加签算法密钥
5+
6+
## 需要在 year 里面输入每一年的国家规定安排

dingding-attendance/s.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
edition: 1.0.0
2+
name: compoent-test
3+
access: wss-root
4+
services:
5+
cn-shenzhen-dingding-attendance-timer:
6+
component: devsapp/fc
7+
props:
8+
region: cn-hangzhou
9+
service:
10+
description: 定时提醒打卡
11+
internetAccess: true
12+
name: dingding-attendance
13+
function:
14+
handler: index.handler
15+
timeout: 60
16+
diskSize: 512
17+
instanceType: e1
18+
runtime: nodejs16
19+
cpu: 0.05
20+
instanceConcurrency: 1
21+
memorySize: 128
22+
name: timer
23+
codeUri: ./code
24+
environmentVariables:
25+
webhook: ${env.webhook}
26+
secret: ${env.secret}
27+
triggers:
28+
- name: evening
29+
description: ''
30+
type: timer
31+
qualifier: LATEST
32+
config:
33+
payload: 已经下班了,打卡了哈
34+
cronExpression: CRON_TZ=Asia/Shanghai 0 30 18 * * MON,TUE,WED,THU,FRI,SAT,SUN
35+
enable: true
36+
- name: morning
37+
description: ''
38+
type: timer
39+
qualifier: LATEST
40+
config:
41+
payload: 即将开始搬砖,打卡了吗?昨天打卡了吗?提的审批通过了吗?
42+
cronExpression: CRON_TZ=Asia/Shanghai 30 27 9 * * MON,WED,TUE,THU,FRI,SUN,SAT
43+
enable: true
44+
- name: pre-evening
45+
description: ''
46+
type: timer
47+
qualifier: LATEST
48+
config:
49+
payload: 即将下班了,注意要打卡了
50+
cronExpression: CRON_TZ=Asia/Shanghai 0 28 18 * * MON,TUE,WED,THU,FRI,SUN,SAT
51+
enable: true
52+
- name: trigger-hb640075
53+
description: ''
54+
type: timer
55+
qualifier: LATEST
56+
config:
57+
payload: 敌军已经到达战场,打卡了吗?昨天打卡了吗?提的审批通过了吗?
58+
cronExpression: CRON_TZ=Asia/Shanghai 0 28 9 * * MON,TUE,THU,WED,FRI,SAT,SUN
59+
enable: true

0 commit comments

Comments
 (0)