Procházet zdrojové kódy

用户头像上传

蔡德晨 před 5 roky
rodič
revize
a8eddd9fe1

+ 54 - 34
src/main/java/com/jeeplus/modules/workstaff/service/WorkStaffEducationService.java

@@ -3,6 +3,8 @@
  */
 package com.jeeplus.modules.workstaff.service;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.text.ParseException;
@@ -14,6 +16,7 @@ import java.util.Map;
 
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.jeeplus.common.bos.BOSClientUtil;
 import com.jeeplus.common.config.Global;
 import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.common.utils.DateUtils;
@@ -111,42 +114,59 @@ public class WorkStaffEducationService extends CrudService<WorkStaffEducationDao
         return flag;
     }
 
-    public String uploadFile(MultipartFile file, String filePath) {
-        if (file != null && !file.isEmpty() &&file.getSize()>0) {
-            String key = "";
-            if (StringUtils.isNotBlank(filePath)) {
-                String aliyunUrl = Global.getAliyunUrl();
-                String aliDownloadUrl = Global.getAliDownloadUrl();
-                String cons = "";
-                if (filePath.contains(aliyunUrl)) {
-                    cons = aliyunUrl;
-                } else if (filePath.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
-                    cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
-                } else {
-                    cons = aliDownloadUrl;
-                }
-                String[] arr = filePath.split(cons + "/");
-                key = arr[1];
-            }
-            try {
-                OSSClientUtil ossUtil1 = new OSSClientUtil();
-                if (StringUtils.isNotBlank(key)) {
-                    ossUtil1.deleteSingleObject(key);
-                }
-            }catch (Exception e){
-                logger.error("oss删除文件失败!");
-            }
-            try {
-                OSSClientUtil ossUtil = new OSSClientUtil();
-                String path = Global.getStaffBasicFilePath()+ DateUtils.formatDate(new Date(),null)+"/";
-                String newName = System.currentTimeMillis()+"-"+file.getOriginalFilename();
-                ossUtil.uploadFile2OSS(file.getInputStream(),path,newName);
-                return  Global.getAliDownloadUrl() + "/" + path + newName;
-            } catch (Exception e) {
-                logger.error("oss上传文件失败!");
+//    public String uploadFile(MultipartFile file, String filePath) {
+//        if (file != null && !file.isEmpty() &&file.getSize()>0) {
+//            String key = "";
+//            if (StringUtils.isNotBlank(filePath)) {
+//                String aliyunUrl = Global.getAliyunUrl();
+//                String aliDownloadUrl = Global.getAliDownloadUrl();
+//                String cons = "";
+//                if (filePath.contains(aliyunUrl)) {
+//                    cons = aliyunUrl;
+//                } else if (filePath.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")) {
+//                    cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
+//                } else {
+//                    cons = aliDownloadUrl;
+//                }
+//                String[] arr = filePath.split(cons + "/");
+//                key = arr[1];
+//            }
+//            try {
+//                OSSClientUtil ossUtil1 = new OSSClientUtil();
+//                if (StringUtils.isNotBlank(key)) {
+//                    ossUtil1.deleteSingleObject(key);
+//                }
+//            }catch (Exception e){
+//                logger.error("oss删除文件失败!");
+//            }
+//            try {
+//                OSSClientUtil ossUtil = new OSSClientUtil();
+//                String path = Global.getStaffBasicFilePath()+ DateUtils.formatDate(new Date(),null)+"/";
+//                String newName = System.currentTimeMillis()+"-"+file.getOriginalFilename();
+//                ossUtil.uploadFile2OSS(file.getInputStream(),path,newName);
+//                return  Global.getAliDownloadUrl() + "/" + path + newName;
+//            } catch (Exception e) {
+//                logger.error("oss上传文件失败!");
+//            }
+//        }
+//        return filePath;
+//    }
+
+    public String uploadFile(MultipartFile file, String filePath){
+	    String date = DateUtils.formatDate(new Date(),"yyMMddHHmm");
+	    try {
+            if (file != null && file.getSize() > 0) {
+                String path = new StringBuilder("/employeeInfo/").append(date)
+                        .append(file.getOriginalFilename()).toString();
+                InputStream inputStream = file.getInputStream();
+                BOSClientUtil bosClientUtil = new BOSClientUtil();
+                String url = bosClientUtil.upload(path, inputStream);
+                return url;
             }
+        }catch (Exception e){
+            logger.error("上传文件失败!");
         }
-        return filePath;
+	    return null;
     }
 
     public void query(WorkStaffBasicInfo workStaffBasicInfo) {

+ 1 - 1
src/main/webapp/webpage/modules/workstaff/workStaffBasicDetailModifyDirectly.jsp

@@ -283,7 +283,7 @@
                                     <c:choose>
                                         <c:when test="${not empty workStaffBasicInfo.picture}">
                                             <span id="this_upload_close_1" class="pic_close glyphicon glyphicon-remove" onclick="this_close_img(1)"></span>
-                                            <img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${workStaffBasicInfo.picture}?x-oss-process=image/resize,w_150,limit_0" onclick="this_upload_image_button(1)"/>
+                                            <img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${workStaffBasicInfo.picture}" onclick="this_upload_image_button(1)"/>
                                         </c:when>
                                         <c:otherwise>
                                             <img alt="_blank" id="this_upload_image_1" class="upload_ico" style="cursor:pointer;"  src="${pageContext.request.contextPath}/static/common/img/pic_add.png" onclick="this_upload_image_button(1)"/>