修改cheat文件

Change-Id: I0ffce820f7ff78b6fe5b9a714baf17814636dc19

API修改

Change-Id: I63a5b9752afcfe6f8088d2cfc065b385ee2a4464

merge

Change-Id: I783bc0349b858b16bccd1ec21623182239170df2

修改cheat文件

Change-Id: I0ffce820f7ff78b6fe5b9a714baf17814636dc19

merge

Change-Id: I783bc0349b858b16bccd1ec21623182239170df2

修改cheat文件

Change-Id: I0ffce820f7ff78b6fe5b9a714baf17814636dc19

merge

Change-Id: I783bc0349b858b16bccd1ec21623182239170df2

合并API代码

Change-Id: I5ac299271c14d247413d78b5da51adc28977e05d
diff --git a/src/main/java/api/ApiApplication.java b/src/main/java/api/ApiApplication.java
new file mode 100644
index 0000000..93eb640
--- /dev/null
+++ b/src/main/java/api/ApiApplication.java
@@ -0,0 +1,11 @@
+package api;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ApiApplication {
+    public static void main(String[] args) {
+        SpringApplication.run(ApiApplication.class, args);
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/api/ApiController.java b/src/main/java/api/ApiController.java
new file mode 100644
index 0000000..a683b0e
--- /dev/null
+++ b/src/main/java/api/ApiController.java
@@ -0,0 +1,78 @@
+package api;
+
+import java.io.File;
+
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import database.Database1;
+import entity.Seed;
+import tracker.Tracker;
+
+@RestController
+public class ApiController implements ApiInterface {
+
+    private static Database1 db;
+
+    private static Tracker tracker;
+
+    @Override
+    public ResponseEntity<Integer> saveTorrent(
+        @RequestParam("userid") String userid,
+        @RequestParam("title") String title,
+        @RequestParam("tag") String tag,
+        @RequestParam("file") MultipartFile file
+    ) {
+        try {
+            Seed seed = new Seed();
+            seed.seedid = "exampleSeedId"; // 示例种子ID
+            seed.seeduserid = userid; // 示例用户ID
+            seed.title = title; // 示例标题
+            seed.seedsize = "1GB"; // 示例种子大小
+            seed.seedtag = tag; // 示例标签
+            seed.url = "http://example.com/torrent"; // 示例URL
+            db = new Database1();
+            tracker = new Tracker();
+            int ret = db.RegisterSeed(seed);
+            System.out.println("RegisterSeed ret: " + ret);
+            System.out.println(seed.seedid + " " + seed.seeduserid + " " + seed.title + " " + seed.seedsize + " " + seed.seedtag + " " + seed.url);
+            // Convert MultipartFile to File
+            File tempFile = File.createTempFile(seed.seedid, file.getOriginalFilename());
+            file.transferTo(tempFile);
+            tracker.SaveTorrent(seed.seedid, tempFile);
+            // Optionally, delete the temp file after saving if not needed
+            // tempFile.delete();
+            return ResponseEntity.ok(0); // 返回 0 表示成功
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseEntity.status(500).body(1); // 返回 1 表示失败
+        }
+    }
+
+    @Override
+    public ResponseEntity<Resource> getTorrent(
+        @RequestParam("seedid") String seedid,
+        @RequestParam("userid") String userid,
+        @RequestParam("ip") String ip
+    ) {
+        // 实现获取种子文件的逻辑
+        // 示例:从本地目录中查找文件
+        tracker = new Tracker();
+        File file = tracker.GetTTorent(seedid, userid, ip);
+        if (file != null) {
+            FileSystemResource resource = new FileSystemResource(file);
+            return ResponseEntity.ok()
+                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"")
+                .contentType(MediaType.APPLICATION_OCTET_STREAM)
+                .body(resource);
+        } else {
+            return ResponseEntity.notFound().build(); // 返回 404 表示文件未找到
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/main/java/api/ApiInterface.java b/src/main/java/api/ApiInterface.java
index 495226d..ab3408c 100644
--- a/src/main/java/api/ApiInterface.java
+++ b/src/main/java/api/ApiInterface.java
@@ -1,5 +1,30 @@
 package api;
 
+import org.springframework.core.io.Resource;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+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 org.springframework.web.multipart.MultipartFile;
+
+@RestController
+@RequestMapping("/api")
 public interface ApiInterface {
-    
+
+    @PostMapping("/save-torrent")
+    ResponseEntity<Integer> saveTorrent(
+        @RequestParam("userid") String userid,
+        @RequestParam("title") String title,
+        @RequestParam("tag") String tag,
+        @RequestParam("file") MultipartFile file
+    );
+
+    @GetMapping("/get-torrent")
+    ResponseEntity<Resource> getTorrent(
+        @RequestParam("seedid") String seedid,
+        @RequestParam("userid") String userid,
+        @RequestParam("ip") String ip
+    );
 }
\ No newline at end of file
diff --git a/src/main/java/cheat/Cheat.java b/src/main/java/cheat/Cheat.java
index 270f2fd..3eecaff 100644
--- a/src/main/java/cheat/Cheat.java
+++ b/src/main/java/cheat/Cheat.java
@@ -1,14 +1,11 @@
 package cheat;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.persistence.EntityTransaction;
+import javax.persistence.PersistenceContext;
+import javax.transaction.Transactional;
 
 import org.apache.commons.lang3.tuple.Pair;
 
@@ -22,138 +19,94 @@
 
 public class Cheat implements CheatInterfnterface {
 
-    private EntityManagerFactory emf;
-
-    public Cheat() {
-        config cfg = new config();
-        Map<String, Object> props = new HashMap<>();
-        props.put("javax.persistence.jdbc.url",
-                "jdbc:mysql://" + cfg.SqlURL + "/" + cfg.Database);
-        props.put("javax.persistence.jdbc.user", cfg.SqlUsername);
-        props.put("javax.persistence.jdbc.password", cfg.SqlPassword);
-        this.emf = Persistence.createEntityManagerFactory("myPersistenceUnit", props);
-    }
-
-    // 测试时注入
-    public Cheat(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-
-    private EntityManager getEntityManager() {
-        return emf.createEntityManager();
-    }
+    @PersistenceContext
+    private EntityManager entityManager;
 
     @Override
+    @Transactional
     public boolean AddAppeal(Appeal appeal) {
-        EntityManager em = getEntityManager();
-        EntityTransaction tx = em.getTransaction();
         try {
-            tx.begin();
-            em.persist(appeal);
-            tx.commit();
+            entityManager.persist(appeal);
         } catch (Exception e) {
-            if (tx.isActive()) {
-                tx.rollback();
-            }
             e.printStackTrace();
             return false;
-        } finally {
-            em.close();
         }
         return true;
     }
 
     @Override
     public Appeal GetAppeal(String appealid) {
-        EntityManager em = getEntityManager();
         try {
-            JPAQueryFactory queryFactory = new JPAQueryFactory(em);
+            JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
             QAppeal qAppeal = QAppeal.appeal;
             Appeal appeal = queryFactory
-                    .selectFrom(qAppeal)
-                    .where(qAppeal.appealid.eq(appealid))
-                    .fetchOne();
+                .selectFrom(qAppeal)
+                .where(qAppeal.appealid.eq(appealid))
+                .fetchOne();
             return appeal;
         } catch (Exception e) {
             e.printStackTrace();
             return null;
-        } finally {
-            em.close();
         }
     }
 
     @Override
     public Appeal[] GetAppealList() {
-        EntityManager em = getEntityManager();
         try {
-            JPAQueryFactory queryFactory = new JPAQueryFactory(em);
+            JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
             QAppeal qAppeal = QAppeal.appeal;
             List<Appeal> appeals = queryFactory
-                    .selectFrom(qAppeal)
-                    .fetch();
+                .selectFrom(qAppeal)
+                .fetch();
             return appeals.toArray(new Appeal[0]);
         } catch (Exception e) {
             e.printStackTrace();
             return null;
-        } finally {
-            em.close();
         }
     }
 
     @Override
     public boolean HandleAppeal(String appealid, Integer status) {
-        EntityManager em = getEntityManager();
-        EntityTransaction tx = em.getTransaction();
         try {
-            tx.begin();
-            Appeal appeal = em.find(Appeal.class, appealid);
+            Appeal appeal = GetAppeal(appealid);
             if (appeal != null) {
                 appeal.status = status;
-                em.merge(appeal);
-                User user = em.find(User.class, appeal.appealuserid);
+                entityManager.merge(appeal);
+                User user = entityManager.find(User.class, appeal.appealuserid);
                 if (user != null && user.accountstate != false) {
                     if (status == 1) {
                         user.accountstate = false;
                     }
-                    em.merge(user);
+                    entityManager.merge(user);
                 }
-                tx.commit();
                 return true;
             }
             return false;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
-        } finally {
-            if (tx.isActive()) {
-                tx.rollback();
-            }
-            em.close();
         }
     }
 
     @Override
     public Pair<String, String>[] GetFakeSeed() {
         List<Pair<String, String>> fakeSeeds = new ArrayList<>();
-        EntityManager em = getEntityManager();
         try {
-            JPAQueryFactory queryFactory = new JPAQueryFactory(em);
+            JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
             QSeed qSeed = QSeed.seed;
             List<com.querydsl.core.Tuple> results = queryFactory
-                    .select(qSeed.seedid, qSeed.seeduserid)
-                    .from(qSeed)
-                    .where(qSeed.faketime.gt(new config().FakeTime))
-                    .fetch();
+                .select(qSeed.seedid, qSeed.seeduserid)
+                .from(qSeed)
+                .where(qSeed.faketime.gt(new config().FakeTime))
+                .fetch();
             for (com.querydsl.core.Tuple result : results) {
                 String seedid = result.get(qSeed.seedid);
-                String userid  = result.get(qSeed.seeduserid);
+                String userid = result.get(qSeed.seeduserid);
                 fakeSeeds.add(Pair.of(seedid, userid));
             }
         } catch (Exception e) {
             e.printStackTrace();
             return null;
-        } finally {
-            em.close();
         }
         return fakeSeeds.toArray(new Pair[0]);
     }
@@ -161,23 +114,20 @@
     @Override
     public String[] GetPunishedUserList() {
         List<String> punishedUsers = new ArrayList<>();
-        EntityManager em = getEntityManager();
         try {
-            JPAQueryFactory queryFactory = new JPAQueryFactory(em);
+            JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
             entity.QUser qUser = entity.QUser.user;
             List<String> results = queryFactory
-                    .select(qUser.userid)
-                    .from(qUser)
-                    .where(qUser.accountstate.isTrue())
-                    .fetch();
+                .select(qUser.userid)
+                .from(qUser)
+                .where(qUser.accountstate.isTrue())
+                .fetch();
             for (String userid : results) {
                 punishedUsers.add(userid);
             }
         } catch (Exception e) {
             e.printStackTrace();
             return null;
-        } finally {
-            em.close();
         }
         return punishedUsers.toArray(new String[0]);
     }
@@ -198,17 +148,21 @@
 
         //     int n = tasks.size();
         //     if (n == 0) continue;
+
         //     double[] xArr = new double[n];
         //     for (int i = 0; i < n; i++) {
         //         TransRecord t = tasks.get(i);
         //         xArr[i] = Math.max(0, t.upload - t.download);
         //     }
+
         //     double sum = 0;
         //     for (double x : xArr) sum += x;
         //     double mu = sum / n;
+
         //     double sqSum = 0;
         //     for (double x : xArr) sqSum += (x - mu) * (x - mu);
         //     double sigma = Math.sqrt(sqSum / n);
+
         //     for (int i = 0; i < n; i++) {
         //         if (Math.abs(xArr[i] - mu) > 3 * sigma) {
         //             User user = entityManager.find(User.class, tasks.get(i).downloaduserid);
@@ -223,37 +177,27 @@
     }
 
     @Override
-    public void DetectFakeSeed() {
+    public void DetectFakeSeed(){
     }
 
     @Override
-    public boolean DetectFakeSeed(String seedid) {
+    public boolean DetectFakeSeed(String seedid){
         return false;
     }
 
     @Override
-    public void PunishUser() {
-        EntityManager em = getEntityManager();
-        EntityTransaction tx = em.getTransaction();
-        try {
-            tx.begin();
-            JPAQueryFactory queryFactory = new JPAQueryFactory(em);
-            entity.QUser qUser = entity.QUser.user;
-            List<User> users = queryFactory
-                    .selectFrom(qUser)
-                    .where(qUser.detectedCount.gt(new entity.config().CheatTime)
-                            .or(qUser.fakeDetectedCount.gt(new entity.config().FakeTime)))
-                    .fetch();
+    public void PunishUser(){
+        JPAQueryFactory queryFactory = new JPAQueryFactory(entityManager);
+        entity.QUser qUser = entity.QUser.user;
+        List<User> users = queryFactory
+            .selectFrom(qUser)
+            .where(qUser.detectedCount.gt(new entity.config().CheatTime) 
+                .or(qUser.fakeDetectedCount.gt(new entity.config().FakeTime)))
+            .fetch();
 
-            for (User user : users) {
-                user.accountstate = true;
-                em.merge(user);
-            }
-            tx.commit();
-        } catch (Exception e) {
-            if (tx.isActive()) tx.rollback();
-        } finally {
-            em.close();
+        for (User user : users) {
+            user.accountstate = true;
+            entityManager.merge(user);
         }
     }
-}
+}
\ No newline at end of file
diff --git a/src/main/java/database/Database1.java b/src/main/java/database/Database1.java
index 766c90a..f835288 100644
--- a/src/main/java/database/Database1.java
+++ b/src/main/java/database/Database1.java
@@ -5,7 +5,7 @@
 import java.util.Map;
 
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceContext;
 import javax.persistence.Persistence;
 
 import com.querydsl.jpa.impl.JPAQuery;
@@ -23,68 +23,55 @@
 import entity.User;
 import entity.UserPT;
 import entity.UserStar;
+import entity.config;
 
 public class Database1 implements DataManagerInterface {
-
-    private EntityManagerFactory emf;
+    @PersistenceContext
+    private final EntityManager entitymanager;
 
     public Database1() {
-        entity.config cfg = new entity.config();
-        Map<String, Object> props = new HashMap<>();
-        props.put("javax.persistence.jdbc.url", "jdbc:mysql://" + cfg.SqlURL + "/" + cfg.Database);
+        config cfg = new config();
+        Map<String,Object> props = new HashMap<>();
+        props.put("javax.persistence.jdbc.url",
+                  "jdbc:mysql://" + cfg.SqlURL + "/" + cfg.Database);
         props.put("javax.persistence.jdbc.user", cfg.SqlUsername);
         props.put("javax.persistence.jdbc.password", cfg.SqlPassword);
-        this.emf = Persistence.createEntityManagerFactory("myPersistenceUnit", props);
-    }
-
-    // 方便测试时注入
-    public Database1(EntityManagerFactory emf) {
-        this.emf = emf;
-    }
-
-    private EntityManager getEntityManager() {
-        return emf.createEntityManager();
+        this.entitymanager = Persistence.createEntityManagerFactory("myPersistenceUnit", props).createEntityManager();
     }
 
     // 返回状态:0 success,1 邮箱重复,2其他原因
     @Override
-    public int RegisterUser(User userinfo) {
-        EntityManager em = getEntityManager();
-        try {
-            JPAQuery<String> query = new JPAQuery<>(em);
+    public int RegisterUser(User userinfo){
+        try{
+            JPAQuery<String> query = new JPAQuery<>(entitymanager);
             QUser u = QUser.user;
             List<String> allEmails = query.select(u.email).from(u).fetch();
 
-            if (allEmails.contains(userinfo.email)) {
+            if(allEmails.contains(userinfo.email)){
                 return 1;
             }
-            em.getTransaction().begin();
-            em.persist(userinfo);
-            em.getTransaction().commit();
+            entitymanager.persist(userinfo);
             return 0;
 
-        } catch (Exception e) {
+        }catch(Exception e){
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     // 返回状态:0 success,1 不存在,2其他原因
     @Override
-    public int UpdateInformation(User userinfo) {
-        EntityManager em = getEntityManager();
+    public int UpdateInformation(User userinfo){
         try {
             if (userinfo.userid == null) {
                 return 2; // userid为null直接返回错误
             }
-            JPAQuery<User> query = new JPAQuery<>(em);
+            JPAQuery<User> query = new JPAQuery<>(entitymanager);
             QUser u = QUser.user;
             User updateUser = query.select(u).from(u).where(u.userid.eq(userinfo.userid)).fetchOne();
 
-            if (updateUser == null) {
+            if(updateUser == null){
                 return 1;
             }
             // 只更新需要的字段,避免破坏持久化状态和关联关系
@@ -98,305 +85,242 @@
             updateUser.accountstate = userinfo.accountstate;
             updateUser.invitetimes = userinfo.invitetimes;
             // 如有其他字段也一并赋值
-            em.getTransaction().begin();
-            em.merge(updateUser);
-            em.getTransaction().commit();
+            entitymanager.merge(updateUser);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     // 返回用户的全部基本信息
     @Override
-    public User GetInformation(String userid) {
-        EntityManager em = getEntityManager();
-        try {
-            User user = em.find(User.class, userid);
-            return user;
-        } finally {
-            em.close();
-        }
+    public User GetInformation(String userid){
+        User user = entitymanager.find(User.class, userid);
+        return user;
     }
 
     //返回用户的全部pt站信息
     @Override
-    public UserPT GetInformationPT(String userid) {
-        EntityManager em = getEntityManager();
-        try {
-            UserPT userPT = em.find(UserPT.class, userid);
-            return userPT;
-        } finally {
-            em.close();
-        }
+    public UserPT GetInformationPT(String userid){
+        UserPT userPT = entitymanager.find(UserPT.class, userid);
+        return userPT;
     }
 
     //返回状态:0 success,1 邮箱重复,2其他原因
     @Override
-    public int UpdateInformationPT(UserPT userinfo) {
-        EntityManager em = getEntityManager();
-        try {
-            JPAQuery<UserPT> query = new JPAQuery<>(em);
+    public int UpdateInformationPT(UserPT userinfo){
+        try{
+            JPAQuery<UserPT> query = new JPAQuery<>(entitymanager);
             QUserPT u = QUserPT.userPT;
             UserPT userPT = query.select(u).from(u).where(u.userid.eq(userinfo.userid)).fetchOne();
-
-            if (userPT == null) {
+        
+            if(userPT == null){
                 return 1;
             }
             userPT = userinfo;
-            em.getTransaction().begin();
-            em.merge(userPT);
-            em.getTransaction().commit();
+            entitymanager.merge(userPT);
             return 0;
 
-        } catch (Exception e) {
+        }catch(Exception e){
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
     }
 
     //返回状态:0 success,1 id重复,2其他原因
     @Override
-    public int RegisterUserPT(UserPT userinfo) {
-        EntityManager em = getEntityManager();
+    public int RegisterUserPT(UserPT userinfo){
         try {
-            JPAQuery<UserPT> query = new JPAQuery<>(em);
+            JPAQuery<UserPT> query = new JPAQuery<>(entitymanager);
             QUserPT u = QUserPT.userPT;
             UserPT checkUserPT = query.select(u).from(u).where(u.userid.eq(userinfo.userid)).fetchOne();
             if (checkUserPT != null) {
                 return 1;
             }
-            em.getTransaction().begin();
-            em.persist(userinfo);
-            em.getTransaction().commit();
+            entitymanager.persist(userinfo);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
     }
 
     //返回种子的全部信息
     @Override
-    public Seed GetSeedInformation(String seedid) {
-        EntityManager em = getEntityManager();
-        try {
-            JPAQuery<Seed> query = new JPAQuery<>(em);
-            QSeed s = QSeed.seed;
-            Seed seed = query.select(s).from(s).where(s.seedid.eq(seedid)).fetchOne();
-            return seed;
-        } finally {
-            em.close();
-        }
+    public Seed GetSeedInformation(String seedid){
+        JPAQuery<Seed> query = new JPAQuery<>(entitymanager);
+        QSeed s = QSeed.seed;
+        Seed seed = query.select(s).from(s).where(s.seedid.eq(seedid)).fetchOne();
+        return seed;
     }
 
     //添加一个新的种子,0成功,其他失败信息待定;
     @Override
-    public int RegisterSeed(Seed seedinfo) {
-        EntityManager em = getEntityManager();
+    public int RegisterSeed(Seed seedinfo){
         try {
-            JPAQuery<Seed> query = new JPAQuery<>(em);
+            JPAQuery<Seed> query = new JPAQuery<>(entitymanager);
             QSeed s = QSeed.seed;
             Seed seed = query.select(s).from(s).where(s.seedid.eq(seedinfo.seedid)).fetchOne();
             if (seed != null) {
                 return 1;
             }
-            em.getTransaction().begin();
-            em.persist(seedinfo);
-            em.getTransaction().commit();
+            entitymanager.persist(seedinfo);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
     }
 
     //接收新的种子然后更新其全部属性
     @Override
-    public int UpdateSeed(Seed seedinfo) {
-        EntityManager em = getEntityManager();
+    public int UpdateSeed(Seed seedinfo){
         try {
-            JPAQuery<Seed> query = new JPAQuery<>(em);
+            JPAQuery<Seed> query = new JPAQuery<>(entitymanager);
             QSeed s = QSeed.seed;
             Seed seed = query.select(s).from(s).where(s.seedid.eq(seedinfo.seedid)).fetchOne();
             if (seed == null) {
                 return 1;
             }
             seed = seedinfo;
-            em.getTransaction().begin();
-            em.merge(seed);
-            em.getTransaction().commit();
+            entitymanager.merge(seed);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
     }
 
     //传入搜索的关键词或句子,返回搜索到的种子信息(按照公共字符数量排序)
     @Override
-    public Seed[] SearchSeed(String userQ) {
-        EntityManager em = getEntityManager();
-        try {
-            JPAQuery<Seed> query = new JPAQuery<>(em);
-            QSeed s = QSeed.seed;
-            List<Seed> seeds = query.select(s).from(s).fetch();
+    public Seed[] SearchSeed(String userQ){
+        JPAQuery<Seed> query = new JPAQuery<>(entitymanager);
+        QSeed s = QSeed.seed;
+        List<Seed> seeds = query.select(s).from(s).fetch();
 
-            if (seeds == null || userQ == null || userQ.trim().isEmpty()) {
-                return seeds.toArray(new Seed[0]);
-            }
-
-            String processedQuery = userQ.toLowerCase().trim();
-            Map<Seed, Integer> seedCountMap = new HashMap<>();
-            for (Seed seed : seeds) {
-                String title = seed.title.toLowerCase().trim();
-                int count = countCommonCharacter(processedQuery, title);
-                seedCountMap.put(seed, count);
-            }
-            seeds.sort((s1, s2) -> {
-                int count1 = seedCountMap.getOrDefault(s1, 0);
-                int count2 = seedCountMap.getOrDefault(s2, 0);
-                return Integer.compare(count2, count1);
-            });
-
+        if (seeds == null || userQ == null || userQ.trim().isEmpty()) {
             return seeds.toArray(new Seed[0]);
-        } finally {
-            em.close();
         }
+
+        String processedQuery = userQ.toLowerCase().trim();
+        Map<Seed, Integer> seedCountMap = new HashMap<>();
+        for(Seed seed : seeds){
+            String title = seed.title.toLowerCase().trim();
+            int count = countCommonCharacter(processedQuery, title);
+            seedCountMap.put(seed, count);
+        }
+        seeds.sort((s1, s2) -> {
+            int count1 = seedCountMap.getOrDefault(s1, 0);
+            int count2 = seedCountMap.getOrDefault(s2, 0);
+            return Integer.compare(count2, count1);
+        });
+
+        return seeds.toArray(new Seed[0]);
     }
 
     //计算字符串公共字符数量
-    private int countCommonCharacter(String str1, String str2) {
+    private int countCommonCharacter(String str1, String str2){
         Map<Character, Integer> map1 = new HashMap<>();
         Map<Character, Integer> map2 = new HashMap<>();
 
-        for (char c : str1.toCharArray()) {
+        for(char c : str1.toCharArray()){
             if (!Character.isWhitespace(c)) {
                 map1.put(c, map1.getOrDefault(c, 0) + 1);
             }
         }
 
-        for (char c : str2.toCharArray()) {
+        for(char c : str2.toCharArray()){
             if (!Character.isWhitespace(c)) {
                 map2.put(c, map2.getOrDefault(c, 0) + 1);
             }
         }
 
         int res = 0;
-        for (char c : map1.keySet()) {
+        for(char c : map1.keySet()){
             if (map2.containsKey(c)) {
                 res += Math.min(map1.get(c), map2.get(c));
             }
-
+            
         }
         return res;
     }
 
     //返回状态:0 success,1 重复,2其他原因
     @Override
-    public int AddNotice(Notice notice) {
-        EntityManager em = getEntityManager();
+    public int AddNotice(Notice notice){
         try {
-            JPAQuery<Notice> query = new JPAQuery<>(em);
+            JPAQuery<Notice> query = new JPAQuery<>(entitymanager);
             QNotice n = QNotice.notice;
             Notice checkNotice = query.select(n).from(n).where(n.noticeid.eq(notice.noticeid)).fetchOne();
             if (checkNotice != null) {
                 return 1;
             }
-
-            em.getTransaction().begin();
-            em.persist(notice);
-            em.getTransaction().commit();
+            
+            entitymanager.persist(notice);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     //返回状态:0 success,1 不存在,2其他原因
     @Override
-    public boolean UpdateNotice(Notice notice) {
-        EntityManager em = getEntityManager();
+    public boolean UpdateNotice(Notice notice){
         try {
-            Notice oldNotice = em.find(Notice.class, notice.noticeid);
+            Notice oldNotice = entitymanager.find(Notice.class, notice.noticeid);
             if (oldNotice == null) {
                 return false;
             }
             oldNotice = notice;
-            em.getTransaction().begin();
-            em.merge(oldNotice);
-            em.getTransaction().commit();
+            entitymanager.merge(oldNotice);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
-        } finally {
-            em.close();
         }
     }
 
     //删除公告,返回状态:0 success,1 不存在,2其他原因
     @Override
-    public boolean DeleteNotice(String noticeid) {
-        EntityManager em = getEntityManager();
+    public boolean DeleteNotice(String noticeid){
         try {
-            Notice notice = em.find(Notice.class, noticeid);
+            Notice notice = entitymanager.find(Notice.class, noticeid);
             if (notice == null) {
                 return false;
             }
-            em.getTransaction().begin();
-            em.remove(notice);
-            em.getTransaction().commit();
+            entitymanager.remove(notice);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     //获取用户的剩余邀请次数
-    public int GetUserAvailableInviteTimes(String userid) {
-        EntityManager em = getEntityManager();
+    public int GetUserAvailableInviteTimes(String userid){
         try {
-            JPAQuery<Integer> query = new JPAQuery<>(em);
+            JPAQuery<Integer> query = new JPAQuery<>(entitymanager);
             QUser u = QUser.user;
             int invite_left = query.select(u.invitetimes).from(u).where(u.userid.eq(userid)).fetchOne();
-
+            
             return invite_left;
         } catch (Exception e) {
             e.printStackTrace();
             return -1;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     //邀请用户,返回状态:0 success,1 剩余次数不足,2,3其他原因
     @Override
-    public int InviteUser(String inviterid, String inviteemail) {
-        EntityManager em = getEntityManager();
+    public int InviteUser(String inviterid,String inviteemail){
         try {
-            User user = em.find(User.class, inviterid);
+            User user = entitymanager.find(User.class, inviterid);
             if (user == null || !user.email.equals(inviteemail)) {
                 return 3;
             }
@@ -404,176 +328,158 @@
                 return 1;
             }
             user.invitetimes -= 1;
-            em.getTransaction().begin();
-            em.merge(user);
-            em.getTransaction().commit();
+            entitymanager.merge(user);
             return 0;
         } catch (Exception e) {
             e.printStackTrace();
             return 2;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     //添加一个收藏,返回状态:0 success,1 不存在,2其他原因
     @Override
-    public boolean AddCollect(String userid, String seedid) {
-        EntityManager em = getEntityManager();
-        try {
-            JPAQuery<User> query2 = new JPAQuery<>(em);
-            QUser u2 = QUser.user;
-            User user = query2.select(u2).from(u2).where(u2.userid.eq(userid)).fetchOne();
-            if (user == null) {
-                return false;
-            }
-            JPAQuery<Seed> query3 = new JPAQuery<>(em);
-            QSeed p = QSeed.seed;
-            Seed seed = query3.select(p).from(p).where(p.seedid.eq(seedid)).fetchOne();
-            if (seed == null) {
-                return false;
-            }
-            JPAQuery<String> query = new JPAQuery<>(em);
-            QUserStar u = QUserStar.userStar;
-            List<String> allSeedId = query.select(u.seedid).from(u).where(u.userid.eq(userid)).fetch();
-
-            if (allSeedId.contains(seedid)) {
-                return false;
-            }
-            UserStar userStar = new UserStar();
-            userStar.userid = userid;
-            userStar.seedid = seedid;
-            em.getTransaction().begin();
-            em.persist(userStar);
-            em.getTransaction().commit();
-            return true;
-        } catch (Exception e) {
-            e.printStackTrace();
+    public boolean AddCollect(String userid,String seedid){
+        JPAQuery<User> query2 = new JPAQuery<>(entitymanager);
+        QUser u2 = QUser.user;
+        User user = query2.select(u2).from(u2).where(u2.userid.eq(userid)).fetchOne();
+        if (user == null) {
             return false;
-        } finally {
-            em.close();
         }
+        JPAQuery<Seed> query3 = new JPAQuery<>(entitymanager);
+        QSeed p = QSeed.seed;
+        Seed seed = query3.select(p).from(p).where(p.seedid.eq(seedid)).fetchOne();
+        if (seed == null) {
+            return false;
+        }
+        JPAQuery<String> query = new JPAQuery<>(entitymanager);
+        QUserStar u = QUserStar.userStar;
+        List<String> allSeedId = query.select(u.seedid).from(u).where(u.userid.eq(userid)).fetch();
+
+        if (allSeedId.contains(seedid)) {
+            return false;
+        }
+        UserStar userStar = new UserStar();
+        userStar.userid = userid;
+        userStar.seedid = seedid;
+        entitymanager.persist(userStar);
+        return true;
     }
 
     //删除一个收藏,返回状态:0 success,1 不存在,2其他原因
     @Override
-    public boolean DeleteCollect(String userid, String seedid) {
-        EntityManager em = getEntityManager();
+    public boolean DeleteCollect(String userid,String seedid){
         try {
-            JPAQuery<UserStar> query = new JPAQuery<>(em);
+            JPAQuery<UserStar> query = new JPAQuery<>(entitymanager);
             QUserStar u = QUserStar.userStar;
             UserStar userStar = query.select(u).from(u).where(u.userid.eq(userid).and(u.seedid.eq(seedid))).fetchOne();
             if (userStar == null) {
                 return true; // 收藏不存在
             }
-            em.getTransaction().begin();
-            em.remove(userStar);
-            em.getTransaction().commit();
+            entitymanager.remove(userStar);
             return true;
         } catch (Exception e) {
             e.printStackTrace();
             return false;
-        } finally {
-            em.close();
         }
-
+        
     }
 
     @Override
-    public int AddBegSeed(BegInfo info) {
+    public int AddBegSeed(BegInfo info){
         return 0;
     }
 
     @Override
-    public int UpdateBegSeed(BegInfo info) {
+    public int UpdateBegSeed(BegInfo info){
         return 0;
     }
 
     @Override
-    public int DeleteBegSeed(String begid) {
+    public int DeleteBegSeed(String begid){
         return 0;
     }
 
     @Override
-    public int VoteSeed(String begId, String seedId, String userId) {
+    public int VoteSeed(String begId, String seedId, String userId){
         return 0;
     }
 
     @Override
-    public int SubmitSeed(String begid, Seed seed) {
+    public int SubmitSeed(String begid,Seed seed){
         return 0;
     }
 
     @Override
-    public void SettleBeg() {
-
+    public void SettleBeg(){
+        
     }
 
     @Override
-    public int AddPost(Post post) {
+    public int AddPost(Post post){
         return 0;
     }
 
     @Override
-    public int UpdatePost(Post post) {
+    public int UpdatePost(Post post){
         return 0;
     }
 
     @Override
-    public int DeletePost(String postid) {
+    public int DeletePost(String postid){
         return 0;
     }
 
     @Override
-    public int AddComment(String postid, String userid, String comment) {
+    public int AddComment(String postid, String userid, String comment){
         return 0;
     }
 
     @Override
-    public int DeleteComment(String postid, String commentid) {
+    public int DeleteComment(String postid,String commentid){
         return 0;
     }
 
     @Override
-    public boolean ExchangeMagicToUpload(String userid, int magic)//将魔力值兑换为上传量,返回状态:0 success,1 不存在,2其他原因
+    public boolean ExchangeMagicToUpload(String userid,int magic)//将魔力值兑换为上传量,返回状态:0 success,1 不存在,2其他原因
     {
         return true;
     }
-
+    
     @Override
-    public boolean ExchangeMagicToDownload(String userid, int magic) {
+    public boolean ExchangeMagicToDownload(String userid,int magic)
+    {
         return true;
     }//将魔力值兑换为下载量,返回状态:0 success,1 不存在,2其他原因
 
     @Override
-    public boolean ExchangeMagicToVip(String userid, int magic) {
+    public boolean ExchangeMagicToVip(String userid,int magic){
         return true;
     }
     //将魔力值兑换为VIP次数,返回状态:0 success,1 不存在,2其他原因
 
     @Override
-    public boolean UploadTransmitProfile(Profile profile) {
+    public boolean UploadTransmitProfile(Profile profile){
         return true;
     }
 
     @Override
-    public Profile GetTransmitProfile(String profileid) {
+    public Profile GetTransmitProfile(String profileid){
         Profile profile = new Profile();
         return profile;
     }
     //获取迁移信息
-
+    
     @Override
-    public boolean ExamTransmitProfile(String profileid, boolean result) {
+    public boolean ExamTransmitProfile(String profileid,boolean result){
         return true;
     }
-
     //审核迁移信息,0成功,1失败
     @Override
-    public Profile[] GetTransmitProfileList() {
+    public Profile[] GetTransmitProfileList(){
         return new Profile[0];
     }
     //获取所有迁移信息
 
 }
+
diff --git a/src/main/java/entity/config.java b/src/main/java/entity/config.java
index c509df3..ec4ab2e 100644
--- a/src/main/java/entity/config.java
+++ b/src/main/java/entity/config.java
@@ -8,7 +8,7 @@
     public static final int CheatTime=5;
     // 请根据实际环境修改为可达的地址
     public static final String SqlURL = "192.168.5.9:3306";
-    public static final String Database = "pt_database";
+    public static final String Database = "pt_database_test";
     public static final String TestDatabase = "pt_database_test";
     public static final String SqlPassword = "123456";
     public static final String SqlUsername = "root";
diff --git a/src/test/java/cheattest/cheatsystest.java b/src/test/java/cheattest/cheatsystest.java
index 98ebf73..4f3a035 100644
--- a/src/test/java/cheattest/cheatsystest.java
+++ b/src/test/java/cheattest/cheatsystest.java
@@ -30,7 +30,6 @@
 import entity.config;
 
 public class cheatsystest {
-
     private static EntityManagerFactory emf;
     private static EntityManager em;
     private static Cheat cheat;
@@ -44,15 +43,19 @@
         Map<String, Object> props = new HashMap<>();
         config cfg = new config();
         String jdbcUrl = String.format(
-                "jdbc:mysql://%s/%s?useSSL=false&serverTimezone=UTC",
-                cfg.SqlURL, cfg.TestDatabase);
+            "jdbc:mysql://%s/%s?useSSL=false&serverTimezone=UTC",
+            cfg.SqlURL, cfg.TestDatabase);
         props.put("javax.persistence.jdbc.url", jdbcUrl);
         props.put("javax.persistence.jdbc.user", cfg.SqlUsername);
         props.put("javax.persistence.jdbc.password", cfg.SqlPassword);
         props.put("javax.persistence.jdbc.driver", "com.mysql.cj.jdbc.Driver");
         emf = Persistence.createEntityManagerFactory("myPersistenceUnit", props);
         em = emf.createEntityManager();
-        cheat = new Cheat(emf);
+        cheat = new Cheat();
+        // 通过反射注入 entityManager
+        java.lang.reflect.Field f = Cheat.class.getDeclaredField("entityManager");
+        f.setAccessible(true);
+        f.set(cheat, em);
     }
 
     @AfterAll
@@ -85,7 +88,7 @@
         if (em != null && em.isOpen()) {
             em.getTransaction().begin();
             List<String> insertedUserIds = em.createQuery("SELECT u.userid FROM User u WHERE u.accountstate = true", String.class)
-                    .getResultList();
+                                             .getResultList();
             for (String userId : insertedUserIds) {
                 User user = em.find(User.class, userId);
                 if (user != null) {
@@ -96,58 +99,54 @@
         }
 
         // 关闭 EntityManager 和 EntityManagerFactory
-        if (em != null && em.isOpen()) {
-            em.close();
-        }
-        if (emf != null && emf.isOpen()) {
-            emf.close();
-        }
+        if (em != null && em.isOpen()) em.close();
+        if (emf != null && emf.isOpen()) emf.close();
     }
 
     @TestFactory
     Collection<DynamicTest> testAddAppeal() {
         // 查询数据库中已存在的一个用户
         String userId = em.createQuery("SELECT u.userid FROM User u", String.class)
-                .setMaxResults(1)
-                .getSingleResult();
+                          .setMaxResults(1)
+                          .getSingleResult();
 
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("AddAppeal test #" + i, () -> {
-            // 插入 Appeal
-            String appealId = UUID.randomUUID().toString();
-            Appeal appeal = new Appeal();
-            appeal.appealid = appealId;
-            appeal.appealuserid = userId;
-            appeal.content = "Test appeal content " + i;
-            appeal.fileURL = "http://example.com/file" + i;
-            appeal.status = 0;
+            .mapToObj(i -> DynamicTest.dynamicTest("AddAppeal test #" + i, () -> {
+                // 插入 Appeal
+                String appealId = UUID.randomUUID().toString();
+                Appeal appeal = new Appeal();
+                appeal.appealid = appealId;
+                appeal.appealuserid = userId;
+                appeal.content = "Test appeal content " + i;
+                appeal.fileURL = "http://example.com/file" + i;
+                appeal.status = 0;
 
-            em.getTransaction().begin();
-            boolean result = cheat.AddAppeal(appeal);
-            em.getTransaction().commit();
+                em.getTransaction().begin();
+                boolean result = cheat.AddAppeal(appeal);
+                em.getTransaction().commit();
 
-            Assertions.assertTrue(result, "AddAppeal 应返回 true");
+                Assertions.assertTrue(result, "AddAppeal 应返回 true");
 
-            // 验证 Appeal 是否插入
-            Appeal fetched = em.find(Appeal.class, appealId);
-            Assertions.assertNotNull(fetched, "数据库应能查到新插入的 Appeal");
-            Assertions.assertEquals(userId, fetched.appealuserid);
-            Assertions.assertEquals("Test appeal content " + i, fetched.content);
+                // 验证 Appeal 是否插入
+                Appeal fetched = em.find(Appeal.class, appealId);
+                Assertions.assertNotNull(fetched, "数据库应能查到新插入的 Appeal");
+                Assertions.assertEquals(userId, fetched.appealuserid);
+                Assertions.assertEquals("Test appeal content " + i, fetched.content);
 
-            // 清理
-            em.getTransaction().begin();
-            em.remove(fetched);
-            em.getTransaction().commit();
-        }))
-                .collect(Collectors.toList());
+                // 清理
+                em.getTransaction().begin();
+                em.remove(fetched);
+                em.getTransaction().commit();
+            }))
+            .collect(Collectors.toList());
     }
 
     @TestFactory
     Collection<DynamicTest> testGetAppeal() {
         // 查询数据库中已存在的10个Appeal
         List<Appeal> appeals = em.createQuery("SELECT a FROM Appeal a", Appeal.class)
-                .setMaxResults(10)
-                .getResultList();
+                             .setMaxResults(10)
+                             .getResultList();
 
         List<DynamicTest> tests = new ArrayList<>();
 
@@ -179,140 +178,140 @@
     Collection<DynamicTest> testGetAppealList() {
         // 查询数据库中已存在的一个用户
         String userId = em.createQuery("SELECT u.userid FROM User u", String.class)
-                .setMaxResults(1)
-                .getSingleResult();
+                      .setMaxResults(1)
+                      .getSingleResult();
         // 用于记录测试过程中插入的 Appeal ID
 
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("GetAppealList test #" + i, () -> {
-            // 插入一个新的 Appeal
-            String appealId = UUID.randomUUID().toString();
-            Appeal appeal = new Appeal();
-            appeal.appealid = appealId;
-            appeal.appealuserid = userId;
-            appeal.content = "GetAppealList test content " + i;
-            appeal.fileURL = "http://example.com/file" + i;
-            appeal.status = 0;
+            .mapToObj(i -> DynamicTest.dynamicTest("GetAppealList test #" + i, () -> {
+                // 插入一个新的 Appeal
+                String appealId = UUID.randomUUID().toString();
+                Appeal appeal = new Appeal();
+                appeal.appealid = appealId;
+                appeal.appealuserid = userId;
+                appeal.content = "GetAppealList test content " + i;
+                appeal.fileURL = "http://example.com/file" + i;
+                appeal.status = 0;
 
-            em.getTransaction().begin();
-            em.persist(appeal);
-            em.getTransaction().commit();
+                em.getTransaction().begin();
+                em.persist(appeal);
+                em.getTransaction().commit();
 
-            // 记录插入的 Appeal ID
-            insertedAppealIds.add(appealId);
+                // 记录插入的 Appeal ID
+                insertedAppealIds.add(appealId);
 
-            // 调用 GetAppealList 并验证
-            Appeal[] appeals = cheat.GetAppealList();
-            Assertions.assertNotNull(appeals, "GetAppealList 应返回非空");
+                // 调用 GetAppealList 并验证
+                Appeal[] appeals = cheat.GetAppealList();
+                Assertions.assertNotNull(appeals, "GetAppealList 应返回非空");
 
-            // 检查整个列表是否包含所有插入的数据
-            for (String id : insertedAppealIds) {
-                boolean found = Arrays.stream(appeals)
-                        .anyMatch(a -> a.appealid.equals(id));
-                Assertions.assertTrue(found, "GetAppealList 应包含插入的 Appeal ID: " + id);
-            }
-        }))
-                .collect(Collectors.toList());
+                // 检查整个列表是否包含所有插入的数据
+                for (String id : insertedAppealIds) {
+                    boolean found = Arrays.stream(appeals)
+                                           .anyMatch(a -> a.appealid.equals(id));
+                    Assertions.assertTrue(found, "GetAppealList 应包含插入的 Appeal ID: " + id);
+                }
+            }))
+            .collect(Collectors.toList());
     }
 
     @TestFactory
     Collection<DynamicTest> testHandleAppeal() {
         // 查询数据库中已存在的一个用户
         String userId = em.createQuery("SELECT u.userid FROM User u", String.class)
-                .setMaxResults(1)
-                .getSingleResult();
+                          .setMaxResults(1)
+                          .getSingleResult();
 
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("HandleAppeal test #" + i, () -> {
-            // 插入一个新的 Appeal
-            String appealId = UUID.randomUUID().toString();
-            Appeal appeal = new Appeal();
-            appeal.appealid = appealId;
-            appeal.appealuserid = userId;
-            appeal.content = "HandleAppeal test content " + i;
-            appeal.fileURL = "http://example.com/file" + i;
-            appeal.status = 0;
+            .mapToObj(i -> DynamicTest.dynamicTest("HandleAppeal test #" + i, () -> {
+                // 插入一个新的 Appeal
+                String appealId = UUID.randomUUID().toString();
+                Appeal appeal = new Appeal();
+                appeal.appealid = appealId;
+                appeal.appealuserid = userId;
+                appeal.content = "HandleAppeal test content " + i;
+                appeal.fileURL = "http://example.com/file" + i;
+                appeal.status = 0;
 
-            em.getTransaction().begin();
-            em.persist(appeal);
-            em.getTransaction().commit();
-
-            // 如果 newStatus 为 1,先将用户的 account_status 设置为 true
-            if (i % 2 == 0) { // 偶数索引对应 newStatus = 1
                 em.getTransaction().begin();
-                User user = em.find(User.class, userId);
-                Assertions.assertNotNull(user, "数据库应能查到相关用户");
-                user.accountstate = true; // 设置为 true
+                em.persist(appeal);
                 em.getTransaction().commit();
-            }
 
-            // 测试处理申诉
-            int newStatus = (i % 2 == 0) ? 1 : 2; // 偶数索引通过申诉,奇数索引拒绝申诉
-            boolean result = cheat.HandleAppeal(appealId, newStatus);
-            Assertions.assertTrue(result, "HandleAppeal 应返回 true");
+                // 如果 newStatus 为 1,先将用户的 account_status 设置为 true
+                if (i % 2 == 0) { // 偶数索引对应 newStatus = 1
+                    em.getTransaction().begin();
+                    User user = em.find(User.class, userId);
+                    Assertions.assertNotNull(user, "数据库应能查到相关用户");
+                    user.accountstate = true; // 设置为 true
+                    em.getTransaction().commit();
+                }
 
-            // 验证 Appeal 状态是否更新
-            Appeal updatedAppeal = em.find(Appeal.class, appealId);
-            Assertions.assertNotNull(updatedAppeal, "数据库应能查到更新后的 Appeal");
-            Assertions.assertEquals(newStatus, updatedAppeal.status, "Appeal 的状态应被更新为: " + newStatus);
+                // 测试处理申诉
+                int newStatus = (i % 2 == 0) ? 1 : 2; // 偶数索引通过申诉,奇数索引拒绝申诉
+                boolean result = cheat.HandleAppeal(appealId, newStatus);
+                Assertions.assertTrue(result, "HandleAppeal 应返回 true");
 
-            // 如果申诉通过,验证用户的 account_status 是否被设置为 false
-            if (newStatus == 1) {
-                User user = em.find(User.class, userId);
-                Assertions.assertNotNull(user, "数据库应能查到相关用户");
-                Assertions.assertFalse(user.accountstate, "通过申诉后用户的 account_status 应为 false");
-            }
+                // 验证 Appeal 状态是否更新
+                Appeal updatedAppeal = em.find(Appeal.class, appealId);
+                Assertions.assertNotNull(updatedAppeal, "数据库应能查到更新后的 Appeal");
+                Assertions.assertEquals(newStatus, updatedAppeal.status, "Appeal 的状态应被更新为: " + newStatus);
 
-            // 清理测试数据
-            em.getTransaction().begin();
-            em.remove(updatedAppeal);
-            em.getTransaction().commit();
-        }))
-                .collect(Collectors.toList());
+                // 如果申诉通过,验证用户的 account_status 是否被设置为 false
+                if (newStatus == 1) {
+                    User user = em.find(User.class, userId);
+                    Assertions.assertNotNull(user, "数据库应能查到相关用户");
+                    Assertions.assertFalse(user.accountstate, "通过申诉后用户的 account_status 应为 false");
+                }
+
+                // 清理测试数据
+                em.getTransaction().begin();
+                em.remove(updatedAppeal);
+                em.getTransaction().commit();
+            }))
+            .collect(Collectors.toList());
     }
 
     @TestFactory
     Collection<DynamicTest> testGetFakeSeed() {
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("GetFakeSeed test #" + i, () -> {
-            // 插入一个新的假种子
-            String seedId = UUID.randomUUID().toString();
-            String userId = em.createQuery("SELECT u.userid FROM User u", String.class)
-                    .setMaxResults(1)
-                    .getSingleResult();
+            .mapToObj(i -> DynamicTest.dynamicTest("GetFakeSeed test #" + i, () -> {
+                // 插入一个新的假种子
+                String seedId = UUID.randomUUID().toString();
+                String userId = em.createQuery("SELECT u.userid FROM User u", String.class)
+                                  .setMaxResults(1)
+                                  .getSingleResult();
 
-            Seed seed = new Seed();
-            seed.seedid = seedId;
-            seed.seeduserid = userId;
-            seed.faketime = 100 + i; // 设置为大于 config.FakeTime 的值
-            seed.lastfakecheck = new Date();
-            seed.outurl = "http://example.com/fake" + i;
-            seed.title = "Fake Seed " + i;
-            seed.subtitle = "Subtitle " + i;
-            seed.seedsize = "100MB";
-            seed.seedtag = "test,fake";
-            seed.downloadtimes = 0;
-            seed.url = "http://example.com/seed" + i;
+                Seed seed = new Seed();
+                seed.seedid = seedId;
+                seed.seeduserid = userId;
+                seed.faketime = 100 + i; // 设置为大于 config.FakeTime 的值
+                seed.lastfakecheck = new Date();
+                seed.outurl = "http://example.com/fake" + i;
+                seed.title = "Fake Seed " + i;
+                seed.subtitle = "Subtitle " + i;
+                seed.seedsize = "100MB";
+                seed.seedtag = "test,fake";
+                seed.downloadtimes = 0;
+                seed.url = "http://example.com/seed" + i;
 
-            em.getTransaction().begin();
-            em.persist(seed);
-            em.getTransaction().commit();
+                em.getTransaction().begin();
+                em.persist(seed);
+                em.getTransaction().commit();
 
-            // 记录插入的 Seed ID
-            insertedSeedIds.add(seedId);
+                // 记录插入的 Seed ID
+                insertedSeedIds.add(seedId);
 
-            // 调用 GetFakeSeed 并验证
-            Pair<String, String>[] fakeSeeds = cheat.GetFakeSeed();
-            Assertions.assertNotNull(fakeSeeds, "GetFakeSeed 应返回非空");
+                // 调用 GetFakeSeed 并验证
+                Pair<String, String>[] fakeSeeds = cheat.GetFakeSeed();
+                Assertions.assertNotNull(fakeSeeds, "GetFakeSeed 应返回非空");
 
-            // 验证返回的假种子列表是否包含所有插入的假种子
-            for (String id : insertedSeedIds) {
-                boolean found = Arrays.stream(fakeSeeds)
-                        .anyMatch(pair -> pair.getLeft().equals(id));
-                Assertions.assertTrue(found, "GetFakeSeed 应包含插入的假种子 ID: " + id);
-            }
-        }))
-                .collect(Collectors.toList());
+                // 验证返回的假种子列表是否包含所有插入的假种子
+                for (String id : insertedSeedIds) {
+                    boolean found = Arrays.stream(fakeSeeds)
+                                           .anyMatch(pair -> pair.getLeft().equals(id));
+                    Assertions.assertTrue(found, "GetFakeSeed 应包含插入的假种子 ID: " + id);
+                }
+            }))
+            .collect(Collectors.toList());
     }
 
     @TestFactory
@@ -320,47 +319,47 @@
         List<String> insertedUserIds = new ArrayList<>(); // 用于记录插入的用户 ID
 
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("GetPunishedUserList test #" + i, () -> {
-            // 插入一个新的用户,accountstate 设置为 true
-            String userId = UUID.randomUUID().toString();
-            User user = new User();
-            user.userid = userId;
-            user.email = "test" + i + "@example.com";
-            user.username = "TestUser" + i;
-            user.password = "password" + i;
-            user.sex = "M";
-            user.detectedCount = 0;
-            user.lastDetectedTime = new Date();
-            user.school = "TestSchool";
-            user.pictureurl = "http://example.com/avatar" + i;
-            user.profile = "Test profile " + i;
-            user.accountstate = true; // 设置为 true
-            user.invitetimes = 5;
+            .mapToObj(i -> DynamicTest.dynamicTest("GetPunishedUserList test #" + i, () -> {
+                // 插入一个新的用户,accountstate 设置为 true
+                String userId = UUID.randomUUID().toString();
+                User user = new User();
+                user.userid = userId;
+                user.email = "test" + i + "@example.com";
+                user.username = "TestUser" + i;
+                user.password = "password" + i;
+                user.sex = "M";
+                user.detectedCount = 0;
+                user.lastDetectedTime = new Date();
+                user.school = "TestSchool";
+                user.pictureurl = "http://example.com/avatar" + i;
+                user.profile = "Test profile " + i;
+                user.accountstate = true; // 设置为 true
+                user.invitetimes = 5;
 
-            // 创建并设置 UserPT 实例
-            UserPT userPT = new UserPT();
-            userPT.user = user; // 关联 User 实例
-            user.userPT = userPT;
+                // 创建并设置 UserPT 实例
+                UserPT userPT = new UserPT();
+                userPT.user = user; // 关联 User 实例
+                user.userPT = userPT;
 
-            em.getTransaction().begin();
-            em.persist(user);
-            em.persist(userPT); // 持久化 UserPT 实例
-            em.getTransaction().commit();
+                em.getTransaction().begin();
+                em.persist(user);
+                em.persist(userPT); // 持久化 UserPT 实例
+                em.getTransaction().commit();
 
-            // 记录插入的用户 ID
-            insertedUserIds.add(userId);
+                // 记录插入的用户 ID
+                insertedUserIds.add(userId);
 
-            // 调用 GetPunishedUserList 并验证
-            String[] punishedUsers = cheat.GetPunishedUserList();
-            Assertions.assertNotNull(punishedUsers, "GetPunishedUserList 应返回非空");
+                // 调用 GetPunishedUserList 并验证
+                String[] punishedUsers = cheat.GetPunishedUserList();
+                Assertions.assertNotNull(punishedUsers, "GetPunishedUserList 应返回非空");
 
-            // 验证返回的用户列表是否包含所有插入的用户
-            for (String id : insertedUserIds) {
-                boolean found = Arrays.stream(punishedUsers).anyMatch(returnedId -> returnedId.equals(id));
-                Assertions.assertTrue(found, "GetPunishedUserList 应包含插入的用户 ID: " + id);
-            }
-        }))
-                .collect(Collectors.toList());
+                // 验证返回的用户列表是否包含所有插入的用户
+                for (String id : insertedUserIds) {
+                    boolean found = Arrays.stream(punishedUsers).anyMatch(returnedId -> returnedId.equals(id));
+                    Assertions.assertTrue(found, "GetPunishedUserList 应包含插入的用户 ID: " + id);
+                }
+            }))
+            .collect(Collectors.toList());
     }
 
     @TestFactory
@@ -368,76 +367,76 @@
         List<String> insertedUserIds = new ArrayList<>(); // 用于记录插入的用户 ID
 
         return IntStream.range(0, 10)
-                .mapToObj(i -> DynamicTest.dynamicTest("PunishUser test #" + i, () -> {
-            // 配置参数
-            int cheatTime = config.CheatTime;
-            int fakeTime = config.FakeTime;
+            .mapToObj(i -> DynamicTest.dynamicTest("PunishUser test #" + i, () -> {
+                // 配置参数
+                int cheatTime = config.CheatTime;
+                int fakeTime = config.FakeTime;
 
-            // 插入用户 1(作弊用户)
-            String userId1 = UUID.randomUUID().toString();
-            User user1 = new User();
-            user1.userid = userId1;
-            user1.email = "cheater" + i + "_" + UUID.randomUUID().toString() + "@example.com"; // 确保唯一性
-            user1.username = "Cheater" + i;
-            user1.password = "password" + i;
-            user1.sex = "M";
-            user1.detectedCount = cheatTime + 1; // detectedCount 超过 cheatTime
-            user1.fakeDetectedCount = 0;
-            user1.lastDetectedTime = new Date();
-            user1.fakeLastDetectedTime = new Date();
-            user1.accountstate = false; // 初始状态为未封禁
-            user1.invitetimes = 5;
+                // 插入用户 1(作弊用户)
+                String userId1 = UUID.randomUUID().toString();
+                User user1 = new User();
+                user1.userid = userId1;
+                user1.email = "cheater" + i + "_" + UUID.randomUUID().toString() + "@example.com"; // 确保唯一性
+                user1.username = "Cheater" + i;
+                user1.password = "password" + i;
+                user1.sex = "M";
+                user1.detectedCount = cheatTime + 1; // detectedCount 超过 cheatTime
+                user1.fakeDetectedCount = 0;
+                user1.lastDetectedTime = new Date();
+                user1.fakeLastDetectedTime = new Date();
+                user1.accountstate = false; // 初始状态为未封禁
+                user1.invitetimes = 5;
 
-            // 创建并设置 UserPT 实例
-            UserPT userPT1 = new UserPT();
-            userPT1.user = user1; // 关联 User 实例
-            user1.userPT = userPT1;
+                // 创建并设置 UserPT 实例
+                UserPT userPT1 = new UserPT();
+                userPT1.user = user1; // 关联 User 实例
+                user1.userPT = userPT1;
 
-            // 插入用户 2(非作弊用户)
-            String userId2 = UUID.randomUUID().toString();
-            User user2 = new User();
-            user2.userid = userId2;
-            user2.email = "normal" + i + "_" + UUID.randomUUID().toString() + "@example.com"; // 确保唯一性
-            user2.username = "NormalUser" + i;
-            user2.password = "password" + i;
-            user2.sex = "F";
-            user2.detectedCount = 0;
-            user2.fakeDetectedCount = fakeTime - 1; // fakeDetectedCount 未超过 fakeTime
-            user2.lastDetectedTime = new Date();
-            user2.fakeLastDetectedTime = new Date();
-            user2.accountstate = false; // 初始状态为未封禁
-            user2.invitetimes = 5;
+                // 插入用户 2(非作弊用户)
+                String userId2 = UUID.randomUUID().toString();
+                User user2 = new User();
+                user2.userid = userId2;
+                user2.email = "normal" + i + "_" + UUID.randomUUID().toString() + "@example.com"; // 确保唯一性
+                user2.username = "NormalUser" + i;
+                user2.password = "password" + i;
+                user2.sex = "F";
+                user2.detectedCount = 0;
+                user2.fakeDetectedCount = fakeTime - 1; // fakeDetectedCount 未超过 fakeTime
+                user2.lastDetectedTime = new Date();
+                user2.fakeLastDetectedTime = new Date();
+                user2.accountstate = false; // 初始状态为未封禁
+                user2.invitetimes = 5;
 
-            // 创建并设置 UserPT 实例
-            UserPT userPT2 = new UserPT();
-            userPT2.user = user2; // 关联 User 实例
-            user2.userPT = userPT2;
+                // 创建并设置 UserPT 实例
+                UserPT userPT2 = new UserPT();
+                userPT2.user = user2; // 关联 User 实例
+                user2.userPT = userPT2;
 
-            em.getTransaction().begin();
-            em.persist(user1);
-            em.persist(userPT1); // 持久化 UserPT 实例
-            em.persist(user2);
-            em.persist(userPT2); // 持久化 UserPT 实例
-            em.getTransaction().commit();
+                em.getTransaction().begin();
+                em.persist(user1);
+                em.persist(userPT1); // 持久化 UserPT 实例
+                em.persist(user2);
+                em.persist(userPT2); // 持久化 UserPT 实例
+                em.getTransaction().commit();
 
-            // 记录插入的用户 ID
-            insertedUserIds.add(userId1);
-            insertedUserIds.add(userId2);
+                // 记录插入的用户 ID
+                insertedUserIds.add(userId1);
+                insertedUserIds.add(userId2);
 
-            // 调用 PunishUser 方法
-            cheat.PunishUser();
+                // 调用 PunishUser 方法
+                cheat.PunishUser();
 
-            // 验证用户 1 是否被封禁
-            User punishedUser1 = em.find(User.class, userId1);
-            Assertions.assertNotNull(punishedUser1, "数据库应能查到用户 1");
-            Assertions.assertTrue(punishedUser1.accountstate, "作弊用户应被封禁");
+                // 验证用户 1 是否被封禁
+                User punishedUser1 = em.find(User.class, userId1);
+                Assertions.assertNotNull(punishedUser1, "数据库应能查到用户 1");
+                Assertions.assertTrue(punishedUser1.accountstate, "作弊用户应被封禁");
 
-            // 验证用户 2 是否未被封禁
-            User punishedUser2 = em.find(User.class, userId2);
-            Assertions.assertNotNull(punishedUser2, "数据库应能查到用户 2");
-            Assertions.assertFalse(punishedUser2.accountstate, "非作弊用户不应被封禁");
-        }))
-                .collect(Collectors.toList());
+                // 验证用户 2 是否未被封禁
+                User punishedUser2 = em.find(User.class, userId2);
+                Assertions.assertNotNull(punishedUser2, "数据库应能查到用户 2");
+                Assertions.assertFalse(punishedUser2.accountstate, "非作弊用户不应被封禁");
+            }))
+            .collect(Collectors.toList());
     }
 
     // @TestFactory
@@ -445,6 +444,7 @@
     //     List<String> insertedUserIds = new ArrayList<>(); // 用于记录插入的用户 ID
     //     List<String> insertedSeedIds = new ArrayList<>(); // 用于记录插入的种子 ID
     //     List<String> insertedTransIds = new ArrayList<>(); // 用于记录插入的传输记录 ID
+
     //     return IntStream.range(0, 10)
     //         .mapToObj(i -> DynamicTest.dynamicTest("DetectTrans test #" + i, () -> {
     //             // 插入上传用户
@@ -461,10 +461,12 @@
     //             uploader.fakeLastDetectedTime = new Date();
     //             uploader.accountstate = false;
     //             uploader.invitetimes = 5;
+
     //             // 创建并设置 UserPT 实例
     //             UserPT uploaderPT = new UserPT();
     //             uploaderPT.user = uploader; // 关联 User 实例
     //             uploader.userPT = uploaderPT;
+
     //             // 插入下载用户
     //             String downloaderId = UUID.randomUUID().toString();
     //             User downloader = new User();
@@ -479,10 +481,12 @@
     //             downloader.fakeLastDetectedTime = new Date();
     //             downloader.accountstate = false;
     //             downloader.invitetimes = 5;
+
     //             // 创建并设置 UserPT 实例
     //             UserPT downloaderPT = new UserPT();
     //             downloaderPT.user = downloader; // 关联 User 实例
     //             downloader.userPT = downloaderPT;
+
     //             em.getTransaction().begin();
     //             em.persist(uploader);
     //             em.persist(uploaderPT); // 持久化 UserPT 实例
@@ -491,6 +495,7 @@
     //             em.getTransaction().commit();
     //             insertedUserIds.add(uploaderId);
     //             insertedUserIds.add(downloaderId);
+
     //             // 插入种子
     //             String seedId = UUID.randomUUID().toString();
     //             Seed seed = new Seed();
@@ -505,10 +510,12 @@
     //             seed.seedtag = "test";
     //             seed.downloadtimes = 0;
     //             seed.url = "http://example.com/seed" + i;
+
     //             em.getTransaction().begin();
     //             em.persist(seed);
     //             em.getTransaction().commit();
     //             insertedSeedIds.add(seedId);
+
     //             // 插入正常和异常的传输记录
     //             List<TransRecord> transRecords = new ArrayList<>();
     //             for (int j = 0; j < 15; j++) {
@@ -521,14 +528,17 @@
     //                 transRecord.download = (j < 13) ? 90 : 10; // 异常数据的上传量远大于下载量
     //                 transRecord.maxupload = 200;
     //                 transRecord.maxdownload = 200;
+
     //                 em.getTransaction().begin();
     //                 em.persist(transRecord);
     //                 em.getTransaction().commit();
     //                 insertedTransIds.add(transRecord.taskid);
     //                 transRecords.add(transRecord);
     //             }
+
     //             // 调用 DetectTrans 方法
     //             cheat.DetectTrans();
+
     //             // 验证下载用户的 detectedCount 是否增加
     //             User detectedDownloader = em.find(User.class, downloaderId);
     //             Assertions.assertNotNull(detectedDownloader, "数据库应能查到上传用户");
diff --git a/src/test/java/databasetest/databasesystest.java b/src/test/java/databasetest/databasesystest.java
index f4b22f1..f802360 100644
--- a/src/test/java/databasetest/databasesystest.java
+++ b/src/test/java/databasetest/databasesystest.java
@@ -45,7 +45,10 @@
         props.put("javax.persistence.jdbc.driver", "com.mysql.cj.jdbc.Driver");
         emf = Persistence.createEntityManagerFactory("myPersistenceUnit", props);
         em = emf.createEntityManager();
-        db = new Database1(emf);
+        db = new Database1();
+        java.lang.reflect.Field f = Database1.class.getDeclaredField("entitymanager");
+        f.setAccessible(true);
+        f.set(db, em);
         testUserIds = new ArrayList<>();
         testEmails = new ArrayList<>();
         for (int i = 0; i < 10; i++) {