|
@@ -1,5 +1,6 @@
|
|
|
package com.sooka.sponest.data.utils;
|
|
|
|
|
|
+import com.ruoyi.common.core.utils.DateUtils;
|
|
|
import com.ruoyi.common.core.utils.SpringUtils;
|
|
|
import com.ruoyi.common.core.utils.file.FilePrefixUtils;
|
|
|
import com.ruoyi.common.redis.service.RedisService;
|
|
@@ -11,23 +12,19 @@ import org.apache.commons.collections4.MapUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
-import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
-import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.File;
|
|
|
-import java.net.HttpURLConnection;
|
|
|
-import java.net.URL;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
-@Configuration
|
|
|
-@EnableScheduling
|
|
|
-//@RestController
|
|
|
-//@RequestMapping("/testattach")
|
|
|
+//@Configuration
|
|
|
+//@EnableScheduling
|
|
|
+@RestController
|
|
|
+@RequestMapping("/testattach")
|
|
|
public class ScheduleAtachUtil {
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
@@ -58,38 +55,20 @@ public class ScheduleAtachUtil {
|
|
|
}
|
|
|
|
|
|
//每周的周日晚上8点开始运行
|
|
|
- @Scheduled(cron = "0 0 20 ? * 1")
|
|
|
+// @Scheduled(cron = "0 0 20 ? * 1")
|
|
|
@GetMapping("/urlToMultipartFile")
|
|
|
public void urlToMultipartFile() {
|
|
|
Map<String, String> paramMap = SpringUtils.getBean(RemoteConfigService.class).remotegetConfigMap(Arrays.asList(FILE_PREFIX_LOCAL, FILE_PREFIX_HIK1, FILE_PREFIX_HIK2, FILE_PREFIX_DH1, FILE_PREFIX_DH2)).getData();
|
|
|
List<Map<String, Object>> attaches = centerdataTAttachService.selectFailUpattah();
|
|
|
for (Map<String, Object> item : attaches) {
|
|
|
paramMap.put("token", redisService.getCacheObject("DH_TOKEN"));// 大华token
|
|
|
- File file = null;
|
|
|
- MultipartFile multipartFile = null;
|
|
|
String url = "";
|
|
|
if ("DH_1".equals(item.get("BusSource"))) {
|
|
|
url = FilePrefixUtils.getUrlPrefix(item.get("BusSource").toString(), paramMap) + item.get("url") + "?token=" + MapUtils.getString(paramMap, "token");
|
|
|
} else {
|
|
|
url = FilePrefixUtils.getUrlPrefix(item.get("BusSource").toString(), paramMap) + item.get("url");
|
|
|
}
|
|
|
- HttpURLConnection httpUrl = null;
|
|
|
- try {
|
|
|
- httpUrl = (HttpURLConnection) new URL(url).openConnection();
|
|
|
- // 设置连接超时时间为5秒
|
|
|
- httpUrl.setConnectTimeout(5000);
|
|
|
- // 设置读取超时时间为10秒
|
|
|
- httpUrl.setReadTimeout(10000);
|
|
|
- httpUrl.connect();
|
|
|
- file = FilePrefixUtils.inputStreamToFile(httpUrl.getInputStream(), System.currentTimeMillis() + ".jpg");
|
|
|
- multipartFile = FilePrefixUtils.fileToMultipartFile(file);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.info(e.getMessage());
|
|
|
- } finally {
|
|
|
- if (null != httpUrl) {
|
|
|
- httpUrl.disconnect();
|
|
|
- }
|
|
|
- }
|
|
|
+ MultipartFile multipartFile = FilePrefixUtils.urlToMultipartFile(url, System.currentTimeMillis() + ".jpg");
|
|
|
if (null != multipartFile) {
|
|
|
SysFile sysFile = SpringUtils.getBean(RemoteFileService.class).upload(multipartFile).getData();
|
|
|
try {
|
|
@@ -101,5 +80,6 @@ public class ScheduleAtachUtil {
|
|
|
centerdataTAttachService.updateEventAttachSchedule(item, sysFile);
|
|
|
}
|
|
|
}
|
|
|
+ logger.info(DateUtils.getDate() + "处理异常数据:" + attaches.size());
|
|
|
}
|
|
|
}
|