|
@@ -1,5 +1,6 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -8,6 +9,7 @@ import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.biz.dal.dao.ImLiveRoomReservationDao;
|
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+import com.ym.mec.biz.dal.entity.ImLiveBroadcastRoom;
|
|
|
import com.ym.mec.biz.dal.entity.ImLiveRoomReservation;
|
|
|
import com.ym.mec.biz.dal.enums.MessageTypeEnum;
|
|
|
import com.ym.mec.biz.dal.vo.ImLiveBroadcastRoomVo;
|
|
@@ -19,6 +21,7 @@ import com.ym.mec.common.page.PageInfo;
|
|
|
import com.ym.mec.common.page.PageUtil;
|
|
|
import com.ym.mec.common.tenant.TenantContextHolder;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -27,6 +30,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
/**
|
|
|
* 直播预约记录(ImLiveRoomReservation)表服务实现类
|
|
@@ -37,7 +41,7 @@ import java.util.*;
|
|
|
@Service("imLiveRoomReservationService")
|
|
|
public class ImLiveRoomReservationServiceImpl extends ServiceImpl<ImLiveRoomReservationDao, ImLiveRoomReservation> implements ImLiveRoomReservationService {
|
|
|
|
|
|
- private final static Logger logger = LoggerFactory.getLogger(ImLiveRoomReservationServiceImpl.class);
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(ImLiveRoomReservationServiceImpl.class);
|
|
|
|
|
|
@Autowired
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
@@ -57,7 +61,7 @@ public class ImLiveRoomReservationServiceImpl extends ServiceImpl<ImLiveRoomRese
|
|
|
optional.filter(a -> Objects.nonNull(a.getUserId())).orElseThrow(() -> new BizException("学员id不能为空"));
|
|
|
entity.setPushState(-1);
|
|
|
entity.setCreateTime(new Date());
|
|
|
- this.baseMapper.insert(entity);
|
|
|
+ this.saveOrUpdate(entity);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -87,10 +91,51 @@ public class ImLiveRoomReservationServiceImpl extends ServiceImpl<ImLiveRoomRese
|
|
|
return PageUtil.pageInfo(page);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 预约直播间推送极光
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void push(ImLiveBroadcastRoom room) {
|
|
|
+ List<ImLiveRoomReservation> list = this.list(Wrappers.<ImLiveRoomReservation>lambdaQuery()
|
|
|
+ .eq(ImLiveRoomReservation::getRoomUid, room.getRoomUid())
|
|
|
+ .eq(ImLiveRoomReservation::getPushState, -1));
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SysUser user = getUser(room.getSpeakerId());
|
|
|
+ String baseUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
|
|
|
+ String memo = "10?" + baseUrl + "/#/live?roomUid=" + room.getRoomUid();
|
|
|
+ Map<Integer, String> pushStudentList = new HashMap<>();
|
|
|
+ for (ImLiveRoomReservation obj : list) {
|
|
|
+ pushStudentList.put(obj.getUserId(), obj.getUserId().toString());
|
|
|
+ }
|
|
|
+ //推送状态
|
|
|
+ AtomicInteger pushState = new AtomicInteger(0);
|
|
|
+ try {
|
|
|
+ // 约直播间通知发送
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.JIGUANG_LIVE_RESERVATION, pushStudentList,
|
|
|
+ null, 0, memo, "STUDENT", user.getUsername(), room.getRoomTitle());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("推送消息失败", e);
|
|
|
+ pushState.set(1);
|
|
|
+ }
|
|
|
+ log.info("ImLiveRoomReservation push >>> state:{} |>>>> memo:{} |>>>> studentList :{} |>>>> username:{} |>>>>room:{}", pushState.get(), memo, pushStudentList, user.getUsername(), JSONObject.toJSONString(room));
|
|
|
+ //修改推送状态
|
|
|
+ this.update(Wrappers.<ImLiveRoomReservation>lambdaUpdate()
|
|
|
+ .set(ImLiveRoomReservation::getPushState, pushState.get())
|
|
|
+ .eq(ImLiveRoomReservation::getRoomUid, room.getRoomUid()));
|
|
|
+ }
|
|
|
+
|
|
|
private SysUser getUser() {
|
|
|
return Optional.ofNullable(sysUserFeignService.queryUserInfo())
|
|
|
.orElseThrow(() -> new BizException("用户信息获取失败,请刷新页面或者重新登录!"));
|
|
|
}
|
|
|
|
|
|
+ private SysUser getUser(Integer userId) {
|
|
|
+ return Optional.ofNullable(userId)
|
|
|
+ .map(sysUserFeignService::queryUserById)
|
|
|
+ .orElseThrow(() -> new BizException("用户不存在"));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|