export_style_task.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. TaskName string `gorm:"column:task_name" json:"task_name"`
  17. Path string `gorm:"column:path" json:"path"`
  18. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  19. }
  20. type defaultExportStyleTaskModel struct {
  21. tableName string
  22. fields string
  23. }
  24. func NewExportStyleTaskModel() ExportStyleTaskModel {
  25. return &defaultExportStyleTaskModel{
  26. tableName: "db_adm_management.t_export_style_task",
  27. fields: "id, task_name, path, created_at",
  28. }
  29. }
  30. func (d *defaultExportStyleTaskModel) Insert(db *gorm.DB, data interface{}) error {
  31. return database.Create(db, data, database.Option{
  32. TableName: d.tableName,
  33. })
  34. }
  35. func (d *defaultExportStyleTaskModel) Update(db *gorm.DB, values interface{}) error {
  36. return database.Update(db, values, database.Option{
  37. TableName: d.tableName,
  38. })
  39. }
  40. func (d *defaultExportStyleTaskModel) List (db *gorm.DB) ([]ExportStyleTask, error) {
  41. var res []ExportStyleTask
  42. err := database.List(db, &res, database.Option{
  43. TableName: d.tableName,
  44. Fields: d.fields,
  45. OrderBy: "id DESC",
  46. })
  47. return res, err
  48. }
  49. func (d *defaultExportStyleTaskModel) Delete(db *gorm.DB) error {
  50. m := ExportStyleTask{}
  51. return db.Table(d.tableName).Delete(&m).Error
  52. }
  53. func (d *defaultExportStyleTaskModel) Get(db *gorm.DB) (*ExportStyleTask, error) {
  54. var res ExportStyleTask
  55. err := database.Get(db, &res, database.Option{
  56. TableName: d.tableName,
  57. Fields: d.fields,
  58. })
  59. return &res, err
  60. }