Bladeren bron

9/20 update

xiexiang 1 jaar geleden
bovenliggende
commit
3beb727976

+ 4 - 0
pom.xml

@@ -30,6 +30,10 @@
         <sa-token.version>1.29.0</sa-token.version>
         <springdoc.version>1.6.6</springdoc.version>
         <elasticsearch.version>8.6.1</elasticsearch.version>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+        <java.version>17</java.version>
+        <skipTests>true</skipTests>
     </properties>
 
 

+ 0 - 25
src/main/java/com/example/mos/common/model/dto/FollowDTO.java

@@ -1,25 +0,0 @@
-package com.example.mos.common.model.dto;
-
-
-import lombok.Data;
-
-/**
- * @Author xiexiang
- * @Date 2024/6/3
- */
-@Data
-public class FollowDTO {
-    /**
-     * 关注类型(0微信公众号 1网页)
-     */
-    private Integer followType;
-
-    /**
-     * 公众号fakeid/网页id
-     */
-    private String followId;
-
-    private String pictureUrl;
-
-    private String name;
-}

+ 0 - 1
src/main/java/com/example/mos/container/SearchUI.java

@@ -3,7 +3,6 @@ package com.example.mos.container;
 import com.example.mos.common.model.vo.OfficalAccountReVO.AccountNameVO;
 import com.example.mos.handler.FollowAccountHandler;
 import com.example.mos.service.ArticleInfoService;
-import com.example.mos.service.FollowService;
 import com.example.mos.service.WeChatAccountInfoService;
 
 import javax.swing.*;

+ 0 - 38
src/main/java/com/example/mos/controller/FollowController.java

@@ -1,38 +0,0 @@
-package com.example.mos.controller;
-
-import com.example.mos.common.model.dto.FollowDTO;
-import com.example.mos.service.FollowService;
-import io.swagger.v3.oas.annotations.Operation;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.io.IOException;
-
-/**
- * @Author xiexiang
- * @Date 2024/6/3
- */
-
-
-@Slf4j
-@RestController
-@RequiredArgsConstructor
-@RequestMapping("/follow")
-public class FollowController {
-    private final FollowService followService;
-
-    @PostMapping("/addFollow")
-    @Operation(summary = "关注")
-    public String addFollow(@RequestBody FollowDTO followDTO) {
-        if (followDTO != null) {
-            Integer id = followService.add(followDTO);
-            return "上传成功";
-        } else {
-            return "上传失败";
-        }
-    }
-}

+ 0 - 26
src/main/java/com/example/mos/domain/Follow.java

@@ -1,26 +0,0 @@
-package com.example.mos.domain;
-
-import com.baomidou.mybatisplus.annotation.TableField;
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.example.mos.common.model.BaseEntity;
-import lombok.Data;
-
-/**
- * @Author xiexiang
- * @Date 2024/5/30
- */
-@Data
-@TableName("follow_account")
-public class Follow extends BaseEntity<Follow> {
-    /**
-     * 关注类型(0微信公众号 1网页)
-     */
-    @TableField("follow_type")
-    private Integer followType;
-
-    /**
-     * 公众号fakeid/网页id
-     */
-    @TableField("follow_id")
-    private String followId;
-}

+ 0 - 10
src/main/java/com/example/mos/handler/FollowAccountHandler.java

@@ -1,9 +1,7 @@
 package com.example.mos.handler;
 
-import com.example.mos.common.model.dto.FollowDTO;
 import com.example.mos.common.model.dto.WeChatAccountInfoDTO;
 import com.example.mos.common.model.vo.OfficalAccountReVO.AccountNameVO;
