This commit is contained in:
jiangyong27 2023-08-04 20:35:50 +08:00
parent e58acb28d9
commit 431b36a2b1
6 changed files with 34 additions and 5 deletions

View File

@ -5,6 +5,7 @@ type Checkin struct {
UserId string UserId string
Day string Day string
Exception string Exception string
Rawdata string
StartTime int64 StartTime int64
EndTime int64 EndTime int64
CreateTime int64 CreateTime int64

View File

@ -2,6 +2,8 @@ package qyweixin
type UserCheckIn struct { type UserCheckIn struct {
UserId string UserId string
Exception string
Rawdata string
StartTime int64 StartTime int64
EndTime int64 EndTime int64
} }

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"
"strings"
"time" "time"
) )
@ -122,15 +123,26 @@ func (q *QyWeixin) GetCheckinData(day, userId string) (*UserCheckIn, error) {
checkindatas := cast.ToSlice(result["checkindata"]) checkindatas := cast.ToSlice(result["checkindata"])
userData := new(UserCheckIn) userData := new(UserCheckIn)
userData.UserId = userId userData.UserId = userId
exception := make([]string, 0)
isException := false
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"])
if exceptionType != "" {
isException = true
}
exception = append(exception, exceptionType)
if checkinType == "上班打卡" { if checkinType == "上班打卡" {
userData.StartTime = cast.ToInt64(c["checkin_time"]) userData.StartTime = cast.ToInt64(c["checkin_time"])
} else if checkinType == "下班打卡" { } else if checkinType == "下班打卡" {
userData.EndTime = cast.ToInt64(c["checkin_time"]) userData.EndTime = cast.ToInt64(c["checkin_time"])
} }
} }
userData.Rawdata = goutil.EncodeJSON(checkindatas)
if isException {
userData.Exception = strings.Join(exception, ",")
}
if userData.EndTime == 0 && userData.StartTime == 0 { if userData.EndTime == 0 && userData.StartTime == 0 {
return nil, nil return nil, nil
} }

View File

@ -4,6 +4,7 @@ import (
"enterprise/common/config" "enterprise/common/config"
"enterprise/common/global" "enterprise/common/global"
"enterprise/common/model" "enterprise/common/model"
"fmt"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil" "github.com/smbrave/goutil"
"strings" "strings"
@ -21,11 +22,11 @@ func ViewCheckin(checkin *model.Checkin) {
return return
} }
message := make([]string, 0) message := make([]string, 0)
message = append(message, "员工名称:%s", checkin.UserId) message = append(message, fmt.Sprintf("员工名称:%s", checkin.UserId))
message = append(message, "考勤日期:%s", checkin.Day) message = append(message, fmt.Sprintf("考勤日期:%s", checkin.Day))
message = append(message, "开始时间:%s", goutil.TimeToDateTime(checkin.StartTime)) message = append(message, fmt.Sprintf("开始时间:%s", goutil.TimeToDateTime(checkin.StartTime)))
message = append(message, "结束时间:%s", goutil.TimeToDateTime(checkin.EndTime)) message = append(message, fmt.Sprintf("结束时间:%s", goutil.TimeToDateTime(checkin.EndTime)))
message = append(message, "工作时长:%s", (time.Duration(duration) * time.Second).String()) message = append(message, fmt.Sprintf("工作时长:%s", (time.Duration(duration)*time.Second).String()))
if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil {
log.Errorf("send message error :%s", err.Error()) log.Errorf("send message error :%s", err.Error())

View File

@ -49,6 +49,11 @@ func SyncCheckin(day string) error {
isUpdate = true isUpdate = true
checkin.EndTime = realCheckin.EndTime checkin.EndTime = realCheckin.EndTime
} }
if realCheckin.Exception != "" && realCheckin.Exception != checkin.Exception {
checkin.Exception = realCheckin.Exception
isUpdate = true
}
checkin.Rawdata = realCheckin.Rawdata
if isNew { if isNew {
_, err = checkinDao.Create(checkin) _, err = checkinDao.Create(checkin)
} else { } else {

View File

@ -5,6 +5,14 @@ import (
"time" "time"
) )
func Init1() error {
for i := 0; i < 120; i++ {
day := time.Now().AddDate(0, 0, -1-i).Format("2006-01-02")
SyncCheckin(day)
}
return nil
}
func Init() error { func Init() error {
timezone, _ := time.LoadLocation("Asia/Shanghai") timezone, _ := time.LoadLocation("Asia/Shanghai")
cron := gocron.NewScheduler(timezone) cron := gocron.NewScheduler(timezone)