浏览代码

更新文件发送功能

wuweihao 4 年之前
父节点
当前提交
1c932417b3

+ 15 - 2
README.md

@@ -73,6 +73,19 @@ server
     
     /root/user/java/apache-tomcat-8.0.52-4dkankan-xiaoan/webapps
     
+server: 
+tomcat: /本地消安/root/user/java/apache-tomcat-8.0.52-4dkankan-xiaoan/webapps/xiaoan
+doc: http://192.168.0.163:8088/xiaoan/doc.html
+web: http://192.168.0.163:8088/dist/#/login    
+    
 ## 需求修改日志
-    20200519
-        添加高级管理员(high),可以看到所有场景;需要手动在tb_role添加high角色    
+   20200519
+        添加高级管理员(high),可以看到所有场景;需要手动在tb_role添加high角色   
+     
+   20200615
+        更新t_scene_pro, 新增字段download_status
+        
+   20201231
+        新增文件发送功能
+                  
+         

+ 14 - 12
pom.xml

@@ -43,6 +43,7 @@
         <shiro.version>1.4.0</shiro.version>
         <jwt.version>3.2.0</jwt.version>
         <jjwt.version>0.6.0</jjwt.version>
+        <junit.version>4.12</junit.version>
 
 
     </properties>
@@ -152,18 +153,6 @@
                 <version>${lang3.version}</version>
             </dependency>
 
-            <!--&lt;!&ndash;swagger2核心包和swagger-ui界面包&ndash;&gt;-->
-            <!--<dependency>-->
-                <!--<groupId>io.springfox</groupId>-->
-                <!--<artifactId>springfox-swagger2</artifactId>-->
-                <!--<version>${swagger2.version}</version>-->
-            <!--</dependency>-->
-            <!--<dependency>-->
-                <!--<groupId>io.springfox</groupId>-->
-                <!--<artifactId>springfox-swagger-ui</artifactId>-->
-                <!--<version>${swagger2.version}</version>-->
-            <!--</dependency>-->
-
             <!-- knife4j aip 包-->
             <dependency>
                 <groupId>com.github.xiaoymin</groupId>
@@ -199,6 +188,19 @@
                 <version>${kaptcha.version}</version>
             </dependency>
 
+            <!---http 文件上传 ,好像直接用这个包就可以了-->
+            <dependency>
+                <groupId>org.apache.httpcomponents</groupId>
+                <artifactId>httpmime</artifactId>
+                <version>4.5.3</version>
+            </dependency>
+
+            <dependency>
+                <groupId>junit</groupId>
+                <artifactId>junit</artifactId>
+                <version>${junit.version}</version>
+            </dependency>
+
 
         </dependencies>
     </dependencyManagement>

+ 7 - 0
xiaoan-application/src/main/resources/application-dev.properties

@@ -56,3 +56,10 @@ logging.path=E:/javaProject/log/xiaoan
 camera.version.path=F:\\test\\xiaoan\\camera_version\\
 
 server.domian=http://localhost:8011
+
+# 打包文件文件存放地址
+server.package.result=${server.domian}/scene/result/
+
+# 远程服务器地址(用来接收文件)
+remote.domian=http://127.0.0.1:8088
+remote.api=${remote.domian}/api/scene/uploadSceneHtmlData

+ 8 - 1
xiaoan-application/src/main/resources/application-sit.properties

@@ -52,4 +52,11 @@ logging.path=/root/user/java/log/xiaoan
 # file path
 camera.version.path=/oss/4Dkankan/camera_version/
 
-server.domian=http://192.168.0.163:8088
+server.domian=http://192.168.0.163:8088
+
+# 打包文件文件存放地址
+server.package.result=/mnt/4Dkankan/scene/result/
+
+# 远程服务器地址(用来接收文件)
+remote.domian=http://127.0.0.1:8088
+remote.api=${remote.domian}/api/scene/uploadSceneHtmlData

+ 8 - 1
xiaoan-application/src/main/resources/application-uat.properties

@@ -52,4 +52,11 @@ logging.path=/root/user/java/log/xiaoan
 # file path
 camera.version.path=/oss/4Dkankan/camera_version/
 
-server.domian=http://218.17.126.170:9997
+server.domian=http://218.17.126.170:9997
+
+# 打包文件文件存放地址
+server.package.result=${server.domian}/scene/result/
+
+# 远程服务器地址(用来接收文件)
+remote.domian=http://127.0.0.1:8088
+remote.api=${remote.domian}/api/scene/uploadSceneHtmlData

+ 11 - 10
xiaoan-common/pom.xml

@@ -87,16 +87,6 @@
             <!--<artifactId>druid</artifactId>-->
         </dependency>
 
