21301050 | f5f827d | 2025-06-09 15:09:33 +0800 | [diff] [blame^] | 1 | package com.pt5.pthouduan.service; |
| 2 | |
| 3 | import com.pt5.pthouduan.entity.Invites; |
| 4 | import com.pt5.pthouduan.entity.User; |
| 5 | import com.pt5.pthouduan.entity.UserTrafficStat; |
| 6 | import com.pt5.pthouduan.mapper.InvitesMapper; |
| 7 | import com.pt5.pthouduan.mapper.UserMapper; |
| 8 | import com.pt5.pthouduan.mapper.UserTrafficMapper; |
| 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Service; |
| 11 | |
| 12 | import java.time.LocalDate; |
| 13 | import java.util.ArrayList; |
| 14 | import java.util.HashMap; |
| 15 | import java.util.List; |
| 16 | import java.util.Map; |
| 17 | |
| 18 | @Service |
| 19 | public class ExamService { |
| 20 | @Autowired |
| 21 | private UserTrafficMapper userTrafficMapper; |
| 22 | @Autowired |
| 23 | private UserMapper userMapper; |
| 24 | //所有用户月度下载量考核 |
| 25 | public Map<String, Object> MonthDownload(LocalDate startDate,LocalDate endDate){ |
| 26 | Map<String, Object> result = new HashMap<>(); |
| 27 | List<Map<String, Object>> users = userMapper.selectAllUsersBasicInfo(); |
| 28 | for (Map<String, Object> user : users) { |
| 29 | // 获取 gradeId,这里转为数字 |
| 30 | Object gradeIdObj = user.get("grade_id"); |
| 31 | int gradeId = (gradeIdObj instanceof Number) ? ((Number) gradeIdObj).intValue() : 0; |
| 32 | UserTrafficStat userTrafficStat=userTrafficMapper.getUserTrafficStats((String) user.get("passkey"),startDate,endDate); |
| 33 | System.out.println(gradeId+" "+userTrafficStat.getTotalUploaded()+" "+userTrafficStat.getTotalDownloaded()); |
| 34 | // 根据 gradeId 的值审核下载量 |
| 35 | if (gradeId == 1) { |
| 36 | if(userTrafficStat.getTotalDownloaded()<1073741824){ |
| 37 | if(userTrafficStat.getTotalUploaded()< 1073741824L *50) |
| 38 | failure((String) user.get("username"),gradeId); |
| 39 | } |
| 40 | } else if (gradeId == 2) { |
| 41 | if(userTrafficStat.getTotalDownloaded()< 1073741824L *3){ |
| 42 | if(userTrafficStat.getTotalUploaded()< 1073741824L *50) |
| 43 | failure((String) user.get("username"),gradeId); |
| 44 | } |
| 45 | } else if (gradeId == 3) { |
| 46 | if(userTrafficStat.getTotalDownloaded()< 1073741824L *5){ |
| 47 | if(userTrafficStat.getTotalUploaded()< 1073741824L *50) |
| 48 | failure((String) user.get("username"),gradeId); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | result.put("success", true); |
| 53 | result.put("message", "用户月度考核完毕"); |
| 54 | return result; |
| 55 | } |
| 56 | //考核失败 |
| 57 | void failure(String username,int gradeId){ |
| 58 | System.out.println("failure"+username+gradeId); |
| 59 | if(gradeId == 1){ |
| 60 | userMapper.deleteByUsername(username); |
| 61 | }else{ |
| 62 | userMapper.updateGrade(username,gradeId-1); |
| 63 | } |
| 64 | } |
| 65 | //所有用户季度上传量考核 |
| 66 | public Map<String, Object> QuarterUpload(LocalDate startDate,LocalDate endDate){ |
| 67 | Map<String, Object> result = new HashMap<>(); |
| 68 | List<Map<String, Object>> users = userMapper.selectAllUsersBasicInfo(); |
| 69 | for (Map<String, Object> user : users) { |
| 70 | // 获取 gradeId,这里转为数字 |
| 71 | Object gradeIdObj = user.get("grade_id"); |
| 72 | int gradeId = (gradeIdObj instanceof Number) ? ((Number) gradeIdObj).intValue() : 0; |
| 73 | UserTrafficStat userTrafficStat=userTrafficMapper.getUserTrafficStats((String) user.get("passkey"),startDate,endDate); |
| 74 | // 根据 gradeId 的值审核上传 |
| 75 | if (gradeId == 1) { |
| 76 | if(userTrafficStat.getTotalUploaded()< 1073741824L *50){ |
| 77 | failure((String) user.get("username"),gradeId); |
| 78 | } |
| 79 | } else if (gradeId == 2) { |
| 80 | if(userTrafficStat.getTotalUploaded()< 1073741824L*60){ |
| 81 | failure((String) user.get("username"),gradeId); |
| 82 | } |
| 83 | } else if (gradeId == 3) { |
| 84 | System.out.println("here"); |
| 85 | if(userTrafficStat.getTotalUploaded()< 1073741824L*70){ |
| 86 | System.out.println("failure"); |
| 87 | failure((String) user.get("username"),gradeId); |
| 88 | } |
| 89 | }else if (gradeId == 4) { |
| 90 | if(userTrafficStat.getTotalUploaded()< 1073741824L*80){ |
| 91 | failure((String) user.get("username"),gradeId); |
| 92 | } |
| 93 | }else if (gradeId == 5) { |
| 94 | if(userTrafficStat.getTotalUploaded()< 1073741824L*100){ |
| 95 | failure((String) user.get("username"),gradeId); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | result.put("success", true); |
| 100 | result.put("message", "用户季度考核完毕"); |
| 101 | return result; |
| 102 | } |
| 103 | } |