export_style_task.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package model
  2. import (
  3. "time"
  4. "git.getensh.com/common/gopkgsv2/database"
  5. "gorm.io/gorm"
  6. )
  7. type ExportStyleTaskModel interface {
  8. Insert(db *gorm.DB, data interface{}) error
  9. Update(db *gorm.DB, values interface{}) error
  10. List(db *gorm.DB) ([]ExportStyleTask, error)
  11. Delete(db *gorm.DB) error
  12. Get(db *gorm.DB) (*ExportStyleTask, error)
  13. }
  14. type ExportStyleTask struct {
  15. ID int64 `gorm:"column:id" json:"id"`
  16. ExportId string `gorm:"column:export_id" json:"export_id" form:"export_id"`
  17. TaskName string `gorm:"column:task_name" json:"task_name"`
  18. Path string `gorm:"column:path" json:"path"`
  19. Status int8 `gorm:"column:status" json:"status"`
  20. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  21. }
  22. type defaultExportStyleTaskModel struct {
  23. tableName string
  24. fields string
  25. }
  26. func NewExportStyleTaskModel() ExportStyleTaskModel {
  27. return &defaultExportStyleTaskModel{
  28. tableName: "db_adm_management.t_export_style_task",
  29. fields: "id, export_id, task_name, path, status, created_at",
  30. }
  31. }
  32. func (d *defaultExportStyleTaskModel) Insert(db *gorm.DB, data interface{}) error {
  33. return database.Create(db, data, database.Option{
  34. TableName: d.tableName,
  35. })
  36. }
  37. func (d *defaultExportStyleTaskModel) Update(db *gorm.DB, values interface{}) error {
  38. return database.Update(db, values, database.Option{
  39. TableName: d.tableName,
  40. })
  41. }
  42. func (d *defaultExportStyleTaskModel) List(db *gorm.DB) ([]ExportStyleTask, error) {
  43. var res []ExportStyleTask
  44. err := database.List(db, &res, database.Option{
  45. TableName: d.tableName,
  46. Fields: d.fields,
  47. OrderBy: "id DESC",
  48. })
  49. return res, err
  50. }
  51. func (d *defaultExportStyleTaskModel) Delete(db *gorm.DB) error {
  52. m := ExportStyleTask{}
  53. return db.Table(d.tableName).Delete(&m).Error
  54. }
  55. func (d *defaultExportStyleTaskModel) Get(db *gorm.DB) (*ExportStyleTask, error) {
  56. var res ExportStyleTask
  57. err := database.Get(db, &res, database.Option{
  58. TableName: d.tableName,
  59. Fields: d.fields,
  60. })
  61. return &res, err
  62. }