查看冷门资源

Change-Id: Idb875bd6ff4c6dba3cc40cf6ef298731b526c1a7
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1f20988..a8762d7 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,17 +6,19 @@
   <component name="ChangeListManager">
     <list default="true" id="f008fe30-0711-42e2-bb33-17dcfdbad387" name="Changes" comment="pom">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/MyProjectApplication.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/MyProjectApplication.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/PromotionController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/PromotionController.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/TorrentController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/controller/TorrentController.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/entity/TorrentReport.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/entity/TorrentReport.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/mapper/TorrentMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/mapper/TorrentMapper.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/TorrentService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/TorrentService.java" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/MyProjectApplication.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/MyProjectApplication.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/src/main/resources/mapper/TorrentMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/resources/mapper/TorrentMapper.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/controller/PromotionController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/controller/PromotionController.class" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/controller/TorrentController.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/controller/TorrentController.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/entity/TorrentReport$TorrentReportBuilder.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/entity/TorrentReport$TorrentReportBuilder.class" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/entity/TorrentReport.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/entity/TorrentReport.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/mapper/TorrentMapper.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/mapper/TorrentMapper.class" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/service/TorrentService.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/service/TorrentService.class" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/target/classes/mapper/TorrentMapper.xml" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/mapper/TorrentMapper.xml" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
     <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -55,38 +57,38 @@
     <option name="hideEmptyMiddlePackages" value="true" />
     <option name="showLibraryContents" value="true" />
   </component>
-  <component name="PropertiesComponent">{
-        &quot;keyToString&quot;: {
-        &quot;ASKED_ADD_EXTERNAL_FILES&quot;: &quot;true&quot;,
-        &quot;JUnit.UserControllerTest.executor&quot;: &quot;Run&quot;,
-        &quot;JUnit.UserControllerTest.testUpdateUserAvatar.executor&quot;: &quot;Run&quot;,
-        &quot;JUnit.UserControllerTest.testUploadUserAvatar.executor&quot;: &quot;Run&quot;,
-        &quot;RequestMappingsPanelOrder0&quot;: &quot;0&quot;,
-        &quot;RequestMappingsPanelOrder1&quot;: &quot;1&quot;,
-        &quot;RequestMappingsPanelWidth0&quot;: &quot;75&quot;,
-        &quot;RequestMappingsPanelWidth1&quot;: &quot;75&quot;,
-        &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
-        &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
-        &quot;RunOnceActivity.git.unshallow&quot;: &quot;true&quot;,
-        &quot;Spring Boot.MyProjectApplication.executor&quot;: &quot;Run&quot;,
-        &quot;git-widget-placeholder&quot;: &quot;完成pt与bt交互、补充图片资源&quot;,
-        &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
-        &quot;kotlin-language-version-configured&quot;: &quot;true&quot;,
-        &quot;last_opened_file_path&quot;: &quot;D:/Desktop/echo后端/echo-backend/images&quot;,
-        &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
-        &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
-        &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
-        &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
-        &quot;settings.editor.selected.configurable&quot;: &quot;project.propVCSSupport.DirectoryMappings&quot;,
-        &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;,
-        &quot;应用程序.MyProjectApplication.executor&quot;: &quot;Run&quot;
-        },
-        &quot;keyToStringList&quot;: {
-        &quot;DatabaseDriversLRU&quot;: [
-        &quot;mysql_aurora&quot;
-        ]
-        }
-        }</component>
+  <component name="PropertiesComponent"><![CDATA[{
+  "keyToString": {
+    "ASKED_ADD_EXTERNAL_FILES": "true",
+    "JUnit.UserControllerTest.executor": "Run",
+    "JUnit.UserControllerTest.testUpdateUserAvatar.executor": "Run",
+    "JUnit.UserControllerTest.testUploadUserAvatar.executor": "Run",
+    "RequestMappingsPanelOrder0": "0",
+    "RequestMappingsPanelOrder1": "1",
+    "RequestMappingsPanelWidth0": "75",
+    "RequestMappingsPanelWidth1": "75",
+    "RunOnceActivity.OpenProjectViewOnStart": "true",
+    "RunOnceActivity.ShowReadmeOnStart": "true",
+    "RunOnceActivity.git.unshallow": "true",
+    "Spring Boot.MyProjectApplication.executor": "Run",
+    "git-widget-placeholder": "完成pt与bt交互、补充图片资源",
+    "ignore.virus.scanning.warn.message": "true",
+    "kotlin-language-version-configured": "true",
+    "last_opened_file_path": "D:/study/学习资源/大三下/school/java-ee/live-reward-system",
+    "node.js.detected.package.eslint": "true",
+    "node.js.selected.package.eslint": "(autodetect)",
+    "node.js.selected.package.tslint": "(autodetect)",
+    "nodejs_package_manager_path": "npm",
+    "settings.editor.selected.configurable": "project.propVCSSupport.DirectoryMappings",
+    "vue.rearranger.settings.migration": "true",
+    "应用程序.MyProjectApplication.executor": "Run"
+  },
+  "keyToStringList": {
+    "DatabaseDriversLRU": [
+      "mysql_aurora"
+    ]
+  }
+}]]></component>
   <component name="RecentsManager">
     <key name="CopyFile.RECENT_KEYS">
       <recent name="D:\Desktop\echo后端\echo-backend\images" />
