smart_resource.go 3.2 KB

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