ads14.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package model
  2. import (
  3. "time"
  4. "git.getensh.com/common/gopkgsv2/database"
  5. "gorm.io/gorm"
  6. )
  7. type Ads14Model interface {
  8. List(db *gorm.DB) ([]StyleItem, error)
  9. Update(db *gorm.DB, values interface{}) error
  10. Insert(db *gorm.DB, datab []Ads14) error
  11. Delete(db *gorm.DB) error
  12. }
  13. type Ads14 struct {
  14. ID int64 `gorm:"column:id" json:"id"`
  15. StyleId string `gorm:"column:style_id" json:"style_id"`
  16. C2Id int64 `gorm:"column:c2_id" json:"c2_id"`
  17. AttributeRule string `gorm:"column:attribute_rule" json:"attribute_rule"`
  18. Useage string `gorm:"column:useage" json:"useage"`
  19. Detail string `gorm:"column:detail" json:"detail"`
  20. CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
  21. UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
  22. }
  23. type StyleItem struct {
  24. ID int64 `gorm:"column:id" json:"id"`
  25. StyleId string `gorm:"column:style_id" json:"style_id"`
  26. C2Id int64 `gorm:"column:c2_id" json:"c2_id"`
  27. C2Name string `gorm:"column:c2_name" json:"c2_name"`
  28. AttributeRule string `gorm:"column:attribute_rule" json:"attribute_rule"`
  29. Useage string `gorm:"column:useage" json:"useage"`
  30. Detail string `gorm:"column:detail" json:"detail"`
  31. }
  32. type defaultAds14Model struct {
  33. tableName string
  34. fields string
  35. }
  36. func NewAds14Model() Ads14Model {
  37. return &defaultAds14Model{
  38. tableName: "db_adm_ads.t_adm_ads14",
  39. fields: "id, style_id, c2_id, attribute_rule, useage, detail, created_at, updated_at",
  40. }
  41. }
  42. func (d *defaultAds14Model) List(db *gorm.DB) ([]StyleItem, error) {
  43. var res []StyleItem
  44. err := database.List(db, &res, database.Option{
  45. TableName: d.tableName + " AS t1",
  46. Fields: "t1.id, style_id, c2_id, useage, attribute_rule, detail, t2.name AS c2_name",
  47. Joins: []string{"LEFT JOIN db_adm_ads.t_adm_ads6 AS t2 ON t1.c2_id = t2.id"},
  48. })
  49. return res, err
  50. }
  51. func (d *defaultAds14Model) Update(db *gorm.DB, values interface{}) error {
  52. return database.Update(db, values, database.Option{
  53. TableName: d.tableName,
  54. })
  55. }
  56. func (d *defaultAds14Model) Insert(db *gorm.DB, data []Ads14) error {
  57. return database.Create(db, data, database.Option{
  58. TableName: d.tableName,
  59. })
  60. }
  61. func (d *defaultAds14Model) Delete(db *gorm.DB) error {
  62. m := Ads14{}
  63. return db.Table(d.tableName).Delete(&m).Error
  64. }