|
@@ -1,8 +1,10 @@
|
|
|
package com.xiaoan.service.backend.listener;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.xiaoan.common.constant.ConfigConstant;
|
|
|
+import com.xiaoan.common.exception.BaseRuntimeException;
|
|
|
import com.xiaoan.common.util.HttpRequestorUtil;
|
|
|
import com.xiaoan.domain.backend.SceneProEditEntity;
|
|
|
import com.xiaoan.domain.backend.SceneProEntity;
|
|
@@ -10,6 +12,7 @@ import com.xiaoan.service.backend.SceneProEditService;
|
|
|
import com.xiaoan.service.backend.SceneService;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.junit.Test;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -46,15 +49,19 @@ public class AsyncTask {
|
|
|
if (!Variable.queue.isEmpty()) {
|
|
|
String poll = Variable.queue.poll();
|
|
|
String id = StringUtils.substringAfterLast(poll, ",");
|
|
|
+ SceneProEntity proEntity = sceneProService.findById(Long.valueOf(id));
|
|
|
try {
|
|
|
log.info("start process ");
|
|
|
- this.process(Long.valueOf(id));
|
|
|
+ this.process(proEntity);
|
|
|
log.info("end process ");
|
|
|
} catch (Exception e) {
|
|
|
+ proEntity.setDownloadStatus(3);
|
|
|
+ proEntity.setUpdateTime(new Date());
|
|
|
+ sceneProService.update(proEntity);
|
|
|
log.error("文件发送失败");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- log.info("poll消费: {}", poll);
|
|
|
+ log.info("poll消费完成: {}", poll);
|
|
|
|
|
|
// 队列为空, 休眠
|
|
|
} else {
|
|
@@ -73,13 +80,10 @@ public class AsyncTask {
|
|
|
|
|
|
/**
|
|
|
* 处理逻辑
|
|
|
- * @param id
|
|
|
+ * @param
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
- public void process(Long id) throws Exception {
|
|
|
-
|
|
|
- SceneProEntity proEntity = sceneProService.findById(id);
|
|
|
-
|
|
|
+ public void process(SceneProEntity proEntity) throws Exception {
|
|
|
|
|
|
if (proEntity == null) {
|
|
|
log.error("对象为空");
|
|
@@ -88,7 +92,12 @@ public class AsyncTask {
|
|
|
|
|
|
if (proEntity.getDownloadStatus() >= 1) {
|
|
|
String api = configConstant.REMOTE_API + "?sceneNum=" + proEntity.getNum();
|
|
|
- int i = HttpRequestorUtil.fileRemote(api, configConstant.SERVER_PACKAGE_RESULT + proEntity.getNum() + ".zip");
|
|
|
+ String filePath = configConstant.SERVER_PACKAGE_RESULT + proEntity.getNum() + ".zip";
|
|
|
+ if (!FileUtil.isFile(filePath)) {
|
|
|
+ log.error("文件不存在:{}", filePath);
|
|
|
+ new BaseRuntimeException("文件不存在");
|
|
|
+ }
|
|
|
+ int i = HttpRequestorUtil.fileRemote(api, filePath);
|
|
|
if (i == 200) {
|
|
|
log.info("文件发送成功");
|
|
|
|
|
@@ -106,8 +115,9 @@ public class AsyncTask {
|
|
|
log.error("发送insertSceneProInfo接口失败");
|
|
|
proEntity.setDownloadStatus(3);
|
|
|
} else {
|
|
|
+ log.info("insertSceneProInfo 请求完成");
|
|
|
// 成功
|
|
|
- SceneProEditEntity proEditEntity = sceneProEditService.findByProId(id);
|
|
|
+ SceneProEditEntity proEditEntity = sceneProEditService.findByProId(proEntity.getId());
|
|
|
// 将返回值id更新
|
|
|
log.info("proId 准备更新");
|
|
|
JSONObject dataJson = proJson.getJSONObject("data");
|
|
@@ -118,6 +128,8 @@ public class AsyncTask {
|
|
|
if (!"0".equals(s)){
|
|
|
log.error("发送insertSceneProEditInfo接口失败");
|
|
|
proEntity.setDownloadStatus(3);
|
|
|
+ } else {
|
|
|
+ log.info("insertSceneProEditInfo 请求完成");
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -140,6 +152,7 @@ public class AsyncTask {
|
|
|
|
|
|
proEntity.setWebSite(editDomain(proEntity.getWebSite()));
|
|
|
proEntity.setThumb(editDomain(proEntity.getThumb()));
|
|
|
+ proEntity.setVideos(editVideos(proEntity.getVideos()));
|
|
|
proEntity.setDownloadStatus(-1);
|
|
|
|
|
|
log.info("send proEntity: {}", proEntity.toString());
|
|
@@ -152,7 +165,7 @@ public class AsyncTask {
|
|
|
|
|
|
private String insertSceneProEditInfo(SceneProEditEntity proEditEntity) throws Exception {
|
|
|
// /api/scene/insertSceneProEditInfo
|
|
|
- String api = configConstant.SERVER_DOMIAN + "/api/scene/insertSceneProEditInfo";
|
|
|
+ String api = configConstant.REMOTE_DOMIAN + "/api/scene/insertSceneProEditInfo";
|
|
|
log.info("send proEditEntity: {}", proEditEntity.toString());
|
|
|
String post = HttpRequestorUtil.postJson(api, JSON.toJSONString(proEditEntity), "POST");
|
|
|
log.info("response proEditEntity: {}", post);
|
|
@@ -164,10 +177,26 @@ public class AsyncTask {
|
|
|
|
|
|
// 编辑远程域名
|
|
|
private String editDomain(String url){
|
|
|
-// log.info("url input: {}", url);
|
|
|
- url = StringUtils.substringAfterLast(url, ":");
|
|
|
- url = StringUtils.substringAfter(url, "/");
|
|
|
-// log.info("url output: {}", url);
|
|
|
- return configConstant.REMOTE_DOMIAN + "/" + url;
|
|
|
+ // 需要注意weiSite的url
|
|
|
+ url = StringUtils.substringAfterLast(url, "icloud3d.net");
|
|
|
+ return configConstant.REMOTE_DOMIAN + url;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private String editVideos(String str){
|
|
|
+ String replace = str.replace("http://icloud3d.net/", configConstant.REMOTE_DOMIAN);
|
|
|
+ return replace;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void tes(){
|
|
|
+ String url = "{\"data\":[],\"upPath\":\"http://icloud3d.net/scene/data/dataxa-7Rg2CA0T0/Up.xml\",\"version\":3}";
|
|
|
+ System.out.println(editVideos(url));
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|