zero 1 هفته پیش
والد
کامیت
ae5fe29143

+ 2 - 3
src/main/java/com/cslg/ppa/service/GetWebArticle/GetIprDailyArticleService.java

@@ -54,7 +54,7 @@ public class GetIprDailyArticleService {
      * IprDaily中文网
      * @throws Exception
      */
-//    @Scheduled(cron = "0 15 0 * * ?")
+    @Scheduled(cron = "0 15 0 * * ?")
     @Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
     public void crawIprDailyArticle() throws Exception {
         System.out.println(new Date() + "IprDaily-Begin");
@@ -66,7 +66,7 @@ public class GetIprDailyArticleService {
         //行业----国际视野
         urlMap.put("http://www.iprdaily.cn/index.php?s=api&c=api&m=template&name=get_news.html&catid=15", 5);
         //行业----行业
-        urlMap.put("http://www.iprdaily.cn/index.php?s=api&c=api&m=template&name=get_news.html&catid=8", 5);
+//        urlMap.put("http://www.iprdaily.cn/index.php?s=api&c=api&m=template&name=get_news.html&catid=8", 5);
         for (String key : urlMap.keySet()) {
             Integer type = urlMap.get(key);
             try {
@@ -82,7 +82,6 @@ public class GetIprDailyArticleService {
                 String res = Objects.requireNonNull(okHttpClient.newCall(request).execute().body()).string();
                 JSONObject parseObject = JSONObject.parseObject(res);
                 String htmlContent = parseObject.getString("msg");
-//            final Integer code = parseObject.getInteger("code");
                 this.addIprDailyArticle(htmlContent, BaseUrl,BaseId,type);
             } catch (IOException e) {
                 System.out.println("Get IPRDaily Web Article Error:" + e);

+ 53 - 44
src/main/java/com/cslg/ppa/service/GetWebArticle/GetWeChatArticleService.java

@@ -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;
-    }
 }

+ 4 - 4
src/main/java/com/cslg/ppa/service/commom/DifyService.java

@@ -23,8 +23,8 @@ public class DifyService {
     private String url;
     @Value("${DIFY.getAbstractKey}")
     private String getAbstractKey;
-    @Value("${DIFY.getPctAbstractKey}")
-    private String getPctAbstractKey;
+    @Value("${DIFY.articleClassifyKey}")
+    private String articleClassifyKey;
 
     public String getCondensedAbstract(String text) throws Exception {
         Map<String, Object> map = new HashMap<>();
@@ -56,7 +56,7 @@ public class DifyService {
         return DataUtils.unicodeDecode(content);
     }
 
-    public String getPctCondensedAbstract(String text) throws Exception {
+    public String getArticleClassify(String text) throws Exception {
         Map<String, Object> map = new HashMap<>();
         map.put("content", text);
         OAMessageDTO oaMessageDTO = new OAMessageDTO();
@@ -73,7 +73,7 @@ public class DifyService {
                 .build();
         Request request = new Request.Builder()
                 .url(url + "workflows/run")
-                .addHeader("Authorization", "Bearer " + getPctAbstractKey)
+                .addHeader("Authorization", "Bearer " + articleClassifyKey)
                 .post(requestBody)
                 .build();
         String res = Objects.requireNonNull(client.newCall(request).execute().body()).string();

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 3 - 3
src/main/resources/application-dev.yml


+ 3 - 2
src/test/java/com/cslg/ppa/PpaApplicationTests.java

@@ -147,7 +147,7 @@ class PpaApplicationTests {
     void getCondensedAbstract() throws Exception {
 //        difyService.getCondensedAbstract("近日,最高人民法院知识产权法庭审结一起侵害发明专利权纠纷,驳回专利权人。" +
 //                "专利权人无正当理由隐瞒不报,构成“故意作虚假陈述妨碍人民法院审理”的,人民法院可以依法处罚。");
-        final String s = difyService.getPctCondensedAbstract("新加坡知识产权局自2025年9月1日起上调发明专利年费。");
+        final String s = difyService.getArticleClassify("新加坡知识产权局自2025年9月1日起上调发明专利年费。");
         System.out.println(s);
     }
 
@@ -228,7 +228,8 @@ class PpaApplicationTests {
     @Test
     void singleTestAdd() throws IOException {
         List<String> list = new ArrayList<>();
-        list.add("https://mp.weixin.qq.com/s?__biz=Mzg5MjA1MTkyNA==&mid=2247485509&idx=1&sn=8d9551806c9a6d2dd1cb8f0a5351144e&chksm=cfc540fef8b2c9e857a9142d5c433922a33c0f82cb25600582fcac91a00dd5fbc21b2eac9e24#rd");
+        list.add("https://mp.weixin.qq.com/s/2g2CmjYI-9NhPRlKfPvRzw");
+//        list.add("https://mp.weixin.qq.com/s?__biz=Mzg5MjA1MTkyNA==&mid=2247485509&idx=1&sn=8d9551806c9a6d2dd1cb8f0a5351144e&chksm=cfc540fef8b2c9e857a9142d5c433922a33c0f82cb25600582fcac91a00dd5fbc21b2eac9e24#rd");
 //        list.add("https://mp.weixin.qq.com/s/LCnC8UICiG7wxdvMqfE5qQ");
 //        list.add("https://www.cnipa.gov.cn/art/2025/8/21/art_74_201139.html");
         for (String url : list) {