Browse Source

Merge remote-tracking branch 'origin/master'

user4 5 năm trước cách đây
mục cha
commit
6b9a920d19

+ 5 - 0
pom.xml

@@ -964,6 +964,11 @@
             <artifactId>smack-sasl-provided</artifactId>
             <version>4.3.0</version>
         </dependency>
+        <dependency>
+            <groupId>com.baidubce</groupId>
+            <artifactId>bce-java-sdk</artifactId>
+            <version>0.10.87</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 121 - 0
src/main/java/com/jeeplus/common/bos/BOSClientUtil.java

@@ -0,0 +1,121 @@
+package com.jeeplus.common.bos;
+
+import com.baidubce.auth.DefaultBceCredentials;
+import com.baidubce.services.bos.BosClient;
+import com.baidubce.services.bos.BosClientConfiguration;
+import com.baidubce.services.bos.model.PutObjectResponse;
+import com.jeeplus.common.config.Global;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+public class BOSClientUtil {
+    private final static String accessKey= Global.getConfig("bos_access_key");
+    private final static String secretKey= Global.getConfig("bos_secret_key");
+    private final static String endpoint= Global.getConfig("bos_endpoint");
+    private final static String bucketName= Global.getConfig("bos_buck_name");
+    private static BosClient bosClient;
+
+    public BOSClientUtil() {
+        BosClientConfiguration config = new BosClientConfiguration();
+        config.setMaxConnections(10);
+        config.setCredentials(new DefaultBceCredentials(accessKey, secretKey));
+        config.setEndpoint(endpoint);
+        bosClient = new BosClient(config);
+    }
+
+    /**
+     * 获取BosClient对象
+     * @return
+     */
+    public static BosClient getBosClient() {
+        BosClientConfiguration config = new BosClientConfiguration();
+        config.setMaxConnections(10);
+        config.setCredentials(new DefaultBceCredentials(accessKey, secretKey));
+        config.setEndpoint(endpoint);
+        return new BosClient(config);
+    }
+
+    /**
+     *百度bos以file形式上传文件(不超过5GB)
+     * @param file
+     * @param objectKey 文件路径/文件名(可以用“/”来创建多层文件夹)
+     * @return
+     */
+    public static PutObjectResponse uploadFileToBos(File file,
+                                                    String objectKey) {
+        return bosClient.putObject(bucketName, objectKey, file);
+    }
+
+    /**
+     *以数据流形式上传Object(不超过5GB)
+     * @param inputStream
+     * @param objectKey 文件路径/文件名(可以用“/”来创建多层文件夹)
+     * @return
+     */
+    public static PutObjectResponse uploadInputStreamToBos(InputStream inputStream,
+                                                           String objectKey) {
+        return bosClient.putObject(bucketName, objectKey, inputStream);
+    }
+
+
+    /**
+     * 删除已经上传的Object
+     *
+     * @param objectKey  文件路径/文件名(可以用“/”来创建多层文件夹)
+     * @return 上传成功后的tag
+     */
+    public static void deleteObject(String objectKey) {
+        bosClient.deleteObject(bucketName, objectKey);
+    }
+
+
+    /**
+     * 获取文件下载URL
+     * @param objectKey           文件夹和文件名
+     * @return 目标文件的下载url
+     */
+    public static String generatePresignedUrl(String objectKey) {
+        URL url = bosClient.generatePresignedUrl(bucketName, objectKey, -1);
+        return url.toString();
+    }
+
+
+    public static String upload(String path,File file){
+        String objectKey = path+file.getName();
+        bosClient.putObject(bucketName, objectKey, file);
+        URL url = bosClient.generatePresignedUrl(bucketName, objectKey, -1);
+        return url.toString();
+    }
+
+    public static String upload(String path,InputStream inputStream){
+        String objectKey = path;
+        bosClient.putObject(bucketName, objectKey, inputStream);
+        URL url = bosClient.generatePresignedUrl(bucketName, objectKey, -1);
+        return url.toString();
+    }
+
+    @Test
+    public void testPut(){
+        File file = new File("E:/bk1.png");
+        String name = file.getName();
+        BOSClientUtil.uploadFileToBos(file,"/test/"+name);
+    }
+
+
+    @Test
+    public void testDel(){
+        BOSClientUtil.deleteObject("/test/1.txt");
+    }
+
+    @Test
+    public void testUrl(){
+        File file = new File("E:/bk1.png");
+        String upload = BOSClientUtil.upload("/text1/", file);
+        System.out.println(upload);
+    }
+
+
+}

