作者 yangfu

我的文章、评论回复列表搜索

... ... @@ -78,7 +78,7 @@ service Core {
@server(
prefix: v1/system
group: article
jwt: MiniAuth
jwt: SystemAuth
)
service Core {
@doc "管理后台获取文章内容详情"
... ... @@ -88,4 +88,8 @@ service Core {
@doc "管理后台获取文章列表"
@handler SystemSearchArticle
post /article/search (SystemArticleSearchRequest) returns (SystemArticleSearchResponse)
@doc "管理后台获取我发布的文章"
@handler SystemArticleSearchMe
post /article/search/me (SystemArticleSearchMeRequest) returns (SystemArticleSearchMeResponse)
}
\ No newline at end of file
... ...
... ... @@ -88,6 +88,18 @@ type (
CountComment int `json:"CountComment"` //评论数量
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
SystemArticleSearchMeRequest {
Page int `json:"page"`
Size int `json:"size"`
AuthorId int64 `json:"authorId"` // 用户
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
SystemArticleSearchMeResponse {
Total int `json:"total"`
List []ArticleSearchMe `json:"list"`
}
)
//小程序端获取文章有哪些人进行了点赞
... ...
... ... @@ -45,6 +45,19 @@ service Core {
post /article_comment/at_who/list (MiniArticleCommentAtWhoRequest) returns (MiniArticleCommentAtWhoResponse)
}
// 后台接口
@server(
prefix: v1/system
group: comment
middleware: LoginStatusCheck
jwt: SystemAuth
)
service Core {
@doc "小程序获取回复@人可选列表"
@handler SystemArticleCommentSearchMe
post /article_comment/search/me (SystemArticleCommentSearchMeRequest) returns (SystemArticleCommentSearchMeResponse)
}
//
// 小程序获取回复@人可选列表
type (
... ... @@ -138,6 +151,7 @@ type (
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
Content string `json:"content"` // 评论的内容
}
)
... ... @@ -189,4 +203,18 @@ type (
MiniArticleCommentAtWhoResponse {
List []CommentAtWho `json:"list"`
}
)
type(
SystemArticleCommentSearchMeRequest{
Page int `json:"page"`
Size int `json:"size"`
AuthorId int64 `json:"authorId"` // 用户
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
SystemArticleCommentSearchMeResponse{
List []ArticleCommentItem `json:"list"`
Total int64 `json:"total"`
}
)
\ No newline at end of file
... ...
... ... @@ -261,11 +261,13 @@ type(
Code string `json:"code"`
}
UserStatisticsRequest{
UserId int64 `json:"userId"`
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
UserId int64 `json:"userId,optional"`
ItemFlag int `json:"itemFlag"` //0:默认查询所有 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
}
UserStatisticsResponse{
List []StatisticsItem `json:"list"`
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
}
StatisticsItem{
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
... ...
package article
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/article"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemArticleSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := article.NewSystemArticleSearchMeLogic(r.Context(), svcCtx)
resp, err := l.SystemArticleSearchMe(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
package comment
import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.SystemArticleCommentSearchMeRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := comment.NewSystemArticleCommentSearchMeLogic(r.Context(), svcCtx)
resp, err := l.SystemArticleCommentSearchMe(&req)
result.HttpResult(r, w, resp, err)
}
}
... ...
... ... @@ -61,6 +61,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
)
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.LoginStatusCheck},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/article_comment/search/me",
Handler: comment.SystemArticleCommentSearchMeHandler(serverCtx),
},
}...,
),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
server.AddRoutes(
[]rest.Route{
{
Method: http.MethodPost,
... ... @@ -371,8 +386,13 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/article/search",
Handler: article.SystemSearchArticleHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/article/search/me",
Handler: article.SystemArticleSearchMeHandler(serverCtx),
},
},
rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret),
rest.WithJwt(serverCtx.Config.SystemAuth.AccessSecret),
rest.WithPrefix("/v1/system"),
)
... ...
... ... @@ -42,19 +42,24 @@ func (l *MiniArticleSearchMeLogic) MiniArticleSearchMe(req *types.MiniArticleSea
List: make([]types.ArticleSearchMe, len(articleList)),
}
for i := range articleList {
images := []string{}
for _, val2 := range articleList[i].Images {
images = append(images, val2.Url)
}
resp.List[i] = types.ArticleSearchMe{
Id: articleList[i].Id,
Title: articleList[i].Title,
Images: images,
CreatedAt: articleList[i].CreatedAt,
CountLove: articleList[i].CountLove,
CountComment: articleList[i].CountComment,
Show: int(articleList[i].Show),
}
resp.List[i] = NewArticle(articleList[i])
}
return
}
func NewArticle(article *domain.Article) types.ArticleSearchMe {
images := []string{}
for _, val2 := range article.Images {
images = append(images, val2.Url)
}
articleSearchMe := types.ArticleSearchMe{
Id: article.Id,
Title: article.Title,
Images: images,
CreatedAt: article.CreatedAt,
CountLove: article.CountLove,
CountComment: article.CountComment,
Show: int(article.Show),
}
return articleSearchMe
}
... ...
package article
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemArticleSearchMeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemArticleSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleSearchMeLogic {
return &SystemArticleSearchMeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemArticleSearchMeLogic) SystemArticleSearchMe(req *types.SystemArticleSearchMeRequest) (resp *types.SystemArticleSearchMeResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("authorId", req.AuthorId).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
cnt, articleList, err := l.svcCtx.ArticleRepository.Find(l.ctx, conn, userToken.CompanyId, queryOptions)
if err != nil {
return &types.SystemArticleSearchMeResponse{}, xerr.NewErrMsgErr("获取文章列表失败", err)
}
resp = &types.SystemArticleSearchMeResponse{
Total: int(cnt),
List: make([]types.ArticleSearchMe, len(articleList)),
}
for i := range articleList {
resp.List[i] = NewArticle(articleList[i])
}
return
}
... ...
... ... @@ -51,36 +51,7 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
List: make([]types.ArticleCommentItem, len(commentList)),
}
for i, val := range commentList {
item := types.ArticleCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArtitcleId: val.ArticleId,
SectionId: val.SectionId,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
Id: val.FromUser.Id,
Name: val.FromUser.Name,
Avatar: val.FromUser.Avatar,
Position: val.FromUser.Position,
Company: val.FromUser.Company,
},
ToUserId: val.ToUserId,
ToUser: types.CommentAuthor{
Id: val.ToUser.Id,
Name: val.ToUser.Name,
Avatar: val.ToUser.Avatar,
Position: val.ToUser.Position,
Company: val.ToUser.Company,
},
SectionContent: val.SectionContent,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
AtWho: []types.CommentAtWho{},
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
}
item := NewArticleCommentItem(val)
if _, ok := flagMap[val.Id]; ok {
item.MeLoveFlag = 1
... ... @@ -95,3 +66,38 @@ func (l *MiniTop5ArticleCommentLogic) MiniTop5ArticleComment(req *types.MiniTop5
}
return
}
func NewArticleCommentItem(val *domain.ArticleComment) types.ArticleCommentItem {
item := types.ArticleCommentItem{
Id: val.Id,
Pid: val.Pid,
TopId: val.TopId,
ArtitcleId: val.ArticleId,
SectionId: val.SectionId,
FromUserId: val.FromUserId,
FromUser: types.CommentAuthor{
Id: val.FromUser.Id,
Name: val.FromUser.Name,
Avatar: val.FromUser.Avatar,
Position: val.FromUser.Position,
Company: val.FromUser.Company,
},
ToUserId: val.ToUserId,
ToUser: types.CommentAuthor{
Id: val.ToUser.Id,
Name: val.ToUser.Name,
Avatar: val.ToUser.Avatar,
Position: val.ToUser.Position,
Company: val.ToUser.Company,
},
SectionContent: val.SectionContent,
CountReply: val.CountReply,
CountUserLove: val.CountUserLove,
CountAdminLove: val.CountAdminLove,
AtWho: []types.CommentAtWho{},
CreatedAt: val.CreatedAt,
MeLoveFlag: 0,
Content: val.Content,
}
return item
}
... ...
package comment
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type SystemArticleCommentSearchMeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewSystemArticleCommentSearchMeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SystemArticleCommentSearchMeLogic {
return &SystemArticleCommentSearchMeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *SystemArticleCommentSearchMeLogic) SystemArticleCommentSearchMe(req *types.SystemArticleCommentSearchMeRequest) (resp *types.SystemArticleCommentSearchMeResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
queryOptions := domain.IndexCompanyId(userToken.CompanyId)().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("fromUserId", req.AuthorId).
WithKV("beginCreatedAt", req.BeginTime).
WithKV("endCreatedAt", req.EndTime)
cnt, articleList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOptions)
if err != nil {
return &types.SystemArticleCommentSearchMeResponse{}, xerr.NewErrMsgErr("获取评论回复列表失败", err)
}
resp = &types.SystemArticleCommentSearchMeResponse{
Total: cnt,
List: make([]types.ArticleCommentItem, len(articleList)),
}
for i := range articleList {
resp.List[i] = NewArticleCommentItem(articleList[i])
}
return
}
... ...
... ... @@ -2,6 +2,8 @@ package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
... ... @@ -24,7 +26,58 @@ func NewSystemUserStatisticsLogic(ctx context.Context, svcCtx *svc.ServiceContex
}
func (l *SystemUserStatisticsLogic) SystemUserStatistics(req *types.UserStatisticsRequest) (resp *types.UserStatisticsResponse, err error) {
// todo: add your logic here and delete this line
var (
userId = req.UserId
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
s := StatisticsItems(l.ctx, l.svcCtx, userToken.CompanyId, userId, req.ItemFlag)
resp = &types.UserStatisticsResponse{
TotalArticle: s.TotalArticle,
TotalComment: s.TotalComment,
TotalLoved: s.TotalLoved,
}
return
}
func StatisticsItems(ctx context.Context, svcCtx *svc.ServiceContext, companyId, userId int64, itemFlag int) (s Statistics) {
var conn = svcCtx.DefaultDBConn()
s = Statistics{}
if itemFlag == 0 {
itemFlag = -1
}
if (itemFlag & TotalArticle) > 0 {
var total int64
total, _, _ = svcCtx.ArticleRepository.Find(ctx, conn, companyId, domain.NewQueryOptions().WithCountOnly().MustWithKV("authorId", userId))
s.TotalArticle = int(total)
}
if (itemFlag & TotalComment) > 0 {
var total int64
total, _, _ = svcCtx.ArticleCommentRepository.Find(ctx, conn, domain.IndexCompanyId(companyId)().WithCountOnly().MustWithKV("fromUserId", userId))
s.TotalComment = int(total)
}
if (itemFlag & TotalLoved) > 0 {
var total int64
total, _, _ = svcCtx.UserLoveFlagRepository.Find(ctx, conn, domain.IndexCompanyId(companyId)().WithCountOnly().MustWithKV("userId", userId))
s.TotalComment = int(total)
}
return
}
type Statistics struct {
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
}
const (
TotalArticle = 1
TotalComment = 2
TotalLoved = 4
)
func NewStatisticsItem(itemFlag int, value float64) types.StatisticsItem {
return types.StatisticsItem{
ItemFlag: itemFlag,
Value: value,
}
}
... ...
... ... @@ -86,6 +86,7 @@ type ArticleCommentItem struct {
AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
CreatedAt int64 `json:"createdAt"` //
MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
Content string `json:"content"` // 评论的内容
}
type MiniGetArticleCommentRequest struct {
... ... @@ -128,6 +129,19 @@ type MiniArticleCommentAtWhoResponse struct {
List []CommentAtWho `json:"list"`
}
type SystemArticleCommentSearchMeRequest struct {
Page int `json:"page"`
Size int `json:"size"`
AuthorId int64 `json:"authorId"` // 用户
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type SystemArticleCommentSearchMeResponse struct {
List []ArticleCommentItem `json:"list"`
Total int64 `json:"total"`
}
type MessageSystemRequest struct {
Page int `json:"page"`
Size int `json:"size"`
... ... @@ -427,12 +441,14 @@ type SystemUserInfoResponse struct {
}
type UserStatisticsRequest struct {
UserId int64 `json:"userId"`
ItemFlag int `json:"itemFlag"` // 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
UserId int64 `json:"userId,optional"`
ItemFlag int `json:"itemFlag"` //0:默认查询所有 1:他的帖子 2:他的评论/回复 4:他收到的赞 8:TA的圆桌讨论 16:被采纳
}
type UserStatisticsResponse struct {
List []StatisticsItem `json:"list"`
TotalArticle int `json:"totalArticle"`
TotalComment int `json:"totalComment"`
TotalLoved int `json:"totalLoved"`
}
type StatisticsItem struct {
... ... @@ -639,6 +655,19 @@ type ArticleSearchMe struct {
Show int `json:"show"` //是否隐藏 [0显示、1不显示]
}
type SystemArticleSearchMeRequest struct {
Page int `json:"page"`
Size int `json:"size"`
AuthorId int64 `json:"authorId"` // 用户
BeginTime int64 `json:"beginTime,optional"` // 开始时间
EndTime int64 `json:"endTime,optional"` // 结束时间
}
type SystemArticleSearchMeResponse struct {
Total int `json:"total"`
List []ArticleSearchMe `json:"list"`
}
type MiniUserLikeArticleRequest struct {
ArticleId int64 `json:"articleId"` // 文章id
CompanyId int64 `json:",optional"` //公司id
... ...
... ... @@ -137,10 +137,18 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
if v, ok := queryOptions["sectionId"]; ok {
tx = tx.Where("section_id=?", v)
}
if v, ok := queryOptions["companyId"]; ok {
tx = tx.Where("company_id=?", v)
}
if v, ok := queryOptions["fromUserId"]; ok {
tx = tx.Where("from_user_id=?", v)
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
if v, ok := queryOptions["endCreatedAt"]; ok {
tx = tx.Where("created_at < ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
... ...
... ... @@ -127,6 +127,12 @@ func (repository *ArticleRepository) Find(ctx context.Context, conn transaction.
if v, ok := queryOptions["authorId"]; ok {
tx = tx.Where("author_id = ?", v)
}
if v, ok := queryOptions["beginCreatedAt"]; ok {
tx = tx.Where("created_at >= ?", v)
}
if v, ok := queryOptions["endCreatedAt"]; ok {
tx = tx.Where("created_at < ?", v)
}
if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
... ...
... ... @@ -126,6 +126,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac
if v, ok := queryOptions["commentId"]; ok {
tx = tx.Where("comment_id=?", v)
}
if v, ok := queryOptions["companyId"]; ok {
tx = tx.Where("company_id=?", v)
}
if v, ok := queryOptions["userId"]; ok {
tx = tx.Where("user_id=?", v)
}
... ...