Merge "新上传的图片,新增上传文件大小限制(不加默认为1mb)"
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1f20988..0d4874b 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -6,16 +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/dto/PromotionCreateDTO.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/dto/PromotionCreateDTO.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/PromotionService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/example/myproject/service/PromotionService.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$/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/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/dto/PromotionCreateDTO.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/dto/PromotionCreateDTO.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/PromotionServiceImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/com/example/myproject/service/serviceImpl/PromotionServiceImpl.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" />
     </list>
     <option name="SHOW_DIALOG" value="false" />
@@ -55,38 +58,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..145692c 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;
@@ -32,45 +34,7 @@
     @Autowired
     private PromotionService promotionService;
 
-    @Autowired
-    private UserService userService;
-    @SaCheckLogin
-    @Operation(summary = "删除种子")
-    @DeleteMapping("/{torrentId}")
-    public Result deleteTorrent(@PathVariable Long torrentId) {
-        try {
-            //  验证用户权限
-            Long userId = StpUtil.getLoginIdAsLong();
-            if (!torrentService.canUserDeleteTorrent(torrentId, userId)) {
-                return Result.error("没有权限删除此种子");
-            }
 
-            torrentService.deleteTorrent(torrentId);
-            return Result.ok();
-        } catch (Exception e) {
-            return Result.error("删除失败: " + e.getMessage());
-        }
-    }
-
-    @SaCheckLogin
-    @Operation(summary = "修改种子信息")
-    @PutMapping("/{torrentId}")
-    public Result updateTorrent(
-            @PathVariable Long torrentId,
-            @RequestBody @Validated TorrentUpdateDTO updateDTO) {
-        try {
-            // 验证用户权限
-            Long userId = StpUtil.getLoginIdAsLong();
-            if (!torrentService.canUserUpdateTorrent(torrentId, userId)) {
-                return Result.error("没有权限修改此种子");
-            }
-
-            torrentService.updateTorrent(torrentId, updateDTO);
-            return Result.ok();
-        } catch (Exception e) {
-            return Result.error("更新失败: " + e.getMessage());
-        }
-    }
 
     @SaCheckLogin
     @Operation(summary = "创建促销活动")
@@ -88,6 +52,39 @@
             return Result.error("创建促销失败: " + e.getMessage());
         }
     }
+    @SaCheckLogin
+    @Operation(summary = "根据分类创建促销活动")
+    @PostMapping("/promotions/category")
+    public Result createPromotionByCategory(@RequestParam String category, @RequestBody @Validated PromotionCreateDTO promotionDTO) {
+        try {
+            // 校验权限
+//            Long userId = StpUtil.getLoginIdAsLong();
+//            var userOpt = userRepository.findById(userId);
+//            if (userOpt.isEmpty() || !"admin".equals(userOpt.get().getRole())) {
+//                return Result.error("没有权限创建促销活动");
+//            }
+
+            // 查询该分类下的所有种子
+            List<TorrentEntity> torrents = torrentService.getTorrentsByCategory(category);
+            if (torrents.isEmpty()) {
+                return Result.error("分类【" + category + "】下没有可用的资源");
+            }
+
+            // 提取所有种子的 ID
+            List<Long> ids = torrents.stream().map(TorrentEntity::getId).toList();
+
+            // 设置到 DTO 中
+            promotionDTO.setApplicableTorrentIds(ids);
+
+            // 创建促销
+            Promotion promotion = promotionService.createPromotion(promotionDTO);
+
+            return Result.ok("成功创建促销,适用于分类【" + category + "】的 " + ids.size() + " 个资源");
+        } catch (Exception e) {
+            return Result.error("分类创建促销失败: " + e.getMessage());
+        }
+    }
+
 
     @SaCheckLogin
     @Operation(summary = "获取促销活动列表")
@@ -138,4 +135,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..4229fc4 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);
     }
 
@@ -170,6 +173,7 @@
             @PathVariable("seed_id") Long seedId,
             @RequestParam("passkey") String passkey,
             HttpServletResponse response) throws IOException {
+        torrentService.incrementDownloadCount(seedId);
 
         // 获取种子实体
         TorrentEntity entity = torrentService.selectBySeedId(seedId);
@@ -202,6 +206,43 @@
         response.getOutputStream().write(torrentBytes);
         response.getOutputStream().flush();
     }
+    @SaCheckLogin
+    @Operation(summary = "修改种子信息")
+    @PutMapping("/{torrentId}")
+    public Result updateTorrent(
+            @PathVariable Long torrentId,
+            @RequestBody @Validated TorrentUpdateDTO updateDTO) {
+        try {
+            // 验证用户权限
+            Long userId = StpUtil.getLoginIdAsLong();
+            if (!torrentService.canUserUpdateTorrent(torrentId, userId)) {
+                return Result.error("没有权限修改此种子");
+            }
+
+            torrentService.updateTorrent(torrentId, updateDTO);
+            return Result.ok();
+        } catch (Exception e) {
+            return Result.error("更新失败: " + e.getMessage());
+        }
+    }
+    @SaCheckLogin
+    @Operation(summary = "删除种子")
+    @DeleteMapping("/{torrentId}")
+    public Result deleteTorrent(@PathVariable Long torrentId) {
+        try {
+            //  验证用户权限
+            Long userId = StpUtil.getLoginIdAsLong();
+            if (!torrentService.canUserDeleteTorrent(torrentId, userId)) {
+                return Result.error("没有权限删除此种子");
+            }
+
+            torrentService.deleteTorrent(torrentId);
+            return Result.ok();
+        } catch (Exception e) {
+            return Result.error("删除失败: " + e.getMessage());
+        }
+    }
+
 
     /**
      * 收藏或者取消收藏
@@ -264,7 +305,6 @@
              * 作弊检测——下载速度检测
              */
 
