zouxuan 5 år sedan
förälder
incheckning
b9dcf5821a

+ 1 - 0
edu-im/edu-im-server/src/main/java/com/keao/edu/im/controller/RoomController.java

@@ -63,6 +63,7 @@ public class RoomController{
 
     @RequestMapping(value = "/statusSync")
     public Object statusSync(@RequestBody String body) throws Exception {
+        log.info("statusSyncParam  body: {}",body);
         ChannelStateNotify notify = JSONObject.parseObject(body, ChannelStateNotify.class);
         log.info("statusSyncParam: {}",JSONObject.toJSON(notify));
         roomService.statusSync(notify);

+ 12 - 0
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/storage/StoragePlugin.java

@@ -8,6 +8,18 @@ public interface StoragePlugin {
 	String getName();
 
 	/**
+	 * @describe 设置文件访问为私有或公开
+	 * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
+	 * @author zouxuan
+	 * @date 2020/8/28
+	 * @time 17:35
+	 * @param fileName:
+	 * @param isPublic:
+	 * @return void
+	 */
+	void setFileAcl(String fileName,Boolean isPublic);
+
+	/**
 	 * 上传文件
 	 * @param folderName 文件夹
 	 * @param file 需要上传的文件

+ 6 - 0
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/storage/StoragePluginContext.java

@@ -4,6 +4,7 @@ import java.io.File;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 
 import com.keao.edu.thirdparty.exception.ThirdpartyException;
@@ -25,6 +26,11 @@ public class StoragePluginContext {
 		return StoragePlugin.uploadFile(folderName, file);
 	}
 
+	public void setFileAcl(String storagePluginName,String fileName,Boolean isPublic){
+		StoragePlugin storagePlugin = getStoragePlugin(storagePluginName);
+		storagePlugin.setFileAcl(fileName,isPublic);
+	}
+
 	private StoragePlugin getStoragePlugin(String storagePluginName) {
 		StoragePlugin storagePlugin = mapper.get(storagePluginName);
 

+ 6 - 0
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/storage/provider/AliyunOssStoragePlugin.java

@@ -3,6 +3,7 @@ package com.keao.edu.thirdparty.storage.provider;
 import com.aliyun.oss.ClientConfiguration;
 import com.aliyun.oss.OSSClient;
 import com.aliyun.oss.model.OSSObject;
+import com.google.zxing.client.result.BizcardResultParser;
 import com.keao.edu.thirdparty.exception.ThirdpartyException;
 import com.keao.edu.thirdparty.storage.StoragePlugin;
 import com.keao.edu.thirdparty.storage.StoragePluginContext;
@@ -40,6 +41,11 @@ public class AliyunOssStoragePlugin implements StoragePlugin, InitializingBean,
 	}
 
 	@Override
+	public void setFileAcl(String fileName, Boolean isPublic) {
+		return;
+	}
+
+	@Override
 	public void afterPropertiesSet() throws Exception {
 		// 创建ClientConfiguration。ClientConfiguration是OSSClient的配置类,可配置代理、连接超时、最大连接数等参数。
 		ClientConfiguration conf = new ClientConfiguration();

+ 14 - 0
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/storage/provider/KS3StoragePlugin.java

@@ -3,6 +3,7 @@ package com.keao.edu.thirdparty.storage.provider;
 import java.io.File;
 import java.io.IOException;
 
+import com.ksyun.ks3.service.request.PutObjectACLRequest;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.util.IOUtils;
 import org.springframework.beans.factory.DisposableBean;
@@ -115,6 +116,19 @@ public class KS3StoragePlugin implements StoragePlugin, InitializingBean, Dispos
 		}
 	}
 
+	public void setFileAcl(String fileName,Boolean isPublic){
+		PutObjectACLRequest request = new PutObjectACLRequest(bucketName,fileName);
+		if (isPublic){
+			//设为公开读
+			request.setCannedAcl(CannedAccessControlList.PublicRead);
+		}else {
+			//设为私有
+			request.setCannedAcl(CannedAccessControlList.Private);
+		}
+		client.putObjectACL(request);
+
+	}
+
 	@Override
 	public void destroy() throws Exception {
 	}

+ 12 - 8
edu-thirdparty/src/main/java/com/keao/edu/thirdparty/storage/provider/QiniuKodoStoragePlugin.java

@@ -1,9 +1,9 @@
 package com.keao.edu.thirdparty.storage.provider;
 
-import java.io.File;
-import java.io.IOException;
-import java.net.URLEncoder;
-
+import com.keao.edu.thirdparty.exception.ThirdpartyException;
+import com.keao.edu.thirdparty.storage.StoragePlugin;
+import com.keao.edu.thirdparty.storage.StoragePluginContext;
+import com.qiniu.util.Auth;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.DisposableBean;
@@ -11,10 +11,9 @@ import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
-import com.keao.edu.thirdparty.exception.ThirdpartyException;
-import com.keao.edu.thirdparty.storage.StoragePlugin;
-import com.keao.edu.thirdparty.storage.StoragePluginContext;
-import com.qiniu.util.Auth;
+import java.io.File;
+import java.io.IOException;
+import java.net.URLEncoder;
 
 @Component
 public class QiniuKodoStoragePlugin implements StoragePlugin, InitializingBean, DisposableBean {
@@ -37,6 +36,11 @@ public class QiniuKodoStoragePlugin implements StoragePlugin, InitializingBean,
 	}
 
 	@Override
+	public void setFileAcl(String fileName, Boolean isPublic) {
+		return;
+	}
+
+	@Override
 	public void afterPropertiesSet() throws Exception {
 		auth = Auth.create(accessKeyId, accessKeySecret);
 

+ 11 - 3
edu-user/edu-user-biz/src/main/java/com/keao/edu/user/service/impl/StudentExamResultServiceImpl.java

@@ -15,6 +15,8 @@ import com.keao.edu.im.api.client.ImFeignService;
 import com.keao.edu.im.api.entity.MemberChangedMessage;
 import com.keao.edu.im.api.entity.PublishMessageDto;
 import com.keao.edu.thirdparty.message.provider.JiguangPushPlugin;
+import com.keao.edu.thirdparty.storage.StoragePluginContext;
+import com.keao.edu.thirdparty.storage.provider.KS3StoragePlugin;
 import com.keao.edu.user.api.entity.ExamRoom;
 import com.keao.edu.user.api.entity.ExamRoomStudentRelation;
 import com.keao.edu.user.api.entity.Student;
@@ -72,6 +74,8 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 	private ExamReviewDao examReviewDao;
 	@Autowired
 	private SysConfigService sysConfigService;
+	@Autowired
+	private StoragePluginContext storagePluginContext;
 
 	private final static Logger logger = LoggerFactory.getLogger(StudentExamResultServiceImpl.class);
 
@@ -279,7 +283,7 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 
 	@Override
 	@Transactional(rollbackFor = Exception.class)
-	public void recordSync(RecordNotify recordNotify) {
+	public synchronized void recordSync(RecordNotify recordNotify) {
 		logger.info("recordSync paramJson{}",recordNotify);
 		if (recordNotify.getType() == 4){
 			JSONObject jsonObject = JSONObject.parseObject(recordNotify.getOutput());
@@ -294,10 +298,14 @@ public class StudentExamResultServiceImpl extends BaseServiceImpl<Long, StudentE
 						return;
 					}
 					String videoUrl = studentExamResult.getVideoUrl();
+					String fileName = jsonObject.get("fileUrl").toString();
+					String substring = fileName.substring(0, fileName.lastIndexOf("?"));
+					String substring1 = substring.substring(substring.lastIndexOf("/") + 1);
+					storagePluginContext.setFileAcl(KS3StoragePlugin.PLUGIN_NAME,substring1,true);
 					if(StringUtils.isNotEmpty(videoUrl)){
-						videoUrl += "," + jsonObject.get("fileUrl");
+						videoUrl += "," + substring1;
 					}else {
-						videoUrl = jsonObject.get("fileUrl").toString();
+						videoUrl = substring1;
 					}
 					studentExamResult.setVideoUrl(videoUrl);
 					studentExamResultDao.update(studentExamResult);