Merge branch 'master' of git.u8t.cn:open/gosdk

This commit is contained in:
jiangyong27 2025-03-12 17:49:18 +08:00
commit e8509f60d0
1 changed files with 78 additions and 1 deletions

View File

@ -8,7 +8,9 @@ import (
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
"github.com/tidwall/gjson"
"gorm.io/gorm/utils"
"strings"
"time"
)
@ -16,6 +18,7 @@ type UserCheckIn struct {
Day string
Month string
UserId string
UserName string
Exception string
Rawdata string
StartTime int64
@ -118,6 +121,7 @@ func (q *AppCheckin) GetCheckinData(startDay, endDay string, userIds []string) (
key := fmt.Sprintf("%s_%s", userid, checkDay)
var userData *UserCheckIn = nil
var ok bool
if userData, ok = checkData[key]; !ok {
userData = new(UserCheckIn)
userData.UserId = userid
@ -129,11 +133,14 @@ func (q *AppCheckin) GetCheckinData(startDay, endDay string, userIds []string) (
userData.Exception += goutil.If(userData.Exception != "", ",", "")
userData.Exception += checkinType + ":" + exceptionType
}
userData.Rawdata = goutil.If(userData.Rawdata == "", "", "\n") + goutil.EncodeJSON(dat)
userData.Rawdata += goutil.If(userData.Rawdata == "", "", "\n") + goutil.EncodeJSON(dat)
if checkinType == "上班打卡" {
userData.StartTime = goutil.If(userData.StartTime == 0 || checkinTime < userData.StartTime, checkinTime, userData.StartTime)
userData.StartTime = goutil.If(strings.Contains(exceptionType, "未打卡"), 0, userData.StartTime)
} else if checkinType == "下班打卡" {
userData.EndTime = goutil.If(checkinTime > userData.EndTime, checkinTime, userData.EndTime)
userData.EndTime = goutil.If(strings.Contains(exceptionType, "未打卡"), 0, userData.EndTime)
} else {
log.Errorf("不支持的打卡类型:%s %s", checkinType, goutil.EncodeJSON(dat))
}
@ -148,3 +155,73 @@ 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 - 1
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() {
ruleCheckinTimes := dat.Get("base_info.rule_info.checkintime").Array()
if len(ruleCheckinTimes) < 1 {
continue
}
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 = dat.Raw
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 {
if earliestTime <= ruleCheckinTimes[0].Get("off_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
}