Search in sources :

Example 1 with Room

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

the class PresentRewardRewardServiceImpl method createReward.

@Override
public boolean createReward(Integer fromId, Integer presentId, Integer rvId, Integer number, Integer type) {
    String mark = null;
    Integer toId = null;
    Room room;
    Present present = presentMapper.selectById(presentId);
    BigDecimal totalPrice = present.getPrice().multiply(new BigDecimal(number));
    Bill fromLast = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", fromId).orderByDesc("id").last("limit 0,1"));
    BigDecimal ret = fromLast.getBalance().subtract(totalPrice);
    // 余额不足
    if (ret.compareTo(BigDecimal.ZERO) < 0) {
        log.info("余额不足");
        return false;
    }
    PresentReward presentReward = new PresentReward();
    if (type.equals(Constants.PresentRewardType.LIVE.getCode())) {
        room = roomMapper.selectById(rvId);
        toId = room.getUserId();
        presentReward.setRoomId(room.getId());
        presentReward.setType(Constants.PresentRewardType.LIVE.getCode());
        mark = Constants.BillMark.LIVE_REWARD.getDesc();
        // 直播间显示赠送礼物信息
        try {
            // TODO 逻辑有点问题
            String key = String.format(RedisPrefix.LIVE_KEY_PREFIX, room.getId());
            if (redisUtils.exists(key)) {
                // 舍去小数点
                redisUtils.hIncrBy(key, RedisPrefix.LIVE_PRESENT_COUNT, totalPrice.longValue());
            }
            User fromUser = userMapper.selectById(fromId);
            WebMessage webMessage = WebMessage.createPresent(fromUser, new WebMessage.P(present.getId(), present.getName(), present.getIcon(), number));
            roomChatServer.sendSystemPresentMessage(webMessage.toJson(), room.getId());
        } catch (Exception e) {
            log.error("RoomChatServer err:{}", e.getMessage());
        }
    } else if (type.equals(Constants.PresentRewardType.VIDEO.getCode())) {
        Video video = videoMapper.selectById(rvId);
        toId = video.getUserId();
        presentReward.setVideoId(video.getId());
        presentReward.setType(Constants.PresentRewardType.VIDEO.getCode());
        mark = Constants.BillMark.VIDEO_REWARD.getDesc();
    }
    presentReward.setNumber(number);
    presentReward.setUnitPrice(present.getPrice());
    presentReward.setFromId(fromId);
    presentReward.setToId(toId);
    presentReward.setPresentId(present.getId());
    presentReward.setTotalPrice(totalPrice);
    Bill toLast = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", toId).orderByDesc("id").last("limit 0,1"));
    Bill fromBill = new Bill();
    fromBill.setBillChange(totalPrice.negate());
    fromBill.setBalance(fromLast.getBalance().subtract(totalPrice));
    fromBill.setMark(mark);
    fromBill.setType(Constants.BillType.OUTLAY.getCode());
    fromBill.setBillChange(totalPrice.negate());
    fromBill.setUserId(fromId);
    fromBill.setOrderNo(CommonUtils.getOrderNo());
    Bill toBill = new Bill();
    toBill.setBillChange(totalPrice);
    toBill.setBalance(toLast.getBalance().add(totalPrice));
    toBill.setMark(mark);
    toBill.setType(Constants.BillType.INCOME.getCode());
    toBill.setBillChange(totalPrice);
    toBill.setUserId(toId);
    toBill.setOrderNo(CommonUtils.getOrderNo());
    int rf = presentRewardMapper.insert(presentReward);
    int rs = billMapper.insert(fromBill);
    int rt = billMapper.insert(toBill);
    return rf == 1 && rs == 1 && rt == 1;
}
Also used : User(cn.imhtb.antlive.entity.User) PresentReward(cn.imhtb.antlive.entity.database.PresentReward) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BigDecimal(java.math.BigDecimal) Video(cn.imhtb.antlive.entity.database.Video) Bill(cn.imhtb.antlive.entity.Bill) Present(cn.imhtb.antlive.entity.Present) Room(cn.imhtb.antlive.entity.Room) WebMessage(cn.imhtb.antlive.server.WebMessage)

Example 2 with Room

use of cn.imhtb.antlive.entity.Room 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 Room

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

the class LiveController method publish.

/**
 * nginx授权认证
 */
@RequestMapping("/on_publish")
public ApiResponse publish(String name, String key, HttpServletResponse response) {
    Integer roomId = Integer.valueOf(name);
    Room room = roomService.getById(roomId);
    if (room != null) {
        if (key.equals(room.getSecret())) {
            return ApiResponse.ofSuccess();
        }
    }
    response.setStatus(400);
    return ApiResponse.ofError();
}
Also used : Room(cn.imhtb.antlive.entity.Room)

Example 4 with Room

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

the class LiveController method config.

/**
 * 更新直播间信息
 */
@PostMapping("/config")
public ApiResponse config(@RequestBody RoomRequest request) {
    Room room = modelMapper.map(request, Room.class);
    roomService.updateById(room);
    return ApiResponse.ofSuccess(room);
}
Also used : Room(cn.imhtb.antlive.entity.Room)

Example 5 with Room

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

the class RoomController method saveInfo.

@PostMapping("/info/save")
public ApiResponse saveInfo(@RequestBody RoomInfoSaveRequest request, HttpServletRequest r) {
    Integer uid = JwtUtils.getId(r);
    Room one = roomService.getOne(new QueryWrapper<Room>().eq("user_id", uid).last("limit 0,1"));
    if (one == null) {
        return ApiResponse.ofError();
    }
    Room room = new Room();
    room.setId(one.getId());
    room.setTitle(request.getTitle());
    room.setCover(request.getCover());
    room.setCategoryId(request.getCid());
    room.setNotice(request.getNotice());
    roomService.updateById(room);
    return ApiResponse.ofSuccess();
}
Also used : Room(cn.imhtb.antlive.entity.Room)

Aggregations

Room (cn.imhtb.antlive.entity.Room)16 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)9 LiveInfo (cn.imhtb.antlive.entity.LiveInfo)5 HashMap (java.util.HashMap)5 ArrayList (java.util.ArrayList)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 LocalDate (java.time.LocalDate)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AuthInfo (cn.imhtb.antlive.entity.AuthInfo)1 Bill (cn.imhtb.antlive.entity.Bill)1 Present (cn.imhtb.antlive.entity.Present)1 User (cn.imhtb.antlive.entity.User)1 PresentReward (cn.imhtb.antlive.entity.database.PresentReward)1 StatisticSpeak (cn.imhtb.antlive.entity.database.StatisticSpeak)1 StatisticView (cn.imhtb.antlive.entity.database.StatisticView)1 Video (cn.imhtb.antlive.entity.database.Video)1 WebMessage (cn.imhtb.antlive.server.WebMessage)1 LiveBanResponse (cn.imhtb.antlive.vo.response.LiveBanResponse)1 LiveStatResponse (cn.imhtb.antlive.vo.response.LiveStatResponse)1 WatchResponse (cn.imhtb.antlive.vo.response.WatchResponse)1