fix:删除白名单记录前先删玩家答题记录
This commit is contained in:
parent
65584bb8d8
commit
a8c3f70973
|
|
@ -129,7 +129,7 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
GET /api/whitelist/rejected
|
||||
```
|
||||
|
||||
Returns paginated list of rejected players (status=0).
|
||||
Returns paginated list of rejected players (status=3).
|
||||
|
||||
**Parameters:** Same as `/list` (including `all`).
|
||||
|
||||
|
|
@ -364,9 +364,9 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
|
||||
| status | statusText |
|
||||
|--------|------------|
|
||||
| 0 | 已拒绝 (Rejected) |
|
||||
| 1 | 已通过 (Approved) |
|
||||
| 2 | 待审核 (Pending) |
|
||||
| 3 | 已拒绝 (Rejected) |
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -409,7 +409,7 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
| playerName | String | Minecraft username |
|
||||
| uuid | String | Mojang account UUID |
|
||||
| qq | String | QQ number |
|
||||
| status | Byte | 0=rejected, 1=approved, 2=pending |
|
||||
| status | Byte | 1=approved, 2=pending, 3=rejected |
|
||||
| description | String | Application note |
|
||||
| createTime | String | Application timestamp (ISO 8601) |
|
||||
| regionCode | Long | Region postal code |
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
GET /api/whitelist/rejected
|
||||
```
|
||||
|
||||
分页查询已被拒绝的玩家(status=0)。
|
||||
分页查询已被拒绝的玩家(status=3)。
|
||||
|
||||
**请求参数:** 同 `/list`(含 `all` 参数)。
|
||||
|
||||
|
|
@ -350,9 +350,9 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
|
||||
| status | statusText |
|
||||
|--------|------------|
|
||||
| 0 | 已拒绝 |
|
||||
| 1 | 已通过 |
|
||||
| 2 | 待审核 |
|
||||
| 3 | 已拒绝 |
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -395,7 +395,7 @@ curl -H "X-API-TOKEN: <token>" \
|
|||
| playerName | String | Minecraft 用户名 |
|
||||
| uuid | String | Mojang 正版 UUID |
|
||||
| qq | String | QQ 号 |
|
||||
| status | Byte | 0=已拒绝, 1=已通过, 2=待审核 |
|
||||
| status | Byte | 1=已通过, 2=待审核, 3=已拒绝 |
|
||||
| description | String | 申请备注 |
|
||||
| createTime | String | 申请时间(ISO 8601) |
|
||||
| regionCode | Long | 地区邮政编码 |
|
||||
|
|
|
|||
2
pom.xml
2
pom.xml
|
|
@ -10,7 +10,7 @@
|
|||
</parent>
|
||||
<groupId>com.linearpast</groupId>
|
||||
<artifactId>MinecraftManager</artifactId>
|
||||
<version>1.1.3</version>
|
||||
<version>1.1.5</version>
|
||||
<name>MinecraftManager</name>
|
||||
<description>MinecraftManager</description>
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ public class WhitelistController {
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取被拒绝列表(status=0)
|
||||
* 获取被拒绝列表(status=3)
|
||||
*/
|
||||
@GetMapping("/rejected")
|
||||
public Result<?> getRejected(
|
||||
|
|
@ -72,7 +72,7 @@ public class WhitelistController {
|
|||
) {
|
||||
Pageable pageable = all ? Pageable.unpaged() : PageRequest.of(page - 1, size);
|
||||
Page<PlayerInfoView> players = playersService.getPlayers(
|
||||
playerName, null, null, (byte) 0,
|
||||
playerName, null, null, (byte) 3,
|
||||
null, null, pageable
|
||||
);
|
||||
return Result.successPage(players.getContent(), players.getTotalElements());
|
||||
|
|
@ -94,7 +94,7 @@ public class WhitelistController {
|
|||
@PostMapping("/reject/{id}")
|
||||
public Result<?> reject(@PathVariable Integer id, HttpSession session) {
|
||||
Operators operators = (Operators) session.getAttribute("adminAccount");
|
||||
int code = playersService.updatePlayerStatus(id, (byte) 0, operators);
|
||||
int code = playersService.updatePlayerStatus(id, (byte) 3, operators);
|
||||
return code > 0 ? Result.success().msg("已拒绝申请") : Result.error("操作失败,Rcon连接错误或玩家不存在");
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ public class WhitelistController {
|
|||
@PostMapping("/batchReject")
|
||||
public Result<?> batchReject(@RequestBody List<Integer> ids, HttpSession session) {
|
||||
Operators operators = (Operators) session.getAttribute("adminAccount");
|
||||
int code = playersService.updatePlayersStatus(ids, (byte) 0, operators);
|
||||
int code = playersService.updatePlayersStatus(ids, (byte) 3, operators);
|
||||
return code > 0 ? Result.success().msg("成功处理:" + code + "/" + ids.size()) : Result.error("操作失败");
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,7 @@ public class WhitelistController {
|
|||
Map<String, Object> stats = new HashMap<>();
|
||||
stats.put("approved", playersService.getPlayersCountByStatus((byte) 1));
|
||||
stats.put("pending", playersService.getPlayersCountByStatus((byte) 2));
|
||||
stats.put("rejected", playersService.getPlayersCountByStatus((byte) 0));
|
||||
stats.put("rejected", playersService.getPlayersCountByStatus((byte) 3));
|
||||
return Result.success(stats);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.linearpast.minecraftmanager.entity.Players;
|
|||
import com.linearpast.minecraftmanager.entity.view.PlayerInfoView;
|
||||
import com.linearpast.minecraftmanager.repository.PlayersRepository;
|
||||
import com.linearpast.minecraftmanager.repository.view.PlayerInfoViewRepository;
|
||||
import com.linearpast.minecraftmanager.service.inter.PlayerAnswersService;
|
||||
import com.linearpast.minecraftmanager.service.inter.PlayersService;
|
||||
import com.linearpast.minecraftmanager.utils.WhitelistTarget;
|
||||
import com.linearpast.minecraftmanager.utils.config.ConfigLoader;
|
||||
|
|
@ -44,6 +45,8 @@ public class PlayersServiceImpl implements PlayersService {
|
|||
@Autowired
|
||||
private PlayerInfoViewRepository playerInfoViewRepository;
|
||||
@Autowired
|
||||
private PlayerAnswersService playerAnswersService;
|
||||
@Autowired
|
||||
private MinecraftRconUtils rconService;
|
||||
@Autowired
|
||||
private JavaMailSenderImpl mailSender;
|
||||
|
|
@ -76,13 +79,18 @@ public class PlayersServiceImpl implements PlayersService {
|
|||
if(minecraftRcon == null) return false;
|
||||
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(byId.getPlayerName()), WhiteListModes.REMOVE));
|
||||
if(response.getResponseId() != 0) return false;
|
||||
this.asyncSendEmail(byId, (byte)0, true);
|
||||
this.asyncSendEmail(byId, (byte)3, true);
|
||||
playerAnswersService.deleteAllPlayerAnswers(byId);
|
||||
playersRepository.deleteById(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceDeletePlayer(List<Integer> ids) {
|
||||
List<Players> players = playersRepository.findAllById(ids);
|
||||
for (Players player : players) {
|
||||
playerAnswersService.deleteAllPlayerAnswers(player);
|
||||
}
|
||||
playersRepository.deleteAllById(ids);
|
||||
}
|
||||
|
||||
|
|
@ -165,7 +173,8 @@ public class PlayersServiceImpl implements PlayersService {
|
|||
RconResponse response = minecraftRcon.sendSync(new SelfWhiteListCommand(Target.player(players.getPlayerName()), WhiteListModes.REMOVE));
|
||||
if (response.getResponseId() == 0) {
|
||||
successIds.add(players.getId());
|
||||
asyncSendEmail(players, (byte) 0, true);
|
||||
asyncSendEmail(players, (byte) 3, true);
|
||||
playerAnswersService.deleteAllPlayerAnswers(players);
|
||||
}
|
||||
});
|
||||
playersRepository.deleteAllById(successIds);
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class WhitelistControllerTest {
|
|||
@Test
|
||||
void getRejected_shouldReturnPage() throws Exception {
|
||||
Page<PlayerInfoView> page = new PageImpl<>(Collections.emptyList());
|
||||
when(playersService.getPlayers(isNull(), isNull(), isNull(), eq((byte) 0),
|
||||
when(playersService.getPlayers(isNull(), isNull(), isNull(), eq((byte) 3),
|
||||
isNull(), isNull(), any(Pageable.class))).thenReturn(page);
|
||||
|
||||
mockMvc.perform(get("/api/whitelist/rejected"))
|
||||
|
|
@ -149,7 +149,7 @@ class WhitelistControllerTest {
|
|||
|
||||
@Test
|
||||
void reject_success() throws Exception {
|
||||
when(playersService.updatePlayerStatus(eq(1), eq((byte) 0), any(Operators.class))).thenReturn(1);
|
||||
when(playersService.updatePlayerStatus(eq(1), eq((byte) 3), any(Operators.class))).thenReturn(1);
|
||||
|
||||
mockMvc.perform(post("/api/whitelist/reject/1").session(adminSession))
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -159,7 +159,7 @@ class WhitelistControllerTest {
|
|||
|
||||
@Test
|
||||
void reject_failure() throws Exception {
|
||||
when(playersService.updatePlayerStatus(eq(99), eq((byte) 0), any(Operators.class))).thenReturn(0);
|
||||
when(playersService.updatePlayerStatus(eq(99), eq((byte) 3), any(Operators.class))).thenReturn(0);
|
||||
|
||||
mockMvc.perform(post("/api/whitelist/reject/99").session(adminSession))
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -234,7 +234,7 @@ class WhitelistControllerTest {
|
|||
@Test
|
||||
void batchReject_success() throws Exception {
|
||||
List<Integer> ids = List.of(1, 2);
|
||||
when(playersService.updatePlayersStatus(eq(ids), eq((byte) 0), any(Operators.class))).thenReturn(2);
|
||||
when(playersService.updatePlayersStatus(eq(ids), eq((byte) 3), any(Operators.class))).thenReturn(2);
|
||||
|
||||
mockMvc.perform(post("/api/whitelist/batchReject")
|
||||
.session(adminSession)
|
||||
|
|
@ -277,7 +277,7 @@ class WhitelistControllerTest {
|
|||
void getStats_shouldReturnCounts() throws Exception {
|
||||
when(playersService.getPlayersCountByStatus((byte) 1)).thenReturn(10);
|
||||
when(playersService.getPlayersCountByStatus((byte) 2)).thenReturn(5);
|
||||
when(playersService.getPlayersCountByStatus((byte) 0)).thenReturn(3);
|
||||
when(playersService.getPlayersCountByStatus((byte) 3)).thenReturn(3);
|
||||
|
||||
mockMvc.perform(get("/api/whitelist/stats"))
|
||||
.andExpect(status().isOk())
|
||||
|
|
@ -332,7 +332,7 @@ class WhitelistControllerTest {
|
|||
@Test
|
||||
void checkPlayer_rejectedStatus() throws Exception {
|
||||
Players player = new Players();
|
||||
player.setStatus((byte) 0);
|
||||
player.setStatus((byte) 3);
|
||||
|
||||
when(playersService.getPlayer("RejectedGuy")).thenReturn(player);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user