smart_resource.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package smart_report
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. type SmartReportResource struct {
  10. ResourceId int `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"`
  11. ImgUrl string `gorm:"column:img_url" description:"图片链接"` // 图片链接
  12. Style string `gorm:"column:style" description:"版图样式"` // 版图样式
  13. ImgName string `gorm:"column:img_name" description:"图片名称"` // 图片名称
  14. Type int `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾
  15. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"` // 创建时间
  16. }
  17. func (m *SmartReportResource) TableName() string {
  18. return "smart_report_resource"
  19. }
  20. func (m *SmartReportResource) PrimaryId() string {
  21. return "resource_id"
  22. }
  23. func (m *SmartReportResource) Create() (err error) {
  24. o := global.DmSQL["rddp"]
  25. err = o.Create(m).Error
  26. return
  27. }
  28. func (m *SmartReportResource) Update(cols []string) (err error) {
  29. o := global.DmSQL["rddp"]
  30. err = o.Model(m).Select(cols).Updates(m).Error
  31. return
  32. }
  33. func (m *SmartReportResource) Del() (err error) {
  34. o := global.DmSQL["rddp"]
  35. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  36. err = o.Exec(sql, m.ResourceId).Error
  37. return
  38. }
  39. type SmartReportResourceItem struct {
  40. ResourceId int `orm:"column(resource_id);pk" gorm:"column:resource_id;primaryKey" description:"智能研报资源ID"`
  41. ImgUrl string `gorm:"column:img_url" description:"图片链接"` // 图片链接
  42. ImgName string `gorm:"column:img_name" description:"图片名称"` // 图片名称
  43. Style string `gorm:"column:style" description:"版图样式"` // 版图样式
  44. Type int `gorm:"column:type" description:"类型 1-版头 2-版尾"` // 类型 1-版头 2-版尾
  45. CreateTime string `gorm:"column:create_time" description:"创建时间"` // 创建时间
  46. }
  47. type SmartReportResourceListResp struct {
  48. List []*SmartReportResourceItem
  49. Paging *paging.PagingItem `description:"分页数据"`
  50. }
  51. func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  52. o := global.DmSQL["rddp"]
  53. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  54. err = o.Raw(sql, pars...).Scan(&count).Error
  55. return
  56. }
  57. func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) {
  58. o := global.DmSQL["rddp"]
  59. fields := strings.Join(fieldArr, ",")
  60. if len(fieldArr) == 0 {
  61. fields = `*`
  62. }
  63. order := ` ORDER BY create_time DESC`
  64. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  65. pars = append(pars, startSize, pageSize)
  66. err = o.Raw(sql, pars...).Find(&items).Error
  67. return
  68. }
  69. func (m *SmartReportResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string) (items []*SmartReportResourceItem, err error) {
  70. o := global.DmSQL["rddp"]
  71. fields := strings.Join(fieldArr, ",")
  72. if len(fieldArr) == 0 {
  73. fields = `*`
  74. }
  75. order := ` ORDER BY create_time DESC`
  76. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s `, fields, m.TableName(), condition, order)
  77. err = o.Raw(sql, pars...).Find(&items).Error
  78. return
  79. }
  80. type SmartReportResourceEditReq struct {
  81. ResourceId int `description:"资源ID"`
  82. ImgName string `description:"图片名称"`
  83. Style string `description:"版图样式"`
  84. }
  85. func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
  86. o := global.DmSQL["rddp"]
  87. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  88. err = o.Raw(sql, id).First(&item).Error
  89. return
  90. }
  91. type SmartReportResourceRemoveReq struct {
  92. ResourceIds string `description:"资源IDs"`
  93. }
  94. type SmartReportResourceAddReq struct {
  95. Type int `description:"类型 1-版头 2-版尾"`
  96. ImgUrl string `description:"图片链接"`
  97. ImgName string `description:"图片名称"`
  98. Style string `description:"版图样式"`
  99. }
  100. func GetResourceItemById(id int) (item *SmartReportResource, err error) {
  101. o := global.DmSQL["rddp"]
  102. sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
  103. err = o.Raw(sql, id).First(&item).Error
  104. return
  105. }