-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_kqyc.py
More file actions
91 lines (79 loc) · 3.12 KB
/
api_kqyc.py
File metadata and controls
91 lines (79 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# -*- coding: utf-8 -*-
"""
cron: 0 9 * * *
new Env('我的考勤异常');
"""
import json
import requests
import datetime
import calendar
from notify_mtr import send
from my_util import get_user_id
from utils import get_data
from my_email_util import sendMail
class KQYC:
def __init__(self, check_items):
self.check_items = check_items
def get_kq(self, url, emp_no):
data = get_data()
user_id = get_user_id(emp_no)
month = datetime.datetime.now().month
year = datetime.datetime.now().year
day = str(calendar.monthrange(year, month)[1])
first_day = str(year) + '-' + str(month) + '-' + '1'
last_day = str(year) + '-' + str(month) + '-' + day
headers = {
'x-emp-id': user_id,
'x-emp-no': emp_no,
'x-lang-id': 'zh_CN',
'x-tenant-id': '10000',
'User-Agent': data.get('EMP_USER_AGENT'),
'Content-Type': 'application/json'
}
payload = {
"command": "KQ-JG-002",
"params": {
"pageDTO": {
"pageSize": "100",
"pageNo": "1"
},
"startDate": first_day,
"endDate": last_day,
"displayType": "01",
"empId": user_id
}
}
response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
abnormalAttendancTimes = str(json.loads(response.text)['bo']['abnormalAttendancTimes'])
absenceTimes = str(json.loads(response.text)['bo']['abnormalAttendanceStatisticDTO']['absenceTimes'])
lateOrLeaveEarlyTimes = str(json.loads(response.text)['bo']
['abnormalAttendanceStatisticDTO']
['lateOrLeaveEarlyTimes'])
realInWorkTimes = str(json.loads(response.text)['bo']
['abnormalAttendanceStatisticDTO']
['realInWorkTimes'])
return abnormalAttendancTimes, absenceTimes, lateOrLeaveEarlyTimes, realInWorkTimes
def main(self):
msg_all = ''
has_abnormal = False
url = self.check_items.get('url')
for check_item in self.check_items.get('emp_info'):
emp_no = check_item.get('emp_no')
abnormalAttendancTimes, absenceTimes, lateOrLeaveEarlyTimes, realInWorkTimes = self.get_kq(url, emp_no)
msg_all = "本月上班" + realInWorkTimes + "天," + "异常考勤:" + abnormalAttendancTimes + "次" + "\n"
msg_all += "其中缺席:" + absenceTimes + "次" + "\n"
msg_all += "迟到早退:" + lateOrLeaveEarlyTimes + "次" + "\n"
has_abnormal = has_abnormal or int(abnormalAttendancTimes) > 0
if has_abnormal:
send("异常考勤提醒", msg_all)
sendMail(msg_all, '考勤通知')
else:
print('无异常考勤,跳过通知')
return msg_all
def start():
data = get_data()
_check_items = data.get('KQYC', [])
res = KQYC(check_items=_check_items).main()
print(res)
if __name__ == '__main__':
start()