checkin
This commit is contained in:
parent
54dfc300c0
commit
cfc44a71a5
|
@ -8,6 +8,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/smbrave/goutil"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/tidwall/gjson"
|
||||
"gorm.io/gorm/utils"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -17,6 +18,7 @@ type UserCheckIn struct {
|
|||
Day string
|
||||
Month string
|
||||
UserId string
|
||||
UserName string
|
||||
Exception string
|
||||
Rawdata string
|
||||
StartTime int64
|
||||
|
@ -153,3 +155,69 @@ func (q *AppCheckin) GetCheckinData(startDay, endDay string, userIds []string) (
|
|||
}
|
||||
return userDatas, nil
|
||||
}
|
||||
|
||||
func (q *AppCheckin) GetCheckinDataV2(startDay, endDay string, userIds []string) ([]*UserCheckIn, error) {
|
||||
|
||||
dayTime, _ := time.ParseInLocation("2006-01-02", startDay, time.Local)
|
||||
endTime, _ := time.ParseInLocation("2006-01-02", endDay, time.Local)
|
||||
|
||||
reqData := make(map[string]interface{})
|
||||
reqData["starttime"] = dayTime.Unix()
|
||||
reqData["endtime"] = endTime.Unix() + 86400
|
||||
reqData["useridlist"] = userIds
|
||||
reqUrl := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=%s", q.GetToken())
|
||||
rspBody, err := util.HttpPostJson(reqUrl, nil, []byte(goutil.EncodeJSON(reqData)))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
g := gjson.ParseBytes(rspBody)
|
||||
if g.Get("errcode").Int() != 0 {
|
||||
log.Errorf("http url[%s] result[%s] error ", reqUrl, string(rspBody))
|
||||
return nil, errors.New(string(rspBody))
|
||||
}
|
||||
|
||||
userDatas := make([]*UserCheckIn, 0)
|
||||
for _, dat := range g.Get("datas").Array() {
|
||||
userData := new(UserCheckIn)
|
||||
dayTimestamp := dat.Get("base_info.date").Int()
|
||||
userId := dat.Get("base_info.acctid").String()
|
||||
userName := dat.Get("base_info.name").String()
|
||||
summaryInfo := dat.Get("summary_info").Map()
|
||||
earliestTime := summaryInfo["earliest_time"].Int()
|
||||
lastestTime := summaryInfo["lastest_time"].Int()
|
||||
userData.Day = time.Unix(dayTimestamp, 0).Format("2006-01-02")
|
||||
userData.Month = time.Unix(dayTimestamp, 0).Format("200601")
|
||||
userData.UserId = userId
|
||||
userData.UserName = userName
|
||||
userData.Rawdata = goutil.EncodeJSON(dat)
|
||||
|
||||
if earliestTime > 0 {
|
||||
userData.StartTime = dayTimestamp + earliestTime
|
||||
}
|
||||
if lastestTime > 0 {
|
||||
userData.EndTime = dayTimestamp + lastestTime
|
||||
}
|
||||
|
||||
if lastestTime == 0 || earliestTime == 0 {
|
||||
userData.Exception = "上班未打卡;下班未打卡"
|
||||
userDatas = append(userDatas, userData)
|
||||
continue
|
||||
}
|
||||
|
||||
if earliestTime == lastestTime {
|
||||
ruleCheckinTimes := dat.Get("base_info.rule_info.checkintime").Array()
|
||||
if earliestTime < ruleCheckinTimes[1].Get("work_sec").Int() {
|
||||
userData.Exception = "下班未打卡"
|
||||
} else {
|
||||
userData.Exception = "上班未打卡"
|
||||
}
|
||||
} else {
|
||||
if dat.Get("summary_info.regular_work_sec").Int() < dat.Get("summary_info.standard_work_sec").Int() {
|
||||
userData.Exception = "出勤异常"
|
||||
}
|
||||
}
|
||||
userDatas = append(userDatas, userData)
|
||||
}
|
||||
|
||||
return userDatas, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue