dengsixing 1 سال پیش
والد
کامیت
a078e43824

+ 19 - 5
pom.xml

@@ -85,22 +85,30 @@
         </dependency>
 
         <dependency>
-            <groupId>com.oracle</groupId>
-            <artifactId>ojdbc6</artifactId>
-            <version>11.2.0.3</version>
+            <groupId>com.oracle.ojdbc</groupId>
+            <artifactId>ojdbc8</artifactId>
+            <version>19.3.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>cn.easyproject</groupId>
+            <artifactId>orai18n</artifactId>
+            <version>12.1.0.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+
         <!--mybatis-plus整合依赖-->
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-boot-starter</artifactId>
-            <version>3.0.5</version>
+            <version>3.4.3.4</version>
         </dependency>
 
         <!-- mybatis-plus逆向工程依赖 -->
         <dependency>
             <groupId>com.baomidou</groupId>
             <artifactId>mybatis-plus-generator</artifactId>
-            <version>3.2.0</version>
+            <version>3.5.1</version>
         </dependency>
 
         <!-- freemarker 说明:mybatis-plus逆向工程需要freemarker模板引擎 -->
@@ -127,6 +135,12 @@
 <!--            <version>1.6</version>-->
 <!--        </dependency>-->
 
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.17</version>
+        </dependency>
+
     </dependencies>
 
 

+ 21 - 1
src/main/java/com/fdkankan/scene/controller/SceneController.java

@@ -1,16 +1,26 @@
 package com.fdkankan.scene.controller;
 
 
+import cn.hutool.http.HttpResponse;
+import cn.hutool.http.HttpUtil;
 import com.fdkankan.common.constant.SceneInfoReqType;
 import com.fdkankan.scene.bean.ResultData;
+import com.fdkankan.scene.httpclient.CustomHttpClient;
+import com.fdkankan.scene.service.SceneFileMappingService;
 import com.fdkankan.scene.service.SceneService;
 import com.fdkankan.scene.vo.SceneInfoParamVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.Resource;
+import org.springframework.http.ResponseEntity;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletResponse;
+import javax.websocket.server.PathParam;
+import java.io.IOException;
+
 /**
  * <p>
  * 场景表 前端控制器
@@ -25,7 +35,6 @@ public class SceneController {
 
     @Autowired
     private SceneService sceneService;
-
     /**
      * <p>
      获取场景详情
@@ -41,6 +50,17 @@ public class SceneController {
         return sceneService.getSceneInfo(param);
     }
 
+//    @GetMapping("/file")
+//    public ResponseEntity<Resource> outFileByKey(String key, HttpServletResponse response) throws IOException {
+//        return sceneService.outFileByKey(key, response);
+//    }
+
+    @GetMapping("/file")
+    public void outFileByKey2(String key, HttpServletResponse response) throws IOException {
+        sceneService.outFileByKey2(key, response);
+    }
+
+
     @GetMapping(value = "/ping")
     public ResultData ping(){
         return ResultData.ok();

+ 100 - 0
src/main/java/com/fdkankan/scene/generator/AutoGenerate.java

@@ -0,0 +1,100 @@
+package com.fdkankan.scene.generator;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.generator.FastAutoGenerator;
+import com.baomidou.mybatisplus.generator.config.OutputFile;
+import com.baomidou.mybatisplus.generator.config.rules.DateType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class AutoGenerate {
+
+
+    public static void main(String[] args) {
+
+        String path =System.getProperty("user.dir");
+
+        generate(path,"project.tieta.generator", getTables(new String[]{
+                "T_FULLPHOTO_UPRECORD"
+        }));
+
+//        generate(path,"goods", getTables(new String[]{
+//                        "t_camera","t_camera_detail","t_camera_out","t_camera_space","t_camera_version",
+//                        "t_company","t_goods","t_goods_sku","t_cart","t_goods_spec",
+//                        "t_goods_spec_value","t_goods_spu_spec","t_sn_code"
+//        }));
+//
+//        generate(path,"order", getTables(new String[]{
+//                        "t_increment_order","t_invoice","t_order","t_order_item",
+//                        "t_pre_sale","t_space_sdk","t_trade_log","t_commerce_order","t_download_order","t_expansion_order"
+//        }));
+//        generate(path,"order", getTables(new String[]{
+//                        "t_virtual_order"
+//        }));
+//
+//        generate(path,"user", getTables(new String[]{
+//                        "t_user","t_user_increment","t_manager","t_province","t_increment_type","t_intercom_message","t_receiver_info"
+//        }));
+    }
+
+    public static List<String> getTables(String [] tableNames){
+        return new ArrayList<>(Arrays.asList(tableNames));
+    }
+
+
+    public static void  generate(String path,String moduleName,  List<String> tables){
+        FastAutoGenerator.create("jdbc:oracle:thin:@//10.180.41.37:1521/resdb",
+            "RES_FILE","qNQVkH3YbA")
+                .globalConfig(builder -> {
+                    builder.author("")               //作者
+                            .outputDir(path+"\\src\\main\\java")    //输出路径(写到java目录)
+                            //.enableSwagger()           //开启swagger
+                            .commentDate("yyyy-MM-dd")
+                            .dateType(DateType.ONLY_DATE)
+                            .fileOverride();            //开启覆盖之前生成的文件
+
+                })
+                .packageConfig(builder -> {
+                    builder.parent("com.fdkankan")
+                            .moduleName(moduleName)
+                            .entity("entity")
+                            .service("service")
+                            .serviceImpl("service.impl")
+                            .controller("controller")
+                            .mapper("mapper")
+                            .xml("test.mapper")
+                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml,path+"\\src\\main\\resources\\mapper\\"+moduleName));
+                })
+                .strategyConfig(builder -> {
+                    builder.addInclude(tables)
+                            .addTablePrefix("t_")
+
+                            .serviceBuilder()
+                            .formatServiceFileName("%sService")
+                            .formatServiceImplFileName("%sServiceImpl")
+
+                            .entityBuilder()
+                            .enableLombok()
+                            .logicDeleteColumnName("rec_status")
+                            .enableTableFieldAnnotation()
+                            .idType(IdType.AUTO)
+//                            .superClass(BaseEntity.class)
+
+                            .controllerBuilder()
+                            .formatFileName("%sController")
+                            .enableRestStyle()
+
+                            .mapperBuilder()
+                            .superClass(BaseMapper.class)
+                            .formatMapperFileName("%sMapper")
+                            .enableMapperAnnotation()
+                            .formatXmlFileName("%sMapper");
+                })
+//                 .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板,默认的是Velocity引擎模板
+                .execute();
+    }
+}

+ 0 - 186
src/main/java/com/fdkankan/scene/generator/MappingGeneratorOracle.java

@@ -1,186 +0,0 @@
-package com.fdkankan.scene.generator;
-
-import com.baomidou.mybatisplus.annotation.DbType;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.generator.AutoGenerator;
-import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
-import com.baomidou.mybatisplus.generator.config.GlobalConfig;
-import com.baomidou.mybatisplus.generator.config.PackageConfig;
-import com.baomidou.mybatisplus.generator.config.StrategyConfig;
-import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
-import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
-import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
-
-/**
- * 代码生成器
- *
- * <p>
- * 根据数据库中的表生成:数据库表映射对象、Mapper 接口、Mapper XML 文件(含基础的 ResultMap 和字段代码片段)、 Service
- * 接口、Service 接口实现累、基础的 Controller 类。
- * </p>
- * <p>
- * 如果数据库设计符合规范,并且代码没有特殊要求。设置好表名前缀(无则忽略)、表字段前缀(无则忽略)后, 直接修改输出的路径、JDBC
- * Url、数据库的账户和密码即可直接生成代码。
- * </p>
- * <p>
- * 生成后将 Mapper 中的 xml 包中的 XML 文件移动到 resource 下即可,XML 存放文件夹名为 Mapper
- * 接口包名(全包名)的同名文件夹<br/>
- * 如 Mapper 接口包名为:com.example.mapper,那么在 resource 下新建同名文件夹:com.example.mapper,将
- * xml 文件移动到该文件夹下即可。
- * </p>
- *
- * @author wayne
- * @since 2020-01-08 23:00
- */
-public class MappingGeneratorOracle {
-
-	/**
-	 * 生成代码输出路径,<strong>路径必须是绝对路径,不需要包含包名</strong>
-	 */
-	private static final String OUTPUT_DIR = ".\\src\\main\\java\\com\\fdkankan\\scene\\generator";
-	/**
-	 * 生成代码输出的包名
-	 * <p>
-	 * 总包名,后续生成的 Mapper,Service 等将在该包下生成子包
-	 * </p>
-	 */
-	private static final String PACKAGE = "com.fdkankan.scene";
-	/**
-	 * JDBC URL 说明: url地址前需要加上@,否则会报错
-	 */
-
-	private static final String JDBC_URL = "jdbc:oracle:thin:@//10.180.41.39:1521/resdb";
-	/**
-	 * 数据库账户
-	 */
-	private static final String DB_USERNAME = "RES_VR";
-	/**
-	 * 数据库账户密码
-	 */
-	private static final String DB_PASSWORD = "IDCqawsed@123.";
-
-	/**
-	 * 执行即可生成代码 需要添加 freemarker 依赖 <dependency> <groupId>org.freemarker</groupId>
-	 * <artifactId>freemarker</artifactId> <version>2.3.29</version> </dependency>
-	 */
-	// 不要在src/main/java里面使用main方法,否则springboot项目某人为main方法的类就是启动类
-//	public static void main(String[] args) {
-//		autoGenerator().execute();
-//	}
-
-	public static AutoGenerator autoGenerator() {
-		AutoGenerator autoGenerator = new AutoGenerator();
-		autoGenerator.setGlobalConfig(globalConfig());
-		autoGenerator.setDataSource(oracleDataSourceConfig());
-		autoGenerator.setStrategy(strategyConfig());
-		autoGenerator.setPackageInfo(packageConfig());
-		autoGenerator.setTemplateEngine(new FreemarkerTemplateEngine());
-		return autoGenerator;
-	}
-
-	public static void main(String[] args) {
-		autoGenerator().execute();
-	}
-
-	/**
-	 * 全局配置
-	 *
-	 * @return {@link GlobalConfig}
-	 */
-	private static GlobalConfig globalConfig() {
-		GlobalConfig globalConfig = new GlobalConfig();
-		globalConfig.setAuthor("dsx");
-		// 设置代码输出位置,需要绝对路径
-		globalConfig.setOutputDir(OUTPUT_DIR);
-		// 覆盖已有的代码
-		globalConfig.setFileOverride(false);
-		// 基本表的 ResultMap
-		globalConfig.setBaseResultMap(true);
-		// 基本表字段片段
-		globalConfig.setBaseColumnList(true);
-		// 开启基于 Model 操作数据库
-		globalConfig.setActiveRecord(true);
-		// 设置 ID 类型
-		globalConfig.setIdType(IdType.AUTO);
-//		// 生成基本 Swagger2 文档
-//		globalConfig.setSwagger2(true);
-		// 开启二级缓存
-//		globalConfig.setEnableCache(true);
-		// 设置生成的对象名称规则,%s 表示当前的 Entity
-		// 数据库表映射对象名称规则
-		globalConfig.setEntityName("%s");
-		// 也可以使用下面这种就是末尾会以DO结尾
-//		globalConfig.setEntityName("%sDO");
-		// Mapper 接口名称规则
-		globalConfig.setMapperName("%sMapper");
-		// Mapper XML 文件名称规则
-		globalConfig.setXmlName("%sMapper");
-		// Controller 生成规则
-		globalConfig.setControllerName("%sController");
-		// Service 接口生成名称规则
-		globalConfig.setServiceName("%sService");
-		// Service 实现类生成名称规则
-		globalConfig.setServiceImplName("%sServiceImpl");
-		return globalConfig;
-	}
-
-	/**
-	 * 生成策略配置
-	 *
-	 * @return StrategyConfig
-	 */
-	private static StrategyConfig strategyConfig() {
-		StrategyConfig strategyConfig = new StrategyConfig();
-		strategyConfig.setCapitalMode(false);
-		strategyConfig.setEntityLombokModel(true);
-		strategyConfig.setRestControllerStyle(true);
-		strategyConfig.setNaming(NamingStrategy.underline_to_camel);
-		strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
-		// TODO 填写表前缀、表字段前缀,生成代码时去除字段前缀
-		strategyConfig.setTablePrefix("t_");
-		strategyConfig.setFieldPrefix("a_", "c_", "e_", "f_", "p_", "r_", "t_", "tf_");
-		strategyConfig.setInclude("T_FULLPHOTO_FILEINDEX");
-		return strategyConfig;
-	}
-
-	/**
-	 * MySQL 数据源配置
-	 *
-	 * @return DataSourceConfig
-	 */
-	private static DataSourceConfig oracleDataSourceConfig() {
-		DataSourceConfig dataSourceConfig = new DataSourceConfig();
-		dataSourceConfig.setDbType(DbType.ORACLE);
-		dataSourceConfig.setTypeConvert(new MySqlTypeConvert());
-		dataSourceConfig.setDriverName("oracle.jdbc.driver.OracleDriver");
-		dataSourceConfig.setUrl(JDBC_URL);
-		dataSourceConfig.setUsername(DB_USERNAME);
-		dataSourceConfig.setPassword(DB_PASSWORD);
-		return dataSourceConfig;
-	}
-
-	/**
-	 * 包相关配置信息
-	 * <p>
-	 * 配置生成代码的包信息,如生成的 Mapper 包,Service 包等
-	 * </p>
-	 */
-	private static PackageConfig packageConfig() {
-		PackageConfig packageConfig = new PackageConfig();
-		// 设置父包
-		packageConfig.setParent(PACKAGE);
-		// TODO 设置生成代码的包
-		// Controller 包
-		packageConfig.setController("controller");
-		// 数据库表映射对象包
-		packageConfig.setEntity("entity");
-		// Mapper 接口包,含 XML 文件
-		packageConfig.setMapper("mapper");
-		// Service 接口包
-		packageConfig.setService("service");
-		// Service 接口实现类包
-		packageConfig.setServiceImpl("service.impl");
-		return packageConfig;
-	}
-}
-

+ 0 - 20
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/controller/FullphotoFileindexController.java

@@ -1,20 +0,0 @@
-package com.fdkankan.scene.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- *  前端控制器
- * </p>
- *
- * @author dsx
- * @since 2024-07-08
- */
-@RestController
-@RequestMapping("/fullphotoFileindex")
-public class FullphotoFileindexController {
-
-}

+ 0 - 132
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/entity/FullphotoFileindex.java

@@ -1,132 +0,0 @@
-package com.fdkankan.scene.entity;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.extension.activerecord.Model;
-import java.time.LocalDate;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableField;
-import java.io.Serializable;
-import lombok.Data;
-import lombok.EqualsAndHashCode;
-import lombok.experimental.Accessors;
-
-/**
- * <p>
- * 
- * </p>
- *
- * @author dsx
- * @since 2024-07-08
- */
-@Data
-@EqualsAndHashCode(callSuper = false)
-@Accessors(chain = true)
-@TableName("T_FULLPHOTO_FILEINDEX")
-public class FullphotoFileindex extends Model<FullphotoFileindex> {
-
-    private static final long serialVersionUID = 1L;
-
-    /**
-     * 省分
-     */
-    @TableField("PROVINCE_ID")
-    private String provinceId;
-
-    /**
-     * 地市
-     */
-    @TableField("REGION_ID")
-    private String regionId;
-
-    /**
-     * 站址编码
-     */
-    @TableField("STATION_CODE")
-    private String stationCode;
-
-    /**
-     * 机房ID
-     */
-    @TableField("ENTITY_ID")
-    private String entityId;
-
-    /**
-     * 文件名称
-     */
-    @TableField("FILE_NAME")
-    private String fileName;
-
-    /**
-     * 文件md5码
-     */
-    @TableField("FILE_MD5")
-    private String fileMd5;
-
-    /**
-     * 文件类型(1-512图片,2-4K图片,3-8K图片,5-小地图文件,7-点位文件,11-模型文件,12-场景信息文件(可根据实际增加枚举值))
-     */
-    @TableField("FILE_TYPE")
-    private String fileType;
-
-    /**
-     * 点位Uuid
-     */
-    @TableField("PIC_UUID")
-    private String picUuid;
-
-    /**
-     * 上传时间
-     */
-    @TableField("UP_TIME")
-    private LocalDate upTime;
-
-    /**
-     * 上传用户
-     */
-    @TableField("UP_USER")
-    private String upUser;
-
-    /**
-     * 文件大小
-     */
-    @TableField("FILE_SIZE")
-    private String fileSize;
-
-    /**
-     * 文件标识fileID
-     */
-    @TableField("FILEID")
-    private String fileid;
-
-    /**
-     * 记录唯一ID
-     */
-    @TableField("RECORD_ID")
-    private String recordId;
-
-    /**
-     * 上传记录id
-     */
-    @TableField("UPLOAD_ID")
-    private String uploadId;
-
-    /**
-     * 状态: 1-正常 2-已删除 3-删除失败
-     */
-    @TableField("STATUS")
-    private String status;
-
-    /**
-     * 分布式存储文件下载URL
-     */
-    @TableField("FILE_URL")
-    private String fileUrl;
-
-
-    @Override
-    protected Serializable pkVal() {
-        return null;
-    }
-
-}

+ 0 - 16
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/mapper/FullphotoFileindexMapper.java

@@ -1,16 +0,0 @@
-package com.fdkankan.scene.mapper;
-
-import com.fdkankan.scene.entity.FullphotoFileindex;
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-
-/**
- * <p>
- *  Mapper 接口
- * </p>
- *
- * @author dsx
- * @since 2024-07-08
- */
-public interface FullphotoFileindexMapper extends BaseMapper<FullphotoFileindex> {
-
-}

+ 0 - 30
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/mapper/xml/FullphotoFileindexMapper.xml

@@ -1,30 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
-<mapper namespace="com.fdkankan.scene.mapper.FullphotoFileindexMapper">
-
-    <!-- 通用查询映射结果 -->
-    <resultMap id="BaseResultMap" type="com.fdkankan.scene.entity.FullphotoFileindex">
-        <result column="PROVINCE_ID" property="provinceId" />
-        <result column="REGION_ID" property="regionId" />
-        <result column="STATION_CODE" property="stationCode" />
-        <result column="ENTITY_ID" property="entityId" />
-        <result column="FILE_NAME" property="fileName" />
-        <result column="FILE_MD5" property="fileMd5" />
-        <result column="FILE_TYPE" property="fileType" />
-        <result column="PIC_UUID" property="picUuid" />
-        <result column="UP_TIME" property="upTime" />
-        <result column="UP_USER" property="upUser" />
-        <result column="FILE_SIZE" property="fileSize" />
-        <result column="FILEID" property="fileid" />
-        <result column="RECORD_ID" property="recordId" />
-        <result column="UPLOAD_ID" property="uploadId" />
-        <result column="STATUS" property="status" />
-        <result column="FILE_URL" property="fileUrl" />
-    </resultMap>
-
-    <!-- 通用查询结果列 -->
-    <sql id="Base_Column_List">
-        PROVINCE_ID, REGION_ID, STATION_CODE, ENTITY_ID, FILE_NAME, FILE_MD5, FILE_TYPE, PIC_UUID, UP_TIME, UP_USER, FILE_SIZE, FILEID, RECORD_ID, UPLOAD_ID, STATUS, FILE_URL
-    </sql>
-
-</mapper>

+ 0 - 16
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/service/FullphotoFileindexService.java

@@ -1,16 +0,0 @@
-package com.fdkankan.scene.service;
-
-import com.fdkankan.scene.entity.FullphotoFileindex;
-import com.baomidou.mybatisplus.extension.service.IService;
-
-/**
- * <p>
- *  服务类
- * </p>
- *
- * @author dsx
- * @since 2024-07-08
- */
-public interface FullphotoFileindexService extends IService<FullphotoFileindex> {
-
-}

+ 0 - 20
src/main/java/com/fdkankan/scene/generator/com/fdkankan/scene/service/impl/FullphotoFileindexServiceImpl.java

@@ -1,20 +0,0 @@
-package com.fdkankan.scene.service.impl;
-
-import com.fdkankan.scene.entity.FullphotoFileindex;
-import com.fdkankan.scene.mapper.FullphotoFileindexMapper;
-import com.fdkankan.scene.service.FullphotoFileindexService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- *  服务实现类
- * </p>
- *
- * @author dsx
- * @since 2024-07-08
- */
-@Service
-public class FullphotoFileindexServiceImpl extends ServiceImpl<FullphotoFileindexMapper, FullphotoFileindex> implements FullphotoFileindexService {
-
-}

+ 8 - 0
src/main/java/com/fdkankan/scene/httpclient/CustomHttpClient.java

@@ -2,14 +2,22 @@ package com.fdkankan.scene.httpclient;
 
 
 import com.alibaba.fastjson.JSONObject;
+import com.dtflys.forest.annotation.GetRequest;
 import com.dtflys.forest.annotation.JSONBody;
 import com.dtflys.forest.annotation.Post;
 import com.dtflys.forest.annotation.Var;
 
+import java.io.InputStream;
+
 public interface CustomHttpClient {
 
     @Post(url = "{url}", connectTimeout = 30000,  readTimeout = 30000, maxRetryInterval = 3)
     JSONObject postJson(@Var("url") String url, @JSONBody Object object);
 
+    /**
+     * 返回类型用InputStream,用流的方式读取文件内容
+     */
+    @GetRequest(url = "{url}", connectTimeout = 6000, readTimeout = 60000, maxRetryInterval = 5)
+    InputStream downloadFileToInputStream(@Var("url") String url);
 
 }

+ 11 - 0
src/main/java/com/fdkankan/scene/service/SceneService.java

@@ -5,6 +5,13 @@ import com.fdkankan.scene.entity.Scene;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.scene.vo.SceneInfoParamVO;
 import com.fdkankan.scene.vo.SceneInfoVO;
+import org.springframework.core.io.Resource;
+import org.springframework.http.ResponseEntity;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.websocket.server.PathParam;
+import java.io.IOException;
+import java.net.MalformedURLException;
 
 /**
  * <p>
@@ -18,4 +25,8 @@ public interface SceneService extends IService<Scene> {
 
     ResultData getSceneInfo(SceneInfoParamVO param) throws Exception;
 
+    ResponseEntity<Resource> outFileByKey(String key, HttpServletResponse response) throws IOException;
+
+    void outFileByKey2(String key, HttpServletResponse response) throws IOException;
+
 }

+ 54 - 1
src/main/java/com/fdkankan/scene/service/impl/SceneServiceImpl.java

@@ -1,5 +1,7 @@
 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 com.alibaba.fastjson.JSON;
 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.entity.Scene;
 import com.fdkankan.scene.entity.SceneFileMapping;
+import com.fdkankan.scene.httpclient.CustomHttpClient;
 import com.fdkankan.scene.mapper.SceneMapper;
 import com.fdkankan.scene.service.SceneFileMappingService;
 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 org.springframework.beans.factory.annotation.Autowired;
 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 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.Map;
 import java.util.Objects;
@@ -61,6 +75,8 @@ public class SceneServiceImpl extends ServiceImpl<SceneMapper, Scene> implements
     private TietaFeignClient tietaFeignClient;
     @Autowired
     private WS4AServiceClient ws4AServiceClient;
+    @Resource
+    private CustomHttpClient customHttpClient;
 
     @Override
     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));
-        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);
 
         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) {
         JSONObject params = new JSONObject();
         params.put("SYSCODE", "aaa");

+ 2 - 1
src/main/resources/application-dev.yml

@@ -20,6 +20,7 @@ spring:
       max-lifetime: 1800000
       login-timeout: 60000
       pool-name: MyHikariCP
+      connection-test-query: SELECT 1 FROM DUAL
 
 mybatis-plus:
   mapper-locations: classpath:mapper/*Mapper.xml
@@ -30,7 +31,7 @@ tieta:
   sysCode: CT00017
   serverName: scene
   checkToken:
-    syscode: CHNTRMS2
+    syscode: CHNTZCGL_ZCSZHGL
 
 redis:
   host: http://10.180.22.54:8081

+ 2 - 1
src/main/resources/application-preprod.yml

@@ -20,6 +20,7 @@ spring:
       max-lifetime: 1800000
       login-timeout: 60000
       pool-name: MyHikariCP
+      connection-test-query: SELECT 1 FROM DUAL
 
 mybatis-plus:
   mapper-locations: classpath:mapper/*Mapper.xml
@@ -30,7 +31,7 @@ tieta:
   sysCode: CT00017
   serverName: scene
   checkToken:
-    syscode: CHNTRMS2
+    syscode: CHNTZCGL_ZCSZHGL
 
 redis:
   host: http://10.34.53.34:8081

+ 2 - 1
src/main/resources/application-prod.yml

@@ -20,6 +20,7 @@ spring:
       max-lifetime: 1800000
       login-timeout: 60000
       pool-name: MyHikariCP
+      connection-test-query: SELECT 1 FROM DUAL
 
 mybatis-plus:
   mapper-locations: classpath:mapper/*Mapper.xml
@@ -30,7 +31,7 @@ tieta:
   sysCode: CT00017
   serverName: scene
   checkToken:
-    syscode: CHNTRMS2
+    syscode: CHNTZCGL_ZCSZHGL
 
 redis:
   host: http://192.168.53.243:8081

+ 2 - 1
src/main/resources/application-test.yml

@@ -20,6 +20,7 @@ spring:
       max-lifetime: 1800000
       login-timeout: 60000
       pool-name: MyHikariCP
+      connection-test-query: SELECT 1 FROM DUAL
 
 mybatis-plus:
   mapper-locations: classpath:mapper/*Mapper.xml
@@ -30,7 +31,7 @@ tieta:
   sysCode: CT00017
   serverName: scene
   checkToken:
-    syscode: CHNTRMS2
+    syscode: CHNTZCGL_ZCSZHGL
 
 redis:
   host: http://10.190.22.99:8081