go_dreamfactory/modules/timer/sociaty.go
2022-10-31 15:12:35 +08:00

48 lines
1.1 KiB
Go

package timer
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/cron"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go.mongodb.org/mongo-driver/bson"
)
type SociatyTimer struct {
modules.MCompModel
service core.IService
}
//组件初始化接口
func (this *SociatyTimer) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableSociaty
this.MCompModel.Init(service, module, comp, options)
this.service = service
return
}
func (this *SociatyTimer) Start() (err error) {
err = this.MCompModel.Start()
cron.AddFunc("0 0 12 * * ?", this.updateSign)
return
}
// updateSign
func (this *SociatyTimer) updateSign() {
cur, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{})
if err != nil {
return
}
for cur.Next(context.TODO()) {
sociaty := &pb.DBSociaty{}
if err = cur.Decode(sociaty); err == nil {
sociaty.LastSignCount = int32(len(sociaty.SignIds))
sociaty.SignIds = make([]string, 0)
_, err = this.DB.UpdateOne(core.SqlTable(this.TableName), bson.M{}, sociaty)
}
}
}