by su 3 лет назад
Родитель
Сommit
c0773ff142

+ 6 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/SceneApplication.java

@@ -1,5 +1,6 @@
 package com.fdkankan.scene;
 
+import com.fdkankan.common.config.FileRouteConfig;
 import com.fdkankan.common.constant.RedisUtil;
 import com.fdkankan.common.exception.GlobalExceptionHandler;
 import com.fdkankan.common.util.UploadToOssUtil;
@@ -36,6 +37,11 @@ public class SceneApplication {
     }
 
     @Bean
+    public FileRouteConfig fileRouteConfig(){
+        return new FileRouteConfig();
+    }
+
+    @Bean
     public UploadToOssUtil uploadToOssUtil(){
         return new UploadToOssUtil();
     }

+ 760 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/controller/SceneFileController.java

@@ -0,0 +1,760 @@
+package com.fdkankan.scene.controller;
+
+import cn.hutool.core.util.StrUtil;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fdkankan.common.constant.RedisUtil;
+import com.fdkankan.common.controller.BaseController;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.common.util.RSAEncrypt;
+import com.fdkankan.scene.service.*;
+import com.fdkankan.scene.vo.ResponseSceneFile;
+import lombok.extern.log4j.Log4j2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.util.Base64;
+
+/**
+ * 场景文件上传模块
+ */
+@Log4j2
+@RestController
+@RequestMapping("/api/scene/file")
+@Transactional(rollbackFor = Exception.class)
+public class SceneFileController extends BaseController {
+
+//    @Autowired
+//    private FileService fileService;
+    @Autowired
+    private ISceneFileUploadService sceneFileUploadService;
+    @Autowired
+    private ISceneFileBuildService sceneFileBuildService;
+//    @Autowired
+//    private FileRouteConfig routeConfig;
+//    @Autowired
+//    private ModelingMsgProducer producer;
+    private String splice = "#";
+
+//    @Autowired
+//    private GoodsFeignClient goodsService;
+    @Autowired
+    private ObjectMapper mapper;
+
+    @Autowired
+    private ISceneProService sceneProService;
+
+    @Autowired
+    private ISceneProEditService sceneProEditService;
+
+//    @Autowired
+//    private UserFeignClient userService;
+//
+//    @Autowired
+//    private IScene3dNumNewService numService;
+//
+//    @Autowired
+//    private UploadToOssUtil uploadToOssUtil;
+//
+//    @Autowired
+//    private ICompanyService companyService;
+
+    @Autowired
+    private ISceneCooperationService sceneCooperationService;
+
+    @Autowired
+    private ISceneResourceCooperationService sceneResourceCooperationService;
+
+    @Autowired
+    private ISceneResourceCameraService sceneResourceCameraService;
+
+    @Autowired
+    RedisUtil redisUtil;
+
+    @Autowired
+    RedisTemplate redisTemplate;
+
+    @Value("${main.url}")
+    private String mainUrl;
+
+    @Value("${scene.url}")
+    private String sceneUrl;
+
+    @Value("${scene.pro.url}")
+    private String sceneProUrl;
+
+    @Value("${scene.pro.new.url}")
+    private String sceneProNewUrl;
+
+    @Value("${oss.type}")
+    private String type;
+
+    @Value("${prefix.ali}")
+    private String prefixAli;
+
+    @Value("${ecs.type}")
+    private String ecsType;
+
+//    @Autowired
+//    private RubberSheetingUtil rubberSheetingUtil;
+//
+//    @Autowired
+//    private SceneNumService sceneNumService;
+
+    @Value("${unCalculated.company.ids:#{null}}")
+    private String[] unCalculatedCompanyIds;
+
+    /**
+     * 场景文件上传之前先获取fileId
+     * @param params
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("preUpload")
+    public ResponseSceneFile preUpload(String params) throws Exception {
+        return sceneFileBuildService.preUpload(params);
+    }
+
+
+
+    /**
+     * 获取文件上传的状态
+     * @param params
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("getProgress")
+    public ResponseSceneFile getProgress(String params) throws Exception {
+        return sceneFileBuildService.getProgress(params);
+    }
+
+    /**
+     * 单个文件上传
+     * @param file
+     * @param params
+     * @return
+     */
+    @PostMapping("upload")
+    public ResultData upload(@RequestParam(value = "file",required = false) MultipartFile file,
+                         String params) throws Exception {
+        return sceneFileBuildService.uploadFile(file, params);
+    }
+
+    /**
+     * 上传大文件
+     * @param file
+     * @return
+     * @throws
+     */
+    @PostMapping("uploadBigFile")
+    public ResultData uploadBigFile(@RequestParam(value = "file",required = false) MultipartFile file,
+                                String params) throws Exception {
+        return sceneFileBuildService.uploadFile(file, params);
+    }
+
+    /**
+     * 更新fileid文件的上传状态  -- 作废
+     *
+     * @param params
+     * @return
+     */
+    @PostMapping("uploadSuccess")
+    public ResultData uploadSuccess(String params) throws Exception {
+        log.info("uploadSuccess-params: " + params);
+        if (StrUtil.isEmpty(params)) {
+            throw new BaseRuntimeException("params为空。");
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("uploadSuccess-params解密结果:" + restr);
+        String[] strArr = restr.split(splice);
+        if (strArr.length != 3) {
+            throw new BaseRuntimeException("缺少必要参数。");
+        }
+        String mac = strArr[0];
+        String fileId = strArr[1];
+        String folderName = JedisUtil.getStringValue(fileId);
+        if(StringUtils.isEmpty(folderName)){
+            SceneProEntity sceneProEntity = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+            if(sceneProEntity != null){
+                folderName = sceneProEntity.getDataSource().substring(sceneProEntity.getDataSource().lastIndexOf("/") + 1);
+            }
+
+            if(StringUtils.isEmpty(folderName)){
+                SceneFileBuildEntity sceneFileBuildEntity = sceneFileBuildService.findByFileId(fileId);
+                if(sceneFileBuildEntity != null){
+                    folderName = sceneFileBuildEntity.getUnicode();
+                }
+            }
+        }
+        StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
+        boolean flag = sceneFileBuildService.uploadSuccess(fileId, filePathBuffer);
+
+        if(flag){
+            //调用建模的方法
+            buildScene(filePathBuffer.toString(), fileId, false, null);
+        }
+        return Result.success();
+    }
+
+//    /**
+//     * 更新fileid文件的上传状态
+//     *
+//     * @param params
+//     * @return
+//     */
+//    @PostMapping("uploadSuccessBuild")
+//    @ApiOperation("更新fileid文件的上传状态  - 后端八目上传逻辑")
+//    @ApiImplicitParam(name = "params", value = "加密参数", dataType = "String")
+//    public Result uploadSuccessBuild(String params) throws Exception {
+//        log.info("uploadSuccessBuild-params: " + params);
+//        if (StringUtils.isEmpty(params)) {
+//            throw new BaseRuntimeException("params为空。");
+//        }
+//        params = params.replaceAll("%2B", "+");
+//        Base64 base64 = new Base64();
+//        String cipher = params;
+//        // 私钥解密过程
+//        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+//                base64.decode(cipher));
+//        String restr = new String(res, "UTF-8");
+//        log.debug("uploadSuccessBuild-params解密结果:" + restr);
+//        String[] strArr = restr.split(splice);
+//        if (strArr.length != 3) {
+//            throw new BaseRuntimeException("缺少必要参数。");
+//        }
+//        String mac = strArr[0];
+//        String fileId = strArr[1];
+//        String folderName = JedisUtil.getStringValue(fileId);
+//        if(StringUtils.isEmpty(folderName)){
+//            SceneProEntity sceneProEntity = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+//            if(sceneProEntity != null){
+//                folderName = sceneProEntity.getDataSource().substring(sceneProEntity.getDataSource().lastIndexOf("/") + 1);
+//            }
+//
+//            if(StringUtils.isEmpty(folderName)){
+//                SceneFileBuildEntity sceneFileBuildEntity = sceneFileBuildService.findByFileId(fileId);
+//                if(sceneFileBuildEntity != null){
+//                    folderName = sceneFileBuildEntity.getUnicode();
+//                }
+//            }
+//        }
+//        StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
+//        StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
+//
+//        File filePath = new File(filePathBuffer.toString());
+//        if(!filePath.exists()){
+//            filePath.mkdirs();
+//        }
+//        if("s3".equals(type)){
+//            CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
+//        }else {
+//            CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
+//        }
+//        buildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
+//        return Result.success();
+//    }
+//
+//    /**
+//     * 更新fileid文件的上传状态
+//     *
+//     * @param params
+//     * @return
+//     */
+//    @PostMapping("turntableUploadSuccess")
+//    @ApiOperation("转台相机,激光相机")
+//    @ApiImplicitParam(name = "params", value = "加密参数", dataType = "String")
+//    public Result turntableUploadSuccess(String params) throws Exception {
+//        log.info("uploadSuccessBuild-params: " + params);
+//        if (StringUtils.isEmpty(params)) {
+//            throw new BaseRuntimeException("params为空。");
+//        }
+//        params = params.replaceAll("%2B", "+");
+//        Base64 base64 = new Base64();
+//        String cipher = params;
+//        // 私钥解密过程
+//        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+//                base64.decode(cipher));
+//        String restr = new String(res, "UTF-8");
+//        log.debug("uploadSuccessBuild-params解密结果:" + restr);
+//        String[] strArr = restr.split(splice);
+//        if (strArr.length != 3) {
+//            throw new BaseRuntimeException("缺少必要参数。");
+//        }
+//        String mac = strArr[0];
+//        String fileId = strArr[1];
+//        String folderName = JedisUtil.getStringValue(fileId);
+//        if(StringUtils.isEmpty(folderName)){
+//            SceneProEntity sceneProEntity = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+//            if(sceneProEntity != null){
+//                folderName = sceneProEntity.getDataSource().substring(sceneProEntity.getDataSource().lastIndexOf("/") + 1);
+//            }
+//
+//            if(StringUtils.isEmpty(folderName)){
+//                SceneFileBuildEntity sceneFileBuildEntity = sceneFileBuildService.findByFileId(fileId);
+//                if(sceneFileBuildEntity != null){
+//                    folderName = sceneFileBuildEntity.getUnicode();
+//                }
+//            }
+//        }
+//        //判断 是否为激光相机
+//        CameraEntity cameraEntity = goodsService.findByChildName(mac);
+//        CameraDetailEntity cameraDetailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
+//
+//        String hardDisk = routeConfig.getHardDisk();
+//        if(cameraDetailEntity!=null){
+//            if(cameraDetailEntity.getType() == 10){
+//                hardDisk = routeConfig.getHardDiskLaser();
+//            }
+//        }
+//
+//        log.info("相机 mnt 路径 : " + hardDisk + ", 相机类型 : " + cameraDetailEntity.getType());
+//
+//        StringBuilder filePathBuffer = new StringBuilder(hardDisk).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
+//        StringBuilder prefixBuffer = new StringBuilder(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator);
+//
+//        File filePath = new File(filePathBuffer.toString());
+//        if(!filePath.exists()){
+//            filePath.mkdirs();
+//        }
+//        if("s3".equals(type)){
+//            CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString() + "data.fdage");
+//        }else {
+//            CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefixBuffer.toString() + "data.fdage", filePathBuffer.toString());
+//        }
+//        turntableBuildScene(filePathBuffer.toString(), fileId, true, prefixBuffer.toString());
+//        return Result.success();
+//    }
+//
+//    /**
+//     * 获取亚马逊S3文件上传url
+//     *
+//     * @return
+//     */
+//    @PostMapping("getS3UploadUrl")
+//    @ApiOperation("获取亚马逊S3文件上传url")
+//    @ApiImplicitParam(name = "params", value = "加密参数", dataType = "String")
+//    public Result getS3UploadUrl(String params) throws Exception {
+//        if (StringUtils.isEmpty(params)) {
+//            throw new BaseRuntimeException("params为空。");
+//        }
+//        JSONObject jsonObject = JSON.parseObject(params);
+//        if(jsonObject == null){
+//            throw new BaseRuntimeException("params数据不正确");
+//        }
+//        JSONArray files = jsonObject.getJSONArray("Files");
+//        if(files == null){
+//            throw new BaseRuntimeException("params数据不正确");
+//        }
+//        List<String> urls = new ArrayList<>();
+//        for(int i = 0, len = files.size(); i < len; i++){
+//            urls.add(files.getJSONObject(i).getString("filename"));
+//        }
+//        return Result.success(uploadToOssUtil.getUploadS3Url(urls));
+//    }
+//
+//    /**
+//     * 计算双目场景
+//     *
+//     * @return
+//     */
+//    @ApiOperation("计算双目场景 - 新双目相机上传 小红屋")
+//    @PostMapping("buildLiteScene")
+//    @ApiImplicitParams({
+//            @ApiImplicitParam(name = "prefix", value = "文件下载前缀,结尾不加/", dataType = "String"),
+//            @ApiImplicitParam(name = "dataFdage", value = "dataFdage", dataType = "String"),
+//            @ApiImplicitParam(name = "zipName", value = "zip文件包名称", dataType = "String"),
+//            @ApiImplicitParam(name = "password", value = "密码", dataType = "String"),
+//            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String")})
+//    public Result buildLiteScene(String prefix, String dataFdage, String zipName, String userName, String password, String oldNum) throws Exception{
+//        log.info("参数-prefix: {}, dataFdage: {}, zipName: {}, password: {}, userName: {}", prefix,
+//                dataFdage, zipName, password, userName);
+//
+//        if(StringUtils.isEmpty(prefix) || StringUtils.isEmpty(dataFdage) || StringUtils.isEmpty(zipName) ||
+//                StringUtils.isEmpty(userName) || StringUtils.isEmpty(password)){
+//            throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
+//        }
+//
+//        CameraEntity cameraEntity = goodsService.findByChildName(userName);
+//
+//        if(cameraEntity == null){
+//            cameraEntity = goodsService.findBySnCode(userName);
+//        }
+//        if (cameraEntity == null){
+//            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+//        }
+//        if(!password.equals(cameraEntity.getChildPassword())){
+//            throw new BaseRuntimeException(LoginConstant.FAILURE_CODE_3014, LoginConstant.FAILURE_MSG_3014);
+//        }
+//
+//        String unicode = prefix.substring(prefix.lastIndexOf("/") + 1);
+//        String path = ConstantFilePath.BUILD_MODEL_PATH + unicode;
+//
+//        //下载data.fdage
+//        FileUtils.downLoadFromUrl(prefix + "/" + dataFdage + "?m=" + System.currentTimeMillis(), dataFdage, path + File.separator + "capture");
+//        String data = FileUtils.readFile(path + File.separator + "capture/" + dataFdage);
+//        JSONObject jsonObject = JSONObject.parseObject(data);
+//        if(jsonObject == null){
+//            log.info("data.fdage不存在");
+//            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6009, CameraConstant.FAILURE_MSG_6009);
+//        }
+//
+//        String sceneNum = "";
+//        //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
+//        SceneProEntity proEntity = sceneProService.findByFileId("/" + unicode);
+//        int rebuild = 1;
+//        if(StringUtil.isNotEmpty(oldNum)){
+//            sceneNum = oldNum;
+//        }else {
+//
+//            if(proEntity != null){
+//                sceneNum = proEntity.getNum();
+//                //重算的场景,先移除该场景对应的容量
+//                userService.rebuildReduceSpaceBySceneNum(sceneNum);
+//            }else {
+//                sceneNum = sceneNumService.generateSceneNum();
+//                rebuild = 0;
+//            }
+//        }
+//
+//        String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
+//        log.info("查询相机:" + cameraName);
+//        cameraEntity = goodsService.findByChildName(cameraName);
+//
+//        if(cameraEntity ==  null){
+//            log.error("该相机不存在:" + cameraName);
+//            //偶现data.fdage给的相机码多了或少了4DKKPRO_
+//            if(cameraName.contains("4DKKPRO_")){
+//                cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", ""));
+//            }else {
+//                cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName);
+//            }
+//            if(cameraEntity == null){
+//                throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+//            }
+//        }
+//
+//        CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
+//        if(detailEntity ==  null){
+//            log.error("该相机详情不存在:" + cameraName);
+//            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+//        }
+//
+//        String icon = null;
+//        if(jsonObject.containsKey("icon") && StringUtil.isNotEmpty(jsonObject.getString("icon"))){
+//            //下载封面图icon
+//            FileUtils.downLoadFromUrl(prefix + "/" + jsonObject.getString("icon") + "?m=" + System.currentTimeMillis(), jsonObject.getString("icon"), path + File.separator + "capture");
+//            uploadToOssUtil.upload(path + File.separator + "capture" + File.separator +
+//                    jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
+//            icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+//            if("s3".equals(type)){
+//                icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+//            }
+//        }
+//
+//        JSONObject firmwareVersion = new JSONObject();
+//        if(jsonObject.containsKey("camSoftwareVersion") && StringUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
+//            firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
+//        }
+//
+//        if(jsonObject.containsKey("version") && StringUtil.isNotEmpty(jsonObject.getString("version"))){
+//            firmwareVersion.put("version", jsonObject.getString("version"));
+//        }
+//
+//        String sceneUrl = mainUrl + sceneProNewUrl;
+//        String buildType = "V3";
+//        //表示新款双目
+//        Long cameraType = 5L;
+//        if(jsonObject.getJSONObject("cam").getIntValue("type") == 5){
+//
+//            //6表示小红屋双目
+//            cameraType = 6L;
+//        }
+//
+//        SceneProEntity scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+//                jsonObject.getString("pwd"), unicode,
+//                cameraType, "", prefix, zipName, icon, "0", detailEntity.getUserId(), userName,
+//                jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+//                jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+//                jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
+//                producer, 4, firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
+//                sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
+//
+//        if(scene == null){
+//            log.info("双目相机入库失败");
+//            return Result.failure("双目相机异常");
+//        }
+//        JSONObject statusJson = new JSONObject();
+//        //临时将-2改成1,app还没完全更新
+//        statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
+//        statusJson.put("webSite", scene.getWebSite());
+//        statusJson.put("sceneNum", scene.getNum());
+//        statusJson.put("thumb", scene.getThumb());
+//        statusJson.put("payStatus", scene.getPayStatus());
+//        FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
+//        uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
+//                "data/data"+sceneNum+File.separator+"status.json");
+//
+//        //删除oss的houst_floor.json
+//        uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
+//
+//        producer.sendMsg(scene.getMqMsg());
+//
+//        Map<String, String> map = new HashMap<>();
+//        map.put("sceneNum", sceneNum);
+//        map.put("sceneUrl", sceneUrl + sceneNum);
+//        return Result.success(map);
+//
+//
+//    }
+//
+//    /**
+//     *
+//     * @return
+//     */
+//    @PostMapping("buildScene")
+//    @ApiOperation("获取亚马逊S3文件上传url")
+//    @ApiImplicitParams({
+//        @ApiImplicitParam(name = "unicode", value = "unicode文件夹", dataType = "String"),
+//            @ApiImplicitParam(name = "zip", value = "zip包的名称", dataType = "String"),
+//            @ApiImplicitParam(name = "dataFdage", value = "dataFdage名称", dataType = "String")})
+//    public Result buildScene(String prefix, String unicode, String zip, String dataFdage) throws Exception{
+//
+////        FileUtils.downLoadFromUrl(prefix);
+//
+//        String data = FileUtils.readFile(ConstantFilePath.BUILD_MODEL_PATH + unicode + "/data.fdage");
+//        JSONObject jsonObject = JSONObject.parseObject(data);
+//
+//
+//        String sceneNum = sceneNumService.generateSceneNum();
+//
+////        SceneProEntity scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+////                jsonObject.getString("pwd"), unicode,
+////                cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName,
+////                jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+////                jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+////                jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
+////                producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type);
+//
+//        return Result.success(mainUrl + sceneProNewUrl + sceneNum);
+//    }
+//
+
+//    public void turntableBuildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
+//        String data = FileUtils.readFile(filePath + "data.fdage");
+//        JSONObject jsonObject = JSONObject.parseObject(data);
+//
+//        //调用createScene方法生成scene数据和加入算法队列
+//        if(jsonObject == null) {
+//            log.info("data.fdage文件不存在");
+//            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6009, CameraConstant.FAILURE_MSG_6009);
+//        }
+//
+//        String sceneNum = "";
+//
+//        String snCode = jsonObject.getJSONObject("cam").getString("uuid");
+//        String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime"); //从data.fage 取出
+////            sceneProService.updateRecStatus(unicode);
+//        //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
+//        SceneProEntity proEntity = sceneProService.findByFileId("/" + fileId + "/");
+//        int rebuild = 1;
+//        if(proEntity != null){
+//            sceneNum = proEntity.getNum();
+//            if(proEntity.getStatus() == 0){
+//                log.info(sceneNum + ":场景处于计算中,不能再计算");
+//                return;
+//            }
+//        }else {
+//            sceneNum = sceneNumService.generateSceneNum();
+//            rebuild = 0;
+//        }
+//
+//        if(sceneNum == null){
+//            log.error("大场景序号为空:" + sceneNum);
+//            throw new BaseRuntimeException(SceneConstant.FAILURE_CODE_5005, SceneConstant.FAILURE_MSG_5005);
+//        }
+//
+//        log.info("查询相机:" + snCode);
+//        CameraEntity cameraEntity = goodsService.findByChildName(snCode);
+//
+//        if(cameraEntity ==  null){
+//            log.error("该相机不存在:" + snCode);
+//            cameraEntity = goodsService.findBySnCode(snCode);
+//            if(cameraEntity == null){
+//                throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+//            }
+//        }
+//
+//        CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
+//        if(detailEntity ==  null){
+//            log.error("该相机详情不存在:" + snCode);
+//            throw new BaseRuntimeException(CameraConstant.FAILURE_CODE_6003, CameraConstant.FAILURE_MSG_6003);
+//        }
+//
+//        String userName = null;
+//        if(detailEntity.getUserId() != null){
+//            Result result = userService.findById(detailEntity.getUserId());
+//            SSOUser user = mapper.convertValue(result.getData(), SSOUser.class);
+//            if(user != null){
+//                userName = user.getUserName();
+//            }
+//        }
+//
+//        String icon = null;
+//        if(jsonObject.containsKey("icon") && StringUtil.isNotEmpty(jsonObject.getString("icon"))){
+//            CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
+//            icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+//            if("s3".equals(type)){
+//                CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
+//                icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+//            }
+//            uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
+//        }
+//
+//        JSONObject firmwareVersion = new JSONObject();
+//        if(jsonObject.containsKey("camSoftwareVersion") && StringUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
+//            firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
+//        }
+//
+//        if(jsonObject.containsKey("version") && StringUtil.isNotEmpty(jsonObject.getString("version"))){
+//            firmwareVersion.put("version", jsonObject.getString("version"));
+//        }
+//
+//        String sceneUrl = mainUrl + sceneProNewUrl;
+//        String buildType = "V3";
+//        //13表示转台
+//        Long cameraType = 13L;
+//        //国际版本使用切割好的瓦片图
+////                if("s3".equals(type)){
+////                    cameraType = 12L;
+////                }
+//
+//        //激光转台 八目相机占用 10 和 11
+//        if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
+//            //激光转台
+//            cameraType = 14L;
+//        }
+//
+//
+//        //重算的场景,先移除该场景对应的容量
+//        if(rebuild == 1){
+//            userService.rebuildReduceSpaceBySceneNum(sceneNum);
+//        }else {
+//            //上传log-main.png
+//            uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
+//            uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
+//        }
+//        SceneProEntity scene = null;
+//        scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+//                jsonObject.getString("pwd"), unicode,
+//                cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName,
+//                jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+//                jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+//                jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
+//                producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
+//                sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
+//
+//        if(scene != null){
+//            JSONObject statusJson = new JSONObject();
+//            //临时将-2改成1,app还没完全更新
+//            statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
+//            statusJson.put("webSite", scene.getWebSite());
+//            statusJson.put("sceneNum", scene.getNum());
+//            statusJson.put("thumb", scene.getThumb());
+//            statusJson.put("payStatus", scene.getPayStatus());
+//            statusJson.put("recStatus", scene.getRecStatus());
+//            FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
+//            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
+//                    "data/data"+sceneNum+File.separator+"status.json");
+//        }
+//
+//        if(detailEntity.getCompanyId() != null){
+//            CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId());
+//            if(companyEntity != null){
+//
+//                Map<String, Object> jsonMap = new HashMap<>();
+//
+//                log.info("复制企业logo");
+//                SceneProEditEntity sceneProEditEntity = sceneProEditService.findByProId(scene.getId());
+//
+//                if(StringUtil.isNotEmpty(companyEntity.getTopLogo())){
+//
+//                    FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(),
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
+//                    uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
+//                            "images/images" + sceneNum + "/logo-main.png");
+//                }
+//
+//                if(StringUtil.isNotEmpty(companyEntity.getFloorLogo())){
+//
+//                    FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(),
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
+//                    uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
+//                            "images/images" + sceneNum + "/floorLogoImg.png");
+//
+//                    sceneProEditEntity.setFloorLogo("user");
+//                    jsonMap.put("floorLogoSize", sceneProEditEntity.getFloorLogoSize());
+//                    jsonMap.put("floorLogo", "user");
+//                }
+//
+//                if(StringUtil.isNotEmpty(companyEntity.getQrLogo())){
+//
+//                    FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(),
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
+//                    uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
+//                            "images/images" + sceneNum + "/QRShareLogo.png");
+//                    sceneProEditEntity.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
+//
+//                    //生成新的分享的二维码
+//                    MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
+//                    MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
+//                }
+//
+//                if(StringUtil.isNotEmpty(companyEntity.getMarkerLogo())){
+//
+//                    FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(),
+//                            ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
+//                    uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
+//                            "images/images" + sceneNum + "/marker.png");
+//
+//                    sceneProEditEntity.setMarkerLogo("user");
+//                    jsonMap.put("markerLogo", "user");
+//                }
+//
+//                sceneProEditEntity.setShowLogoBottom(companyEntity.getShowLogo());
+//                sceneProEditService.update(sceneProEditEntity);
+//
+//                jsonMap.put("showLogoBottom", companyEntity.getShowLogo());
+//                FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
+//            }
+//
+//            //删除oss的houst_floor.json
+//            uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
+//
+//        }
+//
+//        //激光转台 八目相机占用 10 和 11
+//        if(jsonObject.getJSONObject("cam").getIntValue("type") == 10){
+//
+//            producer.sendMsgLaser(scene.getMqMsg());
+//        }else  if(scene != null){
+//            producer.sendMsg(scene.getMqMsg());
+//        }
+//    }
+//
+
+
+}

+ 11 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/ISceneFileBuildService.java

@@ -1,7 +1,10 @@
 package com.fdkankan.scene.service;
 
+import com.fdkankan.common.response.ResultData;
 import com.fdkankan.scene.entity.SceneFileBuild;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.fdkankan.scene.vo.ResponseSceneFile;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * <p>
@@ -21,4 +24,12 @@ public interface ISceneFileBuildService extends IService<SceneFileBuild> {
 
     void unzipSingleFile(String filePath);
 
+    ResultData uploadFile(MultipartFile file, String params) throws Exception;
+
+    ResponseSceneFile preUpload(String params) throws Exception;
+
+    ResponseSceneFile getProgress(String params) throws Exception;
+
+    ResultData uploadSuccess(String params) throws Exception;
+
 }

+ 730 - 12
4dkankan-center-scene/src/main/java/com/fdkankan/scene/service/impl/SceneFileBuildServiceImpl.java

@@ -1,31 +1,35 @@
 package com.fdkankan.scene.service.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.fdkankan.common.constant.ErrorCode;
-import com.fdkankan.common.constant.RecStatus;
-import com.fdkankan.common.constant.TbStatus;
-import com.fdkankan.common.constant.UploadStatus;
+import com.fdkankan.common.config.FileRouteConfig;
+import com.fdkankan.common.constant.*;
 import com.fdkankan.common.exception.BusinessException;
-import com.fdkankan.scene.entity.SceneDownloadLog;
-import com.fdkankan.scene.entity.SceneFileBuild;
-import com.fdkankan.scene.entity.SceneFileUpload;
+import com.fdkankan.common.response.ResultData;
+import com.fdkankan.common.util.*;
+import com.fdkankan.scene.entity.*;
 import com.fdkankan.scene.mapper.ISceneFileBuildMapper;
-import com.fdkankan.scene.service.ISceneFileBuildService;
+import com.fdkankan.scene.service.*;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.fdkankan.scene.service.ISceneFileUploadService;
+import com.fdkankan.scene.vo.ResponseSceneFile;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
-import java.util.Calendar;
-import java.util.List;
-import java.util.Objects;
+import java.time.LocalDate;
+import java.util.*;
 
 /**
  * <p>
@@ -39,8 +43,43 @@ import java.util.Objects;
 @Service
 public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper, SceneFileBuild> implements ISceneFileBuildService {
 
+    private static final String SPLICE = "#";
+
+    @Value("${main.url}")
+    private String mainUrl;
+
+    @Value("${scene.url}")
+    private String sceneUrl;
+
+    @Value("${scene.pro.url}")
+    private String sceneProUrl;
+
+    @Value("${scene.pro.new.url}")
+    private String sceneProNewUrl;
+
+    @Value("${oss.type}")
+    private String type;
+
+    @Value("${prefix.ali}")
+    private String prefixAli;
+
+    @Value("${ecs.type}")
+    private String ecsType;
+
     @Autowired
     ISceneFileUploadService sceneFileUploadService;
+    @Autowired
+    RedisTemplate redisTemplate;
+    @Autowired
+    ISceneProService sceneProService;
+    @Autowired
+    private FileRouteConfig routeConfig;
+    @Autowired
+    UploadToOssUtil uploadToOssUtil;
+    @Autowired
+    ISceneProEditService sceneProEditService;
+    @Autowired
+    ISceneProEditExtService sceneProEditExtService;
 
     @Override
     public SceneFileBuild findByFileId(String fileId) {
@@ -156,4 +195,683 @@ public class SceneFileBuildServiceImpl extends ServiceImpl<ISceneFileBuildMapper
         }
     }
 
+    @Override
+    public ResponseSceneFile preUpload(String params) throws Exception {
+        log.info("preUpload-params: "+params);
+        if (StrUtil.isEmpty(params)){
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("preUpload-params解密结果:" + restr);
+        String[] strArr = restr.split(SPLICE);
+        if (strArr.length != 5) {
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        String mac = strArr[0];
+        String totalPicNum = strArr[1];
+        String chunks = strArr[2];
+        String folderName = strArr[3];
+
+        if (StrUtil.isEmpty(mac)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
+        }
+        if (totalPicNum == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5045);
+        }
+        if (chunks == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5046);
+        }
+        if (folderName == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5047);
+        }
+
+        log.info("mac:" + mac + "准备上传文件");
+        SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + folderName, "A");
+        if(scenePro != null && scenePro.getDataSource() != null){
+            int n = scenePro.getDataSource().split("/").length;
+            if(n > 1){
+                String fileId = scenePro.getDataSource().split("/")[n - 2];
+
+                ResponseSceneFile responseSceneFile = new ResponseSceneFile();
+                responseSceneFile.setFileId(fileId);
+                //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
+                redisTemplate.opsForValue().set(fileId, folderName, 1537920000);
+                return responseSceneFile;
+            }
+
+        }else {
+            SceneFileBuild sceneFileBuild = this.findByUnicode(folderName);
+            if(sceneFileBuild != null){
+                String fileId = sceneFileBuild.getFileId();
+
+                ResponseSceneFile responseSceneFile = new ResponseSceneFile();
+                responseSceneFile.setFileId(fileId);
+                //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
+                redisTemplate.opsForValue().set(fileId, folderName, 1537920000);
+                return responseSceneFile;
+            }
+        }
+
+        // 构造方法设置机器码:第0个机房的第0台机器
+        SnowflakeIdGenerator snowflakeIdGenerator = new SnowflakeIdGenerator(0, 0);
+        long fileId = snowflakeIdGenerator.nextId();
+
+        SceneFileBuild sceneFileBuild = new SceneFileBuild();
+        sceneFileBuild.setChildName(mac);
+        sceneFileBuild.setFileId(String.valueOf(fileId));
+        sceneFileBuild.setUnicode(folderName);
+        sceneFileBuild.setUploadStatus(0);
+        sceneFileBuild.setBuildStatus(0);
+        sceneFileBuild.setTotalPicNum(Integer.valueOf(totalPicNum));
+        sceneFileBuild.setChunks(Integer.valueOf(chunks));
+        this.save(sceneFileBuild);
+
+        ResponseSceneFile responseSceneFile = new ResponseSceneFile();
+        responseSceneFile.setFileId(String.valueOf(fileId));
+        //可以重复上传,文件id保存50年(因为该redis工具无法设置永久保存)
+        redisTemplate.opsForValue().set(String.valueOf(fileId), folderName, 1537920000);
+        return responseSceneFile;
+    }
+
+    @Override
+    public ResponseSceneFile getProgress(String params) throws Exception {
+        log.info("getProgress-params:{} ", params);
+        if (StrUtil.isEmpty(params)){
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("getProgress-params解密结果:{}" , restr);
+        String[] strArr = restr.split(SPLICE);
+        if (strArr.length != 3) {
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        String fileId = strArr[0];
+        String chunk = strArr[1];
+
+        chunk = chunk.split(SPLICE)[0];
+        SceneFileUpload sceneFileUpload = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
+
+        ResponseSceneFile responseSceneFile = new ResponseSceneFile();
+        responseSceneFile.setUploadStatus(sceneFileUpload != null ? sceneFileUpload.getUploadStatus() : -1);
+        return responseSceneFile;
+    }
+
+    @Override
+    public ResultData uploadFile(MultipartFile file, String params) throws Exception{
+        log.info("upload-params: "+params);
+        if (StringUtils.isEmpty(params)){
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("upload-params解密结果:{}", restr);
+        String[] strArr = restr.split(SPLICE);
+        if (strArr.length != 6) {
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        String mac = strArr[0];
+        String fileId = strArr[1];
+        String picNum = strArr[2];
+        String md5 = strArr[3];
+        String chunk = strArr[4];
+
+        ResultData result = null;
+        if (file.isEmpty()){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5048);
+        }
+        if (StringUtils.isEmpty(fileId)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5049);
+        }
+        if (picNum == null){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5050);
+        }
+        if (StringUtils.isEmpty(mac)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5044);
+        }
+        if (StringUtils.isEmpty(md5)){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_5051);
+        }
+        long size = file.getSize();
+        log.warn("fileId:"+fileId+"---picNum:"+picNum+"---size:"+size+"---md5:"+md5+"---mac:"+mac);
+        chunk = chunk.split(SPLICE)[0];
+        // 获取文件名
+        String fileName = file.getOriginalFilename();
+        log.info("上传的文件名为:" + fileName);
+        // 获取文件的后缀名
+        String suffixName = fileName.substring(fileName.lastIndexOf("."));
+        log.info("上传的后缀名为:" + suffixName);
+        String folderName = (String) redisTemplate.opsForValue().get(fileId);
+        if(StringUtils.isEmpty(folderName)){
+            SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+            if(scenePro != null){
+                folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
+            }
+        }
+        // 1. 判断该文件是否已经上传过
+        // 2. 如果已经上传过,判断MD5值和文件大小是否相等。如果相等,更新数据记录。如果不相等,删除该文件,重新上传。
+        // 3. 如果未上传过,需要上传。
+        StringBuffer filePathBuffer = new StringBuffer(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture");
+        StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(filePathBuffer.toString()).append(File.separator).append(fileName);
+
+        boolean needUpload = false;
+        File dbFile = new File(sb.toString());
+        if (dbFile.exists()){
+            String fileMD5 = FileMd5Util.getFileMD5(dbFile);
+            if (md5.equals(fileMD5) && dbFile.length() == size){
+                log.warn("文件已存在,MD5和文件大小一致。");
+
+                SceneFileUpload uploadEntity = sceneFileUploadService.findByFileIdAndChunk(fileId, Integer.valueOf(chunk));
+                if (uploadEntity != null){
+                    uploadEntity.setSize((int) size);
+                    uploadEntity.setMd5(md5);
+                    uploadEntity.setFilePath(sb.toString());
+                    uploadEntity.setFileSourceName(fileName);
+                    uploadEntity.setUploadStatus(1);
+                    sceneFileUploadService.updateById(uploadEntity);
+                }else{
+                    SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
+                    sceneFileUploadEntity.setSize((int) size);
+                    sceneFileUploadEntity.setMd5(md5);
+                    sceneFileUploadEntity.setFilePath(sb.toString());
+                    sceneFileUploadEntity.setFileSourceName(fileName);
+                    sceneFileUploadEntity.setUploadStatus(1);
+                    sceneFileUploadEntity.setFileId(fileId);
+                    sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
+                    sceneFileUploadService.save(sceneFileUploadEntity);
+                }
+                result = ResultData.ok();
+            }else if (!md5.equals(fileMD5)) {
+                log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
+                FileUtil.delFile(sb.toString());
+                needUpload = true;
+            }else if (dbFile.length() != size){
+                log.warn("文件已上传,文件大小不一致。上传失败");
+                FileUtil.delFile(sb.toString());
+                needUpload = true;
+            }
+        }else {
+            log.warn("文件不存在,需要重新上传");
+            needUpload = true;
+        }
+
+        // 4. 上传成功后,校验MD5和文件大小是否相等
+        // 5. 如果相等,更新数据记录。如果不相等,返回上传失败结果。
+        try {
+            if (needUpload){
+                String name = fileName.substring(0, fileName.lastIndexOf("."));
+                String filePath = this.saveFile(file, filePathBuffer.toString(), name);
+                File uploadFile = new File(filePath);
+                String fileMD5 = FileMd5Util.getFileMD5(uploadFile);
+
+                SceneFileUpload sceneFileUploadEntity = new SceneFileUpload();
+                sceneFileUploadEntity.setSize((int) size);
+                sceneFileUploadEntity.setMd5(md5);
+                sceneFileUploadEntity.setFilePath(sb.toString());
+                sceneFileUploadEntity.setFileSourceName(fileName);
+                sceneFileUploadEntity.setFileId(fileId);
+                sceneFileUploadEntity.setChunk(Integer.valueOf(chunk));
+
+                if (md5.equals(fileMD5) && uploadFile.length() == size){
+                    log.warn("文件已上传,MD5和文件大小一致。上传成功");
+                    sceneFileUploadEntity.setUploadStatus(1);
+                    sceneFileUploadService.save(sceneFileUploadEntity);
+                    result = ResultData.ok();
+                }else if (!md5.equals(fileMD5)) {
+                    log.warn("文件已上传,上传MD5:"+md5+",服务器MD5:"+fileMD5+"。不一致。上传失败");
+                    sceneFileUploadEntity.setUploadStatus(-1);
+                    sceneFileUploadService.save(sceneFileUploadEntity);
+                    result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
+                }else if (uploadFile.length() != size){
+                    log.warn("文件已上传,文件大小不一致。上传失败");
+                    sceneFileUploadEntity.setUploadStatus(-1);
+                    sceneFileUploadService.save(sceneFileUploadEntity);
+                    result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
+                }
+            }
+        }catch (IllegalStateException | IOException e) {
+            log.error(ErrorCode.FAILURE_CODE_5052.message(), e);
+            result = ResultData.error(ErrorCode.FAILURE_CODE_5052);
+        }
+        return result;
+    }
+
+    public ResultData uploadSuccess(String params) throws Exception {
+        log.info("uploadSuccess-params: " + params);
+        if (StrUtil.isEmpty(params)) {
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        params = params.replaceAll("%2B", "+");
+        Base64 base64 = new Base64();
+        String cipher = params;
+        // 私钥解密过程
+        byte[] res = RSAEncrypt.decrypt(RSAEncrypt.loadPrivateKeyByStr(RSAEncrypt.loadPrivateKeyByFile()),
+                base64.decode(cipher));
+        String restr = new String(res, "UTF-8");
+        log.debug("uploadSuccess-params解密结果:" + restr);
+        String[] strArr = restr.split(SPLICE);
+        if (strArr.length != 3) {
+            throw new BusinessException(ErrorCode.PARAM_REQUIRED);
+        }
+        String mac = strArr[0];
+        String fileId = strArr[1];
+        String folderName = (String) redisTemplate.opsForValue().get(fileId);
+        if(StringUtils.isEmpty(folderName)){
+            SceneProPO scenePro = sceneProService.getSceneStatusByUnicode("/" + fileId + "/", "A");
+            if(scenePro != null){
+                folderName = scenePro.getDataSource().substring(scenePro.getDataSource().lastIndexOf("/") + 1);
+            }
+
+            if(StringUtils.isEmpty(folderName)){
+                SceneFileBuild sceneFileBuild = this.findByFileId(fileId);
+                if(sceneFileBuild != null){
+                    folderName = sceneFileBuild.getUnicode();
+                }
+            }
+        }
+        StringBuilder filePathBuffer = new StringBuilder(routeConfig.getHardDisk()).append(mac).append(File.separator).append(fileId).append(File.separator).append(folderName).append(File.separator).append("capture").append(File.separator);
+        boolean flag = this.uploadSuccess(fileId, filePathBuffer);
+
+        if(flag){
+            //调用建模的方法
+            buildScene(filePathBuffer.toString(), fileId, false, null);
+        }
+        return ResultData.ok();
+    }
+
+    public void buildScene(String filePath, String fileId, boolean fromOss, String prefix) throws Exception{
+        //获取解压后的资源的data.fdage中的数据
+        String data = FileUtils.readFile(filePath + "data.fdage");
+        JSONObject jsonObject = JSONObject.parseObject(data);
+
+        //调用createScene方法生成scene数据和加入算法队列
+        if(jsonObject != null){
+            //有calibration值为标定,1: camera_calibration 2: color_anlysis,0正常计算
+            if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("1")){
+                String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
+                String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/camera_calibration";
+                //生成标定数据
+                ComputerUtil.createCalibrationData(calPath, filePath);
+                //开始标定计算
+                producer.sendMsg(calPath);
+
+            }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("2")){
+                String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
+                String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/color_anlysis";
+                //生成标定数据
+                ComputerUtil.createCalibrationData(calPath, filePath);
+                //开始标定计算
+                Map<String,String> map = ComputerUtil.computerCalibration(calPath);
+            }else if(jsonObject.get("calibration") != null && jsonObject.getString("calibration").equals("3")){
+                String mac = filePath.replace(ConstantFilePath.BUILD_MODEL_PATH, "").split("/")[0];
+                String calPath = ConstantFilePath.BUILD_MODEL_PATH + mac + "/shading";
+                //生成标定数据
+                ComputerUtil.createCalibrationData(calPath, filePath);
+                //开始标定计算
+                producer.sendMsg(calPath);
+
+            }else {
+
+                String sceneNum = "";
+
+                String cameraName = jsonObject.getJSONObject("cam").getString("uuid");
+                String unicode = jsonObject.getString("creator") + "_" + jsonObject.getString("uuidtime");
+                //查看场景中的文件目录是否有改文件id,有则重新计算改场景,无则新建场景
+                SceneProPO proEntity = sceneProService.findByFileId("/" + fileId + "/");
+                int rebuild = 1;
+                if(proEntity != null){
+                    sceneNum = proEntity.getSceneCode();
+                    if(proEntity.getSceneStatus() == SceneStatus.wait.code()){
+                        log.info(sceneNum + ":场景处于计算中,不能再计算");
+                        return;
+                    }
+                }else {
+                    sceneNum = sceneNumService.generateSceneNum();
+                    rebuild = 0;
+                }
+
+                if(sceneNum == null){
+                    log.error("大场景序号为空:" + sceneNum);
+                    throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
+                }
+
+                log.info("查询相机:" + cameraName);
+                CameraEntity cameraEntity = goodsService.findByChildName(cameraName);
+
+                if(cameraEntity ==  null){
+                    log.error("该相机不存在:" + cameraName);
+                    //偶现data.fdage给的相机码多了或少了4DKKPRO_
+                    if(cameraName.contains("4DKKPRO_")){
+                        cameraEntity = goodsService.findByChildName(cameraName.replace("4DKKPRO_", ""));
+                    }else {
+                        cameraEntity = goodsService.findByChildName("4DKKPRO_" + cameraName);
+                    }
+                    if(cameraEntity == null){
+                        throw new BusinessException(CameraConstant.FAILURE_6003);
+                    }
+                }
+
+                CameraDetailEntity detailEntity = goodsService.findCameraDetailByCameraId(cameraEntity.getId());
+                if(detailEntity ==  null){
+                    log.error("该相机详情不存在:" + cameraName);
+                    throw new BusinessException(CameraConstant.FAILURE_6003);
+                }
+
+                String userName = null;
+                if(detailEntity.getUserId() != null){
+                    ResultData result = userService.findById(detailEntity.getUserId());
+                    SSOUser user = mapper.convertValue(result.getData(), SSOUser.class);
+                    if(user != null){
+                        userName = user.getUserName();
+                    }
+                }
+                String icon = null;
+                if(jsonObject.containsKey("icon") && StrUtil.isNotEmpty(jsonObject.getString("icon"))){
+                    CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath);
+                    icon = prefixAli + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+                    if("s3".equals(type)){
+                        CreateObjUtil.ossFileCp(ConstantFilePath.OSS_PREFIX + prefix + jsonObject.getString("icon"), filePath + jsonObject.getString("icon"));
+                        icon = ConstantUrl.PREFIX_AWS + "images/images" + sceneNum + "/" + jsonObject.getString("icon");
+                    }
+                    uploadToOssUtil.upload(filePath + jsonObject.getString("icon"), "images/images" + sceneNum + "/" + jsonObject.getString("icon"));
+                }
+
+                JSONObject firmwareVersion = new JSONObject();
+                if(jsonObject.containsKey("camSoftwareVersion") && StrUtil.isNotEmpty(jsonObject.getString("camSoftwareVersion"))){
+                    firmwareVersion.put("camSoftwareVersion", jsonObject.getString("camSoftwareVersion"));
+                }
+
+                if(jsonObject.containsKey("version") && StrUtil.isNotEmpty(jsonObject.getString("version"))){
+                    firmwareVersion.put("version", jsonObject.getString("version"));
+                }
+
+                String sceneUrl = mainUrl + sceneProUrl;
+                String buildType = "V2";
+                Long cameraType = 10L;
+                //根据videoVersion判断是V2还是V3版本的算法和页面
+                if(jsonObject.containsKey("videoVersion") && StrUtil.isNotEmpty(jsonObject.getString("videoVersion"))){
+                    if(jsonObject.getIntValue("videoVersion") >= 4){
+                        buildType = "V3";
+                        cameraType = 11L;
+                        sceneUrl = mainUrl + sceneProNewUrl;
+                    }
+                }
+                //重算的场景,先移除该场景对应的容量
+                if(rebuild == 1){
+                    userService.rebuildReduceSpaceBySceneNum(sceneNum);
+                }else {
+                    //上传log-main.png
+                    uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main.png", "images/images" + sceneNum + "/logo-main.png");
+                    uploadToOssUtil.upload(ConstantFilePath.LOGO_PATH + "logo-main-en.png", "images/images" + sceneNum + "/logo-main-en.png");
+                }
+                SceneProPO scene = null;
+                if(fromOss){
+                    scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+                            jsonObject.getString("pwd"), unicode,
+                            cameraType, String.valueOf(fileId), prefix, "", icon, "0", detailEntity.getUserId(), userName,
+                            jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+                            jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+                            jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
+                            producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
+                            sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
+                }else {
+                    scene = ComputerUtil.createScenePro(sceneNum, cameraEntity.getId(), cameraEntity.getChildName(), jsonObject.getString("creator"),
+                            jsonObject.getString("pwd"), unicode,
+                            detailEntity.getGoodsId(), String.valueOf(fileId), "", "", icon, "0", detailEntity.getUserId(), userName,
+                            jsonObject.getString("location") != null && "1".equals(jsonObject.getString("location")) ? "sfm" : "slam",
+                            jsonObject.getJSONArray("points").size(), jsonObject.getString("name"), jsonObject.getString("info"),
+                            jsonObject.getInteger("scenetype"), jsonObject.getString("gps"), sceneProService, sceneProEditService, rebuild,
+                            producer, jsonObject.getInteger("resolution"), firmwareVersion.toString(), sceneUrl, buildType, type, ecsType,
+                            sceneCooperationService, sceneResourceCooperationService, sceneResourceCameraService, detailEntity.getCooperationUser(), rubberSheetingUtil);
+                }
+
+                if(scene != null){
+                    JSONObject statusJson = new JSONObject();
+                    //临时将-2改成1,app还没完全更新
+                    statusJson.put("status", scene.getStatus() == -2? 1 : scene.getStatus());
+                    statusJson.put("webSite", scene.getWebSite());
+                    statusJson.put("sceneNum", scene.getNum());
+                    statusJson.put("thumb", scene.getThumb());
+                    statusJson.put("payStatus", scene.getPayStatus());
+                    statusJson.put("recStatus", scene.getRecStatus());
+                    FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json", statusJson.toString());
+                    uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+sceneNum+File.separator+"status.json",
+                            "data/data"+sceneNum+File.separator+"status.json");
+                }
+
+                //删除oss的houst_floor.json(国际版可能会卡住)
+                uploadToOssUtil.delete("data/data"+sceneNum+File.separator+"houst_floor.json");
+
+                if(detailEntity.getCompanyId() != null){
+                    CompanyEntity companyEntity = companyService.findById(detailEntity.getCompanyId());
+                    if(companyEntity != null){
+
+                        Map<String, Object> jsonMap = new HashMap<>();
+
+                        log.info("复制企业logo");
+                        SceneProEdit sceneProEdit = sceneProEditService.findByProId(scene.getId());
+                        SceneProEditExt sceneProEditExt = sceneProEditExtService.getByProEditId(sceneProEdit.getId());
+
+                        if(StrUtil.isNotEmpty(companyEntity.getTopLogo())){
+                            //复制阿里云主服务器的图片到横琴云副服务器中
+                            if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo()).exists()){
+                                log.info("下载topLogo");
+                                FileUtils.downLoadFromUrl(mainUrl + companyEntity.getTopLogo() + "?t=" + System.currentTimeMillis(),
+                                        companyEntity.getTopLogo().substring(companyEntity.getTopLogo().lastIndexOf("/") + 1),
+                                        ConstantFilePath.BASE_PATH + companyEntity.getTopLogo().substring(0, companyEntity.getTopLogo().lastIndexOf("/")));
+                            }
+
+                            FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getTopLogo(),
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png", true);
+                            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/logo-main.png",
+                                    "images/images" + sceneNum + "/logo-main.png");
+                        }
+
+                        if(StrUtil.isNotEmpty(companyEntity.getFloorLogo())){
+                            //复制阿里云主服务器的图片到横琴云副服务器中
+                            if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo()).exists()){
+                                log.info("下载floorLogo");
+                                FileUtils.downLoadFromUrl(mainUrl + companyEntity.getFloorLogo() + "?t=" + System.currentTimeMillis(),
+                                        companyEntity.getFloorLogo().substring(companyEntity.getFloorLogo().lastIndexOf("/") + 1),
+                                        ConstantFilePath.BASE_PATH + companyEntity.getFloorLogo().substring(0, companyEntity.getFloorLogo().lastIndexOf("/")));
+                            }
+
+                            FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getFloorLogo(),
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png", true);
+                            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/floorLogoImg.png",
+                                    "images/images" + sceneNum + "/floorLogoImg.png");
+
+                            sceneProEdit.setFloorLogo("user");
+                            jsonMap.put("floorLogoSize", sceneProEdit.getFloorLogoSize());
+                            jsonMap.put("floorLogo", "user");
+                        }
+
+                        if(StrUtil.isNotEmpty(companyEntity.getQrLogo())){
+                            //复制阿里云主服务器的图片到横琴云副服务器中
+                            if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo()).exists()){
+                                log.info("下载qrLogo");
+                                FileUtils.downLoadFromUrl(mainUrl + companyEntity.getQrLogo() + "?t=" + System.currentTimeMillis(),
+                                        companyEntity.getQrLogo().substring(companyEntity.getQrLogo().lastIndexOf("/") + 1),
+                                        ConstantFilePath.BASE_PATH + companyEntity.getQrLogo().substring(0, companyEntity.getQrLogo().lastIndexOf("/")));
+                            }
+
+                            FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getQrLogo(),
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png", true);
+                            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png",
+                                    "images/images" + sceneNum + "/QRShareLogo.png");
+                            sceneProEdit.setShareLogo("images/images" + sceneNum + "/QRShareLogo.png");
+
+                            //生成新的分享的二维码
+                            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+".png",
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
+                            MatrixToImageWriterUtil.createQRCode(sceneUrl + sceneNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+sceneNum+"_en.png",
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/QRShareLogo.png");
+                        }
+
+                        if(StrUtil.isNotEmpty(companyEntity.getMarkerLogo())){
+                            //复制阿里云主服务器的图片到横琴云副服务器中
+                            if(!new File(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo()).exists()){
+                                log.info("下载floorLogo");
+                                FileUtils.downLoadFromUrl(mainUrl + companyEntity.getMarkerLogo() + "?t=" + System.currentTimeMillis(),
+                                        companyEntity.getMarkerLogo().substring(companyEntity.getMarkerLogo().lastIndexOf("/") + 1),
+                                        ConstantFilePath.BASE_PATH + companyEntity.getMarkerLogo().substring(0, companyEntity.getMarkerLogo().lastIndexOf("/")));
+                            }
+
+                            FileUtils.copyFile(ConstantFilePath.BASE_PATH + File.separator + companyEntity.getMarkerLogo(),
+                                    ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png", true);
+                            uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH + "images/images" + sceneNum + "/marker.png",
+                                    "images/images" + sceneNum + "/marker.png");
+
+                            sceneProEdit.setMarkerLogo("user");
+                            jsonMap.put("markerLogo", "user");
+                        }
+
+                        sceneProEdit.setUpdateTime(Calendar.getInstance().getTime());
+                        sceneProEditService.updateById(sceneProEdit);
+
+                        sceneProEditExt.setUpdateTime(Calendar.getInstance().getTime());
+                        sceneProEditExt.setShowLogoBottom(companyEntity.getShowLogo());
+                        sceneProEditExtService.updateById(sceneProEditExt);
+
+                        jsonMap.put("showLogoBottom", companyEntity.getShowLogo());
+                        FileUtils.writeJsonFile(ConstantFilePath.SCENE_PATH + "data/data" + sceneNum + "/scene.json", jsonMap);
+                    }
+
+                }
+
+                // 正顺相机不予计算
+                Long companyId = detailEntity.getCompanyId();
+                if(Objects.nonNull(unCalculatedCompanyIds) && Arrays.asList(unCalculatedCompanyIds).contains(companyId)){
+                    return;
+                }
+                if(scene != null){
+                    producer.sendMsg(scene.getMqMsg());
+                }
+
+            }
+        }else {
+            log.info("data.fdage文件不存在");
+            throw new BusinessException(CameraConstant.FAILURE_6009);
+        }
+    }
+
+
+
+    public String saveFile(MultipartFile file, String filePath, String fileId) throws IOException {
+        //扩展名格式
+        String extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+        String name;
+        /*
+          指定上传目录
+         */
+        if (filePath != null && !"".equals(filePath.trim())) {
+            name = designatedUp(filePath, fileId, file);
+            return name;
+        }
+        /*
+          默认上传目录
+         */
+        //图片类型文件
+        if (this.inArray(routeConfig.getImageType(), extName)) {
+            filePath = routeConfig.getImageFolder();
+        }
+        //视频类型文件
+        else if (this.inArray(routeConfig.getVideoType(), extName)) {
+            filePath = routeConfig.getVideoFolder();
+        }
+        //文档类型文件
+        else if (this.inArray(routeConfig.getDocumentType(), extName)) {
+            filePath = routeConfig.getDocumentFolder();
+        }
+        //音频类型文件
+        else if (this.inArray(routeConfig.getMusicType(), extName)) {
+            filePath = routeConfig.getMusicFolder();
+        } else {
+            return "This upload type is not supported temporarily";
+        }
+        name = myfileUp(filePath, file);
+        return name;
+    }
+
+    /**
+     * 删除文件
+     *
+     * @param filePath 包含文件路径的文件名
+     * @return
+     */
+    public String dropFile(String filePath) {
+        try {
+            FileUtil.delFile(routeConfig.getHardDisk() + File.separator + filePath);
+            return "successful operation";
+        } catch (Exception e) {
+            return "drop file error";
+        }
+    }
+
+    /**
+     * 判断数组中是否包含某个元素
+     *
+     * @param array   类型的数组
+     * @param element 被检查的类型
+     * @return
+     */
+    private boolean inArray(String[] array, String element) {
+        boolean flag = false;
+        for (String type : array) {
+            if (element.equals(type)) {
+                flag = true;
+                break;
+            }
+        }
+        return flag;
+    }
+
+    /**
+     * 默认上传文件到文件夹
+     *
+     * @param folder 默认文件夹
+     * @param file   上传的文件
+     * @return
+     */
+    private String myfileUp(String folder, MultipartFile file) throws IOException {
+        LocalDate today = LocalDate.now();
+        String saveName = File.separator + today.getYear() + "." + today.getMonthValue() + File.separator;
+        String fileCode = UUID.randomUUID().toString().trim().replaceAll("-", "");
+        String returnName = FileUpload.fileUp(file, routeConfig.getHardDisk() + File.separator + folder + saveName, fileCode);
+        saveName = folder + File.separator + saveName + File.separator + returnName;
+        log.warn("This file has been uploaded: " + saveName);
+        return saveName;
+    }
+
+    /**
+     * 指定目录上传文件
+     *
+     * @param folder 指定文件夹
+     * @param file   上传文件
+     * @return
+     */
+    private String designatedUp(String folder, String fileId, MultipartFile file) throws IOException {
+        StringBuffer sb = new StringBuffer(routeConfig.getHardDisk()).append(File.separator).append(folder);
+        String returnName = FileUpload.fileUp(file, sb.toString(), fileId);
+        String filePathName = sb.toString() + File.separator + File.separator + returnName;
+        log.warn("This file has been uploaded: " + filePathName);
+        return filePathName;
+    }
+
 }

