作者 yangfu

重构-我的点赞/收藏/评论

... ... @@ -247,7 +247,7 @@ func GetChanceComment(uid int64, lastId int64, pageSize int, v interface{}) (tot
sql := fmt.Sprintf(`select a.*,b.content commented_content,b.create_at commented_time,b.user_id commented_user_id
from (
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.publish_status,b.status from (
select a.*,b.id chance_id,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.approve_data,b.publish_status,b.status from (
select id,content,view_total,zan_total,comment_total,source_type,source_id,create_at comment_time from comment
where user_id =? and (?=0 or id<?)
)a left outer join chance b on a.source_id = b.id and source_type=1
... ...
... ... @@ -223,7 +223,7 @@ func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceIte
PublicStatus: chance.PublishStatus,
}
item.UpdateTime = chance.UpdateTime.Unix() * 1000
item.ApproveTime = chance.UpdateTime.Unix() * 1000
item.ApproveTime = chance.ChanceApproveTime.Unix() * 1000
if item.ApproveTime < 0 {
item.ApproveTime = 0
}
... ...
... ... @@ -1704,62 +1704,32 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.ChanceId
//if len(ormItem.SourceContent) == 0 || ormItem.ChanceEnableStatus == 0 { //机会删除
// commItem.ChanceStatus = protocol.ChanceStatusDelete
//}
//if ormItem.Status == models.ChanceStatusClose { //机会关闭
// commItem.ChanceStatus = protocol.ChanceStatusClose
//}
//
//if ormItem.ChanceUserId > 0 {
// if provider, err = agg.GetUserBaseInfo(ormItem.ChanceUserId, header.CompanyId); err != nil {
// commItem.ChanceStatus = protocol.ChanceStatusDelete
// log.Error(err)
// //return
// } else {
// item := protocol.ChanceItem{
// Id: ormItem.ChanceId,
// Provider: provider,
// CreateTime: ormItem.CreateTime.Unix() * 1000,
// PublicStatus: ormItem.PublishStatus,
// }
// jsonUnmarshal(ormItem.SourceContent, &item.FormList)
// item.FormList = clearEmptyForm(item.FormList)
// jsonUnmarshal(ormItem.Images, &item.Pictures)
// jsonUnmarshal(ormItem.Voices, &item.Speechs)
// jsonUnmarshal(ormItem.Videos, &item.Videos)
// commItem.Chance = item
// }
//}
//
//commItem.ReviewStatus = ormItem.ReviewStatus
{
var chanceData = protocol.ChanceData{
ThumbsUpTotal: ormItem.ZanTotal,
CommentTotal: ormItem.CommentTotal,
PageViewTotal: ormItem.ViewTotal,
}
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
commItem.ChanceData = chanceData
}
{
//做一次查询 查回所有的模板数据
commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
//chanceData
var chanceData = protocol.ChanceData{
ThumbsUpTotal: ormItem.ZanTotal,
CommentTotal: ormItem.CommentTotal,
PageViewTotal: ormItem.ViewTotal,
}
{
collect := protocol.CollectData{
Id: ormItem.CollectId,
CollectTime: ormItem.CollectTime.Unix() * 1000,
}
if collect.CollectTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
collect.CollectTime = ormItem.UpdateTime.Unix() * 1000
}
//收藏数据
commItem.CollectData = collect
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
commItem.ChanceData = chanceData
//commItem.ChanceId = chance.ChanceId
//做一次查询 查回所有的模板数据
commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
//收藏数据
collect := protocol.CollectData{
Id: ormItem.CollectId,
CollectTime: ormItem.CollectTime.Unix() * 1000,
}
if collect.CollectTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
collect.CollectTime = ormItem.UpdateTime.Unix() * 1000
}
commItem.CollectData = collect
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ... @@ -1769,10 +1739,9 @@ func MyCollectChance(header *protocol.RequestHeader, request *protocol.MyCollect
//我点赞的机会
func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUpChanceRequest) (rsp *protocol.MyThumbUpChanceResponse, err error) {
var (
myChances []protocol.ChanceThumbUpItemOrm
total int
provider *protocol.BaseUserInfo
favorite *models.ChanceFavorite
ormItems []protocol.ChanceThumbUpItemOrm
total int
favorite *models.ChanceFavorite
)
if request.LastId > 0 {
if favorite, err = models.GetChanceFavoriteById(request.LastId); err != nil {
... ... @@ -1781,7 +1750,7 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
}
request.LastId = favorite.ZanTime.Unix()
}
if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = models.GetChanceThumbUp(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1790,63 +1759,38 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
return
}
rsp = &protocol.MyThumbUpChanceResponse{Total: total}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := &protocol.CommonListItem{}
commItem.ReviewStatus = chance.ReviewStatus
commItem.ChanceId = chance.ChanceId
if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除
commItem.ChanceStatus = protocol.ChanceStatusDelete
}
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.ChanceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
}
}
commItem.ReviewStatus = chance.ReviewStatus
{
var chanceData = protocol.ChanceData{
ThumbsUpTotal: chance.ZanTotal,
CommentTotal: chance.CommentTotal,
PageViewTotal: chance.ViewTotal,
}
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, chance.ChanceId)
commItem.ChanceData = chanceData
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.ChanceId
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
//点赞收藏数据
var chanceData = protocol.ChanceData{
ThumbsUpTotal: ormItem.ZanTotal,
CommentTotal: ormItem.CommentTotal,
PageViewTotal: ormItem.ViewTotal,
}
{
//做一次查询 查回所有的模板数据
commItem.ChanceTemplate = getTemplate(chance.TemplateId)
commItem.ChanceType = getChanceType(chance.ChanceTypeId)
chanceData.IsThumbsUp, chanceData.IsCollect, _ = getChanceMarkFlag(header, ormItem.ChanceId)
commItem.ChanceData = chanceData
//模板数据
commItem.ChanceTemplate = getTemplate(ormItem.TemplateId)
commItem.ChanceType = getChanceType(ormItem.ChanceTypeId)
//点赞数据
thumb := protocol.ThumbUpData{
Id: ormItem.CollectId,
ThumbUpTime: ormItem.ZanTime.Unix() * 1000,
}
{
thumb := protocol.ThumbUpData{
Id: chance.CollectId,
ThumbUpTime: chance.ZanTime.Unix() * 1000,
}
if thumb.ThumbUpTime <= 0 && chance.UpdateTime.Unix() > 0 {
thumb.ThumbUpTime = chance.UpdateTime.Unix() * 1000
}
//收藏数据
commItem.ThumbUpData = thumb
if thumb.ThumbUpTime <= 0 && ormItem.UpdateTime.Unix() > 0 {
thumb.ThumbUpTime = ormItem.UpdateTime.Unix() * 1000
}
commItem.ThumbUpData = thumb
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ... @@ -1856,11 +1800,11 @@ func MyThumbUpChance(header *protocol.RequestHeader, request *protocol.MyThumbUp
//我的评论
func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentRequest) (rsp *protocol.MyCommentResponse, err error) {
var (
myChances []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
ormItems []protocol.ChanceCommentItemOrm
total int
provider *protocol.BaseUserInfo
)
if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &myChances); err != nil {
if total, err = models.GetChanceComment(header.UserId, request.LastId, request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
... ... @@ -1873,47 +1817,30 @@ func MyComment(header *protocol.RequestHeader, request *protocol.MyCommentReques
log.Error(err)
return
}
for i := 0; i < len(myChances); i++ {
chance := myChances[i]
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := &protocol.CommonListItem{}
commItem.ChanceId = chance.SourceId
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
}
item := protocol.ChanceItem{
Id: chance.SourceId,
Provider: provider,
CreateTime: chance.CreateTime.Unix() * 1000,
PublicStatus: chance.PublishStatus,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
item.FormList = clearEmptyForm(item.FormList)
jsonUnmarshal(chance.Images, &item.Pictures)
jsonUnmarshal(chance.Voices, &item.Speechs)
jsonUnmarshal(chance.Videos, &item.Videos)
commItem.Chance = item
commItem.ReviewStatus = chance.ReviewStatus
}
if chance.SourceType == protocol.SourceTypeComment {
commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, ormItem.CommChanceItemOrm)
commItem.ReviewStatus = ormItem.ReviewStatus
commItem.ChanceId = ormItem.SourceId
commItem.Chance.UpdateTime = 0
commItem.Chance.ApproveTime = 0
commItem.Chance.Provider = provider
//被评论的数据内容
if ormItem.SourceType == protocol.SourceTypeComment {
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,
}
}
//评论内容
commItem.CommentData = protocol.CommentData{
Id: chance.CommentId,
CommentTime: chance.CommentTime.Unix() * 1000,
Content: chance.CommentContent,
Id: ormItem.CommentId,
CommentTime: ormItem.CommentTime.Unix() * 1000,
Content: ormItem.CommentContent,
}
commItem.SourceType = chance.SourceType
commItem.SourceType = ormItem.SourceType
rsp.List = append(rsp.List, commItem)
}
agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.List)
... ...