This commit is contained in:
jiangyong27 2023-08-04 19:29:13 +08:00
parent 9ec19f9467
commit 58d79525b2
7 changed files with 120 additions and 11 deletions

View File

@ -36,14 +36,15 @@ type Redis struct {
} }
type QyWeixin struct { type QyWeixin struct {
Corpid string `toml:"corpid"` Corpid string `toml:"corpid"`
CheckinAgent string `toml:"checkin_agent"` CheckinAgent string `toml:"checkin_agent"`
CheckinSecret string `toml:"checkin_secret"` CheckinSecret string `toml:"checkin_secret"`
CheckinGroup string `toml:"checkin_group"` CheckinGroup string `toml:"checkin_group"`
EnterpriseAgent string `toml:"enterprise_agent"` CheckinPayThresold float64 `toml:"checkin_pay_thresold"`
EnterpriseSecret string `toml:"enterprise_secret"` EnterpriseAgent string `toml:"enterprise_agent"`
HrAgent string `toml:"hr_agent"` EnterpriseSecret string `toml:"enterprise_secret"`
HrSecret string `toml:"hr_secret"` HrAgent string `toml:"hr_agent"`
HrSecret string `toml:"hr_secret"`
} }
type Config struct { type Config struct {

58
common/global/message.go Normal file
View File

@ -0,0 +1,58 @@
package global
import (
"context"
"enterprise/common/config"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work"
"github.com/ArtisanCloud/PowerWeChat/v3/src/work/message/request"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
"strings"
)
var (
wxEnterprise *work.Work
)
func initWxWork() (*work.Work, error) {
cfg := config.GetConfig()
client, err := work.NewWork(&work.UserConfig{
CorpID: cfg.QyWeixin.Corpid,
AgentID: cast.ToInt(cfg.QyWeixin.EnterpriseAgent),
Secret: cfg.QyWeixin.EnterpriseSecret,
OAuth: work.OAuth{
Callback: "https://wecom.artisan-cloud.com/callback",
Scopes: nil,
},
})
if err != nil {
log.Errorf("config[%s] init error : %s", goutil.EncodeJSON(cfg), err.Error())
return nil, err
}
return client, nil
}
func SendMessage(user []string, content string) error {
if wxEnterprise == nil {
wxM, err := initWxWork()
if err != nil {
return err
}
wxEnterprise = wxM
}
cfg := config.GetConfig()
receivers := user
message := &request.RequestMessageSendText{}
message.ToUser = strings.Join(receivers, "|")
message.MsgType = "text"
message.AgentID = cast.ToInt(cfg.QyWeixin.EnterpriseAgent)
message.Text = &request.RequestText{Content: content}
if _, err := wxEnterprise.Message.SendText(context.Background(), message); err != nil {
log.Errorf("send message [%s] error : %s", goutil.EncodeJSON(message), err)
return err
}
return nil
}

View File

@ -24,3 +24,4 @@ enterprise_secret = "oMB24UhKe50-XPTg7vhnwoTuhEXaq5XeiHPAUtF4hOs"
checkin_agent = "3010011" checkin_agent = "3010011"
checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU" checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU"
checkin_group = "1,2" checkin_group = "1,2"
checkin_pay_thresold = 11.5

View File

@ -24,3 +24,4 @@ enterprise_secret = "oMB24UhKe50-XPTg7vhnwoTuhEXaq5XeiHPAUtF4hOs"
checkin_agent = "3010011" checkin_agent = "3010011"
checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU" checkin_secret = "6ljYNGt4DonZLmr9SCtgkTlOvtqmsOchBrTWwGl_GpU"
checkin_group = "1,2" checkin_group = "1,2"
checkin_pay_thresold = 11

9
go.mod
View File

@ -3,6 +3,7 @@ module enterprise
go 1.18 go 1.18
require ( require (
github.com/ArtisanCloud/PowerWeChat/v3 v3.0.56
github.com/go-co-op/gocron v1.31.0 github.com/go-co-op/gocron v1.31.0
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
@ -16,6 +17,10 @@ require (
) )
require ( require (
github.com/ArtisanCloud/PowerLibs/v3 v3.0.12 // indirect
github.com/ArtisanCloud/PowerSocialite/v3 v3.0.6 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
@ -24,14 +29,18 @@ require (
github.com/jonboulle/clockwork v0.4.0 // indirect github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect github.com/magiconair/properties v1.8.7 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/redis/go-redis/v9 v9.0.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/spf13/afero v1.9.5 // indirect github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect github.com/subosito/gotenv v1.4.2 // indirect
go.uber.org/atomic v1.9.0 // indirect go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/sys v0.8.0 // indirect golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect golang.org/x/text v0.9.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect

33
worker/autopay.go Normal file
View File

@ -0,0 +1,33 @@
package worker
import (
"enterprise/common/config"
"enterprise/common/global"
"enterprise/common/model"
log "github.com/sirupsen/logrus"
"github.com/smbrave/goutil"
"strings"
"time"
)
func ViewCheckin(checkin *model.Checkin) {
if checkin.Exception != "" {
log.Errorf("execption[%s] %s", checkin.Exception, goutil.EncodeJSON(checkin))
return
}
thresold := config.GetConfig().QyWeixin.CheckinPayThresold
duration := checkin.EndTime - checkin.StartTime
if duration < int64(3600*thresold) {
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(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())
}
}

View File

@ -20,6 +20,7 @@ func SyncCheckin(day string) error {
checkinDao := dao.NewCheckinDao() checkinDao := dao.NewCheckinDao()
for _, user := range users { for _, user := range users {
isNew := false isNew := false
isUpdate := false
checkin, err := checkinDao.GetByDay(user, day) checkin, err := checkinDao.GetByDay(user, day)
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
@ -40,10 +41,12 @@ func SyncCheckin(day string) error {
if realCheckin == nil { if realCheckin == nil {
continue continue
} }
if realCheckin.StartTime != 0 { if realCheckin.StartTime != 0 && realCheckin.StartTime != checkin.StartTime {
isUpdate = true
checkin.StartTime = realCheckin.StartTime checkin.StartTime = realCheckin.StartTime
} }
if realCheckin.EndTime != 0 { if realCheckin.EndTime != 0 && realCheckin.EndTime != checkin.EndTime {
isUpdate = true
checkin.EndTime = realCheckin.EndTime checkin.EndTime = realCheckin.EndTime
} }
if isNew { if isNew {
@ -54,6 +57,9 @@ func SyncCheckin(day string) error {
if err != nil { if err != nil {
log.Errorf("db error :%s", err.Error()) log.Errorf("db error :%s", err.Error())
} }
if isUpdate {
go ViewCheckin(checkin)
}
} }
return nil return nil