-        <!--&lt;!&ndash;swagger2核心包和swagger-ui界面包&ndash;&gt;-->
-        <!--<dependency>-->
-            <!--<groupId>io.springfox</groupId>-->
-            <!--<artifactId>springfox-swagger2</artifactId>-->
-        <!--</dependency>-->
-        <!--<dependency>-->
-            <!--<groupId>io.springfox</groupId>-->
-            <!--<artifactId>springfox-swagger-ui</artifactId>-->
-        <!--</dependency>-->
-
         <!-- knife4j aip 包-->
         <dependency>
             <groupId>com.github.xiaoymin</groupId>
@@ -160,6 +150,17 @@
             <version>1.9.3</version>
         </dependency>
 
+        <!---http 文件上传-->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+
     </dependencies>
 
 

+ 491 - 0
xiaoan-common/src/main/java/com/xiaoan/common/util/HttpRequestorUtil.java

@@ -0,0 +1,491 @@
+package com.xiaoan.common.util;
+
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.mime.HttpMultipartMode;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.junit.Test;
+
+import java.io.*;
+import java.net.*;
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+@Slf4j
+public class HttpRequestorUtil {
+
+	private String charset = "utf-8";
+    private Integer connectTimeout = null;
+    private Integer socketTimeout = null;
+    private String proxyHost = null;
+    private Integer proxyPort = null;
+    
+    /**
+     * Do GET request
+     * @param url
+     * @return
+     * @throws Exception
+     * @throws IOException
+     */
+    public String doGet(String url) throws Exception {
+        
+        URL localURL = new URL(url);
+        
+        URLConnection connection = openConnection(localURL);
+        HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
+        
+        httpURLConnection.setRequestProperty("Accept-Charset", charset);
+        httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+        
+        InputStream inputStream = null;
+        InputStreamReader inputStreamReader = null;
+        BufferedReader reader = null;
+        StringBuffer resultBuffer = new StringBuffer();
+        String tempLine = null;
+        
+        if (httpURLConnection.getResponseCode() >= 300) {
+            throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
+        }
+        
+        try {
+            inputStream = httpURLConnection.getInputStream();
+            inputStreamReader = new InputStreamReader(inputStream,"UTF-8");
+            reader = new BufferedReader(inputStreamReader);
+            
+            while ((tempLine = reader.readLine()) != null) {
+                resultBuffer.append(tempLine);
+            }
+            
+        } finally {
+            
+            if (reader != null) {
+                reader.close();
+            }
+            
+            if (inputStreamReader != null) {
+                inputStreamReader.close();
+            }
+            
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            
+        }
+
+        return resultBuffer.toString();
+    }
+    
+    /**
+     * Do POST request
+     * @param url
+     * @param parameterMap
+     * @return
+     * @throws Exception 
+     */
+    public static String doPost(String url, Map parameterMap) throws Exception {
+        
+        /* Translate parameter map to parameter date string */
+        StringBuffer parameterBuffer = new StringBuffer();
+        if (parameterMap != null) {
+            Iterator iterator = parameterMap.keySet().iterator();
+            String key = null;
+            String value = null;
+            while (iterator.hasNext()) {
+                key = (String)iterator.next();
+                if (parameterMap.get(key) != null) {
+                    value = (String)parameterMap.get(key);
+                } else {
+                    value = "";
+                }
+                
+                parameterBuffer.append(key).append("=").append(value);
+                if (iterator.hasNext()) {
+                    parameterBuffer.append("&");
+                }
+            }
+        }
+        
+        log.info("POST parameter : " + parameterBuffer.toString());
+        
+        URL localURL = new URL(url);
+        log.info("POST URL : " + url);
+        HttpURLConnection connection = (HttpURLConnection) localURL.openConnection();
+        HttpURLConnection httpURLConnection = (HttpURLConnection)connection;
+        
+        httpURLConnection.setDoOutput(true);
+        httpURLConnection.setRequestMethod("POST");
+        httpURLConnection.setRequestProperty("Accept-Charset", "UTF-8");
+        httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+        httpURLConnection.setRequestProperty("Content-Length", String.valueOf(parameterBuffer.length()));
+        
+        OutputStream outputStream = null;
+        OutputStreamWriter outputStreamWriter = null;
+        InputStream inputStream = null;
+        InputStreamReader inputStreamReader = null;
+        BufferedReader reader = null;
+        StringBuffer resultBuffer = new StringBuffer();
+        String tempLine = null;
+        
+        try {
+            outputStream = httpURLConnection.getOutputStream();
+            outputStreamWriter = new OutputStreamWriter(outputStream);
+            
+            outputStreamWriter.write(parameterBuffer.toString());
+            outputStreamWriter.flush();
+            
+            if (httpURLConnection.getResponseCode() >= 300) {
+                throw new Exception("HTTP Request is not success, Response code is " + httpURLConnection.getResponseCode());
+            }
+            log.info("POST finish.");
+            
+            inputStream = httpURLConnection.getInputStream();
+            inputStreamReader = new InputStreamReader(inputStream);
+            reader = new BufferedReader(inputStreamReader);
+            
+            while ((tempLine = reader.readLine()) != null) {
+                resultBuffer.append(tempLine);
+            }
+            
+        } finally {
+            
+            if (outputStreamWriter != null) {
+                outputStreamWriter.close();
+            }
+            
+            if (outputStream != null) {
+                outputStream.close();
+            }
+            
+            if (reader != null) {
+                reader.close();
+            }
+            
+            if (inputStreamReader != null) {
+                inputStreamReader.close();
+            }
+            
+            if (inputStream != null) {
+                inputStream.close();
+            }
+            
+        }
+
+        return resultBuffer.toString();
+    }
+
+    /**
+     * 文件上传支持中文
+     *
+     * @param reportUrl
+     * @param filepath
+     * @param savepath
+     * @throws IOException
+     */
+//    public static void uploadReport(String reportUrl, String filepath,
+//                                    String savepath) {
+//        CloseableHttpClient closeableHttpClient = null;
+//        CloseableHttpResponse response = null;
+//        try {
+//            closeableHttpClient = HttpClients.createDefault();
+//            HttpPost httpPost = new HttpPost(reportUrl);
+//            String filename = filepath.split("/")[filepath.split("/").length - 1];
+//            File file = new File(filepath);
+//
+//            FileBody fileBody = new FileBody(file, ContentType.create("multipart/form-data", "UTF-8"), filename);
+//            StringBody userIdStringBody = new StringBody(savepath, ContentType.create("multipart/form-data", "UTF-8"));
+//            StringBody reportNameStringBody = new StringBody(filename, ContentType.create("multipart/form-data", "UTF-8"));
+//
+//            HttpEntity httpEntity = MultipartEntityBuilder
+//                    .create()
+//                    .setCharset(Charset.forName("UTF-8"))
+//                    .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
+//                    .addPart("file", fileBody)
+//                    .addPart("savepath", userIdStringBody)
+//                    .addPart("reportName", reportNameStringBody)
+//                    .build();
+//
+//            httpPost.setEntity(httpEntity);
+//            response = closeableHttpClient.execute(httpPost);
+//            HttpEntity responseEntity = response.getEntity();
+//            int statusCode = response.getStatusLine().getStatusCode();
+//            if (statusCode == 200) {
+//                log.info("上传成功:" + savepath);
+//            } else {
+//                BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
+//                StringBuffer buffer = new StringBuffer();
+//                String str = "";
+//                while ((str = reader.readLine()) != null && (str = reader.readLine()).trim().length() > 0) {
+//                    buffer.append(str);
+//                }
+//                log.info(buffer.toString());
+//                log.info("上传失败:" + statusCode);
+//            }
+//            closeableHttpClient.close();
+//            if (response != null) {
+//                response.close();
+//            }
+//
+//        } catch (Exception ex) {
+//            log.info("uploadReport发生异常:" + ex);
+//        } finally {
+//            try {
+//                if (closeableHttpClient != null) {
+//                    closeableHttpClient.close();
+//                }
+//                if (response != null) {
+//                    response.close();
+//                }
+//            } catch (Exception ex) {
+//                ex.printStackTrace();
+//            }
+//        }
+//    }
+
+    /**
+     *
+     * 远程传输文件
+     * @param api 服务器接口地址(需要http)
+     * @param filePath 本地文件地址
+     *
+     *  20201217
+     *  测试成功
+     */
+    public static int fileRemote(String api, String filePath){
+        long start = System.currentTimeMillis();
+        log.info("filePath: {}", filePath);
+
+        int status = 200;
+        CloseableHttpClient closeableHttpClient = null;
+        CloseableHttpResponse response = null;
+        try {
+            closeableHttpClient = HttpClients.createDefault();
+            HttpPost httpPost = new HttpPost(api);
+            File file = new File(filePath);
+            String fileName = file.getName();
+
+            FileBody fileBody = new FileBody(file, ContentType.create("multipart/form-data", "UTF-8"), fileName);
+            StringBody reportNameStringBody = new StringBody(fileName, ContentType.create("multipart/form-data", "UTF-8"));
+
+            HttpEntity httpEntity = MultipartEntityBuilder
+                    .create()
+                    .setCharset(Charset.forName("UTF-8"))
+                    .setMode(HttpMultipartMode.BROWSER_COMPATIBLE)
+                    .addPart("file", fileBody)
+                    .addPart("reportName", reportNameStringBody)
+                    .build();
+
+            httpPost.setEntity(httpEntity);
+            response = closeableHttpClient.execute(httpPost);
+            HttpEntity responseEntity = response.getEntity();
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode == 200) {
+                log.info("文件发送成功");
+                status = statusCode;
+            } else {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(responseEntity.getContent()));
+                StringBuffer buffer = new StringBuffer();
+                String str = "";
+                while ((str = reader.readLine()) != null && (str = reader.readLine()).trim().length() > 0) {
+                    buffer.append(str);
+                }
+                log.error("上传失败:" + buffer.toString());
+                status = 5001;
+            }
+            closeableHttpClient.close();
+            if (response != null) {
+                response.close();
+            }
+
+        } catch (Exception ex) {
+            log.error("uploadReport发生异常:" + ex);
+            status = 5001;
+        } finally {
+            try {
+                if (closeableHttpClient != null) {
+                    closeableHttpClient.close();
+                }
+                if (response != null) {
+                    response.close();
+                }
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                status = 5001;
+            }
+        }
+
+        long end = System.currentTimeMillis();
+        log.info("耗时:" + (end - start)/1000);
+        return status;
+    }
+
+    /**
+     * 测试成功,测试前确保对方服务器是启动的
+     */
+    @Test
+    public void uploadReport1() {
+        String api = "http://120.25.146.52:8109/manage/file/upload";
+        String filepath = "F:\\test\\upload\\1.zip";
+        fileRemote(api, filepath);
+    }
+
+    /**
+     * 发送HttpPost请求
+     *
+     * @param strURL
+     *            服务地址
+     * @param params
+     *            json字符串,例如: "{ \"id\":\"12345\" }" ;其中属性名必须带双引号<br/>
+     * @return 成功:返回json字符串<br/>
+     */
+    public static String postJson(String strURL, String params, String type) {
+        log.info(strURL);
+        log.info(params);
+        BufferedReader reader = null;
+        try {
+            URL url = new URL(strURL);// 创建连接
+            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setUseCaches(false);
+            connection.setInstanceFollowRedirects(true);
+            connection.setRequestMethod(type); // 设置请求方式
+            // connection.setRequestProperty("Accept", "application/json"); // 设置接收数据的格式
+            connection.setRequestProperty("Content-Type", "application/json"); // 设置发送数据的格式
+            connection.setRequestProperty("Authorizations", "Y9z$w*WA%z!uz0O$dcCQ@i1KHKs5rhQW");
+            connection.connect();
+            //一定要用BufferedReader 来接收响应, 使用字节来接收响应的方法是接收不到内容的
+            OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream(), "UTF-8"); // utf-8编码
+            out.append(params);
+            out.flush();
+            out.close();
+            // 读取响应
+            reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
+            String line;
+            String res = "";
+            while ((line = reader.readLine()) != null) {
+                res += line;
+            }
+            reader.close();
+
+            //如果一定要使用如下方式接收响应数据, 则响应必须为: response.getWriter().print(StringUtils.join("{\"errCode\":\"1\",\"errMsg\":\"", message, "\"}")); 来返回
+//            int length = (int) connection.getContentLength();// 获取长度
+//            if (length != -1) {
+//                byte[] data = new byte[length];
+//                byte[] temp = new byte[512];
+//                int readLen = 0;
+//                int destPos = 0;
+//                while ((readLen = is.read(temp)) > 0) {
+//                    System.arraycopy(temp, 0, data, destPos, readLen);
+//                    destPos += readLen;
+//                }
+//                String result = new String(data, "UTF-8"); // utf-8编码
+//                log.info(result);
+//                return result;
+//            }
+
+            return res;
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        return "error"; // 自定义错误信息
+    }
+
+    public static void main(String[] args) {
+        try{
+            Map postData = new HashMap();
+//            postData.put("vrBuilding", "http://192.168.0.47:8086/showProMobile.html?m=001-zFzxA5FkS");
+//            postData.put("editBuilding", "http://192.168.0.47:8086/editProMobile.html?m=001-zFzxA5FkS");
+//            postData.put("siweiId", "001-zFzxA5FkS");
+//            postData.put("name", "中国银行2");
+//            String result = doPost("http://49.4.86.68:8080/bankBack/back/vrhome/insertbuilding.htm", postData);
+            HttpRequestorUtil util = new HttpRequestorUtil();
+            String result = util.doGet("https://4dkk.4dage.com/data/datagu6HmTLKp/hot.json");
+            log.info(result);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+//        uploadReport("http://114.215.208.201:8080/filecommon/file/uploadsiweifile.htm", "F:\\桌面\\迁移场景\\bi8u5kUcn\\tex\\texture1.jpg",
+//                "scene/data/datat-KvqDwm3/");
+    }
+
+    private URLConnection openConnection(URL localURL) throws IOException {
+        URLConnection connection;
+        if (proxyHost != null && proxyPort != null) {
+            Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
+            connection = localURL.openConnection(proxy);
+        } else {
+            connection = localURL.openConnection();
+        }
+        return connection;
+    }
+    
+    /**
+     * Render request according setting
+     */
+    private void renderRequest(URLConnection connection) {
+        
+        if (connectTimeout != null) {
+            connection.setConnectTimeout(connectTimeout);
+        }
+        
+        if (socketTimeout != null) {
+            connection.setReadTimeout(socketTimeout);
+        }
+        
+    }
+
+    /*
+     * Getter & Setter
+     */
+    public Integer getConnectTimeout() {
+        return connectTimeout;
+    }
+
+    public void setConnectTimeout(Integer connectTimeout) {
+        this.connectTimeout = connectTimeout;
+    }
+
+    public Integer getSocketTimeout() {
+        return socketTimeout;
+    }
+
+    public void setSocketTimeout(Integer socketTimeout) {
+        this.socketTimeout = socketTimeout;
+    }
+
+    public String getProxyHost() {
+        return proxyHost;
+    }
+
+    public void setProxyHost(String proxyHost) {
+        this.proxyHost = proxyHost;
+    }
+
+    public Integer getProxyPort() {
+        return proxyPort;
+    }
+
+    public void setProxyPort(Integer proxyPort) {
+        this.proxyPort = proxyPort;
+    }
+
+    public String getCharset() {
+        return charset;
+    }
+
+    public void setCharset(String charset) {
+        this.charset = charset;
+    }
+}

