Commit 8880737a by 李传峰

Merge branch 'hotfix/jedis' into 'release'

Hotfix/jedis

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