|
@@ -5,23 +5,24 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fs.ad.yk.utils.Md5Util;
|
|
|
import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.common.utils.bean.BeanUtils;
|
|
|
import com.fs.course.domain.FsUserTalent;
|
|
|
import com.fs.course.service.IFsUserTalentService;
|
|
|
-import com.fs.live.domain.Live;
|
|
|
-import com.fs.live.domain.LiveData;
|
|
|
-import com.fs.live.domain.LiveVideo;
|
|
|
-import com.fs.live.mapper.LiveMapper;
|
|
|
-import com.fs.live.service.ILiveDataService;
|
|
|
-import com.fs.live.service.ILiveService;
|
|
|
-import com.fs.live.service.ILiveVideoService;
|
|
|
+import com.fs.live.domain.*;
|
|
|
+import com.fs.live.mapper.*;
|
|
|
+import com.fs.live.service.*;
|
|
|
import com.fs.live.utils.ProcessManager;
|
|
|
import com.fs.live.vo.LiveListVo;
|
|
|
+import com.fs.live.vo.LiveLotteryConfVo;
|
|
|
+import com.fs.live.vo.LiveLotteryProductListVo;
|
|
|
import com.fs.system.domain.SysConfig;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.FormBody;
|
|
|
import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Request;
|
|
@@ -29,11 +30,13 @@ import okhttp3.Response;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.fs.aicall.utils.Md5Utils;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.Base64Utils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 直播Service业务层处理
|
|
@@ -43,6 +46,7 @@ import java.util.*;
|
|
|
*/
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements ILiveService
|
|
|
{
|
|
|
private final LiveMapper liveMapper;
|
|
@@ -58,6 +62,22 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
@Autowired
|
|
|
private ProcessManager processManager;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ILiveGoodsService liveGoodsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveRedConfService liveRedConfService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveLotteryConfService liveLotteryConfService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILiveAutoTaskService liveAutoTaskService;
|
|
|
+ @Autowired
|
|
|
+ private LiveLotteryProductConfMapper liveLotteryProductConfMapper;
|
|
|
+ @Autowired
|
|
|
+ private RedisCache redisCache;
|
|
|
+
|
|
|
/**
|
|
|
* 查询直播
|
|
|
*
|
|
@@ -76,6 +96,23 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
return byId;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R currentActivities(Long liveId,String userId) {
|
|
|
+ R r = liveGoodsService.showGoods(liveId);
|
|
|
+ Object data = r.get("data");
|
|
|
+ List<LiveRedConf> liveRedConfs = liveRedConfService.selectActivedRed(liveId, userId);
|
|
|
+ List<LiveLotteryConfVo> liveLotteryConfs = liveLotteryConfService.selectActivedLottery(liveId, userId);
|
|
|
+ List<Long> lotteryIds = liveLotteryConfs.stream().map(LiveLotteryConfVo::getLotteryId).collect(Collectors.toList());
|
|
|
+ if (!lotteryIds.isEmpty()) {
|
|
|
+ List<LiveLotteryProductListVo> products = liveLotteryProductConfMapper.selectLiveLotteryProductConfByLotteryIds(lotteryIds);
|
|
|
+ for (LiveLotteryConfVo liveLotteryConf : liveLotteryConfs) {
|
|
|
+ liveLotteryConf.setProducts(products.stream().filter(product -> product.getLotteryId().equals(liveLotteryConf.getLotteryId())).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return R.ok().put("red", liveRedConfs).put("lottery", liveLotteryConfs).put("goods", data);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询企业直播
|
|
|
* @param liveId 直播ID
|
|
@@ -147,6 +184,14 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
//新增直播数据表
|
|
|
LiveData liveData = new LiveData();
|
|
|
liveData.setLiveId(live.getLiveId());
|
|
|
+ liveData.setPageViews(0L);
|
|
|
+ liveData.setUniqueVisitors(0L);
|
|
|
+ liveData.setTotalViews(0L);
|
|
|
+ liveData.setUniqueViewers(0L);
|
|
|
+ liveData.setPeakConcurrentViewers(0L);
|
|
|
+ liveData.setLikes(0L);
|
|
|
+ liveData.setFavourite_num(0L);
|
|
|
+ liveData.setFollow_num(0L);
|
|
|
liveDataService.insertLiveData(liveData);
|
|
|
return save ? 1 : 0;
|
|
|
}
|
|
@@ -168,7 +213,9 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
liveVideo.setDuration(live.getDuration());
|
|
|
liveVideoService.updateById(liveVideo);
|
|
|
}
|
|
|
- return liveMapper.updateLive(live);
|
|
|
+ int result = liveMapper.updateLive(live);
|
|
|
+ liveAutoTaskService.recalcLiveAutoTask(live.getLiveId());
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -416,16 +463,18 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
return R.error("直播已下架");
|
|
|
}
|
|
|
String rtmpPushUrl = generateRtmpPushUrl("rtmp://200149.push.tlivecloud.com", "live", exist.getLiveId().toString());
|
|
|
- String hlvPlayUrl = generateHlvPlayUrl("http://live.test.ifeiyu100.com", "live", exist.getLiveId().toString());
|
|
|
+ String hlvPlayUrl = generateHlvPlayUrl("https://live.test.ifeiyu100.com", "live", exist.getLiveId().toString());
|
|
|
+ Date now = new Date();
|
|
|
exist.setRtmpUrl(rtmpPushUrl);
|
|
|
exist.setFlvHlsUrl(hlvPlayUrl);
|
|
|
|
|
|
exist.setStatus(2);
|
|
|
- exist.setUpdateTime(new Date());
|
|
|
+ exist.setUpdateTime(now);
|
|
|
exist.setFinishTime( null);
|
|
|
exist.setStartTime(LocalDateTime.now());
|
|
|
liveMapper.updateLive(exist);
|
|
|
|
|
|
+
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
@@ -441,6 +490,115 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R copyLive(Live live) {
|
|
|
+ Long existLiveId = live.getLiveId();
|
|
|
+ Date now = new Date();
|
|
|
+ Live exist = liveMapper.selectLiveByLiveId(existLiveId);
|
|
|
+ if (exist == null) {
|
|
|
+ return R.error("直播间不存在");
|
|
|
+ }
|
|
|
+ // 复制直播间, 创建 livedata
|
|
|
+ // 身份认证
|
|
|
+ Live liveEntity = new Live();
|
|
|
+ BeanUtils.copyBeanProp(liveEntity, exist);
|
|
|
+ liveEntity.setLiveId(null);
|
|
|
+ liveEntity.setCompanyId(live.getCompanyId());
|
|
|
+ liveEntity.setCompanyUserId(live.getCompanyUserId());
|
|
|
+ liveEntity.setRtmpUrl( null);
|
|
|
+ liveEntity.setFlvHlsUrl( null);
|
|
|
+ liveEntity.setFinishTime( null);
|
|
|
+ liveEntity.setIsAudit( 0);
|
|
|
+ liveEntity.setStatus( 1);
|
|
|
+ liveEntity.setCreateTime( now);
|
|
|
+ liveMapper.insertLive(liveEntity);
|
|
|
+ if(liveEntity.getLiveId() == null) throw new RuntimeException("插入直播间异常");
|
|
|
+ Long newLiveId = liveEntity.getLiveId();
|
|
|
+ LiveData liveData = new LiveData();
|
|
|
+ liveData.setLiveId(newLiveId);
|
|
|
+ liveData.setPageViews(0L);
|
|
|
+ liveData.setUniqueVisitors(0L);
|
|
|
+ liveData.setTotalViews(0L);
|
|
|
+ liveData.setUniqueViewers(0L);
|
|
|
+ liveData.setPeakConcurrentViewers(0L);
|
|
|
+ liveData.setLikes(0L);
|
|
|
+ liveData.setFavourite_num(0L);
|
|
|
+ liveData.setFollow_num(0L);
|
|
|
+ liveDataService.insertLiveData(liveData);
|
|
|
+ // 直播视频
|
|
|
+ LiveVideo liveVideo = liveVideoService.selectLiveVideoByLiveId(existLiveId);
|
|
|
+ if (!Objects.isNull(liveVideo)) {
|
|
|
+ LiveVideo videoEntity = new LiveVideo();
|
|
|
+ BeanUtils.copyBeanProp(videoEntity, liveVideo);
|
|
|
+ videoEntity.setVideoId(null);
|
|
|
+ videoEntity.setLiveId(newLiveId);
|
|
|
+ videoEntity.setCreateTime(now);
|
|
|
+ liveVideoService.insertLiveVideo(videoEntity);
|
|
|
+ }
|
|
|
+ //直播间红包配置
|
|
|
+ List<LiveRedConf> liveRedConfs = liveRedConfService.selectByLiveId(existLiveId);
|
|
|
+ if (!liveRedConfs.isEmpty()) {
|
|
|
+ LiveRedConf liveRedConfEntity = new LiveRedConf();
|
|
|
+ for (LiveRedConf liveRedConf : liveRedConfs) {
|
|
|
+ BeanUtils.copyBeanProp(liveRedConfEntity, liveRedConf);
|
|
|
+ liveRedConfEntity.setRedId(null);
|
|
|
+ liveRedConfEntity.setLiveId(newLiveId);
|
|
|
+ liveRedConfEntity.setRedStatus(0L);
|
|
|
+ liveRedConfEntity.setCreateTime(now);
|
|
|
+ liveRedConfService.insertLiveRedConf(liveRedConfEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 直播间礼物配置
|
|
|
+ List<LiveLotteryConf> liveLotteryConfs = liveLotteryConfService.selectByLiveId(existLiveId);
|
|
|
+ if (!liveLotteryConfs.isEmpty()) {
|
|
|
+ LiveLotteryConf liveLotteryConfEntity = new LiveLotteryConf();
|
|
|
+ for (LiveLotteryConf liveLotteryConf : liveLotteryConfs) {
|
|
|
+ BeanUtils.copyBeanProp(liveLotteryConfEntity, liveLotteryConf);
|
|
|
+ liveLotteryConfEntity.setLotteryId(null);
|
|
|
+ liveLotteryConfEntity.setLiveId(newLiveId);
|
|
|
+ liveLotteryConfEntity.setLotteryStatus(String.valueOf(0));
|
|
|
+ liveLotteryConfEntity.setCreateTime(now);
|
|
|
+ liveLotteryConfService.insertLiveLotteryConf(liveLotteryConfEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 直播间商品
|
|
|
+ List<LiveGoods> goodsList = liveGoodsService.selectByLiveId(existLiveId);
|
|
|
+ if (!goodsList.isEmpty()) {
|
|
|
+ LiveGoods liveGoodsEntity = new LiveGoods();
|
|
|
+ for (LiveGoods liveGoods : goodsList) {
|
|
|
+ BeanUtils.copyBeanProp(liveGoodsEntity, liveGoods);
|
|
|
+ liveGoodsEntity.setGoodsId(null);
|
|
|
+ liveGoodsEntity.setLiveId(newLiveId);
|
|
|
+ liveGoodsEntity.setCreateTime(now);
|
|
|
+ liveGoodsEntity.setCompanyId(live.getCompanyId());
|
|
|
+ liveGoodsEntity.setCompanyUserId(live.getCompanyUserId());
|
|
|
+ liveGoodsService.insertLiveGoods(liveGoodsEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 运营自动化
|
|
|
+ List<LiveAutoTask> liveAutoTasksList = liveAutoTaskService.selectLiveAutoTaskByLiveId(existLiveId);
|
|
|
+ if (!liveAutoTasksList.isEmpty()) {
|
|
|
+ LiveAutoTask liveAutoTaskEntity = new LiveAutoTask();
|
|
|
+ for (LiveAutoTask liveAutoTask : liveAutoTasksList) {
|
|
|
+ BeanUtils.copyBeanProp(liveAutoTaskEntity, liveAutoTask);
|
|
|
+ liveAutoTaskEntity.setId(null);
|
|
|
+ liveAutoTaskEntity.setLiveId(newLiveId);
|
|
|
+ liveAutoTaskEntity.setCreateTime(now);
|
|
|
+ liveAutoTaskEntity.setUpdateTime(now);
|
|
|
+ liveAutoTaskEntity.setFinishStatus(0L);
|
|
|
+ liveAutoTaskService.copyInsertLiveAutoTask(liveAutoTaskEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return R.ok("复制成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 构建FFmpeg推流命令
|
|
|
*/
|
|
@@ -539,7 +697,7 @@ public class LiveServiceImpl extends ServiceImpl<LiveMapper, Live> implements IL
|
|
|
app +
|
|
|
"/" +
|
|
|
liveId +
|
|
|
- ".m3u8?" +
|
|
|
+ ".flv?" +
|
|
|
"txSecret=" +
|
|
|
Md5Util.MD5("NiMfMYG5HQxZQ5bk88ri" + liveId + to16Hex(now)) +
|
|
|
"&" +
|