Authored by mali

直播的回调请求

... ... @@ -102,7 +102,7 @@ public class QNUploadServiceImpl implements IQNUploadService {
}
}
// http://api.qiniu.com/status/get/prefop?id=z0.5c0df16438b9f349c88d2e9c 查看文件的状态
// http://api.qiniu.com/status/get/prefop?id=z0.5c13269138b9f349c8b0e84d 查看文件的状态
private static void transfer() {
String m3u8Address = "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8";
//设置账号的AK,SK
... ...
... ... @@ -11,21 +11,21 @@ import com.qiniu.storage.model.FetchRet;
import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlSafeBase64;
import com.yoho.ufo.exception.PlatformException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.HashMap;
/**
* Created by li.ma on 2018/12/11.
* http://api.qiniu.com/status/get/prefop?id=z0.5c0f69a738b9f349c8868db6 http请求查询状态
*/
@Service
public class QNliveService {
private static final Logger logger = LoggerFactory.getLogger(QNliveService.class);
public class QNliveUtil {
private static final Logger logger = LoggerFactory.getLogger(QNliveUtil.class);
private static final Configuration cfg = new Configuration(Zone.zone0());
... ... @@ -65,17 +65,28 @@ public class QNliveService {
* @param startTime 摄像开始时间
* @param endTime 摄像结束时间
*/
public void fetch(String fileKey, String cameraIdentify, String startTime, String endTime) {
public void fetch(String fileKey, Integer cameraIdentify, String startTime, String endTime) throws PlatformException {
logger.info("bucketManager.fetch begin fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, cameraIdentify, startTime, endTime);
//实例化一个BucketManager对象
BucketManager bucketManager = new BucketManager(auth, cfg);
//文件保存的空间名和文件名
String key = FILEKEY_PRE + fileKey; // 例如 "ufo/live/m3u8/yohotest15.m3u8";
String key = FILEKEY_PRE + fileKey + ".m3u8"; // 例如 "ufo/live/m3u8/yohotest15.m3u8";
//要fetch的url "http://yoho-live-down.yohobuy.com/yoho13/yoho.m3u8?starttime=1544425260&endtime=1544425440";
String fetchUrl = FETCH_URL_PRE + "yoho13/yoho.m3u8" + "?starttime=" + startTime + "&endtime=" + endTime;
String fetchUrl = null;
if (Integer.valueOf(1).equals(cameraIdentify)) { // 南京的鉴定中心对应的摄像头视频URL
fetchUrl = FETCH_URL_PRE + "yoho13/yoho.m3u8" + "?starttime=" + startTime + "&endtime=" + endTime;
} else if (Integer.valueOf(0).equals(cameraIdentify)){ // 北京的鉴定中心对应的摄像头视频URL
fetchUrl = FETCH_URL_PRE + "yoho13/yoho.m3u8" + "?starttime=" + startTime + "&endtime=" + endTime;
}
logger.info("bucketManager.fetch before fetchUrl is {}", fetchUrl);
if (null == fetchUrl) {
throw new PlatformException(400);
}
try {
FetchRet fetch = bucketManager.fetch(fetchUrl, BUCKET, key); //调用fetch方法抓取文件
... ... @@ -86,6 +97,8 @@ public class QNliveService {
//捕获异常信息
Response r = e.response;
logger.error("bucketManager.fetch find wrong fileKey is {}, cameraIdentify is {}, startTime is {}, endTime is {} error is {}", fileKey, cameraIdentify, startTime, endTime, e.response);
throw new PlatformException(400);
}
}
... ... @@ -94,13 +107,13 @@ public class QNliveService {
* @param fileKey
* @param mp4FileName
*/
public void transfer(String fileKey, String mp4FileName) {
public String transfer(String fileKey, String mp4FileName) {
OperationManager operater = new OperationManager(auth, cfg);
String key = FILEKEY_PRE + fileKey; //设置要转码的空间和key,并且这个key在你空间中存在
String key = FILEKEY_PRE + fileKey + ".m3u8"; //设置要转码的空间和key,并且这个key在你空间中存在
//可以对转码后的文件进行使用saveas参数自定义命名,当然也可以不指定文件会默认命名并保存在当前空间。 BUCKET = "yhb-img01";
String mp4FileEncode = BUCKET + MP4_FILEKEY_PRE + mp4FileName;
String mp4FileEncode = BUCKET + MP4_FILEKEY_PRE + mp4FileName + ".mp4";
String urlBase64 = UrlSafeBase64.encodeToString(mp4FileEncode);
String pfops = FOPS_PARAMS + "|saveas/" + urlBase64;
... ... @@ -110,6 +123,8 @@ public class QNliveService {
String persistId = operater.pfop(BUCKET, key, pfops, params);
logger.info("method transfer end fileKey is {}, mp4FileName is {} , persistid is {}", fileKey, mp4FileName, persistId);
return persistId;
} catch (QiniuException e) {
logger.error("method transfer error fileKey is {}, mp4FileName is {} , error is {}", fileKey, mp4FileName, e.response);
try {
... ... @@ -118,6 +133,8 @@ public class QNliveService {
//ignore
}
}
return null;
}
/**
... ...
package com.yoho.order.dal;
import com.yoho.order.model.QiniuLiveRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface QiniuLiveRecordMapper {
int insert(QiniuLiveRecord record);
List<QiniuLiveRecord> selectByOrderCodes(@Param("orderCodes") List<Long> orderCodes);
int updateProductBySkup(QiniuLiveRecord record);
int updateVedioBySkup(QiniuLiveRecord record);
int updateStatusBySkup(@Param("skup")Integer skup, @Param("status")Integer status);
}
\ No newline at end of file
... ...
package com.yoho.order.model;
public class QiniuLiveRecord {
private Integer id;
private Long orderCode;
private Integer skup;
private Long sellerOrderCode;
private Integer depotNo;
private Integer startTime;
private Integer endTime;
private String persistId;
private String vedioFileUrl;
private Integer createTime;
private Integer updateTime;
private Integer pid;
private Integer status;
private Integer storageId;
private Integer goodsId;
private Integer productId;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Long getOrderCode() {
return orderCode;
}
public void setOrderCode(Long orderCode) {
this.orderCode = orderCode;
}
public Integer getSkup() {
return skup;
}
public void setSkup(Integer skup) {
this.skup = skup;
}
public Long getSellerOrderCode() {
return sellerOrderCode;
}
public void setSellerOrderCode(Long sellerOrderCode) {
this.sellerOrderCode = sellerOrderCode;
}
public Integer getDepotNo() {
return depotNo;
}
public void setDepotNo(Integer depotNo) {
this.depotNo = depotNo;
}
public Integer getStartTime() {
return startTime;
}
public void setStartTime(Integer startTime) {
this.startTime = startTime;
}
public Integer getEndTime() {
return endTime;
}
public void setEndTime(Integer endTime) {
this.endTime = endTime;
}
public String getPersistId() {
return persistId;
}
public void setPersistId(String persistId) {
this.persistId = persistId == null ? null : persistId.trim();
}
public String getVedioFileUrl() {
return vedioFileUrl;
}
public void setVedioFileUrl(String vedioFileUrl) {
this.vedioFileUrl = vedioFileUrl == null ? null : vedioFileUrl.trim();
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getPid() {
return pid;
}
public void setPid(Integer pid) {
this.pid = pid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getStorageId() {
return storageId;
}
public void setStorageId(Integer storageId) {
this.storageId = storageId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
}
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.order.dal.QiniuLiveRecordMapper" >
<resultMap id="BaseResultMap" type="com.yoho.order.model.QiniuLiveRecord" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="order_code" property="orderCode" jdbcType="BIGINT" />
<result column="skup" property="skup" jdbcType="INTEGER" />
<result column="seller_order_code" property="sellerOrderCode" jdbcType="BIGINT" />
<result column="depot_no" property="depotNo" jdbcType="INTEGER" />
<result column="start_time" property="startTime" jdbcType="INTEGER" />
<result column="end_time" property="endTime" jdbcType="INTEGER" />
<result column="persist_id" property="persistId" jdbcType="VARCHAR" />
<result column="vedio_file_url" property="vedioFileUrl" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="pid" property="pid" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
<result column="storage_id" property="storageId" jdbcType="INTEGER" />
<result column="goods_id" property="goodsId" jdbcType="INTEGER" />
<result column="product_id" property="productId" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code, skup, seller_order_code, depot_no, start_time, end_time, persist_id,
vedio_file_url, create_time, update_time, pid, status, storage_id, goods_id, product_id
</sql>
<select id="selectByOrderCodes" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from qiniu_live_record
where order_code in
<foreach collection="orderCodes" open="(" close=")" separator="," item="orderCode">
#{orderCode,jdbcType=BIGINT}
</foreach>
</select>
<insert id="insert" parameterType="com.yoho.order.model.QiniuLiveRecord" >
insert into qiniu_live_record (order_code, skup,
seller_order_code, depot_no, start_time,
end_time, persist_id, vedio_file_url,
create_time, pid,
status)
values (#{orderCode,jdbcType=BIGINT}, #{skup,jdbcType=INTEGER},
#{sellerOrderCode,jdbcType=BIGINT}, #{depotNo,jdbcType=INTEGER}, #{startTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{persistId,jdbcType=VARCHAR}, #{vedioFileUrl,jdbcType=VARCHAR},
#{createTime,jdbcType=INTEGER}, #{pid,jdbcType=INTEGER},
#{status,jdbcType=INTEGER})
</insert>
<update id="updateProductBySkup" parameterType="com.yoho.order.model.QiniuLiveRecord" >
update qiniu_live_record
set seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=INTEGER},
storage_id = #{storageId,jdbcType=INTEGER},
goods_id = #{goodsId,jdbcType=INTEGER},
product_id = #{productId,jdbcType=INTEGER}
where skup = #{skup,jdbcType=INTEGER}
</update>
<update id="updateVedioBySkup" parameterType="com.yoho.order.model.QiniuLiveRecord" >
update qiniu_live_record
set start_time = #{startTime,jdbcType=INTEGER},
end_time = #{endTime,jdbcType=INTEGER},
persist_id = #{persistId,jdbcType=VARCHAR},
vedio_file_url = #{vedioFileUrl,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=INTEGER},
pid = #{pid,jdbcType=INTEGER},
status = #{status,jdbcType=INTEGER}
where skup = #{skup,jdbcType=INTEGER}
</update>
<update id="updateStatusBySkup">
update qiniu_live_record
set status = #{status,jdbcType=INTEGER}
where skup = #{skup,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.order.controller;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.order.service.impl.UfoLiveService;
import com.yoho.ufo.service.model.ApiResponse;
import com.yohobuy.ufo.model.order.req.QNliveReq;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by li.ma on 2018/12/13.
*/
@RestController
@RequestMapping(value = "/live")
public class UfoLiveController {
private static final Logger LOGGER = LoggerFactory.getLogger(UfoLiveController.class);
@Autowired
private UfoLiveService ufoLiveService;
@RequestMapping(value = "/generateMp4")
public ApiResponse generateMp4(QNliveReq req) {
LOGGER.info("generateMp4 in. req is {}", req);
try {
ufoLiveService.generateMp4(req);
} catch (Exception e) {
LOGGER.info("generateMp4 error. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(400).message("上传失败").build();
}
LOGGER.info("generateMp4 success. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(200).message("上传成功").build();
}
@RequestMapping(value = "/queryMp4Vedio")
public ApiResponse queryMp4Vedio(QNliveReq req) {
LOGGER.info("queryMp4Vedio in. req is {}", req);
String fileUrl = null;
try {
fileUrl = ufoLiveService.queryMp4Vedio(req);
} catch (PlatformException e) {
LOGGER.info("generateMp4 error. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}catch (Exception e) {
LOGGER.info("generateMp4 error. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(400).message("查询失败").build();
}
LOGGER.info("queryMp4Vedio success. req is {}, fileUrl is {}", req, fileUrl);
if (StringUtils.isEmpty(fileUrl)) {
return new ApiResponse.ApiResponseBuilder().code(400).message("视频还未转码完成").build();
}
return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").build();
}
}
... ...
package com.yoho.ufo.order.service.impl;
import com.google.common.collect.Lists;
import com.yoho.order.dal.QiniuLiveRecordMapper;
import com.yoho.order.model.QiniuLiveRecord;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.impl.QNliveUtil;
import com.yoho.ufo.service.impl.UserHelper;
import com.yoho.ufo.util.DateUtil;
import com.yohobuy.ufo.model.order.req.QNliveReq;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by li.ma on 2018/12/13.
*/
@Service
public class UfoLiveService {
private static final Logger LOGGER = LoggerFactory.getLogger(UfoLiveService.class);
@Autowired
private QNliveUtil qNliveUtil;
@Autowired
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
public void generateMp4(QNliveReq req) throws PlatformException {
LOGGER.info("method UfoLiveService.generateMp4 in, QNliveReq is {}", req);
String fileName = String.valueOf(req.getOrderCode()) + "_" + String.valueOf(req.getStartTime());
qNliveUtil.fetch(fileName, req.getDepotNo(), String.valueOf(req.getStartTime()), String.valueOf(req.getEndTime()));
String persistId = qNliveUtil.transfer(fileName, fileName);
if (StringUtils.isEmpty(persistId)) {
throw new PlatformException(400);
}
saveRecord(req, fileName, persistId);
LOGGER.info("method UfoLiveService.generateMp4 end, QNliveReq is {}, persistId is {}", req, persistId);
}
// 保存记录
private void saveRecord(QNliveReq req, String fileName, String persistId) {
QiniuLiveRecord record = new QiniuLiveRecord();
record.setDepotNo(req.getDepotNo());
record.setCreateTime(DateUtil.getCurrentTimeSeconds());
record.setEndTime(req.getEndTime());
record.setOrderCode(req.getOrderCode());
record.setPersistId(persistId);
record.setPid(new UserHelper().getUserId());
record.setSkup(req.getSkup());
record.setStartTime(req.getStartTime());
record.setStatus(1);
record.setVedioFileUrl(fileName + ".mp4");
qiniuLiveRecordMapper.insert(record);
}
public String queryMp4Vedio(QNliveReq req) throws PlatformException {
List<QiniuLiveRecord> qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCodes(Lists.newArrayList(req.getOrderCode()));
if (CollectionUtils.isEmpty(qiniuLiveRecords)) {
throw new PlatformException("记录已不存在", 400);
}
QiniuLiveRecord qiniuLiveRecord = qiniuLiveRecords.get(0);
if (Integer.valueOf(1).equals(qiniuLiveRecord.getStatus())) { // 如果已经转码成功,直接返回视频连接
return qiniuLiveRecord.getVedioFileUrl();
}
if ("success".equals(qNliveUtil.queryPrefopStatus(qiniuLiveRecord.getPersistId()))) { // 如果主动查询转码已成功,则更新状态
qiniuLiveRecordMapper.updateStatusBySkup(req.getSkup(), 1);
return qiniuLiveRecord.getVedioFileUrl();
}
return null;
}
}
... ...
... ... @@ -293,7 +293,9 @@ function getToBeJudgedList(){
return "<a role='confirm' dataId='"+ rowData.id +"' style='margin-left:10px;background-color: #5cb85c !important;'>确认收货</a>";
} else if (rowData.status == 3) {
return "<a role='pass' dataId='"+ rowData.id + "'" + " orderCode='"+rowData.orderCode +"' style='margin-left:10px;background-color: #5cb85c !important;'>鉴定通过</a>"+
"<a role='reject' dataId='"+ rowData.id + "'" + " skup='"+rowData.skup +"' style='margin-left:10px;background-color: #d9534f !important;'>鉴定不通过</a>";
"<a role='reject' dataId='"+ rowData.id + "'" + " skup='"+rowData.skup +"' style='margin-left:10px;background-color: #d9534f !important;'>鉴定不通过</a>"+
"<a role='query' dataId='"+ rowData.id + "'" + " skup='"+rowData.skup +"' style='margin-left:10px;background-color: #5cb85c !important;'>查看视频</a>"+
"<a role='record' dataId='"+ rowData.id + "' order_code='" + rowData.orderCode + "' skup='"+rowData.skup +"' style='margin-left:10px;background-color: #5cb85c !important;'>录制视频</a>";
} else if (rowData.status == 17) {
if(rowData.platformWaybillCode){
return "<a role='send_back_rebackAddress' dataId='"+ rowData.orderCode +"' skup='"+ rowData.skup +"' style='margin-left:10px;background-color: #5cb85c !important;'>商品寄回地址</a>"
... ... @@ -351,6 +353,25 @@ function getToBeJudgedList(){
}
});
// 查看视频
$(this).datagrid("getPanel").find("a[role='query']").linkbutton({
onClick: function () {
var skup = $(this).attr("skup");
$("#skup").val(skup);
}
});
// 录制视频
$(this).datagrid("getPanel").find("a[role='record']").linkbutton({
onClick: function () {
var skup = $(this).attr("skup");
var order_code = $(this).attr("order_code");
$("#skup").val(skup);
addRecordPage(skup, order_code, $(this).attr("dataId"));
}
});
$(this).datagrid("getPanel").find("a[role='reback']").linkbutton({
onClick: function () {
var skup = $(this).attr("skup");
... ... @@ -653,6 +674,63 @@ function addRejectPage(id) {
});
}
function addRecordPage(skup, order_code, id) {
var div = $("<div id='recordDiv'>").appendTo($(document.body));
var url = contextPath + "/html/judgeCenter/record.html";
$(div).myDialog({
width: "50%",
height: "60%",
title: "视频录制",
href: url,
modal: true,
collapsible: true,
cache: false,
buttons: [{
text: "开始录制",
id: "recordBtn",
iconCls: "icon-save",
onClick: function () {
if (!$('#startTime').val() || $('#startTime').val() == '') {
$('#recordBtn').linkbutton({text:'结束录制'});
$('#startTime').val(parseInt(new Date().getTime() / 1000));
} else if ($('#endTime').val() == '') {
$('#endTime').val(parseInt(new Date().getTime() / 1000));
$('#recordBtn').linkbutton({text:'上传云端'});
} else if ($('#startTime').val() != '' && $('#endTime').val() != ''){
$('#recordBtn').linkbutton('disable');
$.post(contextPath + "/live/generateMp4", {
id : id,
skup : skup,
orderCode : order_code,
startTime : $('#startTime').val(),
endTime : $('#endTime').val(),
depotNo: $("#depotNo").combobox("getValue")
}, function(data) {
if (data.code == 200) {
$("#recordDiv").dialog("close");
$("#orderListTable").datagrid("reload");
window.self.$.messager.show({
title : "提示",
msg : "鉴定通过操作成功!"
});
}else {
window.self.$.messager.alert("失败", data.message, "error");
}
});
}
//sendBackGoods(id);
}
},{
text: "取消",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
}]
});
}
function deliverGoods(id){
var expressCompanyId = $("#expressCompany").myCombobox("getValue");
var waybillCode = $("#waybillCode").textbox("getValue");
... ...