job.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package models
  2. import (
  3. "IotAdmin/common/models"
  4. "gorm.io/gorm"
  5. )
  6. // SysJob 定时任务实体
  7. type SysJob struct {
  8. JobId int `json:"jobId" gorm:"type:bigint(20);primaryKey;autoIncrement;comment:编码"`
  9. JobName string `json:"jobName" gorm:"type:varchar(255);comment:名称"`
  10. JobGroup string `json:"jobGroup" gorm:"type:varchar(255);comment:任务分组"`
  11. JobType int `json:"jobType" gorm:"type:tinyint(4);comment:调用类型"`
  12. CronExpression string `json:"cronExpression" gorm:"type:varchar(255);comment:Cron表达式"`
  13. InvokeTarget string `json:"invokeTarget" gorm:"type:varchar(255);comment:调用目标"`
  14. Args string `json:"args" gorm:"type:varchar(255);comment:目标参数"`
  15. ExecCount int `json:"execCount" gorm:"type:bigint(20);comment:执行次数"`
  16. FailCount int `json:"failCount" gorm:"type:bigint(20);comment:失败次数"`
  17. LastExecTime int64 `json:"lastExecTime" gorm:"type:bigint(20);comment:上次执行时间"`
  18. NextExecTime int64 `json:"nextExecTime" gorm:"type:bigint(20);comment:下次执行时间"`
  19. MisfirePolicy int `json:"misfirePolicy" gorm:"type:bigint(20);comment:执行策略"`
  20. Concurrent int `json:"concurrent" gorm:"type:tinyint(4);comment:是否并发"`
  21. Status int `json:"status" gorm:"type:tinyint(4);comment:状态"`
  22. EntryId int `json:"entryId" gorm:"type:smallint(6);comment:EntryId"`
  23. models.ControlBy
  24. models.ModelTime
  25. }
  26. func (*SysJob) TableName() string {
  27. return "sys_job"
  28. }
  29. func (e *SysJob) Generate() models.ActiveRecord {
  30. o := *e
  31. return &o
  32. }
  33. func (e *SysJob) GetId() interface{} {
  34. return e.JobId
  35. }
  36. func (e *SysJob) GetList(tx *gorm.DB, list interface{}) (err error) {
  37. return tx.Table(e.TableName()).Where("status = ?", 2).Find(list).Error
  38. }
  39. // Update 更新SysJob
  40. func (e *SysJob) Update(tx *gorm.DB, id interface{}) (err error) {
  41. return tx.Table(e.TableName()).Where(id).Updates(&e).Error
  42. }
  43. func (e *SysJob) RemoveAllEntryID(tx *gorm.DB) (update SysJob, err error) {
  44. if err = tx.Table(e.TableName()).Where("entry_id > ?", 0).Update("entry_id", 0).Error; err != nil {
  45. return
  46. }
  47. return
  48. }