|
@@ -71,14 +71,14 @@ public class GetWeChatArticleService {
|
|
|
private FileManagerService fileManagerService;
|
|
|
|
|
|
@Scheduled(cron = "0 0 3 * * ?")
|
|
|
- @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public void getWeChatArticle() throws Exception {
|
|
|
System.out.println(new Date() + "Wechat-Begin");
|
|
|
List<SourceInfo> sourceInfos = sourceInfoMapper.selectList(new LambdaQueryWrapper<SourceInfo>()
|
|
|
.eq(SourceInfo::getSourceType, 2));
|
|
|
for (SourceInfo sourceInfo : sourceInfos) {
|
|
|
final String fakeId = sourceInfo.getFakeId();
|
|
|
- WxResultBody<List<Article>> findExList = WeiXinApi.findExList(fakeId, token,cookie);
|
|
|
+ WxResultBody<List<Article>> findExList = WeiXinApi.findExList(fakeId, token, cookie);
|
|
|
List<Article> exList = findExList.getApp_msg_list();
|
|
|
|
|
|
List<GetArticleInfoDTO> articleInfoDTOS = new ArrayList<>();
|
|
@@ -120,10 +120,8 @@ public class GetWeChatArticleService {
|
|
|
continue;
|
|
|
}
|
|
|
String condensedAbstract = null;
|
|
|
-// String pctCondensedAbstract = null;
|
|
|
try {
|
|
|
condensedAbstract = difyService.getCondensedAbstract(weChatArticleContent);
|
|
|
-// pctCondensedAbstract = difyService.getPctCondensedAbstract(weChatArticleContent);
|
|
|
} catch (Exception e) {
|
|
|
continue;
|
|
|
}
|
|
@@ -134,16 +132,10 @@ public class GetWeChatArticleService {
|
|
|
GetArticleInfoDTO articleInfoDTO = new GetArticleInfoDTO();
|
|
|
switch (sourceInfo.getSourceName()) {
|
|
|
case "国专知识产权":
|
|
|
- articleInfoDTO.setCategoryId(4);
|
|
|
- break;
|
|
|
- case "IPRdaily":
|
|
|
- articleInfoDTO.setCategoryId(3);
|
|
|
- break;
|
|
|
case "知识产权界":
|
|
|
- articleInfoDTO.setCategoryId(5);
|
|
|
- break;
|
|
|
+ case "IPRdaily":
|
|
|
case "Bayes美国知识产权":
|
|
|
- articleInfoDTO.setCategoryId(4);
|
|
|
+ articleInfoDTO.setCategoryId(this.wxArticleClassify(title));
|
|
|
break;
|
|
|
default:
|
|
|
articleInfoDTO.setCategoryId(6);
|
|
@@ -158,7 +150,6 @@ public class GetWeChatArticleService {
|
|
|
articleInfoDTO.setWxArticleIcon(guid);
|
|
|
}
|
|
|
articleInfoDTO.setDigest(condensedAbstract);
|
|
|
-// articleInfoDTO.setPctDigest(pctCondensedAbstract);
|
|
|
articleInfoDTOS.add(articleInfoDTO);
|
|
|
}
|
|
|
articleInfoService.batchAddArticleInfo(articleInfoDTOS);
|
|
@@ -166,6 +157,25 @@ public class GetWeChatArticleService {
|
|
|
System.out.println(new Date() + "Wechat-End");
|
|
|
}
|
|
|
|
|
|
+ public Integer wxArticleClassify(String content) {
|
|
|
+ int classify = 6;
|
|
|
+ try {
|
|
|
+ String classifyStr = difyService.getArticleClassify(content);
|
|
|
+ if (StringUtils.isNotEmpty(classifyStr)) {
|
|
|
+ if (classifyStr.contains("判例")) {
|
|
|
+ classify = 3;
|
|
|
+ } else if (classifyStr.contains("国外")) {
|
|
|
+ classify = 4;
|
|
|
+ } else if (classifyStr.contains("行业")) {
|
|
|
+ classify = 5;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ return classify;
|
|
|
+ }
|
|
|
+ return classify;
|
|
|
+ }
|
|
|
+
|
|
|
public String getWeChatArticleContent(String articleUrl) {
|
|
|
String content = "";
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
@@ -212,7 +222,35 @@ public class GetWeChatArticleService {
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
- public void getWeChatArticleContent1(String articleUrl,Integer categoryId,Integer sourceId) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ //测试使用方法1
|
|
|
+ public void getWeChatArticleContent1(String articleUrl, Integer categoryId, Integer sourceId) {
|
|
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
HttpGet request = new HttpGet(articleUrl);
|
|
|
// 设置完整的请求头(关键步骤!)
|
|
@@ -277,11 +315,9 @@ public class GetWeChatArticleService {
|
|
|
}
|
|
|
}
|
|
|
String condensedAbstract = difyService.getCondensedAbstract(content);
|
|
|
-// String pctCondensedAbstract = difyService.getPctCondensedAbstract(content);
|
|
|
ArticleInfo articleInfo = new ArticleInfo();
|
|
|
articleInfo.setTitle(title);
|
|
|
articleInfo.setDigest(condensedAbstract);
|
|
|
-// articleInfo.setPctDigest(pctCondensedAbstract);
|
|
|
articleInfo.setCategoryId(categoryId);
|
|
|
articleInfo.setSourceId(sourceId);
|
|
|
articleInfo.setPublicTime(createTime);
|
|
@@ -293,7 +329,7 @@ public class GetWeChatArticleService {
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ ////测试使用方法2
|
|
|
private static String extractVariable(String scriptContent, String varName) {
|
|
|
// 正则表达式匹配变量赋值(支持字符串或数字)
|
|
|
Pattern pattern = Pattern.compile(
|
|
@@ -306,31 +342,4 @@ 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;
|
|
|
- }
|
|
|
}
|