Commit d446c542 by 胡涛

打日志 直播状态

parent 99652083
......@@ -17,19 +17,16 @@ import com.yizhi.application.orm.util.QueryUtil;
import com.yizhi.core.application.cache.RedisCache;
import com.yizhi.core.application.context.ContextHolder;
import com.yizhi.core.application.context.RequestContext;
import com.yizhi.core.application.enums.InternationalEnums;
import com.yizhi.core.application.enums.TaskParamsEnums;
import com.yizhi.core.application.task.AbstractTaskHandler;
import com.yizhi.core.application.task.TaskExecutor;
import com.yizhi.core.application.vo.DroolsVo;
import com.yizhi.live.application.constant.LiveStatusEnum;
import com.yizhi.live.application.constant.PolyvResponseVO;
import com.yizhi.live.application.constant.PolyvUpdatePO;
import com.yizhi.live.application.constant.UtilConstants;
import com.yizhi.live.application.domain.LiveActivity;
import com.yizhi.live.application.domain.LiveReplay;
import com.yizhi.live.application.domain.ScopeAuthorization;
import com.yizhi.live.application.enums.LiveStatus;
import com.yizhi.live.application.enums.LiveStatusV2;
import com.yizhi.live.application.enums.PolyvReqEnum;
import com.yizhi.live.application.mapper.LiveActivityMapper;
......@@ -46,7 +43,6 @@ import com.yizhi.util.application.date.DateUtil;
import com.yizhi.util.application.domain.BizResponse;
import com.yizhi.util.application.page.PageInfo;
import com.yizhi.util.application.page.PageParam;
import jdk.nashorn.internal.codegen.ObjectClassGenerator;
import org.apache.ibatis.session.RowBounds;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -80,8 +76,6 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Value("${ACTIVE}")
public String active;
@Autowired
LiveUtil liveUtil;
@Autowired
ScopeAuthorizationMapper scopeAuthorizationMapper;
@Autowired
IdGenerator idGenerator;
......@@ -91,10 +85,8 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
private LiveEvenSendMessage liveEvenSendMessage;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private IScopeAuthorizationService scopeAuthorizationService;
@Autowired
RedisCache redisCache;
@Autowired
......@@ -104,9 +96,9 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public String createChanel(Map<String, String> params) {
String sign = liveUtil.generateSign(params, UtilConstants.APP_SECRET);
String sign = LiveUtil.generateSign(params, UtilConstants.APP_SECRET);
params.put("sign", sign);
String result = liveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL, params);
String result = LiveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL, params);
return result;
}
......@@ -114,18 +106,18 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
public List<LiveActivity> findWithinSevenDaysLive(Long companyId, Long siteId, Long accountId) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, -6);
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
// 分级授权修改
// LOG.info("分级授权开始 ------------------------------------------");
//HQueryUtil.startHQ(LiveActivity.class);
// 基础查询条件
EntityWrapper<LiveActivity> ew = QueryUtil.condition(new LiveActivity());
ew.eq("company_id",companyId).eq("site_id",siteId)
.eq("create_by_id",accountId)
.eq("shelves",1)
ew.eq("company_id", companyId).eq("site_id", siteId)
.eq("create_by_id", accountId)
.eq("shelves", 1)
.between("end_time", calendar.getTime(), Calendar.getInstance().getTime());
......@@ -136,29 +128,29 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
public Page<PageLiveVo> searchPage(String title, String startTimeString,
String endTimeString, Long companyId, Long siteId,
List<Long> orgIds, int pageNo, int pageSize,
String expTimeString, Integer status, Integer viewType,Boolean startTimeAsc,Boolean endTimeAsc) {
LOG.info("转换前直播列表 查询参数:startTimeString={},endTimeString={},expTimeString",startTimeString,endTimeString,expTimeString);
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date startTime=null;
Date endTime=null;
Date expTime=null;
try {
if(!StringUtils.isEmpty(startTimeString)) {
startTime=sim.parse(startTimeString);
}
if(!StringUtils.isEmpty(endTimeString)) {
endTime=sim.parse(endTimeString);
}
if(!StringUtils.isEmpty(expTimeString)) {
expTime=sim.parse(expTimeString);
}
} catch (ParseException e) {
LOG.info("直播列表日期转换错误",e);
}
LOG.info("转换后直播列表 查询参数:startTime={},endTime={},expTime",startTime,endTime,expTime);
String expTimeString, Integer status, Integer viewType, Boolean startTimeAsc, Boolean endTimeAsc) {
LOG.info("转换前直播列表 查询参数:startTimeString={},endTimeString={},expTimeString", startTimeString, endTimeString, expTimeString);
SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date startTime = null;
Date endTime = null;
Date expTime = null;
try {
if (!StringUtils.isEmpty(startTimeString)) {
startTime = sim.parse(startTimeString);
}
if (!StringUtils.isEmpty(endTimeString)) {
endTime = sim.parse(endTimeString);
}
if (!StringUtils.isEmpty(expTimeString)) {
expTime = sim.parse(expTimeString);
}
} catch (ParseException e) {
LOG.info("直播列表日期转换错误", e);
}
LOG.info("转换后直播列表 查询参数:startTime={},endTime={},expTime", startTime, endTime, expTime);
Page<PageLiveVo> page = new Page<PageLiveVo>(pageNo, pageSize);
// 分页信息
......@@ -175,58 +167,58 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
LOG.info("分级授权开始 ------------------------------------------");
HQueryUtil.startHQ(LiveActivity.class);
LOG.info("直播列表 查询参数:startTime={},endTime={}",startTime,endTime);
LOG.info("直播列表 查询参数:startTime={},endTime={}", startTime, endTime);
if (null != startTime && null != endTime && (endTime.getTime() > startTime.getTime())) {
ew.ge("start_time", startTime).and().le("end_time", endTime);
}else {
if(expTime!=null){
} else {
if (expTime != null) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,0);
calendar.set(Calendar.MINUTE,0);
calendar.set(Calendar.SECOND,0);
calendar.set(Calendar.MILLISECOND,0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
LOG.info("开始时间={},结束时间={}",simpleDateFormat.format(expTime),simpleDateFormat.format(calendar.getTime()));
ew.le("start_time",expTime).ge("end_time",calendar.getTime());
LOG.info("开始时间={},结束时间={}", simpleDateFormat.format(expTime), simpleDateFormat.format(calendar.getTime()));
ew.le("start_time", expTime).ge("end_time", calendar.getTime());
}
}
if(Objects.nonNull(viewType)){
ew.eq("view_type",viewType);
if (Objects.nonNull(viewType)) {
ew.eq("view_type", viewType);
}
if(Objects.nonNull(status)){
ew.eq("shelves",status);
if (Objects.nonNull(status)) {
ew.eq("shelves", status);
}
if(!StringUtils.isEmpty(title)){
if (!StringUtils.isEmpty(title)) {
ew.andNew().
like("title", title, SqlLike.DEFAULT)
.or().like("channel", title, SqlLike.DEFAULT)
.or().like("keywords", title);
}
if (null == startTimeAsc && null == endTimeAsc){
if (null == startTimeAsc && null == endTimeAsc) {
//当开始和结束时间排序都不传递的时候;默认按照创建时间倒叙;
ew.orderBy("create_time",false);
}else {
if (null != startTimeAsc){
ew.orderBy("start_time",startTimeAsc);
}else if (null != endTimeAsc){
ew.orderBy("end_time",endTimeAsc);
ew.orderBy("create_time", false);
} else {
if (null != startTimeAsc) {
ew.orderBy("start_time", startTimeAsc);
} else if (null != endTimeAsc) {
ew.orderBy("end_time", endTimeAsc);
}
}
Page<LiveActivity> retList = this.selectPage(PageUtil.vice(pageParam),ew);
Page<LiveActivity> retList = this.selectPage(PageUtil.vice(pageParam), ew);
// 复制结果到返回变量
BeanUtils.copyProperties(retList,page,"records");
BeanUtils.copyProperties(retList, page, "records");
List<LiveActivity> data = retList.getRecords();
if(CollectionUtils.isEmpty(data)){
if (CollectionUtils.isEmpty(data)) {
return page;
}
// 获取全部的房间号
String channelIds = data.stream().map(p -> p.getChannel()).collect(Collectors.joining(","));
String channelIds = data.stream().map(p -> p.getChannel()).collect(Collectors.joining(","));
// 调用第三方获取房间状态
List<PageLiveVo> retData = new ArrayList<>();
data.stream().forEach(obj -> {
PageLiveVo vo = new PageLiveVo();
BeanUtils.copyProperties(obj,vo);
BeanUtils.copyProperties(obj, vo);
retData.add(vo);
});
page.setRecords(retData);
......@@ -239,10 +231,10 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
params.put("userId", UtilConstants.APP_USER_ID);
String sign = liveUtil.generateSign(params, UtilConstants.APP_SECRET);
String sign = LiveUtil.generateSign(params, UtilConstants.APP_SECRET);
params.put("sign", sign);
try {
String result = liveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL + "/" + chanel + "/delete", params);
String result = LiveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL + "/" + chanel + "/delete", params);
JSONObject obj = JSON.parseObject(result);
String code = obj.getString("code");
if ("200".equals(code)) {
......@@ -262,11 +254,11 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put("appId", UtilConstants.APP_ID);
params.put("token", token);
params.put("timestamp", System.currentTimeMillis() + "");
String sign = liveUtil.generateSign(params, UtilConstants.APP_SECRET);
String sign = LiveUtil.generateSign(params, UtilConstants.APP_SECRET);
params.put("sign", sign);
try {
String result = liveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL + "/" + chanel + "/set-token", params);
String result = LiveUtil.sendHttpPost(UtilConstants.CREATE_CHANNEL_URL + "/" + chanel + "/set-token", params);
JSONObject obj = JSON.parseObject(result);
String code = obj.getString("code");
if ("200".equals(code)) {
......@@ -311,8 +303,8 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
public Page<PageLiveVo> apiSearchPageList(List<Long> relationIds, String title, Long companyId, Long siteId, int pageNo, int pageSize) {
List<Long> ids = null;
if (!StringUtils.isEmpty(relationIds)) {
Long accountId= ContextHolder.get().getAccountId();
relationIds.add(accountId);
Long accountId = ContextHolder.get().getAccountId();
relationIds.add(accountId);
ids = scopeAuthorizationMapper.selectLiveIdByRelationId(relationIds);
}
......@@ -330,28 +322,33 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
Map<String, String> statusMap = getStringStringMap(channelIds);
liveActivities.parallelStream().forEach(liveActivity-> {
LOG.info("保利威视返回信息:" + (statusMap != null ? statusMap.toString() : statusMap));
liveActivities.parallelStream().forEach(liveActivity -> {
if (statusMap.containsKey(liveActivity.getChannel())) {
// 直播回放
LiveStatusV2 status = PolyvUtils.getLiveStatus(liveActivity.getChannel(), liveActivity.getStartTime(), liveActivity.getEndTime(), null);
LOG.info("直播 channel:" + liveActivity.getChannel() + "名称:" + liveActivity.getTitle() + "查询到直播状态为" + status.toString());
liveActivity.setStatus(String.valueOf(status.getCode()));
if (LiveStatusV2.RUNNING.getCode().equals(status.getCode())){
if (LiveStatusV2.RUNNING.getCode().equals(status.getCode())) {
//添加直播在学人数
String channel = liveActivity.getChannel();
liveActivity.setOnlineCount(0);
try {
List<LiveOnlineCountVo> channelOnlineCountRealTime = getChannelOnlineCountRealTime(channel);
if (null != channelOnlineCountRealTime && channelOnlineCountRealTime.size() > 0){
if (null != channelOnlineCountRealTime && channelOnlineCountRealTime.size() > 0) {
LiveOnlineCountVo liveOnlineCountVo = channelOnlineCountRealTime.get(0);
Integer onlineCountVoCount = liveOnlineCountVo.getCount();
liveActivity.setOnlineCount(onlineCountVoCount);
}
} catch (JsonProcessingException e) {
LOG.error("查询直播在学人数异常: channel = {} ,companyId ={} ,siteId = {}",channel,companyId,siteId,e);
LOG.error("查询直播在学人数异常: channel = {} ,companyId ={} ,siteId = {}", channel, companyId, siteId, e);
}
}
} else {
LOG.error("直播 channel:" + liveActivity.getChannel() + "名称:" + liveActivity.getTitle() + "未在保利威视查询到!!!");
}
});
page.setRecords(liveActivities);
Integer count = this.baseMapper.apiSearchPageCount(ids, title, siteId, companyId);
......@@ -361,7 +358,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public Boolean saveLive(LiveActivityResultVO liveActivityResultVO) {
LOG.info("后台直播创建,携带活动那个参数{},可见范围信息{}",liveActivityResultVO.getLiveActivity(),liveActivityResultVO.getScopeAuthorizations());
LOG.info("后台直播创建,携带活动那个参数{},可见范围信息{}", liveActivityResultVO.getLiveActivity(), liveActivityResultVO.getScopeAuthorizations());
if (liveActivityResultVO.getLiveActivity() == null) {
LOG.info("LiveActivity直播活动表为空");
return false;
......@@ -379,22 +376,22 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put("channelPasswd", liveActivity.getPassword());
params.put("name", liveActivity.getTitle());
String scene = liveActivity.getScene();
if("ppt".equals(scene) || "topclass".equals(scene)){
if ("ppt".equals(scene) || "topclass".equals(scene)) {
}else {
} else {
scene = "alone";
}
params.put("scene", scene);
LOG.info("进入方法之前:参数params{},第二个参数{}",params,UtilConstants.CREATE_CHANNEL_URL);
String result = execPolyvApi(params,UtilConstants.CREATE_CHANNEL_URL);
LOG.info("进入方法之后:{}",result);
LOG.info("进入方法之前:参数params{},第二个参数{}", params, UtilConstants.CREATE_CHANNEL_URL);
String result = execPolyvApi(params, UtilConstants.CREATE_CHANNEL_URL);
LOG.info("进入方法之后:{}", result);
Map<String, Object> maps = new HashMap<String, Object>();
try {
maps = JsonUtil.parseJSON2Map(result);
if (maps.containsKey("data")) {
LOG.info("获取保利威直播频道号的结果={},请求参数={}",JSON.toJSONString(maps),JSON.toJSONString(params));
LOG.info("获取保利威直播频道号的结果={},请求参数={}", JSON.toJSONString(maps), JSON.toJSONString(params));
JSONObject jsonObject = (JSONObject) maps.get("data");
if (jsonObject.containsKey("channelId")) {
String channelId = jsonObject.get("channelId").toString();
......@@ -403,7 +400,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
//进行 自定义授权的配置 channelSetting(设置成授权观看)
String secretKey = channelSetting(jsonObject.get("channelId").toString());
if (StringUtils.isEmpty(secretKey)) {
LOG.info("secretKey 为空:{}",secretKey);
LOG.info("secretKey 为空:{}", secretKey);
return Boolean.FALSE;
}
liveActivity.setSecretKey(secretKey);
......@@ -412,37 +409,37 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
try {
Map<String, String> params1 = new HashMap<String, String>();
params1.put("appId",UtilConstants.APP_ID);
params1.put("appId", UtilConstants.APP_ID);
params1.put("timestamp", System.currentTimeMillis() + "");
// 之前未设置倒计时直播提示和直播时间的频道号,在开启倒计时开关时,必须提交countTips和startTime
//params1.put("countEnabled", "N");
params1.put("startTime", DateUtil.toSeconds(startTime));
String result1 = execPolyvApi(params1, String.format(UtilConstants.CHANNEL_STARTDATE_UPDATE,channelId));
String result1 = execPolyvApi(params1, String.format(UtilConstants.CHANNEL_STARTDATE_UPDATE, channelId));
Map<String, String> params2 = new HashMap<>();
params2.put("channelId", channelId);
//String body = "{\"authSettings\": [ {\"rank\":1,\"enabled\":\"Y\",\"authType\":\"custom\"} ] }";
if(liveActivity.getViewType() == 0){
if (liveActivity.getViewType() == 0) {
String body = "{\"authSettings\":[{\"rank\":1,\"enabled\":\"N\"}]}";
String result2 = LiveUtilPostUrlParam.sendPost(UtilConstants.LIVE_AUTH_UPDATE_URL,body,params2);
String result2 = LiveUtilPostUrlParam.sendPost(UtilConstants.LIVE_AUTH_UPDATE_URL, body, params2);
}
} catch (Exception e) {
LOG.info("新增直播 更新时间异常={}",e);
LOG.info("新增直播 更新时间异常={}", e);
}
}
}
} catch (Exception e) {
LOG.info("插入更新时间 异常:{}",e);
LOG.info("插入更新时间 异常:{}", e);
return Boolean.FALSE;
}
LiveActivity lt = new LiveActivity();
BeanUtils.copyProperties(liveActivity,lt);
LiveActivity lt = new LiveActivity();
BeanUtils.copyProperties(liveActivity, lt);
if(setOptions(lt, lt,true)){
if (setOptions(lt, lt, true)) {
LOG.info("设在参数异常");
return Boolean.FALSE;
}
......@@ -456,7 +453,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
scopeAuthorization1.setId(idGenerator.generate());
scopeAuthorization1.setSiteId(liveActivity.getSiteId());
}
scopeAuthorizationMapper.insertListVO(liveActivityResultVO.getScopeAuthorizations());
scopeAuthorizationMapper.insertListVO(liveActivityResultVO.getScopeAuthorizations());
}
}
LOG.info("直播是否设置了提醒:" + liveActivity.getEnableRemind());
......@@ -471,7 +468,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
}
});
} catch (Exception e) {
LOG.info("直播发消息异常:{}",e);
LOG.info("直播发消息异常:{}", e);
}
}
......@@ -482,15 +479,16 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
/**
* 调用保利威接口
*
* @param params
* @return
*/
private String execPolyvApi(Map<String, String> params,String apiUrl) {
private String execPolyvApi(Map<String, String> params, String apiUrl) {
String sign = getSign(params);
params.put("sign", sign);
//调用地三方接口创建直播 获得直播频道号
String result = liveUtil.sendHttpPost(apiUrl, params);
LOG.info("保利威返回 {};URL IS {}",result,apiUrl,params);
String result = LiveUtil.sendHttpPost(apiUrl, params);
LOG.info("保利威返回 {};URL IS {}", result, apiUrl, params);
System.out.println(result);
return result;
}
......@@ -503,10 +501,10 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
}
LiveActivityVO liveActivity = liveActivityResultVO.getLiveActivity();
LiveActivity updateLiveActivity = this.baseMapper.selectById(liveActivity.getId());
if(updateLiveActivity == null){
if (updateLiveActivity == null) {
return Boolean.FALSE;
}
if (liveActivity!=null){
if (liveActivity != null) {
updateLiveActivity.setEnableTask(liveActivity.getEnableTask());
}
......@@ -525,12 +523,12 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
updateLiveActivity.setReplayStatus(liveActivity.getReplayStatus());
Integer updateCount = this.baseMapper.updateById(updateLiveActivity);
if (updateCount == null || updateCount == 0 ) {
if (updateCount == null || updateCount == 0) {
return Boolean.TRUE;
}
Integer scope = liveActivity.getScope();
if(scope != null ){
if (scope != null) {
if (1 == updateLiveActivity.getScope() && liveActivityResultVO.getScopeAuthorizations().size() > 0) {
ScopeAuthorization scopeAuthorization = new ScopeAuthorization();
scopeAuthorization.setLiveId(updateLiveActivity.getId());
......@@ -570,22 +568,14 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
po.setPublisher(liveActivity.getAnchor());
po.setDesc(liveActivity.getDescription());
po.setStartTime(liveActivity.getStartTime().getTime());
PolyvUtils.updateChannelParams(updateLiveActivity.getChannel(),po,true,updateLiveActivity.getSecretKey(),getRedirectUrl());
PolyvUtils.updateChannelParams(updateLiveActivity.getChannel(), po, true, updateLiveActivity.getSecretKey(), getRedirectUrl());
return Boolean.TRUE;
}
public static void main(String[] args) {
//String secretKey = channelSetting(jsonObject.get("channelId").toString());
Map<String, String> params2 = new HashMap<>();
params2.put("channelId", "1077706");
params2.put("customUri", UtilConstants.UAT_LIVE_CUSTOM_URI);
//LiveUtilPostUrlNotParam.sendPost()
String result2 = LiveUtilPostUrlParam.sendPost(String.format(UtilConstants.LIVE_CHANNEL_SETTING_URL,UtilConstants.APP_USER_ID),null,params2);
System.out.println(result2);
}
private boolean setOptions(final LiveActivity liveActivity, LiveActivity updateLiveActivity, boolean addFlg) {
String title = liveActivity.getTitle();
if(title != null && !org.apache.commons.lang3.StringUtils.equals(title,updateLiveActivity.getTitle())){
if (title != null && !org.apache.commons.lang3.StringUtils.equals(title, updateLiveActivity.getTitle())) {
Map<String, String> params = new HashMap<String, String>();
params.put("appId", UtilConstants.APP_ID);
......@@ -593,49 +583,49 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put("name", title);
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_TITLE_NAME_UPDATE,
updateLiveActivity.getChannel()));
LOG.info("直播频道更新名称结果result={}",result);
if(org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result,"success")>=0){
LOG.info("直播频道更新名称结果result={}", result);
if (org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result, "success") >= 0) {
updateLiveActivity.setTitle(title);//直播主题
}else {
} else {
LOG.info("直播频道更新名称 失败");
return true;
}
}
String pwd = liveActivity.getPassword();
if(pwd != null && !org.apache.commons.lang3.StringUtils.equals(pwd,updateLiveActivity.getPassword())){
if (pwd != null && !org.apache.commons.lang3.StringUtils.equals(pwd, updateLiveActivity.getPassword())) {
Map<String, String> params = new HashMap<String, String>();
params.put("channelId", updateLiveActivity.getChannel());
params.put("appId",UtilConstants.APP_ID);
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
params.put("passwd", pwd);
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_PASSWD_UPDATE,UtilConstants.APP_USER_ID));
LOG.info("直播频道更新名称结果result={}",result);
if(org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result,"success")>=0){
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_PASSWD_UPDATE, UtilConstants.APP_USER_ID));
LOG.info("直播频道更新名称结果result={}", result);
if (org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result, "success") >= 0) {
updateLiveActivity.setPassword(pwd);//直播密码
}else {
} else {
LOG.info("直播频道更新密码 失败");
return true;
}
}
String logo = liveActivity.getLogoImage();
if(addFlg || (logo != null && !org.apache.commons.lang3.StringUtils.equals(logo,updateLiveActivity.getLogoImage()))){
if (addFlg || (logo != null && !org.apache.commons.lang3.StringUtils.equals(logo, updateLiveActivity.getLogoImage()))) {
updateLiveActivity.setLogoImage(logo);// 直播logo
}
String anchor = liveActivity.getAnchor();
if(addFlg || (anchor != null && !org.apache.commons.lang3.StringUtils.equals(anchor,updateLiveActivity.getAnchor()))){
if (addFlg || (anchor != null && !org.apache.commons.lang3.StringUtils.equals(anchor, updateLiveActivity.getAnchor()))) {
Map<String, String> params = new HashMap<String, String>();
params.put("channelId", updateLiveActivity.getChannel());
params.put("appId",UtilConstants.APP_ID);
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
params.put("publisher", anchor);//主持人姓名,不超过20个字符
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_ANCHOR_UPDATE,UtilConstants.APP_USER_ID));
LOG.info("直播频道更新主播名字结果result={}",result);
if(org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result,"success")>=0){
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_ANCHOR_UPDATE, UtilConstants.APP_USER_ID));
LOG.info("直播频道更新主播名字结果result={}", result);
if (org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result, "success") >= 0) {
updateLiveActivity.setAnchor(anchor); // 主播名称
}else {
} else {
LOG.info("直播频道更新主持人姓名 失败");
return true;
}
......@@ -643,53 +633,53 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
Date startTime = liveActivity.getStartTime();
Date dbStartTime = updateLiveActivity.getStartTime();
dbStartTime = dbStartTime==null?(new Date()):dbStartTime;
dbStartTime = dbStartTime == null ? (new Date()) : dbStartTime;
Date endTime = liveActivity.getEndTime();
if(addFlg || (startTime != null && startTime.compareTo(dbStartTime)!=0)){
if (addFlg || (startTime != null && startTime.compareTo(dbStartTime) != 0)) {
Map<String, String> params = new HashMap<String, String>();
params.put("appId",UtilConstants.APP_ID);
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
// 之前未设置倒计时直播提示和直播时间的频道号,在开启倒计时开关时,必须提交countTips和startTime
//params.put("countEnabled", "N");
params.put("startTime", DateUtil.toSeconds(startTime));
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_STARTDATE_UPDATE,updateLiveActivity.getChannel()));
LOG.info("直播频道更新开始时间结果result={}",result);
if(org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result,"success")>=0){
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_STARTDATE_UPDATE, updateLiveActivity.getChannel()));
LOG.info("直播频道更新开始时间结果result={}", result);
if (org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result, "success") >= 0) {
updateLiveActivity.setStartTime(startTime); //直播开始时间
}else {
} else {
LOG.info("直播频道更新开始时间 失败");
return true;
}
}
if(addFlg || endTime != null){
if (addFlg || endTime != null) {
updateLiveActivity.setEndTime(endTime);//直播结束时间
}
String desc = liveActivity.getDescription();
if(addFlg || (desc != null && !org.apache.commons.lang3.StringUtils.equals(desc,updateLiveActivity.getDescription()))){
if (addFlg || (desc != null && !org.apache.commons.lang3.StringUtils.equals(desc, updateLiveActivity.getDescription()))) {
Map<String, String> params = new HashMap<String, String>();
params.put("appId",UtilConstants.APP_ID);
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
params.put("content", desc);
params.put("menuType", "desc");
String result = execPolyvApi(params, String.format(UtilConstants.CHANNEL_DESC_UPDATE,
UtilConstants.APP_USER_ID,updateLiveActivity.getChannel()));
LOG.info("直播频道更新说明信息结果result={}",result);
if(org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result,"success")>=0){
UtilConstants.APP_USER_ID, updateLiveActivity.getChannel()));
LOG.info("直播频道更新说明信息结果result={}", result);
if (org.apache.commons.lang3.StringUtils.isNotBlank(result) && org.apache.commons.lang3.StringUtils.indexOf(result, "success") >= 0) {
updateLiveActivity.setDescription(desc);//直播介绍
}else {
} else {
LOG.info("直播频道更新说明信息 失败");
return true;
}
}
Integer scope = liveActivity.getScope();
if(scope != null){
if (scope != null) {
updateLiveActivity.setScope(scope);
}
if (liveActivity.getEnableRemind()!=null){
if (liveActivity.getEnableRemind() != null) {
updateLiveActivity.setEnableRemind(liveActivity.getEnableRemind());
}
......@@ -703,12 +693,12 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public Page<PageLiveVo> portalList2(String title, Date startTime, Date endTime,
Long companyId, Long siteId,
List<Long> orgId, int pageNo, int pageSize) {
Long companyId, Long siteId,
List<Long> orgId, int pageNo, int pageSize) {
Page<PageLiveVo> page = new Page<PageLiveVo>(pageNo, pageSize);
// 分级授权修改
HQueryUtil.startHQ(LiveActivity.class);
List<PageLiveVo> pageLiveVos = this.baseMapper.portalList2(title, startTime, endTime, companyId, siteId, orgId,page);
List<PageLiveVo> pageLiveVos = this.baseMapper.portalList2(title, startTime, endTime, companyId, siteId, orgId, page);
page.setRecords(pageLiveVos);
return page;
}
......@@ -723,18 +713,18 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
return this.baseMapper.portalList(title, startTime, endTime, companyId, siteId, orgId, new RowBounds(page.getOffset(), page.getLimit()));
}
private Map<String, String> getStringStringMap(String channelIds) {
private static Map<String, String> getStringStringMap(String channelIds) {
Map<String, String> statusMap = new HashMap<String, String>();
try {
Map<String, String> params = new HashMap<String, String>();
params.put("appId", UtilConstants.APP_ID);
params.put("timestamp", System.currentTimeMillis() + "");
params.put("channelIds", channelIds);
String sign = liveUtil.generateSign(params, UtilConstants.APP_SECRET);
String sign = LiveUtil.generateSign(params, UtilConstants.APP_SECRET);
params.put("sign", sign);
String result = liveUtil.sendHttpPost(UtilConstants.LIVE_STATUS_URL, params);
if (StringUtils.isEmpty(result)){
LOG.warn("获取频道直播状态异常;channelIds ={}",channelIds);
String result = LiveUtil.sendHttpPost(UtilConstants.LIVE_STATUS_URL, params);
if (StringUtils.isEmpty(result)) {
LOG.warn("获取频道直播状态异常;channelIds ={}", channelIds);
return statusMap;
}
JSONObject obj = JSON.parseObject(result);
......@@ -752,7 +742,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
return statusMap;
}
public String getRedirectUrl(){
public String getRedirectUrl() {
if ("dev".equals(active)) {
return UtilConstants.DEV_LIVE_CUSTOM_URI;
} else if ("sit".equals(active)) {
......@@ -784,7 +774,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
url.append(UtilConstants.LIVE_CHANNELSETTING_URL);
url.append(UtilConstants.APP_USER_ID);
url.append("/oauth-custom");
String result = liveUtil.sendHttpPost(url.toString(), map);
String result = LiveUtil.sendHttpPost(url.toString(), map);
JSONObject obj = JSON.parseObject(result);
LOG.info("channelSetting:" + result);
......@@ -825,50 +815,45 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
}
@Override
public VisibleRangeExport vsibleRangeExport(Long liveId) {
// TODO Auto-generated method stub
VisibleRangeExport visibleRangeExport = new VisibleRangeExport();
List<Long> accountIds = new ArrayList<Long>();
List<Long> orgIds = new ArrayList<Long>();
@Override
public VisibleRangeExport vsibleRangeExport(Long liveId) {
// TODO Auto-generated method stub
VisibleRangeExport visibleRangeExport=new VisibleRangeExport();
List<Long> accountIds=new ArrayList<Long>();
List<Long> orgIds=new ArrayList<Long>();
LiveActivity liveActivity=liveActivityMapper.selectById(liveId);
if(liveActivity!=null) {
visibleRangeExport.setBizId(liveActivity.getId());
visibleRangeExport.setBizName(liveActivity.getTitle());
}
List<ScopeAuthorization> listStudent=scopeAuthorizationService.listScopeAuthorization(liveId);
if(listStudent!=null&&listStudent.size()>0) {
ScopeAuthorization scopeAuthorization=null;
for (int i = 0; i < listStudent.size(); i++) {
scopeAuthorization=listStudent.get(i);
if(scopeAuthorization!=null&&scopeAuthorization.getType()!=null) {
if(scopeAuthorization.getType()==2) { //用户
accountIds.add(scopeAuthorization.getAccountId());
}
if(scopeAuthorization.getType()==1) { //部门
orgIds.add(scopeAuthorization.getAccountId());
}
}
visibleRangeExport.setAccountIds(accountIds);
visibleRangeExport.setOrgIds(orgIds);
}
}
LiveActivity liveActivity = liveActivityMapper.selectById(liveId);
if (liveActivity != null) {
visibleRangeExport.setBizId(liveActivity.getId());
visibleRangeExport.setBizName(liveActivity.getTitle());
}
List<ScopeAuthorization> listStudent = scopeAuthorizationService.listScopeAuthorization(liveId);
if (listStudent != null && listStudent.size() > 0) {
ScopeAuthorization scopeAuthorization = null;
for (int i = 0; i < listStudent.size(); i++) {
scopeAuthorization = listStudent.get(i);
if (scopeAuthorization != null && scopeAuthorization.getType() != null) {
if (scopeAuthorization.getType() == 2) { //用户
accountIds.add(scopeAuthorization.getAccountId());
}
if (scopeAuthorization.getType() == 1) { //部门
orgIds.add(scopeAuthorization.getAccountId());
}
}
visibleRangeExport.setAccountIds(accountIds);
visibleRangeExport.setOrgIds(orgIds);
}
}
LOG.info("直播ID:{},直播名字:{}",visibleRangeExport.getBizId(),visibleRangeExport.getBizName());
LOG.info("账号Id:{}",visibleRangeExport.getAccountIds());
LOG.info("部门Id:{}",visibleRangeExport.getOrgIds());
return visibleRangeExport;
}
LOG.info("直播ID:{},直播名字:{}", visibleRangeExport.getBizId(), visibleRangeExport.getBizName());
LOG.info("账号Id:{}", visibleRangeExport.getAccountIds());
LOG.info("部门Id:{}", visibleRangeExport.getOrgIds());
return visibleRangeExport;
}
@Override
public Boolean judgeScope(List<Long> relationId, Long liveId) {
......@@ -908,43 +893,43 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
return page;
}
@Override
public Page<LiveActivity> getPageLiveVoListNotIds(List<Long> ids, Long siteId, Integer pageNo, Integer pageSize) {
// TODO Auto-generated method stub
Page<LiveActivity> page=new Page<LiveActivity>(pageNo,pageSize);
LiveActivity liveActivity=new LiveActivity();
liveActivity.setSiteId(siteId);
liveActivity.setShelves(1);
EntityWrapper<LiveActivity> wrapper=new EntityWrapper<LiveActivity>(liveActivity);
if(!CollectionUtils.isEmpty(ids)) {
wrapper.notIn("id", ids);
}
wrapper.orderBy("create_time", false);
@Override
public Page<LiveActivity> getPageLiveVoListNotIds(List<Long> ids, Long siteId, Integer pageNo, Integer pageSize) {
// TODO Auto-generated method stub
Page<LiveActivity> page = new Page<LiveActivity>(pageNo, pageSize);
LiveActivity liveActivity = new LiveActivity();
liveActivity.setSiteId(siteId);
liveActivity.setShelves(1);
EntityWrapper<LiveActivity> wrapper = new EntityWrapper<LiveActivity>(liveActivity);
if (!CollectionUtils.isEmpty(ids)) {
wrapper.notIn("id", ids);
}
wrapper.orderBy("create_time", false);
HQueryUtil.startHQ(LiveActivity.class);
return this.selectPage(page, wrapper);
}
@Override
public Page<LiveActivity> LiveActivityByIds(List<Long> listIds, Integer pageNo, Integer pageSize) {
// TODO Auto-generated method stub
Page<LiveActivity> page=new Page<LiveActivity>(pageNo,pageSize);
LiveActivity liveActivity=new LiveActivity();
liveActivity.setShelves(1);
EntityWrapper<LiveActivity> wrapper=new EntityWrapper<LiveActivity>(liveActivity);
wrapper.orderBy("create_time", false);
if(!CollectionUtils.isEmpty(listIds)) {
wrapper.in("id", listIds);
}
return this.selectPage(page, wrapper);
}
return this.selectPage(page, wrapper);
}
@Override
public Page<LiveActivity> LiveActivityByIds(List<Long> listIds, Integer pageNo, Integer pageSize) {
// TODO Auto-generated method stub
Page<LiveActivity> page = new Page<LiveActivity>(pageNo, pageSize);
LiveActivity liveActivity = new LiveActivity();
liveActivity.setShelves(1);
EntityWrapper<LiveActivity> wrapper = new EntityWrapper<LiveActivity>(liveActivity);
wrapper.orderBy("create_time", false);
if (!CollectionUtils.isEmpty(listIds)) {
wrapper.in("id", listIds);
}
return this.selectPage(page, wrapper);
}
@Override
public Integer getLiveStatus(String channelId) {
LiveActivity liveActivity = new LiveActivity();
liveActivity.setChannel(channelId);
LiveActivity live = liveActivityMapper.selectOne(liveActivity);
LiveActivity live = liveActivityMapper.selectOne(liveActivity);
Integer liveStatus = live.getStatus();
// 获取直播状态
LiveStatusV2 liveStatusEnum = PolyvUtils.getLiveStatus(channelId, live.getStartTime(), live.getEndTime(), liveStatus);
......@@ -956,47 +941,47 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
Page<PageLiveVo> page = new Page<PageLiveVo>(pageNo, pageSize);
RequestContext context = ContextHolder.get();
Set<PageLiveVo> set = liveActivityMapper.queryLiveListByRelationIds(relationIds,context.getSiteId(),new RowBounds(page.getOffset(),page.getLimit()));
List<PageLiveVo> list = new ArrayList<>();
Set<PageLiveVo> set = liveActivityMapper.queryLiveListByRelationIds(relationIds, context.getSiteId(), new RowBounds(page.getOffset(), page.getLimit()));
List<PageLiveVo> list = new ArrayList<>();
list.addAll(set);
return list;
}
@Override
public List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId, List<Long> ids) {
// TODO Auto-generated method stub
List<Map<String, Object>> listMap=null;
//查询
LiveActivity live=new LiveActivity();
live.setCompanyId(companyId);
EntityWrapper<LiveActivity> wrapper=new EntityWrapper<LiveActivity>(live);
if(!CollectionUtils.isEmpty(ids)) {
wrapper.in("id", ids);
}
List<LiveActivity> listLive=this.selectList(wrapper);
//循环组装到输出对象
Map<String, Object> map=null;
if(!CollectionUtils.isEmpty(listLive)) {
listMap=new ArrayList<Map<String, Object>>();
for (LiveActivity c:listLive) {
map=new HashMap<String, Object>();
map.put("catalog", 3);
map.put("id", c.getId());
map.put("name", c.getTitle());
map.put("logo_url", c.getLogoImage());
listMap.add(map);
}
}
return listMap;
}
@Override
public List<Map<String, Object>> getServerByCompanyIdAndIds(Long companyId, List<Long> ids) {
// TODO Auto-generated method stub
List<Map<String, Object>> listMap = null;
//查询
LiveActivity live = new LiveActivity();
live.setCompanyId(companyId);
EntityWrapper<LiveActivity> wrapper = new EntityWrapper<LiveActivity>(live);
if (!CollectionUtils.isEmpty(ids)) {
wrapper.in("id", ids);
}
List<LiveActivity> listLive = this.selectList(wrapper);
//循环组装到输出对象
Map<String, Object> map = null;
if (!CollectionUtils.isEmpty(listLive)) {
listMap = new ArrayList<Map<String, Object>>();
for (LiveActivity c : listLive) {
map = new HashMap<String, Object>();
map.put("catalog", 3);
map.put("id", c.getId());
map.put("name", c.getTitle());
map.put("logo_url", c.getLogoImage());
listMap.add(map);
}
}
return listMap;
}
@Override
public Page<PageLiveVo> pcSearchPageList(List<Long> relationIds, String title, Long companyId, Long siteId, int pageNo, int pageSize) {
Set<Long> ids = null;
List<Long> idList = new ArrayList<>();
if (!StringUtils.isEmpty(relationIds)) {
ids = scopeAuthorizationMapper.selectLiveId(relationIds,siteId);//去重
for (Long a:ids) {
ids = scopeAuthorizationMapper.selectLiveId(relationIds, siteId);//去重
for (Long a : ids) {
idList.add(a);
}
}
......@@ -1004,7 +989,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
Page<PageLiveVo> page = new Page<PageLiveVo>(pageNo, pageSize);
List<PageLiveVo> liveActivities = this.baseMapper.apiSearchPage(idList, title, siteId, companyId, page);
String channelIds = "";
if(!CollectionUtils.isEmpty(liveActivities)){
if (!CollectionUtils.isEmpty(liveActivities)) {
for (PageLiveVo liveActivity : liveActivities) {
if ("".equals(channelIds)) {
channelIds = liveActivity.getChannel();
......@@ -1014,25 +999,25 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
}
Map<String, String> statusMap = getStringStringMap(channelIds);
liveActivities.parallelStream().forEach(liveActivity-> {
liveActivities.parallelStream().forEach(liveActivity -> {
if (statusMap.containsKey(liveActivity.getChannel())) {
// 直播回放
LiveStatusV2 status = PolyvUtils.getLiveStatus(liveActivity.getChannel(), liveActivity.getStartTime(), liveActivity.getEndTime(), null);
liveActivity.setStatus(String.valueOf(status.getCode()));
if (LiveStatusV2.RUNNING.getCode().equals(status.getCode())){
if (LiveStatusV2.RUNNING.getCode().equals(status.getCode())) {
//添加直播在学人数
String channel = liveActivity.getChannel();
liveActivity.setOnlineCount(0);
try {
List<LiveOnlineCountVo> channelOnlineCountRealTime = getChannelOnlineCountRealTime(channel);
if (null != channelOnlineCountRealTime && channelOnlineCountRealTime.size() > 0){
if (null != channelOnlineCountRealTime && channelOnlineCountRealTime.size() > 0) {
LiveOnlineCountVo liveOnlineCountVo = channelOnlineCountRealTime.get(0);
Integer onlineCountVoCount = liveOnlineCountVo.getCount();
liveActivity.setOnlineCount(onlineCountVoCount);
}
} catch (JsonProcessingException e) {
LOG.error("查询直播在学人数异常: channel = {} ,companyId ={} ,siteId = {}",channel,companyId,siteId,e);
LOG.error("查询直播在学人数异常: channel = {} ,companyId ={} ,siteId = {}", channel, companyId, siteId, e);
}
}
}
......@@ -1054,12 +1039,12 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
//根据可见范围获取直播ids
List<Long> trIds = new ArrayList<>();
if (!CollectionUtils.isEmpty(context.getRelationIds())){
if (!CollectionUtils.isEmpty(context.getRelationIds())) {
trIds = scopeAuthorizationMapper.getUsefulIds(ids, context.getRelationIds(), context.getSiteId());
}
List<PageLiveVo> liveActivities = liveActivityMapper.getPageToCalendar(null, trIds, date, context.getSiteId(), page);
if (!CollectionUtils.isEmpty(liveActivities)){
if (!CollectionUtils.isEmpty(liveActivities)) {
liveActivities = buildLiveStatus(liveActivities);
}
......@@ -1071,10 +1056,11 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
/**
* 获取直播状态
*
* @param liveActivities
* @return
*/
public List<PageLiveVo> buildLiveStatus(List<PageLiveVo> liveActivities){
public List<PageLiveVo> buildLiveStatus(List<PageLiveVo> liveActivities) {
String channelIds = "";
for (PageLiveVo liveActivity : liveActivities) {
......@@ -1124,19 +1110,19 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
public List<LiveOnlineCountVo> getChannelOnlineCountRealTime(String channelIds) throws JsonProcessingException {
List<LiveOnlineCountVo> countVoList = new ArrayList<>();
if (StringUtils.isEmpty(channelIds)){
if (StringUtils.isEmpty(channelIds)) {
LOG.warn("查询直播实时在线人数;参数频道id为空");
return countVoList;
}
//存储获取到的频道-频道在学人数的map
Map<String,LiveOnlineCountVo> map = new HashMap<>();
Map<String, LiveOnlineCountVo> map = new HashMap<>();
//缓存数据到redis 接口请求有限制
String hKey = "live_online_";
List<String> noCacheChannelIds = new ArrayList<>();
getRedisCache(channelIds, map, hKey, noCacheChannelIds);
if (noCacheChannelIds.isEmpty()){
if (noCacheChannelIds.isEmpty()) {
//全部命中缓存
map.forEach((k,v) -> {
map.forEach((k, v) -> {
countVoList.add(v);
});
LOG.info("全部命中缓存");
......@@ -1146,9 +1132,9 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
String noCacheChannelIdsStr = noCacheChannelIds.stream().collect(Collectors.joining(","));
//组装参数
String result = getOnlineResult(noCacheChannelIdsStr);
LOG.info("批量获取频道实时在线人数;返回结果: {}",result);
LOG.info("批量获取频道实时在线人数;返回结果: {}", result);
//解析返回结果
if (StringUtils.isEmpty(result)){
if (StringUtils.isEmpty(result)) {
LOG.error("批量获取频道实时在线人数相应值为空!");
return countVoList;
}
......@@ -1156,30 +1142,30 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
PolyvResponseVo<List<LiveOnlineCountVo>> responseVo = mapper.readValue(result, new TypeReference<PolyvResponseVo<List<LiveOnlineCountVo>>>() {});
int code = responseVo.getCode();
List<LiveOnlineCountVo> data = responseVo.getData();
if (200 != code || null == data || data.isEmpty()){
LOG.error("批量获取频道实时在线人数失败;结果: {}",result);
if (200 != code || null == data || data.isEmpty()) {
LOG.error("批量获取频道实时在线人数失败;结果: {}", result);
return countVoList;
}
data.forEach(liveOnlineCountVo -> {
String channelId = liveOnlineCountVo.getChannelId();
String channelId = liveOnlineCountVo.getChannelId();
Integer onlineCount = liveOnlineCountVo.getCount();
if (map.containsKey(channelId)){
LiveOnlineCountVo oldVo = map.get(channelId);
Integer oldCount = oldVo.getCount();
if (null != oldCount && oldCount.compareTo(onlineCount) < 0){
map.put(channelId,liveOnlineCountVo);
redisCache.set(hKey+channelId,JSONObject.toJSONString(liveOnlineCountVo),20);
//LOG.info("放入缓存");
}
}else {
map.put(channelId,liveOnlineCountVo);
if (map.containsKey(channelId)) {
LiveOnlineCountVo oldVo = map.get(channelId);
Integer oldCount = oldVo.getCount();
if (null != oldCount && oldCount.compareTo(onlineCount) < 0) {
map.put(channelId, liveOnlineCountVo);
redisCache.set(hKey + channelId, JSONObject.toJSONString(liveOnlineCountVo), 20);
//LOG.info("放入缓存");
}
} else {
map.put(channelId, liveOnlineCountVo);
//放入缓存
redisCache.set(hKey+channelId,JSONObject.toJSONString(liveOnlineCountVo),20);
redisCache.set(hKey + channelId, JSONObject.toJSONString(liveOnlineCountVo), 20);
//LOG.info("放入缓存");
}
});
map.forEach((k,v) -> {
map.forEach((k, v) -> {
countVoList.add(v);
});
return countVoList;
......@@ -1187,6 +1173,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
/**
* 获取在线人数请求
*
* @param channelIds 频道id;多个用逗号隔开
* @return 返回结果
*/
......@@ -1195,33 +1182,34 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put(PolyvReqEnum.APP_ID.getName(), UtilConstants.APP_ID);
params.put(PolyvReqEnum.TIMESTAMP.getName(), System.currentTimeMillis() + "");
params.put(PolyvReqEnum.CHANNEL_IDS.getName(), channelIds);
String sign = liveUtil.generateSign(params, UtilConstants.APP_SECRET);
String sign = LiveUtil.generateSign(params, UtilConstants.APP_SECRET);
params.put(PolyvReqEnum.SIGN.getName(), sign);
LOG.info("批量获取频道实时在线人数;请求入参: {}",params);
return liveUtil.sendHttpPost(UtilConstants.LIVE_STATISTICS_BATCH_COUNT, params);
LOG.info("批量获取频道实时在线人数;请求入参: {}", params);
return LiveUtil.sendHttpPost(UtilConstants.LIVE_STATISTICS_BATCH_COUNT, params);
}
/**
* 获取缓存中的频道在学人数
* @param channelIds 通道ids
* @param map 频道-LiveOnlineCountVo
* @param hKey redis key
* @param noCacheChannelIds 未命中缓存的频道id;多个用逗号隔开
*
* @param channelIds 通道ids
* @param map 频道-LiveOnlineCountVo
* @param hKey redis key
* @param noCacheChannelIds 未命中缓存的频道id;多个用逗号隔开
*/
private void getRedisCache(String channelIds, Map<String, LiveOnlineCountVo> map, String hKey, List<String> noCacheChannelIds) {
String[] split = channelIds.split(",");
for (String channel : split) {
if (StringUtils.isEmpty(channel)){
if (StringUtils.isEmpty(channel)) {
continue;
}
String strValue = (String) redisCache.get(hKey + channel);
if (StringUtils.isEmpty(strValue)){
if (StringUtils.isEmpty(strValue)) {
noCacheChannelIds.add(channel);
continue;
}
LiveOnlineCountVo liveOnlineCountVo = JSONObject.parseObject(strValue, LiveOnlineCountVo.class);
if (null != liveOnlineCountVo){
map.put(channel,liveOnlineCountVo);
if (null != liveOnlineCountVo) {
map.put(channel, liveOnlineCountVo);
continue;
}
noCacheChannelIds.add(channel);
......@@ -1234,21 +1222,21 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
//校验验签sign
String signSource = new StringBuffer().append(secret).append(timestamp).toString();
String ourSign = org.apache.commons.codec.digest.DigestUtils.md5Hex(signSource);
LOG.info("直播状态修改回调参数:channelId = {} ,sign = {},timestamp={}, 校验的生成规则为md5(AppSecret+timestamp):ourSign={}",channelId,sign,timestamp,ourSign);
if (!sign.equalsIgnoreCase(ourSign)){
LOG.info("直播状态修改回调参数:channelId = {} ,sign = {},timestamp={}, 校验的生成规则为md5(AppSecret+timestamp):ourSign={}", channelId, sign, timestamp, ourSign);
if (!sign.equalsIgnoreCase(ourSign)) {
LOG.warn("直播状态修改回调验签不通过!");
return BizResponse.fail("直播状态修改回调验签不通过");
}
LiveActivity select = new LiveActivity();
select.setChannel(channelId);
LiveActivity activity = baseMapper.selectOne(select);
if (null == activity ){
LOG.error("保利威直播状态回调,根据频道号没有查询到对应的直播channelId={}",channelId);
if (null == activity) {
LOG.error("保利威直播状态回调,根据频道号没有查询到对应的直播channelId={}", channelId);
return BizResponse.fail("没有找到频道");
}
if (PolyvReqEnum.LIVE.getName().equals(status)){
if (PolyvReqEnum.LIVE.getName().equals(status)) {
activity.setStatus(LiveStatusEnum.LIVE.getCode());
}else if (PolyvReqEnum.END.getName().equals(status)){
} else if (PolyvReqEnum.END.getName().equals(status)) {
activity.setStatus(LiveStatusEnum.END.getCode());
}
//修改直播状态
......@@ -1259,7 +1247,7 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public BizResponse livebackCallback(PolyvLiveBackCallbackVo liveBackCallbackVo) {
String channelId = liveBackCallbackVo.getChannelId();
if (StringUtils.isEmpty(channelId)){
if (StringUtils.isEmpty(channelId)) {
LOG.error("保利威直播回放完成回调接口:通道channelId 为空;");
return BizResponse.fail("保利威直播回放完成回调接口:通道channelId 为空;");
}
......@@ -1267,8 +1255,8 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
liveActivity.setChannel(channelId);
EntityWrapper wrapper = new EntityWrapper(liveActivity);
List<LiveActivity> list = baseMapper.selectList(wrapper);
if (null == list || list.isEmpty()){
LOG.error("保利威直播回放完成回调接口,根据频道号没有查询到对应的直播channelId={}",channelId);
if (null == list || list.isEmpty()) {
LOG.error("保利威直播回放完成回调接口,根据频道号没有查询到对应的直播channelId={}", channelId);
return BizResponse.fail("没有找到频道");
}
for (LiveActivity activity : list) {
......@@ -1278,19 +1266,19 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
params.put(PolyvReqEnum.APP_ID.getName(), UtilConstants.APP_ID);
params.put(PolyvReqEnum.TIMESTAMP.getName(), System.currentTimeMillis() + "");
params.put(PolyvReqEnum.CHANNEL_ID.getName(), channelId);
PolyvResponseVo<String> polyvResponseVO = PolyvUtils.execPolyvApi(null,params, UtilConstants.LIVE_BACK_SWITCH_GET, RequestMethod.GET);
LOG.info("保利威直播回放完成回调接口,获取直播回放开关状态结果:{}",JSONObject.toJSONString(polyvResponseVO));
if (null == polyvResponseVO || 200 != polyvResponseVO.getCode()){
LOG.error("保利威直播回放完成回调接口,获取直播回放开关状态失败",channelId);
PolyvResponseVo<String> polyvResponseVO = PolyvUtils.execPolyvApi(null, params, UtilConstants.LIVE_BACK_SWITCH_GET, RequestMethod.GET);
LOG.info("保利威直播回放完成回调接口,获取直播回放开关状态结果:{}", JSONObject.toJSONString(polyvResponseVO));
if (null == polyvResponseVO || 200 != polyvResponseVO.getCode()) {
LOG.error("保利威直播回放完成回调接口,获取直播回放开关状态失败", channelId);
return BizResponse.fail("获取直播回放开关状态失败");
}
String data = polyvResponseVO.getData();
if (StringUtils.isEmpty(data) || "N".equals(data)){
if (StringUtils.isEmpty(data) || "N".equals(data)) {
continue;
}
//查询保利威直播回放;
List<LiveReplay> channelReplay = PolyvUtils.getChannelReplay(channelId);
if (null == channelReplay || channelReplay.isEmpty()){
if (null == channelReplay || channelReplay.isEmpty()) {
continue;
}
//新增回放
......@@ -1300,14 +1288,14 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
query.setVideoPoolId(videoPoolId);
EntityWrapper<LiveReplay> ew = new EntityWrapper<>(query);
List<LiveReplay> replayList = liveReplayMapper.selectList(ew);
if (null != replayList && replayList.size() > 0){
if (null != replayList && replayList.size() > 0) {
for (LiveReplay replay : replayList) {
Long id = replay.getId();
copyLiveProperties(liveReplay,replay,activity);
copyLiveProperties(liveReplay, replay, activity);
replay.setId(id);
liveReplayMapper.updateById(replay);
}
}else {
} else {
liveReplay.setCompanyId(activity.getCompanyId());
liveReplay.setSiteId(activity.getSiteId());
liveReplay.setLivePlanStartAt(activity.getStartTime());
......@@ -1368,24 +1356,24 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
RequestContext context = replayLivesReq.getRequestContext();
int pageNo = replayLivesReq.getPageNo();
int pageSize = replayLivesReq.getPageSize();
if (pageNo == 0 || pageSize == 0){
if (pageNo == 0 || pageSize == 0) {
pageNo = 1;
pageSize = Integer.MAX_VALUE;
}
Page<LiveTitleVo> page = new Page<>(pageNo,pageSize);
Page<LiveTitleVo> page = new Page<>(pageNo, pageSize);
try {
//获取开启直播回放开关的直播间id
List<Long> liveIds = getReplayOnLiveIds(context);
if (null == liveIds || liveIds.isEmpty()){
if (null == liveIds || liveIds.isEmpty()) {
LOG.error("获取全部可见的回放开关开启上架直播列表id为空. companyId = {} , siteId = {} , accountId = {} ."
,context.getCompanyCode(),context.getSiteId(),context.getAccountId());
, context.getCompanyCode(), context.getSiteId(), context.getAccountId());
return page;
}
List<LiveTitleVo> liveTitleVos = liveReplayMapper.selectHashReviewLiveList(liveIds, context.getCompanyId(), context.getSiteId(), page);
page.setRecords(liveTitleVos);
return page;
}catch (Exception e){
LOG.error("获取直播回放的直播间异常,companyId = {} , siteId = {} , accountId = {} . 错误信息如下:",context.getCompanyCode(),context.getSiteId(),context.getAccountId(),e);
} catch (Exception e) {
LOG.error("获取直播回放的直播间异常,companyId = {} , siteId = {} , accountId = {} . 错误信息如下:", context.getCompanyCode(), context.getSiteId(), context.getAccountId(), e);
}
return page;
}
......@@ -1393,14 +1381,14 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public List<Long> getReplayOnLiveIds(RequestContext context) {
List<Long> relationIds = context.getRelationIds();
if (null == relationIds){
if (null == relationIds) {
relationIds = new ArrayList<>();
}
relationIds.add(context.getAccountId());
//获取指定用户可见的直播id
List<Long> authLiveIds = scopeAuthorizationMapper.selectLiveIdByRelationId(relationIds);
//获取全部可见的回放开关开启上架直播
return scopeAuthorizationMapper.selectReplayOnLiveIds(authLiveIds,context.getCompanyId(),context.getSiteId());
return scopeAuthorizationMapper.selectReplayOnLiveIds(authLiveIds, context.getCompanyId(), context.getSiteId());
}
@Override
......@@ -1408,30 +1396,30 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
int pageNo = liveReviewsVo.getPageNo();
int pageSize = liveReviewsVo.getPageSize();
Page<LiveReplayVo> page = new Page<>(pageNo,pageSize);
Page<LiveReplayVo> page = new Page<>(pageNo, pageSize);
Long liveId = liveReviewsVo.getLiveId();
RequestContext context = liveReviewsVo.getRequestContext();
if (null == liveId){
LOG.error("获取直播下所有直播回放列表,liveId is null ;accountId = {} , siteId = {}",context.getAccountId(),context.getSiteId());
if (null == liveId) {
LOG.error("获取直播下所有直播回放列表,liveId is null ;accountId = {} , siteId = {}", context.getAccountId(), context.getSiteId());
return page;
}
LiveActivity activity = liveActivityMapper.selectById(liveId);
if (null == activity){
LOG.error("获取直播下所有直播回放列表;根据liveId = {} 未查询到直播信息;accountId = {} , siteId = {}",liveId,context.getAccountId(),context.getSiteId());
if (null == activity) {
LOG.error("获取直播下所有直播回放列表;根据liveId = {} 未查询到直播信息;accountId = {} , siteId = {}", liveId, context.getAccountId(), context.getSiteId());
return page;
}
String logoImage = activity.getLogoImage();
List<LiveReplayVo> replayVoList = liveReplayMapper.selectReplayListByLiveId(liveId,page);
if (null == replayVoList || replayVoList.isEmpty()){
List<LiveReplayVo> replayVoList = liveReplayMapper.selectReplayListByLiveId(liveId, page);
if (null == replayVoList || replayVoList.isEmpty()) {
return page;
}
replayVoList.parallelStream().forEach(replayVo -> {
String liveLogoUrl = replayVo.getLiveLogoUrl();
replayVo.setLiveTitle(activity.getTitle());
replayVo.setLiveDefaultLogoUrl(logoImage);
if (!StringUtils.isEmpty(logoImage) && logoImage.equals(liveLogoUrl)){
if (!StringUtils.isEmpty(logoImage) && logoImage.equals(liveLogoUrl)) {
replayVo.setDefaultLogo(true);
}else {
} else {
replayVo.setDefaultLogo(false);
}
});
......@@ -1441,20 +1429,20 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public Boolean updateReplayStatus(Long replayId, Boolean operation) {
if (null == replayId || null == operation){
LOG.error("直播回放上架、下架失败. replayId = {} ,top ={}",replayId,operation);
if (null == replayId || null == operation) {
LOG.error("直播回放上架、下架失败. replayId = {} ,top ={}", replayId, operation);
return false;
}
LiveReplay liveReplay = liveReplayMapper.selectById(replayId);
if (null == liveReplay){
LOG.error("直播回放上架、下架失败. 未查询到replayId = {} 的直播回放",replayId);
if (null == liveReplay) {
LOG.error("直播回放上架、下架失败. 未查询到replayId = {} 的直播回放", replayId);
return false;
}
liveReplay.setLiveReplayStatus(operation);
try {
liveReplayMapper.updateById(liveReplay);
}catch (Exception e){
LOG.error("直播回放上架、下架异常: ",e);
} catch (Exception e) {
LOG.error("直播回放上架、下架异常: ", e);
return false;
}
return true;
......@@ -1462,24 +1450,24 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public Boolean updateReplayTop(Long replayId, Boolean top) {
if (null == replayId || null == top){
LOG.error("直播回放置顶、取消置顶失败. replayId = {} ,top ={}",replayId,top);
if (null == replayId || null == top) {
LOG.error("直播回放置顶、取消置顶失败. replayId = {} ,top ={}", replayId, top);
return false;
}
LiveReplay liveReplay = liveReplayMapper.selectById(replayId);
if (null == liveReplay){
LOG.error("直播回放置顶、取消置顶失败. 未查询到replayId = {} 的直播回放",replayId);
if (null == liveReplay) {
LOG.error("直播回放置顶、取消置顶失败. 未查询到replayId = {} 的直播回放", replayId);
return false;
}
if (top){
if (top) {
liveReplay.setTopTime(new Date());
}else {
} else {
liveReplay.setTopTime(null);
}
try {
liveReplayMapper.updateTopTime(liveReplay.getId(),liveReplay.getTopTime());
}catch (Exception e){
LOG.error("直播回放置顶、取消置顶异常: ",e);
liveReplayMapper.updateTopTime(liveReplay.getId(), liveReplay.getTopTime());
} catch (Exception e) {
LOG.error("直播回放置顶、取消置顶异常: ", e);
return false;
}
return true;
......@@ -1488,44 +1476,44 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
@Override
public Boolean updateReplayInfos(LiveReplayInfoVo infoVo) {
Long replayId = infoVo.getReplayId();
if (null == replayId){
LOG.error("直播回放编辑信息失败,回放id为空.infoVo = {} ",JSONObject.toJSONString(infoVo));
if (null == replayId) {
LOG.error("直播回放编辑信息失败,回放id为空.infoVo = {} ", JSONObject.toJSONString(infoVo));
return false;
}
try {
LiveReplay liveReplay = liveReplayMapper.selectById(replayId);
if (null == liveReplay){
LOG.error("直播回放编辑信息失败失败. 未查询到replayId = {} 的直播回放",replayId);
if (null == liveReplay) {
LOG.error("直播回放编辑信息失败失败. 未查询到replayId = {} 的直播回放", replayId);
return false;
}
Boolean defaultLogo = infoVo.getDefaultLogo();
if (null != defaultLogo && defaultLogo){
if (null != defaultLogo && defaultLogo) {
//使用本身图片
Long liveId = liveReplay.getLiveId();
LiveActivity activity = liveActivityMapper.selectById(liveId);
if (null == activity){
LOG.error("直播回放编辑信息失败失败. 未查询到replayId = {} ,liveId = {} 的直播",replayId,liveId);
if (null == activity) {
LOG.error("直播回放编辑信息失败失败. 未查询到replayId = {} ,liveId = {} 的直播", replayId, liveId);
return false;
}
liveReplay.setLiveLogoUrl(activity.getLogoImage());
}else {
} else {
String replayLogoUrl = infoVo.getReplayLogoUrl();
if (StringUtils.isEmpty(replayLogoUrl)){
LOG.error("直播回放编辑信息失败失败. replayId = {} 的直播回放,上传图片路径为空",JSONObject.toJSONString(infoVo));
if (StringUtils.isEmpty(replayLogoUrl)) {
LOG.error("直播回放编辑信息失败失败. replayId = {} 的直播回放,上传图片路径为空", JSONObject.toJSONString(infoVo));
return false;
}
liveReplay.setLiveLogoUrl(replayLogoUrl);
}
String anchor = infoVo.getAnchor();
if (StringUtils.isEmpty(anchor)){
LOG.error("直播回放编辑信息失败失败. replayId = {} 的直播回放,主播名为空",JSONObject.toJSONString(infoVo));
if (StringUtils.isEmpty(anchor)) {
LOG.error("直播回放编辑信息失败失败. replayId = {} 的直播回放,主播名为空", JSONObject.toJSONString(infoVo));
return false;
}
liveReplay.setLiveAnchor(anchor);
liveReplay.setImageDesc(infoVo.getImageDesc());
liveReplayMapper.updateById(liveReplay);
}catch (Exception e){
LOG.error("直播回放编辑信息异常: ",e);
} catch (Exception e) {
LOG.error("直播回放编辑信息异常: ", e);
return false;
}
......@@ -1537,30 +1525,30 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
Long liveId = liveReviewsVo.getLiveId();
RequestContext context = liveReviewsVo.getRequestContext();
List<LiveReplayVo> replayVoList = new ArrayList<>();
if (null == liveId){
LOG.error("查询直播间下的直播回放列表;直播id为空!accountId = {},companyId ={},siteId={}",context.getAccountId(),context.getCompanyId(),context.getSiteId());
if (null == liveId) {
LOG.error("查询直播间下的直播回放列表;直播id为空!accountId = {},companyId ={},siteId={}", context.getAccountId(), context.getCompanyId(), context.getSiteId());
return BizResponse.ok(replayVoList);
}
LiveActivity activity = liveActivityMapper.selectById(liveId);
if (null == activity){
LOG.error("查询直播间回放列表;未查询到直播信息: liveId = {},siteId = {}",liveId,context.getSiteId());
if (null == activity) {
LOG.error("查询直播间回放列表;未查询到直播信息: liveId = {},siteId = {}", liveId, context.getSiteId());
return BizResponse.ok(replayVoList);
}
LiveReplay liveReplay = new LiveReplay();
liveReplay.setLiveId(liveId);
liveReplay.setLiveReplayStatus(true);
EntityWrapper<LiveReplay> wrapper = new EntityWrapper<>(liveReplay);
wrapper.orderBy("top_time",false);
wrapper.orderBy("start_time",false);
wrapper.orderBy("top_time", false);
wrapper.orderBy("start_time", false);
List<LiveReplay> liveReplays = liveReplayMapper.selectList(wrapper);
if (null == liveReplays || liveReplays.isEmpty()){
LOG.info("查询直播间liveId ={}的直播回放列表为空;accountId = {},companyId ={},siteId={}",liveId,context.getAccountId(),context.getCompanyId(),context.getSiteId());
if (null == liveReplays || liveReplays.isEmpty()) {
LOG.info("查询直播间liveId ={}的直播回放列表为空;accountId = {},companyId ={},siteId={}", liveId, context.getAccountId(), context.getCompanyId(), context.getSiteId());
return BizResponse.ok(replayVoList);
}
liveReplays.forEach(replay -> {
LiveReplayVo replayVo = new LiveReplayVo();
BeanUtils.copyProperties(replay,replayVo);
BeanUtils.copyProperties(replay, replayVo);
replayVo.setViewType(activity.getViewType());
replayVoList.add(replayVo);
});
......@@ -1572,8 +1560,8 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
String channelId = liveBackCallbackVo.getChannelId();
String sign = liveBackCallbackVo.getSign();
long timestamp = liveBackCallbackVo.getTimestamp();
LOG.info("转播回放成功;保利威回调参数: channelId = {},sign= {},timestamp={}",channelId,sign,timestamp);
if (StringUtils.isEmpty(channelId) || StringUtils.isEmpty(sign)){
LOG.info("转播回放成功;保利威回调参数: channelId = {},sign= {},timestamp={}", channelId, sign, timestamp);
if (StringUtils.isEmpty(channelId) || StringUtils.isEmpty(sign)) {
LOG.error("视频转存回调接口,保利威回调入参;频道号为空;验签为空");
return BizResponse.fail("channelId is null");
}
......@@ -1581,22 +1569,22 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
//校验验签sign
String signSource = new StringBuffer().append(secret).append(timestamp).toString();
String ourSign = org.apache.commons.codec.digest.DigestUtils.md5Hex(signSource);
LOG.info("转播回放成功;保利威回调参数:sign = {},timestamp={}, 校验的生成规则为md5(AppSecret+timestamp):ourSign={}",sign,timestamp,ourSign);
if (!sign.equalsIgnoreCase(ourSign)){
LOG.info("转播回放成功;保利威回调参数:sign = {},timestamp={}, 校验的生成规则为md5(AppSecret+timestamp):ourSign={}", sign, timestamp, ourSign);
if (!sign.equalsIgnoreCase(ourSign)) {
LOG.warn("转播回放成功回调验签不通过!");
return BizResponse.fail("转播回放成功回调验签不通过");
}
LiveActivity select = new LiveActivity();
select.setChannel(channelId);
LiveActivity activity = baseMapper.selectOne(select);
if (null == activity){
LOG.error("保利威视频转存回调接口,根据频道号没有查询到对应的直播channelId={}",channelId);
if (null == activity) {
LOG.error("保利威视频转存回调接口,根据频道号没有查询到对应的直播channelId={}", channelId);
return BizResponse.fail("没有找到频道");
}
activity.setReplayCallbackStatus(true);
//查询保利威直播回放;
List<LiveReplay> channelReplay = PolyvUtils.getChannelReplay(channelId);
if (null == channelReplay || channelReplay.isEmpty()){
if (null == channelReplay || channelReplay.isEmpty()) {
return BizResponse.ok();
}
// 查询本地数据库的channel下的回放列表 alist
......@@ -1611,13 +1599,13 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
for (LiveReplay liveReplay : channelReplay) {
String videoPoolId = liveReplay.getVideoPoolId();
LiveReplay oldReplay = replayService.getByVideoPoolId(videoPoolId);
if (null != oldReplay ){
if (null != oldReplay) {
//修改
Long id = oldReplay.getId();
copyLiveProperties(liveReplay,oldReplay,activity);
copyLiveProperties(liveReplay, oldReplay, activity);
oldReplay.setId(id);
liveReplayMapper.updateById(oldReplay);
}else {
} else {
//新增
liveReplay.setId(idGenerator.generate());
liveReplay.setCompanyId(activity.getCompanyId());
......@@ -1631,18 +1619,18 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
liveReplay.setLiveLogoUrl(activity.getLogoImage());
try {
liveReplayMapper.insert(liveReplay);
}catch (Exception e){
LOG.warn("新增直播回放异常;channelId = "+channelId+" ,videoPoolId = "+videoPoolId+" ;",e);
} catch (Exception e) {
LOG.warn("新增直播回放异常;channelId = " + channelId + " ,videoPoolId = " + videoPoolId + " ;", e);
}
}
}
//删除保利威删除但是数据库未删除的回放记录
if (delReplayIdList.size() > 0){
if (delReplayIdList.size() > 0) {
try {
liveReplayMapper.deleteReplayBatch(delReplayIdList);
LOG.info("直播回放转存回调,删除数据库多余记录{}条",delReplayIdList.size());
}catch (Exception e){
LOG.error("直播回放转存回调,删除数据库多余记录异常; ",e);
LOG.info("直播回放转存回调,删除数据库多余记录{}条", delReplayIdList.size());
} catch (Exception e) {
LOG.error("直播回放转存回调,删除数据库多余记录异常; ", e);
}
}
......@@ -1651,15 +1639,16 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
/**
* 获取数据库要删除的回放记录
*
* @param polyvVideoPoolIdList 保利威的视频回放回调 key=vidPoolId
* @param channelOldReplayList 数据库中channel存在的回放视频
*/
private List<Long> getdelReplayList(List<String> polyvVideoPoolIdList, List<LiveReplay> channelOldReplayList) {
List<Long> delReplayIdList = new ArrayList<>();
if (null != channelOldReplayList && !channelOldReplayList.isEmpty()){
if (null != channelOldReplayList && !channelOldReplayList.isEmpty()) {
channelOldReplayList.parallelStream().forEach(liveReplay -> {
String videoPoolId = liveReplay.getVideoPoolId();
if (!polyvVideoPoolIdList.contains(videoPoolId)){
if (!polyvVideoPoolIdList.contains(videoPoolId)) {
//需要删除的记录
delReplayIdList.add(liveReplay.getId());
}
......@@ -1685,10 +1674,10 @@ public class LiveActivityServiceImpl extends ServiceImpl<LiveActivityMapper, Liv
liveActivity.setCompanyId(companyId);
liveActivity.setShelves(1);
EntityWrapper wrapper = new EntityWrapper(liveActivity);
wrapper.setSqlSelect("distinct(" + field + "),"+"id ")
wrapper.setSqlSelect("distinct(" + field + ")," + "id ")
.isNotNull(field)
.like(field, value)
.addFilter(field+"!=''")
.addFilter(field + "!=''")
.orderBy("create_time", false);
String upperField = ClassUtil.getFieldName(field);
......
......@@ -19,11 +19,7 @@ import java.util.*;
@Component
public class LiveUtil {
private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000)
.setConnectionRequestTimeout(15000).build();
public String sendHttpPost(String httpUrl, Map<String, String> maps) {
public static String sendHttpPost(String httpUrl, Map<String, String> maps) {
HttpPost httpPost = new HttpPost(httpUrl);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
......@@ -38,14 +34,14 @@ public class LiveUtil {
return sendHttpPost(httpPost);
}
private String sendHttpPost(HttpPost httpPost) {
private static String sendHttpPost(HttpPost httpPost) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
HttpEntity entity = null;
String responseContent = null;
try {
httpClient = HttpClients.createDefault();
httpPost.setConfig(requestConfig);
httpPost.setConfig(RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000).setConnectionRequestTimeout(15000).build());
response = httpClient.execute(httpPost);
entity = response.getEntity();
responseContent = EntityUtils.toString(entity, "UTF-8");
......@@ -66,16 +62,16 @@ public class LiveUtil {
return responseContent;
}
public String generateSign(Map<String, String> parray, String secretKey) {
Map<String, String> params = this.paraFilter(parray);
String concatedStr = this.concatParams(params);
public static String generateSign(Map<String, String> parray, String secretKey) {
Map<String, String> params = paraFilter(parray);
String concatedStr = concatParams(params);
String plain = secretKey + concatedStr + secretKey;
String encrypted = MD5Utils.getMD5String(plain);
String upperCase = encrypted.toUpperCase();
return upperCase;
}
private Map<String, String> paraFilter(Map<String, String> sArray) {
private static Map<String, String> paraFilter(Map<String, String> sArray) {
Map<String, String> result = new HashMap<String, String>();
if (sArray == null || sArray.size() <= 0) {
return result;
......@@ -91,7 +87,7 @@ public class LiveUtil {
return result;
}
private String concatParams(Map<String, String> params) {
private static String concatParams(Map<String, String> params) {
List<String> keys = new ArrayList<String>(params.keySet());
Collections.sort(keys);
StringBuilder sb = new StringBuilder();
......
......@@ -66,10 +66,12 @@ public class PolyvUtils {
public static LiveStatusV2 getLiveStatus(String channelId, Date startAt, Date endAt, Integer liveStatus) {
// 直播中
if (null != liveStatus && liveStatus.equals(LiveStatusEnum.LIVE.getCode())) {
logger.info("直播 channel:" + channelId+ "-----1");
return LiveStatusV2.RUNNING;
}
if (LiveStatusV2.RUNNING.getCode().equals(getThirdLiveStatus(channelId))) {
logger.info("直播 channel:" + channelId+ "-----2");
return LiveStatusV2.RUNNING;
}
......@@ -77,15 +79,19 @@ public class PolyvUtils {
// 未开始
if (startAt.getTime() > currentTime) {
logger.info("直播 channel:" + channelId+ "-----3");
return LiveStatusV2.UN_START;
}
Integer count = getCountByChannel(channelId, startAt, new Date(currentTime));
if (count > 0) {
logger.info("直播 channel:" + channelId+ "-----4");
return LiveStatusV2.REPLAY;
}
if (count <= 0 && currentTime > endAt.getTime()) {
logger.info("直播 channel:" + channelId+ "-----5");
return LiveStatusV2.END;
}
logger.info("直播 channel:" + channelId+ "-----6");
return LiveStatusV2.UN_START;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment