Authored by mali

Merge branch 'master' into test6.8.5

Conflicts:
	dal/src/main/java/com/yoho/order/model/BuyerOrderReq.java
	order/src/main/java/com/yoho/ufo/order/service/impl/BuyerOrderServiceImpl.java
	web/src/main/webapp/html/judgeCenter/list.html
... ... @@ -9,4 +9,10 @@ public interface RedisKeyConstants {
// 登录账号前置
String LOGIN_PID_PRE = "ufo:platform:login:pid_";
/**
* 直播录制视频
*/
String LIVE_USER = "ufo:pf:live_user";
}
... ...
... ... @@ -133,7 +133,7 @@ public class QNUploadServiceImpl implements IQNUploadService {
}
}
// http://api.qiniu.com/status/get/prefop?id=z0.5c208c6a38b9f349c82caca2 查看文件的状态
// http://api.qiniu.com/status/get/prefop?id=z0.5c39bbd438b9f349c8691e8b 查看文件的状态
// http://flv01.static.yhbimg.com/ufo/live/mp4/yohotest15.mp4
private static void transfer() {
//String m3u8Address = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8";
... ...
... ... @@ -219,4 +219,25 @@ public final class DateUtil {
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* 获取与当前时间间隔的时间戳
* @param interval
* @return
*/
public static Date getTimeSecondOfDay(int interval){
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_MONTH , interval);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTime();
}
public static void main(String[] args) {
System.out.println(getTimeSecondOfDay(1));
}
}
... ...
... ... @@ -69,7 +69,7 @@ public class BuyerOrderReq extends PageRequestBO{
private String receiveMobile;
private String receiveAddressDetail;
private String receiveZipCode;
private String receiveAreaCode;
... ... @@ -84,4 +84,8 @@ public class BuyerOrderReq extends PageRequestBO{
private String platformExpressInfoFlag;
private String queryStr;
private Integer startTime;
private int userId;
}
... ...
package com.yoho.ufo.order.controller;
import com.yoho.order.model.BuyerOrderReq;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.order.service.impl.AsynVideoLiveService;
import com.yoho.ufo.order.service.impl.UfoLiveService;
import com.yoho.ufo.service.model.ApiResponse;
import com.yohobuy.ufo.model.order.req.QNliveReq;
... ... @@ -25,20 +27,23 @@ public class UfoLiveController {
@Autowired
private UfoLiveService ufoLiveService;
@RequestMapping(value = "/generateMp4")
public ApiResponse generateMp4(QNliveReq req) {
LOGGER.info("generateMp4 in. req is {}", req);
@Autowired
private AsynVideoLiveService asynVideoLiveService;
@RequestMapping(value = "/generateMp4Vedio")
public ApiResponse generateMp4Vedio(BuyerOrderReq req) {
LOGGER.info("generateMp4Vedio in. req is {}", req);
String fileUrl = null;
try {
ufoLiveService.generateMp4(req);
} catch (Exception e) {
LOGGER.info("generateMp4 error. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(400).message("上传失败").build();
asynVideoLiveService.generateMp4Vedio(req);
}catch (Exception e) {
LOGGER.error("generateMp4 error. req is {}", req);
}
LOGGER.info("generateMp4 success. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(200).message("上传成功").build();
return new ApiResponse.ApiResponseBuilder().code(200).data(fileUrl).message("查询成功").build();
}
@RequestMapping(value = "/queryMp4Vedio")
public ApiResponse queryMp4Vedio(QNliveReq req) {
LOGGER.info("queryMp4Vedio in. req is {}", req);
... ... @@ -74,21 +79,25 @@ public class UfoLiveController {
}
@RequestMapping(value = "/queryInitCameraRecord")
public ApiResponse queryInitCameraRecord(QNliveReq req) {
@RequestMapping(value = "/saveInitCameraRecord")
public ApiResponse saveInitCameraRecord(QNliveReq req) {
LOGGER.info("queryInitCameraRecord in. req is {}", req);
Integer initCameraCode = ufoLiveService.queryInitCameraCode(req);
Boolean reslut = ufoLiveService.saveInitCameraRecord(req);
return new ApiResponse.ApiResponseBuilder().code(200).data(initCameraCode).message("查询成功").build();
return new ApiResponse.ApiResponseBuilder().code(200).data(reslut).message("查询成功").build();
}
@RequestMapping(value = "/queryCurrentTime")
public ApiResponse queryCurrentTime() {
LOGGER.info("queryCurrentTime method in.");
Integer currentTime = ufoLiveService.queryCurrentTime();
Integer currentTime;
try {
currentTime = ufoLiveService.queryCurrentTime();
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
return new ApiResponse.ApiResponseBuilder().code(200).data(currentTime).message("获取时间成功").build();
}
}
... ...
... ... @@ -3,8 +3,11 @@ package com.yoho.ufo.order.service.event;
import com.google.common.collect.Lists;
import com.yoho.order.dal.QiniuLiveRecordMapper;
import com.yoho.order.dal.SellerOrderGoodsMapper;
import com.yoho.order.model.BuyerOrderReq;
import com.yoho.order.model.QiniuLiveRecord;
import com.yoho.order.model.SellerOrderGoods;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.order.service.impl.UfoLiveService;
import com.yoho.ufo.util.DateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -28,6 +31,9 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
@Autowired
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
@Autowired
private UfoLiveService ufoLiveService;
/**
* seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=INTEGER},
... ... @@ -39,9 +45,31 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
@Override
public void onApplicationEvent(QiniuLiveRecordEvent event) {
LOGGER.info("LiveEventsListener.onApplicationEvent method in. param is {}", event);
QiniuLiveRecord record = event.getRecord();
QiniuLiveRecord record = convertQiNiuLiveRecord(event.getRecord());
record.setEndTime(DateUtil.getCurrentTimeSeconds()); // 鉴定通过和不通过的时候,默认视频结束
if (record.getStartTime() == null || record.getEndTime() - record.getStartTime() > 1200) {
LOGGER.error("The length of video overstep 20 minutes, event : {}", event);
return;
}
try {
ufoLiveService.generateMp4(record);
} catch (PlatformException e) {
LOGGER.error("method generateMp4 find wrong record :" + record , e);
}
completeRecord(record);
LOGGER.info("LiveEventsListener.onApplicationEvent method out. skup is {}", event.getRecord().getSkup());
}
// 异步补充记录的卖家订单号,商品信息 // 并将之前的skup相关的视频置为不可见
private void completeRecord(QiniuLiveRecord record) {
List<SellerOrderGoods> sellerOrderGoodses = sellerOrderGoodsMapper.selectByIds(Lists.newArrayList(record.getSkup()));
if (CollectionUtils.isEmpty(sellerOrderGoodses)) {
return;
... ... @@ -54,7 +82,16 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
record.setGoodsId(0);
record.setProductId(sellerOrderGoods.getProductId());
qiniuLiveRecordMapper.updateProductBySkup(record);
}
LOGGER.info("LiveEventsListener.onApplicationEvent method out. skup is {}", event.getRecord().getSkup());
private QiniuLiveRecord convertQiNiuLiveRecord(BuyerOrderReq record) {
QiniuLiveRecord result = new QiniuLiveRecord();
result.setSkup(record.getSkup());
result.setDepotNo(record.getDepotNo());
result.setStartTime(record.getStartTime());
result.setPid(record.getUserId());
result.setOrderCode(Long.valueOf(record.getOrderCode()));
return result;
}
}
... ...
package com.yoho.ufo.order.service.event;
import com.alibaba.fastjson.JSONObject;
import com.yoho.order.model.BuyerOrderReq;
import com.yoho.order.model.QiniuLiveRecord;
import org.springframework.context.ApplicationEvent;
... ... @@ -8,22 +9,22 @@ import org.springframework.context.ApplicationEvent;
* Created by li.ma on 2018/12/18.
*/
public class QiniuLiveRecordEvent extends ApplicationEvent {
private QiniuLiveRecord record;
private BuyerOrderReq record;
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
* @param record the object on which the event initially occurred (never {@code null})
*/
public QiniuLiveRecordEvent(QiniuLiveRecord record) {
public QiniuLiveRecordEvent(BuyerOrderReq record) {
super(record);
this.record = record;
}
public QiniuLiveRecord getRecord() {
public BuyerOrderReq getRecord() {
return record;
}
public void setRecord(QiniuLiveRecord record) {
public void setRecord(BuyerOrderReq record) {
this.record = record;
}
... ...
package com.yoho.ufo.order.service.impl;
import com.yoho.order.model.BuyerOrderReq;
import com.yoho.ufo.order.service.event.QiniuLiveRecordEvent;
import com.yoho.ufo.service.impl.UserHelper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/1/14.
*/
@Service
public class AsynVideoLiveService implements ApplicationContextAware {
private ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
public void generateMp4Vedio(BuyerOrderReq req) {
req.setUserId(new UserHelper().getUserId());
applicationContext.publishEvent(new QiniuLiveRecordEvent(req));
}
}
... ...
package com.yoho.ufo.order.service.impl;
import com.alibaba.fastjson.JSON;
import com.yoho.order.model.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.netty.util.internal.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.error.exception.ServiceException;
import com.yoho.order.dal.*;
import com.yoho.order.model.*;
import com.yoho.service.model.order.request.OrderRequest;
import com.yoho.ufo.dal.IdentifyRecordsMapper;
import com.yoho.ufo.dal.ProductMapper;
... ... @@ -26,17 +37,6 @@ import com.yohobuy.ufo.model.order.resp.BuyerOrderResp;
import com.yohobuy.ufo.model.order.resp.ExpressInfoResp;
import com.yohobuy.ufo.model.order.resp.OrderDetailResp;
import com.yohobuy.ufo.model.order.resp.OrderOperateRecordResp;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.netty.util.internal.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
... ... @@ -1417,5 +1417,4 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
}
return list;
}
}
... ...
... ... @@ -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;
}
}
... ...
... ... @@ -5,51 +5,13 @@
<title>Insert title here</title>
</head>
<body>
<input id="startTime" type="hidden"/>
<input id="endTime" type="hidden"/>
<ul>
<li style="padding-bottom: 10px;">
<label>摄像头:</label>
<input id="cameraCode" type="text"/>
</li>
<li style="padding-bottom: 10px; display: none" id="txt_li_id">
<label>计时器:</label>
<input id="txt" type="text" class="easyui-textbox" readonly style="width:200px"/>
</li>
<li style="padding-bottom: 10px; display: none" id="total_li_id">
<label>总时长:</label>
<input id="total" type="text" class="easyui-textbox" readonly style="width:200px"/>
</li>
</ul>
<script type="text/javascript">
var c = 0
var t
if (t) {
clearTimeout(t);
}
function timedCount() {
$('#txt').textbox('setValue', c)
c = c + 1
t = setTimeout("timedCount()", 1000)
}
var totalVar;
function stopCount() {
var totalTime = parseInt($('#txt').val());
var secondVar = parseInt(totalTime % 60);
if (totalTime > 60) {
var minuteVar = parseInt(totalTime / 60);
totalVar = minuteVar + '分' + secondVar + '秒';
} else {
totalVar = secondVar + '秒';
}
c = 0;
setTimeout("$('#total').textbox('setValue', totalVar)", 0);
clearTimeout(t);
}
$(function () {
$.ajax({
contentType: "application/json",
... ... @@ -67,20 +29,6 @@
valueField: "cameraCode",
textField: "cameraName"
});
$.ajax({
contentType: "application/json",
dataType: "json",
type: "GET",
url: contextPath + '/live/queryInitCameraRecord',
success: function (data) {
if (data.code != 200) {
return;
} else if (data.data){
$('#cameraCode').combobox('setValue',data.data);
}
}
});
}
}
});
... ...