smart_resource.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. Type int // 类型 1-版头 2-版尾
  48. CreateTime string // 创建时间
  49. }
  50. // SmartReportResourceListResp 智能研报资源库
  51. type SmartReportResourceListResp struct {
  52. List []*SmartReportResourceItem
  53. Paging *paging.PagingItem `description:"分页数据"`
  54. }
  55. func (m *SmartReportResource) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  56. o := orm.NewOrmUsingDB("rddp")
  57. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  58. err = o.Raw(sql, pars).QueryRow(&count)
  59. return
  60. }
  61. func (m *SmartReportResource) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, startSize, pageSize int) (items []*SmartReportResourceItem, err error) {
  62. o := orm.NewOrmUsingDB("rddp")
  63. fields := strings.Join(fieldArr, ",")
  64. if len(fieldArr) == 0 {
  65. fields = `*`
  66. }
  67. order := ` ORDER BY create_time DESC`
  68. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  69. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  70. return
  71. }
  72. // SmartReportRenameReq 智能研报资源重命名请求体
  73. type SmartReportRenameReq struct {
  74. ResourceId int `description:"资源ID"`
  75. ImgName string `description:"图片名称"`
  76. }
  77. func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
  78. o := orm.NewOrmUsingDB("rddp")
  79. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  80. err = o.Raw(sql, id).QueryRow(&item)
  81. return
  82. }
  83. // SmartReportResourceRemoveReq 删除智能研报资源请求体
  84. type SmartReportResourceRemoveReq struct {
  85. ResourceIds string `description:"资源IDs"`
  86. }
  87. // SmartReportResourceAddReq 新增智能研报资源请求体
  88. type SmartReportResourceAddReq struct {
  89. Type int `description:"类型 1-版头 2-版尾"`
  90. ImgUrl string `description:"图片链接"`
  91. ImgName string `description:"图片名称"`
  92. }
  93. func GetResourceItemById(id int) (item *SmartReportResource, err error) {
  94. o := orm.NewOrmUsingDB("rddp")
  95. sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
  96. err = o.Raw(sql, id).QueryRow(&item)
  97. return
  98. }