+ 18 - 0
4dkankan-center-scene/src/main/java/com/fdkankan/scene/vo/ResponseSceneFile.java

@@ -0,0 +1,18 @@
+package com.fdkankan.scene.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class ResponseSceneFile implements Serializable {
+
+    private static final long serialVersionUID = 1279396211495565258L;
+
+    @ApiModelProperty(value = "文件id", name = "fileId")
+    private String fileId;
+
+    @ApiModelProperty(value = "上传状态", name = "uploadStatus")
+    private int uploadStatus;
+}

+ 108 - 0
4dkankan-common/src/main/java/com/fdkankan/common/config/FileRouteConfig.java

@@ -0,0 +1,108 @@
+package com.fdkankan.common.config;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+
+@Component
+@ConfigurationProperties(prefix = "file.route")
+public class FileRouteConfig {
+    /**
+     * 路径
+     */
+    //保存硬盘地址
+    private String hardDisk;
+	//保存硬盘地址(激光相机)
+	private String hardDiskLaser;
+    //默认图片类型文件夹
+    private String imageFolder;
+    //默认文件类型文件夹
+    private String documentFolder;
+    //默认的视频类型文件夹
+    private String videoFolder;
+    //默认的音频类型文件夹
+    private String musicFolder;
+    //允许上传的ip(上传白名单)
+    private String[] IPs;
+    /**
+     * 类型
+     */
+    //图片类型
+    private String[] imageType;
+    //文件类型
+    private String[] documentType;
+    //视频类型
+    private String[] videoType;
+    //音频类型
+    private String[] musicType;
+	public String getHardDisk() {
+		return hardDisk;
+	}
+	public String getHardDiskLaser() {
+		return hardDiskLaser;
+	}
+	public String getImageFolder() {
+		return imageFolder;
+	}
+	public String getDocumentFolder() {
+		return documentFolder;
+	}
+	public String getVideoFolder() {
+		return videoFolder;
+	}
+	public String getMusicFolder() {
+		return musicFolder;
+	}
+	public String[] getIPs() {
+		return IPs;
+	}
+	public String[] getImageType() {
+		return imageType;
+	}
+	public String[] getDocumentType() {
+		return documentType;
+	}
+	public String[] getVideoType() {
+		return videoType;
+	}
+	public String[] getMusicType() {
+		return musicType;
+	}
+	public void setHardDisk(String hardDisk) {
+
+		this.hardDisk = hardDisk;
+	}
+	public void setHardDiskLaser(String hardDiskLaser) {
+
+		this.hardDiskLaser = hardDiskLaser;
+	}
+	public void setImageFolder(String imageFolder) {
+		this.imageFolder = imageFolder;
+	}
+	public void setDocumentFolder(String documentFolder) {
+		this.documentFolder = documentFolder;
+	}
+	public void setVideoFolder(String videoFolder) {
+		this.videoFolder = videoFolder;
+	}
+	public void setMusicFolder(String musicFolder) {
+		this.musicFolder = musicFolder;
+	}
+	public void setIPs(String[] iPs) {
+		IPs = iPs;
+	}
+	public void setImageType(String[] imageType) {
+		this.imageType = imageType;
+	}
+	public void setDocumentType(String[] documentType) {
+		this.documentType = documentType;
+	}
+	public void setVideoType(String[] videoType) {
+		this.videoType = videoType;
+	}
+	public void setMusicType(String[] musicType) {
+		this.musicType = musicType;
+	}
+    
+    
+}

