smart_resource.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. Style string // 版图样式
  13. ImgName 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. // GetItemsByCondition
  74. // @Description: 根据条件获取所有的审批单
  75. // @author: Roc
  76. // @receiver m
  77. // @datetime 2024-06-27 16:12:55
  78. // @param condition string
  79. // @param pars []interface{}
  80. // @param fieldArr []string
  81. // @return items []*SmartReportResourceItem
  82. // @return err error
  83. func (m *SmartReportResource) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string) (items []*SmartReportResourceItem, err error) {
  84. o := orm.NewOrmUsingDB("rddp")
  85. fields := strings.Join(fieldArr, ",")
  86. if len(fieldArr) == 0 {
  87. fields = `*`
  88. }
  89. order := ` ORDER BY create_time DESC`
  90. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s `, fields, m.TableName(), condition, order)
  91. _, err = o.Raw(sql, pars).QueryRows(&items)
  92. return
  93. }
  94. // SmartReportResourceEditReq 智能研报资源编辑请求体
  95. type SmartReportResourceEditReq struct {
  96. ResourceId int `description:"资源ID"`
  97. ImgName string `description:"图片名称"`
  98. Style string `description:"版图样式"`
  99. }
  100. func (m *SmartReportResource) GetItemById(id int) (item *SmartReportResource, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  103. err = o.Raw(sql, id).QueryRow(&item)
  104. return
  105. }
  106. // SmartReportResourceRemoveReq 删除智能研报资源请求体
  107. type SmartReportResourceRemoveReq struct {
  108. ResourceIds string `description:"资源IDs"`
  109. }
  110. // SmartReportResourceAddReq 新增智能研报资源请求体
  111. type SmartReportResourceAddReq struct {
  112. Type int `description:"类型 1-版头 2-版尾"`
  113. ImgUrl string `description:"图片链接"`
  114. ImgName string `description:"图片名称"`
  115. Style string `description:"版图样式"`
  116. }
  117. func GetResourceItemById(id int) (item *SmartReportResource, err error) {
  118. o := orm.NewOrmUsingDB("rddp")
  119. sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
  120. err = o.Raw(sql, id).QueryRow(&item)
  121. return
  122. }