-
             TorrentReport report = TorrentReport.builder()
                     .userId(userId)
                     .torrentId(torrent.getId())
diff --git a/src/main/java/com/example/myproject/dto/PromotionCreateDTO.java b/src/main/java/com/example/myproject/dto/PromotionCreateDTO.java
index 211979b..ca710d0 100644
--- a/src/main/java/com/example/myproject/dto/PromotionCreateDTO.java
+++ b/src/main/java/com/example/myproject/dto/PromotionCreateDTO.java
@@ -25,7 +25,7 @@
     @Max(value = 100, message = "折扣比例不能大于100")
     private double discountPercentage;
     
-    @NotEmpty(message = "适用种子列表不能为空")
+
     private List<Long> applicableTorrentIds;
     
     @AssertTrue(message = "结束时间必须晚于开始时间")
diff --git a/src/main/java/com/example/myproject/mapper/TorrentMapper.java b/src/main/java/com/example/myproject/mapper/TorrentMapper.java
index 5e72bf2..28e4dfc 100644
--- a/src/main/java/com/example/myproject/mapper/TorrentMapper.java
+++ b/src/main/java/com/example/myproject/mapper/TorrentMapper.java
@@ -31,4 +31,15 @@
                                      @Param("uploaded") double uploaded,
                                      @Param("downloaded") double downloaded);
 
+    void incrementViews(@Param("id") Long id);
+    List<TorrentEntity> selectColdTorrents(@Param("threshold") int threshold);
+    @Select("SELECT * FROM torrent WHERE category = #{category}")
+    List<TorrentEntity> selectByCategory(@Param("category") String category);
+    @Update("UPDATE torrent SET leechers = leechers + 1 WHERE id = #{torrentId}")
+    void incrementDownloadCount(@Param("torrentId") Long torrentId);
+
+
+
+
+
 }
\ No newline at end of file
diff --git a/src/main/java/com/example/myproject/service/PromotionService.java b/src/main/java/com/example/myproject/service/PromotionService.java
index b83bce5..2122411 100644
--- a/src/main/java/com/example/myproject/service/PromotionService.java
+++ b/src/main/java/com/example/myproject/service/PromotionService.java
@@ -18,4 +18,5 @@
     double getDownloadDiscount(Long torrentId);
 
 
-} 
\ No newline at end of file
+
+}
\ 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..700b8ea 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,17 @@
     @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);
+
+    List<TorrentEntity> getTorrentsByCategory(String category);
+
+    void incrementDownloadCount(Long torrentId);
 }
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..dccba96 100644
--- a/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java
+++ b/src/main/java/com/example/myproject/service/serviceImpl/PromotionServiceImpl.java
@@ -3,12 +3,12 @@
 import com.example.myproject.entity.Promotion;
 import com.example.myproject.entity.TorrentEntity;
 import com.example.myproject.mapper.PromotionMapper;
+import com.example.myproject.mapper.TorrentMapper;
 import com.example.myproject.service.PromotionService;
 import com.example.myproject.dto.PromotionCreateDTO;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import io.swagger.models.auth.In;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -23,6 +23,9 @@
     @Autowired
     private PromotionMapper promotionMapper;
 
+    @Autowired
+    private TorrentMapper torrentMapper;
+
     @Override
     @Transactional
     public Promotion createPromotion(PromotionCreateDTO promotionDTO) {
@@ -166,5 +169,4 @@
                 .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..cf97746 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,28 @@
 
         }
     }
+    @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);
+    }
+    @Override
+    public List<TorrentEntity> getTorrentsByCategory(String category) {
+        return torrentMapper.selectByCategory(category);
+    }
+    @Override
+    public void incrementDownloadCount(Long torrentId) {
+        torrentMapper.incrementDownloadCount(torrentId);
+    }
+
+
+
 }
\ 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..2b81885 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..49dbd70 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/dto/PromotionCreateDTO.class b/target/classes/com/example/myproject/dto/PromotionCreateDTO.class
index 3087d39..8dd281b 100644
--- a/target/classes/com/example/myproject/dto/PromotionCreateDTO.class
+++ b/target/classes/com/example/myproject/dto/PromotionCreateDTO.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..b530a48 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..b4d3e30 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/PromotionServiceImpl.class b/target/classes/com/example/myproject/service/serviceImpl/PromotionServiceImpl.class
index 83cf11d..353c7df 100644
--- a/target/classes/com/example/myproject/service/serviceImpl/PromotionServiceImpl.class
+++ b/target/classes/com/example/myproject/service/serviceImpl/PromotionServiceImpl.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..4ee1413 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