浏览代码

配置bucket环境

wuweihao 3 年之前
父节点
当前提交
7c6f386aec

+ 48 - 0
gis_common/src/main/java/com/gis/common/constant/ErrorEnum.java

@@ -0,0 +1,48 @@
+package com.gis.common.constant;
+
+/**
+ * Created by owen on 2022/3/10 0010 14:47
+ */
+public enum ErrorEnum {
+
+    FAILURE_CODE_3001(3001, "缺少必要参数"),
+    FAILURE_CODE_3002(3002, "访问异常!"),
+    FAILURE_CODE_3003(3003, "非法访问!"),
+    FAILURE_CODE_3004(3004, "用户未登录"),
+    FAILURE_CODE_3005(3005, "验证码已过期"),
+    FAILURE_CODE_3006(3006, "验证码错误"),
+    FAILURE_CODE_3007(3007, "昵称已存在"),
+    FAILURE_CODE_3008(3008, "该手机已被注册"),
+    FAILURE_CODE_3009(3009, "两次输入的密码不一致"),
+    FAILURE_CODE_3010(3010, "昵称长度错误"),
+    FAILURE_CODE_3011(3011, "密码需要包含英文大小写、数字,长度8-16字符"),
+    FAILURE_CODE_3012(3012, "昵称包含敏感词"),
+    FAILURE_CODE_3013(3013, "手机号码格式错误"),
+    FAILURE_CODE_3014(3014, "账号或密码不正确"),
+    FAILURE_CODE_3015(3015, "用户不存在"),
+    FAILURE_CODE_3016(3016, "登录失败,账号无权访问"),
+    FAILURE_CODE_3017(3017, "空文件"),
+    FAILURE_CODE_3018(3018, "需要上传或使用的文件不存在"),
+
+    ;
+
+    private Integer code;
+    private String message;
+
+    private ErrorEnum(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public Integer code() {
+        return code;
+    }
+
+    public String message() {
+        return message;
+    }
+
+    public String formatMessage(Object... args){
+        return String.format(message, args);
+    }
+}

+ 40 - 0
gis_common/src/main/java/com/gis/common/exception/BaseRuntimeException.java

@@ -1,5 +1,8 @@
 package com.gis.common.exception;
 
+import cn.hutool.core.util.StrUtil;
+import com.gis.common.constant.ErrorEnum;
+
 public class BaseRuntimeException extends RuntimeException{
 
     private static final long serialVersionUID = -1518945670203783450L;
@@ -8,6 +11,7 @@ public class BaseRuntimeException extends RuntimeException{
 
     public BaseRuntimeException(String msg){
         super(msg);
+        this.code = -1;
         this.msg = msg;
     }
 
@@ -32,4 +36,40 @@ public class BaseRuntimeException extends RuntimeException{
     public void setMsg(String msg) {
         this.msg = msg;
     }
+
+    public static void isNull(Object obj, Integer code, String msg){
+        if (obj == null){
+            throw new BaseRuntimeException(code, msg);
+        }
+    }
+
+    public static void isBlank(Object obj, Integer code, String msg){
+        if (obj == null){
+            throw new BaseRuntimeException(code, msg);
+        }
+
+        if (obj instanceof String || StrUtil.isBlank(obj.toString())){
+            throw new BaseRuntimeException(code, msg);
+        }
+
+    }
+
+    public static void isNull(Object obj, ErrorEnum errorEnum){
+        if (obj == null){
+            throw new BaseRuntimeException(errorEnum.code(), errorEnum.message());
+        }
+    }
+
+    public static void isBlank(Object obj, ErrorEnum errorEnum){
+        Integer code = errorEnum.code();
+        String msg = errorEnum.message();
+        if (obj == null){
+            throw new BaseRuntimeException(code, msg);
+        }
+
+        if (obj instanceof String || StrUtil.isBlank(obj.toString())){
+            throw new BaseRuntimeException(code, msg);
+        }
+
+    }
 }

+ 1 - 1
gis_service/src/main/java/com/gis/service/AliOssService.java

@@ -12,5 +12,5 @@ import java.util.List;
 public interface AliOssService {
 
 
-    Result batchDownload(List<String> code, String bucket, String workId);
+    Result batchDownload(List<String> code, String evn, String workId);
 }

+ 16 - 1
gis_service/src/main/java/com/gis/service/impl/AliOssServiceImpl.java

@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
 import com.gis.common.constant.CmdConstant;
 import com.gis.common.constant.ConfigConstant;
 import com.gis.common.constant.PathConstant;
+import com.gis.common.exception.BaseRuntimeException;
 import com.gis.common.util.CmdUtils;
 import com.gis.common.util.Result;
 import com.gis.common.util.StrUtils;
@@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.io.File;
+import java.util.HashMap;
 import java.util.List;
 
 
@@ -26,10 +28,23 @@ public class AliOssServiceImpl implements AliOssService {
     @Autowired
     ConfigConstant configConstant;
 
+    static final  HashMap<Object, String> bucketMap;
+
+    static {
+        bucketMap = new HashMap<>();
+        bucketMap.put("sit", "oss-xiaoan");
+        bucketMap.put("pro", "4dkankan");
+    }
+
 
     @Override
-    public Result batchDownload(List<String> code, String bucket, String workId) {
+    public Result batchDownload(List<String> code, String evn, String workId) {
         log.info("输入场景码数量: {}", code.size());
+
+        String bucket = bucketMap.get(evn);
+        BaseRuntimeException.isNull(bucket, null, "bucket环境不能为空");
+
+
         String dir ;
         if (StrUtil.isBlank(workId)){
             dir = "720yun_" + StrUtils.getTimeStr();

+ 0 - 2
gis_service/src/main/java/com/gis/service/impl/ConvertServiceImpl.java

@@ -3,12 +3,10 @@ package com.gis.service.impl;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
 import com.gis.common.constant.ConfigConstant;
-import com.gis.common.exception.BaseRuntimeException;
 import com.gis.common.proto.util.ConvertUtils;
 import com.gis.common.proto.util.CreateObjUtil;
 import com.gis.common.util.Result;
 import com.gis.service.ConvertService;
-import lombok.extern.log4j.Log4j2;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;

+ 4 - 8
gis_web/src/main/java/com/gis/web/controller/AliOssController.java

@@ -1,15 +1,11 @@
 package com.gis.web.controller;
 
-import com.gis.common.proto.util.ConvertUtils;
 import com.gis.common.util.Result;
 import com.gis.service.AliOssService;
-import com.gis.service.ConvertService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
-import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -26,11 +22,11 @@ public class AliOssController {
     @Autowired
     AliOssService aliOssService;
 
-    @PostMapping("download/{bucket}")
+    @PostMapping("download/{evn}")
     @ApiOperation(value = "720yun-批量下载场景数据", notes = "批量下载, 场景码以逗号分隔, " +
-            "bucket: oss-xiaoan:全景看看sit, 4dkankan:全景看看pro;  workId:作品id, 用来做目录(允许为空)")
-    public Result batchDownload(@RequestBody List<String> code, @PathVariable String bucket, String workId){
-        return aliOssService.batchDownload(code, bucket, workId);
+            "env: sit,全景看看sit, pro:全景看看pro;  workId:作品id, 用来做目录(允许为空)")
+    public Result batchDownload(@RequestBody List<String> code, @PathVariable String evn, String workId){
+        return aliOssService.batchDownload(code, evn, workId);
     }
 
 

+ 0 - 1
gis_web/src/main/java/com/gis/web/controller/ExceptionController.java

@@ -1,6 +1,5 @@
 package com.gis.web.controller;
 
-import com.gis.common.exception.BaseRuntimeException;
 import com.gis.common.util.Result;
 import lombok.extern.log4j.Log4j2;
 import org.apache.shiro.ShiroException;