smart_resource.go 4.9 KB

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