-import com.example.mos.service.FollowService;
 import com.example.mos.service.WeChatAccountInfoService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -20,7 +18,6 @@ public class FollowAccountHandler implements ActionListener {
     private String accountName;
     private String fakeId;
     private String pictureUrl;
-//    private FollowService followService;
     private WeChatAccountInfoService weChatAccountInfoService;
 
     public FollowAccountHandler(AccountNameVO accountNameVO, WeChatAccountInfoService weChatAccountInfoService) {
@@ -36,13 +33,6 @@ public class FollowAccountHandler implements ActionListener {
         JButton button = (JButton) actionEvent.getSource(); // 获取触发事件的按钮
         String buttonText = button.getText();
         if (buttonText.equals("关注")) {
-//            FollowDTO followDTO = new FollowDTO();
-//            followDTO.setFollowId(fakeId);
-//            followDTO.setFollowType(0);
-//            followDTO.setPictureUrl(pictureUrl);
-//            followDTO.setName(accountName);
-//            followService.add(followDTO);
-
             WeChatAccountInfoDTO weChatAccountInfoDTO = new WeChatAccountInfoDTO();
             weChatAccountInfoDTO.setAccountName(accountName);
             weChatAccountInfoDTO.setFakeId(fakeId);

+ 0 - 1
src/main/java/com/example/mos/handler/SearchWeChatAccountHandler.java

@@ -2,7 +2,6 @@ package com.example.mos.handler;
 
 import com.example.mos.common.model.vo.OfficalAccountReVO.AccountNameVO;
 import com.example.mos.service.ArticleInfoService;
-import com.example.mos.service.FollowService;
 import com.example.mos.service.WeChatAccountInfoService;
 
 import javax.swing.*;

+ 1 - 1
src/main/java/com/example/mos/handler/WeChatLoginHandler.java

@@ -21,6 +21,7 @@ public class WeChatLoginHandler {
     public void weChatLogin() throws IOException, ExecutionException, TimeoutException {
         //图片显示控件
         MyImageShowFrame myImageShowFrame = new MyImageShowFrame();
+        myImageShowFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         // 1. POST请求开始登录接口,初始化cookie
         String sessionid = "" + System.currentTimeMillis() + (int)(Math.random()*100); //生成一个包含当前时间戳以及随机数的字符串
         WxResultBody wxResultBody = WeiXinApi.startLogin(sessionid);
@@ -104,5 +105,4 @@ public class WeChatLoginHandler {
             System.out.println("---login success!");
         });
     }
-
 }

+ 0 - 14
src/main/java/com/example/mos/mapper/FollowMapper.java

@@ -1,14 +0,0 @@
-package com.example.mos.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.example.mos.domain.Follow;
-import org.apache.ibatis.annotations.Mapper;
-import org.springframework.stereotype.Repository;
-
-/**
- * @Author xiexiang
- * @Date 2024/6/3
- */
-@Repository
-public interface FollowMapper extends BaseMapper<Follow> {
-}

+ 46 - 27
src/main/java/com/example/mos/service/ArticleInfoService.java

@@ -31,16 +31,23 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
 
     public List<Integer> addArticles(List<ArticleInfoDTO> articleInfoDTOS) {
         List<Integer> ids = new ArrayList<>();
+
         if (articleInfoDTOS != null && !articleInfoDTOS.isEmpty()) {
-            List<ArticleInfo> articleInfos = new ArrayList<>();
-            for (ArticleInfoDTO articleInfoDTO : articleInfoDTOS) {
-                String title = articleInfoDTO.getTitle();
-                if (!isArticleExists(title)) {
-                    ArticleInfo articleInfo = new ArticleInfo();
-                    BeanUtils.copyProperties(articleInfoDTO, articleInfo);
-                    articleInfos.add(articleInfo);
-                }
-            }
+            List<String> titles = articleInfoDTOS.stream()
+                    .map(ArticleInfoDTO::getTitle)
+                    .collect(Collectors.toList());
+
+            List<ArticleInfo> existingArticles = getExistingArticles(titles);
+
+            List<ArticleInfo> articleInfos = articleInfoDTOS.stream()
+                    .filter(dto -> !isArticleExists(existingArticles, dto.getTitle()))
+                    .map(articleInfoDTO -> {
+                        ArticleInfo articleInfo = new ArticleInfo();
+                        BeanUtils.copyProperties(articleInfoDTO, articleInfo);
+                        return articleInfo;
+                    })
+                    .collect(Collectors.toList());
+
             if (!articleInfos.isEmpty()) {
                 this.saveBatch(articleInfos);
                 ids = articleInfos.stream().map(ArticleInfo::getId).collect(Collectors.toList());
@@ -67,24 +74,36 @@ public class ArticleInfoService extends ServiceImpl<ArticleInfoMapper, ArticleIn
 //        return articleInfos.stream().map(ArticleInfo::getId).collect(Collectors.toList());
 //    }
 
-    private boolean isArticleExists(String title) {
-        // 添加查询数据库检查是否已存在相同数据的逻辑,返回 true 表示已存在,false 表示不存在
-        // 这里假设是 ArticleService 中的一个方法来检查文章是否已经存在
-        if (title == null || title.isEmpty()) {
-            // 可以抛出异常或者返回 false,视情况而定
-            return false;
-        }
-        try {
-            LambdaQueryWrapper<ArticleInfo> queryWrapper = new LambdaQueryWrapper<>();
-            queryWrapper.eq(ArticleInfo::getTitle, title);
-            // 使用 selectOne 进行查询,只关心是否存在记录
-            ArticleInfo article = this.getOne(queryWrapper, false);
-            return article != null;
-        } catch (Exception e) {
-            // 日志记录或其他处理方式
-            e.printStackTrace();
-            return false;
-        }
+//    private boolean isArticleExists(String title) {
+//        // 添加查询数据库检查是否已存在相同数据的逻辑,返回 true 表示已存在,false 表示不存在
+//        // 这里假设是 ArticleService 中的一个方法来检查文章是否已经存在
+//        if (title == null || title.isEmpty()) {
+//            // 可以抛出异常或者返回 false,视情况而定
+//            return false;
+//        }
+//        try {
+//            LambdaQueryWrapper<ArticleInfo> queryWrapper = new LambdaQueryWrapper<>();
+//            queryWrapper.eq(ArticleInfo::getTitle, title);
+//            // 使用 selectOne 进行查询,只关心是否存在记录
+//            ArticleInfo article = this.getOne(queryWrapper, false);
+//            return article != null;
+//        } catch (Exception e) {
+//            // 日志记录或其他处理方式
+//            e.printStackTrace();
+//            return false;
+//        }
+//    }
+
+    private List<ArticleInfo> getExistingArticles(List<String> titles) {
+        // 批量查询数据库中是否已存在对应标题的文章,并返回列表
+        LambdaQueryWrapper<ArticleInfo> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.in(ArticleInfo::getTitle, titles);
+        return this.list(queryWrapper);
+    }
+
+    private boolean isArticleExists(List<ArticleInfo> existingArticles, String title) {
+        // 判断标题是否在已有文章列表中存在
+        return existingArticles.stream().anyMatch(article -> article.getTitle().equals(title));
     }
 
     public List<ArticleDataVO> getArticles() {

+ 0 - 65
src/main/java/com/example/mos/service/FollowService.java

@@ -1,65 +0,0 @@
-package com.example.mos.service;
-
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.example.mos.common.model.dto.FollowDTO;
-import com.example.mos.common.model.dto.WeChatAccountInfoDTO;
-import com.example.mos.common.utils.DBUtil;
-import com.example.mos.domain.ArticleInfo;
-import com.example.mos.domain.Follow;
-import com.example.mos.mapper.FollowMapper;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.BeanUtils;
-import org.springframework.stereotype.Service;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Author xiexiang
- * @Date 2024/6/3
- */
-@Slf4j
-@Service
-@RequiredArgsConstructor
-public class FollowService extends ServiceImpl<FollowMapper, Follow> {
-
-    public Integer add(FollowDTO followDTO){
-        Follow follow = new Follow();
-        BeanUtils.copyProperties(followDTO, follow);
-        follow.insert();
-        return follow.getId();
-    }
-
-    public boolean isExist(String fakeId){
-        String sql = "SELECT CASE WHEN COUNT(*) > 0 THEN 'true' ELSE 'false' END AS result FROM follow_account WHERE follow_id LIKE ?";
-        Connection conn = null;
-        PreparedStatement ps = null;
-        boolean exist = false;
-        try {
-            conn = DBUtil.getConn();
-            ps = conn.prepareStatement(sql);
-            ps.setString(1, "%" + fakeId + "%");
-            ResultSet resultSet = ps.executeQuery();
-            while (resultSet.next()) {
-                String result = resultSet.getString("result");
-                if (result.equals("true")) {
-                    exist = true;
-                    break;
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            DBUtil.closeConn(conn);
-            DBUtil.closePs(ps);
-        }
-        return exist;
-    }
-
-    
-}