...
|
...
|
@@ -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,
|
|
|
}
|
|
|
} |
...
|
...
|
|