作者 tangxvhui
... ... @@ -144,7 +144,9 @@ type(
AuthorId int64 `json:"authorId"` // 特定作者ID
LastArticleId int64 `json:"lastArticleId,optional"`// 最后文章ID
Size int `json:"size"` // 数量
OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc
//OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc
OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)
OrderByValue string `json:"orderByValue,options=asc||desc,optional"` // 排序值 升序 asc 降序 desc
Keywords string `json:"keywords,optional"` // 关键字
BeginTime int64 `json:"beginTime,optional"`// 开始时间
EndTime int64 `json:"endTime,optional"`// 结束时间
... ...
... ... @@ -54,8 +54,8 @@ func (l *MiniHomePageUserInfoLogic) MiniHomePageUserInfo(req *types.MiniHomePage
Enable: user.Enable,
},
TotalFollower: len(user.Follower),
Followed: lo.Contains(currentUser.Following, user.Id),
MutualFollowed: lo.Contains(user.Following, currentUser.Id),
Followed: currentUser.IsFollowed(user.Id),
MutualFollowed: currentUser.IsFriend(user.Id),
}
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
resp.User.CompanyName = company.Name
... ...
... ... @@ -50,9 +50,17 @@ func (l *MiniHomepageUserNewsLogic) MiniHomepageUserNews(req *types.MiniHomepage
queryOptions := domain.IndexCompanyId(userToken.CompanyId)().
WithKV("beginTime", req.BeginTime).
WithKV("endTime", req.EndTime).
WithKV("keywords", req.Keywords).
WithKV("orderByHotScore", req.OrderByHotScore)
WithKV("keywords", req.Keywords)
if len(req.OrderByKey) > 0 && len(req.OrderByValue) > 0 {
switch req.OrderByKey {
case "HotScore":
queryOptions.WithKV("orderByHotScore", req.OrderByValue)
case "All":
queryOptions.WithKV("orderByAll", req.OrderByValue)
case "Time":
queryOptions.WithKV("orderByAll", req.OrderByValue)
}
}
var users = []int64{req.AuthorId}
if _, articles, err = l.svcCtx.ArticleRepository.FindAuthorsLatestArticle(l.ctx, conn, user.CompanyId, users, currentUser.Id, req.LastArticleId, req.Size, queryOptions.Copy().WithFindOnly()); err != nil {
return nil, xerr.NewErrMsgErr("获取快讯异常", err)
... ...
... ... @@ -76,7 +76,7 @@ func follower(ctx context.Context, svcCtx *svc.ServiceContext, user *domain.User
Avatar: foundUser.Avatar,
Position: foundUser.Position,
Followed: true,
MutualFollowed: lo.Contains(user.Following, item),
MutualFollowed: user.IsFriend(item),
})
}
})
... ...
... ... @@ -64,6 +64,7 @@ func (l *MiniAtUsersListLogic) MiniAtUsersList(req *types.MiniUsersListRequest)
Name: item.Name,
PinYinName: item.PinYinName,
Avatar: item.Avatar,
Position: item.Position,
})
})
return map[string]interface{}{
... ...
... ... @@ -485,13 +485,14 @@ type MiniHomePageUserBeLikedResponse struct {
}
type MiniHomepageUserNewsRequest struct {
AuthorId int64 `json:"authorId"` // 特定作者ID
LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID
Size int `json:"size"` // 数量
OrderByHotScore string `json:"orderByHotScore,options=asc|desc,optional,default=desc"` // 热度排序 升序 asc 降序 desc
Keywords string `json:"keywords,optional"` // 关键字
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
AuthorId int64 `json:"authorId"` // 特定作者ID
LastArticleId int64 `json:"lastArticleId,optional"` // 最后文章ID
Size int `json:"size"` // 数量
OrderByKey string `json:"orderByKey,options=HotScore|All|Time,optional,default=desc"` // 按规则排序 (热度:HotScore All:时间排序 Time:时间排序)
OrderByValue string `json:"orderByValue,options=asc||desc,optional"`
Keywords string `json:"keywords,optional"` // 关键字
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type MiniHomepageUserNewsResposne struct {
... ...
... ... @@ -234,6 +234,8 @@ func (repository *ArticleRepository) FindAuthorsLatestArticle(ctx context.Contex
}
if v, ok := queryOptions["orderByHotScore"]; ok {
tx.Order(fmt.Sprintf("(count_comment+count_love) %v", v))
} else if v, ok := queryOptions["orderByAll"]; ok {
tx.Order(fmt.Sprintf("id %v", v))
} else {
tx.Order("id desc")
}
... ...
... ... @@ -136,6 +136,15 @@ func (m *User) WithName(name string) *User {
return m
}
func (m *User) IsFollowed(userId int64) bool {
return lo.Contains(m.Following, userId)
}
// IsFriend 如果是好友,为互相关注
func (m *User) IsFriend(userId int64) bool {
return lo.Contains(m.Following, userId) && lo.Contains(m.Follower, userId)
}
type (
LoginCreator interface {
WechatLogin(r WechatLoginRequest) (*LoginInfo, error)
... ...