tactics_time_line.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hz_crm_api/utils"
  6. "time"
  7. )
  8. type CygxTacticsTimeLine struct {
  9. TimeLineId int `orm:"column(time_line_id);pk"`
  10. PublishTime time.Time `description:"发布日期"`
  11. CreateTime time.Time `description:"创建时间"`
  12. ModifyTime time.Time `description:"更新时间"`
  13. Status int `description:"0:未发布,1:已发布"`
  14. Content string `description:"内容"`
  15. ArticleId int `description:"文章ID"`
  16. ChartId int `description:"图表ID"`
  17. Link string `description:"文章或图表链接"`
  18. AdminId int `description:"管理员ID"`
  19. }
  20. type AddTacticsTimeLineReq struct {
  21. TimeLineId int `orm:"column(time_line_id);pk"`
  22. PublishTime string `description:"发布日期"`
  23. Content string `description:"内容"`
  24. Link string `description:"文章或图表链接"`
  25. }
  26. type TacticsTimeLineTimeLineIdReq struct {
  27. TimeLineId int `description:"ID"`
  28. }
  29. // 添加
  30. func AddCygxTacticsTimeLine(item *CygxTacticsTimeLine) (err error) {
  31. o := orm.NewOrmUsingDB("hz_cygx")
  32. _, err = o.Insert(item)
  33. return
  34. }
  35. // 修改
  36. func UpdateCygxTacticsTimeLine(item *CygxTacticsTimeLine) (err error) {
  37. to := orm.NewOrmUsingDB("hz_cygx")
  38. updateParams := make(map[string]interface{})
  39. updateParams["PublishTime"] = item.PublishTime
  40. updateParams["ModifyTime"] = item.ModifyTime
  41. updateParams["Content"] = item.Content
  42. updateParams["ArticleId"] = item.ArticleId
  43. updateParams["ChartId"] = item.ChartId
  44. updateParams["Link"] = item.Link
  45. ptrStructOrTableName := "cygx_tactics_time_line"
  46. whereParam := map[string]interface{}{"time_line_id": item.TimeLineId}
  47. qs := to.QueryTable(ptrStructOrTableName)
  48. for expr, exprV := range whereParam {
  49. qs = qs.Filter(expr, exprV)
  50. }
  51. _, err = qs.Update(updateParams)
  52. return
  53. }
  54. type GetCygxTacticsTimeLineResp struct {
  55. Status int `description:"0:内部可见,1:全部可见"`
  56. Paging *paging.PagingItem `description:"分页数据"`
  57. List []*CygxTacticsTimeLineResp
  58. }
  59. type CygxTacticsTimeLineResp struct {
  60. TimeLineId int `description:"ID"`
  61. PublishTime string `description:"发布日期"`
  62. CreateTime string `description:"创建时间"`
  63. ModifyTime string `description:"更新时间"`
  64. Status int `description:"0:未发布,1:已发布"`
  65. Content string `description:"内容"`
  66. ArticleId int `description:"文章ID"`
  67. ChartId int `description:"图表ID"`
  68. Link string `description:"文章或图表链接"`
  69. Pv int `description:"PV"`
  70. Uv int `description:"UV"`
  71. Title string `description:"标题"`
  72. }
  73. // 获取数量
  74. func GetCygxTacticsTimeLineCount(condition string, pars []interface{}) (count int, err error) {
  75. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_tactics_time_line as art WHERE 1= 1 `
  76. if condition != "" {
  77. sqlCount += condition
  78. }
  79. o := orm.NewOrmUsingDB("hz_cygx")
  80. err = o.Raw(sqlCount, pars).QueryRow(&count)
  81. return
  82. }
  83. // 列表
  84. func GetCygxTacticsTimeLineList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxTacticsTimeLineResp, err error) {
  85. o := orm.NewOrmUsingDB("hz_cygx")
  86. sql := `SELECT * FROM cygx_tactics_time_line as art WHERE 1= 1 `
  87. if condition != "" {
  88. sql += condition
  89. }
  90. sql += ` LIMIT ?,? `
  91. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  92. return
  93. }
  94. type GetCygxTacticsTimeLineDetailResp struct {
  95. Detail *CygxTacticsTimeLineResp
  96. }
  97. // 通过ID获取详情
  98. func GetCygxTacticsTimeLineDetail(timeLineId int) (item *CygxTacticsTimeLineResp, err error) {
  99. o := orm.NewOrmUsingDB("hz_cygx")
  100. sql := `SELECT * FROM cygx_tactics_time_line WHERE time_line_id=? `
  101. err = o.Raw(sql, timeLineId).QueryRow(&item)
  102. return
  103. }
  104. // 删除数据
  105. func DeleteCygxTacticsTimeLine(timeLineId int) (err error) {
  106. o := orm.NewOrmUsingDB("hz_cygx")
  107. sql := ` DELETE FROM cygx_tactics_time_line WHERE time_line_id = ?`
  108. _, err = o.Raw(sql, timeLineId).Exec()
  109. return
  110. }
  111. // 修改是否展示
  112. func EditCygxTacticsTimeLineStatus(status, timeLineId int) (err error) {
  113. o := orm.NewOrmUsingDB("hz_cygx")
  114. sql := `UPDATE cygx_tactics_time_line SET status=?, modify_time=NOW() WHERE time_line_id=? `
  115. _, err = o.Raw(sql, status, timeLineId).Exec()
  116. return
  117. }
  118. // 一键修改所有的是否展示
  119. func EditCygxTacticsTimeLineStatusAll(status int) (err error) {
  120. o := orm.NewOrmUsingDB("hz_cygx")
  121. to, err := o.Begin()
  122. if err != nil {
  123. return
  124. }
  125. defer func() {
  126. if err != nil {
  127. _ = to.Rollback()
  128. } else {
  129. _ = to.Commit()
  130. }
  131. }()
  132. //sql := `UPDATE cygx_tactics_time_line SET status=?, modify_time=NOW() `
  133. //_, err = to.Raw(sql, status).Exec()
  134. //if err != nil {
  135. // return
  136. //}
  137. sql := ` UPDATE cygx_config SET config_value=? WHERE config_code= ? `
  138. _, err = to.Raw(sql, status, utils.CYGX_TACTICS_TIME_LINE_STATUS).Exec()
  139. if err != nil {
  140. return
  141. }
  142. return
  143. }