Explorar el Código

Merge remote-tracking branch 'origin/master'

xiewenjie hace 3 años
padre
commit
3fc0b387ae

+ 18 - 2
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ConstantFilePath.java

@@ -13,7 +13,7 @@ public class ConstantFilePath {
     // 场景
     public static final String SCENE_PATH = "/mnt/4Dkankan/scene/";
     // 场景
-    public static final String SCENE_v4_PATH = "/mnt/4Dkankan/scene_v4/";
+    public static final String SCENE_V4_PATH = "/mnt/4Dkankan/scene_v4/";
     // 代理商
     public static final String AGENT_PATH = "/mnt/4Dkankan/agent/";
     //电子发票
@@ -75,7 +75,7 @@ public class ConstantFilePath {
     /**
      * scenejson文件本地路径 V4
      */
-    public static final String SCENE_JSON_V4_PATH = SCENE_v4_PATH + "data/data%s/" + ConstantFileName.SCENE_JSON;
+    public static final String SCENE_JSON_V4_PATH = SCENE_V4_PATH + "data/data%s/" + ConstantFileName.SCENE_JSON;
 
     public static final String MEDIAINFO_PATH_FORMAT = DATABUFFER_FORMAT + ConstantFileName.MEDIA_DATAFILE;
 
@@ -124,6 +124,22 @@ public class ConstantFilePath {
 
     public static final String SCENE_CACHE = SCENE_PATH + "%s/caches/";
 
+    public static final String SCENE_DATA_PATH_V4 = SCENE_V4_PATH + "%S/data/";
+
+    public static final String SCENE_IMAGES_PATH_V4 = SCENE_V4_PATH + "%S/images/";
+
+    public static final String SCENE_VIDEOS_PATH_V4 = SCENE_V4_PATH + "%S/videos/";
+
+    public static final String SCENE_VOICES_PATH_V4 = SCENE_V4_PATH + "%S/voices/";
+
+    public static final String SCENE_USER_PATH_V4 = SCENE_V4_PATH + "%S/user/";
+
+    /**
+     * 文件转换目录
+     */
+    public static final String FILE_CONVERT_PATH = BASE_PATH + "/fileConvert/";
+
+
 
 
     public static void main(String[] args) {

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

@@ -10,6 +10,7 @@ public enum ErrorCode {
 
     HAVE_NO_RIGHT(1001, "无权访问!"),
 
+
     AUTH_FAIL(4000, "鉴权失败!"),
     NON_TOKEN(4001, "无token,请重新登录"),
     TOKEN_ILLEGAL(4002, "token不合法"),
@@ -167,6 +168,12 @@ public enum ErrorCode {
     FAILURE_CODE_7021(7021, "场景升级失败,请稍后重试!"),
 
 
+    FAILURE_CODE_8001(8001, "订单不存在"),
+    FAILURE_CODE_8002(8002, "支付失败"),
+    FAILURE_CODE_8003(8003, "开票金额超过范围"),
+    FAILURE_CODE_8004(8004, "支付方式异常"),
+    FAILURE_CODE_8005(8005, "文件转换失败!"),
+
 
 
 

+ 27 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/InternationalType.java

@@ -0,0 +1,27 @@
+package com.fdkankan.common.constant;
+
+/**
+ * 标识系统部署环境是国内服还是国际服
+ */
+public enum InternationalType {
+
+    CN("cn", "中国"),
+    ABROAD("abroad", "海外");
+
+    private String code;
+    private String message;
+
+    private InternationalType(String code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public String code() {
+        return code;
+    }
+
+    public String message() {
+        return message;
+    }
+
+}

+ 0 - 17
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/OrderConstant.java

@@ -1,17 +0,0 @@
-package com.fdkankan.common.constant;
-
-// 8001-9000 订单状态码
-public class OrderConstant {
-    public static final int FAILURE_CODE_8001 = 8001;
-    public static final String FAILURE_MSG_8001 = "订单不存在";
-
-
-    public static final int FAILURE_CODE_8002 = 8002;
-    public static final String FAILURE_MSG_8002 = "支付失败";
-
-    public static final int FAILURE_CODE_8003 = 8003;
-    public static final String FAILURE_MSG_8003 = "开票金额超过范围";
-
-    public static final int FAILURE_CODE_8004 = 8004;
-    public static final String FAILURE_MSG_8004 = "支付方式异常";
-}

+ 0 - 6
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/ServerCode.java

@@ -9,12 +9,6 @@ public enum ServerCode {
 	FEIGN_REQUEST_FAILD(-4, "跨服务请求失败"),
 	SERVER_CLOSING(-5, "服务正在关闭!"),
 
-	AUTH_FAIL(3000, "鉴权失败!"),
-	NON_TOKEN(3001, "无token,请重新登录"),
-	TOKEN_ILLEGAL(3002, "token不合法"),
-	TOKEN_NOT_FOUND(3003, "用户未登录"),
-
-
 	APP_ID_ILLEGAL(3100, "非法的APP ID");
 
 	private Integer code;

+ 2 - 2
4dkankan-common-utils/src/main/java/com/fdkankan/common/constant/UploadFilePath.java

@@ -35,8 +35,8 @@ public class UploadFilePath {
     /**
      * 场景音频
      */
-    public static final String VOICE_EDIT_PATH =  "scene_edit_data/%s/voice/";
-    public static final String VOICE_VIEW_PATH =  "scene_view_data/%s/voice/";
+    public static final String VOICE_EDIT_PATH =  "scene_edit_data/%s/voices/";
+    public static final String VOICE_VIEW_PATH =  "scene_view_data/%s/voices/";
 
     public static final String SCENE_NUM_PATH = "scene/%s";
     public static final String IMG_CACHES_PATH =  "scene/%s/caches/images/";

+ 96 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/response/Result.java

@@ -0,0 +1,96 @@
+package com.fdkankan.common.response;
+
+import java.io.Serializable;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 通用返回类,此类是V3版本的,v3版本停了后要删除
+ *
+ * @author
+ */
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class Result<T> implements Serializable {
+    private static final long serialVersionUID = -1491499610244557029L;
+    public static final String SUCCESS_MSG = "操作成功";
+    public static int CODE_SUCCESS = 0;
+    public static int CODE_FAILURE = -1;
+    public static String[] NOOP = new String[]{};
+
+    /**
+     * 处理状态:0: 成功, 1: 失败
+     */
+    private int code;
+    /**
+     * 消息
+     */
+    private String msg;
+    /**
+     * 返回数据
+     */
+    private T data;
+    /**
+     * 处理成功,并返回数据
+     *
+     * @param data 数据对象
+     * @return data
+     */
+    public static Result success(Object data) {
+        return new Result(CODE_SUCCESS, SUCCESS_MSG, data);
+    }
+    /**
+     * 处理成功
+     *
+     * @return data
+     */
+    public static Result success() {
+        return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP);
+    }
+    /**
+     * 处理成功
+     *
+     * @param msg 消息
+     * @return data
+     */
+    public static Result success(String msg) {
+        return new Result(CODE_SUCCESS, msg, NOOP);
+    }
+    /**
+     * 处理成功
+     *
+     * @param msg  消息
+     * @param data 数据对象
+     * @return data
+     */
+    public static Result success(String msg, Object data) {
+        return new Result(CODE_SUCCESS, msg, data);
+    }
+    /**
+     * 处理失败,并返回数据(一般为错误信息)
+     *
+     * @param code 错误代码
+     * @param msg  消息
+     * @return data
+     */
+    public static Result failure(int code, String msg) {
+        return new Result(code, msg, NOOP);
+    }
+    /**
+     * 处理失败
+     *
+     * @param msg 消息
+     * @return data
+     */
+    public static Result failure(String msg) {
+        return failure(CODE_FAILURE, msg);
+    }
+
+    @Override
+    public String toString() {
+        return "JsonResult [code=" + code + ", msg=" + msg + ", data="
+                + data + "]";
+    }
+}

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

@@ -120,10 +120,16 @@ public class ComputerUtil {
 
             //updown文件复制一份到ecs中并去掉换行符
             if(fileJson.getIntValue("clazz") == 10){
+                // TODO: 2022/5/6 v3停机后需要删除-----------------------------------------------------------------------start
                 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());
+                // TODO: 2022/5/6 v3停机后需要删除-----------------------------------------------------------------------end
+
+                String mappingOssPath = String.format(UploadFilePath.DATA_EDIT_PATH, projectNum) + fileName.replace("updown", "mapping");
+                map.put(path + File.separator + "results" + File.separator+ fileName, mappingOssPath);
+
                 continue;
             }
 

+ 22 - 1
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/CreateObjUtil.java

@@ -1,6 +1,7 @@
 package com.fdkankan.common.util;
 
 import cn.hutool.core.exceptions.ExceptionUtil;
+import cn.hutool.core.io.FileTypeUtil;
 import com.fdkankan.common.constant.ConstantFileName;
 import com.fdkankan.common.constant.ConstantFilePath;
 import com.fdkankan.common.proto.BigSceneProto;
@@ -231,6 +232,24 @@ public class CreateObjUtil {
 
 	}
 
+	public static void convertDamToLzmaByAbsolutePath(String path)throws Exception
+	{
+		try
+		{
+			String command = "lzma "+ path;
+			log.info("开始转换lzma");
+			callshell(command);
+			log.info("转换lzma完毕");
+		}
+		catch(Exception e)
+		{
+			StringWriter trace=new StringWriter();
+			e.printStackTrace(new PrintWriter(trace));
+			log.error(trace.toString());
+		}
+
+	}
+
 	public static void convertDamToLzma2(String folderName)throws Exception
 	{
 		try
@@ -612,7 +631,9 @@ public class CreateObjUtil {
 	}
 
 	public static void main(String[] args) throws Exception{
-		CreateObjUtil.convertTxtToVisionmodeldata("F:\\visiontest\\KJ-HXMNTDYs1E(2)(1).txt", "F:\\visiontest\\vision.modeldata");
+		CreateObjUtil.convertTxtToVisionmodeldata("F:\\visiontest\\KJ-HXMNTDYs1E_3.txt", "F:\\visiontest\\vision.modeldata");
+//		String type = FileTypeUtil.getType(new File("F:\\visiontest\\KJ-HXMNTDYs1E_3.txt"));
+//		System.out.println(type);
 //		CreateObjUtil.convertTxtToDam("F:\\visiontest\\modeldata.txt", "F:\\visiontest\\dacf7dfa24ae47fab8fcebfe4dc41ab9_50k.dam");
 
 //		String text = "web:web";

+ 80 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/DateExtUtil.java

@@ -1,7 +1,17 @@
 package com.fdkankan.common.util;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
+import java.util.Set;
+import java.util.TimeZone;
+import lombok.SneakyThrows;
 
 public class DateExtUtil {
 
@@ -30,4 +40,74 @@ public class DateExtUtil {
         return gc.getTime();
     }
 
+    @SneakyThrows
+    public static void main(String[] args) {
+//        DateExtUtil.testInstant();
+        DateExtUtil.testTransferBetweenZones();
+
+
+
+
+
+
+
+
+    }
+
+    //同一时刻,不同的时区的时间展现形式不一样,但是时刻一样,也就是时间戳是一样的
+
+    public static void testOldDate(){
+        Date currDate = new Date();
+        //国际统一时间字符串格式  Wed Apr 27 16:17:30 CST 2022    CST (china standar time)
+        System.out.println(currDate.toString());
+        //本地时间字符串格式  2022-4-27 16:17:30
+        System.out.println(currDate.toLocaleString());
+        //国际统一GMT(格林威治标准时间)字符串格式  27 Apr 2022 08:17:30 GMT
+        System.out.println(currDate.toGMTString());
+
+        String[] availableIDs = TimeZone.getAvailableIDs();
+        for (String availableID : availableIDs) {
+            System.out.println(availableID);
+        }
+
+        Date bjDate = new Date();
+        System.out.println("时间戳:" + bjDate.getTime());
+        //得到纽约的时区
+        TimeZone newYorkTimeZone = TimeZone.getTimeZone("America/New_York");
+        DateFormat newYorkDateFormat = new SimpleDateFormat(dateStyle);
+        newYorkDateFormat.setTimeZone(newYorkTimeZone);
+        //纽约时间
+        System.out.println("纽约时间:" + newYorkDateFormat.format(bjDate));
+        //背景时间
+        System.out.println("北京时间:" + new SimpleDateFormat(dateStyle).format(bjDate));
+
+    }
+
+    public static void testInstant(){
+        Instant instant = Instant.ofEpochMilli(new Date().getTime());
+        Date from = Date.from(instant);
+        System.out.println(instant.toEpochMilli());
+        System.out.println(from.getTime());
+        System.out.println(instant);
+        System.out.println(from);
+
+    }
+
+    public static void testTransferBetweenZones(){
+        //获取所有时区的id
+        Set<String> availableZoneIds = ZoneId.getAvailableZoneIds();
+
+        //模拟数据库查询出来的时间
+        Instant fromdb = Instant.now();
+
+        ZonedDateTime sydney = ZonedDateTime.ofInstant(fromdb, ZoneId.of("Australia/Sydney"));
+        ZonedDateTime beijing = ZonedDateTime.ofInstant(fromdb, ZoneId.systemDefault());
+        System.out.println(sydney.format(DateTimeFormatter.ofPattern("dd-MM-yy HH:mm:ss")));
+        System.out.println(beijing.format(DateTimeFormatter.ofPattern(dateStyle)));
+        for (String availableZoneId : availableZoneIds) {
+            System.out.println(availableZoneId);
+        }
+
+    }
+
 }

+ 14 - 59
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/FileUtils.java

@@ -1,5 +1,6 @@
 package com.fdkankan.common.util;
 
+import cn.hutool.core.util.ZipUtil;
 import com.alibaba.fastjson.JSONObject;
 import it.sauronsoftware.jave.*;
 import java.net.MalformedURLException;
@@ -1030,66 +1031,20 @@ public class FileUtils {
     }
 
     public static void main(String[] args) throws Exception {
-//        try{
-//            String path = "H:\\test";
-//            InputStream is = null;
-//            String url = "https://file.api.weixin.qq.com/cgi-bin/media/get?access_token=41_veJ0V1PKdwBerxV6qcgty6opVroUYq5xgGG2uaK2f3PNBZNYttxNkTAHWyMt3AYb7iNn7cvpm87sXQhxBlhd6dBekczYR8-j49Hv85HMIV6HVsaMhjYE0QKtJ1C-HFfmsICMaSuvOBczkro5GDEeACAZWX&media_id=mXE_24SEX4-xfg0vB36KnfnkAHaFla5Fz4app1rgFiZDUtUJv04cQgJTOXHN32mm";
-//            URL urlGet = new URL(url);
-//            HttpURLConnection http = (HttpURLConnection) urlGet
-//                    .openConnection();
-//            http.setRequestMethod("GET"); // 必须是get方式请求
-//            http.setRequestProperty("Content-Type",
-//                    "application/x-www-form-urlencoded");
-//            http.setDoOutput(true);
-//            http.setDoInput(true);
-//            System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
-//            System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
-//            http.connect();
-//            // 获取文件转化为byte流
-//            is = http.getInputStream();
-//            File dic = new File(path);
-//            if(!dic.exists())
-//            {
-//                dic.mkdirs();
-//            }
-//            File voice = new File(path+File.separator+ ConstantFileName.WECHAT_VOICE_NAME+".amr");
-//            if(voice.exists())
-//            {
-//                FileUtils.deleteFile(path+File.separator+ConstantFileName.WECHAT_VOICE_NAME+".amr");
-//            }
-//            FileUtils.saveImageToDisk(null, null, ConstantFileName.WECHAT_VOICE_NAME, path+File.separator, is);
-//            System.out.println("下载完成");
-
-//            FileUtils.zipFile("F:\\test.zip", "F:\\downloads\\v3local");
-
-//            ZipOutputStream out = new ZipOutputStream(new FileOutputStream("F:\\test.zip"));
-//            File file = new File("F:\\test\\aaa\\sdf.jpg");
-//            FileInputStream in = new FileInputStream(file);
-//            FileUtils.zipTest(out, "aaa\\sdf.jpg", in);
-//            out.close();
-//
-//            File file = new File("F:\\test");
-//            List<String> list = FileUtils.list(file);
-//            for (String s : list) {
-//                System.out.println(s);
-//            }
-
-//            byte[] bytesFromUrl = FileUtils.getBytesFromUrl(
-//                "https://4dkankan.oss-cn-shenzhen.aliyuncs.com/"
-//                    + "data/datat-ieXdyGl6Md/mesh/texture1.jpg");
-//            FileOutputStream out = new FileOutputStream(new File("F:\\texture1.jpg"));
-//            out.write(bytesFromUrl);
-
-//            List<String> test = null;
-//            List<String> collect = test.stream().map(t -> {
-//                return t;
-//            }).collect(Collectors.toList());
-
-
-//        }catch (Exception e){
-//            e.printStackTrace();
+
+//        ZipUtil.zip("F:\\test\\images", "F:\\test\\images.zip", false);
+//        FileUtils.zipFile("F:\\test\\images.zip", "F:\\test\\images");
+//        List<String> fileList = FileUtil.getFileList("F:\\test\\images\\");
+//        for (String s : fileList) {
+//            System.out.println(s);
+//        }
+
+//        List<String> keyList = cn.hutool.core.io.FileUtil.("F:\\test\\images\\");
+//        for (String s : keyList) {
+//            System.out.println(s);
 //        }
-        FileUtils.decompress("F:\\test\\KJ-t-VJNe28ZImv_images_展厅全景图.zip", "F:\\test\\aaa");
+
+        cn.hutool.core.io.FileUtil.copy("F:\\test2\\1.txt", "F:\\test1\\1.txt", true);
 
     }
 

+ 24 - 0
4dkankan-common-utils/src/main/java/com/fdkankan/common/util/SceneUtil.java

@@ -1,7 +1,14 @@
 package com.fdkankan.common.util;
 
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ConstantFilePath;
 import java.io.File;
+import java.nio.charset.Charset;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -31,4 +38,21 @@ public class SceneUtil {
         return path;
     }
 
+    /**
+     * 根据vision.txt获取全景图名称列表
+     * @param visionPath
+     * @return
+     */
+    public static List<String> getPanoramaImageList(String visionPath){
+        String visionTxt = FileUtil.readString(visionPath, Charset.forName("UTF-8"));
+        JSONObject visionObject = JSON.parseObject(visionTxt);
+        JSONArray sweepLocations = visionObject.getJSONArray("sweepLocations");
+        List<String> imageList = sweepLocations.parallelStream().map(o -> {
+            JSONObject item = (JSONObject) o;
+            return item.getString("uuid") + ".jpg";
+        }).collect(Collectors.toList());
+        return imageList;
+    }
+
+
 }

+ 2 - 2
4dkankan-utils-db/pom.xml

@@ -11,7 +11,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>4dkankan-utils-db</artifactId>
-
+    <version>2.0.1-SNAPSHOT</version>
     <dependencies>
 
         <dependency>
@@ -51,7 +51,7 @@
         <dependency>
             <groupId>com.alibaba</groupId>
             <artifactId>druid-spring-boot-starter</artifactId>
-            <version>1.1.17</version>
+            <version>1.1.22</version>
         </dependency>
 
 

+ 7 - 0
4dkankan-utils-fyun/pom.xml

@@ -13,6 +13,13 @@
 
 
     <dependencies>
+
+        <dependency>
+            <groupId>com.fdkankan</groupId>
+            <artifactId>4dkankan-common-utils</artifactId>
+            <version>2.0.0-SNAPSHOT</version>
+        </dependency>
+
         <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>

+ 288 - 97
4dkankan-utils-fyun/src/main/java/com/fdkankan/fyun/oss/UploadToOssUtil.java

@@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.util.StrUtil;
 import com.alibaba.fastjson.JSON;
+import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.model.*;
 import com.amazonaws.HttpMethod;
@@ -19,6 +20,7 @@ import com.amazonaws.services.s3.model.PutObjectRequest;
 import com.amazonaws.services.s3.model.S3Object;
 import com.amazonaws.services.s3.model.S3ObjectInputStream;
 import com.amazonaws.services.s3.model.S3ObjectSummary;
+import com.fdkankan.common.util.CreateObjUtil;
 import com.fdkankan.fyun.constant.StorageType;
 import com.qiniu.common.Zone;
 import com.qiniu.storage.Configuration;
@@ -83,6 +85,13 @@ public class UploadToOssUtil {
 	@Value("${local.path:/home/4dkankan}")
 	private String localPath;
 
+	/**
+	 * oss文件上传命令
+	 * 第一个参数是oss路径,要包含bucket名称
+	 * 第二个参数是本地文件路径
+	 */
+	private static final String UPLOAD_SH = "bash /opt/ossutil/upload.sh %s %s";
+
 	//上传的数据是byte[],key是上传后的文件名
 	public void upload(byte[] data,String key1) throws IOException{
 		log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , new String(data, "UTF-8"),key1,type);
@@ -114,6 +123,25 @@ public class UploadToOssUtil {
 				break;
 		}
 	}
+
+	/**
+	 * 通过脚本上传
+	 * @param filePath
+	 * @param key
+	 */
+	public void uploadBySh(String filePath, String key) {
+		String ossPath = this.bucket + "/" + key;
+		try {
+			String command = String.format(UploadToOssUtil.UPLOAD_SH, ossPath, filePath);
+			log.info("开始上传文件, ossPath:{}, srcPath:{}", ossPath, filePath);
+			CreateObjUtil.callshell(command);
+			log.info("上传文件完毕, ossPath:{}, srcPath:{}", ossPath, filePath);
+		} catch(Exception e) {
+			log.error("上传文件失败, ossPath:{}, srcPath:{}", ossPath, filePath);
+			log.error("上传文件失败", e);
+		}
+	}
+
 	public void uploadSdk(String filePath, String key1) {
 		log.info("开始上传文件 源路径:{},目标路径:{},type:{}" , filePath,key1,type);
 		switch (type){
@@ -146,12 +174,16 @@ public class UploadToOssUtil {
 		return 1;
 	}
 
-	public void deleteOss(String key1){
+	public void deleteOss(String objectName){
 		OSSClient ossClient = new OSSClient(point, key, secrey);
 		try {
-			ossClient.deleteObject(bucket, key1);
+			ossClient.deleteObject(bucket, objectName);
 		} catch (Exception e) {
-			e.printStackTrace();
+			log.error("OSS删除文件失败,key=" + objectName);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
+			}
 		}
 	}
 
@@ -168,15 +200,34 @@ public class UploadToOssUtil {
 		}
 	}
 
-	public void uploadOss(byte[] data,String key1){
+	public void uploadOss(byte[] data,String objectName){
 		OSSClient ossClient = new OSSClient(point, key, secrey);
 		try {
-			ossClient.putObject(bucket, key1, new ByteArrayInputStream(data));
+			ossClient.putObject(bucket, objectName, new ByteArrayInputStream(data));
 		} catch (Exception e) {
-			log.error(e.toString()+key1);
+			log.error("oss上传文件失败", e);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
+			}
 		}
 	}
-	public void uploadAws(byte[] data,String key1){
+	public void uploadAws(byte[] data,String objectName){
+		BasicAWSCredentials awsCreds = new BasicAWSCredentials(s3key, s3secrey);
+		AmazonS3 s3 = AmazonS3ClientBuilder.standard()
+			.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
+			.withRegion(Regions.EU_WEST_2)
+			.build();
+		try {
+			com.amazonaws.services.s3.model.ObjectMetadata metadata = new com.amazonaws.services.s3.model.ObjectMetadata();
+			s3.putObject(this.bucket, objectName, new ByteArrayInputStream(data), metadata);
+		}catch (Exception e){
+			log.error("s3上传文件失败", e);
+		}finally {
+			if(s3 != null){
+				s3.shutdown();
+			}
+		}
 	}
 	public void uploadLocal(byte[] data,String key1){
 		InputStream in = new ByteArrayInputStream(data);
@@ -228,6 +279,7 @@ public class UploadToOssUtil {
 			ossClient.shutdown();
 		}
 	}
+
 	public void uploadAws(String filePath, String key1){
 		try{
 			uploadS3File(filePath, key1);
@@ -471,10 +523,10 @@ public class UploadToOssUtil {
 	/**
 	 * 删除单个文件
 	 *
-	 * @param filePath 文件路径[ eg: /head/xxxx.jpg ]
+	 * @param objectName 文件路径[ eg: /head/xxxx.jpg ]
 	 * @return
 	 */
-	public void deleteS3Object(String filePath) {
+	public void deleteS3Object(String objectName) {
 
 		/**
 		 * 创建s3对象
@@ -485,13 +537,18 @@ public class UploadToOssUtil {
 				.withRegion(Regions.EU_WEST_2)
 				.build();
 
-		if (filePath.startsWith("/")) {
-			filePath = filePath.substring(1);
+		if (objectName.startsWith("/")) {
+			objectName = objectName.substring(1);
 		}
 
 		try {
-			s3.deleteObject(s3bucket, filePath);
+			s3.deleteObject(s3bucket, objectName);
 		} catch (Exception e) {
+			log.error("s3删除文件失败,key="+objectName, e);
+		}finally {
+			if(s3 != null){
+				s3.shutdown();
+			}
 		}
 	}
 
@@ -556,32 +613,6 @@ public class UploadToOssUtil {
 		return item;
 	}
 
-	/**
-	 * 下载文件
-	 * @param bucketName	桶名
-	 * @param remoteFileName	文件名
-	 * @param path	下载路径
-	 */
-	public boolean downFromS3(String bucketName, String remoteFileName, String path) {
-		try {
-			/**
-			 * 创建s3对象
-			 */
-			BasicAWSCredentials awsCreds = new BasicAWSCredentials(s3key, s3secrey);
-			AmazonS3 s3 = AmazonS3ClientBuilder.standard()
-					.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
-					.withRegion(Regions.EU_WEST_2)
-					.build();
-
-			GetObjectRequest request  = new GetObjectRequest(bucketName,remoteFileName);
-			s3.getObject(request,new File(path));
-			return true;
-		} catch (Exception ase) {
-			log.error("amazonS3下载文件异常 " + ase.getMessage(), ase);
-		}
-		return false;
-	}
-
 	public List<String> listKeys(String sourcePath){
 		StorageType storageType = StorageType.get(type);
 		switch (storageType){
@@ -602,29 +633,38 @@ public class UploadToOssUtil {
 	public List<String> listKeysFromAli(String sourcePath) {
 		List<String> keyList = new ArrayList<>();
 		OSSClient ossClient = new OSSClient(point, key, secrey);
-		boolean flag = true;
-		String nextMaker = null;
-		ListObjectsRequest listObjectsRequest = new ListObjectsRequest(this.bucket);
-		//指定下一级文件
-		listObjectsRequest.setPrefix(sourcePath);
-		//设置分页的页容量
-		listObjectsRequest.setMaxKeys(200);
-		do
-		{
-			//获取下一页的起始点,它的下一项
-			listObjectsRequest.setMarker(nextMaker);
-			ObjectListing objectListing = ossClient.listObjects(listObjectsRequest);
-			List<OSSObjectSummary> objectSummaries = objectListing.getObjectSummaries();
-			List<String> collect = objectSummaries.stream().map(summary -> {
-				return summary.getKey();
-			}).collect(Collectors.toList());
-			if(CollUtil.isNotEmpty(collect)){
-				keyList.addAll(collect);
+		try {
+			boolean flag = true;
+			String nextMaker = null;
+			ListObjectsRequest listObjectsRequest = new ListObjectsRequest(this.bucket);
+			//指定下一级文件
+			listObjectsRequest.setPrefix(sourcePath);
+			//设置分页的页容量
+			listObjectsRequest.setMaxKeys(200);
+			do
+			{
+				//获取下一页的起始点,它的下一项
+				listObjectsRequest.setMarker(nextMaker);
+				ObjectListing objectListing = ossClient.listObjects(listObjectsRequest);
+				List<OSSObjectSummary> objectSummaries = objectListing.getObjectSummaries();
+				List<String> collect = objectSummaries.stream().map(summary -> {
+					return summary.getKey();
+				}).collect(Collectors.toList());
+				if(CollUtil.isNotEmpty(collect)){
+					keyList.addAll(collect);
+				}
+				nextMaker = objectListing.getNextMarker();
+				//全部执行完后,为false
+				flag = objectListing.isTruncated();
+			} while (flag);
+		}catch (Exception e){
+			log.error("获取文件列表失败,path="+sourcePath, e);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
 			}
-			nextMaker = objectListing.getNextMarker();
-			//全部执行完后,为false
-			flag = objectListing.isTruncated();
-		} while (flag);
+		}
+
 
 		ossClient.shutdown();
 
@@ -644,29 +684,34 @@ public class UploadToOssUtil {
 			.withRegion(Regions.EU_WEST_2)
 			.build();
 
-		boolean flag = true;
-		String nextMaker = null;
-		com.amazonaws.services.s3.model.ListObjectsRequest listObjectsRequest = new com.amazonaws.services.s3.model.ListObjectsRequest();
-		listObjectsRequest.setBucketName(this.bucket);
-		listObjectsRequest.setPrefix(sourcePath);
-		listObjectsRequest.setMaxKeys(200);
-
-		do{
-			listObjectsRequest.setMarker(nextMaker);
-			com.amazonaws.services.s3.model.ObjectListing objectListing = s3.listObjects(listObjectsRequest);
-			List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
-			List<String> collect =objectSummaries.stream().map(summary->{
-				return summary.getKey();
-			}).collect(Collectors.toList());
-			if(CollUtil.isNotEmpty(collect)){
-				keyList.addAll(collect);
+		try {
+			boolean flag = true;
+			String nextMaker = null;
+			com.amazonaws.services.s3.model.ListObjectsRequest listObjectsRequest = new com.amazonaws.services.s3.model.ListObjectsRequest();
+			listObjectsRequest.setBucketName(this.bucket);
+			listObjectsRequest.setPrefix(sourcePath);
+			listObjectsRequest.setMaxKeys(200);
+
+			do{
+				listObjectsRequest.setMarker(nextMaker);
+				com.amazonaws.services.s3.model.ObjectListing objectListing = s3.listObjects(listObjectsRequest);
+				List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
+				List<String> collect =objectSummaries.stream().map(summary->{
+					return summary.getKey();
+				}).collect(Collectors.toList());
+				if(CollUtil.isNotEmpty(collect)){
+					keyList.addAll(collect);
+				}
+				nextMaker = objectListing.getNextMarker();
+				flag = objectListing.isTruncated();
+			}while (flag);
+		}catch (Exception e){
+			log.error("获取文件列表失败,path="+sourcePath, e);
+		}finally {
+			if(s3 != null){
+				s3.shutdown();
 			}
-			nextMaker = objectListing.getNextMarker();
-			flag = objectListing.isTruncated();
-		}while (flag);
-
-		s3.shutdown();
-
+		}
 		return keyList;
 	}
 
@@ -681,7 +726,7 @@ public class UploadToOssUtil {
 
 	/**
 	 * <p>
-	        拷贝
+	        拷贝目录
 	 * </p>
 	 * @author dengsixing
 	 * @date 2022/1/18
@@ -691,14 +736,61 @@ public class UploadToOssUtil {
 	public void copyFiles(String sourcePath, String targetPath) throws IOException {
 		StorageType storageType = StorageType.get(type);
 		switch (storageType){
-			case OSS: this.copyFilesFromAli(sourcePath, targetPath);
-			case AWS: this.copyFilesFromAws(sourcePath, targetPath);
+			case OSS:
+				this.copyFilesFromAli(sourcePath, targetPath);
+				break;
+			case AWS:
+				this.copyFilesFromAws(sourcePath, targetPath);
+				break;
 			case LOCAL: this.copyFilesFromLocal(sourcePath, targetPath);
 		}
 	}
 
 	/**
 	 * <p>
+	 拷贝文件
+	 * </p>
+	 * @author dengsixing
+	 * @date 2022/1/18
+	 * @param sourceKey
+	 * @param targetKey
+	 **/
+	public void copyObject(String sourceKey, String targetKey) throws IOException {
+		StorageType storageType = StorageType.get(type);
+		switch (storageType){
+			case OSS:
+				this.copyObjectFromAli(sourceKey, targetKey);
+				break;
+			case AWS:
+				this.copyObjectFromAws(sourceKey, targetKey);
+				break;
+		}
+	}
+
+	/**
+	 * <p>
+	 拷贝-阿里云
+	 * </p>
+	 * @author dengsixing
+	 * @date 2022/1/18
+	 * @param sourcePath
+	 * @param targetPath
+	 **/
+	public void copyObjectFromAli(String sourcePath, String targetPath) throws IOException {
+
+		// 创建OSSClient实例。
+		OSSClient ossClient = new OSSClient(point, key, secrey);
+		// 复制文件
+		log.info("开始复制:" + sourcePath);
+		ossClient.copyObject(this.bucket, sourcePath, this.bucket, targetPath);
+		log.info("复制成功:" + sourcePath);
+		ossClient.shutdown();
+	}
+
+
+
+	/**
+	 * <p>
 	 拷贝-阿里云
 	 * </p>
 	 * @author dengsixing
@@ -762,6 +854,28 @@ public class UploadToOssUtil {
 
 	/**
 	 * <p>
+	 拷贝-亚马逊
+	 * </p>
+	 * @author dengsixing
+	 * @date 2022/1/18
+	 * @param sourceKey
+	 * @param targetKey
+	 **/
+	public void copyObjectFromAws(String sourceKey, String targetKey){
+			BasicAWSCredentials awsCreds = new BasicAWSCredentials(s3key, s3secrey);
+			AmazonS3 s3 = AmazonS3ClientBuilder.standard()
+				.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
+				.withRegion(Regions.EU_WEST_2)//s3 地区位置
+				.build();
+			// 复制文件
+			log.info("开始复制:" + sourceKey);
+			s3.copyObject(this.bucket, sourceKey, this.bucket, targetKey);
+			log.info("复制成功:" + sourceKey);
+			s3.shutdown();
+	}
+
+	/**
+	 * <p>
 	 拷贝-本地
 	 * </p>
 	 * @author dengsixing
@@ -817,9 +931,12 @@ public class UploadToOssUtil {
 			} catch (IOException e) {
 				log.error("读取scene.json文件流失败", e);
 			}
-			ossClient.shutdown();
 		}catch (Exception e){
-			log.error("oos找不到文件,文件路径:{}", objectName);
+			log.error("s3获取文件内容失败,key="+objectName, e);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
+			}
 		}
 
 		return contentJson.toString();
@@ -834,10 +951,16 @@ public class UploadToOssUtil {
 		//创建oss客户端
 		OSSClient ossClient = new OSSClient(point, key, secrey);
 		// ossObject包含文件所在的存储空间名称、文件名称、文件元信息以及一个输入流。
-		OSSObject ossObject = ossClient.getObject(bucket, objectName);
-		String key = ossObject.getKey();
-		if(StrUtil.isNotEmpty(key))
-			return true;
+		try{
+			boolean exist = ossClient.doesObjectExist(bucket, objectName);
+			return exist;
+		}catch (Exception e){
+			log.error("s4判断是否存在key异常,key=" + objectName, e);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
+			}
+		}
 		return false;
 	}
 
@@ -882,7 +1005,6 @@ public class UploadToOssUtil {
 
 	/**
 	 * 获取文件内容-亚马逊
-	 * @param bucketName
 	 * @param objectName
 	 * @return
 	 */
@@ -893,11 +1015,16 @@ public class UploadToOssUtil {
 			.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
 			.withRegion(Regions.EU_WEST_2)
 			.build();
-		GetObjectRequest request  = new GetObjectRequest(bucket,objectName);
-		S3Object s3Object = s3.getObject(request);
-		String key = s3Object.getKey();
-		if(StrUtil.isNotEmpty(key))
-			return true;
+		try {
+			boolean exist = s3.doesObjectExist(bucket, objectName);
+			return exist;
+		}catch (Exception e){
+			log.error("s4判断是否存在key异常,key=" + objectName, e);
+		}finally {
+			if(s3 != null){
+				s3.shutdown();
+			}
+		}
 		return false;
 	}
 
@@ -928,4 +1055,68 @@ public class UploadToOssUtil {
 		return null;
 	}
 
+	/**
+	 * oss下载文件到本地
+	 * @param objectName
+	 * @param localPath
+	 */
+	public boolean download(String objectName, String localPath){
+		StorageType storageType = StorageType.get(this.type);
+		switch (storageType){
+			case OSS:
+				return this.downFormAli(objectName, localPath);
+			case AWS:
+				return this.downFromS3(objectName, localPath);
+		}
+		return false;
+	}
+
+	/**
+	 * 从阿里云oss下载文件到本地
+	 * @param objectName 云端文件k地址
+	 * @param localPath 本地文件地址
+	 * @return
+	 */
+	public boolean downFormAli(String objectName, String localPath){
+		OSSClient ossClient = new OSSClient(point, key, secrey);
+		try {
+			com.aliyun.oss.model.GetObjectRequest request  = new com.aliyun.oss.model.GetObjectRequest(bucket,objectName);
+			ossClient.getObject(request, new File(localPath));
+			return true;
+		}catch (Exception e){
+			log.error("阿里云oss文件下载失败,key=" + objectName, e);
+		}finally {
+			if(ossClient != null){
+				ossClient.shutdown();
+			}
+		}
+		return false;
+	}
+
+	/**
+	 * 从s3下载文件到本地
+	 * @param objectName 云端文件k地址
+	 * @param localPath 本地文件地址
+	 * @return
+	 */
+	public boolean downFromS3(String objectName, String localPath) {
+		BasicAWSCredentials awsCreds = new BasicAWSCredentials(s3key, s3secrey);
+		AmazonS3 s3 = AmazonS3ClientBuilder.standard()
+			.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
+			.withRegion(Regions.EU_WEST_2)
+			.build();
+		try {
+			GetObjectRequest request  = new GetObjectRequest(this.bucket,objectName);
+			s3.getObject(request,new File(localPath));
+			return true;
+		} catch (Exception e) {
+			log.error("amazonS3下载文件失败,key=" + objectName, e);
+		}finally {
+			if(s3 != null){
+				s3.shutdown();
+			}
+		}
+		return false;
+	}
+
 }

+ 5 - 0
4dkankan-utils-redis/src/main/java/com/fdkankan/redis/constant/RedisKey.java

@@ -114,6 +114,11 @@ public class RedisKey {
      */
     public static final String scene_upgrade_progress_num = "scene:upgrade:progress:num:%s";
 
+    /**
+     * v3版本user类型token
+     */
+    public static final String TOKEN_V3 = "token#%s";
+