smart_resource.go 4.0 KB

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