...
|
...
|
@@ -18,6 +18,8 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) |
|
|
comment *models.Comment
|
|
|
baseUserInfo *protocol.BaseUserInfo
|
|
|
chance *models.Chance
|
|
|
updateTable interface{}
|
|
|
updateMap = make(map[string]interface{})
|
|
|
)
|
|
|
switch request.SourceType {
|
|
|
case protocol.SourceType_Chance:
|
...
|
...
|
@@ -25,15 +27,19 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) |
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
updateTable = chance
|
|
|
updateMap["CommentTotal"] = chance.CommentTotal + 1
|
|
|
case protocol.SourceType_Comment:
|
|
|
if _, err = repository.Comment.GetCommentById(request.Id); err != nil {
|
|
|
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
updateTable = comment
|
|
|
updateMap["CommentTotal"] = comment.CommentTotal + 1
|
|
|
default:
|
|
|
err = fmt.Errorf("unknow source_type:%v", request.SourceType)
|
|
|
}
|
|
|
comment = &models.Comment{
|
|
|
newComment := &models.Comment{
|
|
|
Id: idgen.Next(),
|
|
|
UserId: header.Uid,
|
|
|
SourceType: int8(request.SourceType),
|
...
|
...
|
@@ -41,22 +47,21 @@ func IComment(header *protocol.RequestHeader, request *protocol.ICommentRequest) |
|
|
CreateAt: time.Now(),
|
|
|
SourceId: request.Id,
|
|
|
}
|
|
|
if _, err = repository.Comment.AddComment(comment); err != nil {
|
|
|
if _, err = repository.Comment.AddComment(newComment); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil {
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if chance != nil {
|
|
|
//TODO:sql更新
|
|
|
utils.UpdateTableByMap(chance, map[string]interface{}{"CommentTotal": chance.CommentTotal + 1})
|
|
|
if updateTable != nil {
|
|
|
utils.UpdateTableByMap(updateTable, updateMap)
|
|
|
}
|
|
|
rsp = &protocol.ICommentResponse{
|
|
|
Id: comment.Id,
|
|
|
Content: comment.Content,
|
|
|
CreateTime: comment.CreateAt.Unix(),
|
|
|
Id: newComment.Id,
|
|
|
Content: newComment.Content,
|
|
|
CreateTime: newComment.CreateAt.Unix(),
|
|
|
Provider: baseUserInfo,
|
|
|
}
|
|
|
return
|
...
|
...
|
@@ -76,7 +81,7 @@ func IComments(header *protocol.RequestHeader, request *protocol.ICommentsReques |
|
|
rsp = &protocol.ICommentsResponse{
|
|
|
Total: total,
|
|
|
}
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid); err != nil {
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(header.Uid, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -105,8 +110,9 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) |
|
|
comments []*models.Comment
|
|
|
baseUserInfo *protocol.BaseUserInfo
|
|
|
total int
|
|
|
exists bool
|
|
|
)
|
|
|
if comments, total, err = repository.Comment.GetComments(header.Uid, protocol.SourceType_Chance, request.SourceId, request.LastId, request.PageSize); err != nil {
|
|
|
if comments, total, err = repository.Comment.GetComments(header.Uid, request.SourceType, request.SourceId, request.LastId, request.PageSize); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -115,7 +121,7 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) |
|
|
}
|
|
|
for i := range comments {
|
|
|
comment := comments[i]
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId); err != nil {
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
//return
|
|
|
}
|
...
|
...
|
@@ -128,7 +134,63 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) |
|
|
ZanTotal: comment.ZanTotal,
|
|
|
CommentTotal: comment.CommentTotal,
|
|
|
}
|
|
|
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists {
|
|
|
item.IsZan = 1
|
|
|
}
|
|
|
rsp.Comments = append(rsp.Comments, item)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//评论详情-不带地下评论
|
|
|
func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.CommentDetailsSingleRequest) (rsp *protocol.CommentDetailsSingleResponse, err error) {
|
|
|
var (
|
|
|
comment *models.Comment
|
|
|
baseUserInfo *protocol.BaseUserInfo
|
|
|
exists bool
|
|
|
)
|
|
|
rsp = &protocol.CommentDetailsSingleResponse{}
|
|
|
if comment, err = repository.Comment.GetCommentById(request.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if baseUserInfo, err = agg.GetUserBaseInfo(comment.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
//return
|
|
|
}
|
|
|
rsp.Comment = &protocol.Comments{
|
|
|
Id: comment.Id,
|
|
|
Provider: baseUserInfo,
|
|
|
Content: comment.Content,
|
|
|
CreateTime: comment.CreateAt.Unix(),
|
|
|
ViewTotal: comment.ViewTotal,
|
|
|
ZanTotal: comment.ZanTotal,
|
|
|
CommentTotal: comment.CommentTotal,
|
|
|
}
|
|
|
if exists, _ = repository.ChanceFavorite.ExitsChanceFavorite(header.Uid, header.CompanyId, comment.Id, protocol.ObjectType_Zan); exists {
|
|
|
rsp.Comment.IsZan = 1
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//评论详情-带底下评论
|
|
|
func CommentDetailsMulti(header *protocol.RequestHeader, request *protocol.CommentDetailsMultiRequest) (rsp *protocol.CommentDetailsMultiResponse, err error) {
|
|
|
var (
|
|
|
commentDetailSingle *protocol.CommentDetailsSingleResponse
|
|
|
commentDetailMulti *protocol.CommentsResponse
|
|
|
)
|
|
|
rsp = &protocol.CommentDetailsMultiResponse{}
|
|
|
//LastId=0时(返回comment对象和comments列表),commentLastId>0(返回comments列表)
|
|
|
if request.LastId == 0 {
|
|
|
if commentDetailSingle, err = CommentDetailsSingle(header, &protocol.CommentDetailsSingleRequest{Id: request.SourceId}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp.Comment = commentDetailSingle.Comment
|
|
|
}
|
|
|
if commentDetailMulti, err = Comments(header, &protocol.CommentsRequest{LastId: request.LastId, SourceId: request.SourceId, PageSize: request.PageSize, SourceType: protocol.SourceType_Comment}); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp.Comments = commentDetailMulti.Comments
|
|
|
return
|
|
|
} |
...
|
...
|
|