style_item.go 2.4 KB

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