|
@@ -1,5 +1,7 @@
|
|
package com.fdkankan.scene.service.impl;
|
|
package com.fdkankan.scene.service.impl;
|
|
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -15,6 +17,7 @@ import com.fdkankan.redis.util.RedisClient;
|
|
import com.fdkankan.scene.bean.ResultData;
|
|
import com.fdkankan.scene.bean.ResultData;
|
|
import com.fdkankan.scene.entity.Scene;
|
|
import com.fdkankan.scene.entity.Scene;
|
|
import com.fdkankan.scene.entity.SceneFileMapping;
|
|
import com.fdkankan.scene.entity.SceneFileMapping;
|
|
|
|
+import com.fdkankan.scene.httpclient.CustomHttpClient;
|
|
import com.fdkankan.scene.mapper.SceneMapper;
|
|
import com.fdkankan.scene.mapper.SceneMapper;
|
|
import com.fdkankan.scene.service.SceneFileMappingService;
|
|
import com.fdkankan.scene.service.SceneFileMappingService;
|
|
import com.fdkankan.scene.service.SceneService;
|
|
import com.fdkankan.scene.service.SceneService;
|
|
@@ -25,9 +28,20 @@ import io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.core.io.UrlResource;
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.net.MalformedURLException;
|
|
|
|
+import java.net.URL;
|
|
|
|
+import java.net.URLConnection;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
@@ -61,6 +75,8 @@ public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements
|
|
private TietaFeignClient tietaFeignClient;
|
|
private TietaFeignClient tietaFeignClient;
|
|
@Autowired
|
|
@Autowired
|
|
private WS4AServiceClient ws4AServiceClient;
|
|
private WS4AServiceClient ws4AServiceClient;
|
|
|
|
+ @Resource
|
|
|
|
+ private CustomHttpClient customHttpClient;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public ResultData getSceneInfo(SceneInfoParamVO param) throws Exception {
|
|
public ResultData getSceneInfo(SceneInfoParamVO param) throws Exception {
|
|
@@ -120,12 +136,49 @@ public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements
|
|
}
|
|
}
|
|
|
|
|
|
List<SceneFileMapping> mappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getNum, num));
|
|
List<SceneFileMapping> mappingList = sceneFileMappingService.list(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getNum, num));
|
|
- Map<String, String> keyMap = mappingList.stream().collect(Collectors.toMap(SceneFileMapping::getKey, SceneFileMapping::getUrl));
|
|
|
|
|
|
+ Map<String, String> keyMap = mappingList.stream().collect(Collectors.toMap(SceneFileMapping::getKey, v->{
|
|
|
|
+ return "service/scene/file?key=" + v.getKey();
|
|
|
|
+ }));
|
|
sceneInfoVO.setMapping(keyMap);
|
|
sceneInfoVO.setMapping(keyMap);
|
|
|
|
|
|
return ResultData.ok(sceneInfoVO);
|
|
return ResultData.ok(sceneInfoVO);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseEntity<org.springframework.core.io.Resource> outFileByKey(String key, HttpServletResponse response) throws IOException {
|
|
|
|
+ SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key));
|
|
|
|
+// InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
|
|
|
|
+ org.springframework.core.io.Resource resource = null;
|
|
|
|
+ URL url = new URL(one.getUrl());
|
|
|
|
+ URLConnection connection = url.openConnection();
|
|
|
|
+ connection.setConnectTimeout(600000);
|
|
|
|
+ connection.setReadTimeout(600000);
|
|
|
|
+ resource = new UrlResource(url);
|
|
|
|
+ return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).body(resource);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void outFileByKey2(String key, HttpServletResponse response) throws IOException {
|
|
|
|
+ SceneFileMapping one = sceneFileMappingService.getOne(new LambdaQueryWrapper<SceneFileMapping>().eq(SceneFileMapping::getKey, key));
|
|
|
|
+ response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=\"" + FileUtil.getName(key) + "\"");
|
|
|
|
+ try(
|
|
|
|
+ InputStream inputStream = customHttpClient.downloadFileToInputStream(one.getUrl());
|
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream())
|
|
|
|
+ {
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int len;
|
|
|
|
+ while ((len = inputStream.read(buffer)) != -1) {
|
|
|
|
+ outputStream.write(buffer, 0, len);
|
|
|
|
+ }
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ log.info("读取文件失败:key:{},url:{}", one.getKey(), one.getUrl());
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
JSONObject params = new JSONObject();
|
|
JSONObject params = new JSONObject();
|
|
params.put("SYSCODE", "aaa");
|
|
params.put("SYSCODE", "aaa");
|