| | |
| | | return null; |
| | | } |
| | | |
| | | // DATETIME 仅保存秒;写库前截断,避免进位后被误判为未来开播并立即结束。 |
| | | LocalDateTime persistedStartTime = actualStartTime.withNano(0); |
| | | // 使用带状态条件的更新语句保证人工开播与定时开播并发时仍然幂等。 |
| | | int affected = liveSessionMapper.markLivingIfPending(session.getId(), actualStartTime); |
| | | int affected = liveSessionMapper.markLivingIfPending(session.getId(), persistedStartTime); |
| | | if (affected <= 0) { |
| | | if (failWhenInvalid) { |
| | | throw new IllegalArgumentException("场次状态不允许开播"); |
| | |
| | | return null; |
| | | } |
| | | |
| | | reconcileCourseLivingSessions(session.getLiveCourseId(), actualStartTime); |
| | | reconcileCourseLivingSessions(session.getLiveCourseId(), persistedStartTime); |
| | | LiveSession startedSession = liveSessionMapper.selectById(session.getId()); |
| | | if (startedSession == null) { |
| | | session.setLiveStatus(1); |
| | | if (session.getActualStartTime() == null) { |
| | | session.setActualStartTime(actualStartTime); |
| | | session.setActualStartTime(persistedStartTime); |
| | | } |
| | | return new LiveSessionStatusVO(session.getId(), session.getLiveStatus(), session.getActualStartTime(), session.getActualEndTime()); |
| | | } |