Search in sources :

Example 26 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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 27 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project Ant-Live by PinTeh.

the class AlipayServiceImpl method trans.

@Override
public void trans(String outTradeNo, Integer virtualAmount, String uid, String identity, String identityName) throws AlipayApiException {
    /* 开心果 与 金豆 转换率 10:1  提现比例 2 : 1 */
    int realTransAmount = Math.abs(virtualAmount / 10 / 2);
    AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
    request.setBizContent("{" + "\"out_biz_no\":\"" + outTradeNo + "\"," + "\"trans_amount\":" + realTransAmount + "," + "\"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," + "\"biz_scene\":\"DIRECT_TRANSFER\"," + "\"order_title\":\"Live直播开心果提现\"," + "\"payee_info\":{" + "\"identity\":\"" + identity + "\"," + "\"identity_type\":\"ALIPAY_LOGON_ID\"," + "\"name\":\"" + identityName + "\"," + "    }," + "\"remark\":\"Live直播提现备注\"," + "\"business_params\":\"{\\\"payer_show_name\\\":\\\"PinTeh Live\\\"}\"," + "  }");
    AlipayFundTransUniTransferResponse response = client.certificateExecute(request);
    if (response.isSuccess()) {
        // Bill (insert record)
        Bill last = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", uid).orderByDesc("id").last("limit 0,1"));
        BigDecimal virtualBigDecimal = new BigDecimal(virtualAmount);
        BigDecimal ret = last.getBalance().subtract(virtualBigDecimal);
        if (ret.compareTo(BigDecimal.ZERO) < 0) {
            // Balance not enough
            return;
        }
        Bill bill = new Bill();
        bill.setBillChange(virtualBigDecimal.negate());
        bill.setType(1);
        bill.setUserId(Integer.valueOf(uid));
        bill.setBalance(ret);
        bill.setMark("提现");
        bill.setOrderNo(outTradeNo);
        billMapper.insert(bill);
        log.info("[billMapper] insert success");
        // Settle account info (insert)
        Withdrawal withdrawal = new Withdrawal();
        withdrawal.setIdentity(identity);
        withdrawal.setIdentityName(identityName);
        withdrawal.setMark("提现");
        withdrawal.setStatus(1);
        withdrawal.setType(Constants.PayPlatform.ALIPAY.getDesc());
        withdrawal.setVirtualAmount(virtualBigDecimal);
        withdrawal.setRealAmount(new BigDecimal(realTransAmount));
        withdrawal.setUserId(Integer.valueOf(uid));
        withdrawalMapper.insert(withdrawal);
        log.info("[withdrawalMapper] insert success");
        log.info("[alipay] call success");
    } else {
        log.info("[alipay] call fail");
    }
}
Also used : AlipayFundTransUniTransferResponse(com.alipay.api.response.AlipayFundTransUniTransferResponse) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Withdrawal(cn.imhtb.antlive.entity.database.Withdrawal) AlipayFundTransUniTransferRequest(com.alipay.api.request.AlipayFundTransUniTransferRequest) Bill(cn.imhtb.antlive.entity.Bill) BigDecimal(java.math.BigDecimal)

Example 28 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project Ant-Live by PinTeh.

the class MenuServiceImpl method listMenusTree.

private List<FrontMenuItem> listMenusTree(List<Menu> menus, List<Integer> menuIds, Integer hidden) {
    List<FrontMenuItem> list = new LinkedList<>();
    menus.forEach(v -> {
        if (v != null) {
            List<Menu> childList = menuMapper.selectList(new QueryWrapper<Menu>().eq("pid", v.getId()).eq(hidden != null, "hidden", hidden).orderByAsc("sort"));
            if (menuIds == null || menuIds.contains(v.getId())) {
                FrontMenuItem menuItem = new FrontMenuItem();
                menuItem.setId(v.getId());
                menuItem.setLabel(v.getTitle());
                menuItem.setIndex(v.getMenuIndex());
                menuItem.setIcon(v.getIcon());
                menuItem.setPath(v.getPath());
                menuItem.setHidden(v.getHidden());
                menuItem.setSort(v.getSort());
                menuItem.setPid(v.getPid());
                if (childList != null && childList.size() != 0) {
                    menuItem.setChildren(listMenusTree(childList, menuIds, hidden));
                }
                list.add(menuItem);
            }
        }
    });
    return list;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) FrontMenuItem(cn.imhtb.antlive.vo.FrontMenuItem) RoleMenu(cn.imhtb.antlive.entity.database.RoleMenu) Menu(cn.imhtb.antlive.entity.database.Menu)

Example 29 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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 30 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper 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)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30