Authored by mali

Merge branch 'hotfix_video' into test6.8.7

package com.yoho.order.dal;
import com.yoho.order.model.LiveRecordTime;
import org.apache.ibatis.annotations.Param;
public interface LiveRecordTimeMapper {
int insertOrUpdate(LiveRecordTime record);
Integer selectByOrderCode(@Param("orderCode")Long orderCode);
}
\ No newline at end of file
... ...
... ... @@ -18,4 +18,6 @@ public interface QiniuLiveRecordMapper {
int updateShowFlagBySkup(@Param("skup")Integer skup, @Param("showFlag")Integer showFlag, @Param("id") Integer id);
void updateDiscardVideo(@Param("orderCode")Long orderCode, @Param("showFlag")Integer showFlag);
int insertInitRecord(QiniuLiveRecord record);
}
\ No newline at end of file
... ...
package com.yoho.order.model;
import com.alibaba.fastjson.JSONObject;
public class LiveRecordTime {
private Integer id;
private Long orderCode;
private Integer startTime;
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 getStartTime() {
return startTime;
}
public void setStartTime(Integer startTime) {
this.startTime = startTime;
}
public LiveRecordTime() {
}
public LiveRecordTime(Long orderCode, Integer startTime) {
this.orderCode = orderCode;
this.startTime = startTime;
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
}
}
\ No newline at end of file
... ...
... ... @@ -193,6 +193,243 @@ public class QiniuLiveRecord {
this.productId = productId;
}
public static class Builder {
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;
private Integer showFlag;
private Integer notInId;
private Integer cameraCode;
public Integer getCameraCode() {
return cameraCode;
}
public Builder setCameraCode(Integer cameraCode) {
this.cameraCode = cameraCode;
return this;
}
public Integer getNotInId() {
return notInId;
}
public Builder setNotInId(Integer notInId) {
this.notInId = notInId;
return this;
}
public Integer getShowFlag() {
return showFlag;
}
public Builder setShowFlag(Integer showFlag) {
this.showFlag = showFlag;
return this;
}
public Integer getId() {
return id;
}
public Builder setId(Integer id) {
this.id = id;
return this;
}
public Long getOrderCode() {
return orderCode;
}
public Builder setOrderCode(Long orderCode) {
this.orderCode = orderCode;
return this;
}
public Integer getSkup() {
return skup;
}
public Builder setSkup(Integer skup) {
this.skup = skup;
return this;
}
public Long getSellerOrderCode() {
return sellerOrderCode;
}
public Builder setSellerOrderCode(Long sellerOrderCode) {
this.sellerOrderCode = sellerOrderCode;
return this;
}
public Integer getDepotNo() {
return depotNo;
}
public Builder setDepotNo(Integer depotNo) {
this.depotNo = depotNo;
return this;
}
public Integer getStartTime() {
return startTime;
}
public Builder setStartTime(Integer startTime) {
this.startTime = startTime;
return this;
}
public Integer getEndTime() {
return endTime;
}
public Builder setEndTime(Integer endTime) {
this.endTime = endTime;
return this;
}
public String getPersistId() {
return persistId;
}
public Builder setPersistId(String persistId) {
this.persistId = persistId == null ? null : persistId.trim();
return this;
}
public String getVedioFileUrl() {
return vedioFileUrl;
}
public Builder setVedioFileUrl(String vedioFileUrl) {
this.vedioFileUrl = vedioFileUrl == null ? null : vedioFileUrl.trim();
return this;
}
public Integer getCreateTime() {
return createTime;
}
public Builder setCreateTime(Integer createTime) {
this.createTime = createTime;
return this;
}
public Integer getUpdateTime() {
return updateTime;
}
public Builder setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
return this;
}
public Integer getPid() {
return pid;
}
public Builder setPid(Integer pid) {
this.pid = pid;
return this;
}
public Integer getStatus() {
return status;
}
public Builder setStatus(Integer status) {
this.status = status;
return this;
}
public Integer getStorageId() {
return storageId;
}
public Builder setStorageId(Integer storageId) {
this.storageId = storageId;
return this;
}
public Integer getGoodsId() {
return goodsId;
}
public Builder setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
return this;
}
public Integer getProductId() {
return productId;
}
public Builder setProductId(Integer productId) {
this.productId = productId;
return this;
}
public QiniuLiveRecord build() {
QiniuLiveRecord record = new QiniuLiveRecord();
record.setCameraCode(this.getCameraCode());
record.setDepotNo(this.getDepotNo());
record.setStartTime(this.getStartTime());
record.setOrderCode(this.getOrderCode());
record.setSkup(this.getSkup());
record.setEndTime(this.getEndTime());
record.setCreateTime(this.getCreateTime());
record.setGoodsId(this.getGoodsId());
record.setId(this.getId());
record.setNotInId(this.getNotInId());
record.setPersistId(this.getPersistId());
record.setPid(this.getPid());
record.setProductId(this.getProductId());
record.setSellerOrderCode(this.getSellerOrderCode());
record.setStatus(this.getStatus());
record.setStorageId(this.getStorageId());
record.setShowFlag(this.getShowFlag());
record.setVedioFileUrl(this.getVedioFileUrl());
record.setUpdateTime(this.getUpdateTime());
return record;
}
}
@Override
public String toString() {
return JSONObject.toJSONString(this);
... ...
<?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.LiveRecordTimeMapper" >
<resultMap id="BaseResultMap" type="com.yoho.order.model.LiveRecordTime" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="order_code" property="orderCode" jdbcType="BIGINT" />
<result column="start_time" property="startTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, order_code, start_time
</sql>
<select id="selectByOrderCode" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select start_time from live_record_time where order_code = #{orderCode,jdbcType=BIGINT} limit 1
</select>
<insert id="insertOrUpdate" parameterType="com.yoho.order.model.LiveRecordTime" >
insert into live_record_time (order_code, start_time)
values (#{orderCode,jdbcType=BIGINT}, #{startTime,jdbcType=INTEGER})ON DUPLICATE KEY UPDATE start_time=#{startTime,jdbcType=INTEGER}
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -48,6 +48,11 @@
#{status,jdbcType=INTEGER}, #{cameraCode, jdbcType=INTEGER})
</insert>
<insert id="insertInitRecord" parameterType="com.yoho.order.model.QiniuLiveRecord" useGeneratedKeys="true" keyProperty="id">
insert into qiniu_live_record (order_code, start_time, create_time, status, show_flag)
values (#{orderCode,jdbcType=BIGINT}, #{startTime,jdbcType=INTEGER},#{createTime,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{showFlag,jdbcType=INTEGER})
</insert>
<update id="updateProductBySkup" parameterType="com.yoho.order.model.QiniuLiveRecord" >
update qiniu_live_record
set seller_order_code = #{sellerOrderCode,jdbcType=BIGINT},
... ...
... ... @@ -103,12 +103,12 @@ public class UfoLiveController {
}
@RequestMapping(value = "/queryCurrentTime")
public ApiResponse queryCurrentTime() {
public ApiResponse queryCurrentTime(QNliveReq req) {
LOGGER.info("queryCurrentTime method in.");
Integer currentTime;
try {
currentTime = ufoLiveService.queryCurrentTime();
currentTime = ufoLiveService.queryCurrentTime(req.getOrderCode());
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).data("").message(e.getMessage()).build();
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.ufo.order.service.event;
import com.google.common.collect.Lists;
import com.yoho.order.dal.BuyerOrderGoodsMapper;
import com.yoho.order.dal.LiveRecordTimeMapper;
import com.yoho.order.dal.QiniuLiveRecordMapper;
import com.yoho.order.dal.SellerOrderGoodsMapper;
import com.yoho.order.model.BuyerOrderGoods;
... ... @@ -37,6 +38,9 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
private QiniuLiveRecordMapper qiniuLiveRecordMapper;
@Autowired
private LiveRecordTimeMapper liveRecordTimeMapper;
@Autowired
private UfoLiveService ufoLiveService;
/**
... ... @@ -52,20 +56,21 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
LOGGER.info("LiveEventsListener.onApplicationEvent method in. param is {}", event);
QiniuLiveRecord record = convertQiNiuLiveRecord(event.getRecord());
record.setEndTime(DateUtil.getCurrentTimeSeconds()); // 鉴定通过和不通过的时候,默认视频结束
if (record.getStartTime() == null || record.getEndTime() - record.getStartTime() > 1200) {
if (record.getStartTime() == null) {
LOGGER.error("The length of video overstep 20 minutes, event : {}", event);
return;
}
if (record.getEndTime() - record.getStartTime() > 300) {
record.setEndTime(record.getStartTime() + 300);
}
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());
... ... @@ -100,11 +105,14 @@ public class LiveEventsListener implements ApplicationListener<QiniuLiveRecordEv
record.setDepotNo(sellerOrderGoodses.get(0).getDepotNo());
}
Integer startTime = null != record.getStartTime() ? record.getStartTime() : liveRecordTimeMapper.selectByOrderCode(Long.valueOf(record.getOrderCode()));
result.setSkup(record.getSkup());
result.setDepotNo(record.getDepotNo());
result.setStartTime(record.getStartTime());
result.setStartTime(startTime);
result.setPid(record.getUserId());
result.setOrderCode(Long.valueOf(record.getOrderCode()));
result.setEndTime(DateUtil.getCurrentTimeSeconds()); // 鉴定通过和不通过的时候,默认视频结束
return result;
}
}
... ...
... ... @@ -12,9 +12,11 @@ import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.error.exception.ServiceException;
import com.yoho.order.dal.CameraRecordMapper;
import com.yoho.order.dal.LiveRecordTimeMapper;
import com.yoho.order.dal.QiniuLiveRecordMapper;
import com.yoho.order.dal.UserCameraRecordMapper;
import com.yoho.order.model.CameraRecord;
import com.yoho.order.model.LiveRecordTime;
import com.yoho.order.model.QiniuLiveRecord;
import com.yoho.order.model.UserCameraRecord;
import com.yoho.ufo.constants.RedisKeyConstants;
... ... @@ -40,6 +42,7 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
/**
... ... @@ -67,8 +70,9 @@ public class UfoLiveService {
@Autowired
private CameraRecordMapper cameraRecordMapper;
//@Autowired
//private UserCameraRecordMapper userCameraRecordMapper;
@Autowired
private LiveRecordTimeMapper liveRecordTimeMapper;
@Autowired
private ConfigReader configReader;
... ... @@ -194,12 +198,18 @@ public class UfoLiveService {
return null == cameraCode ? null : Integer.valueOf(cameraCode);
}
public Integer queryCurrentTime() throws PlatformException {
public Integer queryCurrentTime(Long orderCode) throws PlatformException {
Integer userId = new UserHelper().getUserId();
RedisKeyBuilder key = RedisKeyBuilder.newInstance().appendFixed(RedisKeyConstants.LIVE_USER).appendVar(userId);
if (redisTemplate.hasKey(key)) {
return DateUtil.getCurrentTimeSeconds();
int currentTimeSeconds = DateUtil.getCurrentTimeSeconds();
if (!Objects.isNull(orderCode)) {
liveRecordTimeMapper.insertOrUpdate(new LiveRecordTime(orderCode, currentTimeSeconds));
}
return currentTimeSeconds;
}
throw new PlatformException("没有选择摄像头", 400);
}
... ...