community_question_comment.go 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. package yb
  2. import (
  3. "errors"
  4. "fmt"
  5. ybResponse "hongze/hongze_mobile_admin/models/response/yb"
  6. "hongze/hongze_mobile_admin/models/tables/chart_permission"
  7. "hongze/hongze_mobile_admin/models/tables/company_approval_message"
  8. "hongze/hongze_mobile_admin/models/tables/wx_user"
  9. "hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
  10. "hongze/hongze_mobile_admin/services"
  11. "hongze/hongze_mobile_admin/services/alarm_msg"
  12. "hongze/hongze_mobile_admin/utils"
  13. "strings"
  14. "time"
  15. )
  16. // GetCommunityQuestionCommentList 问答评论列表
  17. func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize, source int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
  18. commentList = make([]*ybResponse.CommunityQuestionCommentItem, 0)
  19. list := make([]*yb_community_question_comment.YbCommunityQuestionCommentAndQuestion, 0)
  20. // 来源
  21. switch source {
  22. case 1:
  23. // 问答社区
  24. qaTotal, qaList, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
  25. if e != nil {
  26. err = errors.New("获取问题列表失败 Err:" + e.Error())
  27. return
  28. }
  29. list = qaList
  30. total = qaTotal
  31. case 2:
  32. // 视频社区
  33. vcTotal, vcList, e := yb_community_question_comment.GetCommunityVideoCommentList(condition, pars, startSize, pageSize)
  34. if e != nil {
  35. err = errors.New("获取视频评论列表失败 Err:" + e.Error())
  36. return
  37. }
  38. list = vcList
  39. total = vcTotal
  40. case 3:
  41. // 路演视频
  42. rvTotal, rvList, e := yb_community_question_comment.GetRoadVideoCommentList(condition, pars, startSize, pageSize)
  43. if e != nil {
  44. err = errors.New("获取路演视频评论列表失败 Err:" + e.Error())
  45. return
  46. }
  47. // 品种名称
  48. if len(rvList) > 0 {
  49. cpList, e := chart_permission.GetChartPermissionList()
  50. if e != nil {
  51. err = errors.New("获取路演视频品种失败 Err:" + e.Error())
  52. return
  53. }
  54. cpMap := make(map[int]string, 0)
  55. for i := range cpList {
  56. cpMap[cpList[i].ChartPermissionId] = cpList[i].PermissionName
  57. }
  58. for i := range rvList {
  59. if rvList[i].ChartPermissionIds == "" {
  60. continue
  61. }
  62. ids := utils.JoinStr2IntArr(strings.ReplaceAll(rvList[i].ChartPermissionIds, `'`, ``), ",")
  63. if len(ids) == 0 {
  64. continue
  65. }
  66. cpArr := make([]string, 0)
  67. for s := range ids {
  68. if cpMap[ids[s]] != "" {
  69. cpArr = append(cpArr, cpMap[ids[s]])
  70. }
  71. }
  72. rvList[i].TagName = strings.Join(cpArr, ",")
  73. }
  74. }
  75. list = rvList
  76. total = rvTotal
  77. }
  78. if len(list) == 0 {
  79. return
  80. }
  81. // 查找用户
  82. userIdArr := make([]string, 0)
  83. for _, v := range list {
  84. userIdArr = append(userIdArr, fmt.Sprint(v.UserId))
  85. }
  86. //评论人信息
  87. wxUserCompanyInfoMap := make(map[int]*wx_user.UserCompanyInfoList, 0)
  88. if len(userIdArr) > 0 {
  89. userIds := strings.Join(userIdArr, ",")
  90. wxUserCompanyInfoList, tmpErr := wx_user.GetUserListByUserIds(userIds)
  91. if tmpErr != nil {
  92. err = tmpErr
  93. return
  94. }
  95. for _, v := range wxUserCompanyInfoList {
  96. wxUserCompanyInfoMap[v.UserId] = v
  97. }
  98. }
  99. for _, v := range list {
  100. item := &ybResponse.CommunityQuestionCommentItem{
  101. CommunityQuestionCommentId: v.CommunityQuestionCommentId,
  102. CommunityQuestionId: v.CommunityQuestionId,
  103. UserId: v.UserId,
  104. Content: v.Content,
  105. IsTop: v.IsTop,
  106. IsHot: v.IsHot,
  107. HotTopTime: v.HotTopTime,
  108. IsShowName: v.IsShowName,
  109. SourceAgent: v.SourceAgent,
  110. TopTime: v.TopTime,
  111. HotTime: v.HotTime,
  112. ModifyTime: v.ModifyTime,
  113. CreateTime: v.CreateTime,
  114. QuestionContent: v.QuestionContent,
  115. CompanyId: 0,
  116. UserName: "",
  117. CompanyName: "",
  118. CompanyProductStatus: "",
  119. Source: v.Source,
  120. TagName: v.TagName,
  121. }
  122. //评论人信息
  123. if tmpWxUserCompanyInfo, ok := wxUserCompanyInfoMap[int(v.UserId)]; ok {
  124. item.CompanyId = tmpWxUserCompanyInfo.CompanyId
  125. item.UserName = tmpWxUserCompanyInfo.RealName
  126. item.CompanyName = tmpWxUserCompanyInfo.CompanyName
  127. item.CompanyProductStatus = tmpWxUserCompanyInfo.CompanyProductStatus
  128. }
  129. commentList = append(commentList, item)
  130. }
  131. return
  132. }
  133. // SoftDeleteQuestionComment 删除问题评论
  134. func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
  135. errMsg = `删除成功`
  136. questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
  137. if err != nil {
  138. errMsg = "查找评论失败"
  139. if err.Error() == utils.ErrNoRow() {
  140. errMsg = "该评论不存在"
  141. }
  142. return
  143. }
  144. //标记删除
  145. questionCommentInfo.Enabled = 0
  146. questionCommentInfo.ModifyTime = time.Now()
  147. err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
  148. if err != nil {
  149. errMsg = "删除提问失败"
  150. return
  151. }
  152. // 删除评论后的逻辑处理
  153. go afterDeleteComment(questionCommentInfo)
  154. return
  155. }
  156. // SetHotQuestionComment 设置/取消 问题评论精选
  157. func SetHotQuestionComment(questionCommentId int) (err error, errMsg string) {
  158. errMsg = `操作失败`
  159. questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
  160. if err != nil {
  161. errMsg = "查找评论失败"
  162. if err.Error() == utils.ErrNoRow() {
  163. errMsg = "该评论不存在"
  164. }
  165. return
  166. }
  167. //var isHot int8
  168. isHot := int8(1)
  169. if questionCommentInfo.IsHot == 1 {
  170. isHot = 0
  171. }
  172. //标记删除
  173. questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
  174. questionCommentInfo.HotTopTime = time.Now()
  175. questionCommentInfo.HotTime = time.Now()
  176. questionCommentInfo.ModifyTime = time.Now()
  177. err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
  178. if err != nil {
  179. errMsg = "操作失败"
  180. }
  181. return
  182. }
  183. // afterDeleteComment 删除评论后的逻辑处理
  184. func afterDeleteComment(communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
  185. var err error
  186. defer func() {
  187. if err != nil {
  188. go alarm_msg.SendAlarmMsg("问答评论信息删除后,标记站内消息失败"+time.Now().Format(utils.FormatDateTime)+";Err:"+err.Error(), 3)
  189. }
  190. }()
  191. sourceType := 0
  192. switch communityQuestionComment.Source {
  193. case 1:
  194. sourceType = services.CompanyApprovalMessageSourceTypeByQuestionComment
  195. case 2:
  196. sourceType = services.CompanyApprovalMessageSourceTypeByVideoComment
  197. case 3:
  198. sourceType = services.CompanyApprovalMessageSourceTypeByRoadVideoComment
  199. default:
  200. err = errors.New("sourceType有误")
  201. return
  202. }
  203. err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), sourceType)
  204. return
  205. }