|
@@ -8,12 +8,11 @@ import com.tencentcloudapi.tms.v20201229.TmsClient;
|
|
|
import com.tencentcloudapi.tms.v20201229.models.TextModerationRequest;
|
|
|
import com.tencentcloudapi.tms.v20201229.models.TextModerationResponse;
|
|
|
import com.tzld.longarticle.recommend.server.model.remote.ArticleSensitive;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.mapper.crawler.CrawlerBaseMapper;
|
|
|
+import com.tzld.longarticle.recommend.server.util.Md5Util;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.tomcat.util.security.MD5Encoder;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
-import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Base64;
|
|
@@ -24,7 +23,7 @@ import java.util.Objects;
|
|
|
public class ArticleSensitiveRemoteService {
|
|
|
|
|
|
@Autowired
|
|
|
- JdbcTemplate piaoquanCrawlerJdbcTemplate;
|
|
|
+ CrawlerBaseMapper crawlerBaseMapper;
|
|
|
|
|
|
@Value("${tecent.cloud.secret.id:AKIDbLGZox42mZaloeIo16zeJrDRUelkbFfw}")
|
|
|
private String tecentCloudSecretId;
|
|
@@ -34,10 +33,15 @@ public class ArticleSensitiveRemoteService {
|
|
|
public Boolean articleSensitive(String title) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
boolean isSensitive = false;
|
|
|
- String md5 = MD5Encoder.encode(title.getBytes());
|
|
|
+ String md5 = Md5Util.encoderByMd5(title);
|
|
|
ArticleSensitive articleSensitive = getArticleSensitive(md5);
|
|
|
if (Objects.nonNull(articleSensitive)) {
|
|
|
- return articleSensitive.getSensitive();
|
|
|
+ if ("Pass".equals(articleSensitive.getSensitive())
|
|
|
+ || ("Polity".equals(articleSensitive.getLabel()) && "ForeignLeader".equals(articleSensitive.getSubLabel()))) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
String content = Base64.getEncoder().encodeToString(title.getBytes());
|
|
|
try {
|
|
@@ -61,31 +65,24 @@ public class ArticleSensitiveRemoteService {
|
|
|
log.info("articleSensitive title:{} response:{}", title, JSONObject.toJSONString(resp));
|
|
|
if ("Pass".equals(resp.getSuggestion())
|
|
|
|| ("Polity".equals(resp.getLabel()) && "ForeignLeader".equals(resp.getSubLabel()))) {
|
|
|
- return isSensitive;
|
|
|
} else {
|
|
|
isSensitive = true;
|
|
|
}
|
|
|
+ insertArticleSensitive(md5, title, resp.getSuggestion(), resp.getLabel(), resp.getSubLabel(), JSONObject.toJSONString(resp));
|
|
|
} catch (Exception e) {
|
|
|
log.error("articleSensitive error", e);
|
|
|
}
|
|
|
- insertArticleSensitive(md5, title, isSensitive);
|
|
|
log.info("articleSensitive耗时:{}", System.currentTimeMillis() - start);
|
|
|
return isSensitive;
|
|
|
}
|
|
|
|
|
|
- private ArticleSensitive getArticleSensitive(String md5) {
|
|
|
- MapSqlParameterSource parameters = new MapSqlParameterSource();
|
|
|
- parameters.addValue("md5", md5);
|
|
|
- ArticleSensitive result = piaoquanCrawlerJdbcTemplate.queryForObject(
|
|
|
- "select md5, title, sensitiv from articles_sensitive where md5 = ?", ArticleSensitive.class, md5);
|
|
|
- return result;
|
|
|
+ public ArticleSensitive getArticleSensitive(String md5) {
|
|
|
+ return crawlerBaseMapper.getArticleSensitiveByKey(md5);
|
|
|
}
|
|
|
|
|
|
- private void insertArticleSensitive(String md5, String title, boolean sensitive) {
|
|
|
+ public void insertArticleSensitive(String md5, String title, String sensitive, String label, String subLabel, String response) {
|
|
|
// 插入
|
|
|
- piaoquanCrawlerJdbcTemplate.update(
|
|
|
- "insert into articles_sensitive(md5, title, sensitive) values (?,?,?)",
|
|
|
- md5, title, sensitive);
|
|
|
+ crawlerBaseMapper.insertArticleSensitive(md5, title, sensitive, label, subLabel, response);
|
|
|
}
|
|
|
|
|
|
|