You've already forked FrameTour-BE
加点缓存
This commit is contained in:
@ -0,0 +1,7 @@
|
|||||||
|
package com.ycwl.basic.face.repository;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class FaceRepository {
|
||||||
|
}
|
@ -17,6 +17,7 @@ public class GoodsPageVO {
|
|||||||
private String goodsName;
|
private String goodsName;
|
||||||
@ApiModelProperty("景区id")
|
@ApiModelProperty("景区id")
|
||||||
private Long scenicId;
|
private Long scenicId;
|
||||||
|
private Long faceId;
|
||||||
@ApiModelProperty("景区名称")
|
@ApiModelProperty("景区名称")
|
||||||
private String scenicName;
|
private String scenicName;
|
||||||
@ApiModelProperty("商品类型 1:成片视频 2:源素材")
|
@ApiModelProperty("商品类型 1:成片视频 2:源素材")
|
||||||
|
@ -35,6 +35,7 @@ public class SourceRespVO {
|
|||||||
*/
|
*/
|
||||||
@ApiModelProperty("来源设备id")
|
@ApiModelProperty("来源设备id")
|
||||||
private Long deviceId;
|
private Long deviceId;
|
||||||
|
private Long faceId;
|
||||||
@ApiModelProperty("原素材类型:1视频,2图像")
|
@ApiModelProperty("原素材类型:1视频,2图像")
|
||||||
private Integer type;
|
private Integer type;
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,7 @@ public class VideoRespVO {
|
|||||||
*/
|
*/
|
||||||
@ApiModelProperty("用户id")
|
@ApiModelProperty("用户id")
|
||||||
private Long memberId;
|
private Long memberId;
|
||||||
|
private Long faceId;
|
||||||
/**
|
/**
|
||||||
* 模版id
|
* 模版id
|
||||||
*/
|
*/
|
||||||
|
@ -68,6 +68,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|||||||
goodsPageVO.setScenicId(videoRespVO.getScenicId());
|
goodsPageVO.setScenicId(videoRespVO.getScenicId());
|
||||||
goodsPageVO.setScenicName(videoRespVO.getScenicName());
|
goodsPageVO.setScenicName(videoRespVO.getScenicName());
|
||||||
goodsPageVO.setGoodsType(0);
|
goodsPageVO.setGoodsType(0);
|
||||||
|
goodsPageVO.setFaceId(videoRespVO.getFaceId());
|
||||||
goodsPageVO.setGoodsId(videoRespVO.getId());
|
goodsPageVO.setGoodsId(videoRespVO.getId());
|
||||||
goodsPageVO.setTemplateName(videoRespVO.getTemplateName());
|
goodsPageVO.setTemplateName(videoRespVO.getTemplateName());
|
||||||
goodsPageVO.setTemplateCoverUrl(videoRespVO.getTemplateCoverUrl());
|
goodsPageVO.setTemplateCoverUrl(videoRespVO.getTemplateCoverUrl());
|
||||||
@ -81,20 +82,32 @@ public class GoodsServiceImpl implements GoodsService {
|
|||||||
sourceReqQuery.setMemberId(Long.valueOf(BaseContextHandler.getUserId()));
|
sourceReqQuery.setMemberId(Long.valueOf(BaseContextHandler.getUserId()));
|
||||||
//查询源素材
|
//查询源素材
|
||||||
List<SourceRespVO> sourceList = sourceMapper.queryByRelation(sourceReqQuery);
|
List<SourceRespVO> sourceList = sourceMapper.queryByRelation(sourceReqQuery);
|
||||||
sourceList.stream().collect(Collectors.groupingBy(SourceRespVO::getType)).forEach((type, value) -> {
|
List<GoodsPageVO> sourceGoods = sourceList.stream().collect(Collectors.groupingBy(SourceRespVO::getFaceId)).entrySet().stream().flatMap((faceEntry) -> {
|
||||||
GoodsPageVO goodsPageVO = new GoodsPageVO();
|
Long faceId = faceEntry.getKey();
|
||||||
if (type == 1) {
|
List<SourceRespVO> goods = faceEntry.getValue();
|
||||||
goodsPageVO.setGoodsName("原片集");
|
return goods.stream().collect(Collectors.groupingBy(SourceRespVO::getType)).entrySet().stream().map((typeEntry) -> {
|
||||||
goodsPageVO.setGoodsType(1);
|
Integer type = typeEntry.getKey();
|
||||||
} else {
|
GoodsPageVO goodsPageVO = new GoodsPageVO();
|
||||||
goodsPageVO.setGoodsName("照片集");
|
goodsPageVO.setFaceId(faceId);
|
||||||
goodsPageVO.setGoodsType(2);
|
if (type == 1) {
|
||||||
}
|
goodsPageVO.setGoodsName("原片集");
|
||||||
goodsPageVO.setScenicId(query.getScenicId());
|
goodsPageVO.setGoodsType(1);
|
||||||
goodsList.add(goodsPageVO);
|
} else {
|
||||||
});
|
goodsPageVO.setGoodsName("照片集");
|
||||||
|
goodsPageVO.setGoodsType(2);
|
||||||
return ApiResponse.success(goodsList);
|
}
|
||||||
|
goodsPageVO.setScenicId(query.getScenicId());
|
||||||
|
return goodsPageVO;
|
||||||
|
});
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
if (!sourceGoods.isEmpty()) {
|
||||||
|
if (goodsList.size() > 2) {
|
||||||
|
goodsList.addAll(2, sourceGoods);
|
||||||
|
} else {
|
||||||
|
goodsList.addAll(sourceGoods);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ApiResponse.success(goodsList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,106 +78,106 @@ public class VideoPieceGetter {
|
|||||||
queue.add(task);
|
queue.add(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(fixedDelay = 1000L)
|
@Scheduled(fixedRate = 2000L)
|
||||||
public void doTask() {
|
public void doTask() {
|
||||||
Task task = queue.poll();
|
Task task = queue.poll();
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("poll task: {}", task);
|
log.info("poll task: {}", task);
|
||||||
if (!task.getType().equalsIgnoreCase("normal")) {
|
if (task.getType().equalsIgnoreCase("normal")) {
|
||||||
task.getCallback().onInvoke();
|
task.getFaceSampleId().parallelStream().forEach(faceSampleId -> {
|
||||||
return;
|
FaceSampleRespVO faceSample = faceSampleMapper.getById(faceSampleId);
|
||||||
}
|
DeviceEntity device = deviceRepository.getDevice(faceSample.getDeviceId());
|
||||||
task.getFaceSampleId().parallelStream().forEach(faceSampleId -> {
|
DeviceConfigEntity config = deviceRepository.getDeviceConfig(faceSample.getDeviceId());
|
||||||
FaceSampleRespVO faceSample = faceSampleMapper.getById(faceSampleId);
|
|
||||||
DeviceEntity device = deviceRepository.getDevice(faceSample.getDeviceId());
|
|
||||||
DeviceConfigEntity config = deviceRepository.getDeviceConfig(faceSample.getDeviceId());
|
|
||||||
|
|
||||||
SourceEntity source = sourceMapper.querySameVideo(faceSample.getId(), device.getId());
|
SourceEntity source = sourceMapper.querySameVideo(faceSample.getId(), device.getId());
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
// 有原视频
|
// 有原视频
|
||||||
int count = sourceMapper.hasRelationTo(task.getMemberId(), source.getId(), 1);
|
int count = sourceMapper.hasRelationTo(task.getMemberId(), source.getId(), 1);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||||
|
videoSource.setId(SnowFlakeUtil.getLongId());
|
||||||
|
videoSource.setScenicId(faceSample.getScenicId());
|
||||||
|
videoSource.setFaceId(task.getFaceId());
|
||||||
|
videoSource.setMemberId(task.getMemberId());
|
||||||
|
videoSource.setType(1);
|
||||||
|
videoSource.setIsBuy(0);
|
||||||
|
videoSource.setSourceId(source.getId());
|
||||||
|
sourceMapper.addRelation(videoSource);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
BigDecimal cutPre = BigDecimal.valueOf(5L);
|
||||||
|
BigDecimal cutPost = BigDecimal.valueOf(4L);
|
||||||
|
if (config == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 有配置
|
||||||
|
if (config.getCutPre() != null) {
|
||||||
|
cutPre = config.getCutPre();
|
||||||
|
}
|
||||||
|
if (config.getCutPost() != null) {
|
||||||
|
cutPost = config.getCutPost();
|
||||||
|
}
|
||||||
|
IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, config);
|
||||||
|
if (pieceGetter == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
BigDecimal duration = cutPre.add(cutPost);
|
||||||
|
List<FileObject> listByDtRange = pieceGetter.getFileListByDtRange(
|
||||||
|
new Date(faceSample.getCreateAt().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue()),
|
||||||
|
new Date(faceSample.getCreateAt().getTime() + cutPost.multiply(BigDecimal.valueOf(1000)).longValue())
|
||||||
|
);
|
||||||
|
if (listByDtRange.isEmpty()) {
|
||||||
|
log.warn("没有可用的文件");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
long offset = faceSample.getCreateAt().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue() - listByDtRange.get(0).getCreateTime().getTime();
|
||||||
|
FfmpegTask ffmpegTask = new FfmpegTask();
|
||||||
|
ffmpegTask.setFileList(listByDtRange);
|
||||||
|
ffmpegTask.setDuration(duration);
|
||||||
|
ffmpegTask.setOffsetStart(BigDecimal.valueOf(offset, 3));
|
||||||
|
File outFile = new File(faceSample.getDeviceId().toString() + "_" + faceSample.getId() + ".mp4");
|
||||||
|
ffmpegTask.setOutputFile(outFile.getAbsolutePath());
|
||||||
|
boolean result = startFfmpegTask(ffmpegTask);
|
||||||
|
if (!result) {
|
||||||
|
log.warn("视频裁切失败");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.info("视频裁切成功");
|
||||||
|
IStorageAdapter adapter = StorageFactory.use("assets");
|
||||||
|
String url = adapter.uploadFile(outFile, "video-source", outFile.getName());
|
||||||
|
// 上传成功后删除文件
|
||||||
|
outFile.delete();
|
||||||
|
SourceEntity imgSource = sourceMapper.findBySampleId(faceSample.getId());
|
||||||
|
SourceEntity sourceEntity = new SourceEntity();
|
||||||
|
sourceEntity.setId(SnowFlakeUtil.getLongId());
|
||||||
|
sourceEntity.setCreateTime(faceSample.getCreateAt());
|
||||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
MemberSourceEntity videoSource = new MemberSourceEntity();
|
||||||
videoSource.setId(SnowFlakeUtil.getLongId());
|
|
||||||
videoSource.setScenicId(faceSample.getScenicId());
|
|
||||||
videoSource.setFaceId(task.getFaceId());
|
|
||||||
videoSource.setMemberId(task.getMemberId());
|
videoSource.setMemberId(task.getMemberId());
|
||||||
videoSource.setType(1);
|
videoSource.setType(1);
|
||||||
videoSource.setIsBuy(0);
|
videoSource.setIsBuy(0);
|
||||||
videoSource.setSourceId(source.getId());
|
videoSource.setFaceId(task.getFaceId());
|
||||||
|
videoSource.setScenicId(faceSample.getScenicId());
|
||||||
|
videoSource.setSourceId(sourceEntity.getId());
|
||||||
|
if (imgSource != null) {
|
||||||
|
sourceEntity.setUrl(imgSource.getUrl());
|
||||||
|
sourceEntity.setPosJson(imgSource.getPosJson());
|
||||||
|
}
|
||||||
|
sourceEntity.setVideoUrl(url);
|
||||||
|
sourceEntity.setFaceSampleId(faceSample.getId());
|
||||||
|
sourceEntity.setScenicId(faceSample.getScenicId());
|
||||||
|
sourceEntity.setDeviceId(faceSample.getDeviceId());
|
||||||
|
sourceEntity.setType(1);
|
||||||
|
sourceMapper.add(sourceEntity);
|
||||||
sourceMapper.addRelation(videoSource);
|
sourceMapper.addRelation(videoSource);
|
||||||
return;
|
});
|
||||||
}
|
}
|
||||||
BigDecimal cutPre = BigDecimal.valueOf(5L);
|
if (null != task.getCallback()) {
|
||||||
BigDecimal cutPost = BigDecimal.valueOf(4L);
|
task.getCallback().onInvoke();
|
||||||
if (config == null) {
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 有配置
|
|
||||||
if (config.getCutPre() != null) {
|
|
||||||
cutPre = config.getCutPre();
|
|
||||||
}
|
|
||||||
if (config.getCutPost() != null) {
|
|
||||||
cutPost = config.getCutPost();
|
|
||||||
}
|
|
||||||
IDeviceStorageOperator pieceGetter = DeviceFactory.getDeviceStorageOperator(device, config);
|
|
||||||
if (pieceGetter == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BigDecimal duration = cutPre.add(cutPost);
|
|
||||||
List<FileObject> listByDtRange = pieceGetter.getFileListByDtRange(
|
|
||||||
new Date(faceSample.getCreateAt().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue()),
|
|
||||||
new Date(faceSample.getCreateAt().getTime() + cutPost.multiply(BigDecimal.valueOf(1000)).longValue())
|
|
||||||
);
|
|
||||||
if (listByDtRange.isEmpty()) {
|
|
||||||
log.warn("没有可用的文件");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
long offset = faceSample.getCreateAt().getTime() - cutPre.multiply(BigDecimal.valueOf(1000)).longValue() - listByDtRange.get(0).getCreateTime().getTime();
|
|
||||||
FfmpegTask ffmpegTask = new FfmpegTask();
|
|
||||||
ffmpegTask.setFileList(listByDtRange);
|
|
||||||
ffmpegTask.setDuration(duration);
|
|
||||||
ffmpegTask.setOffsetStart(BigDecimal.valueOf(offset, 3));
|
|
||||||
File outFile = new File(faceSample.getDeviceId().toString() + "_" + faceSample.getId() + ".mp4");
|
|
||||||
ffmpegTask.setOutputFile(outFile.getAbsolutePath());
|
|
||||||
boolean result = startFfmpegTask(ffmpegTask);
|
|
||||||
if (!result) {
|
|
||||||
log.warn("视频裁切失败");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log.info("视频裁切成功");
|
|
||||||
IStorageAdapter adapter = StorageFactory.use("assets");
|
|
||||||
String url = adapter.uploadFile(outFile, "video-source", outFile.getName());
|
|
||||||
// 上传成功后删除文件
|
|
||||||
outFile.delete();
|
|
||||||
SourceEntity imgSource = sourceMapper.findBySampleId(faceSample.getId());
|
|
||||||
SourceEntity sourceEntity = new SourceEntity();
|
|
||||||
sourceEntity.setId(SnowFlakeUtil.getLongId());
|
|
||||||
sourceEntity.setCreateTime(faceSample.getCreateAt());
|
|
||||||
MemberSourceEntity videoSource = new MemberSourceEntity();
|
|
||||||
videoSource.setMemberId(task.getMemberId());
|
|
||||||
videoSource.setType(1);
|
|
||||||
videoSource.setIsBuy(0);
|
|
||||||
videoSource.setFaceId(task.getFaceId());
|
|
||||||
videoSource.setScenicId(faceSample.getScenicId());
|
|
||||||
videoSource.setSourceId(sourceEntity.getId());
|
|
||||||
if (imgSource != null) {
|
|
||||||
sourceEntity.setUrl(imgSource.getUrl());
|
|
||||||
sourceEntity.setPosJson(imgSource.getPosJson());
|
|
||||||
}
|
|
||||||
sourceEntity.setVideoUrl(url);
|
|
||||||
sourceEntity.setFaceSampleId(faceSample.getId());
|
|
||||||
sourceEntity.setScenicId(faceSample.getScenicId());
|
|
||||||
sourceEntity.setDeviceId(faceSample.getDeviceId());
|
|
||||||
sourceEntity.setType(1);
|
|
||||||
sourceMapper.add(sourceEntity);
|
|
||||||
sourceMapper.addRelation(videoSource);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean startFfmpegTask(FfmpegTask task) {
|
public boolean startFfmpegTask(FfmpegTask task) {
|
||||||
|
@ -55,8 +55,6 @@ mybatis-plus:
|
|||||||
# 开启驼峰命名法
|
# 开启驼峰命名法
|
||||||
map-underscore-to-camel-case: true
|
map-underscore-to-camel-case: true
|
||||||
use-generated-keys: true
|
use-generated-keys: true
|
||||||
# 这个配置会将执行的sql打印出来,在开发或测试的时候可以用
|
|
||||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
|
||||||
# 指定使用的日志配置文件
|
# 指定使用的日志配置文件
|
||||||
logging:
|
logging:
|
||||||
config: classpath:logback-spring.xml
|
config: classpath:logback-spring.xml
|
||||||
|
@ -124,7 +124,7 @@
|
|||||||
order by so.create_time desc
|
order by so.create_time desc
|
||||||
</select>
|
</select>
|
||||||
<select id="queryByRelation" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
|
<select id="queryByRelation" resultType="com.ycwl.basic.model.pc.source.resp.SourceRespVO">
|
||||||
select so.id, ms.scenic_id, ms.type, so.url, so.create_time, so.update_time,sc.`name` as scenicName
|
select so.id, ms.face_id, ms.scenic_id, ms.type, so.url, so.create_time, so.update_time,sc.`name` as scenicName
|
||||||
from member_source ms
|
from member_source ms
|
||||||
left join source so on ms.source_id = so.id
|
left join source so on ms.source_id = so.id
|
||||||
left join scenic sc on sc.id = so.scenic_id
|
left join scenic sc on sc.id = so.scenic_id
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
select * from video where task_id = #{taskId} limit 1
|
select * from video where task_id = #{taskId} limit 1
|
||||||
</select>
|
</select>
|
||||||
<select id="queryByRelation" resultType="com.ycwl.basic.model.pc.video.resp.VideoRespVO">
|
<select id="queryByRelation" resultType="com.ycwl.basic.model.pc.video.resp.VideoRespVO">
|
||||||
select v.id, mv.scenic_id, v.template_id, mv.task_id, worker_id, video_url, v.create_time, v.update_time,
|
select v.id, mv.scenic_id, v.template_id, mv.task_id, mv.face_id, worker_id, video_url, v.create_time, v.update_time,
|
||||||
s.name scenicName, t.name templateName, t.price templatePrice,t.cover_url templateCoverUrl,mv.is_buy
|
s.name scenicName, t.name templateName, t.price templatePrice,t.cover_url templateCoverUrl,mv.is_buy
|
||||||
from member_video mv
|
from member_video mv
|
||||||
left join video v on mv.video_id = v.id
|
left join video v on mv.video_id = v.id
|
||||||
|
Reference in New Issue
Block a user