123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- package yb
- import (
- "errors"
- "fmt"
- ybResponse "hongze/hongze_mobile_admin/models/response/yb"
- "hongze/hongze_mobile_admin/models/tables/chart_permission"
- "hongze/hongze_mobile_admin/models/tables/company_approval_message"
- "hongze/hongze_mobile_admin/models/tables/wx_user"
- "hongze/hongze_mobile_admin/models/tables/yb_community_question_comment"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/services/alarm_msg"
- "hongze/hongze_mobile_admin/utils"
- "strings"
- "time"
- )
- // GetCommunityQuestionCommentList 问答评论列表
- func GetCommunityQuestionCommentList(condition string, pars []interface{}, startSize, pageSize, source int) (total int, commentList []*ybResponse.CommunityQuestionCommentItem, err error) {
- commentList = make([]*ybResponse.CommunityQuestionCommentItem, 0)
- list := make([]*yb_community_question_comment.YbCommunityQuestionCommentAndQuestion, 0)
- // 来源
- switch source {
- case 1:
- // 问答社区
- qaTotal, qaList, e := yb_community_question_comment.GetCommunityQuestionCommentList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("获取问题列表失败 Err:" + e.Error())
- return
- }
- list = qaList
- total = qaTotal
- case 2:
- // 视频社区
- vcTotal, vcList, e := yb_community_question_comment.GetCommunityVideoCommentList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("获取视频评论列表失败 Err:" + e.Error())
- return
- }
- list = vcList
- total = vcTotal
- case 3:
- // 路演视频
- rvTotal, rvList, e := yb_community_question_comment.GetRoadVideoCommentList(condition, pars, startSize, pageSize)
- if e != nil {
- err = errors.New("获取路演视频评论列表失败 Err:" + e.Error())
- return
- }
- // 品种名称
- if len(rvList) > 0 {
- cpList, e := chart_permission.GetChartPermissionList()
- if e != nil {
- err = errors.New("获取路演视频品种失败 Err:" + e.Error())
- return
- }
- cpMap := make(map[int]string, 0)
- for i := range cpList {
- cpMap[cpList[i].ChartPermissionId] = cpList[i].PermissionName
- }
- for i := range rvList {
- if rvList[i].ChartPermissionIds == "" {
- continue
- }
- ids := utils.JoinStr2IntArr(strings.ReplaceAll(rvList[i].ChartPermissionIds, `'`, ``), ",")
- if len(ids) == 0 {
- continue
- }
- cpArr := make([]string, 0)
- for s := range ids {
- if cpMap[ids[s]] != "" {
- cpArr = append(cpArr, cpMap[ids[s]])
- }
- }
- rvList[i].TagName = strings.Join(cpArr, ",")
- }
- }
- list = rvList
- total = rvTotal
- }
- if len(list) == 0 {
- return
- }
- // 查找用户
- userIdArr := make([]string, 0)
- for _, v := range list {
- userIdArr = append(userIdArr, fmt.Sprint(v.UserId))
- }
- //评论人信息
- wxUserCompanyInfoMap := make(map[int]*wx_user.UserCompanyInfoList, 0)
- if len(userIdArr) > 0 {
- userIds := strings.Join(userIdArr, ",")
- wxUserCompanyInfoList, tmpErr := wx_user.GetUserListByUserIds(userIds)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- for _, v := range wxUserCompanyInfoList {
- wxUserCompanyInfoMap[v.UserId] = v
- }
- }
- for _, v := range list {
- item := &ybResponse.CommunityQuestionCommentItem{
- CommunityQuestionCommentId: v.CommunityQuestionCommentId,
- CommunityQuestionId: v.CommunityQuestionId,
- UserId: v.UserId,
- Content: v.Content,
- IsTop: v.IsTop,
- IsHot: v.IsHot,
- HotTopTime: v.HotTopTime,
- IsShowName: v.IsShowName,
- SourceAgent: v.SourceAgent,
- TopTime: v.TopTime,
- HotTime: v.HotTime,
- ModifyTime: v.ModifyTime,
- CreateTime: v.CreateTime,
- QuestionContent: v.QuestionContent,
- CompanyId: 0,
- UserName: "",
- CompanyName: "",
- CompanyProductStatus: "",
- Source: v.Source,
- TagName: v.TagName,
- }
- //评论人信息
- if tmpWxUserCompanyInfo, ok := wxUserCompanyInfoMap[int(v.UserId)]; ok {
- item.CompanyId = tmpWxUserCompanyInfo.CompanyId
- item.UserName = tmpWxUserCompanyInfo.RealName
- item.CompanyName = tmpWxUserCompanyInfo.CompanyName
- item.CompanyProductStatus = tmpWxUserCompanyInfo.CompanyProductStatus
- }
- commentList = append(commentList, item)
- }
- return
- }
- // SoftDeleteQuestionComment 删除问题评论
- func SoftDeleteQuestionComment(questionCommentId int) (err error, errMsg string) {
- errMsg = `删除成功`
- questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
- if err != nil {
- errMsg = "查找评论失败"
- if err.Error() == utils.ErrNoRow() {
- errMsg = "该评论不存在"
- }
- return
- }
- //标记删除
- questionCommentInfo.Enabled = 0
- questionCommentInfo.ModifyTime = time.Now()
- err = questionCommentInfo.Update([]string{"Enabled", "ModifyTime"})
- if err != nil {
- errMsg = "删除提问失败"
- return
- }
- // 删除评论后的逻辑处理
- go afterDeleteComment(questionCommentInfo)
- return
- }
- // SetHotQuestionComment 设置/取消 问题评论精选
- func SetHotQuestionComment(questionCommentId int) (err error, errMsg string) {
- errMsg = `操作失败`
- questionCommentInfo, err := yb_community_question_comment.GetQuestionCommentById(questionCommentId)
- if err != nil {
- errMsg = "查找评论失败"
- if err.Error() == utils.ErrNoRow() {
- errMsg = "该评论不存在"
- }
- return
- }
- //var isHot int8
- isHot := int8(1)
- if questionCommentInfo.IsHot == 1 {
- isHot = 0
- }
- //标记删除
- questionCommentInfo.IsHot = isHot //是否设置精选(0-未设置,1-已设置)
- questionCommentInfo.HotTopTime = time.Now()
- questionCommentInfo.HotTime = time.Now()
- questionCommentInfo.ModifyTime = time.Now()
- err = questionCommentInfo.Update([]string{"IsHot", "HotTopTime", "HotTime", "ModifyTime"})
- if err != nil {
- errMsg = "操作失败"
- }
- return
- }
- // afterDeleteComment 删除评论后的逻辑处理
- func afterDeleteComment(communityQuestionComment *yb_community_question_comment.YbCommunityQuestionComment) {
- var err error
- defer func() {
- if err != nil {
- go alarm_msg.SendAlarmMsg("问答评论信息删除后,标记站内消息失败"+time.Now().Format(utils.FormatDateTime)+";Err:"+err.Error(), 3)
- }
- }()
- sourceType := 0
- switch communityQuestionComment.Source {
- case 1:
- sourceType = services.CompanyApprovalMessageSourceTypeByQuestionComment
- case 2:
- sourceType = services.CompanyApprovalMessageSourceTypeByVideoComment
- case 3:
- sourceType = services.CompanyApprovalMessageSourceTypeByRoadVideoComment
- default:
- err = errors.New("sourceType有误")
- return
- }
- err = company_approval_message.CancelCompanyApprovalMessage(int(communityQuestionComment.CommunityQuestionCommentId), sourceType)
- return
- }
|