cygx_tag.go 4.6 KB

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