job.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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) Get(tx *gorm.DB, job *SysJob) (err error) {
  37. return tx.Model(e).First(job, e.JobId).Error
  38. }
  39. func (e *SysJob) GetList(tx *gorm.DB, list interface{}) (err error) {
  40. return tx.Table(e.TableName()).Where("status = ?", 2).Find(list).Error
  41. }
  42. // Update 更新SysJob
  43. func (e *SysJob) Update(tx *gorm.DB, id interface{}) (err error) {
  44. return tx.Table(e.TableName()).Where(id).Updates(&e).Error
  45. }
  46. func (e *SysJob) RemoveAllEntryID(tx *gorm.DB) (update SysJob, err error) {
  47. if err = tx.Table(e.TableName()).Where("entry_id > ?", 0).Update("entry_id", 0).Error; err != nil {
  48. return
  49. }
  50. return
  51. }