+ 9 - 0
4dkankan-common/src/main/java/com/fdkankan/common/constant/ErrorCode.java

@@ -116,6 +116,15 @@ public enum ErrorCode {
     FAILURE_CODE_5041(5041, "上传图片多媒体数据失败"),
     FAILURE_CODE_5042(5042, "算法计算失败"),
     FAILURE_CODE_5043(5043, "打包zip失败"),
+    FAILURE_CODE_5044(5044, "mac为空"),
+    FAILURE_CODE_5045(5045, "totalPicNum为空"),
+    FAILURE_CODE_5046(5046, "chunks为空"),
+    FAILURE_CODE_5047(5047, "folderName为空"),
+    FAILURE_CODE_5048(5048, "文件为空"),
+    FAILURE_CODE_5049(5049, "文件Id为空"),
+    FAILURE_CODE_5050(5050, "照片数目为空"),
+    FAILURE_CODE_5051(5051, "md5为空"),
+    FAILURE_CODE_5052(5052, "上传失败, 请重新上传。"),
 
 
 

+ 877 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/ComputerUtil.java

@@ -0,0 +1,877 @@
+package com.fdkankan.common.util;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+//import com.fdkankan.base.mq.ModelingMsgProducer;
+import com.fdkankan.common.constant.ConstantFileName;
+import com.fdkankan.common.constant.ConstantFilePath;
+import com.fdkankan.common.constant.ConstantUrl;
+import lombok.extern.slf4j.Slf4j;
+import org.joda.time.DateTime;
+import org.springframework.stereotype.Component;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
+import java.util.*;
+
+/**
+ * 生成场景和计算场景
+ * Created by Hb_zzZ on 2019/5/8.
+ */
+@Slf4j
+@Component
+public class ComputerUtil {
+
+
+//    public static Map<String,String> computer(String projectNum, String path, String buildType, String ossType) throws Exception{
+//        Map<String,String> map = new HashMap<String,String>();
+//        path = path.replace("//", "/");
+//
+//        log.info("开始建模:"+projectNum);
+//        //构建算法isModel去掉,因此改成空字符串
+//        if("V2".equals(buildType)){
+//            CreateObjUtil.build3dModelOld(path, "");
+//        }
+//        if("V3".equals(buildType)){
+//            CreateObjUtil.build3dModel(path, "");
+////        CreateObjUtil.build3dModel(unicode, "");
+//        }
+//        log.info("建模完成转换数据:"+projectNum);
+//
+//        boolean vision2 = false;
+//        //读取upload文件,检验需要上传的文件是否存在
+//        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+//        JSONObject uploadJson = null;
+//        JSONArray array = null;
+//        if(uploadData!=null) {
+//            uploadJson = JSONObject.parseObject(uploadData);
+//            array = uploadJson.getJSONArray("upload");
+//        }
+//        if(array == null){
+//            String instanceId = FileUtils.readFile("/opt/hosts/hosts.txt");
+//            FileUtils.writeFile(path + File.separator + "javaErrorNow.log", instanceId + ":计算错误!");
+//
+//            Thread.sleep(10000L);
+//            FileUtils.writeFile(path + File.separator + "javaError.log", instanceId + ":计算错误!");
+//            throw new Exception("upload.json数据出错");
+//        }
+//        JSONObject fileJson = null;
+//        String fileName = "";
+//        String meshfix = "";  //双模型时候会有改文件路径
+//        for(int i = 0, len = array.size(); i < len; i++){
+//            fileJson = array.getJSONObject(i);
+//            fileName = fileJson.getString("file");
+//            //文件不存在抛出异常
+//            if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
+//                throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
+//            }
+//
+//            //判断是否有vision2.txt
+//            if("vision2.txt".equals(fileName)){
+//                vision2 = true;
+//            }
+//
+//            //tex文件夹
+//            if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
+//                if(fileName.contains("meshfix.txt")){
+//                    meshfix = fileName;
+//                }else {
+//                    map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
+//                            projectNum+"/"+ ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
+//                }
+//                continue;
+//            }
+//
+//            //high文件夹
+//            if(fileJson.getIntValue("clazz") == 3){
+//                map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
+//                        projectNum+"/pan/high/"+ fileName.replace("high/", ""));
+//                continue;
+//            }
+//            //low文件夹
+//            if(fileJson.getIntValue("clazz") == 4){
+//                map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
+//                        projectNum+"/pan/low/"+ fileName.replace("low/", ""));
+//                continue;
+//            }
+//
+//            //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
+////            if(fileJson.getIntValue("clazz") == 5 && !"s3".equals(ossType)){
+////                map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
+////                        projectNum+ File.separator + fileName);
+////                continue;
+////            }
+//            if(fileJson.getIntValue("clazz") == 5 ){
+//                map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
+//                        projectNum+ File.separator + fileName);
+//                continue;
+//            }
+//
+//            //tiles文件夹,亚马逊瓦片图
+//            if(fileJson.getIntValue("clazz") == 7 ){
+//                if(fileName.contains("/4k_")){
+//                    continue;
+//                }
+//                map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
+//                        projectNum+ File.separator + fileName);
+//                continue;
+//            }
+//
+//            //updown文件复制一份到ecs中并去掉换行符
+//            if(fileJson.getIntValue("clazz") == 10){
+//                String updown = FileUtils.readFile(path + File.separator + "results" +File.separator+ fileName);
+//                JSONObject updownJson = JSONObject.parseObject(updown);
+//                FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + projectNum +
+//                        File.separator + fileName.replace("updown", "mapping"), updownJson.toString());
+//                continue;
+//            }
+//
+//            //video视频文件或封面图
+//            if(fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("cl" +
+//                    "azz") == 12){
+//                map.put(path + File.separator + "results" + File.separator+ fileName,"video/video"+
+//                        projectNum+ File.separator + fileName.replace("videos/", ""));
+//
+//                if(fileName.contains(".mp4")){
+////                    CreateObjUtil.mp4ToFlv(path + File.separator + "results" + File.separator+ fileName,
+////                            path + File.separator + "results" + File.separator+ fileName.replace("mp4", "flv"));
+//
+//                    map.put(path + File.separator + "results" + File.separator+ fileName.replace("mp4", "flv"),"video/video"+
+//                            projectNum+ File.separator + fileName.replace("videos/", "").replace("mp4", "flv"));
+//                }
+//            }
+//
+//            //2048的模型和贴图
+//            if(fileJson.getIntValue("clazz") == 16){
+//                map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
+//                        projectNum+ File.separator + fileName);
+//            }
+//
+//            if(fileJson.getIntValue("clazz") == 18){
+//                map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
+//                        projectNum+ File.separator + fileName);
+//            }
+//        }
+//
+//        CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
+//        CreateObjUtil.convertDamToLzma(path + File.separator + "results");
+//        CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
+//        //有meshfix,表示双模型
+//        if(!"".equals(meshfix)){
+//            CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+meshfix, path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k2.dam");
+//            CreateObjUtil.convertDamToLzma2(path + File.separator + "results");
+//            CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+meshfix, path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k2.dam");
+//            map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam.lzma");
+//            map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam");
+//        }
+//        //8目相机有两个vision.txt因此第二个叫vision2.txt
+//        CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
+//        if(vision2){
+//            CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision2.txt",path + File.separator + "results" +File.separator+"vision2.modeldata");
+//            map.put(path + File.separator + "results" +File.separator+"vision2.modeldata", "images/images"+projectNum+"/"+"vision2.modeldata");
+//        }else {
+//            CreateObjUtil.convertTxtToVisionmodeldataCommon(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
+//        }
+//        log.info("数据转换完成:"+projectNum);
+//
+//        File file = new File(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
+//        while(!file.exists())
+//        {
+//            Thread.sleep(60000);
+//        }
+//
+//        map.put(path + File.separator + "results" +File.separator+"vision.modeldata", "images/images"+projectNum+"/"+"vision.modeldata");
+//        map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
+//        map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
+//
+//        file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
+//        if(!file.exists())
+//        {
+//            file.mkdir();
+//        }
+//        FileUtils.copyFile(path + File.separator + "results" +File.separator+"floor.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floor.json", true);
+//        FileUtils.copyFile(path + File.separator + "results" +File.separator+"floorplan.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floor.json", true);
+//        FileUtils.copyFile(path + File.separator + "results" +File.separator+"floorplan.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floorplan.json", true);
+//        log.info("floor.json路径:"+ path + File.separator + "results" +File.separator+"floor.json");
+//        map.put(path + File.separator + "results" +File.separator+"floor.json","data/data"+projectNum+"/floor.json");
+//        map.put(path + File.separator + "results" +File.separator+"floorplan.json","data/data"+projectNum+"/floor.json");
+////        map.put(path + File.separator + "results" +File.separator+"floorplan_cad.json","data/data"+projectNum+"/house_floor.json");
+//        map.put(path + File.separator + "results" +File.separator+"floorplan_cad.json","data/data"+projectNum+"/floorplan_cad.json");
+//        log.info("准备上传文件到oss:"+projectNum);
+//        return map;
+//    }
+//
+//
+//    public static Map<String,String> computerRebuildVideo(String projectNum, String path) throws Exception{
+//        Map<String,String> map = new HashMap<String,String>();
+//        path = path.replace("//", "/");
+//
+//        log.info("开始建模:"+projectNum);
+//        //构建算法isModel去掉,因此改成空字符串
+//        CreateObjUtil.build3dModel(path, "");
+//        log.info("建模完成转换数据:"+projectNum);
+//
+//        boolean vision2 = false;
+//        //读取upload文件,检验需要上传的文件是否存在
+//        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+//        JSONObject uploadJson = null;
+//        JSONArray array = null;
+//        if(uploadData!=null) {
+//            uploadJson = JSONObject.parseObject(uploadData);
+//            array = uploadJson.getJSONArray("upload");
+//        }
+//
+//        if(array == null){
+//            String instanceId = FileUtils.readFile("/opt/hosts/hosts.txt");
+//            FileUtils.writeFile(path + File.separator + "javaErrorNow.log", instanceId + ":计算错误!");
+//
+//            Thread.sleep(10000L);
+//            FileUtils.writeFile(path + File.separator + "javaError.log", instanceId + ":计算错误!");
+//            throw new Exception("upload.json数据出错");
+//        }
+//
+//        JSONObject fileJson = null;
+//        String fileName = "";
+//        for(int i = 0, len = array.size(); i < len; i++) {
+//            fileJson = array.getJSONObject(i);
+//            fileName = fileJson.getString("file");
+//            //文件不存在抛出异常
+//            if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
+//                throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
+//            }
+//
+//            //video视频文件或封面图
+//            if (fileJson.getIntValue("clazz") == 20) {
+//                if (fileName.contains(".flv")) {
+//                    map.put(path + File.separator + "results" + File.separator + fileName, "video/video" +
+//                            projectNum + File.separator + fileName.replace("videos/", ""));
+//                }
+//
+//                if (fileName.contains(".mp4")) {
+//                    map.put(path + File.separator + "results" + File.separator + fileName, "video/video" +
+//                            projectNum + File.separator + fileName.replace("videos/", ""));
+//                }
+//            }
+//        }
+//
+//        log.info("准备上传文件到oss:"+projectNum);
+//        return map;
+//    }
+
+    /**
+     *  标定算法
+     * @param path
+     * @throws Exception
+     */
+    public static Map<String,String> computerCalibration(String path) throws Exception{
+
+        Map<String,String> map = new HashMap<String,String>();
+
+        log.info("开始标定:" );
+        //构建算法isModel去掉,因此改成空字符串
+        CreateObjUtil.build3dModel(path, "");
+//        CreateObjUtil.build3dModel(unicode, "");
+        log.info("标定完成转换数据:" );
+
+        boolean vision2 = false;
+        //读取upload文件,检验需要上传的文件是否存在
+        String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
+        JSONObject uploadJson = null;
+        JSONArray array = null;
+        if(uploadData!=null) {
+            uploadJson = JSONObject.parseObject(uploadData);
+            array = uploadJson.getJSONArray("upload");
+        }
+        if(array == null){
+            throw new Exception("upload.json数据出错");
+        }
+        JSONObject fileJson = null;
+        String fileName = "";
+        for(int i = 0, len = array.size(); i < len; i++) {
+            fileJson = array.getJSONObject(i);
+            fileName = fileJson.getString("file");
+            //文件不存在抛出异常
+            if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
+                throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
+            }
+
+            if(fileJson.getIntValue("clazz") == 13 || fileJson.getIntValue("clazz") == 14){
+                map.put(path + File.separator + "results" +File.separator+ fileName,
+                        ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") +
+                                File.separator + fileName);
+            }
+        }
+        return map;
+    }
+//
+//    public static void createJson(String path, String splitType, String skyboxType, String dataDescribe,
+//                                  String sceneNum, String dataSource) throws Exception{
+//        JSONObject projectJson = new JSONObject();
+//        projectJson.put("version", "201909231830");
+//        projectJson.put("protocol", "file api 1.4");
+//        projectJson.put("uuid", UUID.randomUUID().toString());
+//        projectJson.put("description", "");
+//        projectJson.put("time", System.currentTimeMillis());
+//        projectJson.put("category", "default");
+//        projectJson.put("tag", null);
+//        projectJson.put("status", null);
+//        projectJson.put("sceneNum", sceneNum);
+//        projectJson.put("dataSource", dataSource);
+//        FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
+//
+//        JSONObject dataJson = new JSONObject();
+//        dataJson.put("split_type", splitType);
+//        dataJson.put("skybox_type", skyboxType);
+//        dataJson.put("extras", null);
+//        FileUtils.writeFile(path + File.separator + "data.json", dataJson.toString());
+//    }
+//
+//    public static void createExtras(String rebuildParam, String hdrParam, String path) throws Exception {
+//
+//        FileUtils.writeFile( path + File.separator + "extras" + File.separator + "videos_hdr_param.json", hdrParam);
+//
+//        FileUtils.writeFile( path + File.separator + "extras" + File.separator + "required_videos.json", rebuildParam);
+//
+//    }
+//
+//    public static void createExtras(String rebuildParam,String path) throws Exception {
+//        FileUtils.writeFile( path + File.separator + "extras" + File.separator + "image-ROI.json", rebuildParam);
+//    }
+
+    /**
+     * 生成标定数据
+     * @param calPath
+     * @param prefix
+     * @throws Exception
+     */
+    public static void createCalibrationData(String calPath, String prefix) throws Exception{
+        File calFile = new File(calPath);
+        if(calFile.exists()){
+            calFile.mkdirs();
+        }
+        //删除results和capture文件夹
+        FileUtils.deleteDirectory(calPath + "/capture");
+        FileUtils.deleteDirectory(calPath + "/results");
+
+//        CreateObjUtil.ossUtilCp(ConstantFilePath.OSS_PREFIX + prefix, calPath + "/capture");
+        for(File oldFile : new File(prefix).listFiles()){
+            FileUtils.copyFile(oldFile.getAbsolutePath(), calPath + "/capture/" + oldFile.getName(), true);
+        }
+        JSONObject dataJson = new JSONObject();
+        dataJson.put("split_type", "SPLIT_V7");
+        dataJson.put("skybox_type", "SKYBOX_V5");
+        FileUtils.writeFile(calPath + "/data.json", dataJson.toString());
+    }
+
+//    public static Map<String, String> getTypeString(String cameraType, String algorithm, String resolution){
+//        Map<String, String> map = new HashMap<>();
+//        String splitType = "";
+//        String skyboxType = "";
+//        String dataDescribe = "";
+//        if(Integer.parseInt(cameraType) >= 4){
+//            if("0".equals(resolution)){
+////            skyboxType = "SKYBOX_V4";  //tiles
+////            skyboxType = "SKYBOX_V6";    //high,low,4k
+//                skyboxType = "SKYBOX_V7";    //high,low,2k
+//            }else {
+//                skyboxType = "SKYBOX_V1";
+//            }
+//            splitType = "SPLIT_V1";
+////            skyboxType = "SKYBOX_V4";  //tiles
+//            dataDescribe = "double spherical";
+//
+//            if(Integer.parseInt(cameraType) == 5 ){
+//                //新双目相机
+////              skyboxType = "SKYBOX_V9";
+//                splitType = "SPLIT_V9";
+//                skyboxType = "SKYBOX_V1";
+//            }
+//            if(Integer.parseInt(cameraType) == 6){
+//                //小红屋新双目相机
+////                    skyboxType = "SKYBOX_V9";
+//                splitType = "SPLIT_V3";
+//                skyboxType = "SKYBOX_V7";
+//            }
+//
+//            if(Integer.parseInt(cameraType) == 13){
+//                //转台相机
+//                skyboxType = "SKYBOX_V6";
+//                splitType = "SPLIT_V12";
+//            }
+//
+//            if(Integer.parseInt(cameraType) == 14){
+//                //转台相机
+//                log.info("激光转台相机调用算法");
+//                skyboxType = "SKYBOX_V11";
+//                splitType = "SPLIT_V14";
+//            }
+//
+//        }else {
+//            if("sfm".equals(algorithm)){
+//                splitType = "SPLIT_V2";
+//                skyboxType = "SKYBOX_V1";
+//                dataDescribe = "old sfm";
+//            }else {
+//                splitType = "SPLIT_V3";
+//                skyboxType = "SKYBOX_V1";
+//                dataDescribe = "old slam";
+//            }
+//        }
+//        map.put("splitType", splitType);
+//        map.put("skyboxType", skyboxType);
+//        map.put("dataDescribe", dataDescribe);
+//        return map;
+//    }
+//
+//    public static SceneEntity createScene(String projectNum, Long cameraId, String cameraName, String phoneId, String scenepsd,
+//                                          String unicode, Long cameraType, String fileId, String prefix,
+//                                          String imgsName, String pic, String isModel, Long userId, String userName,
+//                                          String algorithm, Integer sceneShootCount, String sceneName,
+//                                          String sceneDec, Integer sceneType, String gps, ISceneService sceneService,
+//                                          Integer type, ModelingMsgProducer producer, String url, String ecsType,
+//                                          RubberSheetingUtil rubberSheetingUtil)throws Exception{
+//        //先返回链接地址
+//        SceneEntity scene = new SceneEntity();
+//        scene.setWebSite(url+projectNum);
+//        scene.setCameraId(cameraId);
+//        scene.setPhoneId(phoneId);
+//        scene.setNum(String.valueOf(projectNum));
+//        if(scenepsd == null)
+//        {
+//            scenepsd = "";
+//        }
+//        if(!scenepsd.equals(""))
+//        {
+//            scene.setSceneKey(scenepsd);
+//        }
+//
+//        if(!StringUtils.isEmpty(ecsType)){
+//            scene.setEcs(ecsType);
+//        }
+//
+//        String path =  ConstantFilePath.BUILD_MODEL_PATH + unicode;
+//
+//        if(cameraType.longValue() >= 4){
+//            scene.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
+//                    cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator + fileId + File.separator + unicode);
+//        }else {
+//            scene.setDataSource(prefix+imgsName);
+//        }
+//
+//        if(cameraType.longValue() == 14){
+//
+//            scene.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
+//                    cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
+//                    fileId + File.separator + unicode);
+//
+//            log.info("激光相机 dataSource :" + scene.getDataSource());
+//
+//        }
+//
+//
+//        if(pic!=null&&pic.length()>5)
+//        {
+//            scene.setThumb(pic);
+//        }
+//        else
+//        {
+//            scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
+//        }
+//
+//        String parametr = "";
+//        parametr+=unicode+":;"+path+":;"+prefix+":;"+imgsName+":;"+projectNum+":;"+isModel;
+//        if(userName!=null&&!userName.trim().equals(""))
+//        {
+//            parametr+=":;"+userName;
+//            scene.setUserId(userId);
+//        }
+//        else
+//        {
+//            parametr+=":;noMan";
+//        }
+//        parametr+=":;"+cameraType;
+//        parametr+=":;"+algorithm;
+//        parametr += ":;" + fileId;
+//        parametr += ":;" + cameraName;
+//        parametr += ":;1";
+//        log.info("大场景添加到队列:"+parametr);
+//        producer.sendMsg(parametr);
+//
+//        if(sceneShootCount == null)
+//        {
+//            scene.setShootCount(0);
+//        }
+//        else
+//        {
+//            scene.setShootCount(sceneShootCount);
+//        }
+//        if(sceneName!=null)
+//        {
+//            scene.setSceneName(sceneName);
+//        }
+//        if(sceneDec!=null)
+//        {
+//            scene.setSceneDec("<p>"+sceneDec+"</p>");
+//        }
+//
+//        if(sceneType!=null)
+//        {
+//            scene.setSceneType(sceneType);
+//        }
+//
+//        if(gps!=null&&!gps.trim().equals(""))
+//        {
+//            scene.setGps(gps);
+//        }
+//
+//        scene.setSceneScheme(cameraType.intValue());
+//        scene.setAlgorithm(algorithm);
+//        log.info("场景记录添加到数据库:"+projectNum);
+//        if(type == 0){
+//            sceneService.save(scene);
+//        }
+//
+//        JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
+//        scenejson.put("thumbImg", 0);
+//        scenejson.put("version", 0);
+//        scenejson.put("floorLogo", 0);
+//        if(!scenepsd.equals("")){
+//            scenejson.put("scenePsd", scenepsd);
+//            scenejson.put("public", 1);
+//        }else{
+//            scenejson.put("scenePsd", "");
+//            scenejson.put("public", 0);
+//        }
+//        if(cameraType < 4){
+//            scenejson.put("visions", 1);
+//        }else {
+//            scenejson.put("visions", 2);
+//        }
+//        scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
+//
+//        File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
+//        if(!file.exists()||!file.isDirectory())
+//        {
+//            file.mkdirs();
+//        }
+//        FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
+//
+//        //生成二维码
+//        MatrixToImageWriterUtil.createQRCode(url + projectNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png", null);
+//        MatrixToImageWriterUtil.createQRCode(url + projectNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png", null);
+//        log.info("二维码生成完成");
+//
+//        return scene;
+//    }
+//
+//    public static SceneProEntity createScenePro(String projectNum, Long cameraId, String cameraName, String phoneId, String sceneKey,
+//                                                String unicode, Long cameraType, String fileId, String prefix,
+//                                                String imgsName, String pic, String isModel, Long userId, String userName,
+//                                                String algorithm, Integer sceneShootCount, String sceneName,
+//                                                String sceneDec, Integer sceneType, String gps, ISceneProService sceneProService,
+//                                                ISceneProEditService sceneProEditService, Integer type, ModelingMsgProducer producer,
+//                                                Integer resolution, String firmwareVersion, String url, String buildType, String ossType, String ecsType,
+//                                                ISceneCooperationService sceneCooperationService,
+//                                                ISceneResourceCooperationService sceneResourceCooperationService,
+//                                                ISceneResourceCameraService sceneResourceCameraService, Long cooperationUser,
+//                                                RubberSheetingUtil rubberSheetingUtil)throws Exception{
+//        //先返回链接地址
+//        SceneProEntity scene = new SceneProEntity();
+//        scene.setWebSite(url+projectNum);
+//        scene.setCameraId(cameraId);
+//        scene.setPhoneId(phoneId);
+//        scene.setNum(projectNum);
+//
+//        String path =  ConstantFilePath.BUILD_MODEL_PATH + unicode;
+//
+//        scene.setSceneSource(1);
+//        if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
+//            //场景来源双目相机
+//            scene.setSceneSource(2);
+//            scene.setDataSource(ConstantFilePath.BUILD_MODEL_PATH + unicode);
+//        }else if(cameraType.longValue() == 14){
+//
+//            scene.setDataSource(ConstantFilePath.BUILD_MODEL_LASER_PATH +
+//                    cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
+//                    fileId + File.separator + unicode);
+//            path =  ConstantFilePath.BUILD_MODEL_LASER_PATH + unicode;
+//            log.info("激光相机 dataSource :" + scene.getDataSource());
+//
+//        }else if(cameraType.longValue() >= 3){
+//            scene.setDataSource(ConstantFilePath.BUILD_MODEL_PATH +
+//                    cameraName.replace("4DKKPRO_", "").replace("-fdage", "").toLowerCase() + File.separator +
+//                    fileId + File.separator + unicode);
+//        }else {
+//            scene.setDataSource(prefix+imgsName);
+//        }
+//
+//        if(!StringUtils.isEmpty(ecsType)){
+//            scene.setEcs(ecsType);
+//        }
+//
+//        if(resolution == null || resolution.intValue() == 0){
+//            scene.setSceneScheme(cameraType.intValue());
+//        }else {
+//            scene.setSceneScheme(4);
+//        }
+//
+//        //场景来源双目相机,sceneScheme为4,加载high,low图
+//        if(cameraType.longValue() == 5 || cameraType.longValue() == 6){
+//            scene.setSceneScheme(4);
+//        }
+//
+//        //转台相机用4k图
+//        if(cameraType.longValue() == 13 ){
+//            scene.setSceneSource(3);
+//            scene.setSceneScheme(10);
+//        }
+//
+//        //激光相机
+//        if(cameraType.longValue() == 14 ){
+//            scene.setSceneSource(4);
+//            scene.setSceneScheme(10);
+//        }
+//
+//        //亚马逊s3没有裁剪4k图的api
+////        if("s3".equals(ossType)){
+////            scene.setSceneScheme(3);
+////        }
+//
+//        if(pic!=null&&pic.length()>5)
+//        {
+//            scene.setThumb(pic);
+////            scene.setThumbImg(2);
+//        }
+//        else
+//        {
+//            scene.setThumb(ConstantUrl.DEFAULT_SCENE_PIC);
+//        }
+//        scene.setThumb(scene.getThumb().concat("?t=")+System.currentTimeMillis());
+//        String parametr = getMQMsg(projectNum, cameraName, unicode, cameraType, fileId, prefix, imgsName, isModel,
+//                userName, algorithm, resolution, buildType, path);
+//        if(!ObjectUtils.isEmpty(userName)){
+//            scene.setUserId(userId);
+//        }
+//        scene.setMqMsg(parametr);
+//
+//        if(sceneShootCount == null)
+//        {
+//            scene.setShootCount(0);
+//        }
+//        else
+//        {
+//            scene.setShootCount(sceneShootCount);
+//        }
+//        if(sceneName!=null)
+//        {
+//            scene.setSceneName(sceneName);
+//        }
+//        if(sceneDec!=null)
+//        {
+//            scene.setSceneDec("<p>"+ new String(sceneDec.getBytes("UTF-8"))+"</p>");
+//        }
+//
+//        if(sceneType!=null)
+//        {
+//            scene.setSceneType(sceneType);
+//        }
+//
+//        if(gps!=null&&!gps.trim().equals(""))
+//        {
+//            scene.setGps(gps);
+//        }
+//
+//        scene.setAlgorithm(algorithm);
+//        scene.setFilesName(imgsName);
+//        if(!StringUtils.isEmpty(firmwareVersion)){
+//            scene.setFirmwareVersion(firmwareVersion);
+//        }
+//        scene.setBuildType(buildType);
+//        log.info("场景记录添加到数据库:"+projectNum);
+//        //type=0为新生成场景,其余为重新计算场景
+//
+//        SceneProEditEntity sceneEdit = new SceneProEditEntity();
+//        if(type == 0){
+//            sceneProService.save(scene);
+//
+//            sceneEdit = new SceneProEditEntity();
+//            sceneEdit.setNeedKey(0);
+//
+//            if(sceneKey == null) {
+//                sceneKey = "";
+//            }
+//            sceneEdit.setSceneKey(sceneKey);
+//            if(!sceneKey.equals("")) {
+//                sceneEdit.setNeedKey(1);
+//            }else {
+//                sceneEdit.setNeedKey(0);
+//            }
+//
+//            sceneEdit.setProId(scene.getId());
+//            sceneEdit.setMapVisi(1);
+//            sceneEdit.setTourVisi(1);
+//            sceneEdit.setVrVisi(1);
+//            sceneEdit.setRulerVisi(1);
+//            sceneEdit.setCadImgVisi(1);
+//            sceneEdit.setPanoVisi(1);
+//            sceneEdit.setM2dVisi(1);
+//            sceneEdit.setM3dVisi(1);
+//            sceneEdit.setMeasureVisi(0);
+//            sceneEdit.setFloorLogoSize(100);
+//            sceneEdit.setCreateTime(new Date());
+//            sceneProEditService.save(sceneEdit);
+//
+//            //新增场景时,同时新增场景协作信息
+//            if(cooperationUser != null){
+//                SceneCooperationEntity sceneCooperationEntity = new SceneCooperationEntity();
+//                sceneCooperationEntity.setSceneNum(projectNum);
+//                sceneCooperationEntity.setUserId(cooperationUser);
+//                sceneCooperationService.save(sceneCooperationEntity);
+//
+//                List<SceneResourceCameraEntity> resourceCameraList = sceneResourceCameraService.findListByCameraId(cameraId);
+//
+//                SceneResourceCooperationEntity sceneResourceCooperationEntity = null;
+//                if(resourceCameraList != null && resourceCameraList.size() > 0){
+//                    for (SceneResourceCameraEntity sceneResourceCameraEntity : resourceCameraList) {
+//                        sceneResourceCooperationEntity = new SceneResourceCooperationEntity();
+//                        sceneResourceCooperationEntity.setSceneResourceId(sceneResourceCameraEntity.getSceneResourceId());
+//                        sceneResourceCooperationEntity.setSceneCooperationId(sceneCooperationEntity.getId());
+//                        sceneResourceCooperationService.save(sceneResourceCooperationEntity);
+//                    }
+//                }
+//            }
+//        }else {
+//            SceneProEntity oldScene = sceneProService.findBySceneNum(projectNum);
+//            scene.setId(oldScene.getId());
+//            scene.setStatus(0);
+//            scene.setPayStatus(0);
+//            scene.setRecStatus("A");
+//            scene.setCreateTime(new Date());
+//            scene.setSpace(oldScene.getSpace());
+//            scene.setEcs(oldScene.getEcs());
+//            scene.setViewCount(oldScene.getViewCount());
+//            if(sceneName!=null) {
+//                scene.setSceneName(sceneName);
+//            }
+//            if(sceneType!=null) {
+//                scene.setSceneType(sceneType);
+//            }
+//            sceneProService.updateAll(scene);
+//
+//            SceneProEditEntity oldSceneEdit = sceneProEditService.findByProId(scene.getId());
+//            sceneEdit = new SceneProEditEntity();
+//            sceneEdit.setNeedKey(0);
+//
+//            if(sceneKey == null) {
+//                sceneKey = "";
+//            }
+//            sceneEdit.setSceneKey(sceneKey);
+//            if(!sceneKey.equals("")) {
+//                sceneEdit.setNeedKey(1);
+//            }else {
+//                sceneEdit.setNeedKey(0);
+//            }
+//
+//            sceneEdit.setProId(scene.getId());
+//            sceneEdit.setMapVisi(1);
+//            sceneEdit.setTourVisi(1);
+//            sceneEdit.setVrVisi(1);
+//            sceneEdit.setRulerVisi(1);
+//            sceneEdit.setCadImgVisi(1);
+//            sceneEdit.setPanoVisi(1);
+//            sceneEdit.setM2dVisi(1);
+//            sceneEdit.setM3dVisi(1);
+//            sceneEdit.setMeasureVisi(0);
+//            sceneEdit.setFloorLogoSize(100);
+//            sceneEdit.setUpdateTime(new Date());
+//            sceneEdit.setCreateTime(oldSceneEdit.getCreateTime());
+//            sceneEdit.setRecStatus("A");
+//            sceneEdit.setFloorPublishVer(oldSceneEdit.getFloorEditVer() + 1);
+//            sceneEdit.setFloorEditVer(oldSceneEdit.getFloorEditVer() + 1);
+//            sceneEdit.setVersion(oldSceneEdit.getVersion() + 1);
+//            sceneEdit.setImagesVersion(oldSceneEdit.getImagesVersion() + 1);
+//            sceneEdit.setId(oldSceneEdit.getId());
+//
+//            sceneProEditService.updateAll(sceneEdit);
+//
+//
+//        }
+//
+//        JSONObject scenejson = JSONObject.parseObject(JSONObject.toJSONString(scene));
+//        scenejson.put("thumbImg", 0);
+//        scenejson.put("version", 0);
+//        scenejson.put("floorLogo", 0);
+//        if(!sceneKey.equals("")){
+//            scenejson.put("sceneKey", sceneKey);
+//            scenejson.put("public", 1);
+//        }else{
+//            scenejson.put("sceneKey", "");
+//            scenejson.put("public", 0);
+//        }
+//        if(cameraType.longValue() < 4 || cameraType.longValue() == 5 || cameraType.longValue() == 6){
+//            scenejson.put("visions", 1);
+//        }else {
+//            scenejson.put("visions", 2);
+//        }
+//        scenejson.put("createTime", new DateTime(new Date()).toString("yyyy-MM-dd HH:mm"));
+//
+//        scenejson.put("floorPublishVer", sceneEdit.getFloorPublishVer());
+//        scenejson.put("floorEditVer", sceneEdit.getFloorEditVer());
+//        scenejson.put("entry", null);
+//
+//        if(!StringUtils.isEmpty(sceneEdit.getHotsIds())){
+//            scenejson.put("hots", 1);
+//        }
+//
+//        File file = new File(ConstantFilePath.SCENE_PATH+"data/data"+projectNum);
+//        if(!file.exists()||!file.isDirectory())
+//        {
+//            file.mkdirs();
+//        }
+//        FileUtils.writeFile(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", scenejson.toString());
+////        uploadToOssUtil.upload(ConstantFilePath.SCENE_PATH+"data/data"+projectNum+File.separator+"scene.json", "data/data"+projectNum+File.separator+"scene.json");
+//
+//        //生成二维码
+//        MatrixToImageWriterUtil.createQRCode(url + projectNum, ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+".png", null);
+//        MatrixToImageWriterUtil.createQRCode(url + projectNum + "&lang=en", ConstantFilePath.BASE_PATH + File.separator + "sceneQRcode/"+projectNum+"_en.png", null);
+//        log.info("二维码生成完成");
+//
+//        //当mq排队数大于指定数量时使用弹性升缩
+////        int mqNum = producer.getMessageCount();
+////        log.info("mqNum:" + mqNum);
+////        if(mqNum - Integer.parseInt(baseNum) > 0){
+////            log.info("使用弹性升缩开启一台ECS");
+////            log.info(rubberSheetingUtil.createEcs());
+////        }
+//        return scene;
+//    }
+//
+//    public static String getMQMsg(String projectNum, String cameraName, String unicode, Long cameraType, String fileId,
+//                                   String prefix, String imgsName, String isModel,String userName,
+//                                   String algorithm, Integer resolution, String buildType, String path) {
+//        String parametr = "";
+//        parametr+= unicode +":;"+ path +":;"+ prefix +":;"+ imgsName +":;"+ projectNum +":;"+ isModel;
+//        if(userName !=null&&!userName.trim().equals("")){
+//            parametr+=":;"+ userName;
+//        }else{
+//            parametr+=":;noMan";
+//        }
+//        parametr+=":;"+ cameraType;
+//        parametr+=":;"+ algorithm;
+//        parametr += ":;" + fileId;
+//        parametr += ":;" + cameraName;
+//        if(resolution == null){
+//            parametr += ":;0";
+//        }else {
+//            parametr += ":;" + resolution.intValue();
+//        }
+//
+//        if(buildType != null){
+//            parametr += ":;" + buildType;
+//        }
+//
+//        log.info("pro大场景添加到队列:"+parametr);
+//        return parametr;
+//    }
+}

