cygx_morning_meeting_reviews.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package cygx
  2. import (
  3. "errors"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // CygxMorningMeetingReviews [...]
  9. type CygxMorningMeetingReviews struct {
  10. Id int `orm:"column(id);pk"`
  11. MeetingTime time.Time `json:"meetingTime"` // 晨会日期
  12. PublishTime time.Time `json:"publishTime"` // 发布日期
  13. CreateTime time.Time `json:"createTime"`
  14. ModifyTime time.Time `json:"modifyTime"`
  15. Status int `json:"status"` // 0:未发布,1:已发布
  16. PartNums int `json:"partNums"` // 段落数
  17. IndustryNames string `json:"industryName"` // 产业名称
  18. }
  19. // 添加晨报点评
  20. func AddCygxMorningMeetingReviews(item *CygxMorningMeetingReviews) (id int64, err error) {
  21. o := orm.NewOrmUsingDB("hz_cygx")
  22. id, err = o.Insert(item)
  23. return
  24. }
  25. // 列表
  26. func GetCygxMorningMeetingReviewsList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxMorningMeetingReviews, err error) {
  27. o := orm.NewOrmUsingDB("hz_cygx")
  28. sql := `SELECT * FROM cygx_morning_meeting_reviews WHERE 1=1 `
  29. if condition != "" {
  30. sql += condition
  31. }
  32. sql += ` LIMIT ?,? `
  33. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  34. return
  35. }
  36. func GetCygxMorningMeetingReviewsListCount(condition string, pars []interface{}) (count int, err error) {
  37. o := orm.NewOrmUsingDB("hz_cygx")
  38. sql := `SELECT COUNT(1) AS count FROM cygx_morning_meeting_reviews WHERE 1=1 `
  39. if condition != "" {
  40. sql += condition
  41. }
  42. err = o.Raw(sql, pars).QueryRow(&count)
  43. return
  44. }
  45. type CygxMorningMeetingReviewItem struct {
  46. Id int `orm:"column(id);pk"`
  47. MeetingTime string `json:"meetingTime"` // 晨会日期
  48. PublishTime string `json:"publishTime"` // 发布日期
  49. CreateTime string `json:"createTime"`
  50. ModifyTime string `json:"modifyTime"`
  51. Status int `json:"status"` // 0:未发布,1:已发布
  52. PartNums int `json:"partNums"` // 段落数
  53. IndustryNames string `json:"industryName"` // 产业名称
  54. Pv int `description:"PV"`
  55. Uv int `description:"UV"`
  56. }
  57. type CygxMorningMeetingReviewsList struct {
  58. List []*CygxMorningMeetingReviewItem
  59. Paging *paging.PagingItem `description:"分页数据"`
  60. }
  61. func GetMorningMeetingReviewById(reviewId int) (item *CygxMorningMeetingReviews, err error) {
  62. o := orm.NewOrmUsingDB("hz_cygx")
  63. sql := `SELECT * FROM cygx_morning_meeting_reviews WHERE id=?`
  64. err = o.Raw(sql, reviewId).QueryRow(&item)
  65. return
  66. }
  67. // 发布报告
  68. func PublishMorningMeetingReviewById(reviewId int) (err error) {
  69. o := orm.NewOrmUsingDB("hz_cygx")
  70. sql := `UPDATE cygx_morning_meeting_reviews SET status=1,publish_time=now(),modify_time=NOW() WHERE id = ? `
  71. _, err = o.Raw(sql, reviewId).Exec()
  72. return
  73. }
  74. type MorningReviewPublishReq struct {
  75. ReviewIds string `description:"晨会id,多个用英文逗号隔开"`
  76. }
  77. type MorningReviewPublishCancelReq struct {
  78. ReviewId int `description:"晨会id"`
  79. }
  80. // 取消发布报告
  81. func PublishCancelMorningMeetingReview(reviewId int) (err error) {
  82. o := orm.NewOrmUsingDB("hz_cygx")
  83. sql := ` UPDATE cygx_morning_meeting_reviews SET status=0,publish_time=null WHERE id =? `
  84. _, err = o.Raw(sql, reviewId).Exec()
  85. return
  86. }
  87. type MorningReviewDeleteReq struct {
  88. ReviewId int `description:"晨会id"`
  89. }
  90. // DeleteMorningReviewAndChapter 删除晨会点评及章节
  91. func DeleteMorningReviewAndChapter(reviewId int) (err error) {
  92. reviewInfo, err := GetMorningMeetingReviewById(reviewId)
  93. if err != nil {
  94. err = errors.New("报告信息有误, Err: " + err.Error())
  95. return
  96. }
  97. if reviewInfo.Status == 1 {
  98. err = errors.New("报告已发布,不可删除")
  99. return
  100. }
  101. err = DeleteMorningMeeting(reviewId)
  102. if err != nil {
  103. err = errors.New("删除失败, Err: " + err.Error())
  104. return
  105. }
  106. err = DeleteMorningMeetingChapter(reviewId)
  107. if err != nil {
  108. err = errors.New("删除失败, Err: " + err.Error())
  109. return
  110. }
  111. return
  112. }
  113. // 删除晨会点评
  114. func DeleteMorningMeeting(reviewId int) (err error) {
  115. o := orm.NewOrmUsingDB("hz_cygx")
  116. sql := ` DELETE FROM cygx_morning_meeting_reviews WHERE id =? `
  117. _, err = o.Raw(sql, reviewId).Exec()
  118. return
  119. }
  120. // 更新晨报点评
  121. func UpdateCygxMorningMeetingReviews(item *CygxMorningMeetingReviews) (err error) {
  122. o := orm.NewOrmUsingDB("hz_cygx")
  123. sql := `UPDATE cygx_morning_meeting_reviews
  124. SET
  125. meeting_time =?,
  126. publish_time = ?,
  127. modify_time = ?,
  128. part_nums = ?,
  129. industry_names = ?,
  130. status = ?
  131. WHERE id = ? `
  132. _, err = o.Raw(sql, item.MeetingTime, item.PublishTime, item.ModifyTime, item.PartNums, item.IndustryNames, item.Status, item.Id).Exec()
  133. return
  134. }