...
|
...
|
@@ -2,12 +2,17 @@ package com.yoho.ufo.order.service.impl; |
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.dal.datasource.annotation.Database;
|
|
|
import com.yoho.core.redis.cluster.annotation.Redis;
|
|
|
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
|
|
|
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yoho.order.dal.CameraRecordMapper;
|
|
|
import com.yoho.order.dal.QiniuLiveRecordMapper;
|
|
|
import com.yoho.order.dal.UserCameraRecordMapper;
|
|
|
import com.yoho.order.model.CameraRecord;
|
|
|
import com.yoho.order.model.QiniuLiveRecord;
|
|
|
import com.yoho.order.model.UserCameraRecord;
|
|
|
import com.yoho.ufo.constants.RedisKeyConstants;
|
|
|
import com.yoho.ufo.exception.PlatformException;
|
|
|
import com.yoho.ufo.order.service.event.QiniuLiveRecordEvent;
|
|
|
import com.yoho.ufo.service.impl.QNLiveUtilService;
|
...
|
...
|
@@ -26,40 +31,44 @@ import org.springframework.context.ApplicationContextAware; |
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
|
* Created by li.ma on 2018/12/13.
|
|
|
*/
|
|
|
@Service
|
|
|
public class UfoLiveService implements ApplicationContextAware {
|
|
|
public class UfoLiveService {
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(UfoLiveService.class);
|
|
|
|
|
|
@Redis("yohoNoSyncRedis")
|
|
|
private YHRedisTemplate redisTemplate;
|
|
|
|
|
|
@Redis("yohoNoSyncRedis")
|
|
|
private YHValueOperations yhValueOperations;
|
|
|
|
|
|
@Autowired
|
|
|
private QNLiveUtilService qNliveUtilService;
|
|
|
|
|
|
@Autowired
|
|
|
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
|
|
|
|
|
|
private ApplicationContext context;
|
|
|
|
|
|
@Autowired
|
|
|
private CameraRecordMapper cameraRecordMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private UserCameraRecordMapper userCameraRecordMapper;
|
|
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
|
|
this.context = applicationContext;
|
|
|
}
|
|
|
//@Autowired
|
|
|
//private UserCameraRecordMapper userCameraRecordMapper;
|
|
|
|
|
|
@Database(ForceMaster = true)
|
|
|
public void generateMp4(QNliveReq req) throws PlatformException {
|
|
|
public void generateMp4(QiniuLiveRecord req) throws PlatformException {
|
|
|
LOGGER.info("method UfoLiveService.generateMp4 in, QNliveReq is {}", req);
|
|
|
|
|
|
Integer userId = req.getPid();
|
|
|
|
|
|
String fileName = String.valueOf(req.getOrderCode()) + "_" + String.valueOf(req.getStartTime());
|
|
|
|
|
|
String m3u8Url = queryM3u8Url(req.getCameraCode());
|
|
|
String m3u8Url = queryM3u8Url(queryInitCameraCode(req), userId);
|
|
|
|
|
|
qNliveUtilService.fetch(fileName, m3u8Url, String.valueOf(req.getStartTime()), String.valueOf(req.getEndTime()));
|
|
|
|
...
|
...
|
@@ -70,13 +79,13 @@ public class UfoLiveService implements ApplicationContextAware { |
|
|
throw new PlatformException(400);
|
|
|
}
|
|
|
|
|
|
saveRecord(req, fileName, persistId);
|
|
|
saveRecord(req, fileName, persistId, userId);
|
|
|
|
|
|
LOGGER.info("method UfoLiveService.generateMp4 end, QNliveReq is {}, persistId is {}", req, persistId);
|
|
|
}
|
|
|
|
|
|
// 保存记录
|
|
|
private void saveRecord(QNliveReq req, String fileName, String persistId) {
|
|
|
private void saveRecord(QiniuLiveRecord req, String fileName, String persistId, int userId) {
|
|
|
qiniuLiveRecordMapper.updateShowFlagBySkup(req.getSkup(), 0, 0); // 先更新之前的视频记录为不可见
|
|
|
|
|
|
QiniuLiveRecord record = new QiniuLiveRecord();
|
...
|
...
|
@@ -86,7 +95,7 @@ public class UfoLiveService implements ApplicationContextAware { |
|
|
record.setOrderCode(req.getOrderCode());
|
|
|
record.setSellerOrderCode(0L);
|
|
|
record.setPersistId(persistId);
|
|
|
record.setPid(new UserHelper().getUserId());
|
|
|
record.setPid(userId);
|
|
|
record.setSkup(req.getSkup());
|
|
|
record.setStartTime(req.getStartTime());
|
|
|
record.setStatus(0);
|
...
|
...
|
@@ -95,8 +104,6 @@ public class UfoLiveService implements ApplicationContextAware { |
|
|
qiniuLiveRecordMapper.insert(record);
|
|
|
|
|
|
record.setNotInId(record.getId());
|
|
|
|
|
|
context.publishEvent(new QiniuLiveRecordEvent(record)); // 异步补充记录的卖家订单号,商品信息 // 并将之前的skup相关的视频置为不可见
|
|
|
}
|
|
|
|
|
|
public String queryMp4Vedio(QNliveReq req) throws PlatformException {
|
...
|
...
|
@@ -126,8 +133,10 @@ public class UfoLiveService implements ApplicationContextAware { |
|
|
return QNLiveUtilService.LIVE_VEDIO_DOMAIN + QNLiveUtilService.MP4_FILEKEY_PRE + qiniuLiveRecord.getVedioFileUrl();
|
|
|
}
|
|
|
|
|
|
public String queryM3u8Url(Integer cameraCode) throws PlatformException {
|
|
|
userCameraRecordMapper.insertUserCameraRecord(new UserHelper().getUserId(), cameraCode);
|
|
|
public String queryM3u8Url(Integer cameraCode, int userId) throws PlatformException {
|
|
|
//userCameraRecordMapper.insertUserCameraRecord(userId, cameraCode);
|
|
|
|
|
|
|
|
|
|
|
|
List<CameraRecord> cameraRecordList = cameraRecordMapper.selectAllCameraRecord();
|
|
|
|
...
|
...
|
@@ -149,12 +158,42 @@ public class UfoLiveService implements ApplicationContextAware { |
|
|
}
|
|
|
|
|
|
// 查询当前登录用户默认的摄像头设备
|
|
|
public Integer queryInitCameraCode(QNliveReq req) {
|
|
|
UserCameraRecord userCameraRecord = userCameraRecordMapper.selectUserCameraRecord(new UserHelper().getUserId());
|
|
|
return null == userCameraRecord ? null : userCameraRecord.getCameraCode();
|
|
|
public Integer queryInitCameraCode(QiniuLiveRecord req) {
|
|
|
// UserCameraRecord userCameraRecord = userCameraRecordMapper.selectUserCameraRecord(new UserHelper().getUserId());
|
|
|
|
|
|
String cameraCode = yhValueOperations.get(getRedisKey(req.getPid()));
|
|
|
|
|
|
req.setCameraCode(null == cameraCode ? null : Integer.valueOf(cameraCode));
|
|
|
|
|
|
return null == cameraCode ? null : Integer.valueOf(cameraCode);
|
|
|
}
|
|
|
|
|
|
public Integer queryCurrentTime() throws PlatformException {
|
|
|
Integer userId = new UserHelper().getUserId();
|
|
|
|
|
|
RedisKeyBuilder key = RedisKeyBuilder.newInstance().appendFixed(RedisKeyConstants.LIVE_USER).appendVar(userId);
|
|
|
if (redisTemplate.hasKey(key)) {
|
|
|
return DateUtil.getCurrentTimeSeconds();
|
|
|
}
|
|
|
throw new PlatformException("没有选择摄像头", 400);
|
|
|
}
|
|
|
|
|
|
public Integer queryCurrentTime() {
|
|
|
return DateUtil.getCurrentTimeSeconds();
|
|
|
/**
|
|
|
* 根据登录用户id 获取缓存键值
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
private RedisKeyBuilder getRedisKey(int userId) {
|
|
|
return RedisKeyBuilder.newInstance().appendFixed(RedisKeyConstants.LIVE_USER).appendVar(userId);
|
|
|
}
|
|
|
|
|
|
public Boolean saveInitCameraRecord(QNliveReq req) {
|
|
|
Integer userId = new UserHelper().getUserId();
|
|
|
yhValueOperations.set(getRedisKey(userId), String.valueOf(req.getCameraCode()), 12, TimeUnit.HOURS);
|
|
|
|
|
|
redisTemplate.expireAt(getRedisKey(userId), DateUtil.getTimeSecondOfDay(1));
|
|
|
return Boolean.TRUE;
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|