yeshijie 7 éve
szülő
commit
c87590be21

+ 2 - 2
base/common-cache/pom.xml

@ -10,8 +10,8 @@
        <relativePath>../../common-lib-parent-pom/pom.xml</relativePath>
    </parent>
    <groupId>common-customCache</groupId>
    <artifactId>common-customCache</artifactId>
    <groupId>common-cache</groupId>
    <artifactId>common-cache</artifactId>
    <version>1.0.0</version>
    <dependencies>

+ 1 - 1
svr-lib-parent-pom/pom.xml

@ -520,7 +520,7 @@
            <dependency>
                <groupId>com.yihu.base</groupId>
                <artifactId>common-data-fastdfs</artifactId>
                <version>${version.fastdfs}</version>
                <version>${version.myCommon}</version>
            </dependency>
            <dependency>
                <groupId>org.csource</groupId>

+ 0 - 4
svr/svr-iot/pom.xml

@ -62,10 +62,6 @@
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-mysql</artifactId>
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-quartz</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>

+ 2 - 0
svr/svr-iot/src/main/java/com/yihu/iot/IOTApplication.java

@ -2,6 +2,7 @@ package com.yihu.iot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
/**
@ -9,6 +10,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 */
@EnableJpaAuditing
@SpringBootApplication
@ComponentScan(basePackages={"com"})
public class IOTApplication {
    public static void main(String[] args) {

+ 99 - 102
svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java

@ -1,102 +1,99 @@
//package com.yihu.iot.controller.common;
//
//import com.fasterxml.jackson.databind.node.ObjectNode;
//import com.yihu.base.fastdfs.FastDFSHelper;
//import com.yihu.iot.vo.common.UploadVO;
//import com.yihu.jw.exception.ApiException;
//import com.yihu.jw.exception.code.ExceptionCode;
//import com.yihu.jw.restmodel.common.Envelop;
//import com.yihu.jw.restmodel.common.EnvelopRestController;
//import com.yihu.jw.rm.iot.IotRequestMapping;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.ByteArrayInputStream;
//import java.io.InputStream;
//import java.net.URLDecoder;
//import java.util.Base64;
//
///**
// * @author yeshijie on 2017/12/7.
// */
//@RestController
//@RequestMapping(IotRequestMapping.api_iot_common)
//@Api(value = "文件上传相关操作", description = "文件上传相关操作")
//public class FileUploadController extends EnvelopRestController{
//
////    @Autowired
////    private FastDFSConfig fastDFSConfig;
//    @Value("${fastDFS.fastdfs_file_url}")
//    private String fastdfs_file_url;
//
//    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream)
//    @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
//    public Envelop uploadStream(@ApiParam(value = "文件", required = true) @RequestParam(value = "file", required = true) MultipartFile file) {
//        try {
//            // 得到文件的完整名称  xxx.txt
//            String fullName = file.getOriginalFilename();
//            //得到文件类型
//            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
//            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
//            //上传到fastdfs
//            FastDFSHelper fastDFSHelper = new FastDFSHelper();
//            ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
//            //解析返回的objectNode
//            UploadVO uploadVO = new UploadVO();
//            uploadVO.setFileName(fileName);
//            uploadVO.setFileType(fileType);
//            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
//            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
//            return Envelop.getSuccess(IotRequestMapping.DeviceSupplier.message_success_create, uploadVO);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
//        }
//    }
//
//    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_string)
//    @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
//    public Envelop uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流") @RequestBody String jsonData) throws Exception {
//        try {
//            if(jsonData == null){
//                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_jsonData_is_null, ExceptionCode.common_error_params_code);
//            }
//            String date = URLDecoder.decode(jsonData,"UTF-8");
//            String[] fileStreams = date.split(",");
//            String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
//            byte[] in = Base64.getDecoder().decode(is);
//
//            String pictureName = fileStreams[0].substring(0,fileStreams[0].length()-1);
//            String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
//            String description = null;
//            if ((pictureName != null) && (pictureName.length() > 0)) {
//                int dot = pictureName.lastIndexOf('.');
//                if ((dot > -1) && (dot < (pictureName.length()))) {
//                    description = pictureName.substring(0, dot);
//                }
//            }
//            InputStream inputStream = new ByteArrayInputStream(in);
//            FastDFSHelper fastDFSHelper = new FastDFSHelper();
//            ObjectNode objectNode = fastDFSHelper.upload(inputStream, ".png", "");
//            String groupName = objectNode.get("groupName").toString();
//            String remoteFileName = objectNode.get("remoteFileName").toString();
////        String path = "{\"groupName\":" + groupName + ",\"remoteFileName\":" + remoteFileName + "}";
//            String path = groupName.substring(1,groupName.length()-1) + ":" + remoteFileName.substring(1,remoteFileName.length()-1);
//            //解析返回的objectNode
//            UploadVO uploadVO = new UploadVO();
//            uploadVO.setFileName(remoteFileName);
//            uploadVO.setFileType(groupName);
//            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
//            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
//            //返回文件路径
//            return Envelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, path);
//        }catch (ApiException e){
//            return Envelop.getError(e.getMessage(), e.getErrorCode());
//        }
//    }
//
//}
package com.yihu.iot.controller.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.iot.vo.common.UploadVO;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
import java.util.Base64;
/**
 * @author yeshijie on 2017/12/7.
 */
@RestController
@RequestMapping(IotRequestMapping.api_iot_common)
@Api(value = "文件上传相关操作", description = "文件上传相关操作")
public class FileUploadController extends EnvelopRestController{
    @Autowired
    private FastDFSHelper fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream)
    @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
    public Envelop uploadStream(@ApiParam(value = "文件", required = true) @RequestParam(value = "file", required = true) MultipartFile file) {
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(fileName);
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.DeviceSupplier.message_success_create, uploadVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_string)
    @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
    public Envelop uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流") @RequestBody String jsonData) throws Exception {
        try {
            if(jsonData == null){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_jsonData_is_null, ExceptionCode.common_error_params_code);
            }
            String date = URLDecoder.decode(jsonData,"UTF-8");
            String[] fileStreams = date.split(",");
            String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
            byte[] in = Base64.getDecoder().decode(is);
            String pictureName = fileStreams[0].substring(0,fileStreams[0].length()-1);
            String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
            String description = null;
            if ((pictureName != null) && (pictureName.length() > 0)) {
                int dot = pictureName.lastIndexOf('.');
                if ((dot > -1) && (dot < (pictureName.length()))) {
                    description = pictureName.substring(0, dot);
                }
            }
            InputStream inputStream = new ByteArrayInputStream(in);
            ObjectNode objectNode = fastDFSHelper.upload(inputStream, "png", "");
            String groupName = objectNode.get("groupName").toString();
            String remoteFileName = objectNode.get("remoteFileName").toString();
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(remoteFileName);
            uploadVO.setFileType(groupName);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            //返回文件路径
            return Envelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, uploadVO);
        }catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 23 - 3
svr/svr-iot/src/main/resources/application.yml

@ -1,4 +1,7 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主  git上 svr-base ->  git application ->本地 appliction ->本地 bootstarp
server:
  port: 10050
spring:
  application:
    name:  svr-iot  ##注册到发现服务的id 如果id一样 eurika会自动做负载
@ -28,6 +31,20 @@ hibernate:
  ejb:
    naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy
fast-dfs:
  tracker-server: 172.19.103.54:22122 #服务器地址
  connect-timeout: 2 #链接超时时间
  network-timeout: 30
  charset: ISO8859-1 #编码
  http:
    tracker-http-port: 80
    anti-steal-token: no
    secret-key: FastDFS1234567890
  pool: #连接池大小
    init-size: 5
    max-size: 20
    wait-time: 500
---
spring:
  profiles: jwdev
@ -36,13 +53,16 @@ spring:
    url: jdbc:mysql://172.19.103.77:3306/xmiot?useUnicode=true&amp;characterEncoding=utf-8&amp;autoReconnect=true
    username: root
    password: 123456
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
---
spring:
  profiles: jwtest
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
---
spring:
  profiles: jwprod
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/