|
@@ -11,9 +11,11 @@ import com.cslg.ppa.entity.commom.WxResultBody;
|
|
|
import com.cslg.ppa.mapper.SourceInfoMapper;
|
|
|
import com.cslg.ppa.service.ArticleInfoService;
|
|
|
import com.cslg.ppa.service.commom.DifyService;
|
|
|
+import com.cslg.ppa.service.commom.FileManagerService;
|
|
|
import com.cslg.ppa.service.commom.WeiXinApi;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.io.IOUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
|
@@ -33,8 +35,17 @@ import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.regex.Matcher;
|
|
@@ -56,6 +67,8 @@ public class GetWeChatArticleService {
|
|
|
private ArticleInfoService articleInfoService;
|
|
|
@Autowired
|
|
|
private DifyService difyService;
|
|
|
+ @Autowired
|
|
|
+ private FileManagerService fileManagerService;
|
|
|
|
|
|
@Scheduled(cron = "0 0 4 * * ?")
|
|
|
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
|
|
@@ -88,6 +101,7 @@ public class GetWeChatArticleService {
|
|
|
String link = article.getLink();
|
|
|
String cover = article.getCover();
|
|
|
|
|
|
+
|
|
|
// 检查文章是否已存在
|
|
|
ArticleInfo articleInfo = articleInfoService.getOne(new QueryWrapper<ArticleInfo>().lambda().eq(ArticleInfo::getTitle, title));
|
|
|
if (ObjectUtils.isNotEmpty(articleInfo)) {
|
|
@@ -105,10 +119,10 @@ public class GetWeChatArticleService {
|
|
|
continue;
|
|
|
}
|
|
|
String condensedAbstract = null;
|
|
|
- String pctCondensedAbstract = null;
|
|
|
+// String pctCondensedAbstract = null;
|
|
|
try {
|
|
|
condensedAbstract = difyService.getCondensedAbstract(weChatArticleContent);
|
|
|
- pctCondensedAbstract = difyService.getPctCondensedAbstract(weChatArticleContent);
|
|
|
+// pctCondensedAbstract = difyService.getPctCondensedAbstract(weChatArticleContent);
|
|
|
} catch (Exception e) {
|
|
|
continue;
|
|
|
}
|
|
@@ -132,9 +146,12 @@ public class GetWeChatArticleService {
|
|
|
articleInfoDTO.setArticleUrl(link);
|
|
|
articleInfoDTO.setTitle(title);
|
|
|
articleInfoDTO.setPublicTime(createTime);
|
|
|
- articleInfoDTO.setWxArticleIcon(cover);
|
|
|
+ if (StringUtils.isNotEmpty(cover)) {
|
|
|
+ String guid = this.getGuid(cover);
|
|
|
+ articleInfoDTO.setWxArticleIcon(guid);
|
|
|
+ }
|
|
|
articleInfoDTO.setDigest(condensedAbstract);
|
|
|
- articleInfoDTO.setPctDigest(pctCondensedAbstract);
|
|
|
+// articleInfoDTO.setPctDigest(pctCondensedAbstract);
|
|
|
articleInfoDTOS.add(articleInfoDTO);
|
|
|
}
|
|
|
articleInfoService.batchAddArticleInfo(articleInfoDTOS);
|
|
@@ -253,11 +270,11 @@ public class GetWeChatArticleService {
|
|
|
}
|
|
|
}
|
|
|
String condensedAbstract = difyService.getCondensedAbstract(content);
|
|
|
- String pctCondensedAbstract = difyService.getPctCondensedAbstract(content);
|
|
|
+// String pctCondensedAbstract = difyService.getPctCondensedAbstract(content);
|
|
|
ArticleInfo articleInfo = new ArticleInfo();
|
|
|
articleInfo.setTitle(title);
|
|
|
articleInfo.setDigest(condensedAbstract);
|
|
|
- articleInfo.setPctDigest(pctCondensedAbstract);
|
|
|
+// articleInfo.setPctDigest(pctCondensedAbstract);
|
|
|
articleInfo.setCategoryId(categoryId);
|
|
|
articleInfo.setSourceId(sourceId);
|
|
|
articleInfo.setPublicTime(createTime);
|
|
@@ -282,4 +299,31 @@ public class GetWeChatArticleService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+
|
|
|
+ public String getGuid(String url) throws Exception {
|
|
|
+ String guid = "";
|
|
|
+ try {
|
|
|
+ URL fileUrl = new URL(url);
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
|
|
|
+ File tempFile = File.createTempFile("tem-", ".jpeg");
|
|
|
+ try (InputStream in = connection.getInputStream(); FileOutputStream out = new FileOutputStream(tempFile)) {
|
|
|
+ IOUtils.copy(in, out);
|
|
|
+ }
|
|
|
+ List<String> list = null;
|
|
|
+ try {
|
|
|
+ list = fileManagerService.uploadFileGetGuid2(Collections.singletonList(tempFile));
|
|
|
+ } catch (IOException e) {
|
|
|
+ list = new ArrayList<>();
|
|
|
+ }
|
|
|
+ Files.delete(tempFile.toPath());
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ guid = list.get(0);
|
|
|
+ } else {
|
|
|
+ guid = url;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return url;
|
|
|
+ }
|
|
|
+ return guid;
|
|
|
+ }
|
|
|
}
|