fix: thread interrupt handling + dbinfo null safety

This commit is contained in:
2026-08-18 19:05:16 +08:00
parent a62b515e49
commit ffb7edc896
6 changed files with 23 additions and 163 deletions
@@ -63,16 +63,18 @@ public class DataServiceController {
return Result.success(new ServiceVo(res));
}
@GetMapping("/stopService")
@GetMapping("/stopService")
public Result<ServiceVo> stopService() {
int res = 0;
if(thread != null) {
thread.interrupt();
try {
thread.join();
thread.join(5000); // 5秒超时
if (thread.isAlive()) {
res = -1; // 超时未停止
}
} catch (InterruptedException e) {
// result = e.getMessage();
e.printStackTrace();
Thread.currentThread().interrupt();
res = -1;
}
thread = null;
@@ -197,18 +199,23 @@ public class DataServiceController {
}
@GetMapping("/dbinfo")
public Result<DBInfoVo> getDBInfo(){
public Result<DBInfoVo> getDBInfo() {
DBInfoVo dbInfo = new DBInfoVo();
dbInfo.setGameNum( (int)gameService.count() );
dbInfo.setTeamNum( (int)teamService.count() );
dbInfo.setGameNum((int) gameService.count());
dbInfo.setTeamNum((int) teamService.count());
dbInfo.setMatchNum(matchService.getMatchCount());
Map<String, Object> map = matchService.getMap(new QueryWrapper<Match>().select("min(time) as dtMin, max(time) as dtMax"));
LocalDateTime dt = LocalDateTime.ofEpochSecond((Integer) map.get("dtMin"), 0, ZoneOffset.ofHours(8));
dbInfo.setYearStart( dt.getYear() );
dt = LocalDateTime.ofEpochSecond((Integer) map.get("dtMax"), 0, ZoneOffset.ofHours(8));
dbInfo.setYearEnd( dt.getYear() );
Number dtMin = (Number) map.get("dtMin");
Number dtMax = (Number) map.get("dtMax");
if (dtMin == null || dtMax == null) {
return Result.failed("DB time range unavailable");
}
LocalDateTime dt = LocalDateTime.ofEpochSecond(dtMin.longValue(), 0, ZoneOffset.ofHours(8));
dbInfo.setYearStart(dt.getYear());
dt = LocalDateTime.ofEpochSecond(dtMax.longValue(), 0, ZoneOffset.ofHours(8));
dbInfo.setYearEnd(dt.getYear());
return Result.success(dbInfo);
}