作者 yangfu

重构-消息中心 点赞/评论/机会提交/审核消息

... ... @@ -198,7 +198,7 @@ func GetUserMsgsBulletin(userId, companyId int64, msgType int, lastId int64, pag
//获取机会消息
func GetChanceMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.status from (
select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data chance_approve_data,b.status from (
select id,company_id,receive_user_id,message,source_id,is_read,chance_id,create_at msg_time,data,sender_user_id
from user_msg where receive_user_id=? and source_type=1 and (?=0 or id<?) and msg_type=?
)a left outer join chance b on a.source_id = b.id
... ...
... ... @@ -373,7 +373,7 @@ type CommChanceItemOrm struct {
Videos string `orm:"column(videos)"`
PublishStatus int `orm:"column(publish_status)"` //公开状态
Status int `orm:"column(status)"` //开启状态
ApproveData string `orm:"column(chance_approve_data)"` //审核数据
ChanceApproveData string `orm:"column(chance_approve_data)"` //审核数据
CommentTotal int `orm:"column(comment_total)"`
ZanTotal int `orm:"column(zan_total)"`
ViewTotal int `orm:"column(view_total)"`
... ...
... ... @@ -272,15 +272,7 @@ type MsgChanceReviseResponse struct {
//我的审核机会列表
type MsgChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus int `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
ReviewStatus int `orm:"column(review_status)"`
Status int `orm:"column(status)"`
ApproveData string `orm:"column(approve_data)"` //审核数据
CommChanceItemOrm
Id int64 `orm:"column(id)"` //消息id
MsgTime time.Time `orm:"column(msg_time)"`
... ... @@ -289,10 +281,10 @@ type MsgChanceApproveItemOrm struct {
CreateTime time.Time `orm:"column(create_at)"`
Message string `orm:"column(message)"`
IsRead int64 `orm:"column(is_read)"`
ChanceId int64 `orm:"column(chance_id)"` // 机会id
//EnableStatus int `orm:"column(enable_status)"`
SourceId int64 `orm:"column(source_id)"` // 机会id
Data string `orm:"column(data)"`
//ChanceId int64 `orm:"column(chance_id)"` // 机会id
EnableStatus int `orm:"column(enable_status)"`
SourceId int64 `orm:"column(source_id)"` // 机会id
Data string `orm:"column(data)"`
}
/*Announcement H5公告详情*/
... ...
... ... @@ -1523,7 +1523,7 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh
commItem.ReviewStatus = ormItem.ReviewStatus
if request.ReviewStatus == protocol.ReviewStatusPass {
var approveData protocol.ApproveData
jsonUnmarshal(ormItem.ApproveData, &approveData)
jsonUnmarshal(ormItem.ChanceApproveData, &approveData)
commItem.Score = approveData.Score
}
rsp.List = append(rsp.List, commItem)
... ...
... ... @@ -303,11 +303,10 @@ func MsgCompanyNotice(header *protocol.RequestHeader, request *protocol.MsgCompa
//消息中心-机会审核消息
func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanceApproveRequest) (rsp *protocol.MsgChanceApproveResponse, err error) {
var (
myChances []protocol.MsgChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.MsgChanceApproveItemOrm
total int
)
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &myChances); err != nil {
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAudit, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -317,49 +316,18 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceApproveResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
continue
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = agg.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
//if chance.ReviewStatus == protocol.ReviewStatusPass {
// var approveData *protocol.ApproveData
// utils.JsonUnmarshal(chance.ApproveData, &approveData)
// if approveData != nil {
// commItem.Score = approveData.Score
// }
//}
commItem.MsgId = chance.Id
commItem.MsgTime = chance.MsgTime.Unix() * 1000
commItem.MsgId = ormItem.Id
commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
//审核完有审核数据
commItem.Message = chance.Message
commItem.IsRead = chance.IsRead == 1
commItem.ChanceId = chance.ChanceId
commItem.Message = ormItem.Message
commItem.IsRead = ormItem.IsRead == 1
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -368,11 +336,10 @@ func MsgChanceApprove(header *protocol.RequestHeader, request *protocol.MsgChanc
// 消息中心-我提交的
func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChanceSubmitRequest) (rsp *protocol.MsgChanceSubmitResponse, err error) {
var (
myChances []protocol.MsgChanceApproveItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.MsgChanceApproveItemOrm
)
if total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &myChances); err != nil {
rsp = &protocol.MsgChanceSubmitResponse{List: make([]protocol.MsgCommonListItem, 0)}
if rsp.Total, err = models.GetChanceMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeAuditBy, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -380,62 +347,33 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
log.Error(err)
return
}
rsp = &protocol.MsgChanceSubmitResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
approveUserId := chance.ChanceUserId
if chance.SenderUserId != 0 {
approveUserId = chance.SenderUserId
}
if provider, err = agg.GetUserBaseInfo(approveUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
continue
} else {
item := protocol.ChanceItem{
Id: chance.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = agg.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
//注:此处是审核人的用户信息
if ormItem.SenderUserId != 0 {
ormItem.CommChanceItemOrm.ChanceUserId = ormItem.SenderUserId
}
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
//if chance.ReviewStatus == protocol.ReviewStatusPass {
// var approveData *protocol.ApproveData
// utils.JsonUnmarshal(chance.ApproveData, &approveData)
// if approveData != nil {
// commItem.Score = approveData.Score
// }
//}
if len(chance.Data) > 0 && chance.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass
//审核数据
if len(ormItem.Data) > 0 && ormItem.ReviewStatus != protocol.ReviewStatusReturn { //获取评分 && chance.ReviewStatus == protocol.ReviewStatusPass
var msgData *protocol.MsgData
utils.JsonUnmarshal(chance.Data, &msgData)
utils.JsonUnmarshal(ormItem.Data, &msgData)
commItem.Score = msgData.Score
}
commItem.IsRead = chance.IsRead == 1
//审核完有审核数据
commItem.Message = chance.Message
commItem.MsgId = chance.Id
commItem.MsgTime = chance.MsgTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
if commItem.ChanceId == 0 && chance.SourceId > 0 {
commItem.ChanceId = chance.SourceId
//消息基础数据
commItem.IsRead = ormItem.IsRead == 1
commItem.Message = ormItem.Message
commItem.MsgId = ormItem.Id
commItem.MsgTime = ormItem.MsgTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
if commItem.ChanceId == 0 && ormItem.SourceId > 0 {
commItem.ChanceId = ormItem.SourceId
}
rsp.List = append(rsp.List, commItem) //非指针 append对象完 再修改数据也是无效
}
... ... @@ -445,11 +383,11 @@ func MsgChanceSubmit(header *protocol.RequestHeader, request *protocol.MsgChance
// 消息中心-互动消息.评论
func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanceCommentRequest) (rsp *protocol.MsgChanceCommentResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &myChances); err != nil {
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeComment, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -459,66 +397,46 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceCommentResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.ChanceUserId > 0 {
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
if ormItem.SourceType == protocol.SourceTypeChance {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
//被评论内容
if ormItem.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Id: ormItem.SourceId,
Content: ormItem.CommentedContent,
CommentTime: ormItem.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
//评论内容
comment := protocol.CommentData{
Id: chance.CommentId,
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
CommentTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
//Provider: provider,
}
comment.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId)
comment.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
commItem.CommentData = comment
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.MsgTime = chance.CommentTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
//消息基础内容
commItem.IsRead = ormItem.IsRead == 1
commItem.SourceType = ormItem.SourceType
commItem.MsgId = ormItem.CommentId
commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ... @@ -527,11 +445,11 @@ func MsgChanceComment(header *protocol.RequestHeader, request *protocol.MsgChanc
//消息中心-互动消息.点赞
func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanceThumbUpRequest) (rsp *protocol.MsgChanceThumbUpResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &myChances); err != nil {
if total, err = models.GetChanceCommentMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeThumbUp, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -541,65 +459,44 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc
}
rsp = &protocol.MsgChanceThumbUpResponse{Total: total}
rsp.List = make([]protocol.MsgCommonListItem, 0)
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := protocol.MsgCommonListItem{}
if chance.SourceType == protocol.SourceTypeChance {
commItem.ReviewStatus = chance.ReviewStatus
if len(chance.SourceContent) == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
} else if chance.ChanceEnableStatus == 0 { //机会关闭
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if chance.Status == models.ChanceStatusClose {
commItem.ChanceStatus = protocol.ChanceStatusClose
}
if provider, err = agg.GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
} else {
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
}
utils.JsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = protocol.ClearEmptyForm(item.FormList)
utils.JsonUnmarshal(chance.Images, &item.Pictures)
utils.JsonUnmarshal(chance.Voices, &item.Speechs)
utils.JsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
commItem.ReviewStatus = chance.ReviewStatus
if ormItem.SourceType == protocol.SourceTypeChance {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(chance.CommentedUserId, header.CompanyId); err != nil {
//点赞评论的内容
if ormItem.SourceType == protocol.SourceTypeComment {
if provider, err = agg.GetUserBaseInfo(ormItem.CommentedUserId, header.CompanyId); err != nil {
commItem.ChanceStatus = protocol.ChanceStatusDelete
log.Error(err)
//return
}
commItem.CommentedData = protocol.CommentData{
Id: chance.SourceId,
Content: chance.CommentedContent,
CommentTime: chance.CommentedTime.Unix() * 1000,
Id: ormItem.SourceId,
Content: ormItem.CommentedContent,
CommentTime: ormItem.CommentedTime.Unix() * 1000,
Provider: provider,
}
}
//点赞数据
thumb := protocol.ThumbUpData{
Id: chance.CommentId,
ThumbUpTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
ThumbUpTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
//Provider: provider,
}
thumb.Provider, _ = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId)
thumb.Provider, _ = agg.GetUserBaseInfo(ormItem.SenderUserId, header.CompanyId)
commItem.ThumbUpData = thumb
commItem.IsRead = chance.IsRead == 1
commItem.SourceType = chance.SourceType
commItem.MsgId = chance.CommentId
commItem.MsgTime = chance.CommentTime.Unix() * 1000
commItem.ChanceId = chance.ChanceId
//消息基础数据
commItem.IsRead = ormItem.IsRead == 1
commItem.SourceType = ormItem.SourceType
commItem.MsgId = ormItem.CommentId
commItem.MsgTime = ormItem.CommentTime.Unix() * 1000
commItem.ChanceId = ormItem.ChanceId
rsp.List = append(rsp.List, commItem)
}
return
... ...