Browse Source

文本审核

wangqifan 3 years ago
parent
commit
26e16ffc6b

+ 9 - 3
src/main/java/com/izouma/nineth/service/netease/NeteaseMessageService.java

@@ -8,6 +8,7 @@ import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.netease.NeteaseMessageRepo;
 import com.izouma.nineth.repo.UserRepo;
+import com.izouma.nineth.service.ContentAuditService;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Page;
@@ -20,9 +21,10 @@ import java.util.Map;
 @AllArgsConstructor
 public class NeteaseMessageService {
 
-    private NeteaseMessageRepo neteaseMessageRepo;
-    private NeteaseUserService neteaseUserService;
-    private UserRepo           userRepo;
+    private NeteaseMessageRepo  neteaseMessageRepo;
+    private NeteaseUserService  neteaseUserService;
+    private UserRepo            userRepo;
+    private ContentAuditService contentAuditService;
 
     public Page<NeteaseMessage> all(PageQuery pageQuery) {
         return neteaseMessageRepo
@@ -30,6 +32,10 @@ public class NeteaseMessageService {
     }
 
     public NeteaseMessage sendMessage(NeteaseMessage msg) {
+        boolean result1 = contentAuditService.auditText(msg.getBody());
+        if (!result1) {
+            throw new BusinessException("包含敏感词!");
+        }
         User from = userRepo.findById(Long.valueOf(msg.getFromId())).orElseThrow(new BusinessException("未找到用户"));
 //        User to = userRepo.findById(Long.valueOf(msg.getToId())).orElseThrow(new BusinessException("未找到用户"));
         msg.setFromAvatar(from.getAvatar());