From 431b36a2b1c4a0b90c9a382ac1c64f6602bcb644 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Fri, 4 Aug 2023 20:35:50 +0800 Subject: [PATCH] message2 --- common/model/checkin.go | 1 + common/qyweixin/checkin.go | 2 ++ common/qyweixin/qyweixin.go | 12 ++++++++++++ worker/autopay.go | 11 ++++++----- worker/checkin.go | 5 +++++ worker/worker.go | 8 ++++++++ 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/common/model/checkin.go b/common/model/checkin.go index fc9683c..cf7f54b 100644 --- a/common/model/checkin.go +++ b/common/model/checkin.go @@ -5,6 +5,7 @@ type Checkin struct { UserId string Day string Exception string + Rawdata string StartTime int64 EndTime int64 CreateTime int64 diff --git a/common/qyweixin/checkin.go b/common/qyweixin/checkin.go index caedba2..cb13ae8 100644 --- a/common/qyweixin/checkin.go +++ b/common/qyweixin/checkin.go @@ -2,6 +2,8 @@ package qyweixin type UserCheckIn struct { UserId string + Exception string + Rawdata string StartTime int64 EndTime int64 } diff --git a/common/qyweixin/qyweixin.go b/common/qyweixin/qyweixin.go index bd673e6..6cc1c3a 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" + "strings" "time" ) @@ -122,15 +123,26 @@ func (q *QyWeixin) GetCheckinData(day, userId string) (*UserCheckIn, error) { checkindatas := cast.ToSlice(result["checkindata"]) userData := new(UserCheckIn) userData.UserId = userId + exception := make([]string, 0) + isException := false for _, checkdata := range checkindatas { c := cast.ToStringMap(checkdata) checkinType := cast.ToString(c["checkin_type"]) + exceptionType := cast.ToString(c["exception_type"]) + if exceptionType != "" { + isException = true + } + exception = append(exception, exceptionType) if checkinType == "上班打卡" { userData.StartTime = cast.ToInt64(c["checkin_time"]) } else if checkinType == "下班打卡" { 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 { return nil, nil } diff --git a/worker/autopay.go b/worker/autopay.go index e670f27..0ce94f9 100644 --- a/worker/autopay.go +++ b/worker/autopay.go @@ -4,6 +4,7 @@ import ( "enterprise/common/config" "enterprise/common/global" "enterprise/common/model" + "fmt" log "github.com/sirupsen/logrus" "github.com/smbrave/goutil" "strings" @@ -21,11 +22,11 @@ func ViewCheckin(checkin *model.Checkin) { return } message := make([]string, 0) - message = append(message, "员工名称:%s", checkin.UserId) - message = append(message, "考勤日期:%s", checkin.Day) - message = append(message, "开始时间:%s", goutil.TimeToDateTime(checkin.StartTime)) - message = append(message, "结束时间:%s", goutil.TimeToDateTime(checkin.EndTime)) - message = append(message, "工作时长:%s", (time.Duration(duration) * time.Second).String()) + message = append(message, fmt.Sprintf("员工名称:%s", checkin.UserId)) + message = append(message, fmt.Sprintf("考勤日期:%s", checkin.Day)) + message = append(message, fmt.Sprintf("开始时间:%s", goutil.TimeToDateTime(checkin.StartTime))) + message = append(message, fmt.Sprintf("结束时间:%s", goutil.TimeToDateTime(checkin.EndTime))) + message = append(message, fmt.Sprintf("工作时长:%s", (time.Duration(duration)*time.Second).String())) if err := global.SendMessage([]string{"jiangyong"}, strings.Join(message, "\n")); err != nil { log.Errorf("send message error :%s", err.Error()) diff --git a/worker/checkin.go b/worker/checkin.go index e7823fb..b46b87c 100644 --- a/worker/checkin.go +++ b/worker/checkin.go @@ -49,6 +49,11 @@ func SyncCheckin(day string) error { isUpdate = true checkin.EndTime = realCheckin.EndTime } + if realCheckin.Exception != "" && realCheckin.Exception != checkin.Exception { + checkin.Exception = realCheckin.Exception + isUpdate = true + } + checkin.Rawdata = realCheckin.Rawdata if isNew { _, err = checkinDao.Create(checkin) } else { diff --git a/worker/worker.go b/worker/worker.go index a875d70..055fc9e 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -5,6 +5,14 @@ import ( "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 { timezone, _ := time.LoadLocation("Asia/Shanghai") cron := gocron.NewScheduler(timezone)