From 80ea9d9c1b4474fb3d14622c945c3ddceb860218 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期四, 24 四月 2025 14:17:40 +0800
Subject: [PATCH] 代码初始化

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

diff --git a/server/src/main/java/com/doumee/api/common/PublicCloudController.java b/server/src/main/java/com/doumee/api/common/PublicCloudController.java
index 075c33b..197c8d1 100644
--- a/server/src/main/java/com/doumee/api/common/PublicCloudController.java
+++ b/server/src/main/java/com/doumee/api/common/PublicCloudController.java
@@ -10,9 +10,13 @@
 import com.doumee.core.constants.Constants;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.ApiResponse;
 import com.doumee.core.utils.DateUtil;
 import com.doumee.core.utils.FtpUtil;
 import com.doumee.core.utils.azure.AzureBlobUtil;
+import com.doumee.core.utils.qiyeweixin.QywxUtil;
+import com.doumee.core.utils.qiyeweixin.model.response.QywxUploadMediaResponse;
+import com.doumee.dao.business.dto.WebQwUploadDto;
 import com.doumee.dao.system.model.SystemDictData;
 import com.doumee.service.common.EmailService;
 import io.swagger.annotations.Api;
@@ -56,6 +60,62 @@
     public static FtpUtil ftp  = null;
     public static AzureBlobUtil azureBlobUtil  = null;
 
+    @ApiOperation(value = "娴嬭瘯浼佷笟绱犳潗涓婁紶涓嬭浇")
+    @RequestMapping(method= RequestMethod.POST,value="/testQwImg")
+    @ResponseBody
+    public ApiResponse<Map<String, Object>> testQwImg(  @RequestParam(required = false) String imgurl ) throws Exception {
+        QywxUploadMediaResponse r = QywxUtil.uploadMedia(systemDictDataBiz.queryByCode(Constants.QYWX,Constants.QYWX_TOKEN).getCode(),"image",imgurl);
+        if(r!=null && r.getMedia_id()!=null){
+            String  folder = systemDictDataBiz.queryByCode(Constants.FTP,Constants.WORKORDER_FILE_PATH).getCode();
+            String prefixPath = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode();
+            Map<String, Object> context = new HashMap<>();
+            try {
+                initUploadTool();
+                context.put("success", true);
+                context.put("code", 200);
+                context.put("errno",0);
+                JSONArray jsonArray = new JSONArray();
+                Integer index = Constants.ONE;
+                    //鑾峰緱姣忎竴涓枃浠�
+                    String endType = ".jpg";
+                    String originname = UUID.randomUUID().toString()+endType;
+                    InputStream is = QywxUtil.getMediaInputstream(systemDictDataBiz.queryByCode(Constants.QYWX,Constants.QYWX_TOKEN).getCode(),r.getMedia_id());
+                    if(is == null){
+                        context.put("code", 0);
+                        context.put("message", "涓婁紶澶辫触");
+                        context.put("errno",0);
+                    }else{
+                        String date = DateUtil.getNowShortDate();
+                        String fName = date + "/" + originname;
+                        String fileName = folder + fName;
+                        boolean r1 =false;
+                        if(StringUtils.equals(Constants.uploadType.blob,uploadType)){
+                            r1 = azureBlobUtil.uploadFileWithResponse( fileName,is);//涓婁紶
+                        }else{
+                            r1 = ftp.uploadInputstreamBatch(is, fileName, true,index);
+                        }
+                        if (r1) {
+                            JSONObject fileJSON = new JSONObject();
+                            fileJSON.put("url", prefixPath + fileName);
+                            fileJSON.put("imgaddr", fName);
+                            fileJSON.put("imgname", fileName);
+                            fileJSON.put("originname", originname);
+                            jsonArray.add(fileJSON);
+                        }
+                    }
+                context.put("data",jsonArray);
+            } catch (Exception e) {
+                log.error("銆愪笂浼燜TP澶辫触銆�======================"+e.getMessage());
+                context.put("code", 0);
+                context.put("message", "涓婁紶澶辫触");
+                context.put("errno",0);
+
+            }
+            return ApiResponse.success(context);
+        }
+        return ApiResponse.failed("涓婁紶澶辫触"+r!=null?JSONObject.toJSONString(r):"");
+
+    }
     @ApiOperation(value = "娴嬭瘯閭欢鍙戦��")
     @RequestMapping(method= RequestMethod.POST,value="/testEmail")
     @ResponseBody
