From 996154fb8fab5468cdfc99efbab606605fb762e1 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 14 七月 2025 17:40:34 +0800
Subject: [PATCH] 前端

---
 server/services/src/main/java/com/doumee/api/common/PublicCloudController.java |   73 ++++++++++++++++++++++++++++++++++++
 1 files changed, 73 insertions(+), 0 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java b/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
index 6a8ff19..c265fb7 100644
--- a/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
+++ b/server/services/src/main/java/com/doumee/api/common/PublicCloudController.java
@@ -14,6 +14,7 @@
 import com.doumee.core.utils.DateUtil;
 import com.doumee.core.utils.FtpUtil;
 import com.doumee.core.utils.azure.AzureBlobUtil;
+import com.doumee.core.utils.huaweiOBS.ObsUtil;
 import com.doumee.core.utils.qiyeweixin.QywxUtil;
 import com.doumee.core.utils.qiyeweixin.model.response.QywxUploadMediaResponse;
 import com.doumee.dao.system.model.SystemDictData;
@@ -66,6 +67,78 @@
                 systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode());
 
     }
+    @ApiOperation(value = "涓婁紶OBS", notes = "涓婁紶OBS", httpMethod = "POST", position = 6)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "folder", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
+            @ApiImplicitParam(name = "file", value = "鏂囦欢澶�", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class),
+    })
+    @PostMapping(value = "/upload", headers = "content-type=multipart/form-data")
+    @ResponseBody
+    public void upload(HttpServletRequest request, HttpServletResponse response, String folder) throws Exception {
+        Date d1 = new Date();
+        log.error("鎬诲緱涓婁紶鏂囦欢鎴愬姛=============寮�濮�========="+DateUtil.getPlusTime2(d1));
+        SystemDictData folderData =  systemDictDataBiz.queryByCode(Constants.FTP,folder);
+        if(Objects.isNull(folderData)||StringUtils.isBlank(folderData.getCode())){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩爣鏂囦欢澶归敊璇�");
+        }
+        folder =folderData.getCode().replace("/", "");
+        String prefixPath = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode();
+        InputStream is = null;
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("text/html;charset=UTF-8");
+        Map<String, Object> context = new HashMap<>();
+        try {
+            CommonsMultipartResolver multipartResovler = new CommonsMultipartResolver();
+            if (multipartResovler.isMultipart(request)) {
+                MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+                Iterator<String> it = multipartRequest.getFileNames();
+                while (it.hasNext()) {
+                    MultipartFile file = multipartRequest.getFile(it.next());
+                    System.out.println(file.getSize());
+                    String originname = file.getOriginalFilename();
+                    is = file.getInputStream();
+                    String endType = ".jpg";
+                    if(originname.indexOf(".")>0){
+                        endType=originname.substring(originname.lastIndexOf("."),originname.length());
+                    }
+                    String date = DateUtil.getNowShortDate();
+                    String fName =  date+"/"+ UUID.randomUUID()+endType;
+                    String fileName = folder+"/"+fName;
+                    boolean r =false;
+                    ObsUtil obsUtil = new ObsUtil( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSID).getCode(),
+                            systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ACCESSKEY).getCode(),
+                            systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_ENDPOINT).getCode());
+                    r = obsUtil.uploadFile( systemDictDataBiz.queryByCode(Constants.HWY_OBS,Constants.HWY_OBS_BUCKET).getCode(),is,fileName);//涓婁紶
+                    if(r){
+                        context.put("success", true);
+                        context.put("code", 200);
+                        context.put("errno",0);
+                        JSONObject fileJSON = new JSONObject();
+//                        fileJSON.put("prefixPath", prefixPath);
+//                        fileJSON.put("folder", folder);
+                        fileJSON.put("url", prefixPath+fileName);
+                        fileJSON.put("imgaddr", fName);
+                        fileJSON.put("imgname", fileName);
+                        fileJSON.put("originname", originname);
+                        context.put("data",fileJSON);
+                        context.put("message","璇锋眰鎴愬姛");
+                        writerJson(response, context);
+                        Date d2= new Date();
+                        log.error("鎬荤殑涓婁紶鏂囦欢鎴愬姛=============缁撴潫========="+DateUtil.getPlusTime2(d2) +"鑰楁椂绉掞細"+( (d2.getTime()-d1.getTime()) /1000));
+                        return;
+                    }
+                }
+            }
+        } catch (Exception e) {
+            log.error("銆愪笂浼燜TP澶辫触銆�======================"+e.getMessage());
+        }
+        context.put("code", 0);
+        context.put("message", "涓婁紶澶辫触");
+        context.put("errno",0);
+        writerJson(response, context);
+        return;
+    }
+
 
     public void uploadFileLocal(HttpServletRequest request,  HttpServletResponse response, String rootPath,String dir) throws Exception {
         response.setCharacterEncoding("UTF-8");

--
Gitblit v1.9.3