+ 134 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/FileUpload.java

@@ -0,0 +1,134 @@
+package com.fdkankan.common.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.multipart.MultipartFile;
+
+import java.io.*;
+
+/**
+ * @author MeepoGuan
+ *
+ * <p>Description: 上传问题件</p>
+ *
+ * 2017年4月30日
+ *
+ */
+@Slf4j
+public class FileUpload {
+
+	/**
+	 * @param file 			//文件对象
+	 * @param filePath		//上传路径
+	 * @param fileName		//文件名
+	 * @return  文件名
+	 */
+	public static String fileUp(MultipartFile file, String filePath, String fileName) throws IOException {
+		String extName = ""; // 扩展名格式:
+
+		if (file.getOriginalFilename().lastIndexOf(".") >= 0){
+			extName = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
+		}
+		copyFile(file.getInputStream(), filePath, fileName+extName).replaceAll("-", "");
+
+		return fileName+extName;
+	}
+	
+	/**
+	 * 写文件到当前目录的upload目录中
+	 * 
+	 * @param in
+	 * @param dir
+	 * @param realName
+	 * @throws IOException
+	 */
+	private static String copyFile(InputStream in, String dir, String realName)
+			throws IOException {
+		File file = new File(dir, realName);
+		if (!file.exists()) {
+			if (!file.getParentFile().exists()) {
+				file.getParentFile().mkdirs();
+			}
+			file.createNewFile();
+		}
+        org.apache.commons.io.FileUtils.copyInputStreamToFile(in, file);
+		return realName;
+	}
+
+	/**
+	 * 断点续传
+	 * @param
+     */
+	public static String fileUpAgain(InputStream in, String filePath, String fileName, String realSavePath) throws IOException {
+		try{
+			File realFile = new File(realSavePath +  fileName);
+			File tempFile = new File(filePath + fileName);
+			if(!realFile.getParentFile().exists()){
+				realFile.getParentFile().mkdirs();
+			}
+			if(!tempFile.getParentFile().exists()){
+				tempFile.getParentFile().mkdirs();
+			}
+
+//			InputStream in = file.getInputStream();
+			long needSkipBytes = 0;
+			if (tempFile.exists()) {//续传
+				needSkipBytes = tempFile.length();
+			} else {//第一次传
+				tempFile.createNewFile();
+			}
+			log.info("跳过的字节数为:" + needSkipBytes);
+			in.skip(needSkipBytes);
+			RandomAccessFile tempRandAccessFile = new RandomAccessFile(tempFile, "rw");
+			tempRandAccessFile.seek(needSkipBytes);
+			byte[] buffer = new byte[1024];
+			int len = 0;
+			int count = 0;
+			while ((len = in.read(buffer)) > 0) {
+				tempRandAccessFile.write(buffer);
+				count++;
+			}
+			in.close();
+			tempRandAccessFile.close();
+			realFile.createNewFile();
+			if (fileCopy(tempFile, realFile)) {
+				tempFile.delete();
+			}
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+		return realSavePath + fileName;
+	}
+
+	private static boolean fileCopy(File sourceFile, File targetFile) {
+		boolean success = true;
+		try {
+			FileInputStream in = new FileInputStream(sourceFile);
+			FileOutputStream out = new FileOutputStream(targetFile);
+			byte[] buffer = new byte[1024];
+			int len = 0;
+			while ((len = in.read(buffer)) > 0) {
+				out.write(buffer);
+			}
+			in.close();
+			out.close();
+		} catch (FileNotFoundException e) {
+			success = false;
+		} catch (IOException e) {
+			success = false;
+		}
+		return success;
+	}
+
+
+	public static void main(String[] args) {
+		try{
+			String path = "F:\\桌面\\20190925151119-T.h264";
+			FileInputStream f = new FileInputStream(path);
+			fileUpAgain(f, "G:\\javaProject\\9b918c802c3e40282267a89b5231f9a8_201905101446434643\\videos\\", "test123-T.h264", "G:\\javaProject\\9b918c802c3e40282267a89b5231f9a8_201905101446434643\\capture\\");
+//			copyFile(f, "G:\\javaProject\\zhoushan-system\\zhoushan-system-api\\src\\main\\resources\\static\\head", "test.h264");
+		}catch (Exception e){
+			e.printStackTrace();
+		}
+
+	}
+}

+ 465 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/RSAEncrypt.java

@@ -0,0 +1,465 @@
+package com.fdkankan.common.util;
+
+import org.apache.commons.codec.binary.Base64;
+import org.springframework.util.ResourceUtils;
+import sun.misc.BASE64Decoder;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import java.io.*;
+import java.security.*;
+import java.security.interfaces.RSAPrivateKey;
+import java.security.interfaces.RSAPublicKey;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.PKCS8EncodedKeySpec;
+import java.security.spec.X509EncodedKeySpec;
+
+
+public class RSAEncrypt {
+
+    /**
+     * 字节数据转字符串专用集合
+     */
+    private static final char[] HEX_CHAR = {'0', '1', '2', '3', '4', '5', '6',
+            '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+
+    private static final String PRIVATE_KEY = "classpath:key/private_pkcs8.pem";
+
+    private static final String PUBLIC_KEY = "classpath:key/public.pem";
+    /**
+     * RSA最大解密密文大小
+     */
+    private static final int MAX_DECRYPT_BLOCK = 128;
+    /**
+     * 随机生成密钥对
+     */
+    public static void genKeyPair(String filePath) {
+        // KeyPairGenerator类用于生成公钥和私钥对,基于RSA算法生成对象
+        KeyPairGenerator keyPairGen = null;
+        try {
+            keyPairGen = KeyPairGenerator.getInstance("RSA");
+        } catch (NoSuchAlgorithmException e) {
+            e.printStackTrace();
+        }
+        // 初始化密钥对生成器,密钥大小为96-1024位
+        keyPairGen.initialize(1024, new SecureRandom());
+        // 生成一个密钥对,保存在keyPair中
+        KeyPair keyPair = keyPairGen.generateKeyPair();
+        // 得到私钥
+        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
+        // 得到公钥
+        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
+        try {
+            // 得到公钥字符串
+            Base64 base64 = new Base64();
+            String publicKeyString = new String(base64.encode(publicKey.getEncoded()));
+            // 得到私钥字符串
+            String privateKeyString = new String(base64.encode(privateKey.getEncoded()));
+            // 将密钥对写入到文件
+            FileWriter pubfw = new FileWriter(filePath + PUBLIC_KEY);
+            FileWriter prifw = new FileWriter(filePath + PRIVATE_KEY);
+            BufferedWriter pubbw = new BufferedWriter(pubfw);
+            BufferedWriter pribw = new BufferedWriter(prifw);
+            pubbw.write(publicKeyString);
+            pribw.write(privateKeyString);
+            pubbw.flush();
+            pubbw.close();
+            pubfw.close();
+            pribw.flush();
+            pribw.close();
+            prifw.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 从文件中输入流中加载公钥
+     *
+     * @throws Exception 加载公钥时产生的异常
+     */
+    public static String loadPublicKeyByFile() throws Exception {
+        try {
+            BufferedReader br = new BufferedReader(new FileReader(ResourceUtils.getFile(PUBLIC_KEY)));
+            String readLine = null;
+            StringBuilder sb = new StringBuilder();
+            while ((readLine = br.readLine()) != null) {
+                if (readLine.charAt(0) == '-') {
+                    continue;
+                } else {
+                    sb.append(readLine);
+                    sb.append('\r');
+                }
+            }
+            br.close();
+            return sb.toString();
+        } catch (IOException e) {
+            throw new Exception("公钥数据流读取错误");
+        } catch (NullPointerException e) {
+            throw new Exception("公钥输入流为空");
+        }
+    }
+
+    /**
+     * 从文件中输入流中加载公钥
+     *
+     * @throws Exception 加载公钥时产生的异常
+     */
+    public static String loadPublicKeyByFile(String publicKy) throws Exception {
+        try {
+            BufferedReader br = new BufferedReader(new FileReader(new File(publicKy)));
+            String readLine = null;
+            StringBuilder sb = new StringBuilder();
+            while ((readLine = br.readLine()) != null) {
+                if (readLine.charAt(0) == '-') {
+                    continue;
+                } else {
+                    sb.append(readLine);
+                    sb.append('\r');
+                }
+            }
+            br.close();
+            return sb.toString();
+        } catch (IOException e) {
+            throw new Exception("公钥数据流读取错误");
+        } catch (NullPointerException e) {
+            throw new Exception("公钥输入流为空");
+        }
+    }
+
+    /**
+     * 从字符串中加载公钥
+     *
+     * @param publicKeyStr 公钥数据字符串
+     * @throws Exception 加载公钥时产生的异常
+     */
+    public static RSAPublicKey loadPublicKeyByStr(String publicKeyStr)
+            throws Exception {
+        try {
+            BASE64Decoder base64 = new BASE64Decoder();
+            byte[] buffer = base64.decodeBuffer(publicKeyStr);
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            X509EncodedKeySpec keySpec = new X509EncodedKeySpec(buffer);
+            return (RSAPublicKey) keyFactory.generatePublic(keySpec);
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此算法");
+        } catch (InvalidKeySpecException e) {
+            throw new Exception("公钥非法");
+        } catch (NullPointerException e) {
+            throw new Exception("公钥数据为空");
+        }
+    }
+
+    /**
+     * 从文件中加载私钥
+     *
+     * @return 是否成功
+     * @throws Exception
+     */
+    public static String loadPrivateKeyByFile() throws Exception {
+        try {
+            InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("key/private_pkcs8.pem");
+            StringBuilder builder = new StringBuilder();
+            InputStreamReader reader = new InputStreamReader(inputStream , "UTF-8" );
+            BufferedReader bfReader = new BufferedReader( reader );
+            String tmpContent = null;
+            while ((tmpContent = bfReader.readLine()) != null) {
+                if (tmpContent.charAt(0) == '-') {
+                    continue;
+                } else {
+                    builder.append(tmpContent);
+                    builder.append('\r');
+                }
+            }
+            bfReader.close();
+            return builder.toString();
+//            BufferedReader br = new BufferedReader(new FileReader(ResourceUtils.getFile(PRIVATE_KEY)));
+//            String readLine = null;
+//            StringBuilder sb = new StringBuilder();
+//            while ((readLine = br.readLine()) != null) {
+//                if (readLine.charAt(0) == '-') {
+//                    continue;
+//                } else {
+//                    sb.append(readLine);
+//                    sb.append('\r');
+//                }
+//            }
+//            br.close();
+//            return sb.toString();
+        } catch (IOException e) {
+            throw new Exception("私钥数据读取错误");
+        } catch (NullPointerException e) {
+            throw new Exception("私钥输入流为空");
+        }
+    }
+
+    /**
+     * 从文件中加载私钥
+     *
+     * @return 是否成功
+     * @throws Exception
+     */
+    public static String loadPrivateKeyByFile(String filePath) throws Exception {
+        try {
+            InputStream inputStream = new FileInputStream(filePath);
+            StringBuilder builder = new StringBuilder();
+            InputStreamReader reader = new InputStreamReader(inputStream , "UTF-8" );
+            BufferedReader bfReader = new BufferedReader( reader );
+            String tmpContent = null;
+            while ((tmpContent = bfReader.readLine()) != null) {
+                if (tmpContent.charAt(0) == '-') {
+                    continue;
+                } else {
+                    builder.append(tmpContent);
+                    builder.append('\r');
+                }
+            }
+            bfReader.close();
+            return builder.toString();
+//            BufferedReader br = new BufferedReader(new FileReader(ResourceUtils.getFile(PRIVATE_KEY)));
+//            String readLine = null;
+//            StringBuilder sb = new StringBuilder();
+//            while ((readLine = br.readLine()) != null) {
+//                if (readLine.charAt(0) == '-') {
+//                    continue;
+//                } else {
+//                    sb.append(readLine);
+//                    sb.append('\r');
+//                }
+//            }
+//            br.close();
+//            return sb.toString();
+        } catch (IOException e) {
+            throw new Exception("私钥数据读取错误");
+        } catch (NullPointerException e) {
+            throw new Exception("私钥输入流为空");
+        }
+    }
+
+    public static RSAPrivateKey loadPrivateKeyByStr(String privateKeyStr)
+            throws Exception {
+        try {
+            BASE64Decoder base64Decoder = new BASE64Decoder();
+            byte[] buffer = base64Decoder.decodeBuffer(privateKeyStr);
+            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(buffer);
+            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
+            return (RSAPrivateKey) keyFactory.generatePrivate(keySpec);
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此算法");
+        } catch (InvalidKeySpecException e) {
+            throw new Exception("私钥非法");
+        } catch (NullPointerException e) {
+            throw new Exception("私钥数据为空");
+        }
+    }
+
+    /**
+     * 公钥加密过程
+     *
+     * @param publicKey     公钥
+     * @param plainTextData 明文数据
+     * @return
+     * @throws Exception 加密过程中的异常信息
+     */
+    public static byte[] encrypt(RSAPublicKey publicKey, byte[] plainTextData)
+            throws Exception {
+        if (publicKey == null) {
+            throw new Exception("加密公钥为空, 请设置");
+        }
+        Cipher cipher = null;
+        try {
+            // 使用默认RSA
+            cipher = Cipher.getInstance("RSA");
+            // cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
+            cipher.init(Cipher.ENCRYPT_MODE, publicKey);
+            byte[] output = cipher.doFinal(plainTextData);
+            return output;
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此加密算法");
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+            return null;
+        } catch (InvalidKeyException e) {
+            throw new Exception("加密公钥非法,请检查");
+        } catch (IllegalBlockSizeException e) {
+            throw new Exception("明文长度非法");
+        } catch (BadPaddingException e) {
+            throw new Exception("明文数据已损坏");
+        }
+    }
+
+    /**
+     * 私钥加密过程
+     *
+     * @param privateKey    私钥
+     * @param plainTextData 明文数据
+     * @return
+     * @throws Exception 加密过程中的异常信息
+     */
+    public static byte[] encrypt(RSAPrivateKey privateKey, byte[] plainTextData)
+            throws Exception {
+        if (privateKey == null) {
+            throw new Exception("加密私钥为空, 请设置");
+        }
+        Cipher cipher = null;
+        try {
+            // 使用默认RSA
+            cipher = Cipher.getInstance("RSA");
+            cipher.init(Cipher.ENCRYPT_MODE, privateKey);
+            byte[] output = cipher.doFinal(plainTextData);
+            return output;
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此加密算法");
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+            return null;
+        } catch (InvalidKeyException e) {
+            throw new Exception("加密私钥非法,请检查");
+        } catch (IllegalBlockSizeException e) {
+            throw new Exception("明文长度非法");
+        } catch (BadPaddingException e) {
+            throw new Exception("明文数据已损坏");
+        }
+    }
+
+    /**
+     * 私钥解密过程
+     *
+     * @param privateKey 私钥
+     * @param cipherData 密文数据
+     * @return 明文
+     * @throws Exception 解密过程中的异常信息
+     */
+    public static byte[] decrypt(RSAPrivateKey privateKey, byte[] cipherData)
+            throws Exception {
+        if (privateKey == null) {
+            throw new Exception("解密私钥为空, 请设置");
+        }
+        Cipher cipher = null;
+        try {
+            // 使用默认RSA
+            cipher = Cipher.getInstance("RSA");
+//             cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
+            cipher.init(Cipher.DECRYPT_MODE, privateKey);
+            /*byte[] output = cipher.doFinal(cipherData);
+            return output;*/
+            return getDecrytedData(cipherData, cipher);
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此解密算法");
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+            return null;
+        } catch (InvalidKeyException e) {
+            throw new Exception("解密私钥非法,请检查");
+        } catch (IllegalBlockSizeException e) {
+            throw new Exception("密文长度非法");
+        } catch (BadPaddingException e) {
+            throw new Exception("密文数据已损坏");
+        }
+    }
+
+    /**
+     * 公钥解密过程
+     *
+     * @param publicKey  公钥
+     * @param cipherData 密文数据
+     * @return 明文
+     * @throws Exception 解密过程中的异常信息
+     */
+    public static byte[] decrypt(RSAPublicKey publicKey, byte[] cipherData)
+            throws Exception {
+        if (publicKey == null) {
+            throw new Exception("解密公钥为空, 请设置");
+        }
+        Cipher cipher = null;
+        try {
+            // 使用默认RSA
+            cipher = Cipher.getInstance("RSA");
+            // cipher= Cipher.getInstance("RSA", new BouncyCastleProvider());
+            cipher.init(Cipher.DECRYPT_MODE, publicKey);
+            /*byte[] output = cipher.doFinal(cipherData);
+            return output;*/
+            return getDecrytedData(cipherData, cipher);
+        } catch (NoSuchAlgorithmException e) {
+            throw new Exception("无此解密算法");
+        } catch (NoSuchPaddingException e) {
+            e.printStackTrace();
+            return null;
+        } catch (InvalidKeyException e) {
+            throw new Exception("解密公钥非法,请检查");
+        } catch (IllegalBlockSizeException e) {
+            throw new Exception("密文长度非法");
+        } catch (BadPaddingException e) {
+            throw new Exception("密文数据已损坏");
+        }
+    }
+
+    private static byte[] getDecrytedData(byte[] cipherData, Cipher cipher) throws IllegalBlockSizeException, BadPaddingException, IOException {
+//        int inputLen = cipherData.length;
+////        ByteArrayOutputStream out = new ByteArrayOutputStream();
+////        int offSet = 0;
+////        byte[] cache;
+////        int i = 0;
+////        // 对数据分段解密
+////        while (inputLen - offSet > 0) {
+////            if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
+////                cache = cipher.doFinal(cipherData, offSet, MAX_DECRYPT_BLOCK);
+////            } else {
+////                cache = cipher.doFinal(cipherData, offSet, inputLen - offSet);
+////            }
+////            out.write(cache, 0, cache.length);
+////            i++;
+////            offSet = i * MAX_DECRYPT_BLOCK;
+////        }
+////        byte[] decryptedData = out.toByteArray();
+////        out.close();
+////        return decryptedData;
+        int inputLen = cipherData.length;
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        int offSet = 0;
+
+        for(int i = 0; inputLen - offSet > 0; offSet = i * 256) {
+            byte[] cache;
+            if(inputLen - offSet > 256) {
+                cache = cipher.doFinal(cipherData, offSet, 256);
+            } else {
+                cache = cipher.doFinal(cipherData, offSet, inputLen - offSet);
+            }
+            out.write(cache, 0, cache.length);
+            ++i;
+        }
+
+        byte[] decryptedData = out.toByteArray();
+        out.close();
+        return decryptedData;
+    }
+
+    /**
+     * 字节数据转十六进制字符串
+     *
+     * @param data 输入数据
+     * @return 十六进制内容
+     */
+    public static String byteArrayToString(byte[] data) {
+        StringBuilder stringBuilder = new StringBuilder();
+        for (int i = 0; i < data.length; i++) {
+            // 取出字节的高四位 作为索引得到相应的十六进制标识符 注意无符号右移
+            stringBuilder.append(HEX_CHAR[(data[i] & 0xf0) >>> 4]);
+            // 取出字节的低四位 作为索引得到相应的十六进制标识符
+            stringBuilder.append(HEX_CHAR[(data[i] & 0x0f)]);
+            if (i < data.length - 1) {
+                stringBuilder.append(' ');
+            }
+        }
+        return stringBuilder.toString();
+    }
+
+    public static void main(String[] args) throws Exception {
+
+
+
+    }
+
+}

+ 206 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/RubberSheetingUtil.java

@@ -0,0 +1,206 @@
+package com.fdkankan.common.util;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * Created by Hb_zzZ on 2020/8/25.
+ */
+@Slf4j
+@Component
+public class RubberSheetingUtil {
+
+    @Value("${scaling.group.id}")
+    private String ScalingGroupId;
+
+    @Value("${scaling.rule.ari}")
+    private String ScalingRuleAri;
+
+    private static String AccessKeyId = "LTAI4GKZQBM1zZZZBJK7nGjR";
+
+    private String sign(String action, Map<String, String> parameters) throws Exception{
+        final String HTTP_METHOD = "GET";
+
+        final String ALGORITHM = "HmacSHA1";
+        final String ENCODING = "UTF-8";
+        String keySecret = "bo1ura8KODXASVyZ5fofy0fWFILumz&";
+
+        // 对参数进行排序
+        String[] sortedKeys = parameters.keySet().toArray(new String[]{});
+        Arrays.sort(sortedKeys);
+
+        final String SEPARATOR = "&";
+
+        // 生成stringToSign字符串
+        StringBuilder stringToSign = new StringBuilder();
+        stringToSign.append(HTTP_METHOD).append(SEPARATOR);
+        stringToSign.append(percentEncode("/")).append(SEPARATOR);
+
+        StringBuilder canonicalizedQueryString = new StringBuilder();
+        for(String key : sortedKeys) {
+            // 这里注意对key和value进行编码
+            canonicalizedQueryString.append("&")
+                    .append(percentEncode(key)).append("=")
+                    .append(percentEncode(parameters.get(key)));
+        }
+//        System.out.println("canonicalizedQueryString:" + canonicalizedQueryString.toString());
+
+        // 这里注意对canonicalizedQueryString进行编码
+        stringToSign.append(percentEncode(
+                canonicalizedQueryString.toString().substring(1)));
+//        System.out.println("stringToSign:" + stringToSign.toString());
+
+        Mac mac = Mac.getInstance(ALGORITHM);
+        mac.init(new SecretKeySpec(keySecret.getBytes(ENCODING), ALGORITHM));
+        byte[] signData = mac.doFinal(stringToSign.toString().getBytes(ENCODING));
+
+        String signature = new String(org.apache.commons.codec.binary.Base64.encodeBase64(signData));
+        return signature;
+    }
+
+    private static final String ISO8601_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+    private static String formatIso8601Date(Date date) {
+        SimpleDateFormat df = new SimpleDateFormat(ISO8601_DATE_FORMAT);
+        df.setTimeZone(new SimpleTimeZone(0, "GMT"));
+        return df.format(date);
+    }
+
+    private static final String ENCODING = "UTF-8";
+
+    private static String percentEncode(String value) throws UnsupportedEncodingException {
+        return value != null ? URLEncoder.encode(value, ENCODING).replace("+", "%20").replace("*", "%2A").replace("%7E", "~") : null;
+    }
+
+    public static void main(String[] args) {
+
+        String text = "";
+        for(int i = 0, len = 100; i < len; i ++){
+//            createEcs();
+        }
+//        System.out.println(deleteEcs("i-wz95huv20p8v6csu6q1q"));
+
+//        try{
+//            System.out.println(FileUtils.readFile("C:\\Users\\hisun\\Downloads\\hosts.txt"));
+//            System.out.println(1);
+//        }catch (Exception e){
+//            e.printStackTrace();
+//        }
+    }
+
+    public String createEcs(){
+        try {
+
+            boolean tag = true;
+            Map<String, String> parameters = null;
+            while (tag){
+                parameters = new HashMap<String, String>();
+                // 加入请求参数
+                parameters.put("Action", "ExecuteScalingRule");
+                parameters.put("ScalingRuleAri", ScalingRuleAri);
+                parameters.put("Version", "2014-08-28");
+                parameters.put("AccessKeyId", AccessKeyId);
+                parameters.put("Timestamp", formatIso8601Date(new Date()));
+                parameters.put("SignatureMethod", "HMAC-SHA1");
+                parameters.put("SignatureVersion", "1.0");
+                parameters.put("SignatureNonce", UUID.randomUUID().toString());
+                parameters.put("Format", "JSON");
+
+                String signature = sign("AttachInstances", parameters);
+                System.out.println(signature);
+                if(!signature.contains("+") && !signature.contains("/")){
+                    tag = false;
+                }
+                parameters.put("Signature", signature);
+            }
+
+
+            StringBuffer parameterBuffer = new StringBuffer();
+            if (parameters != null) {
+                Iterator iterator = parameters.keySet().iterator();
+                String key = null;
+                String value = null;
+                while (iterator.hasNext()) {
+                    key = (String) iterator.next();
+                    if (parameters.get(key) != null) {
+                        value = (String) parameters.get(key);
+                    } else {
+                        value = "";
+                    }
+
+                    parameterBuffer.append(key).append("=").append(value);
+                    if (iterator.hasNext()) {
+                        parameterBuffer.append("&");
+                    }
+                }
+            }
+//            System.out.println("POST parameter : " + parameterBuffer.toString());
+            return OkHttpUtils.httpGet("http://ess.aliyuncs.com?" + parameterBuffer.toString());
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return null;
+    }
+
+    public String deleteEcs(String id){
+        try {
+            boolean tag = true;
+            Map<String, String> parameters = null;
+            while (tag){
+                parameters = new HashMap<String, String>();
+                // 加入请求参数
+                parameters.put("Action", "RemoveInstances");
+                parameters.put("InstanceId.1", id);
+                parameters.put("ScalingGroupId", ScalingGroupId);
+                parameters.put("Version", "2014-08-28");
+                parameters.put("AccessKeyId", AccessKeyId);
+                parameters.put("Timestamp", formatIso8601Date(new Date()));
+                parameters.put("SignatureMethod", "HMAC-SHA1");
+                parameters.put("SignatureVersion", "1.0");
+                parameters.put("SignatureNonce", UUID.randomUUID().toString());
+                parameters.put("Format", "JSON");
+
+                String signature = sign("AttachInstances", parameters);
+//            System.out.println(signature);
+                if(!signature.contains("+") && !signature.contains("/")){
+                    tag = false;
+                }
+                parameters.put("Signature", signature);
+            }
+
+            StringBuffer parameterBuffer = new StringBuffer();
+            if (parameters != null) {
+                Iterator iterator = parameters.keySet().iterator();
+                String key = null;
+                String value = null;
+                while (iterator.hasNext()) {
+                    key = (String) iterator.next();
+                    if (parameters.get(key) != null) {
+                        value = (String) parameters.get(key);
+                    } else {
+                        value = "";
+                    }
+
+                    parameterBuffer.append(key).append("=").append(value);
+                    if (iterator.hasNext()) {
+                        parameterBuffer.append("&");
+                    }
+                }
+            }
+//            System.out.println("POST parameter : " + parameterBuffer.toString());
+            return OkHttpUtils.httpGet("http://ess.aliyuncs.com?" + parameterBuffer.toString());
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+}

+ 135 - 0
4dkankan-common/src/main/java/com/fdkankan/common/util/SnowflakeIdGenerator.java

@@ -0,0 +1,135 @@
+package com.fdkankan.common.util;
+
+/**
+ * Twitter_Snowflake<br>
+ * SnowFlake的结构如下(每部分用-分开):<br>
+ * 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
+ * 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0<br>
+ * 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
+ * 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
+ * 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId<br>
+ * 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br>
+ * 加起来刚好64位,为一个Long型。<br>
+ * SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
+ */
+public class SnowflakeIdGenerator {
+
+    // ==============================Fields===========================================
+    /** 开始时间截 (2015-01-01) */
+    private final long twepoch = 1420041600000L;
+
+    /** 机器id所占的位数 */
+    private final long workerIdBits = 5L;
+
+    /** 数据标识id所占的位数 */
+    private final long datacenterIdBits = 5L;
+
+    /** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
+    private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
+
+    /** 支持的最大数据标识id,结果是31 */
+    private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
+
+    /** 序列在id中占的位数 */
+    private final long sequenceBits = 12L;
+
+    /** 机器ID向左移12位 */
+    private final long workerIdShift = sequenceBits;
+
+    /** 数据标识id向左移17位(12+5) */
+    private final long datacenterIdShift = sequenceBits + workerIdBits;
+
+    /** 时间截向左移22位(5+5+12) */
+    private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
+
+    /** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */
+    private final long sequenceMask = -1L ^ (-1L << sequenceBits);
+
+    /** 工作机器ID(0~31) */
+    private long workerId;
+
+    /** 数据中心ID(0~31) */
+    private long datacenterId;
+
+    /** 毫秒内序列(0~4095) */
+    private long sequence = 0L;
+
+    /** 上次生成ID的时间截 */
+    private long lastTimestamp = -1L;
+
+    //==============================Constructors=====================================
+    /**
+     * 构造函数
+     * @param workerId 工作ID (0~31)
+     * @param datacenterId 数据中心ID (0~31)
+     */
+    public SnowflakeIdGenerator(long workerId, long datacenterId) {
+        if (workerId > maxWorkerId || workerId < 0) {
+            throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
+        }
+        if (datacenterId > maxDatacenterId || datacenterId < 0) {
+            throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
+        }
+        this.workerId = workerId;
+        this.datacenterId = datacenterId;
+    }
+
+    // ==============================Methods==========================================
+    /**
+     * 获得下一个ID (该方法是线程安全的)
+     * @return SnowflakeId
+     */
+    public synchronized long nextId() {
+        long timestamp = timeGen();
+
+        //如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
+        if (timestamp < lastTimestamp) {
+            throw new RuntimeException(
+                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
+        }
+
+        //如果是同一时间生成的,则进行毫秒内序列
+        if (lastTimestamp == timestamp) {
+            sequence = (sequence + 1) & sequenceMask;
+            //毫秒内序列溢出
+            if (sequence == 0) {
+                //阻塞到下一个毫秒,获得新的时间戳
+                timestamp = tilNextMillis(lastTimestamp);
+            }
+        }
+        //时间戳改变,毫秒内序列重置
+        else {
+            sequence = 0L;
+        }
+
+        //上次生成ID的时间截
+        lastTimestamp = timestamp;
+
+        //移位并通过或运算拼到一起组成64位的ID
+        return ((timestamp - twepoch) << timestampLeftShift) //
+                | (datacenterId << datacenterIdShift) //
+                | (workerId << workerIdShift) //
+                | sequence;
+    }
+
+    /**
+     * 阻塞到下一个毫秒,直到获得新的时间戳
+     * @param lastTimestamp 上次生成ID的时间截
+     * @return 当前时间戳
+     */
+    protected long tilNextMillis(long lastTimestamp) {
+        long timestamp = timeGen();
+        while (timestamp <= lastTimestamp) {
+            timestamp = timeGen();
+        }
+        return timestamp;
+    }
+
+    /**
+     * 返回以毫秒为单位的当前时间
+     * @return 当前时间(毫秒)
+     */
+    protected long timeGen() {
+        return System.currentTimeMillis();
+    }
+}