+ 1 - 1
src/main/java/com/jeeplus/modules/workstaff/service/WorkStaffBasicInfoService.java

@@ -610,7 +610,7 @@ public class WorkStaffBasicInfoService extends CrudService<WorkStaffBasicInfoDao
             workStaffBasicInfo.setBranchOffice(new Office(branchOffice.getBranchOffice()));
         }
         this.preSave(workStaffBasicInfo, request);
-        this.uploadFile(workStaffBasicInfo);
+//        this.uploadFile(workStaffBasicInfo);
         this.saveAchive(workStaffBasicInfo);
         workStaffBasicInfo.setAchiveId(workStaffBasicInfo.getId());
         int cou = this.saveDetails(workStaffBasicInfo,true);

+ 11 - 0
src/main/java/com/jeeplus/modules/workstaff/web/WorkStaffBasicInfoController.java

@@ -17,6 +17,7 @@ import javax.servlet.http.HttpServletResponse;
 import javax.validation.ConstraintViolationException;
 
 import com.google.common.collect.Maps;
+import com.jeeplus.common.bos.BOSClientUtil;
 import com.jeeplus.common.json.AjaxJson;
 import com.jeeplus.common.oss.OSSClientUtil;
 import com.jeeplus.modules.sys.entity.Area;
@@ -223,6 +224,16 @@ public class WorkStaffBasicInfoController extends BaseController {
 		if (!beanValidator(model, workStaffBasicInfo)){
 			return form(workStaffBasicInfo, model,false);
 		}
+		MultipartFile pictureFile = workStaffBasicInfo.getPictureFile();
+		if(pictureFile != null && pictureFile.getSize()>0){
+			String path = new StringBuilder("/headImg/")
+			.append(workStaffBasicInfo.getName()).append(".png").toString();
+			InputStream inputStream = pictureFile.getInputStream();
+			BOSClientUtil bosClientUtil = new BOSClientUtil();
+			String url = bosClientUtil.upload(path, inputStream);
+            workStaffBasicInfo.setPicture(url);
+		}
+
 		if(!workStaffBasicInfo.getIsNewRecord()){//编辑表单保存
 			WorkStaffBasicInfo t = workStaffBasicInfoService.get(workStaffBasicInfo.getId());//从数据库取出记录的值
 			MyBeanUtils.copyBeanNotNull2Bean(workStaffBasicInfo, t);//将编辑表单中的非NULL值覆盖数据库记录中的值

+ 10 - 4
src/main/resources/jeeplus.properties

@@ -32,10 +32,10 @@ slave.jdbc.password=root
 
 #redis settings
 redis.keyPrefix=jeeplus
-#redis.host=192.168.2.4
-redis.host=127.0.0.1
-#redis.port=6380
-redis.port=6379
+redis.host=192.168.2.4
+#redis.host=127.0.0.1
+redis.port=6380
+#redis.port=6379
 
 #============================#
 #===== System settings ======#
@@ -237,3 +237,9 @@ yy_shcxurl=https://api.yonyoucloud.com/apis/dst/enterpriseTicketQuery/enterprise
 #yy_mhcxurl=https://api.yonyoucloud.com/apis/dst/enterpriseTicketQuery/enterpriseSearchByName?keyword=KEY
 #yy_shcxurl=https://api.yonyoucloud.com/apis/dst/enterpriseTicketQuery/enterpriseTicketInfo?id=ID
 
+#百度BOS
+bos_access_key=9915286aab2949949b489e8ab3f70a09
+bos_secret_key=069036bdb93c4bc59c4995ccc543243e
+bos_endpoint=http://su.bcebos.com
+bos_buck_name=newxgccpm
+

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

@@ -404,7 +404,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)"/>