YelinCui | 09ee07c | 2025-06-07 05:09:55 +0800 | [diff] [blame] | 1 | package com.example.myproject.service; |
| 2 | |
| 3 | import com.example.myproject.entity.AuditRecord; |
| 4 | import com.example.myproject.entity.BannedUser; |
| 5 | import com.example.myproject.entity.SuspiciousUser; |
| 6 | import com.example.myproject.mapper.AuditRecordMapper; |
| 7 | import com.example.myproject.mapper.BannedUserMapper; |
| 8 | import com.example.myproject.mapper.SuspiciousUserMapper; |
| 9 | import org.checkerframework.checker.units.qual.A; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Service; |
| 12 | |
| 13 | import java.time.LocalDateTime; |
| 14 | @Service |
| 15 | public class AuditService { |
| 16 | @Autowired |
| 17 | AuditRecordMapper auditRecordMapper; |
| 18 | @Autowired |
| 19 | SuspiciousUserMapper suspiciousUserMapper; |
| 20 | @Autowired |
| 21 | BannedUserMapper bannedUserMapper; |
| 22 | public void flagTorrentForReview(Long torrentId, double upload, double download) { |
| 23 | AuditRecord record = new AuditRecord(); |
| 24 | record.setTorrentId(torrentId); |
| 25 | record.setUpload(upload); |
| 26 | record.setDownload(download); |
| 27 | record.setCreateTime(LocalDateTime.now()); |
| 28 | |
YelinCui | edbf91e | 2025-06-08 23:56:51 +0800 | [diff] [blame] | 29 | auditRecordMapper.upsert(record); |
YelinCui | 09ee07c | 2025-06-07 05:09:55 +0800 | [diff] [blame] | 30 | } |
| 31 | public void addSuspiciousUser(Long userId, String reason, double speedKBs) { |
| 32 | SuspiciousUser user = new SuspiciousUser(); |
| 33 | user.setUserId(userId); |
| 34 | user.setReason(reason); |
| 35 | user.setSpeedKBs(speedKBs); |
YelinCui | 5b436b4 | 2025-06-09 17:30:09 +0800 | [diff] [blame^] | 36 | user.setCreateTime(LocalDateTime.now()); |
YelinCui | 09ee07c | 2025-06-07 05:09:55 +0800 | [diff] [blame] | 37 | suspiciousUserMapper.insert(user); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | public void banUser(Long userId, String reason) { |
| 42 | BannedUser bannedUser = new BannedUser(); |
| 43 | bannedUser.setUserId(userId); |
| 44 | bannedUser.setReason(reason); |
YelinCui | 5b436b4 | 2025-06-09 17:30:09 +0800 | [diff] [blame^] | 45 | bannedUser.setCreateTime(LocalDateTime.now()); |
YelinCui | 09ee07c | 2025-06-07 05:09:55 +0800 | [diff] [blame] | 46 | bannedUserMapper.insert(bannedUser); |
| 47 | } |
| 48 | } |