推荐算法 用户考核 头像上传
Change-Id: Iaac96768d5238142f5ed445f5cc64ccedd239d0f
diff --git a/src/main/java/com/pt5/pthouduan/controller/ExamController.java b/src/main/java/com/pt5/pthouduan/controller/ExamController.java
new file mode 100644
index 0000000..a5941be
--- /dev/null
+++ b/src/main/java/com/pt5/pthouduan/controller/ExamController.java
@@ -0,0 +1,27 @@
+package com.pt5.pthouduan.controller;
+
+import com.pt5.pthouduan.service.ExamService;
+import com.pt5.pthouduan.service.ShopService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.time.LocalDate;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/exam")
+public class ExamController {
+ @Autowired
+ private ExamService examService;
+ @PostMapping("/MonthDownload")
+ public Map<String, Object> MonthDownload(@RequestParam LocalDate startDate, @RequestParam LocalDate endDate) {
+ return examService.MonthDownload(startDate, endDate);
+ }
+ @PostMapping("/QuarterUpload")
+ public Map<String, Object> QuarterUpload(@RequestParam LocalDate startDate, @RequestParam LocalDate endDate) {
+ return examService.QuarterUpload(startDate, endDate);
+ }
+}
diff --git a/src/main/java/com/pt5/pthouduan/controller/RecommendController.java b/src/main/java/com/pt5/pthouduan/controller/RecommendController.java
new file mode 100644
index 0000000..da981cb
--- /dev/null
+++ b/src/main/java/com/pt5/pthouduan/controller/RecommendController.java
@@ -0,0 +1,26 @@
+package com.pt5.pthouduan.controller;
+
+import com.pt5.pthouduan.entity.Torrent;
+import com.pt5.pthouduan.entity.User;
+import com.pt5.pthouduan.service.InviteService;
+import com.pt5.pthouduan.service.RecommendService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/recommend")
+public class RecommendController {
+ @Autowired
+ private RecommendService recommendService;
+// @GetMapping("/test")
+// public List<Map<String, Object>> test() {
+// return recommendService.test();
+// }
+ @GetMapping("/list")
+ public List<Torrent> getRecommendList(@RequestParam Long userId) {
+ return recommendService.recommendForUser(userId);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/pt5/pthouduan/controller/UserController.java b/src/main/java/com/pt5/pthouduan/controller/UserController.java
index 4a23ea9..11f77ce 100644
--- a/src/main/java/com/pt5/pthouduan/controller/UserController.java
+++ b/src/main/java/com/pt5/pthouduan/controller/UserController.java
@@ -31,7 +31,11 @@
public class UserController {
@Autowired
private UserService userService;
- private String uploadDir="../var/www/avatars/"; // 配置文件上传目录,例如: /var/www/avatars/
+
+ @Value("${torrent.user-image-dir}")
+ private String uploadDir;
+
+ //private String uploadDir="../var/www/avatars/"; // 配置文件上传目录,例如: /var/www/avatars/
private String accessPath="../avatars/";
@@ -113,68 +117,68 @@
return userService.getuserid(username);
}
- @PostMapping("/uploadimage")
- public ResponseEntity<Map<String, Object>> uploadAvatar(@RequestParam("avatar") MultipartFile file) {
- Map<String, Object> response = new HashMap<>();
+// @PostMapping("/uploadimage")
+// public ResponseEntity<Map<String, Object>> uploadAvatar(@RequestParam("avatar") MultipartFile file) {
+// Map<String, Object> response = new HashMap<>();
+//
+// // 1. 验证文件是否为空
+// if (file.isEmpty()) {
+// response.put("success", false);
+// response.put("message", "请选择要上传的文件");
+// return ResponseEntity.badRequest().body(response);
+// }
+//
+// // 2. 验证文件类型
+// String contentType = file.getContentType();
+// if (!"image/jpeg".equals(contentType) &&
+// !"image/png".equals(contentType) &&
+// !"image/gif".equals(contentType)) {
+// response.put("success", false);
+// response.put("message", "只支持JPG/PNG/GIF格式的图片");
+// return ResponseEntity.badRequest().body(response);
+// }
+//
+// // 3. 验证文件大小 (前端已验证,后端再次验证)
+// if (file.getSize() > 10 * 1024 * 1024) { // 10MB
+// response.put("success", false);
+// response.put("message", "图片大小不能超过10MB");
+// return ResponseEntity.badRequest().body(response);
+// }
- // 1. 验证文件是否为空
- if (file.isEmpty()) {
- response.put("success", false);
- response.put("message", "请选择要上传的文件");
- return ResponseEntity.badRequest().body(response);
- }
-
- // 2. 验证文件类型
- String contentType = file.getContentType();
- if (!"image/jpeg".equals(contentType) &&
- !"image/png".equals(contentType) &&
- !"image/gif".equals(contentType)) {
- response.put("success", false);
- response.put("message", "只支持JPG/PNG/GIF格式的图片");
- return ResponseEntity.badRequest().body(response);
- }
-
- // 3. 验证文件大小 (前端已验证,后端再次验证)
- if (file.getSize() > 10 * 1024 * 1024) { // 10MB
- response.put("success", false);
- response.put("message", "图片大小不能超过10MB");
- return ResponseEntity.badRequest().body(response);
- }
-
- try {
- // 4. 创建上传目录(如果不存在)
- File dir = new File(uploadDir);
- if (!dir.exists()) {
- dir.mkdirs();
- }
- System.out.println(dir.getAbsolutePath());
- // 5. 生成唯一文件名 (日期+UUID+后缀)
- String originalFilename = file.getOriginalFilename();
- String fileExt = originalFilename.substring(originalFilename.lastIndexOf("."));
- String newFilename = new SimpleDateFormat("yyyyMMdd").format(new Date()) +
- "_" + UUID.randomUUID().toString().replace("-", "") +
- fileExt.toLowerCase();
-
- // 6. 保存文件
- Path path = Paths.get(uploadDir, newFilename);
- Files.copy(file.getInputStream(), path);
-
- // 7. 返回访问URL
- String fileUrl = accessPath + newFilename;
-
- response.put("success", true);
- response.put("url", fileUrl);
- response.put("message", "头像上传成功");
-
- return ResponseEntity.ok(response);
-
- } catch (IOException e) {
- e.printStackTrace();
- response.put("success", false);
- response.put("message", "文件上传失败: " + e.getMessage());
- return ResponseEntity.status(500).body(response);
- }
- }
+// try {
+// // 4. 创建上传目录(如果不存在)
+// File dir = new File(uploadDir);
+// if (!dir.exists()) {
+// boolean created = dir.mkdirs(); // 递归创建目录
+// if (!created) {
+// throw new IOException("无法创建目录:" + uploadDir);
+// }
+// }
+// System.out.println(dir.getAbsolutePath());
+// String filename = System.currentTimeMillis()+"_"+file.getOriginalFilename();
+// Path userimagePath = Paths.get(uploadDir, filename);
+//
+// // 6. 保存文件
+// Files.createDirectories(userimagePath.getParent()); // 创建目录
+// Files.copy(file.getInputStream(), userimagePath, StandardCopyOption.REPLACE_EXISTING);
+//
+// // 7. 返回访问URL
+// //String fileUrl = accessPath + newFilename;
+// String fileUrl = "http://localhost:8080/" + uploadDir + filename;
+//
+// response.put("success", true);
+// response.put("url", fileUrl);
+// response.put("message", "头像上传成功");
+//
+// return ResponseEntity.ok(response);
+//
+// } catch (IOException e) {
+// e.printStackTrace();
+// response.put("success", false);
+// response.put("message", "文件上传失败: " + e.getMessage());
+// return ResponseEntity.status(500).body(response);
+// }
+ //}
}