+ 20 - 0
xiaoan-dao/src/main/java/com/xiaoan/dao/backend/SceneProEditMapper.java

@@ -0,0 +1,20 @@
+package com.xiaoan.dao.backend;
+
+import com.xiaoan.domain.backend.SceneProEditEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * Created by Hb_zzZ on 2020/3/2.
+ */
+@Component
+@Mapper
+public interface SceneProEditMapper extends IBaseMapper<SceneProEditEntity, Long> {
+
+    @Select(value = "select * from t_scene_pro_edit where rec_status = 'A' and pro_id = #{proId}")
+    SceneProEditEntity findByProId(Long proId);
+
+}

+ 1 - 1
xiaoan-domain/src/main/java/com/xiaoan/domain/backend/SceneProEntity.java

@@ -145,7 +145,7 @@ public class SceneProEntity extends BaseModel implements Serializable {
     @ApiModelProperty(value = "调用V2还是V3的算法")
     private String buildType;
 
-    @ApiModelProperty(value = "下载场景状态,-1未生成过zip,0生成中,1生成zip完成")
+    @ApiModelProperty(value = "下载场景状态,-1未生成过zip,0生成中,1生成zip完成, 2:文件发送成功, 3:文件发送失败")
     private Integer downloadStatus;
 
 

+ 19 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/SceneProEditService.java

@@ -0,0 +1,19 @@
+package com.xiaoan.service.backend;
+
+import com.xiaoan.domain.backend.SceneProEditEntity;
+import com.xiaoan.service.IBaseService;
+
+
+/**
+ * Created by Hb_zzZ on 2020/3/2.
+ */
+public interface SceneProEditService extends IBaseService<SceneProEditEntity, Long> {
+
+
+
+    SceneProEditEntity findByProId(Long proId);
+
+
+
+
+}

+ 3 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/SceneService.java

@@ -1,5 +1,6 @@
 package com.xiaoan.service.backend;
 
+import com.xiaoan.common.util.ResultJson;
 import com.xiaoan.domain.backend.SceneProEntity;
 import com.xiaoan.domain.dto.request.SceneProRequest;
 import com.xiaoan.domain.dto.response.SceneResponse;
@@ -22,5 +23,7 @@ public interface SceneService extends IBaseService<SceneProEntity, Long> {
 
     SceneProEntity findBySceneNum(String sceneNum);
 
+
+
 //    List<SceneResponse> findAllBySearchKey(SceneProRequest param, List<Long> ids, Long userId);
 }

+ 40 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/impl/SceneProEditServiceImpl.java

@@ -0,0 +1,40 @@
+package com.xiaoan.service.backend.impl;
+
+import com.github.pagehelper.PageHelper;
+import com.xiaoan.dao.backend.IBaseMapper;
+import com.xiaoan.dao.backend.SceneProEditMapper;
+import com.xiaoan.dao.backend.SceneRepository;
+import com.xiaoan.domain.backend.SceneProEditEntity;
+import com.xiaoan.domain.backend.SceneProEntity;
+import com.xiaoan.domain.dto.request.SceneProRequest;
+import com.xiaoan.domain.dto.response.SceneResponse;
+import com.xiaoan.service.BaseServiceImpl;
+import com.xiaoan.service.backend.SceneProEditService;
+import com.xiaoan.service.backend.SceneService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+ * Created by Hb_zzZ on 2020/3/2.
+ */
+@Service
+@Transactional
+public class SceneProEditServiceImpl extends BaseServiceImpl<SceneProEditEntity, Long> implements SceneProEditService {
+
+    @Autowired
+    private SceneProEditMapper entityMapper;
+
+    @Override
+    public IBaseMapper<SceneProEditEntity, Long> getBaseMapper() {
+        return this.entityMapper;
+    }
+
+
+    @Override
+    public SceneProEditEntity findByProId(Long proId) {
+        return entityMapper.findByProId(proId);
+    }
+}

+ 5 - 0
xiaoan-service/src/main/java/com/xiaoan/service/backend/impl/SceneServiceImpl.java

@@ -1,6 +1,9 @@
 package com.xiaoan.service.backend.impl;
 
 import com.github.pagehelper.PageHelper;
+import com.xiaoan.common.constant.MsgCode;
+import com.xiaoan.common.util.HttpRequestorUtil;
+import com.xiaoan.common.util.ResultJson;
 import com.xiaoan.dao.backend.IBaseMapper;
 import com.xiaoan.dao.backend.SceneRepository;
 import com.xiaoan.domain.backend.SceneProEntity;
@@ -12,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -51,4 +55,5 @@ public class SceneServiceImpl extends BaseServiceImpl<SceneProEntity, Long> impl
     }
 
 
