Commit 679155e3 by 郑永强

bug: [none] jedis NPE 解决

parent 58ce2ed2
package com.pcloud.book.mq.topic;
import com.google.common.collect.Maps;
import com.pcloud.book.advertising.biz.AdvertisingSpaceBiz;
import com.pcloud.book.advertising.entity.AdvertisingSpace;
import com.pcloud.common.core.aspect.ParamLog;
......@@ -12,20 +11,18 @@ import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.FileUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.contentcenter.resource.enums.ResourceTypeEnum;
import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Map;
import javax.annotation.PostConstruct;
/**
* @描述:文件转码
* @作者:zhuyajie
......@@ -37,7 +34,6 @@ import javax.annotation.PostConstruct;
public class ConvertFileListener {
private static final Logger LOGGER = LoggerFactory.getLogger(ConvertFileListener.class);
private static ConvertFileListener convertFileListener;
@Autowired
private AdvertisingSpaceBiz advertisingSpaceBiz;
......@@ -46,56 +42,41 @@ public class ConvertFileListener {
*/
private static Map<String, ConvertQueueDto> cqds = Maps.newHashMap();
private static Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
//如果cqds没有记录,休眠60秒
if (MapUtils.isEmpty(cqds)) {
try {
Thread.sleep(1000 * 60);
} catch (InterruptedException e) {
LOGGER.error("pmrismap线程执行出错", e);
}
} else {
for (Map.Entry<String, ConvertQueueDto> e : cqds.entrySet()) {
if (e.getValue() != null) {
ConvertQueueDto convertFileDto = e.getValue();
LOGGER.info("转码后信息>>>>>" + convertFileDto.toString());
String fileCategory = FileUtils.getGatherName(convertFileDto.getFileType());
String fileId = convertFileDto.getFileId();
String fileUrl = convertFileDto.getFileUrl();
if (ResourceTypeEnum.AUDIO.code.equals(fileCategory) || ResourceTypeEnum.VIDEO.code.equals(fileCategory)) {
List<AdvertisingSpace> filelist = convertFileListener.advertisingSpaceBiz.getUnConvertFile(fileId);
if (!ListUtils.isEmpty(filelist)) {
//更新
convertFileListener.advertisingSpaceBiz.updateFile(filelist, fileUrl);
cqds.remove(e.getKey());
} else {
if (convertFileDto.getProcessTimes() < 10) {
convertFileDto.setProcessTimes(convertFileDto.getProcessTimes() + 1);
LOGGER.info("音频资源 ,未找到对应记录,进入下一个循环!fileid=" + convertFileDto.getFileId());
} else {
cqds.remove(e.getKey());
}
}
}
@Scheduled(fixedDelay = 1000 * 60)
public void run() {
//如果cqds没有记录,休眠60秒
if (MapUtils.isEmpty(cqds)) {
return;
}
for (Map.Entry<String, ConvertQueueDto> e : cqds.entrySet()) {
if (e.getValue() != null) {
ConvertQueueDto convertFileDto = e.getValue();
LOGGER.info("转码后信息>>>>>" + convertFileDto.toString());
String fileCategory = FileUtils.getGatherName(convertFileDto.getFileType());
String fileId = convertFileDto.getFileId();
String fileUrl = convertFileDto.getFileUrl();
if (ResourceTypeEnum.AUDIO.code.equals(fileCategory) || ResourceTypeEnum.VIDEO.code.equals(fileCategory)) {
List<AdvertisingSpace> filelist = advertisingSpaceBiz.getUnConvertFile(fileId);
if (!ListUtils.isEmpty(filelist)) {
//更新
advertisingSpaceBiz.updateFile(filelist, fileUrl);
cqds.remove(e.getKey());
} else {
if (convertFileDto.getProcessTimes() < 10) {
convertFileDto.setProcessTimes(convertFileDto.getProcessTimes() + 1);
LOGGER.info("音频资源 ,未找到对应记录,进入下一个循环!fileid=" + convertFileDto.getFileId());
} else {
// 当该key内无实体时,即清除
cqds.remove(e.getKey());
}
}
}
} else {
// 当该key内无实体时,即清除
cqds.remove(e.getKey());
}
}
});
// 开始缓存处理
static {
t1.start();
}
@RabbitHandler
@ParamLog("文件转码")
public void process(ConvertQueueDto convertQueueDto) throws BizException {
......@@ -120,22 +101,14 @@ public class ConvertFileListener {
String fileUrl = convertFileDto.getFileUrl();
// 修改点读书音频转码后的地址
if (ResourceTypeEnum.AUDIO.code.equals(fileCategory)) {
List<AdvertisingSpace> filelist = convertFileListener.advertisingSpaceBiz.getUnConvertFile(fileId);
List<AdvertisingSpace> filelist = advertisingSpaceBiz.getUnConvertFile(fileId);
if (ListUtils.isEmpty(filelist)) {
LOGGER.info("接收到转码状态时,数据库还未插入记录,先将音频转码信息放到缓存fileId=" + fileId + "convertFileDto=" + convertFileDto.toString());
cqds.put(fileId, convertFileDto);
} else {
convertFileListener.advertisingSpaceBiz.updateFile(filelist, fileUrl);
advertisingSpaceBiz.updateFile(filelist, fileUrl);
}
}
}
}
@PostConstruct
public void init() {
convertFileListener = this;
convertFileListener.advertisingSpaceBiz = this.advertisingSpaceBiz;
}
}
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