Search in sources :

Example 1 with LiveInfo

use of cn.imhtb.antlive.entity.LiveInfo in project Ant-Live by PinTeh.

the class TencentLiveServiceImpl method ban.

@Override
public boolean ban(Integer rid, String resumeTime, String reason) {
    List<BanRecord> banRecords = banRecordMapper.selectList(new QueryWrapper<BanRecord>().eq("room_id", rid).eq("status", 0));
    if (banRecords.size() > 0) {
        return false;
    }
    LiveInfo liveInfo = liveInfoMapper.selectOne(new QueryWrapper<LiveInfo>().eq("room_id", rid).orderByDesc("id").last("limit 0,1"));
    if (liveInfo.getEndTime() == null) {
        // 不能直接更新liveInfo
        LiveInfo updateInfo = new LiveInfo();
        updateInfo.setId(liveInfo.getId());
        updateInfo.setEndTime(LocalDateTime.now());
        // 0-living 1-finished
        updateInfo.setStatus(Constants.LiveInfoStatus.YES.getCode());
        liveInfoMapper.updateById(updateInfo);
    }
    try {
        roomMapper.updateById(Room.builder().id(rid).status(Constants.LiveStatus.BANNING.getCode()).build());
    } catch (Exception e) {
        log.error("更新房间状态异常:{}", e.getMessage());
    }
    log.info("调用腾讯云封禁接口: rid = " + rid);
    ForbidLiveStreamRequest forbidLiveStreamRequest = new ForbidLiveStreamRequest();
    forbidLiveStreamRequest.setAppName("live");
    forbidLiveStreamRequest.setDomainName("live.imhtb.cn");
    forbidLiveStreamRequest.setStreamName(String.valueOf(rid));
    forbidLiveStreamRequest.setReason("reason");
    /*
         * 	恢复流的时间。UTC 格式,例如:2018-11-29T19:00:00Z。
         * 注意:
         * 1. 默认禁播7天,且最长支持禁播90天。
         */
    LocalDateTime resumeLocalDateTime = LocalDateTime.now().plusDays(7);
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    if (!StringUtils.isEmpty(resumeTime)) {
        forbidLiveStreamRequest.setResumeTime(resumeTime);
        // TODO 手动添加8小时
        resumeLocalDateTime = LocalDateTime.parse(resumeTime, df).plusHours(8L);
    }
    ForbidLiveStreamResponse resp = null;
    try {
        resp = client.ForbidLiveStream(forbidLiveStreamRequest);
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
        return false;
    }
    LocalDateTime now = LocalDateTime.now();
    BanRecord record = new BanRecord();
    record.setRoomId(rid);
    record.setReason(reason);
    record.setCreateTime(now);
    record.setStartTime(now);
    record.setResumeTime(resumeLocalDateTime);
    record.setStatus(0);
    banRecordMapper.insert(record);
    roomMapper.updateById(Room.builder().id(rid).status(Constants.LiveStatus.BANNING.getCode()).build());
    log.info(ForbidLiveStreamRequest.toJsonString(resp));
    log.info("调用腾讯云封禁接口:执行成功");
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DateTimeFormatter(java.time.format.DateTimeFormatter) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BanRecord(cn.imhtb.antlive.entity.database.BanRecord) LiveInfo(cn.imhtb.antlive.entity.LiveInfo)

Example 2 with LiveInfo

use of cn.imhtb.antlive.entity.LiveInfo in project Ant-Live by PinTeh.

the class LiveInfoController method list.

@GetMapping("/list")
public ApiResponse list(Integer rid, @RequestParam(required = false) String dateRange, @RequestParam(required = false, defaultValue = "10") Integer limit, @RequestParam(required = false, defaultValue = "1") Integer page, HttpServletRequest request) {
    String token = request.getHeader(JwtUtils.getHeaderKey());
    Integer uid = JwtUtils.getId(token);
    Room room = roomService.getOne(new QueryWrapper<Room>().eq("user_id", uid));
    String maxTime = "", minTime = "";
    boolean condition = !StringUtils.isEmpty(dateRange) && !"null".equals(dateRange);
    if (condition) {
        maxTime = dateRange.split(",")[1];
        minTime = dateRange.split(",")[0];
    }
    QueryWrapper<LiveInfo> liveInfoQueryWrapper = new QueryWrapper<LiveInfo>().eq("room_id", room.getId()).eq("status", 1).le(condition, "start_time", maxTime).ge(condition, "start_time", minTime).orderByDesc("id");
    Page<LiveInfo> liveInfoPage = liveInfoService.page(new Page<>(page, limit), liveInfoQueryWrapper);
    LiveStatResponse response = packageResponse(liveInfoPage.getRecords());
    response.setTotal(liveInfoPage.getTotal());
    return ApiResponse.ofSuccess(response);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LiveStatResponse(cn.imhtb.antlive.vo.response.LiveStatResponse) Room(cn.imhtb.antlive.entity.Room) LiveInfo(cn.imhtb.antlive.entity.LiveInfo) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with LiveInfo

use of cn.imhtb.antlive.entity.LiveInfo in project Ant-Live by PinTeh.

the class LiveInfoController method packageResponse.

private LiveStatResponse packageResponse(List<LiveInfo> list) {
    LiveStatResponse response = new LiveStatResponse();
    List<LiveStatResponse.LiveStat> liveStats = new ArrayList<>();
    long totalTime = 0L;
    for (LiveInfo v : list) {
        LiveStatResponse.LiveStat liveStat = new LiveStatResponse.LiveStat();
        liveStat.setEndTime(v.getEndTime());
        liveStat.setStartTime(v.getStartTime());
        liveStat.setId(v.getId());
        liveStat.setDanMuCount(v.getDanMuCount());
        liveStat.setPresentCount(v.getPresentCount());
        liveStat.setClickCount(v.getClickCount());
        long sub = LocalDateTimeUtils.subMinutes(v.getStartTime(), v.getEndTime());
        totalTime += sub;
        liveStat.setTime(sub);
        liveStats.add(liveStat);
    }
    response.setLiveStats(liveStats);
    response.setTotalTime(totalTime);
    return response;
}
Also used : ArrayList(java.util.ArrayList) LiveStatResponse(cn.imhtb.antlive.vo.response.LiveStatResponse) LiveInfo(cn.imhtb.antlive.entity.LiveInfo)

Example 4 with LiveInfo

use of cn.imhtb.antlive.entity.LiveInfo in project Ant-Live by PinTeh.

the class LiveController method open.

@PostMapping("/open")
public ApiResponse open(HttpServletRequest request) {
    String token = request.getHeader(JwtUtils.getHeaderKey());
    Integer uid = JwtUtils.getId(token);
    Room room = roomService.getOne(new QueryWrapper<Room>().eq("user_id", uid));
    if (room == null || room.getStatus() != Constants.LiveStatus.STOP.getCode()) {
        return ApiResponse.ofError("开播失败");
    }
    room.setSecret(CommonUtils.getRandomString());
    room.setStatus(Constants.LiveStatus.LIVING.getCode());
    roomService.updateById(room);
    // 记录直播时长
    LocalDateTime dateTime = LocalDateTime.now();
    LiveInfo liveInfo = new LiveInfo();
    liveInfo.setUserId(uid);
    liveInfo.setRoomId(room.getId());
    liveInfo.setStatus(0);
    liveInfo.setStartTime(dateTime);
    liveInfoService.save(liveInfo);
    return ApiResponse.ofSuccess(liveInfo);
}
Also used : LocalDateTime(java.time.LocalDateTime) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Room(cn.imhtb.antlive.entity.Room) LiveInfo(cn.imhtb.antlive.entity.LiveInfo)

Example 5 with LiveInfo

use of cn.imhtb.antlive.entity.LiveInfo in project Ant-Live by PinTeh.

the class LiveController method done.

@RequestMapping("/on_done")
public ApiResponse done(String name) {
    Integer roomId = Integer.valueOf(name);
    Room room = new Room();
    room.setId(roomId);
    room.setStatus(Constants.LiveStatus.STOP.getCode());
    roomService.updateById(room);
    // 更新直播信息
    LiveInfo liveInfo = liveInfoService.getOne(new QueryWrapper<LiveInfo>().eq("room_id", roomId).orderByDesc("id").last("limit 0,1"));
    if (liveInfo.getEndTime() != null) {
        // TODO
        return ApiResponse.ofSuccess();
    }
    liveInfo.setEndTime(LocalDateTime.now());
    liveInfo.setStatus(1);
    liveInfoService.updateById(liveInfo);
    return ApiResponse.ofSuccess();
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Room(cn.imhtb.antlive.entity.Room) LiveInfo(cn.imhtb.antlive.entity.LiveInfo)

Aggregations

LiveInfo (cn.imhtb.antlive.entity.LiveInfo)7 Room (cn.imhtb.antlive.entity.Room)5 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)5 LiveStatResponse (cn.imhtb.antlive.vo.response.LiveStatResponse)2 LocalDateTime (java.time.LocalDateTime)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 BanRecord (cn.imhtb.antlive.entity.database.BanRecord)1 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1