审查视图

cmd/discuss/api/internal/logic/message/mini_system_logic.go 4.6 KB
郑周 authored
1 2 3 4
package message

import (
	"context"
5
	"fmt"
郑周 authored
6
	"github.com/zeromicro/go-zero/core/logx"
郑周 authored
7 8
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
9
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
郑周 authored
10
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
11
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
郑周 authored
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
)

type MiniSystemLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMiniSystemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniSystemLogic {
	return &MiniSystemLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}
28
func (l *MiniSystemLogic) MiniSystem(req *types.MessageRequest) (resp *types.MessageSystemResponse, err error) {
29 30 31 32
	var userToken = contextdata.GetUserTokenFromCtx(l.ctx)

	total, list, err := l.svcCtx.MessageSystemRepository.Find(l.ctx, l.svcCtx.DefaultDBConn(), domain.NewQueryOptions().
		WithOffsetLimit(req.Page, req.Size).
郑周 authored
33
		WithKV("companyId", userToken.CompanyId).
34
		WithKV("recipientId", userToken.UserId))
郑周 authored
35 36 37
	if err != nil {
		return nil, err
	}
郑周 authored
38 39 40 41
	resp = &types.MessageSystemResponse{
		Total: total,
		List:  make([]types.MessageSystemItem, 0),
	}
郑周 authored
42 43 44
	for _, item := range list {
		to := types.MessageSystemItem{
			Id:        item.Id,
45
			Type:      int(item.Type),
郑周 authored
46 47 48 49 50 51 52 53
			Title:     item.Title,
			Content:   item.Content,
			CreatedAt: item.CreatedAt,
		}
		resp.List = append(resp.List, to)
	}
	return resp, nil
}
郑周 authored
54
55 56 57 58 59
// ArticleDefined 文章已定性
func (l *MiniSystemLogic) ArticleDefined(conn transaction.Conn, companyId, at int64, item string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeNormal, "帖子已定性", fmt.Sprintf("您的帖子[%s]已被定性,如有疑问,请联系运营管理员了解详情。", item))
}
60 61 62 63 64 65
//// ArticleAuth 文章权限变更
//func (l *MiniSystemLogic) ArticleAuth(conn transaction.Conn, companyId, at int64, item string) (err error) {
//	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "权限变更", fmt.Sprintf("您的帖子[%s]可见权限已添加,如有疑问,请联系运营管理员了解详情。", item))
//}

// AbnormalArticleUnapproved 异常通知-文章未审核通过
66 67
func (l *MiniSystemLogic) AbnormalArticleUnapproved(conn transaction.Conn, companyId, at int64, item string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "发帖未通过审核", fmt.Sprintf("您的帖子[%s]因违反运营规则未通过审核,如有疑问,请联系运营管理员了解详情。", item))
郑周 authored
68
}
郑周 authored
69
70
// AbnormalArticleHidden 异常通知-文章被隐藏
71 72 73 74
func (l *MiniSystemLogic) AbnormalArticleHidden(conn transaction.Conn, companyId, at int64, item string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "帖子被隐藏", fmt.Sprintf("您的帖子[%s]已被隐藏,如有疑问,请联系运营管理员了解详情。", item))
}
75 76 77 78 79 80
//// AbnormalArticleAuth 异常通知-文章权限变更
//func (l *MiniSystemLogic) AbnormalArticleAuth(conn transaction.Conn, companyId, at int64, item string) (err error) {
//	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "权限变更", fmt.Sprintf("您的帖子[%s]可见权限已被移除,如有疑问,请联系运营管理员了解详情。", item))
//}

// AbnormalCommentUnapproved 异常通知-评论未审核通过
81 82 83 84
func (l *MiniSystemLogic) AbnormalCommentUnapproved(conn transaction.Conn, companyId, at int64, item string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "评论未通过审核", fmt.Sprintf("您的评论[%s]因违反运营规则未通过审核,如有疑问,请联系运营管理员了解详情。", item))
}
85
// AbnormalCommentHidden 异常通知-评论被隐藏
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
func (l *MiniSystemLogic) AbnormalCommentHidden(conn transaction.Conn, companyId, at int64, item string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeAbnormal, "评论被隐藏", fmt.Sprintf("您的评论[%s]已被隐藏,如有疑问,请联系运营管理员了解详情。", item))
}

func (l *MiniSystemLogic) createMessage(conn transaction.Conn, companyId, at int64, msgType domain.MsgSystemType, title string, content string) (err error) {
	var msg = &domain.MessageSystem{
		Type:        msgType,
		CompanyId:   companyId,
		RecipientId: at,
		Title:       title,
		Content:     content,
	}
	msg, err = l.svcCtx.MessageSystemRepository.Insert(l.ctx, conn, msg)
	return err
}