更新求种后端函数

Change-Id: I9e593e5eecfc6337120f75b3f6338f8279579dd1
diff --git a/src/main/java/api/ApiApplication.java b/src/main/java/api/ApiApplication.java
index 1f39e69..c28da07 100644
--- a/src/main/java/api/ApiApplication.java
+++ b/src/main/java/api/ApiApplication.java
@@ -16,18 +16,4 @@
         }
         SpringApplication.run(ApiApplication.class, args);
     }
-
-    // @Bean
-    // public WebMvcConfigurer corsConfigurer() {
-    //     return new WebMvcConfigurer() {
-    //         @Override
-    //         public void addCorsMappings(CorsRegistry registry) {
-    //             registry.addMapping("/**")
-    //                     .allowedOrigins("*")
-    //                     .allowedMethods("*")
-    //                     .allowedHeaders("*")
-    //                     .exposedHeaders(HttpHeaders.CONTENT_DISPOSITION);
-    //         }
-    //     };
-    // }
 }
\ No newline at end of file
diff --git a/src/main/java/api/ApiController.java b/src/main/java/api/ApiController.java
index c2562bc..2c37f8b 100644
--- a/src/main/java/api/ApiController.java
+++ b/src/main/java/api/ApiController.java
@@ -1,6 +1,11 @@
 package api;
 
 import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Date;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
 
 import javax.annotation.PostConstruct;
 
@@ -15,19 +20,27 @@
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.PostMapping;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 import database.Database1;
 import tracker.Tracker;
+import cheat.Cheat;
 
 import entity.Seed;
 import entity.User;
 import entity.Post;
+import entity.BegSeedDetail;
 import entity.PostReply;
+import entity.Profile;
 import entity.UserPT;
+import entity.config;
+import entity.Appeal;
+import entity.BegInfo;
+import entity.BegInfoDetail;
+import entity.UserStar;
+import entity.SeedWithVotes;
 
 import java.util.UUID;
 
@@ -36,12 +49,14 @@
 
     private static Database1 db1;
     private static Tracker tracker;
+    private static Cheat cheat;
     private static ObjectMapper mapper;
     private static HttpHeaders headers;
     private static HttpHeaders errorHeaders;
 
     @PostConstruct
     public void init() {
+        cheat = new Cheat();
         db1 = new Database1();
         tracker = new Tracker();
         mapper = new ObjectMapper();
@@ -77,7 +92,7 @@
                 // 如果注册种子失败,返回错误状态
                 return new ResponseEntity<>(ret, headers, HttpStatus.INTERNAL_SERVER_ERROR);
             }
-            File tempFile = File.createTempFile(seed.seedid, file.getOriginalFilename());
+            File tempFile = File.createTempFile(userid, file.getOriginalFilename());
             file.transferTo(tempFile);
             tracker.SaveTorrent(seed.seedid, tempFile);
             return new ResponseEntity<>(0, headers, HttpStatus.OK); // 返回 0 表示成功
