This commit is contained in:
jiangyong27 2023-08-04 20:43:26 +08:00
parent 431b36a2b1
commit 9686088e4b
1 changed files with 15 additions and 2 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"github.com/spf13/cast" "github.com/spf13/cast"
"gorm.io/gorm/utils" "gorm.io/gorm/utils"
"math"
"strings" "strings"
"time" "time"
) )
@ -125,20 +126,32 @@ func (q *QyWeixin) GetCheckinData(day, userId string) (*UserCheckIn, error) {
userData.UserId = userId userData.UserId = userId
exception := make([]string, 0) exception := make([]string, 0)
isException := false isException := false
startTime := int64(math.MaxInt64)
endTime := int64(0)
for _, checkdata := range checkindatas { for _, checkdata := range checkindatas {
c := cast.ToStringMap(checkdata) c := cast.ToStringMap(checkdata)
checkinType := cast.ToString(c["checkin_type"]) checkinType := cast.ToString(c["checkin_type"])
exceptionType := cast.ToString(c["exception_type"]) exceptionType := cast.ToString(c["exception_type"])
checkinTime := cast.ToInt64(c["checkin_time"])
if exceptionType != "" { if exceptionType != "" {
isException = true isException = true
} }
exception = append(exception, exceptionType) exception = append(exception, exceptionType)
if checkinType == "上班打卡" { if checkinType == "上班打卡" {
userData.StartTime = cast.ToInt64(c["checkin_time"]) if checkinTime < startTime {
startTime = checkinTime
}
} else if checkinType == "下班打卡" { } 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) userData.Rawdata = goutil.EncodeJSON(checkindatas)
if isException { if isException {
userData.Exception = strings.Join(exception, ",") userData.Exception = strings.Join(exception, ",")