smart_resource.go 4.4 KB

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