@@ -112,7 +127,7 @@
     ) {
         try {
             Seed[] seeds = db1.GetSeedListByTag(tag);
-            if (seeds == null || seeds.length == 0) {
+            if (seeds == null) {
                 return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 404 表示未找到种子
             }
             String json = mapper.writeValueAsString(seeds);
@@ -227,7 +242,7 @@
     ) {
         try {
             Seed[] seeds = db1.GetSeedListByUser(userid);
-            if (seeds == null || seeds.length == 0) {
+            if (seeds == null) {
                 return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 404 表示未找到种子
             }
             String json = mapper.writeValueAsString(seeds);
@@ -484,7 +499,7 @@
     public ResponseEntity<String> getForum() {
         try {
             Post[] posts = db1.GetPostList();
-            if (posts == null || posts.length == 0) {
+            if (posts == null) {
                 return new ResponseEntity<>("[]", HttpStatus.OK); // 返回空数组表示没有帖子
             }
             String json = mapper.writeValueAsString(posts);
@@ -645,7 +660,7 @@
     ) {
         try {
             Seed[] seeds = db1.SearchSeed(query);
-            if (seeds == null || seeds.length == 0) {
+            if (seeds == null) {
                 return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到种子
             }
             
@@ -680,7 +695,7 @@
     ) {
         try {
             Post[] posts = db1.SearchPost(query);
-            if (posts == null || posts.length == 0) {
+            if (posts == null) {
                 return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到帖子
             }
             String json = mapper.writeValueAsString(posts);
@@ -713,4 +728,820 @@
             return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
         }
     }
+
+    @Override
+    public ResponseEntity<String> getConfig(
+        @RequestParam("userid") String userid
+    ) {
+        try {
+            int ret = db1.CheckAdmin(userid);
+            if (ret != 0) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.UNAUTHORIZED); // 返回 401 表示未授权
+            }
+            // 创建配置信息的 JSON 对象
+            Map<String, Object> configData = new HashMap<>();
+            configData.put("FarmNumber", config.getFarmNumber());
+            configData.put("FakeTime", config.getFakeTime());
+            configData.put("BegVote", config.getBegVote());
+            configData.put("CheatTime", config.getCheatTime());
+            
+            String json = mapper.writeValueAsString(configData);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getCheatUsers(
+        @RequestParam("userid") String userid
+    ) {
+        try {
+            int ret = db1.CheckAdmin(userid);
+            if (ret != 0) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.UNAUTHORIZED); // 返回 401 表示未授权
+            }
+            User[] cheatUsers = cheat.GetCheatUsers();
+            if (cheatUsers == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到作弊用户
+            }
+            String json = mapper.writeValueAsString(cheatUsers);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getSuspiciousUsers(
+        @RequestParam("userid") String userid
+    ) {
+        try {
+            int ret = db1.CheckAdmin(userid);
+            if (ret != 0) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.UNAUTHORIZED); // 返回 401 表示未授权
+            }
+            User[] suspiciousUsers = cheat.GetSuspiciousUsers();
+            if (suspiciousUsers == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到可疑用户
+            }
+            String json = mapper.writeValueAsString(suspiciousUsers);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> unbanUser(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            if (useridNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String userid = useridNode.asText();
+            
+            // 添加参数验证
+            if (userid == null || userid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            int ret = cheat.UnbanUser(userid);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.NOT_FOUND); // 返回 1 表示用户不存在
+            } else if (ret == 2) {
+                return new ResponseEntity<>(2, HttpStatus.CONFLICT); // 返回 2 表示用户未被封禁
+            } else {
+                return new ResponseEntity<>(3, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> banUser(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            if (useridNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String userid = useridNode.asText();
+            
+            // 添加参数验证
+            if (userid == null || userid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            int ret = cheat.BanUser(userid);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.NOT_FOUND); // 返回 1 表示用户不存在
+            } else if (ret == 2) {
+                return new ResponseEntity<>(2, HttpStatus.CONFLICT); // 返回 2 表示用户已被封禁
+            } else {
+                return new ResponseEntity<>(3, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getAppeals() {
+        try {
+            Appeal[] appeals = cheat.GetAppealList();
+            if (appeals == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到申诉
+            }
+            String json = mapper.writeValueAsString(appeals);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getMigrations() {
+        try {
+            Profile[] migrations = db1.GetTransmitProfileList();
+            if (migrations == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到迁移记录
+            }
+            String json = mapper.writeValueAsString(migrations);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> approveAppeal(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode appealidNode = jsonNode.get("appealid");
+            if (appealidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String appealid = appealidNode.asText();
+            
+            // 添加参数验证
+            if (appealid == null || appealid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            boolean ret = cheat.HandleAppeal(appealid, 1);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> rejectAppeal(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode appealidNode = jsonNode.get("appealid");
+            if (appealidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String appealid = appealidNode.asText();
+            
+            // 添加参数验证
+            if (appealid == null || appealid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            boolean ret = cheat.HandleAppeal(appealid, 2);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> approveMigration(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode migrationidNode = jsonNode.get("migration_id");
+            if (migrationidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String migrationid = migrationidNode.asText();
+            System.out.println("Migration ID: " + migrationid);
+            
+            // 添加参数验证
+            if (migrationid == null || migrationid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            boolean ret = db1.ExamTransmitProfile(migrationid, true);
+            System.out.println("Migration approval result: " + ret);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> rejectMigration(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode migrationidNode = jsonNode.get("migration_id");
+            if (migrationidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String migrationid = migrationidNode.asText();
+            
+            // 添加参数验证
+            if (migrationid == null || migrationid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            boolean ret = db1.ExamTransmitProfile(migrationid, false);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> inviteUser(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode emailNode = jsonNode.get("invite_email");
+            if (useridNode == null || emailNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String userid = useridNode.asText();
+            String email = emailNode.asText();
+            
+            // 添加参数验证
+            if (email == null || email.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            int ret = db1.InviteNewUser(userid, email);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.CONFLICT); // 返回 1 表示邀请已存在
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+    
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> submitAppeal(
+        @RequestParam("userid") String userid,
+        @RequestParam("content") String content,
+        @RequestParam("file") MultipartFile file
+    ) {
+        try {
+            System.out.println("Submit appeal request: userid=" + userid + ", content=" + content);
+            // 先进行参数验证
+            if (userid == null || userid.trim().isEmpty() || 
+                content == null || content.trim().isEmpty() ||
+                file == null || file.isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            if (file.getSize() > 100 * 1024 * 1024) {
+                System.out.println("File size exceeds limit: " + file.getSize() + " bytes");
+                return new ResponseEntity<>(3, HttpStatus.PAYLOAD_TOO_LARGE); // 返回 3 表示文件过大
+            }
+            
+            System.out.println("Submit appeal request: userid=" + userid + ", content=" + content);
+            File tempFile = File.createTempFile(userid, file.getOriginalFilename());
+            file.transferTo(tempFile);
+            
+            int ret = cheat.SubmitAppeal(userid, content, tempFile);
+            System.out.println("Submit appeal result: " + ret);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.CONFLICT); // 返回 1 表示用户未被封禁或其他错误
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (org.springframework.web.multipart.MaxUploadSizeExceededException e) {
+            System.out.println("File upload size exceeded: " + e.getMessage());
+            return new ResponseEntity<>(3, HttpStatus.PAYLOAD_TOO_LARGE); // 返回 3 表示文件过大
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getUserStats(
+        @RequestParam("userid") String userid
+    ) {
+        try {
+            if (userid == null || userid.trim().isEmpty()) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.BAD_REQUEST); // 返回 400 表示参数不完整
+            }
+
+            UserPT userPT = db1.GetInformationPT(userid);
+            if (userPT == null) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到用户PT信息
+            }   
+
+            String json = mapper.writeValueAsString(userPT);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 500 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> magicExchange(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode magicNode = jsonNode.get("magic");
+            com.fasterxml.jackson.databind.JsonNode typeNode = jsonNode.get("exchangeType");
+
+            if (useridNode == null || magicNode == null || typeNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+            String userid = useridNode.asText();
+            int magic = magicNode.asInt();
+            String exchangeType = typeNode.asText();
+
+            boolean ret = false;
+            if( "uploaded".equals(exchangeType) ) {
+                ret = db1.ExchangeMagicToUpload(userid, magic);
+            } else if( "downloaded".equals(exchangeType) ) {
+                ret = db1.ExchangeMagicToDownload(userid, magic);
+            } else if( "vip_downloads".equals(exchangeType) ) {
+                ret = db1.ExchangeMagicToVip(userid, magic);
+            } else {
+                System.out.println("Invalid exchange type: " + exchangeType);
+                return new ResponseEntity<>(2, HttpStatus.BAD_REQUEST); // 返回 2 表示交换类型错误
+            }
+            if (!ret) {
+                return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+            }
+            return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getUserFavorites(
+        @RequestParam("userid") String userid
+    ) {
+        try {
+            if (userid == null || userid.trim().isEmpty()) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.BAD_REQUEST); // 返回 400 表示参数不完整
+            }
+
+            UserStar[] favorites = db1.GetUserStarList(userid);
+            if (favorites == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到用户收藏
+            }
+
+            String json = mapper.writeValueAsString(favorites);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 500 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> removeFavorite(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode seedidNode = jsonNode.get("seedid");
+            if (useridNode == null || seedidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            String userid = useridNode.asText();
+            String seedid = seedidNode.asText();
+
+            // 添加参数验证
+            if (userid == null || userid.trim().isEmpty() || 
+                seedid == null || seedid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+
+            boolean ret = db1.DeleteCollect(userid, seedid);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> addFavorite(
+        @RequestBody String requestBody
+    ) {
+        try {
+            // 解析 JSON 数据
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode seedidNode = jsonNode.get("seedid");
+            if (useridNode == null || seedidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            String userid = useridNode.asText();
+            String seedid = seedidNode.asText();
+
+            // 添加参数验证
+            if (userid == null || userid.trim().isEmpty() || 
+                seedid == null || seedid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+
+            boolean ret = db1.AddCollect(userid, seedid);
+            if (ret) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> migrateAccount(
+        @RequestParam("userid") String userid,
+        @RequestParam("file") MultipartFile file
+    ) {
+        try {
+            // 先进行参数验证
+            if (userid == null || userid.trim().isEmpty() || 
+                file == null || file.isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST);
+            }
+            
+            if (file.getSize() > 100 * 1024 * 1024) {
+                System.out.println("File size exceeds limit: " + file.getSize() + " bytes");
+                return new ResponseEntity<>(3, HttpStatus.PAYLOAD_TOO_LARGE); // 返回 3 表示文件过大
+            }
+            
+            File tempFile = File.createTempFile(userid, file.getOriginalFilename());
+            file.transferTo(tempFile);
+
+            int ret = db1.UploadMigration(userid, tempFile);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.CONFLICT); // 返回 1 表示用户已存在或其他错误
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getBegSeedList() {
+        try {
+            BegSeedDetail[] begSeedList = db1.GetBegList();
+            if (begSeedList == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到种子列表
+            }
+            String json = mapper.writeValueAsString(begSeedList);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 500 表示处理失败
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getBegSeedDetail(
+        @RequestParam("begid") String begid
+    ) {
+        try {
+            System.out.println("getBegSeedDetail called with begid: " + begid);
+            if (begid == null || begid.trim().isEmpty()) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.BAD_REQUEST); // 返回 400 表示参数不完整
+            }
+
+            BegSeedDetail begSeedDetail = db1.GetBegSeedDetail(begid);
+            if (begSeedDetail == null) {
+                return new ResponseEntity<>("", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到种子详情
+            }
+            String json = mapper.writeValueAsString(begSeedDetail);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 500 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    public ResponseEntity<String> getBegSeedSubmissions(
+        @RequestParam("begid") String begid
+    ) {
+        try {
+            if (begid == null || begid.trim().isEmpty()) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.BAD_REQUEST); // 返回 400 表示参数不完整
+            }
+
+            SeedWithVotes[] submissionsWithVotes = db1.GetBegSeedListWithVotes(begid);
+            if (submissionsWithVotes == null) {
+                return new ResponseEntity<>("[]", errorHeaders, HttpStatus.NOT_FOUND); // 返回 404 表示未找到提交记录
+            }
+
+            String json = mapper.writeValueAsString(submissionsWithVotes);
+            return new ResponseEntity<>(json, headers, HttpStatus.OK);
+        } catch (JsonProcessingException e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 500 表示处理失败
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>("[]", errorHeaders, HttpStatus.INTERNAL_SERVER_ERROR);
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> submitSeed(
+        @RequestBody String requestBody
+    ) {
+        try {
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode begidNode = jsonNode.get("begid");
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode seedidNode = jsonNode.get("seedid");
+            
+            if (begidNode == null || useridNode == null || seedidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            String begid = begidNode.asText();
+            String userid = useridNode.asText();
+            String seedid = seedidNode.asText();
+
+            if (begid == null || begid.trim().isEmpty() || 
+                userid == null || userid.trim().isEmpty() || 
+                seedid == null || seedid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            int ret = db1.SubmitBegSeed(begid, seedid, userid);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(1, HttpStatus.CONFLICT); // 返回 1 表示提交失败或其他错误
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> voteSeed(
+        @RequestBody String requestBody
+    ) {
+        try {
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode begidNode = jsonNode.get("begid");
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode seedidNode = jsonNode.get("seedid");
+
+            if (begidNode == null || useridNode == null || seedidNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            String begid = begidNode.asText();
+            String userid = useridNode.asText();
+            String seedid = seedidNode.asText();
+
+            if (begid == null || begid.trim().isEmpty() || 
+                userid == null || userid.trim().isEmpty() || 
+                seedid == null || seedid.trim().isEmpty()) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            int ret = db1.VoteSeed(begid, seedid, userid);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(3, HttpStatus.CONFLICT); // 返回 1 表示投票失败或其他错误
+            } else {
+                return new ResponseEntity<>(2, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        }
+    }
+
+    @Override
+    @CrossOrigin(origins = "*", allowedHeaders = "*")
+    public ResponseEntity<Integer> createBegSeed(
+        @RequestBody String requestBody
+    ) {
+        try {
+            com.fasterxml.jackson.databind.JsonNode jsonNode = mapper.readTree(requestBody);
+            com.fasterxml.jackson.databind.JsonNode useridNode = jsonNode.get("userid");
+            com.fasterxml.jackson.databind.JsonNode infoNode = jsonNode.get("info");
+            com.fasterxml.jackson.databind.JsonNode rewardNode = jsonNode.get("reward_magic");
+            com.fasterxml.jackson.databind.JsonNode dedlineNode = jsonNode.get("deadline");
+
+            if (useridNode == null || infoNode == null || rewardNode == null || dedlineNode == null) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            String userid = useridNode.asText();
+            String info = infoNode.asText();
+
+            if (userid == null || userid.trim().isEmpty() ||
+                info == null || info.trim().isEmpty() ||
+                rewardNode.asInt() <= 0 ){
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 参数不完整
+            }
+
+            // 解析日期字符串
+            Date endTime;
+            try {
+                String deadlineStr = dedlineNode.asText();
+                SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
+                endTime = dateFormat.parse(deadlineStr);
+            } catch (ParseException e) {
+                return new ResponseEntity<>(1, HttpStatus.BAD_REQUEST); // 日期格式错误
+            }
+
+            BegInfo beg = new BegInfo();
+            beg.begid = java.util.UUID.randomUUID().toString();
+            beg.begnumbers = 0; // 初始提交数为0
+            beg.magic = rewardNode.asInt();
+            beg.endtime = endTime;
+            beg.hasseed = 0; // 初始状态为未开始
+
+            // int ret = db1.AddBegSeed(beg);
+            int ret = db1.createBagSeed(beg, userid, info);
+            if (ret == 0) {
+                return new ResponseEntity<>(0, HttpStatus.OK); // 返回 0 表示成功
+            } else if (ret == 1) {
+                return new ResponseEntity<>(2, HttpStatus.CONFLICT); // 返回 1 表示创建失败或其他错误
+            } else {
+                return new ResponseEntity<>(3, HttpStatus.INTERNAL_SERVER_ERROR); // 返回其他状态表示失败
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return new ResponseEntity<>(1, HttpStatus.INTERNAL_SERVER_ERROR); // 返回 1 表示处理失败
+        }
+    }
 }
\ No newline at end of file
diff --git a/src/main/java/api/ApiInterface.java b/src/main/java/api/ApiInterface.java
index 2d79fa7..475b5d2 100644
--- a/src/main/java/api/ApiInterface.java
+++ b/src/main/java/api/ApiInterface.java
@@ -101,4 +101,126 @@
     ResponseEntity<String> getUserPT(
         @RequestParam("userid") String userid
     );
+
+    @GetMapping("/admin/config")
+    ResponseEntity<String> getConfig(
+        @RequestParam("userid") String userid
+    );
+
+    @GetMapping("/admin/cheat-users")
+    ResponseEntity<String> getCheatUsers(
+        @RequestParam("userid") String userid
+    );
+
+    @GetMapping("/admin/suspicious-users")
+    ResponseEntity<String> getSuspiciousUsers(
+        @RequestParam("userid") String userid
+    );
+
+    @PostMapping("/admin/unban-user")
+    ResponseEntity<Integer> unbanUser(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/admin/ban-user")
+    ResponseEntity<Integer> banUser(
+        @RequestBody String requestBody
+    );
+
+    @GetMapping("/appeals")
+    ResponseEntity<String> getAppeals();
+
+    @GetMapping("/migrations")
+    ResponseEntity<String> getMigrations();
+
+    @PostMapping("/appeals-approve")
+    ResponseEntity<Integer> approveAppeal(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/appeals-reject")
+    ResponseEntity<Integer> rejectAppeal(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/migrations-approve")
+    ResponseEntity<Integer> approveMigration(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/migrations-reject")
+    ResponseEntity<Integer> rejectMigration(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/invite")
+    ResponseEntity<Integer> inviteUser(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/submit-appeal")
+    ResponseEntity<Integer> submitAppeal(
+        @RequestParam("userid") String userid,
+        @RequestParam("content") String content,
+        @RequestParam("file") MultipartFile file
+    );
+    
+    @GetMapping("/user-stats")
+    ResponseEntity<String> getUserStats(
+        @RequestParam("userid") String userid
+    );
+
+    @PostMapping("/exchange")
+    ResponseEntity<Integer> magicExchange(
+        @RequestBody String requestBody
+    );
+
+    @GetMapping("/user-favorites")
+    ResponseEntity<String> getUserFavorites(
+        @RequestParam("userid") String userid
+    );
+
+    @PostMapping("/remove-favorite")
+    ResponseEntity<Integer> removeFavorite(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/add-favorite")
+    ResponseEntity<Integer> addFavorite(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/migrate-account")
+    ResponseEntity<Integer> migrateAccount(
+        @RequestParam("userid") String userid,
+        @RequestParam("file") MultipartFile file
+    );
+
+    @GetMapping("/begseed-list")
+    ResponseEntity<String> getBegSeedList();
+
+    @GetMapping("/begseed-detail")
+    ResponseEntity<String> getBegSeedDetail(
+        @RequestParam("begid") String begid
+    );
+
+    @GetMapping("/begseed-submissions")
+    ResponseEntity<String> getBegSeedSubmissions(
+        @RequestParam("begid") String begid
+    );
+
+    @PostMapping("/submit-seed")
+    ResponseEntity<Integer> submitSeed(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/vote-seed")
+    ResponseEntity<Integer> voteSeed(
+        @RequestBody String requestBody
+    );
+
+    @PostMapping("/create-begseed")
+    ResponseEntity<Integer> createBegSeed(
+        @RequestBody String requestBody
+    );
 }
\ No newline at end of file