Authored by mali

Merge branch 'hotfix_vedio' into gray

... ... @@ -247,6 +247,9 @@
<artifactId>orika-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>com.yoho.ufo.model</groupId>
<artifactId>order-ufo-model</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
package com.yohoufo.common.constant;
import com.yoho.core.config.ConfigReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2019/4/15.
*/
@Service
public class OrderConfigConstant {
@Autowired
private ConfigReader configReader;
/**
* 获取视频生成方式。true 老的七牛直播方式 false 则代表NVR方式
* @return
*/
public boolean getVedioConfig() {
return configReader.getBoolean("ufo.Vedio.Config", true);
}
}
\ No newline at end of file
... ...
package com.yohoufo.common.utils;
import com.yohobuy.ufo.model.order.constants.QNliveConstants;
import org.apache.commons.lang3.StringUtils;
/**
* Created by li.ma on 2019/4/15.
*/
public class QiniuLiveUrlUtil {
public static final String LIVE_VIDEO_DOMAIN = QNliveConstants.LIVE_VIDEO_DOMAIN;
public static final String MP4_FILEKEY_PRE = QNliveConstants.MP4_FILEKEY_PRE; // mp4文件路径
public static String makeLiveVideoUrl(String filename) {
if (StringUtils.isBlank(filename)) {
return null;
}
if (filename.startsWith("http")) { // 如果数据库存放的是绝对路径,则直接返回
return filename;
}
return LIVE_VIDEO_DOMAIN + MP4_FILEKEY_PRE + filename;
}
public static String makeLiveVideoUrl(String videoName, String filename) {
if (StringUtils.isNotBlank(videoName)) { // 优先取新的鉴定视频链接
return videoName;
}
return makeLiveVideoUrl(filename);
}
public static boolean filterVideoValid(String videoName, Integer status) {
return StringUtils.isNotBlank(videoName) || 1 == status;
}
}
... ...
... ... @@ -15,8 +15,16 @@ public interface QiniuLiveRecordMapper {
QiniuLiveRecord selectByOrderCode(@Param("orderCode") Long orderCode);
// 包含状态为0的,因为有可能是新的鉴定视频链接
QiniuLiveRecord selectByOrderCodeEx(@Param("orderCode") Long orderCode);
List<QiniuLiveRecord> selectByOrderCodes(@Param("orderCodes") List<Long> orderCodes);
// 包含状态为0的,因为有可能是新的鉴定视频链接
List<QiniuLiveRecord> selectByOrderCodesEx(@Param("orderCodes") List<Long> orderCodes);
List<QiniuLiveRecord> selectByProductId(@Param("productId")int productId);
// 包含状态为0的,因为有可能是新的鉴定视频链接
List<QiniuLiveRecord> selectByProductIdEx(@Param("productId")int productId);
}
... ...
... ... @@ -38,6 +38,7 @@ public class QiniuLiveRecord {
private Integer showFlag;
private String videoUrl; // 新的鉴定视频生成的URL
public String getPersistId() {
return persistId;
... ... @@ -167,6 +168,14 @@ public class QiniuLiveRecord {
this.showFlag = showFlag;
}
public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}
public String getVideoUrl() {
return videoUrl;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
... ...
... ... @@ -17,10 +17,11 @@
<result column="storage_id" property="storageId" jdbcType="INTEGER" />
<result column="goods_id" property="goodsId" jdbcType="INTEGER" />
<result column="product_id" property="productId" jdbcType="INTEGER" />
<result column="video_url" property="videoUrl" jdbcType="VARCHAR" />
</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, status, storage_id, goods_id, product_id
vedio_file_url, create_time, update_time, status, storage_id, goods_id, product_id, video_url
</sql>
<select id="selectByOrderCode" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
... ... @@ -30,6 +31,14 @@
and show_flag = 1 and status = 1 order by id DESC limit 1
</select>
<select id="selectByOrderCodeEx" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from qiniu_live_record
where order_code = #{orderCode, jdbcType=BIGINT}
and show_flag = 1 and (status = 1 or video_url != '') order by id DESC limit 1
</select>
<select id="selectByOrderCodes" resultMap="BaseResultMap">
select
... ... @@ -42,6 +51,17 @@
and show_flag = 1 and status = 1 order by id DESC
</select>
<select id="selectByOrderCodesEx" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from qiniu_live_record
where order_code in
<foreach collection="orderCodes" item="orderCode" open="(" separator="," close=")">
#{orderCode}
</foreach>
and show_flag = 1 order by id DESC
</select>
<update id="updateStatusByPersistId">
update qiniu_live_record
set status = #{status,jdbcType=INTEGER}
... ... @@ -50,9 +70,17 @@
<select id="selectByProductId" resultMap="BaseResultMap">
select
order_code, end_time, vedio_file_url, storage_id
order_code, end_time, vedio_file_url, storage_id, status, video_url
from qiniu_live_record
where product_id = #{productId, jdbcType=INTEGER}
and show_flag = 1 and status = 1 order by id DESC limit 10
</select>
<select id="selectByProductIdEx" resultMap="BaseResultMap">
select
order_code, end_time, vedio_file_url, storage_id, status, video_url
from qiniu_live_record
where product_id = #{productId, jdbcType=INTEGER}
and show_flag = 1 order by id DESC limit 10
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -59,7 +59,7 @@ public class UfoLiveAvthumbController {
@IgnoreSession
@IgnoreSignature
@Cachable(expire = 180)
public ApiResponse buyerModifyAddress(@RequestParam("product_id") int productId){
public ApiResponse queryProductVideos(@RequestParam("product_id") int productId){
logger.info("in ufo.order.videos, product_id {}.", productId);
List<OrderVideoResp> respList = qiniuLiveRecordService.queryOrderVideos(productId);
... ...
... ... @@ -6,7 +6,9 @@ import com.yoho.core.config.ConfigReader;
import com.yohobuy.ufo.model.order.common.OrderStatus;
import com.yohobuy.ufo.model.order.constants.QNliveConstants;
import com.yohobuy.ufo.model.order.resp.OrderVideoResp;
import com.yohoufo.common.constant.OrderConfigConstant;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.QiniuLiveUrlUtil;
import com.yohoufo.dal.order.BuyerOrderMapper;
import com.yohoufo.dal.order.QiniuLiveRecordMapper;
import com.yohoufo.dal.order.model.BuyerOrder;
... ... @@ -32,9 +34,6 @@ import java.util.stream.Collectors;
public class QiniuLiveRecordService {
private final Logger LOG = LoggerFactory.getLogger(QiniuLiveRecordService.class);
public static final String LIVE_VIDEO_DOMAIN = QNliveConstants.LIVE_VIDEO_DOMAIN;
public static final String MP4_FILEKEY_PRE = QNliveConstants.MP4_FILEKEY_PRE; // mp4文件路径
@Autowired
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
... ... @@ -44,18 +43,8 @@ public class QiniuLiveRecordService {
@Autowired
private ConfigReader configReader;
private static String makeLiveVideoUrl(String filename) {
if (StringUtils.isBlank(filename)) {
return null;
}
if (filename.startsWith("http")) { // 如果数据库存放的是绝对路径,则直接返回
return filename;
}
return LIVE_VIDEO_DOMAIN + MP4_FILEKEY_PRE + filename;
}
@Autowired
OrderConfigConstant orderConfigConstant;
public void updateStatusByPersistId(String persistId, Integer code) {
if (Integer.valueOf(0).equals(code)) {
... ... @@ -67,14 +56,27 @@ public class QiniuLiveRecordService {
if (null == orderCode) {
return null;
}
QiniuLiveRecord qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCode(orderCode);
QiniuLiveRecord qiniuLiveRecords;
if (orderConfigConstant.getVedioConfig()) {
LOG.info("method selectByOrderCodes in qiniuLiveRecordMapper.selectByOrderCode orderCode is {}", orderCode);
qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCode(orderCode);
if (null == qiniuLiveRecords || StringUtils.isEmpty(qiniuLiveRecords.getVedioFileUrl())) {
return null;
}
qiniuLiveRecords.setVedioFileUrl(makeLiveVideoUrl(qiniuLiveRecords.getVedioFileUrl()));
qiniuLiveRecords.setVedioFileUrl(QiniuLiveUrlUtil.makeLiveVideoUrl(qiniuLiveRecords.getVedioFileUrl()));
} else {
LOG.info("method selectByOrderCodes in qiniuLiveRecordMapper.selectByOrderCodeEx orderCode is {}", orderCode);
qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCodeEx(orderCode);
if (null == qiniuLiveRecords || StringUtils.isEmpty(qiniuLiveRecords.getVedioFileUrl())) {
return null;
}
qiniuLiveRecords.setVedioFileUrl(QiniuLiveUrlUtil.makeLiveVideoUrl(qiniuLiveRecords.getVideoUrl(), qiniuLiveRecords.getVedioFileUrl()));
}
return qiniuLiveRecords;
}
... ... @@ -82,25 +84,58 @@ public class QiniuLiveRecordService {
if (CollectionUtils.isEmpty(orderCodes)) {
return Maps.newHashMap();
}
if (orderConfigConstant.getVedioConfig()) {
LOG.info("method getAppraiseVideoUrl in qiniuLiveRecordMapper.selectByOrderCodes orderCodes is {}", orderCodes);
return qiniuLiveRecordMapper.selectByOrderCodes(orderCodes).stream()
.collect(Collectors.toMap(QiniuLiveRecord::getOrderCode,
e -> QiniuLiveRecordService.makeLiveVideoUrl(e.getVedioFileUrl()),
e -> QiniuLiveUrlUtil.makeLiveVideoUrl(e.getVedioFileUrl()),
(o, n) -> o));
} else {
LOG.info("method getAppraiseVideoUrl in qiniuLiveRecordMapper.selectByOrderCodesEx orderCodes is {}", orderCodes);
return qiniuLiveRecordMapper.selectByOrderCodesEx(orderCodes).stream()
.filter(item -> QiniuLiveUrlUtil.filterVideoValid(item.getVideoUrl(), item.getStatus()))
.collect(Collectors.toMap(QiniuLiveRecord::getOrderCode, e -> QiniuLiveUrlUtil.makeLiveVideoUrl(e.getVideoUrl(), e.getVedioFileUrl()),
(o, n) -> o));
}
}
public String getAppraiseVideoUrl(Long orderCode) {
if (orderConfigConstant.getVedioConfig()) {
LOG.info("method getAppraiseVideoUrl in qiniuLiveRecordMapper.selectByOrderCode orderCode is {}", orderCode);
return Optional.ofNullable(orderCode)
.map(qiniuLiveRecordMapper::selectByOrderCode)
.map(QiniuLiveRecord::getVedioFileUrl)
.map(QiniuLiveRecordService::makeLiveVideoUrl)
.map(QiniuLiveUrlUtil::makeLiveVideoUrl)
.orElse(null);
} else {
LOG.info("method getAppraiseVideoUrl in qiniuLiveRecordMapper.selectByOrderCodeEx orderCode is {}", orderCode);
QiniuLiveRecord qiniuLiveRecord = Optional.ofNullable(orderCode)
.map(qiniuLiveRecordMapper::selectByOrderCodeEx).orElse(null);
return null == qiniuLiveRecord ? null : QiniuLiveUrlUtil.makeLiveVideoUrl(qiniuLiveRecord.getVideoUrl(), qiniuLiveRecord.getVedioFileUrl());
}
}
public List<OrderVideoResp> queryOrderVideos(int productId) {
List<OrderVideoResp> resps = Lists.newArrayList();
queryInitVideo(resps);
List<QiniuLiveRecord> qiNiuLiveRecords = qiniuLiveRecordMapper.selectByProductId(productId);
List<QiniuLiveRecord> qiNiuLiveRecords;
if (orderConfigConstant.getVedioConfig()) {
LOG.info("mthod queryOrderVideos in qiniuLiveRecordMapper.selectByProductId productId is {}", productId);
qiNiuLiveRecords = qiniuLiveRecordMapper.selectByProductId(productId);
} else {
LOG.info("mthod queryOrderVideos in qiniuLiveRecordMapper.selectByProductIdEx productId is {}", productId);
qiNiuLiveRecords = qiniuLiveRecordMapper.selectByProductIdEx(productId).stream()
.filter(item -> QiniuLiveUrlUtil.filterVideoValid(item.getVideoUrl(), item.getStatus())).collect(Collectors.toList());
}
List<Long> orderCodeList = qiNiuLiveRecords.stream().map(QiniuLiveRecord::getOrderCode).collect(Collectors.toList());
if (CollectionUtils.isEmpty(orderCodeList) || !configReader.getBoolean("ufo.order.appressVideoShow", true)) {
return resps;
... ... @@ -108,7 +143,7 @@ public class QiniuLiveRecordService {
LOG.info("method queryOrderVideos in orderCodeList is {}, productId is {}", orderCodeList, productId);
Map<Long, QiniuLiveRecord> recordMap = qiNiuLiveRecords.stream().collect(Collectors.toMap(QiniuLiveRecord::getOrderCode, item -> item));
Map<Long, QiniuLiveRecord> recordMap = qiNiuLiveRecords.stream().collect(Collectors.toMap(QiniuLiveRecord::getOrderCode, item -> item, (a, b) -> a));
List<BuyerOrder> buyerOrders = buyerOrderMapper.selectByOrderCodes(orderCodeList, Lists.newArrayList(OrderStatus.WAITING_RECEIVE.getCode(),
... ... @@ -125,7 +160,12 @@ public class QiniuLiveRecordService {
orderVideoResp.setCreateTime(DateUtil.getDateFormatEx(qiniuLiveRecord.getEndTime(), DateUtil.MM_dd_yyyy_HH_mm_ssEx));
orderVideoResp.setDesc(configReader.getString("ufo.order.realDesc", "鉴定结果:真"));
orderVideoResp.setVideoPictureUrl(configReader.getString("ufo.order.realVideoPic", "http://img11.static.yhbimg.com/goodsimg/2019/01/25/15/01f6c0a2303cfa1957a34b9f8b17e7e746.png"));
orderVideoResp.setVideoUrl(makeLiveVideoUrl(qiniuLiveRecord.getVedioFileUrl()));
if (orderConfigConstant.getVedioConfig()) {
orderVideoResp.setVideoUrl(QiniuLiveUrlUtil.makeLiveVideoUrl(qiniuLiveRecord.getVedioFileUrl()));
} else {
orderVideoResp.setVideoUrl(QiniuLiveUrlUtil.makeLiveVideoUrl(qiniuLiveRecord.getVideoUrl(), qiniuLiveRecord.getVedioFileUrl()));
}
orderVideoResp.setInitFlag(Boolean.FALSE);
appraiseVideoList.add(orderVideoResp);
});
... ...
package com.yohoufo.product.service.impl;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import com.yohoufo.common.constant.OrderConfigConstant;
import com.yohoufo.common.utils.QiniuLiveUrlUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
... ... @@ -152,6 +148,9 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
@Value("${ufo.nfc.syncBlockChain.url}")
private String syncBlockChain_url;
@Autowired
OrderConfigConstant orderConfigConstant;
private static final String UIC_PROFILE_URL = "/profile/getProfile";
public static final String DEFAULT_HEAD_IMG = "http://img11.static.yhbimg.com/yhb-img01/2016/07/05/13/017ec560b82c132ab2fdb22f7cf6f42b83.png?imageView/{mode}/w/{width}/h/{height}";
... ... @@ -951,19 +950,21 @@ public class ProductIdentifyServiceImpl implements ProductIdentifyService{
if (null == orderCode) {
return null;
}
QiniuLiveRecord qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCode(orderCode);
if (null == qiniuLiveRecords || StringUtils.isEmpty(qiniuLiveRecords.getVedioFileUrl())) {
return null;
}
String filename = qiniuLiveRecords.getVedioFileUrl();
if (StringUtils.isBlank(filename)) {
return null;
}
if (filename.startsWith("http")) {
return filename;
if (orderConfigConstant.getVedioConfig()) {
logger.info("method getLiveVideoUrlByOrderCode in qiniuLiveRecordMapper.selectByOrderCode orderCode is {}", orderCode);
return Optional.ofNullable(orderCode).map(qiniuLiveRecordMapper::selectByOrderCode)
.map(item -> QiniuLiveUrlUtil.makeLiveVideoUrl(item.getVedioFileUrl())).orElse(null);
} else {
logger.info("method getLiveVideoUrlByOrderCode in qiniuLiveRecordMapper.selectByOrderCodeEx orderCode is {}", orderCode);
QiniuLiveRecord qiniuLiveRecords = qiniuLiveRecordMapper.selectByOrderCodeEx(orderCode);
return Optional.ofNullable(orderCode).map(qiniuLiveRecordMapper::selectByOrderCodeEx)
.map(item -> QiniuLiveUrlUtil.makeLiveVideoUrl(item.getVideoUrl(), item.getVedioFileUrl())).orElse(null);
}
logger.info("getLiveVideoUrlByOrderCode success! orderCode={},filename={}", orderCode,filename);
return QNliveConstants.LIVE_VIDEO_DOMAIN + QNliveConstants.MP4_FILEKEY_PRE + filename;
}
... ...