diff --git a/src/main/java/com/example/myproject/controller/PromotionController.java b/src/main/java/com/example/myproject/controller/PromotionController.java
index ab6efe7..ed90bf7 100644
--- a/src/main/java/com/example/myproject/controller/PromotionController.java
+++ b/src/main/java/com/example/myproject/controller/PromotionController.java
@@ -5,7 +5,9 @@
 import com.example.myproject.common.base.Result;
 import com.example.myproject.dto.PromotionCreateDTO;
 import com.example.myproject.dto.TorrentUpdateDTO;
+import com.example.myproject.dto.vo.TorrentVO;
 import com.example.myproject.entity.Promotion;
+import com.example.myproject.entity.TorrentEntity;
 import com.example.myproject.service.PromotionService;
 import com.example.myproject.service.TorrentService;
 import com.example.myproject.service.UserService;
@@ -138,4 +140,17 @@
             return Result.error("删除促销失败: " + e.getMessage());
         }
     }
+    @SaCheckLogin
+    @Operation(summary = "查看冷门资源")
+    @GetMapping("/cold")
+    public Result getColdResources() {
+        try {
+            List<TorrentEntity> coldList = torrentService.getColdTorrents(10); // 例如 views < 10
+            return Result.ok(coldList);
+        } catch (Exception e) {
+            return Result.error("获取冷门资源失败: " + e.getMessage());
+        }
+    }
+
+
 }
diff --git a/src/main/java/com/example/myproject/controller/TorrentController.java b/src/main/java/com/example/myproject/controller/TorrentController.java
index 4ce3eca..fd79757 100644
--- a/src/main/java/com/example/myproject/controller/TorrentController.java
+++ b/src/main/java/com/example/myproject/controller/TorrentController.java
@@ -96,6 +96,7 @@
         return Result.ok(list, PageUtil.getPage(list));
     }
 
+
     @SaCheckLogin
     @Operation(summary = "种子详情查询")
     @ApiResponse(responseCode = "0", description = "操作成功", content = {
@@ -104,8 +105,10 @@
     })
     @PostMapping("/info/{id}")
     public Result info(@PathVariable("id")Long id) {
-
-        TorrentEntity entity = torrentService.selectBySeedId(id);
+        TorrentEntity entity = torrentService.selectBySeedIdAndIncrementViews(id);
+        if (entity == null) {
+            return Result.error("未找到该种子");
+        }
         return Result.ok(entity);
     }
 
@@ -264,7 +267,6 @@
              * 作弊检测——下载速度检测
              */
 
-
             TorrentReport report = TorrentReport.builder()
                     .userId(userId)
                     .torrentId(torrent.getId())
diff --git a/src/main/java/com/example/myproject/mapper/TorrentMapper.java b/src/main/java/com/example/myproject/mapper/TorrentMapper.java
index 5e72bf2..3419938 100644
--- a/src/main/java/com/example/myproject/mapper/TorrentMapper.java
+++ b/src/main/java/com/example/myproject/mapper/TorrentMapper.java
@@ -31,4 +31,9 @@
                                      @Param("uploaded") double uploaded,
                                      @Param("downloaded") double downloaded);
 
+    void incrementViews(@Param("id") Long id);
+    List<TorrentEntity> selectColdTorrents(@Param("threshold") int threshold);
+
+
+
 }
\ No newline at end of file
diff --git a/src/main/java/com/example/myproject/service/TorrentService.java b/src/main/java/com/example/myproject/service/TorrentService.java
index 14b96a2..0baee2d 100644
--- a/src/main/java/com/example/myproject/service/TorrentService.java
+++ b/src/main/java/com/example/myproject/service/TorrentService.java
@@ -38,6 +38,7 @@
 package com.example.myproject.service;
 
 import com.example.myproject.common.base.Result;
+import com.example.myproject.dto.vo.TorrentVO;
 import com.example.myproject.entity.TorrentEntity;
 import com.example.myproject.dto.param.TorrentParam;
 import com.example.myproject.dto.param.TorrentUploadParam;
@@ -79,4 +80,13 @@
     @Async
     void processUploadDownload(Long userId, String peerId, String infoHash, Long torrentId, double uploaded, double downloaded);
 
+
+    TorrentEntity selectBySeedIdAndIncrementViews(Long id);
+
+
+    //    @Override
+    //    public List<TorrentEntity> getColdTorrents(int threshold) {
+    //        return torrentMapper.selectColdTorrents(threshold);
+    //    }
+    List<TorrentEntity> getColdTorrents(int threshold);
 }
diff --git a/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java b/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java
index 1cac3a4..caec8e1 100644
--- a/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java
+++ b/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java
@@ -165,6 +165,4 @@
                 .min()
                 .orElse(0.0);
     }
-
-
 }
diff --git a/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java b/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java
index 159c347..2fb4b4d 100644
--- a/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java
+++ b/src/main/java/com/example/myproject/service/serviceImpl/TorrentServiceImpl.java
@@ -298,8 +298,6 @@
 package com.example.myproject.service.serviceImpl;
 import java.time.Duration;
 