+
 }

+ 19 - 0
xiaoan-web/src/main/java/com/xiaoan/web/backend/BaseController.java

@@ -4,6 +4,7 @@ import com.xiaoan.domain.backend.LogEntity;
 import com.xiaoan.service.backend.LogService;
 import com.xiaoan.web.shiro.JwtUtil2;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -18,6 +19,24 @@ public class BaseController {
     @Autowired
     private LogService logService;
 
+    /** 打包文件文件存放地址*/
+    @Value("${server.package.result}")
+    public String SERVER_PACKAGE_RESULT;
+
+    /** 远程服务器地址(用来接收文件)*/
+    @Value("${remote.api}")
+    public String REMOTE_API;
+
+    /** 域名*/
+    @Value("${server.domian}")
+    public String SERVER_DOMIAN;
+
+    /** 发送文件域名*/
+    @Value("${remote.domian}")
+    public String REMOTE_DOMIAN;
+
+
+
     String getTokenUserName(){
         String token = request.getHeader("Authorization");
         return JwtUtil2.getUsername(token);

+ 168 - 12
xiaoan-web/src/main/java/com/xiaoan/web/backend/PersonalCenterController.java

@@ -1,13 +1,15 @@
 package com.xiaoan.web.backend;
 
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.github.pagehelper.PageInfo;
 import com.xiaoan.common.constant.MsgCode;
 import com.xiaoan.common.model.PageDto;
+import com.xiaoan.common.util.HttpRequestorUtil;
 import com.xiaoan.common.util.ResultJson;
-import com.xiaoan.domain.backend.CameraDetailEntity;
-import com.xiaoan.domain.backend.CameraEntity;
-import com.xiaoan.domain.backend.DepartmentEntity;
-import com.xiaoan.domain.backend.SceneProEntity;
+import com.xiaoan.domain.backend.*;
 import com.xiaoan.domain.dto.request.CameraRequest;
 import com.xiaoan.domain.dto.request.SceneProRequest;
 import com.xiaoan.domain.dto.response.CameraResponse;
@@ -20,15 +22,18 @@ import io.swagger.annotations.ApiOperation;
 import lombok.extern.log4j.Log4j2;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.junit.Test;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import tk.mybatis.mapper.entity.Condition;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * Created by Hb_zzZ on 2020/3/2.
@@ -45,12 +50,171 @@ public class PersonalCenterController extends BaseController {
     private SceneService sceneService;
 
     @Autowired
+    private SceneProEditService sceneProEditService;
+
+    @Autowired
     private CameraService cameraService;
 
     @Autowired
     private CameraDetailService cameraDetailService;
 
 
+    /**
+     * 2020-12-22
+     * 新增发送文件功能
+     */
+    @RequiresPermissions("admin:scene:edit")
+    @WebControllerLog(description = "个人中心-我的场景/发送文件")
+    @ApiOperation("发送文件")
+    @GetMapping("scene/send/{id}")
+    public ResultJson send(@PathVariable Long id) throws Exception {
+
+        SceneProEntity proEntity = sceneService.findById(id);
+
+        if (proEntity == null) {
+            return new ResultJson(MsgCode.e_COMMON_3001, MsgCode.msg_COMMON_3001);
+        }
+
+        saveLog("我的场景", "发送文件:"+ proEntity.getSceneName());
+
+        if (proEntity.getDownloadStatus() == 1) {
+            String api = REMOTE_API + "?sceneNum=" + proEntity.getNum();
+            int i = HttpRequestorUtil.fileRemote(api, SERVER_PACKAGE_RESULT + proEntity.getNum() + ".zip");
+            if (i == 200) {
+                log.info("文件发送成功");
+                proEntity.setDownloadStatus(2);
+
+                // 成功后还需要调用仕彬的两个接口
+                JSONObject proJson = insertSceneProInfo(proEntity);
+                String code = proJson.getString("code");
+                if (!"0".equals(code)) {
+                    log.error("发送insertSceneProInfo接口失败");
+                    return new ResultJson(MsgCode.e_COMMON_3001, "发送insertSceneProInfo接口失败");
+                }
+
+
+                SceneProEditEntity proEditEntity = sceneProEditService.findByProId(id);
+                // 将返回值id更新
+                log.info("proId 准备更新");
+                JSONObject dataJson = proJson.getJSONObject("data");
+                Integer proId = dataJson.getInteger("id");
+                log.info("proId: {}", proId);
+                proEditEntity.setProId(Long.valueOf(proId));
+                String s = insertSceneProEditInfo(proEditEntity);
+                if (!"0".equals(s)){
+                    log.error("发送insertSceneProEditInfo接口失败");
+                    return new ResultJson(MsgCode.e_COMMON_3001, "发送insertSceneProEditInfo接口失败");
+                }
+
+                proEntity.setUpdateTime(new Date());
+                sceneService.update(proEntity);
+
+            } else {
+                log.error("发送失败");
+                return new ResultJson(MsgCode.e_COMMON_3001, "文件发送失败");
+            }
+
+        } else {
+            return new ResultJson(MsgCode.e_COMMON_3001, "文件未打包");
+        }
+
+
+
+
+
+        return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
+    }
+
+
+        private JSONObject insertSceneProInfo(SceneProEntity proEntity) throws Exception {
+        // /api/scene/insertSceneProInfo
+        String api = REMOTE_DOMIAN + "/api/scene/insertSceneProInfo";
+
+        proEntity.setWebSite(editDomain(proEntity.getWebSite()));
+        proEntity.setThumb(editDomain(proEntity.getThumb()));
+
+
+            String post = HttpRequestorUtil.postJson(api, JSON.toJSONString(proEntity), "POST");
+            log.info("response: {}", post);
+            JSONObject jsonObject = JSONObject.parseObject(post);
+
+            return jsonObject;
+    }
+
+        private String insertSceneProEditInfo(SceneProEditEntity proEditEntity) throws Exception {
+        // /api/scene/insertSceneProEditInfo
+        String api = SERVER_DOMIAN + "/api/scene/insertSceneProEditInfo";
+
+            String post = HttpRequestorUtil.postJson(api, JSON.toJSONString(proEditEntity), "POST");
+            log.info("response: {}", post);
+
+            JSONObject jsonObject = JSONObject.parseObject(post);
+
+            return jsonObject.getString("code");
+    }
+
+    // 编辑远程域名
+    private String editDomain(String url){
+        url = StringUtils.substringAfterLast(url, ":");
+        url = StringUtils.substringAfter(url, "/");
+        return REMOTE_DOMIAN + "/" + url;
+    }
+
+
+    @Test
+    public void tes(){
+     String aa = "http://192.168.0.163:8088/smobile.html?m=xa-JHoB90HUS";
+
+        String s = StringUtils.substringAfterLast(aa, ":");
+        String s1 = StringUtils.substringAfterLast(s, "/");
+        System.out.println(s);
+        System.out.println(s1);
+    }
+
+//    private String insertSceneProInfo(SceneProEntity proEntity) throws Exception {
+//        // /api/scene/insertSceneProInfo
+//        String api = SERVER_DOMIAN + "/api/scene/insertSceneProInfo";
+//
+//        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(proEntity);
+//        log.info("map: {}", stringObjectMap);
+//
+//        String post = HttpUtil.post(api, stringObjectMap);
+//        log.info("s: {}", post);
+//        JSONObject jsonObject = JSONObject.parseObject(post);
+//
+//        return jsonObject.getString("code");
+//    }
+//
+//
+//    private String insertSceneProEditInfo(SceneProEditEntity proEditEntity) throws Exception {
+//        // /api/scene/insertSceneProEditInfo
+//        String api = SERVER_DOMIAN + "/api/scene/insertSceneProEditInfo";
+//
+//        Map<String, Object> stringObjectMap = BeanUtil.beanToMap(proEditEntity);
+//        log.info("map: {}", stringObjectMap);
+//
+//        String post = HttpUtil.post(api, stringObjectMap);
+//        log.info("s: {}", post);
+//        JSONObject jsonObject = JSONObject.parseObject(post);
+//
+//        return jsonObject.getString("code");
+//    }
+
+
+//    @RequiresPermissions("admin:scene:list")
+//    @WebControllerLog(description = "个人中心-我的场景/搜索")
+//    @ApiOperation("测试用户")
+//    @PostMapping("scene/testUser")
+//    public ResultJson testUser() throws Exception {
+//
+//        insertSceneProInfo();
+//        return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
+//    }
+
+
+
+
+
     @RequiresPermissions("admin:scene:list")
     @WebControllerLog(description = "个人中心-我的场景/搜索")
     @ApiOperation("获取场景列表/搜索")
@@ -101,10 +265,6 @@ public class PersonalCenterController extends BaseController {
             return new ResultJson(MsgCode.e_COMMON_3001, MsgCode.msg_COMMON_3001);
         }
 
-
-//        String webSite = proEntity.getWebSite();
-//        webSite = webSite.replace("showProMobile", "editProMobile");
-
         saveLog("我的场景", "编辑场景:"+ proEntity.getSceneName());
 
         HashMap<Object, Object> map = new HashMap<>();
@@ -214,10 +374,6 @@ public class PersonalCenterController extends BaseController {
 
             // 目前cameraDetailEntity 是写死的,暂时不需要修改他
         }
-
-
-
-
         return new ResultJson(MsgCode.SUCCESS_CODE, MsgCode.msg_SUCCESS);
     }
 

+ 0 - 95
xiaoan-web/src/main/java/com/xiaoan/web/backend/SceneController.java

@@ -1,95 +0,0 @@
-//package com.xiaoan.web.backend;
-//
-//import com.github.pagehelper.PageInfo;
-//import com.xiaoan.common.constant.MsgCode;
-//import com.xiaoan.common.util.ResultJson;
-//import com.xiaoan.domain.dto.request.SceneProRequest;
-//import com.xiaoan.domain.dto.response.SceneResponse;
-//import com.xiaoan.service.backend.SceneService;
-//import com.xiaoan.web.aop.WebControllerLog;
-//import com.xiaoan.web.shiro.JwtUtil2;
-//import io.swagger.annotations.Api;
-//import io.swagger.annotations.ApiOperation;
-//import org.apache.shiro.authz.annotation.RequiresPermissions;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.bind.annotation.*;
-//
-//import java.util.List;
-//
-///**
-// * Created by Hb_zzZ on 2020/3/2.
-// *
-// * 这个好像不使用了
-// */
-//
-//@Api(tags = "后台场景管理", value = "SceneController")
-//
-//@RestController
-//@RequestMapping("api/manage/scene")
-//@Transactional
-//public class SceneController extends BaseController {
-//
-//
-//    @Autowired
-//    private SceneService sceneService;
-//
-//
-//    /**
-//     * 根据场景名称,拍摄人查询
-//     * 需要分角色
-//     */
-//    @RequiresPermissions("admin:scene:list")
-//    @WebControllerLog(description = "场景管理-场景搜索/列表")
-//    @ApiOperation("获取场景列表")
-//    @PostMapping("list")
-//    public ResultJson list(@RequestBody SceneProRequest param){
-//
-//        List<SceneResponse> list = null;
-//        List userRole = JwtUtil2.getUserRole(getToken());
-//        if (userRole.contains("admin")) {
-//            list = sceneService.findAllBySearchKey(param, null);
-//        } else {
-//            Long userId = JwtUtil2.getUserId(getToken());
-//            list = sceneService.findAllBySearchKey(param, userId);
-//        }
-//
-//        PageInfo<SceneResponse> pageInfo = new PageInfo<SceneResponse>(list);
-//        return new ResultJson(MsgCode.SUCCESS_CODE, pageInfo);
-//    }
-//
-//
-//    /**
-//     * 本地后台修改场景名称
-//     */
-////    @ApiOperation("下载场景")
-////    @WebControllerLog(description = "场景管理-下载场景")
-////    @GetMapping(value = "/downloadTexData/{sceneNum}")
-////    public ResultJson downloadTexData(@PathVariable String sceneNum)  {
-////
-////        if(StringUtils.isEmpty(sceneNum)){
-////            return new ResultJson(MsgCode.FAILURE_CODE_3001, MsgCode.FAILURE_MSG_3001);
-////        }
-////        SceneProEntity sceneProEntity = sceneService.findBySceneNum(sceneNum);
-////        if(sceneProEntity == null){
-////            return new ResultJson(MsgCode.FAILURE_CODE_3001, MsgCode.FAILURE_MSG_3001);
-////        }
-////
-////        String dataPath = sceneProEntity.getDataSource() + "/caches/tex";
-////        String saveZipPath = scenePath + "images/images" + sceneNum;
-//////        FileUtils.createDir(saveZipPath);
-////        FileUtil.mkdir(saveZipPath);
-////
-////        String sourcePath = "F:\\test\\test123";
-////        ZipUtil.zip(sourcePath, saveZipPath+ "/tex.zip");
-////
-//////        return new ResultJson(MsgCode.SUCCESS_CODE,mainUrl + "scene/images/images" + sceneNum + "/tex.zip?t=" +System.currentTimeMillis());
-////        return new ResultJson(MsgCode.SUCCESS_CODE,"");
-////    }
-////
-////    public static void main(String[] args) {
-////        String sourcePath = "F:\\test\\test123";
-////        String saveZipPath = "F:\\test\\xiaoan\\";
-////        ZipUtil.zip(sourcePath, saveZipPath+ "tex.zip");
-////    }
-//}