SyncCheckinDay3

This commit is contained in:
jiangyong27 2024-01-17 22:30:38 +08:00
parent 1b03179ad6
commit 124e179058
8 changed files with 56 additions and 65 deletions

View File

@ -25,8 +25,6 @@ func main22() {
global.InitGlobal() global.InitGlobal()
//cfg := config.GetConfig() //cfg := config.GetConfig()
new(worker.Checkin).SyncCheckinDay("2024-01-10") new(worker.Checkin).SyncCheckinDay("2024-01-16")
new(worker.Checkin).SyncCheckinDay("2024-01-11")
new(worker.Checkin).SyncCheckinDay("2024-01-12")
} }

View File

@ -10,11 +10,12 @@ import (
) )
var ( var (
urlGetToken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" urlGetToken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"
urlGetCheckinRlue = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption" urlGetCheckinRlue = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption"
urlGetCheckinData = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata" urlGetCheckinData = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata"
urlConvertOpenid = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid" urlConvertOpenid = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid"
urlGetUser = "https://qyapi.weixin.qq.com/cgi-bin/user/get" urlGetUser = "https://qyapi.weixin.qq.com/cgi-bin/user/get"
urlGetDepartmentUser = "https://qyapi.weixin.qq.com/cgi-bin/user/list"
) )
type QyWeixin struct { type QyWeixin struct {
@ -99,6 +100,30 @@ func (q *QyWeixin) GetUserInfo(userid string) (*UserInfo, error) {
return userInfo, nil return userInfo, nil
} }
func (q *QyWeixin) GetDepartmentUserid(departmentId int) ([]string, error) {
if err := q.refreshToken(); err != nil {
return nil, err
}
reqUrl := fmt.Sprintf("%s?access_token=%s&department_id=%d", urlGetDepartmentUser, q.GetToken(), departmentId)
rspBody, err := butil.HttpGet(reqUrl, nil)
if err != nil {
log.Errorf("httpPost url[%s] error :%s", reqUrl, err.Error())
return nil, err
}
result, err := q.GetResult(rspBody)
if err != nil {
return nil, err
}
userids := make([]string, 0)
userlist := cast.ToSlice(result["userlist"])
for _, u := range userlist {
user := cast.ToStringMap(u)
userids = append(userids, cast.ToString(user["userid"]))
}
return userids, nil
}
func (q *QyWeixin) refreshToken() error { func (q *QyWeixin) refreshToken() error {
if time.Now().Unix() <= q.tokenExpire-600 { if time.Now().Unix() <= q.tokenExpire-600 {
return nil return nil

View File

@ -47,13 +47,9 @@ func (q *QyWeixinCheckin) GetCheckinEmployee(groupIds []string) ([]string, error
if err != nil { if err != nil {
return nil, err return nil, err
} }
result := make(map[string]interface{}) result, err := q.GetResult(rspBody)
if err := json.Unmarshal(rspBody, &result); err != nil { if err != nil {
log.Errorf("http url[%s] result[%s] error :%s", reqUrl, string(rspBody), err.Error()) log.Errorf("q.GetResult error :%s ", err.Error())
return nil, err
}
if cast.ToInt(result["errcode"]) != 0 {
log.Errorf("http url[%s] result[%s] error ", reqUrl, string(rspBody))
return nil, errors.New(string(rspBody)) return nil, errors.New(string(rspBody))
} }
@ -66,6 +62,19 @@ func (q *QyWeixinCheckin) GetCheckinEmployee(groupIds []string) ([]string, error
} }
ranges := cast.ToStringMap(g["range"]) ranges := cast.ToStringMap(g["range"])
userid := cast.ToStringSlice(ranges["userid"]) userid := cast.ToStringSlice(ranges["userid"])
//包含部门获取部门下的员工
departmentIds := cast.ToIntSlice(ranges["party_id"])
if len(departmentIds) != 0 {
for _, did := range departmentIds {
uids, err := q.GetDepartmentUserid(did)
if err != nil {
log.Errorf(" q.GetDepartmentUserid did[%d] error :%s", did, err.Error())
continue
}
resultUser = append(resultUser, uids...)
}
}
resultUser = append(resultUser, userid...) resultUser = append(resultUser, userid...)
} }
return resultUser, nil return resultUser, nil

View File

@ -4,7 +4,7 @@ address = "0.0.0.0:9283"
log_level = 6 log_level = 6
[mysql] [mysql]
host = "14.22.113.49" host = "14.22.116.197"
port = 9305 port = 9305
user = "root" user = "root"
pass = "ZW5aaGVuMIIBIj" pass = "ZW5aaGVuMIIBIj"

View File

@ -1,41 +0,0 @@
[server]
address = "0.0.0.0:9283"
#0:PAINC 1:FATAL 2:ERROR 3:WARNING 4:INFO 5:DEBUG 6:TRACE
log_level = 6
[mysql]
host = "14.22.113.49"
port = 9305
user = "root"
pass = "ZW5aaGVuMIIBIj"
db = "enterprise"
[redis]
addr="127.0.0.1:6379"
db=0
password=""
[qyweixin]
corpid = "ww43c49db2e88a17f8"
hr_agent = "3010185"
hr_secret = "Ko2UQWZPbdM9N1snukp_1CT_3J7CcReyPAzl3ww2xoo"
enterprise_agent = "1000009"
enterprise_secret = "oMB24UhKe50-XPTg7vhnwoTuhEXaq5XeiHPAUtF4hOs"
approve_agent = "3010040"
approve_secret = "xJOClC5V2pPon1azgrAzf5kq1TB72xZ3ScR7O5G3lQo"
checkin_agent = "3010011"
checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU"
checkin_group = "1,2"
checkin_pay_thresold = 11
checkin_onduty_pay_day = ""
pay_secret = "JCGsxntR4E7wrEEQvWGr8_wdKtRlw48n-W6zd8lbwc4"
pay_agent = "3010046"
[wxpay]
pay_key_pem = "conf/wxpay/apiclient_key.pem"
pay_cert_pem = "conf/wxpay/apiclient_cert.pem"
pay_mchid = "1644152531"
pay_serial_number = "32933D9C64A63985F96DC26FD714D7B1EFAE682F"
pay_api_key_v3 = "fe84a99b2fcc2e393b19f37792ee2cd1"
pay_api_key_v2 = "fe84a99b2fcc2e393b19f37792ee2cd1"

View File

@ -4,8 +4,8 @@ address = "0.0.0.0:9283"
log_level = 6 log_level = 6
[mysql] [mysql]
host = "127.0.0.1" host = "10.0.2.157"
port = 3307 port = 3308
user = "root" user = "root"
pass = "ZW5aaGVuMIIBIj" pass = "ZW5aaGVuMIIBIj"
db = "enterprise" db = "enterprise"

View File

@ -76,13 +76,13 @@ func (c *Checkin) saveToDB(user *weixin.UserCheckIn) error {
checkin.Month = user.Month checkin.Month = user.Month
checkin.Username = user.UserId checkin.Username = user.UserId
isNew = true isNew = true
} else {
checkin.Exception = user.Exception
checkin.StartTime = user.StartTime
checkin.EndTime = user.EndTime
checkin.Month = user.Month
} }
checkin.Exception = user.Exception
checkin.StartTime = user.StartTime
checkin.EndTime = user.EndTime
checkin.Month = user.Month
if isNew { if isNew {
_, err = dao.NewCheckinDao().Create(checkin) _, err = dao.NewCheckinDao().Create(checkin)
} else { } else {

View File

@ -17,7 +17,7 @@ func Init() error {
}) })
//同步每日考勤数据 //同步每日考勤数据
cron.Every(1).Day().At("10:00").Do(func() { cron.Every(1).Day().At("05:00").Do(func() {
go checkIn.SyncCheckinDay("") go checkIn.SyncCheckinDay("")
}) })