taskList.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package model
  2. import (
  3. "git.getensh.com/common/gopkgsv2/database"
  4. "gorm.io/gorm"
  5. )
  6. type TaskListModel interface {
  7. List(db *gorm.DB, pagination *Pagination) ([]AdmTaskList, error)
  8. Count(db *gorm.DB) (int64, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Get(db *gorm.DB) (*AdmTaskList, error)
  11. }
  12. type AdmTaskList struct {
  13. TaskId int64 `gorm:"column:task_id" json:"task_id" form:"task_id"`
  14. TaskName string `gorm:"column:task_name" json:"task_name" form:"task_name"`
  15. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  16. TargetTable string `gorm:"column:target_table" json:"target_table" form:"target_table"`
  17. CreatedAt int64 `gorm:"column:created_at" json:"created_at" form:"created_at"`
  18. UpdatedAt int64 `gorm:"column:updated_at" json:"updated_at" form:"updated_at"`
  19. }
  20. type defaultTaskList struct {
  21. tableName string
  22. fields string
  23. }
  24. func NewTaskList() TaskListModel {
  25. return &defaultTaskList{
  26. tableName: "t_adm_tasks_management",
  27. fields: "`task_id`, `task_name`, `desc`, `target_table`, `created_at`, `updated_at`",
  28. }
  29. }
  30. func (d *defaultTaskList) List(db *gorm.DB, pagination *Pagination) ([]AdmTaskList, error) {
  31. var res []AdmTaskList
  32. err := database.List(db, &res, database.Option{
  33. TableName: d.tableName,
  34. Fields: d.fields,
  35. Limit: pagination.Limit,
  36. OffSet: pagination.Offset,
  37. })
  38. return res, err
  39. }
  40. func (d *defaultTaskList) Count(db *gorm.DB) (int64, error) {
  41. return database.Count(db, database.Option{
  42. TableName: d.tableName,
  43. })
  44. }
  45. func (d *defaultTaskList) Update(db *gorm.DB, values interface{}) error {
  46. return database.Update(db, values, database.Option{
  47. TableName: d.tableName,
  48. })
  49. }
  50. func (d *defaultTaskList) Get(db *gorm.DB) (*AdmTaskList, error) {
  51. var res AdmTaskList
  52. err := database.Get(db, &res, database.Option{
  53. TableName: d.tableName,
  54. Fields: d.fields,
  55. })
  56. return &res, err
  57. }
  58. type TaskInfo struct {
  59. TaskId int64 `gorm:"column:task_id" json:"task_id" form:"task_id"`
  60. TaskName string `gorm:"column:task_name" json:"task_name" form:"task_name"`
  61. Desc string `gorm:"column:desc" json:"desc" form:"desc"`
  62. }