Commit 34f714fc authored by yanzg's avatar yanzg

参数处理

parent 17f61a23
...@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.file; ...@@ -2,6 +2,8 @@ package com.yanzuoguang.cloud.file;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import com.yanzuoguang.cloud.file.vo.YzgFileMoveReqVo; import com.yanzuoguang.cloud.file.vo.YzgFileMoveReqVo;
import com.yanzuoguang.cloud.file.vo.YzgFileVideoImageItemReqVo;
import com.yanzuoguang.cloud.file.vo.YzgFileVideoImageReqVo;
import com.yanzuoguang.mq.service.MqService; import com.yanzuoguang.mq.service.MqService;
import com.yanzuoguang.util.exception.CodeException; import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
...@@ -12,6 +14,9 @@ import org.springframework.beans.factory.InitializingBean; ...@@ -12,6 +14,9 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/** /**
* 文件处理 * 文件处理
*/ */
...@@ -85,4 +90,78 @@ public class YzgFileConsumer implements InitializingBean { ...@@ -85,4 +90,78 @@ public class YzgFileConsumer implements InitializingBean {
mqService.basicAck(message, channel); mqService.basicAck(message, channel);
} }
} }
/**
* 处理文件转换
*
* @param json
* @param message
* @param channel
*/
@RabbitListener(queues = {YzgFileProcedure.YZG_CONVERT_IMAGE})
public void convertImage(String json, Message message, Channel channel) {
try {
YzgFileVideoImageReqVo req = JsonHelper.deserialize(json, YzgFileVideoImageReqVo.class);
// 等待下一次MQ执行
List<YzgFileVideoImageItemReqVo> cacheList = req.getList();
if (cacheList == null || cacheList.isEmpty()) {
return;
}
// 本次执行的转换操作
List<YzgFileVideoImageItemReqVo> runList = new ArrayList<>();
runList.add(cacheList.remove(0));
req.setList(runList);
// 执行本次转换
fileService.convertImage(req);
// 继续执行下一次转换
if (!cacheList.isEmpty()) {
req.setList(cacheList);
fileProcedure.convertImage(req);
}
} catch (CodeException ex) {
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
Log.error(YzgFileConsumer.class, ex);
fileProcedure.convertImage(json, 60 * 1000);
} finally {
mqService.basicAck(message, channel);
}
}
/**
* 处理视频转换
*
* @param json
* @param message
* @param channel
*/
@RabbitListener(queues = {YzgFileProcedure.YZG_CONVERT_VIDEO})
public void convertVideo(String json, Message message, Channel channel) {
try {
YzgFileVideoImageReqVo req = JsonHelper.deserialize(json, YzgFileVideoImageReqVo.class);
// 等待下一次MQ执行
List<YzgFileVideoImageItemReqVo> cacheList = req.getList();
if (cacheList == null || cacheList.isEmpty()) {
return;
}
// 本次执行的转换操作
List<YzgFileVideoImageItemReqVo> runList = new ArrayList<>();
runList.add(cacheList.remove(0));
req.setList(runList);
// 执行本次转换
fileService.convertVideo(req);
// 继续执行下一次转换
if (!cacheList.isEmpty()) {
req.setList(cacheList);
fileProcedure.convertVideo(req);
}
} catch (CodeException ex) {
Log.error(YzgFileConsumer.class, ex);
} catch (Exception ex) {
Log.error(YzgFileConsumer.class, ex);
fileProcedure.convertVideo(json, 60 * 1000);
} finally {
mqService.basicAck(message, channel);
}
}
} }
...@@ -261,6 +261,13 @@ public class YzgFileServiceImpl implements YzgFileService { ...@@ -261,6 +261,13 @@ public class YzgFileServiceImpl implements YzgFileService {
// 来源文件路径 // 来源文件路径
String from = fileConfig.getServerFullPath(req.getFrom()); String from = fileConfig.getServerFullPath(req.getFrom());
YzgFileBaseVo fromInfo = new YzgFileBaseVo();
fileConfig.init(fromInfo, from);
if (fromInfo.getType() != FileHelper.FILE_TYPE_VIDEO) {
throw new CodeException("请传入视频文件");
}
// 循环转换所有文件
for (YzgFileVideoImageItemReqVo item : req.getList()) { for (YzgFileVideoImageItemReqVo item : req.getList()) {
String to = fileConfig.getServerFullPath(item.getTo()); String to = fileConfig.getServerFullPath(item.getTo());
// 先压缩到临时文件 // 先压缩到临时文件
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment