cygx_tag.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxTag struct {
  7. TagId int64 `orm:"column(tag_id);pk"`
  8. TagName string `orm:"column(tag_name);NOT NULL"` // 标签名
  9. ArticleTypes string `orm:"column(article_types);NOT NULL"` // 报告系列
  10. ActivityTypes string `orm:"column(activity_types);NOT NULL"` // 活动类型
  11. Industries string `orm:"column(industries);NOT NULL"` // 产业
  12. SubjectNames string `orm:"column(subject_names);NOT NULL"` // 标的
  13. Sort int `orm:"column(sort);"` // 优先级
  14. ModifyTime time.Time `orm:"column(modify_time)"` // 修改时间
  15. CreateTime time.Time `orm:"column(create_time)"` // 创建时间
  16. OnlineTime time.Time `orm:"column(online_time)"` // 上线时间
  17. OfflineTime time.Time `orm:"column(offline_time)"` // 下线时间
  18. Status int `orm:"column(status);NOT NULL"` // 状态:0-禁用 1-启用
  19. }
  20. func (m *CygxTag) Update(cols []string) (err error) {
  21. o := orm.NewOrm()
  22. _, err = o.Update(m, cols...)
  23. return
  24. }
  25. type CygxTagList struct {
  26. TagId int64 `orm:"column(tag_id);pk"`
  27. TagName string `orm:"column(tag_name);NOT NULL"` // 标签名
  28. ArticleTypes string `orm:"column(article_types);NOT NULL"` // 报告系列
  29. ActivityTypes string `orm:"column(activity_types);NOT NULL"` // 活动类型
  30. Industries string `orm:"column(industries);NOT NULL"` // 产业
  31. SubjectNames string `orm:"column(subject_names);NOT NULL"` // 标的
  32. Sort int `orm:"column(sort);"` // 优先级
  33. ModifyTime string `orm:"column(modify_time)"` // 修改时间
  34. CreateTime string `orm:"column(create_time)"` // 创建时间
  35. OnlineTime string `orm:"column(online_time)"` // 上线时间
  36. OfflineTime string `orm:"column(offline_time)"` // 下线时间
  37. Status int `orm:"column(status);NOT NULL"` // 状态:0-禁用 1-启用
  38. CheckList []string // ABCD勾选了哪几列
  39. TagType int `description:"1:热门活动、2:海外研究、3:路演回放、4:语音问答"`
  40. }
  41. type CygxTagListResp struct {
  42. List []*CygxTagList
  43. ListPermission []*ChartPermission
  44. }
  45. // 列表
  46. func GetCygxTagListCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxTagList, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT * FROM cygx_tag as a WHERE 1= 1 `
  49. if condition != "" {
  50. sql += condition
  51. }
  52. if startSize+pageSize > 0 {
  53. sql += ` LIMIT ?,? `
  54. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  55. } else {
  56. _, err = o.Raw(sql, pars).QueryRows(&items)
  57. }
  58. return
  59. }
  60. // 获取tag列表
  61. func GetCygxTagList(cond string) (items []*CygxTagList, err error) {
  62. o := orm.NewOrm()
  63. sql := `SELECT * FROM cygx_tag WHERE 1=1 AND status = 1 `
  64. if cond != "" {
  65. sql += cond
  66. } else {
  67. sql += ` ORDER BY sort ASC `
  68. }
  69. _, err = o.Raw(sql).QueryRows(&items)
  70. return
  71. }
  72. func UpdateCygxTagStatus(id, status int) (err error) {
  73. o := orm.NewOrm()
  74. sql := ``
  75. if status == 1 {
  76. sql = ` UPDATE cygx_tag
  77. SET
  78. status =1,
  79. online_time = NOW(),
  80. modify_time = NOW()
  81. WHERE tag_id = ?`
  82. } else {
  83. sql = ` UPDATE cygx_tag
  84. SET
  85. status =0,
  86. offline_time = NOW(),
  87. modify_time = NOW()
  88. WHERE tag_id = ?`
  89. }
  90. _, err = o.Raw(sql, id).Exec()
  91. return
  92. }
  93. // GetCygxTagByTagId 根据指标id获取指标信息
  94. func GetCygxTagByTagId(tagId int) (item *CygxTag, err error) {
  95. o := orm.NewOrm()
  96. sql := `SELECT * FROM cygx_tag WHERE tag_id=? `
  97. err = o.Raw(sql, tagId).QueryRow(&item)
  98. return
  99. }
  100. // GetCygxTagMinSort 获取最小不等于0的排序
  101. func GetCygxTagMinSort() (sort int, err error) {
  102. o := orm.NewOrm()
  103. sql := `SELECT min(sort) FROM cygx_tag WHERE sort <> 0 `
  104. err = o.Raw(sql).QueryRow(&sort)
  105. return
  106. }
  107. // MoveDownCygxTagBySort 往下移动
  108. func MoveDownCygxTagBySort(prevSort, currentSort int) (err error) {
  109. o := orm.NewOrm()
  110. sql := `update cygx_tag set sort = sort - 1 where sort <= ? and sort> ? `
  111. _, err = o.Raw(sql, prevSort, currentSort).Exec()
  112. return
  113. }
  114. // MoveUpCygxTagBySort 往下移动
  115. func MoveUpCygxTagBySort(prevSort, currentSort int) (err error) {
  116. o := orm.NewOrm()
  117. sql := `update cygx_tag set sort = sort + 1 where sort >= ? and sort< ? `
  118. _, err = o.Raw(sql, prevSort, currentSort).Exec()
  119. return
  120. }
  121. type CygxTagIdReq struct {
  122. TagId int `description:"TagId"`
  123. }