get_sensitive_words_logic.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package logic
  2. import (
  3. "context"
  4. "strings"
  5. "call_center/db/rpc/internal/svc"
  6. "call_center/db/rpc/pb"
  7. "github.com/tal-tech/go-zero/core/logx"
  8. )
  9. type GetSensitiveWordsLogic struct {
  10. ctx context.Context
  11. svcCtx *svc.ServiceContext
  12. logx.Logger
  13. }
  14. func NewGetSensitiveWordsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSensitiveWordsLogic {
  15. return &GetSensitiveWordsLogic{
  16. ctx: ctx,
  17. svcCtx: svcCtx,
  18. Logger: logx.WithContext(ctx),
  19. }
  20. }
  21. func (l *GetSensitiveWordsLogic) GetSensitiveWords(in *pb.SensReq) (*pb.SensRes, error) {
  22. // todo: add your logic here and delete this line
  23. res := new(pb.SensRes)
  24. // 读取db
  25. wordsModel, err := l.svcCtx.SensWordModel.FindAll()
  26. if err != nil {
  27. return res, err
  28. }
  29. filterModel, err := l.svcCtx.ConfigModel.FindOneByConfKey("sensitive_words_filter")
  30. if err != nil {
  31. return res, err
  32. }
  33. // 结果赋值
  34. for _, v := range *wordsModel {
  35. res.SensWords = append(res.SensWords, v.Word)
  36. }
  37. wordsFilter := strings.Split(filterModel.ConfValue, ",")
  38. res.FilterWord = wordsFilter
  39. logx.Infof("[GetSensitiveWords] sensWordLen:%s, filterWordsLen:%s", len(res.SensWords), len(res.FilterWord))
  40. return res, nil
  41. }