manualTask.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type ManualTaskModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmManualTask, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmManualTask, error)
  11. }
  12. type AdmManualTask struct {
  13. Id int64 `gorm:"column:id" json:"id" form:"id"`
  14. TaskName string `gorm:"column:task_name" json:"task_name" form:"task_name"`
  15. Type int64 `gorm:"column:type" json:"type" form:"type"`
  16. Source string `gorm:"column:source" json:"source" form:"source"`
  17. Sql string `gorm:"column:sql" json:"sql" form:"sql"`
  18. TaskIds string `gorm:"column:task_ids" json:"task_ids" form:"task_ids"`
  19. Total int64 `gorm:"column:total" json:"total" form:"total"`
  20. FinishCount int64 `gorm:"column:finish_count" json:"finish_count" form:"finish_count"`
  21. IsFinish int64 `gorm:"column:is_finish" json:"is_finish" form:"is_finish"`
  22. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  23. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  24. }
  25. type defaultManualTask struct {
  26. tableName string
  27. fields string
  28. }
  29. func NewManualTask() ManualTaskModel {
  30. return &defaultManualTask{
  31. tableName: "t_adm_offline_task",
  32. fields: "`id`, `task_name`, `type`, `source`, `sql`, `task_ids`, `total`, `finish_count`, `is_finish`, `created_at`, `updated_at`",
  33. }
  34. }
  35. func (d *defaultManualTask) List(db *gorm.DB, pagination *Pagination) ([]AdmManualTask, error) {
  36. var res []AdmManualTask
  37. err := database.List(db, &res, database.Option{
  38. TableName: d.tableName,
  39. Fields: d.fields,
  40. Limit: pagination.Limit,
  41. OffSet: pagination.Offset,
  42. })
  43. return res, err
  44. }
  45. func (d *defaultManualTask) Count(db *gorm.DB) (int64, error) {
  46. return database.Count(db, database.Option{
  47. TableName: d.tableName,
  48. })
  49. }
  50. func (d *defaultManualTask) Update(db *gorm.DB, values interface{}) error {
  51. return database.Update(db, values, database.Option{
  52. TableName: d.tableName,
  53. })
  54. }
  55. func (d *defaultManualTask) Get(db *gorm.DB) (*AdmManualTask, error) {
  56. var res AdmManualTask
  57. err := database.Get(db, &res, database.Option{
  58. TableName: d.tableName,
  59. Fields: d.fields,
  60. })
  61. return &res, err
  62. }