smart_resource.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package smart_report
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "strings"
  7. "time"
  8. )
  9. type SmartReportResource struct {
  10. ResourceId int `orm:"column(resource_id);pk" description:"智能研报资源ID"`
  11. ImgUrl string // 图片链接
  12. ImgName string // 图片名称
  13. Style string // 版图样式
  14. Type int // 类型 1-版头 2-版尾
  15. CreateTime time.Time // 创建时间
  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 := orm.NewOrmUsingDB("rddp")
  25. id, err := o.Insert(m)
  26. if err != nil {
  27. return
  28. }
  29. m.ResourceId = int(id)
  30. return
  31. }
  32. func (m *SmartReportResource) Update(cols []string) (err error) {
  33. o := orm.NewOrmUsingDB("rddp")
  34. _, err = o.Update(m, cols...)
  35. return
  36. }
  37. func (m *SmartReportResource) Del() (err error) {
  38. o := orm.NewOrmUsingDB("rddp")
  39. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  40. _, err = o.Raw(sql, m.ResourceId).Exec()
  41. return
  42. }
  43. type SmartReportResourceItem struct {
  44. ResourceId int `orm:"column(resource_id);pk" description:"智能研报资源ID"`
  45. ImgUrl string // 图片链接
  46. ImgName string // 图片名称
  47. Style string // 版图样式
  48. Type int // 类型 1-版头 2-版尾
  49. CreateTime string // 创建时间
  50. }
  51. // SmartReportResourceListResp 智能研报资源库
  52. type SmartReportResourceListResp struct {
  53. List []*SmartReportResourceItem
  54. Paging *paging.PagingItem `description:"分页数据"`
  55. }
  56. func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  57. o := orm.NewOrmUsingDB("rddp")
  58. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  59. err = o.Raw(sql, pars).QueryRow(&count)
  60. return
  61. }
  62. func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) {
  63. o := orm.NewOrmUsingDB("rddp")
  64. fields := strings.Join(fieldArr, ",")
  65. if len(fieldArr) == 0 {
  66. fields = `*`
  67. }
  68. order := ` ORDER BY create_time DESC`
  69. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  70. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  71. return
  72. }
  73. // SmartReportResourceEditReq 智能研报资源编辑请求体
  74. type SmartReportResourceEditReq struct {
  75. ResourceId int `description:"资源ID"`
  76. ImgName string `description:"图片名称"`
  77. Style string `description:"版图样式"`
  78. }
  79. func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
  80. o := orm.NewOrmUsingDB("rddp")
  81. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  82. err = o.Raw(sql, id).QueryRow(&item)
  83. return
  84. }
  85. // SmartReportResourceRemoveReq 删除智能研报资源请求体
  86. type SmartReportResourceRemoveReq struct {
  87. ResourceIds string `description:"资源IDs"`
  88. }
  89. // SmartReportResourceAddReq 新增智能研报资源请求体
  90. type SmartReportResourceAddReq struct {
  91. Type int `description:"类型 1-版头 2-版尾"`
  92. ImgUrl string `description:"图片链接"`
  93. ImgName string `description:"图片名称"`
  94. Style string `description:"版图样式"`
  95. }
  96. func GetResourceItemById(id int) (item *SmartReportResource, err error) {
  97. o := orm.NewOrmUsingDB("rddp")
  98. sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
  99. err = o.Raw(sql, id).QueryRow(&item)
  100. return
  101. }