-import cn.dev33.satoken.stp.StpUtil;
-import com.example.myproject.entity.SuspiciousUser;
 import com.example.myproject.entity.TorrentEntity;
 import com.example.myproject.entity.TorrentReport;
 import com.example.myproject.entity.User;
@@ -317,7 +315,6 @@
 import com.turn.ttorrent.bcodec.BDecoder;
 import com.turn.ttorrent.bcodec.BEValue;
 import com.turn.ttorrent.bcodec.BEncoder;
-import com.turn.ttorrent.client.SimpleClient;
 import com.turn.ttorrent.common.TorrentMetadata;
 import com.turn.ttorrent.common.TorrentParser;
 import com.turn.ttorrent.tracker.Tracker;
@@ -326,8 +323,6 @@
 import lombok.extern.slf4j.Slf4j;
 
 
-import org.apache.commons.codec.binary.Hex;
-import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -336,10 +331,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.net.InetAddress;
-import java.nio.file.Path;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.List;
@@ -602,4 +593,18 @@
 
         }
     }
+    @Override
+    public TorrentEntity selectBySeedIdAndIncrementViews(Long id) {
+        torrentMapper.incrementViews(id); // 更新 views
+        return torrentMapper.selectById(id); // 返回更新后的实体
+    }
+//    @Override
+//    public List<TorrentEntity> getColdTorrents(int threshold) {
+//        return torrentMapper.selectColdTorrents(threshold);
+//    }
+    @Override
+    public List<TorrentEntity> getColdTorrents(int threshold) {
+        return torrentMapper.selectColdTorrents(threshold);
+    }
+
 }
\ No newline at end of file
diff --git a/src/main/resources/mapper/TorrentMapper.xml b/src/main/resources/mapper/TorrentMapper.xml
index 8e5419b..9c165ce 100644
--- a/src/main/resources/mapper/TorrentMapper.xml
+++ b/src/main/resources/mapper/TorrentMapper.xml
@@ -105,5 +105,17 @@
         JOIN favorite f ON t.id = f.seed_id
         WHERE f.user_id = #{userId}
     </select>
+    <update id="incrementViews" parameterType="long">
+        UPDATE torrent
+        SET views = views + 1
+        WHERE id = #{id}
+    </update>
+    <select id="selectColdTorrents" resultType="com.example.myproject.entity.TorrentEntity">
+        SELECT * FROM torrent
+        WHERE views &lt; #{threshold}
+        ORDER BY views ASC
+    </select>
+
+
 
 </mapper>
\ No newline at end of file
diff --git a/target/classes/com/example/myproject/controller/PromotionController.class b/target/classes/com/example/myproject/controller/PromotionController.class
index 2de5158..2c5370a 100644
--- a/target/classes/com/example/myproject/controller/PromotionController.class
+++ b/target/classes/com/example/myproject/controller/PromotionController.class
Binary files differ
diff --git a/target/classes/com/example/myproject/controller/TorrentController.class b/target/classes/com/example/myproject/controller/TorrentController.class
index 1fd4786..4713572 100644
--- a/target/classes/com/example/myproject/controller/TorrentController.class
+++ b/target/classes/com/example/myproject/controller/TorrentController.class
Binary files differ
diff --git a/target/classes/com/example/myproject/mapper/TorrentMapper.class b/target/classes/com/example/myproject/mapper/TorrentMapper.class
index 56fb640..1a9a7c9 100644
--- a/target/classes/com/example/myproject/mapper/TorrentMapper.class
+++ b/target/classes/com/example/myproject/mapper/TorrentMapper.class
Binary files differ
diff --git a/target/classes/com/example/myproject/service/TorrentService.class b/target/classes/com/example/myproject/service/TorrentService.class
index 4927d64..579be31 100644
--- a/target/classes/com/example/myproject/service/TorrentService.class
+++ b/target/classes/com/example/myproject/service/TorrentService.class
Binary files differ
diff --git a/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class b/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class
index f1b6465..ac29866 100644
--- a/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class
+++ b/target/classes/com/example/myproject/service/serviceImpl/TorrentServiceImpl.class
Binary files differ
diff --git a/target/classes/mapper/TorrentMapper.xml b/target/classes/mapper/TorrentMapper.xml
index 8e5419b..9c165ce 100644
--- a/target/classes/mapper/TorrentMapper.xml
+++ b/target/classes/mapper/TorrentMapper.xml
@@ -105,5 +105,17 @@
         JOIN favorite f ON t.id = f.seed_id
         WHERE f.user_id = #{userId}
     </select>
+    <update id="incrementViews" parameterType="long">
+        UPDATE torrent
+        SET views = views + 1
+        WHERE id = #{id}
+    </update>
+    <select id="selectColdTorrents" resultType="com.example.myproject.entity.TorrentEntity">
+        SELECT * FROM torrent
+        WHERE views &lt; #{threshold}
+        ORDER BY views ASC
+    </select>
+
+
 
 </mapper>
\ No newline at end of file