smart_resource.go 5.6 KB

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