message2
This commit is contained in:
parent
e58acb28d9
commit
431b36a2b1
|
@ -5,6 +5,7 @@ type Checkin struct {
|
|||
UserId string
|
||||
Day string
|
||||
Exception string
|
||||
Rawdata string
|
||||
StartTime int64
|
||||
EndTime int64
|
||||
CreateTime int64
|
||||
|
|
|
@ -2,6 +2,8 @@ package qyweixin
|
|||
|
||||
type UserCheckIn struct {
|
||||
UserId string
|
||||
Exception string
|
||||
Rawdata string
|
||||
StartTime int64
|
||||
EndTime int64
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue