Jelajahi Sumber

Merge branch 'yb/11.2' into debug

hsun 2 tahun lalu
induk
melakukan
941e8950cd

+ 0 - 3
controller/community/video.go

@@ -1,7 +1,6 @@
 package community
 
 import (
-	"fmt"
 	"github.com/gin-gonic/gin"
 	"hongze/hongze_yb/controller/response"
 	"hongze/hongze_yb/models/request"
@@ -43,7 +42,6 @@ func VideoList(c *gin.Context) {
 	// 点赞/吐槽数据
 	err = community.HandleLikeOrTeaseByCommunityVideoItemList(userInfo.UserID, list)
 	if err != nil {
-		fmt.Println(err.Error())
 		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
 		return
 	}
@@ -51,7 +49,6 @@ func VideoList(c *gin.Context) {
 	// 评论数据
 	err = community.HandleCommentByCommunityVideoItemList(list)
 	if err != nil {
-		fmt.Println(err.Error())
 		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
 		return
 	}

+ 15 - 0
controller/road/video.go

@@ -42,6 +42,21 @@ func VideoList(c *gin.Context) {
 		response.FailMsg("获取失败", "VideoList ErrMsg:"+err.Error(), c)
 		return
 	}
+
+	// 点赞/吐槽数据
+	err = community.HandleLikeOrTeaseByRoadVideoItemList(userinfo.UserID, list.List)
+	if err != nil {
+		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
+		return
+	}
+
+	// 评论数据
+	err = community.HandleCommentByRoadVideoItemList(list.List)
+	if err != nil {
+		response.FailMsg("获取失败", "QuestionList ErrMsg:"+err.Error(), c)
+		return
+	}
+
 	response.OkData("获取成功", list, c)
 }
 

+ 64 - 29
logic/yb_community_question/yb_community_question_comment.go

@@ -6,6 +6,7 @@ import (
 	"hongze/hongze_yb/global"
 	"hongze/hongze_yb/models/response"
 	"hongze/hongze_yb/models/tables/admin"
+	"hongze/hongze_yb/models/tables/chart_permission"
 	"hongze/hongze_yb/models/tables/company"
 	"hongze/hongze_yb/models/tables/company_product"
 	"hongze/hongze_yb/models/tables/wx_user"
@@ -13,6 +14,7 @@ import (
 	"hongze/hongze_yb/models/tables/yb_community_question"
 	"hongze/hongze_yb/models/tables/yb_community_question_comment"
 	"hongze/hongze_yb/models/tables/yb_community_video"
+	"hongze/hongze_yb/models/tables/yb_road_video"
 	"hongze/hongze_yb/services/alarm_msg"
 	"hongze/hongze_yb/services/company_approval_message"
 	"hongze/hongze_yb/services/user"
@@ -20,6 +22,7 @@ import (
 	"hongze/hongze_yb/services/wx_app"
 	"hongze/hongze_yb/utils"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -391,13 +394,69 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 	receiveUserId := int(adminInfo.AdminID)
 
 	var msgType, sourceType, approvalStatus int8
+	var remark, content, msgContent, extra, messageSource string
 	msgType = company_approval_message.CompanyApprovalMessageMessageTypeByApply
-	// 消息来源: 6-问答社区; 7-视频社区
-	if communityQuestionComment.Source == 1 {
+
+	// 消息来源: 6-问答社区; 7-视频社区; 8-线上路演;
+	switch communityQuestionComment.Source {
+	case 1:
 		sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByQuestionComment
-	} else {
+		remark = `您有新的问答评论待查阅`
+		content = `您有新的问答评论待查阅`
+		messageSource = `问答社区`
+
+		// 获取评论对应的问答/视频信息
+		communityQuestion, e := yb_community_question.GetItemById(int(communityQuestionComment.CommunityQuestionID))
+		if e != nil {
+			err = errors.New("获取评论对应的问答失败,err:" + e.Error())
+			return
+		}
+		msgContent = communityQuestion.QuestionContent
+	case 2:
 		sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByVideoComment
+		remark = `您有新的视频评论待查阅`
+		content = `您有新的视频评论待查阅`
+		messageSource = `视频社区`
+
+		communityVideo, e := yb_community_video.GetItemById(int(communityQuestionComment.CommunityQuestionID))
+		if e != nil {
+			err = errors.New("获取评论对应的视频失败,err:" + e.Error())
+			return
+		}
+		msgContent = communityVideo.Title
+		extra = communityVideo.VarietyTagName
+	case 3:
+		sourceType = company_approval_message.CompanyApprovalMessageSourceTypeByRoadVideoComment
+		remark = `您有新的线上路演评论待查阅`
+		content = `您有新的线上路演评论待查阅`
+		messageSource = `线上路演`
+
+		communityVideo, e := yb_road_video.GetItemById(int(communityQuestionComment.CommunityQuestionID))
+		if e != nil {
+			err = errors.New("获取评论对应的路演视频失败,err:" + e.Error())
+			return
+		}
+		msgContent = communityVideo.Title
+		// 路演视频品种
+		if communityVideo.ChartPermissionIds != "" {
+			cpIds := utils.JoinStr2IntArr(strings.ReplaceAll(communityVideo.ChartPermissionIds, `'`, ``), ",")
+			if len(cpIds) > 0 {
+				cpList, e := chart_permission.GetListByIds(cpIds)
+				if e != nil {
+					err = errors.New("获取路演视频品种失败, Err: " + e.Error())
+					return
+				}
+				cpArr := make([]string, 0)
+				for i := range cpList {
+					cpArr = append(cpArr, cpList[i].PermissionName)
+				}
+				extra = strings.Join(cpArr, ",")
+			}
+		}
+	default:
+		return
 	}
+
 	approvalStatus = company_approval_message.CompanyApprovalMessageApprovalStatusByPending
 
 	companyInfo, err := company.GetByCompanyId(wxUser.CompanyID)
@@ -412,32 +471,7 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 	}
 
 	companyName := companyInfo.CompanyName
-	remark := `您有新的问答评论待查阅`
-	content := `您有新的问答评论待查阅`
-	if communityQuestionComment.Source == 2 {
-		remark = `您有新的视频评论待查阅`
-		content = `您有新的视频评论待查阅`
-	}
 
-	// 获取评论对应的问答/视频信息
-	msgContent := ``
-	extra := ``
-	if communityQuestionComment.Source == 1 {
-		communityQuestion, e := yb_community_question.GetItemById(int(communityQuestionComment.CommunityQuestionID))
-		if e != nil {
-			err = errors.New("获取评论对应的问答失败,err:" + e.Error())
-			return
-		}
-		msgContent = communityQuestion.QuestionContent
-	} else {
-		communityVideo, e := yb_community_video.GetItemById(int(communityQuestionComment.CommunityQuestionID))
-		if e != nil {
-			err = errors.New("获取评论对应的视频失败,err:" + e.Error())
-			return
-		}
-		msgContent = communityVideo.Title
-		extra = communityVideo.VarietyTagName
-	}
 	messageInfo := company_approval_message.MessageInfo{
 		CompanyName:          companyInfo.CompanyName,
 		ProductId:            productId,
@@ -447,7 +481,8 @@ func systemMessageToAdmin(adminInfo admin.Admin, wxUser user.UserInfo, community
 		UserId:               wxUser.UserID,
 		UserName:             communityQuestionComment.RealName,
 		CreateTime:           communityQuestionComment.CreateTime,
-		Extra:                extra,	// 附加字段
+		Extra:                extra,         // 附加字段
+		MessageSource:        messageSource, // 消息来源
 	}
 	//客户添加消息
 	err = company_approval_message.AddCompanyApprovalMessage(utils.AdminId, receiveUserId, int(wxUser.CompanyID), int(communityQuestionComment.CommunityQuestionCommentID), msgType, sourceType, approvalStatus, companyName, remark, content, messageInfo)

+ 19 - 14
models/response/community.go

@@ -97,20 +97,25 @@ type CommunityVideoItem struct {
 
 // RoadVideoItem 线上路演
 type RoadVideoItem struct {
-	RoadVideoID         int    `json:"road_video_id"`
-	Title               string `json:"title"`
-	ChartPermissionIds  string `json:"chart_permission_ids"`
-	ChartPermissionName string `json:"chart_permission_name"`
-	CoverImgUrl         string `json:"cover_img_url"`
-	VideoUrl            string `json:"video_url"`
-	VideoSeconds        string `json:"video_seconds"`
-	PublishState        int    `json:"publish_state"`
-	AdminId             int    `json:"admin_id"`
-	AdminRealName       string `json:"admin_real_name"`
-	PublishTime         string `json:"publish_time"`
-	CreateTime          string `json:"create_time"`
-	ModifyTime          string `json:"modify_time"`
-	CollectionId        int    `description:"收藏ID: 大于0则表示已收藏" json:"collection_id"`
+	RoadVideoID         int                                 `json:"road_video_id"`
+	Title               string                              `json:"title"`
+	ChartPermissionIds  string                              `json:"chart_permission_ids"`
+	ChartPermissionName string                              `json:"chart_permission_name"`
+	CoverImgUrl         string                              `json:"cover_img_url"`
+	VideoUrl            string                              `json:"video_url"`
+	VideoSeconds        string                              `json:"video_seconds"`
+	PublishState        int                                 `json:"publish_state"`
+	AdminId             int                                 `json:"admin_id"`
+	AdminRealName       string                              `json:"admin_real_name"`
+	PublishTime         string                              `json:"publish_time"`
+	CreateTime          string                              `json:"create_time"`
+	ModifyTime          string                              `json:"modify_time"`
+	CollectionId        int                                 `description:"收藏ID: 大于0则表示已收藏" json:"collection_id"`
+	OpType              int8                                `description:"类型. 1-点赞 2-吐槽" json:"op_type"`
+	LikeTotal           int                                 `json:"like_total" description:"点赞数"`
+	TeaseTotal          int                                 `json:"tease_total" description:"吐槽数"`
+	CommentTotal        int                                 `json:"comment_total" description:"总共评论数"`
+	CommentList         []*CommunityQuestionCommentListItem `json:"comment_list"`
 }
 
 type RoadVideoItemResp struct {

+ 3 - 2
models/tables/yb_community_question_comment/yb_community_question_comment.go

@@ -76,6 +76,7 @@ var YbCommunityQuestionCommentColumns = struct {
 }
 
 const (
-	SourceQuestion = iota + 1 // 问答社区->1
-	SourceVideo               // 视频社区->2
+	SourceQuestion  = iota + 1 // 问答社区->1
+	SourceVideo                // 视频社区->2
+	SourceRoadVideo            // 路演视频->3
 )

+ 3 - 2
models/tables/yb_community_question_like_tease/yb_community_question_like_tease.go

@@ -46,6 +46,7 @@ var YbCommunityQuestionLikeTeaseColumns = struct {
 }
 
 const (
-	SourceQuestion = iota + 1 // 问答社区->1
-	SourceVideo               // 视频社区->2
+	SourceQuestion  = iota + 1 // 问答社区->1
+	SourceVideo                // 视频社区->2
+	SourceRoadVideo            // 路演视频->3
 )

+ 97 - 0
services/community/video.go

@@ -436,3 +436,100 @@ func HandleCommentByCommunityVideoItemList(questionList []*response.CommunityVid
 
 	return
 }
+
+// HandleLikeOrTeaseByRoadVideoItemList 路演视频 点赞/吐槽 数据
+func HandleLikeOrTeaseByRoadVideoItemList(userId uint64, videoList []*response.RoadVideoItem) (err error) {
+	listLen := len(videoList)
+	if listLen == 0 {
+		return
+	}
+	idArr := make([]uint32, 0)
+	for i := 0; i < listLen; i++ {
+		idArr = append(idArr, uint32(videoList[i].RoadVideoID))
+	}
+
+	// 注:此处视频社区CommunityVideoID在点赞吐槽表中为CommunityQuestionID, 以source区分主键
+
+	// 获取点赞和吐槽数据
+	ybCommunityQuestionLikeTeaseMap := make(map[uint32]*yb_community_question_like_tease.YbCommunityQuestionLikeTease)
+	ybCommunityQuestionLikeTeaseList, err := yb_community_question_like_tease.GetByUserIdAndCommunityQuestionIds(userId, idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range ybCommunityQuestionLikeTeaseList {
+		ybCommunityQuestionLikeTeaseMap[v.CommunityQuestionID] = v
+	}
+
+	// 获取点赞和吐槽汇总数
+	likeMap := make(map[uint32]int)
+	teaseMap := make(map[uint32]int)
+
+	likeList, err := yb_community_question_like_tease.GetLikeNumCommentByCommunityQuestionIds(idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range likeList {
+		likeMap[v.CommunityQuestionID] = v.Total
+	}
+
+	teaseList, err := yb_community_question_like_tease.GetTeaseNumCommentByCommunityQuestionIds(idArr, yb_community_question_like_tease.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range teaseList {
+		teaseMap[v.CommunityQuestionID] = v.Total
+	}
+
+	for _, v := range videoList {
+		if tmpTotal, ok := likeMap[uint32(v.RoadVideoID)]; ok {
+			v.LikeTotal = tmpTotal
+		}
+		if tmpTotal, ok := teaseMap[uint32(v.RoadVideoID)]; ok {
+			v.TeaseTotal = tmpTotal
+		}
+
+		if ybCommunityQuestionLikeTease, ok := ybCommunityQuestionLikeTeaseMap[uint32(v.RoadVideoID)]; ok {
+			//类型. 1-点赞 2-吐槽
+			v.OpType = ybCommunityQuestionLikeTease.OpType
+		}
+	}
+	return
+}
+
+// HandleCommentByRoadVideoItemList 路演视频 -论数据
+func HandleCommentByRoadVideoItemList(questionList []*response.RoadVideoItem) (err error) {
+	listLen := len(questionList)
+	if listLen == 0 {
+		return
+	}
+	idArr := make([]uint32, 0)
+
+	// 注:此处视频社区RoadVideoID在评论表中为CommunityQuestionID, 以source区分主键
+
+	// 问题ID-精选评论列表
+	questionIdCommentsMap := make(map[uint32][]*response.CommunityQuestionCommentListItem, 0)
+
+	for i := 0; i < listLen; i++ {
+		idArr = append(idArr, uint32(questionList[i].RoadVideoID))
+		questionIdCommentsMap[uint32(questionList[i].RoadVideoID)] = make([]*response.CommunityQuestionCommentListItem, 0)
+	}
+
+	// 精选评论数据
+	hotList, err := yb_community_question_comment.GetHotListByCommunityQuestionIds(idArr, yb_community_question_comment.SourceRoadVideo)
+	if err != nil {
+		return
+	}
+	for _, v := range hotList {
+		questionIdCommentsMap[v.CommunityQuestionID] = append(questionIdCommentsMap[v.CommunityQuestionID], &response.CommunityQuestionCommentListItem{
+			QaAvatarUrl: v.QaAvatarUrl,
+			Comment:     v.Content,
+		})
+	}
+
+	for _, v := range questionList {
+		comments := questionIdCommentsMap[uint32(v.RoadVideoID)]
+		v.CommentTotal = len(comments)
+		v.CommentList = comments
+	}
+	return
+}

+ 10 - 8
services/company_approval_message/company_approval_message.go

@@ -6,15 +6,16 @@ import (
 	"time"
 )
 
-//消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论,7:视频评论
+//消息来源类型,1:客户,2:合同,3:用印,4:指标替换,5:问答社区,6:问答评论,7:视频评论,8:线上路演评论
 const (
-	CompanyApprovalMessageSourceTypeByCompany         = 1
-	CompanyApprovalMessageSourceTypeByContract        = 2
-	CompanyApprovalMessageSourceTypeBySeal            = 3
-	CompanyApprovalMessageSourceTypeByEdbInfo         = 4
-	CompanyApprovalMessageSourceTypeByQuestion        = 5
-	CompanyApprovalMessageSourceTypeByQuestionComment = 6
-	CompanyApprovalMessageSourceTypeByVideoComment    = 7
+	CompanyApprovalMessageSourceTypeByCompany          = 1
+	CompanyApprovalMessageSourceTypeByContract         = 2
+	CompanyApprovalMessageSourceTypeBySeal             = 3
+	CompanyApprovalMessageSourceTypeByEdbInfo          = 4
+	CompanyApprovalMessageSourceTypeByQuestion         = 5
+	CompanyApprovalMessageSourceTypeByQuestionComment  = 6
+	CompanyApprovalMessageSourceTypeByVideoComment     = 7
+	CompanyApprovalMessageSourceTypeByRoadVideoComment = 8
 )
 
 // 1:申请消息,2:审批结果,3:消息通知
@@ -42,6 +43,7 @@ type MessageInfo struct {
 	UserName             string    `json:"user_name"`
 	CreateTime           time.Time `json:"create_time"`
 	Extra                string    `json:"extra" description:"附加字段"`
+	MessageSource        string    `json:"message_source" description:"消息来源:问答社区/视频社区/线上路演"`
 }
 
 // AddCompanyApprovalMessage 添加系统消息

+ 24 - 0
utils/common.go

@@ -1000,3 +1000,27 @@ func InArrayByStr(idStrList []string, searchId string) (has bool) {
 	}
 	return
 }
+
+// JoinStr2IntArr 拼接字符串转[]int
+func JoinStr2IntArr(str, sep string) (arr []int) {
+	arr = make([]int, 0)
+	if str == "" {
+		return
+	}
+	if sep == "" {
+		sep = ","
+	}
+	strArr := strings.Split(str, sep)
+	if len(strArr) == 0 {
+		return
+	}
+	for i := range strArr {
+		v, e := strconv.Atoi(strArr[i])
+		// int2str此处过滤掉无效int
+		if e != nil {
+			continue
+		}
+		arr = append(arr, v)
+	}
+	return
+}