FengChaoYu 3 hete
szülő
commit
a2cac75acb

+ 1 - 1
src/main/java/com/gree/mall/manager/controller/common/CommonController.java

@@ -118,7 +118,7 @@ public class CommonController {
             @ApiParam(required = true, value = "附件key") @RequestParam(required = true) String key,
             HttpServletResponse response
     ) throws IOException, RemoteServiceException {
-        String file = commonLogic.getFile(key, response);
+        String file = commonLogic.getFile(key);
         response.sendRedirect(file);
     }
 }

+ 6 - 6
src/main/java/com/gree/mall/manager/helper/ExcelImgHelper.java

@@ -24,7 +24,7 @@ import java.util.*;
 public class ExcelImgHelper {
 
     //导入商品
-    public static  HashMap<String, String> importExcel(MultipartFile file, String uploadFileSuffix,int counts) throws IOException, RemoteServiceException {
+    public static  HashMap<String, String> importExcel(MultipartFile file, String uploadFileSuffix,int counts, OSSUtil ossUtil) throws IOException, RemoteServiceException {
         Workbook workbook = null;
         try {
             if (uploadFileSuffix.equals("xls")) {
@@ -36,7 +36,7 @@ public class ExcelImgHelper {
                 int sheetCount = workbook.getNumberOfSheets();
                 if (sheetCount > 0) {
                     Map<Integer,List<PictureData>> imgsMap = getImgs(file);
-                    HashMap<String, String> imgUrlByXLS = getImgUrlByXLS(imgsMap, counts);
+                    HashMap<String, String> imgUrlByXLS = getImgUrlByXLS(imgsMap, counts, ossUtil);
                     return imgUrlByXLS;
                 }
             }
@@ -50,7 +50,7 @@ public class ExcelImgHelper {
 
 
     //部分代码需要根据导入模板调整
-    public static HashMap<String,String> getImgUrlByXLS(Map<Integer,List<PictureData>> pictures,int counts) throws IOException, RemoteServiceException {
+    public static HashMap<String,String> getImgUrlByXLS(Map<Integer,List<PictureData>> pictures,int counts, OSSUtil ossUtil) throws IOException, RemoteServiceException {
 
         //图片集
         HashMap<String,String> imgMap = new HashMap<>();
@@ -71,12 +71,12 @@ public class ExcelImgHelper {
 
                 //保存路径
                 long currentTime = System.currentTimeMillis();
-                String filePath = OSSUtil.OSS_TYPE_PIC + currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
+                String filePath = ossUtil.getFilePath() + "/" + currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
                 //保存图片到oss
-                if (!OSSUtil.uploadFile(filePath, data)) {
+                if (!ossUtil.uploadFile(filePath, data)) {
                     throw new RemoteServiceException("文件同步oss失败");
                 }
-                ossUrl += OSSUtil.accessUrl + filePath + ",";
+                ossUrl += ossUtil.getAccessUrl2() + filePath + ",";
             }
             if(StringUtils.isNotEmpty(ossUrl)){
                 ossUrl = ossUrl.substring(0,ossUrl.length()-1);

+ 0 - 5
src/main/java/com/gree/mall/manager/logic/admin/AdminCompanyWechatTemplateLogic.java

@@ -48,11 +48,6 @@ public class AdminCompanyWechatTemplateLogic {
      * 更改企业信息和模板信息
      */
     public void updateCompanyWithTemplate(AdminCompanyWechatTemplateUpdateReqDto reqDto){
-
-        if(StringUtils.isEmpty(reqDto.getCompanyWechatId())){
-            throw new RemoteServiceException("企业微信id不能为null");
-        }
-
         final AdminCompanyWechatTemplate wechatTemplate = adminCompanyWechatTemplateService.lambdaQuery()
                 .last("limit 1")
                 .one();

+ 8 - 7
src/main/java/com/gree/mall/manager/logic/common/CommonLogic.java

@@ -30,7 +30,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -72,6 +71,8 @@ public class CommonLogic {
 
     private final AdminDeptWebsitService adminDeptWebsitService;
 
+    private final OSSUtil ossUtil;
+
 
     public AdminUserCom getAdminUser() {
         HttpServletRequest request = ApplicationContextUtils.getHttpServletRequest();
@@ -263,11 +264,11 @@ public class CommonLogic {
         }
 
         try {
-            String filePath = OSSUtil.OSS_TYPE_PIC + currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
-            if (!OSSUtil.uploadFile(filePath, file.getBytes())) {
+            String filePath = ossUtil.getFilePath() + "/" + currentTime + UUID.randomUUID().toString() + "." + uploadFileSuffix;
+            if (!ossUtil.uploadFile(filePath, file.getBytes())) {
                 throw new RemoteServiceException("文件同步oss失败");
             }
-            String ossUrl = OSSUtil.accessUrl + filePath;
+            String ossUrl = ossUtil.getAccessUrl2() + filePath;
 
             CommonFile commonFile = new CommonFile();
             commonFile.setUrl(ossUrl);
@@ -289,8 +290,8 @@ public class CommonLogic {
         return regionService.lambdaQuery().eq(Region::getPid, pid).list();
     }
 
-    public String getFile(String key, HttpServletResponse response) throws IOException {
-        String url = OSSUtil.getUrlWw(key);
+    public String getFile(String key) throws IOException {
+        String url = ossUtil.getUrlWw(key);
         return url;
     }
 
@@ -328,7 +329,7 @@ public class CommonLogic {
     }
 
     public String getFileGet(String key) {
-        String url = OSSUtil.getUrlWw(key, null);
+        String url = ossUtil.getUrlWw(key, null);
         return url;
     }
 

+ 67 - 54
src/main/java/com/gree/mall/manager/utils/oss/OSSUtil.java

@@ -2,102 +2,115 @@ package com.gree.mall.manager.utils.oss;
 
 import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClientBuilder;
-import com.aliyun.oss.common.comm.ResponseMessage;
-import com.aliyun.oss.model.*;
-import com.gree.mall.manager.constant.Constant;
+import com.aliyun.oss.model.GeneratePresignedUrlRequest;
+import com.aliyun.oss.model.PutObjectRequest;
+import com.aliyun.oss.model.PutObjectResult;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.MediaType;
+import org.springframework.stereotype.Service;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 
-
+@Service
 @Slf4j
 public class OSSUtil {
 
+    @Value("${ali.access.key.id}")
+    private String ACCESS_KEY_ID;
+    @Value("${ali.access.key.secert}")
+    private String ACCESS_KEY_SECERT;
+
+    @Value("${ali.oss.bucket.name}")
+    private String OSS_BUCKET_NAME;
+    @Value("${ali.oss.endpoint.ww}")
+    private String OSS_ENDPOINT_WW;
+    @Value("${ali.oss.endpoint}")
+    private String OSS_ENDPOINT;
+    @Value("${spring.profiles.active}")
+    private String active;
+    @Value("${sys.url}")
+    private String sysUrl;
+    @Value("${server.servlet.context-path}")
+    private String servletPath;
+
+    public String getAccessUrl(){
+        return "https://" + OSS_BUCKET_NAME +"."+ OSS_ENDPOINT_WW;
+    }
 
-    // 用户相关文件夹
-    public static final String ALIOSS_BUCKETNAME= "zfire-train";
-    public static final String OSS_TYPE_PIC = "train/pic/";
-    public static final String AliOSSEndPoint = "http://oss-cn-guangzhou.aliyuncs.com";
-    public static final String AliOSSEndPointNohttp = "oss-cn-guangzhou.aliyuncs.com";
-    public static final String accessUrl = "https://zfire-train.oss-cn-guangzhou.aliyuncs.com/";
-//    public static final String OSSAccessKeyID = "LTAI4G3XTLh8G8DiTpXHpWgt";
-//    public static final String OSSAccessKeySecret = "LYe8uf7Lg9WxJ1xejk45qnPFqxXLzN";
+    public String getAccessUrl2(){
+        return sysUrl + servletPath + "/img/get?key=";
+    }
 
-    private static OSS ossClientPri = new OSSClientBuilder().build(AliOSSEndPoint,
-            Constant.Ali.ACCESS_KEY_ID, Constant.Ali.ACCESS_KEY_SECERT);
+    public String getFilePath() {
+        String month = new SimpleDateFormat("yyyy-MM").format(new Date());
+        return month;
+    }
 
-    public static boolean uploadFile(String ossObjectKey, byte[] file) throws IOException {
+    public OSS buildClient(){
+        return new OSSClientBuilder().build(!active.equals("prd") ? OSS_ENDPOINT_WW : OSS_ENDPOINT, ACCESS_KEY_ID, ACCESS_KEY_SECERT);
+    }
 
-        PutObjectResult putObjectResult = null;
-        putObjectResult = ossClientPri.putObject(new PutObjectRequest(ALIOSS_BUCKETNAME, ossObjectKey, new ByteArrayInputStream(file)));
+    /**
+     * 上传到oss
+     *
+     * @param ossObjectKey 附件的唯一路径名称
+     * @param file         附件
+     * @return
+     */
+    public boolean uploadFile(String ossObjectKey, File file) {
+        PutObjectResult putObjectResult = buildClient().putObject(new PutObjectRequest(OSS_BUCKET_NAME, ossObjectKey, file));
         log.info("putObjectResult" + putObjectResult);
-        if (putObjectResult != null) {
-            ResponseMessage responseMessage = putObjectResult.getResponse();
-            if (responseMessage != null) {
-                log.error(responseMessage.getErrorResponseAsString());
-            }
-            return true;
-        }
-
-        return false;
+        return true;
     }
 
-    public static boolean uploadFile(String ossObjectKey,File file) throws IOException {
-        if (file == null) {
-            return false;
-        }
+    public boolean uploadFile(String ossObjectKey, byte[] file) {
+        PutObjectResult putObjectResult = buildClient().putObject(new PutObjectRequest(OSS_BUCKET_NAME, ossObjectKey, new ByteArrayInputStream(file)));
+        log.info("putObjectResult" + putObjectResult);
+        return true;
+    }
 
-        PutObjectResult putObjectResult = ossClientPri.putObject(new PutObjectRequest(ALIOSS_BUCKETNAME, ossObjectKey, new FileInputStream(file)));
+    public boolean uploadFile(String ossObjectKey, ByteArrayInputStream byteArrayInputStream) {
+        PutObjectResult putObjectResult = buildClient().putObject(new PutObjectRequest(OSS_BUCKET_NAME, ossObjectKey, byteArrayInputStream));
         log.info("putObjectResult" + putObjectResult);
-        if (putObjectResult != null) {
-            ResponseMessage responseMessage = putObjectResult.getResponse();
-            if (responseMessage != null) {
-                log.error(responseMessage.getErrorResponseAsString());
-            }
-            return true;
-        }
-        return false;
+        return true;
     }
-    public static String getUrlWw(String key){
-        OSS clientWw = new OSSClientBuilder().build(AliOSSEndPoint,Constant.Ali.ACCESS_KEY_ID, Constant.Ali.ACCESS_KEY_SECERT);
-        // 设置URL过期时间为1小时
-        Date expiration = new Date(new Date().getTime() + 3600 * 1000);
-        GeneratePresignedUrlRequest generatePresignedUrlRequest ;
-        generatePresignedUrlRequest =new GeneratePresignedUrlRequest(ALIOSS_BUCKETNAME, key);
-        generatePresignedUrlRequest.setExpiration(expiration);
-        URL url = clientWw.generatePresignedUrl(generatePresignedUrlRequest);
-        return url.toString();
+
+    public boolean uploadFile(String ossObjectKey, InputStream inputStream) {
+        PutObjectResult putObjectResult = buildClient().putObject(new PutObjectRequest(OSS_BUCKET_NAME, ossObjectKey, inputStream));
+        log.info("putObjectResult" + putObjectResult);
+        return true;
     }
 
+    public String getUrlWw(String key) {
+        return getUrlWw(key, null);
+    }
 
-    public static String getUrlWw(String key, MediaType mediaType) {
+    public String getUrlWw(String key, MediaType mediaType) {
         if (StringUtils.isEmpty(key)) {
             return "";
         }
         // 设置URL过期时间为1小时
         Date expiration = new Date(new Date().getTime() + 3600 * 1000);
-        GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(ALIOSS_BUCKETNAME, key);
+        GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(OSS_BUCKET_NAME, key);
         request.setExpiration(expiration);
         if (mediaType != null) {
             request.setContentType(mediaType.toString());
         }
 
         URL url = new OSSClientBuilder()
-                .build("https://" + AliOSSEndPointNohttp, Constant.Ali.ACCESS_KEY_ID, Constant.Ali.ACCESS_KEY_SECERT)
+                .build("https://" + OSS_ENDPOINT_WW, ACCESS_KEY_ID, ACCESS_KEY_SECERT)
                 .generatePresignedUrl(request);
 
         String resultUrl = url.toString();
 
         return resultUrl;
-
     }
 
 

+ 3 - 6
src/main/java/com/tencent/wework/FinanceClient.java

@@ -1,11 +1,8 @@
 package com.tencent.wework;
 
-import cn.hutool.core.convert.Convert;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
-import com.gree.mall.manager.constant.ChatMessageConstant;
 import com.gree.mall.manager.constant.Constant;
-import com.gree.mall.manager.utils.oss.OSSUtil;
 import com.gree.mall.manager.utils.wecom.RSAUtil;
 import com.tencent.wework.dto.ChatDataDTO;
 import com.tencent.wework.dto.ChatDataResultDTO;
@@ -13,7 +10,6 @@ import com.tencent.wework.dto.ChatMessageDTO;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 import java.io.*;
@@ -229,7 +225,7 @@ public class FinanceClient {
                 if (Finance.IsMediaDataFinish(mediaData) == 1) {
                     Finance.FreeMediaData(mediaData);
                     // TODO: 上传至文件服务,并删除本地文件
-                    OSSUtil.uploadFile(OSSUtil.OSS_TYPE_PIC +fileName,getBytesByFile(FILE_BASE_PATH + "/" + fileName));
+//                    OSSUtil.uploadFile(OSSUtil.OSS_TYPE_PIC +fileName,getBytesByFile(FILE_BASE_PATH + "/" + fileName));
                     boolean flag = false;
                     File file = new File(FILE_BASE_PATH + "/" + fileName);
                     if (file.exists() && file.isFile() && file.delete())
@@ -237,7 +233,8 @@ public class FinanceClient {
                     else
                         flag = false;
 
-                    return OSSUtil.accessUrl+OSSUtil.OSS_TYPE_PIC +fileName;
+//                    return OSSUtil.accessUrl+OSSUtil.OSS_TYPE_PIC +fileName;
+                    return "";
                 } else {
                     indexBuf = Finance.GetOutIndexBuf(mediaData);
                     Finance.FreeMediaData(mediaData);

+ 9 - 12
src/main/resources/bootstrap-dev.properties

@@ -4,6 +4,8 @@
 #spring.cloud.nacos.discovery.server-addr=121.43.111.127:8848
 #spring.cloud.nacos.discovery.namespace=d7b1bacd-5b9f-4d1e-9a20-e6f923a744ba
 
+sys.url=https://jiasm.zfire.top
+
 mybatis-plus.configuration.log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
 #支付回调地址
@@ -91,22 +93,17 @@ spring.redis.lettuce.pool.min-idle=0
 spring.redis.timeout=100000ms
 
 #阿里云key
-ali.accessKeyId=LTAI4G3XTLh8G8DiTpXHpWgt
-ali.accessKeySecret=LYe8uf7Lg9WxJ1xejk45qnPFqxXLzN
-
-
-#corp.id=wwbae17f626bb79a8f
-corp.id=ww62ea04d5c904dc4a
-#corp.members.secret=ZPYLKAKIjWmPLiad1J15P8OiR7vmJX8mOBxQehFfjQQ
-corp.members.secret=NoaUlUOIE5ndQIMF1xppkvf5mNnhxm4E-1ktb4ztluc
-
-corp.agent.id=1000006
-corp.mini.secret=sni3_54CCweAeEgJ4WF6FPnYyrw6tv2Ll8RyJf6Xyck
+ali.access.key.id=LTAI5tDHiEGKuwzNhW2gLPyc
+ali.access.key.secert=NVXSx3Gj7fHv6unGwWgalJh49uMZOI
+ali.oss.bucket.name=zfire-train
+ali.oss.endpoint.ww=oss-cn-shenzhen.aliyuncs.com/
+ali.oss.endpoint=oss-cn-shenzhen-internal.aliyuncs.com/
+ali.oss.type.pic=uploadfile/
+ali.sms.msg.code=SMS_284585310
 
 #延迟消息线程数量
 thread.size = 1
 
-
 #微信
 wechat.appid=wxaddd13c267e81e70
 wechat.mch.id=1602811075

+ 9 - 2
src/main/resources/bootstrap-prd.properties

@@ -4,6 +4,8 @@
 #spring.cloud.nacos.discovery.server-addr=172.18.61.6:8848
 #spring.cloud.nacos.discovery.namespace=80f5fb84-c3f9-4773-a297-204d1f39e23d
 
+sys.url=https://jiasm.zfire.top
+
 #支付回调地址
 wechat.payment.notifyUrl=
 #退款回调地址
@@ -89,8 +91,13 @@ spring.redis.lettuce.pool.min-idle=0
 spring.redis.timeout=100000ms
 
 #阿里云key
-ali.accessKeyId=LTAI4G3XTLh8G8DiTpXHpWgt
-ali.accessKeySecret=LYe8uf7Lg9WxJ1xejk45qnPFqxXLzN
+ali.access.key.id=LTAI5tDHiEGKuwzNhW2gLPyc
+ali.access.key.secert=NVXSx3Gj7fHv6unGwWgalJh49uMZOI
+ali.oss.bucket.name=zfire-train
+ali.oss.endpoint.ww=oss-cn-shenzhen.aliyuncs.com/
+ali.oss.endpoint=oss-cn-shenzhen-internal.aliyuncs.com/
+ali.oss.type.pic=uploadfile/
+ali.sms.msg.code=SMS_284585310
 
 #延迟消息线程数量
 thread.size = 1

+ 9 - 11
src/main/resources/bootstrap-test.properties

@@ -6,6 +6,8 @@
 
 #mybatis-plus.configuration.log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 
+sys.url=https://jiasm.zfire.top
+
 #支付回调地址
 wechat.payment.notifyUrl=
 #退款回调地址
@@ -91,17 +93,13 @@ spring.redis.lettuce.pool.min-idle=0
 spring.redis.timeout=100000ms
 
 #阿里云key
-ali.accessKeyId=LTAI4G3XTLh8G8DiTpXHpWgt
-ali.accessKeySecret=LYe8uf7Lg9WxJ1xejk45qnPFqxXLzN
-
-
-#corp.id=wwbae17f626bb79a8f
-corp.id=ww62ea04d5c904dc4a
-#corp.members.secret=ZPYLKAKIjWmPLiad1J15P8OiR7vmJX8mOBxQehFfjQQ
-corp.members.secret=NoaUlUOIE5ndQIMF1xppkvf5mNnhxm4E-1ktb4ztluc
-
-corp.agent.id=1000006
-corp.mini.secret=sni3_54CCweAeEgJ4WF6FPnYyrw6tv2Ll8RyJf6Xyck
+ali.access.key.id=LTAI5tDHiEGKuwzNhW2gLPyc
+ali.access.key.secert=NVXSx3Gj7fHv6unGwWgalJh49uMZOI
+ali.oss.bucket.name=zfire-train
+ali.oss.endpoint.ww=oss-cn-shenzhen.aliyuncs.com/
+ali.oss.endpoint=oss-cn-shenzhen-internal.aliyuncs.com/
+ali.oss.type.pic=uploadfile/
+ali.sms.msg.code=SMS_284585310
 
 #延迟消息线程数量
 thread.size = 1