zero hai 1 mes
pai
achega
aa9479fce6

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

@@ -121,10 +121,10 @@ public class GetCNIPAArticleService {
                     continue;
                 }
                 String condensedAbstract = null;
-                String pctCondensedAbstract = null;
+//                String pctCondensedAbstract = null;
                 try {
                     condensedAbstract = difyService.getCondensedAbstract(digest);
-                    pctCondensedAbstract = difyService.getPctCondensedAbstract(digest);
+//                    pctCondensedAbstract = difyService.getPctCondensedAbstract(digest);
                 } catch (Exception e) {
 
                 }
@@ -138,7 +138,7 @@ public class GetCNIPAArticleService {
                 articleInfoDTO.setTitle(title);
                 articleInfoDTO.setPublicTime(date);
                 articleInfoDTO.setDigest(condensedAbstract);
-                articleInfoDTO.setPctDigest(pctCondensedAbstract);
+//                articleInfoDTO.setPctDigest(pctCondensedAbstract);
                 articleInfoDTOS.add(articleInfoDTO);
             }
             articleInfoService.batchAddArticleInfo(articleInfoDTOS);

+ 50 - 6
src/main/java/com/cslg/ppa/service/GetWebArticle/GetWeChatArticleService.java

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

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2 - 2
src/main/resources/application-dev.yml


+ 49 - 6
src/test/java/com/cslg/ppa/PpaApplicationTests.java

@@ -3,6 +3,7 @@ package com.cslg.ppa;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.cslg.ppa.common.okhttp.MyCookieStore;
 import com.cslg.ppa.common.utils.DateUtil;
@@ -23,9 +24,11 @@ import com.cslg.ppa.service.CategoryService;
 import com.cslg.ppa.service.GetWebArticle.*;
 import com.cslg.ppa.service.ReportService;
 import com.cslg.ppa.service.commom.DifyService;
+import com.cslg.ppa.service.commom.FileManagerService;
 import com.cslg.ppa.service.commom.WeiXinApi;
 import okhttp3.Cookie;
 import okhttp3.HttpUrl;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.hc.client5.http.classic.methods.HttpGet;
 import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
@@ -40,13 +43,18 @@ import org.jsoup.select.Elements;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+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.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
@@ -77,6 +85,8 @@ class PpaApplicationTests {
     private GetProvinceNewsService getProvinceNewsService;
     @Autowired
     private GetEcigaretteService getEcigaretteService;
+    @Autowired
+    private FileManagerService fileManagerService;
 
     @Test
     void contextLoads() {
@@ -94,11 +104,11 @@ class PpaApplicationTests {
 //        String url = "https://www.cnipa.gov.cn/art/2025/8/22/art_75_201148.html";
 //        getCNIPAArticleService.getDigest(url);
 
-        getCNIPAArticleService.getCNIPA();
+//        getCNIPAArticleService.getCNIPA();
 
 //        getLocalInformationService.getLocalInformation();
 
-//        getWeChatArticleService.getWeChatArticle();
+        getWeChatArticleService.getWeChatArticle();
 
 //        final String digest = getCNIPAArticleService.getDigest("");
 //        final Date yesterdayDate = DateUtil.getYesterdayDate();
@@ -268,4 +278,37 @@ class PpaApplicationTests {
         String url = "https://www.2firsts.cn/";
         getEcigaretteService.crawlEcigaretteArticles(url);
     }
+
+    @Test
+    void getGuid() throws Exception {
+        String url = "https://mmbiz.qlogo.cn/mmbiz_jpg/N7S9NTpmPL8yibib3EwG7zxia25Ij9zS0A2XTlWWxpUomE7S9aDxNe8ibJYX7n8KjF8xf90n9UUSwaC2nTLh2D8a7Q/0?wx_fmt=jpeg";
+        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);
+        }
+        final List<String> list = fileManagerService.uploadFileGetGuid2(Collections.singletonList(tempFile));
+        System.out.println(list.get(0));
+        Files.delete(tempFile.toPath());
+    }
+
+    @Test
+    void test11() throws Exception {
+        List<ArticleInfo> list = articleInfoService.list(new LambdaQueryWrapper<ArticleInfo>()
+                .in(ArticleInfo::getCategoryId,Arrays.asList(3,4,5,6))
+                .isNotNull(ArticleInfo::getWxArticleIcon));
+        System.out.println(list.size());
+        if (!CollectionUtils.isEmpty(list)) {
+            for (ArticleInfo articleInfo : list) {
+                if (StringUtils.isNotEmpty(articleInfo.getWxArticleIcon())) {
+                    String guid = getWeChatArticleService.getGuid(articleInfo.getWxArticleIcon());
+                    articleInfo.setWxArticleIcon(guid);
+                    articleInfo.setId(articleInfo.getId());
+                    articleInfo.updateById();
+                }
+            }
+        }
+        System.out.println("----------------");
+    }
 }