作者 郑周

Merge remote-tracking branch 'origin/dev' into dev

... ... @@ -95,10 +95,12 @@ type (
// 小程序获取文章的评论列表
type (
MiniListArticleCommentRequest {
Page int64 `json:"page"`
Size int64 `json:"size"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
SectionId int64 `json:"sectionId"`
UserId int64 `json:",optional"`
ArticleId int64 `json:"articleId"`
SectionId int64 `json:"sectionId,optional"`
}
MiniListArticleCommentResponse {
Total int64 `json:"total"`
... ...
... ... @@ -14,14 +14,19 @@ info(
jwt: SystemAuth
)
service Core {
@doc "角色详情"
@handler systemGetRole
get /system/role/:id (RoleGetRequest) returns (RoleGetResponse)
@doc "角色新增"
@handler systemSaveRole
post /system/role (RoleSaveRequest) returns (RoleSaveResponse)
@doc "角色删除"
@handler systemDeleteRole
delete /system/role/:id (RoleDeleteRequest) returns (RoleDeleteResponse)
@doc "角色更新"
@handler systemUpdateRole
put /system/role/:id (RoleUpdateRequest) returns (RoleUpdateResponse)
@doc "角色列表搜索"
@handler systemSearchRole
post /system/role/search (RoleSearchRequest) returns (RoleSearchResponse)
}
... ...
... ... @@ -22,6 +22,7 @@ func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
req.UserId = token.UserId
resp, err := l.MiniGetArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
... ...
... ... @@ -21,6 +21,7 @@ func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx)
token := contextdata.GetUserTokenFromCtx(r.Context())
req.CompanyId = token.CompanyId
req.UserId = token.UserId
resp, err := l.MiniListArticleComment(&req)
result.HttpResult(r, w, resp, err)
}
... ...
... ... @@ -11,6 +11,7 @@ import (
"text/template"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -49,13 +50,12 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
return nil, xerr.NewErrMsg("没有评论权限")
}
//查看评论权限,
//TODO 临时注释
// if len(articleInfo.WhoReview) > 0 {
// ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
// if ok < 0 {
// return nil, xerr.NewErrMsg("没有评论权限")
// }
// }
if len(articleInfo.WhoReview) > 0 {
ok := lo.IndexOf(articleInfo.WhoReview, req.FromUserId)
if ok < 0 {
return nil, xerr.NewErrMsg("没有评论权限")
}
}
// 对段落进行评论
var selctionInfo *domain.ArticleSection
if req.SectionId > 0 {
... ...
... ... @@ -5,6 +5,8 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
... ... @@ -24,7 +26,166 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont
}
func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) {
// todo: add your logic here and delete this line
// 先获取最顶层的评论
var conn = l.svcCtx.DefaultDBConn()
if req.Page > 40 {
req.Page = 40
}
queryOption := domain.NewQueryOptions().
WithOffsetLimit(req.Page, req.Size).
MustWithKV("topId", 0).
MustWithKV("articleId", req.ArticleId).
MustWithKV("sectionId", req.SectionId).
MustWithKV("show", domain.CommentShowEnable).
MustWithKV("companyId", req.CompanyId)
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
if cnt == 0 {
resp = &types.MiniListArticleCommentResponse{
Total: 0,
List: make([]types.ArticleCommentAndReply, 0),
}
return
}
queryOption = domain.NewQueryOptions().WithFindOnly().
MustWithKV("articleId", req.ArticleId).
MustWithKV("userId", req.UserId)
// 获取我点赞的评论
_, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
}
// 我点赞的
flagMap := map[int64]struct{}{}
for _, val := range userFlagList {
flagMap[val.CommentId] = struct{}{}
}
resp = &types.MiniListArticleCommentResponse{
Total: cnt,
List: make([]types.ArticleCommentAndReply, len(commentList)),
}
// 获取回复的评论
for i, val := range commentList {
item := types.ArticleCommentAndReply{
Comment: 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,
},
Reply: []types.ArticleCommentItem{},
TotalReply: int64(val.CountReply),
}
if _, ok := flagMap[val.Id]; ok {
item.Comment.MeLoveFlag = 1
}
for _, val2 := range val.AtWho {
item.Comment.AtWho = append(item.Comment.AtWho, types.CommentAtWho{
Id: val2.Id,
Name: val2.Name,
})
}
//获取回复的评论
cntReply, reply := l.listCommentReply(item.Comment.Id, flagMap)
resp.List[i] = item
resp.List[i].Reply = reply
resp.List[i].TotalReply = cntReply
}
return resp, nil
}
// listCommentReply
func (l *MiniListArticleCommentLogic) listCommentReply(commentId int64, loveFlagMap map[int64]struct{}) (cnt int64, replyList []types.ArticleCommentItem) {
var conn = l.svcCtx.DefaultDBConn()
queryOption := domain.NewQueryOptions().
WithOffsetLimit(1, 2).
MustWithKV("topId", commentId).
MustWithKV("show", domain.CommentShowEnable)
cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption)
if err != nil {
return cnt, []types.ArticleCommentItem{}
}
if cnt == 0 {
replyList = []types.ArticleCommentItem{}
return cnt, replyList
}
for _, 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,
}
if _, ok := loveFlagMap[val.Id]; ok {
item.MeLoveFlag = 1
}
for _, val2 := range val.AtWho {
item.AtWho = append(item.AtWho, types.CommentAtWho{
Id: val2.Id,
Name: val2.Name,
})
}
replyList = append(replyList, item)
}
return cnt, replyList
}
... ...
... ... @@ -33,9 +33,10 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
users []*domain.User
departments []*domain.Department
groups = make([]DepartmentUser, 0)
)
resp = map[string]interface{}{
"list": make([]DepartmentUser, 0),
"list": groups,
}
_, departments, err = l.svcCtx.DepartmentRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().WithFindOnly())
if err != nil {
... ... @@ -60,11 +61,15 @@ func (l *MiniUserDepartmentUsersLogic) MiniUserDepartmentUsers(req *types.MiniUs
group.Users = append(group.Users, &domain.User{
Id: user.Id,
Name: user.Name,
PinYinName: user.PinYinName,
})
}
}
groups = append(groups, group)
})
resp = map[string]interface{}{
"list": groups,
}
return
}
... ...
... ... @@ -2,6 +2,7 @@ package user
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
... ... @@ -33,6 +34,9 @@ func (l *SystemUserAccountEnableLogic) SystemUserAccountEnable(req *types.System
users []*domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
if !lo.Contains([]int{domain.UserEnable, domain.UserDisable}, req.Status) {
return nil, xerr.NewErrMsg("启用状态有误")
}
if _, users, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.IndexCompanyId(userToken.CompanyId)().MustWithKV("ids", req.UserIds).WithFindOnly()); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
}
... ... @@ -50,5 +54,6 @@ func (l *SystemUserAccountEnableLogic) SystemUserAccountEnable(req *types.System
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新启用状态失败", err)
}
resp = &types.SystemUserAccountEnableResponse{}
return
}
... ...
... ... @@ -50,10 +50,12 @@ type MiniCreateArticleCommentResponse struct {
}
type MiniListArticleCommentRequest struct {
Page int64 `json:"page"`
Size int64 `json:"size"`
Page int `json:"page"`
Size int `json:"size"`
CompanyId int64 `json:",optional"`
SectionId int64 `json:"sectionId"`
UserId int64 `json:",optional"`
ArticleId int64 `json:"articleId"`
SectionId int64 `json:"sectionId,optional"`
}
type MiniListArticleCommentResponse struct {
... ...
... ... @@ -125,11 +125,23 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
if v, ok := queryOptions["topId"]; ok {
tx = tx.Where("top_id", v)
tx = tx.Where("top_id=?", v)
}
if v, ok := queryOptions["show"]; ok {
tx = tx.Where("show", v)
tx = tx.Where("show=?", v)
}
if v, ok := queryOptions["articleId"]; ok {
tx = tx.Where("article_id=?", v)
}
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 total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil {
return dms, tx.Error
}
... ...
... ... @@ -211,8 +211,8 @@ func (repository *UserRepository) FindDepartmentUsers(ctx context.Context, conn
total int64
)
queryFunc := func() (interface{}, error) {
tx = tx.Model(&ms).Order("id desc")
tx.Select("id", "name", "departments")
tx = tx.Model(&ms).Order("pin_yin_name asc")
tx.Select("id", "name", "departments", "pin_yin_name")
tx.Where("company_id = ?", companyId)
tx.Where("audit_status in (?)", domain.UserAuditStatusPassed)
tx.Where("enable = ?", domain.UserEnable)
... ...