2021-09-28 11:47:19 +08:00
|
|
|
|
package cron
|
|
|
|
|
|
|
|
|
|
type Tenant struct{}
|
|
|
|
|
|
|
|
|
|
type TenantHandle func() (string, func())
|
|
|
|
|
|
|
|
|
|
// ContractDeadline 合同处理
|
|
|
|
|
func (this *Tenant) ContractDeadline() TenantHandle {
|
|
|
|
|
return func() (string, func()) {
|
|
|
|
|
return "0 0 0 * * ?", func() {
|
2021-10-12 16:53:49 +08:00
|
|
|
|
//now := time.Now()
|
|
|
|
|
//
|
|
|
|
|
//mSysTenant := model.NewSysTenant()
|
|
|
|
|
//
|
|
|
|
|
//out := make([]*model.SysTenant, 0)
|
|
|
|
|
//
|
|
|
|
|
//err := model.Find(mSysTenant, &out, &model.ModelWhereOrder{Where: model.NewWhereIn("status", []model.SysTenantStatus{
|
|
|
|
|
// model.SysTenantStatusForNormal, model.SysTenantStatusForWellExpire,
|
|
|
|
|
//})}, &model.ModelWhereOrder{Where: model.NewWhereCondition("deadline", ">=", now.AddDate(0, 0, -7))})
|
|
|
|
|
//
|
|
|
|
|
//if err != nil {
|
|
|
|
|
// logger.ErrorF("Cron Tenant ContractDeadline Error:%v", err)
|
|
|
|
|
// return
|
|
|
|
|
//}
|
|
|
|
|
//well := make([]uint64, 0)
|
|
|
|
|
//expired := make([]uint64, 0)
|
|
|
|
|
//expiredKey := make([]string, 0)
|
|
|
|
|
//
|
|
|
|
|
//for _, v := range out {
|
|
|
|
|
// // 超过协议时间
|
|
|
|
|
// if v.Deadline.After(now) {
|
|
|
|
|
// expired = append(expired, v.ID)
|
|
|
|
|
// expiredKey = append(expiredKey, v.Key)
|
|
|
|
|
// continue
|
|
|
|
|
// }
|
|
|
|
|
// if v.Status == model.SysTenantStatusForNormal {
|
|
|
|
|
// well = append(well, v.ID)
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
// if len(well) > 0 {
|
|
|
|
|
// if err = model.UpdatesWhere(mSysTenant, map[string]interface{}{
|
|
|
|
|
// "status": model.SysTenantStatusForWellExpire, "updated_at": now,
|
|
|
|
|
// }, []*model.ModelWhere{model.NewWhereIn("id", well)}, tx); err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// if len(expired) > 0 {
|
|
|
|
|
// if err = model.UpdatesWhere(mSysTenant, map[string]interface{}{
|
|
|
|
|
// "status": model.SysTenantStatusForExpired, "updated_at": now,
|
|
|
|
|
// }, []*model.ModelWhere{model.NewWhereIn("id", expired)}, tx); err != nil {
|
|
|
|
|
// return err
|
|
|
|
|
// }
|
|
|
|
|
// service.Publish(config.EventForRedisListDestroy, config.RedisKeyForTenant, expiredKey)
|
|
|
|
|
// }
|
|
|
|
|
// return nil
|
|
|
|
|
//}); err != nil {
|
|
|
|
|
// logger.ErrorF("Cron Tenant ContractDeadline Transaction Error:%v", err)
|
|
|
|
|
// return
|
|
|
|
|
//}
|
2021-09-28 11:47:19 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewTenant() *Tenant {
|
|
|
|
|
return &Tenant{}
|
|
|
|
|
}
|