diff --git a/cmd/enterprise.go b/cmd/enterprise.go index 58a5b3b..9cd99cc 100644 --- a/cmd/enterprise.go +++ b/cmd/enterprise.go @@ -25,8 +25,6 @@ func main22() { global.InitGlobal() //cfg := config.GetConfig() - new(worker.Checkin).SyncCheckinDay("2024-01-10") - new(worker.Checkin).SyncCheckinDay("2024-01-11") - new(worker.Checkin).SyncCheckinDay("2024-01-12") + new(worker.Checkin).SyncCheckinDay("2024-01-16") } diff --git a/common/weixin/qyweixin.go b/common/weixin/qyweixin.go index 1eefccb..e330a7f 100644 --- a/common/weixin/qyweixin.go +++ b/common/weixin/qyweixin.go @@ -10,11 +10,12 @@ import ( ) var ( - urlGetToken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" - urlGetCheckinRlue = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption" - urlGetCheckinData = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata" - urlConvertOpenid = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid" - urlGetUser = "https://qyapi.weixin.qq.com/cgi-bin/user/get" + urlGetToken = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" + urlGetCheckinRlue = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcorpcheckinoption" + urlGetCheckinData = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata" + urlConvertOpenid = "https://qyapi.weixin.qq.com/cgi-bin/user/convert_to_openid" + urlGetUser = "https://qyapi.weixin.qq.com/cgi-bin/user/get" + urlGetDepartmentUser = "https://qyapi.weixin.qq.com/cgi-bin/user/list" ) type QyWeixin struct { @@ -99,6 +100,30 @@ func (q *QyWeixin) GetUserInfo(userid string) (*UserInfo, error) { 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 { if time.Now().Unix() <= q.tokenExpire-600 { return nil diff --git a/common/weixin/qyweixin_checkin.go b/common/weixin/qyweixin_checkin.go index de4b14d..70f19d2 100644 --- a/common/weixin/qyweixin_checkin.go +++ b/common/weixin/qyweixin_checkin.go @@ -47,13 +47,9 @@ func (q *QyWeixinCheckin) GetCheckinEmployee(groupIds []string) ([]string, error if err != nil { return nil, err } - result := make(map[string]interface{}) - if err := json.Unmarshal(rspBody, &result); err != nil { - log.Errorf("http url[%s] result[%s] error :%s", reqUrl, string(rspBody), err.Error()) - return nil, err - } - if cast.ToInt(result["errcode"]) != 0 { - log.Errorf("http url[%s] result[%s] error ", reqUrl, string(rspBody)) + result, err := q.GetResult(rspBody) + if err != nil { + log.Errorf("q.GetResult error :%s ", err.Error()) return nil, errors.New(string(rspBody)) } @@ -66,6 +62,19 @@ func (q *QyWeixinCheckin) GetCheckinEmployee(groupIds []string) ([]string, error } ranges := cast.ToStringMap(g["range"]) 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...) } return resultUser, nil diff --git a/conf/server.conf.dev b/conf/server.conf.dev index 4067d7d..1e79919 100644 --- a/conf/server.conf.dev +++ b/conf/server.conf.dev @@ -4,7 +4,7 @@ address = "0.0.0.0:9283" log_level = 6 [mysql] -host = "14.22.113.49" +host = "14.22.116.197" port = 9305 user = "root" pass = "ZW5aaGVuMIIBIj" diff --git a/conf/server.conf.mac b/conf/server.conf.mac deleted file mode 100644 index 0bce6d8..0000000 --- a/conf/server.conf.mac +++ /dev/null @@ -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" diff --git a/conf/server.conf.prod b/conf/server.conf.prod index 5134d51..9285dd1 100644 --- a/conf/server.conf.prod +++ b/conf/server.conf.prod @@ -4,8 +4,8 @@ address = "0.0.0.0:9283" log_level = 6 [mysql] -host = "127.0.0.1" -port = 3307 +host = "10.0.2.157" +port = 3308 user = "root" pass = "ZW5aaGVuMIIBIj" db = "enterprise" diff --git a/worker/checkin.go b/worker/checkin.go index ad9cc9c..77d263b 100644 --- a/worker/checkin.go +++ b/worker/checkin.go @@ -76,13 +76,13 @@ func (c *Checkin) saveToDB(user *weixin.UserCheckIn) error { checkin.Month = user.Month checkin.Username = user.UserId 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 { _, err = dao.NewCheckinDao().Create(checkin) } else { diff --git a/worker/worker.go b/worker/worker.go index a826a5f..b5306a0 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -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("") })