mini_system_logic.go 5.9 KB
package message

import (
	"context"
	"fmt"
	"github.com/zeromicro/go-zero/core/logx"
	"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/db/transaction"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
)

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

func (l *MiniSystemLogic) MiniSystem(req *types.MessageRequest) (resp *types.MessageSystemResponse, err error) {
	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).
		WithKV("companyId", userToken.CompanyId).
		WithKV("recipientId", userToken.UserId))
	if err != nil {
		return nil, err
	}
	resp = &types.MessageSystemResponse{
		Total: total,
		List:  make([]types.MessageSystemItem, 0),
	}
	for _, item := range list {
		to := types.MessageSystemItem{
			Id:        item.Id,
			Type:      int(item.Type),
			Title:     item.Title,
			Content:   item.Content,
			CreatedAt: item.CreatedAt,
		}
		resp.List = append(resp.List, to)
	}
	return resp, nil
}

// 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))
}

// ArticleDeleted 帖子删除
func (l *MiniSystemLogic) ArticleDeleted(conn transaction.Conn, companyId, at int64, createdTime, title string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeDeleted, "帖子已删除", fmt.Sprintf("你于%v发布的帖子[%v]已被删除,如有疑问,请联系运营管理员了解详情。", createdTime, title))
}

// ArticleIllegal 帖子违规
func (l *MiniSystemLogic) ArticleIllegal(conn transaction.Conn, companyId, at int64, createdTime, title string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeDeleted, "文本内容违规", fmt.Sprintf("你于%v发布的帖子[%v]含有违规信息,未通过审核,已被禁止发布。请自觉遵守相关规定,若有疑问,请咨询运营管理员了解详情。", createdTime, title))
}

//// 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 异常通知-文章未审核通过
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))
}

// AbnormalArticleHidden 异常通知-文章被隐藏
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))
}

//// 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 异常通知-评论未审核通过
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))
}

// AbnormalCommentHidden 异常通知-评论被隐藏
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))
}

// CommentIllegal 评论违规
func (l *MiniSystemLogic) CommentIllegal(conn transaction.Conn, at int64, companyId int64, createdTime, title string) (err error) {
	return l.createMessage(conn, companyId, at, domain.MsgTypeIllegal, "文本内容违规", fmt.Sprintf("你于%v发布的评论[%v]含有违规信息,未通过审核,已被禁止发布。请自觉遵守相关规定,若有疑问,请咨询运营管理员了解详情。", createdTime, title))
}

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
}