@@ -149,6 +209,72 @@
         writerJson(response, context);
         return;
     }
+    @ApiOperation(value = "鎵归噺浠庝紒涓氫复鏃剁礌鏉愬簱涓婁紶鏂囦欢鍒版枃浠舵湇鍔″櫒")
+    @PostMapping(value="/uploadBatchFromWx")
+    @ResponseBody
+    public void uploadBatchFromWx(@RequestBody WebQwUploadDto param, HttpServletResponse response) throws Exception {
+        if(Objects.isNull(param.getFolder()) || param.getMediaIds()==null || param.getMediaIds().size()==0){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        SystemDictData folderData =  systemDictDataBiz.queryByCode(Constants.FTP,param.getFolder());
+        if(Objects.isNull(folderData)||StringUtils.isBlank(folderData.getCode())){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"鐩爣鏂囦欢澶归敊璇�");
+        }
+        String  folder = systemDictDataBiz.queryByCode(Constants.FTP,param.getFolder()).getCode();
+        String prefixPath = systemDictDataBiz.queryByCode(Constants.FTP,Constants.FTP_RESOURCE_PATH).getCode();
+        response.setCharacterEncoding("UTF-8");
+        response.setContentType("text/html;charset=UTF-8");
+        Map<String, Object> context = new HashMap<>();
+        try {
+            initUploadTool();
+            context.put("success", true);
+            context.put("code", 200);
+            context.put("errno",0);
+                JSONArray jsonArray = new JSONArray();
+                    Integer index = Constants.ONE;
+                    for (String media : param.getMediaIds()) {
+                        //鑾峰緱姣忎竴涓枃浠�
+                        String endType = ".jpg";
+                        String originname = UUID.randomUUID().toString()+endType;
+                        InputStream is = QywxUtil.getMediaInputstream(systemDictDataBiz.queryByCode(Constants.QYWX,Constants.QYWX_TOKEN).getCode(),media);
+                        if(is == null){
+                            log.error("浼佷笟寰俊绱犳潗涓嬭浇澶辫触锛�========="+media);
+                            continue;
+                        }
+                        log.error("浼佷笟寰俊绱犳潗涓嬭浇鎴愬姛锛�========="+media);
+                        String date = DateUtil.getNowShortDate();
+                        String fName = date + "/" + originname;
+                        String fileName = folder + fName;
+                        boolean r =false;
+                        if(StringUtils.equals(Constants.uploadType.blob,uploadType)){
+                            r = azureBlobUtil.uploadFileWithResponse( fileName,is);//涓婁紶
+                        }else{
+                            r = ftp.uploadInputstreamBatch(is, fileName, Constants.equalsInteger(index ,param.getMediaIds().size()),index);
+                        }
+                        if (r) {
+                            JSONObject fileJSON = new JSONObject();
+                            fileJSON.put("url", prefixPath + fileName);
+                            fileJSON.put("imgaddr", fName);
+                            fileJSON.put("imgname", fileName);
+                            fileJSON.put("originname", originname);
+                            jsonArray.add(fileJSON);
+                        }
+                        index = index + 1;
+                }
+                context.put("data",jsonArray);
+        } catch (Exception e) {
+            log.error("銆愪笂浼燜TP澶辫触銆�======================"+e.getMessage());
+            context.put("code", 0);
+            context.put("message", "涓婁紶澶辫触");
+            context.put("errno",0);
+            writerJson(response, context);
+            return;
+
+        }
+        writerJson(response, context);
+        return;
+    }
+
     @ApiOperation(value = "鎵归噺涓婁紶鏂囦欢鍒癋TP")
     @RequestMapping(method= RequestMethod.POST,value="/uploadBatchOld")
     @ResponseBody

--
Gitblit v1.9.3