From 9686088e4b8c494cd82b578169968ef5a83ffcdd Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Fri, 4 Aug 2023 20:43:26 +0800 Subject: [PATCH] max time --- common/qyweixin/qyweixin.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common/qyweixin/qyweixin.go b/common/qyweixin/qyweixin.go index 6cc1c3a..fe4b25f 100644 --- a/common/qyweixin/qyweixin.go +++ b/common/qyweixin/qyweixin.go @@ -9,6 +9,7 @@ import ( "github.com/smbrave/goutil" "github.com/spf13/cast" "gorm.io/gorm/utils" + "math" "strings" "time" ) @@ -125,20 +126,32 @@ func (q *QyWeixin) GetCheckinData(day, userId string) (*UserCheckIn, error) { userData.UserId = userId exception := make([]string, 0) isException := false + startTime := int64(math.MaxInt64) + endTime := int64(0) for _, checkdata := range checkindatas { c := cast.ToStringMap(checkdata) checkinType := cast.ToString(c["checkin_type"]) exceptionType := cast.ToString(c["exception_type"]) + checkinTime := cast.ToInt64(c["checkin_time"]) if exceptionType != "" { isException = true } + exception = append(exception, exceptionType) if checkinType == "上班打卡" { - userData.StartTime = cast.ToInt64(c["checkin_time"]) + if checkinTime < startTime { + startTime = checkinTime + } } else if checkinType == "下班打卡" { - userData.EndTime = cast.ToInt64(c["checkin_time"]) + if checkinTime > endTime { + endTime = checkinTime + } } } + if startTime != int64(math.MaxInt64) { + userData.StartTime = startTime + } + userData.EndTime = endTime userData.Rawdata = goutil.EncodeJSON(checkindatas) if isException { userData.Exception = strings.Join(exception, ",")