浏览代码

upgrade fss api...

deason 11 月之前
父节点
当前提交
dc152ff340

+ 137 - 137
examcloud-exchange-api-provider/src/main/java/cn/com/qmth/examcloud/exchange/inner/api/controller/UpyunController.java

@@ -1,137 +1,137 @@
-package cn.com.qmth.examcloud.exchange.inner.api.controller;
-
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
-import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
-import cn.com.qmth.examcloud.commons.exception.StatusException;
-import cn.com.qmth.examcloud.commons.util.AES;
-import cn.com.qmth.examcloud.commons.util.MD5;
-import cn.com.qmth.examcloud.commons.util.UUID;
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
-import cn.com.qmth.examcloud.web.config.SystemProperties;
-import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
-import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
-import cn.com.qmth.examcloud.web.support.ControllerSupport;
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.util.IOUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.ServletInputStream;
-import javax.servlet.http.HttpServletRequest;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
-/**
- * Upyun服务
- *
- * @author WANGWEI
- * @date 2018年11月21日
- * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
- */
-@RestController
-@RequestMapping("${$rmp.ctr.exchange.inner}/upyun")
-public class UpyunController extends ControllerSupport {
-
-    @Autowired
-    SystemProperties systemConfig;
-
-    @Autowired
-    UpyunService upyunService;
-
-    // 保存照片
-    @PutMapping("put/{siteId}/{fileSuffix}")
-    public String putFile(@PathVariable String siteId, @PathVariable String fileSuffix,
-                          @RequestParam(required = false) String md5, HttpServletRequest req) {
-
-        String contentLength = req.getHeader("Content-Length");
-        if (StringUtils.isNotBlank(contentLength)) {
-            long contentLengthLong = Long.parseLong(contentLength);
-            if (contentLengthLong < 10) {
-                throw new StatusException("600108", "empty IO stream");
-            }
-        }
-
-        if (StringUtils.isNotBlank(md5)) {
-            if (MD5.encrypt16("").equalsIgnoreCase(md5)) {
-                throw new StatusException("600109", "empty IO stream");
-            }
-        }
-
-        User accessUser = getAccessUser();
-
-        if (!fileSuffix.matches("\\w+")) {
-            throw new StatusException("600100", "fileSuffix is wrong");
-        }
-
-        fileSuffix = "." + fileSuffix;
-
-        ServletInputStream in = null;
-
-        if (StringUtils.isNotBlank(md5)) {
-
-            try {
-                in = req.getInputStream();
-
-                //通用存储
-                FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
-                env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
-                env.setUserId(String.valueOf(accessUser.getUserId()));
-                env.setFileSuffix(fileSuffix);
-                YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, in, md5);
-                String url = pi.getUrl();
-
-                url = new AES().encrypt(url);
-                return url;
-            } catch (IOException e) {
-                throw new ExamCloudRuntimeException(e);
-            } finally {
-                IOUtils.closeQuietly(in);
-            }
-
-        } else {
-
-            try {
-                FileUtils.forceMkdir(new File(systemConfig.getTempDataDir()));
-            } catch (IOException e1) {
-                LOGGER.error("fail to make dir. path=" + systemConfig.getTempDataDir());
-            }
-
-            String filePath = systemConfig.getTempDataDir() + File.separator + UUID.randomUUID()
-                    + fileSuffix;
-            File file = new File(filePath);
-
-            FileOutputStream out = null;
-            try {
-                in = req.getInputStream();
-                out = new FileOutputStream(file);
-                IOUtils.copy(in, out);
-
-                //通用存储
-                FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
-                env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
-                env.setUserId(String.valueOf(accessUser.getUserId()));
-                env.setFileSuffix(fileSuffix);
-                YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, file, true);
-                String url = pi.getUrl();
-                url = new AES().encrypt(url);
-                return url;
-            } catch (IOException e) {
-                throw new ExamCloudRuntimeException(e);
-            } finally {
-                IOUtils.closeQuietly(in);
-                IOUtils.closeQuietly(out);
-                try {
-                    FileUtils.forceDelete(file);
-                } catch (IOException e) {
-                    LOGGER.error("fail to delete file. path=" + filePath);
-                }
-            }
-
-        }
-
-    }
-
-}
+// package cn.com.qmth.examcloud.exchange.inner.api.controller;
+//
+// import cn.com.qmth.examcloud.api.commons.security.bean.User;
+// import cn.com.qmth.examcloud.commons.exception.ExamCloudRuntimeException;
+// import cn.com.qmth.examcloud.commons.exception.StatusException;
+// import cn.com.qmth.examcloud.commons.util.AES;
+// import cn.com.qmth.examcloud.commons.util.MD5;
+// import cn.com.qmth.examcloud.commons.util.UUID;
+// import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
+// import cn.com.qmth.examcloud.web.config.SystemProperties;
+// import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
+// import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
+// import cn.com.qmth.examcloud.web.support.ControllerSupport;
+// import cn.com.qmth.examcloud.web.upyun.UpyunService;
+// import org.apache.commons.io.FileUtils;
+// import org.apache.commons.lang3.StringUtils;
+// import org.apache.poi.util.IOUtils;
+// import org.springframework.beans.factory.annotation.Autowired;
+// import org.springframework.web.bind.annotation.*;
+//
+// import javax.servlet.ServletInputStream;
+// import javax.servlet.http.HttpServletRequest;
+// import java.io.File;
+// import java.io.FileOutputStream;
+// import java.io.IOException;
+//
+// /**
+//  * Upyun服务
+//  *
+//  * @author WANGWEI
+//  * @date 2018年11月21日
+//  * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+//  */
+// @RestController
+// @RequestMapping("${$rmp.ctr.exchange.inner}/upyun")
+// public class UpyunController extends ControllerSupport {
+//
+//     @Autowired
+//     SystemProperties systemConfig;
+//
+//     @Autowired
+//     UpyunService upyunService;
+//
+//     // 保存照片
+//     @PutMapping("put/{siteId}/{fileSuffix}")
+//     public String putFile(@PathVariable String siteId, @PathVariable String fileSuffix,
+//                           @RequestParam(required = false) String md5, HttpServletRequest req) {
+//
+//         String contentLength = req.getHeader("Content-Length");
+//         if (StringUtils.isNotBlank(contentLength)) {
+//             long contentLengthLong = Long.parseLong(contentLength);
+//             if (contentLengthLong < 10) {
+//                 throw new StatusException("600108", "empty IO stream");
+//             }
+//         }
+//
+//         if (StringUtils.isNotBlank(md5)) {
+//             if (MD5.encrypt16("").equalsIgnoreCase(md5)) {
+//                 throw new StatusException("600109", "empty IO stream");
+//             }
+//         }
+//
+//         User accessUser = getAccessUser();
+//
+//         if (!fileSuffix.matches("\\w+")) {
+//             throw new StatusException("600100", "fileSuffix is wrong");
+//         }
+//
+//         fileSuffix = "." + fileSuffix;
+//
+//         ServletInputStream in = null;
+//
+//         if (StringUtils.isNotBlank(md5)) {
+//
+//             try {
+//                 in = req.getInputStream();
+//
+//                 //通用存储
+//                 FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
+//                 env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
+//                 env.setUserId(String.valueOf(accessUser.getUserId()));
+//                 env.setFileSuffix(fileSuffix);
+//                 YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, in, md5);
+//                 String url = pi.getUrl();
+//
+//                 url = new AES().encrypt(url);
+//                 return url;
+//             } catch (IOException e) {
+//                 throw new ExamCloudRuntimeException(e);
+//             } finally {
+//                 IOUtils.closeQuietly(in);
+//             }
+//
+//         } else {
+//
+//             try {
+//                 FileUtils.forceMkdir(new File(systemConfig.getTempDataDir()));
+//             } catch (IOException e1) {
+//                 LOGGER.error("fail to make dir. path=" + systemConfig.getTempDataDir());
+//             }
+//
+//             String filePath = systemConfig.getTempDataDir() + File.separator + UUID.randomUUID()
+//                     + fileSuffix;
+//             File file = new File(filePath);
+//
+//             FileOutputStream out = null;
+//             try {
+//                 in = req.getInputStream();
+//                 out = new FileOutputStream(file);
+//                 IOUtils.copy(in, out);
+//
+//                 //通用存储
+//                 FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
+//                 env.setRootOrgId(String.valueOf(accessUser.getRootOrgId()));
+//                 env.setUserId(String.valueOf(accessUser.getUserId()));
+//                 env.setFileSuffix(fileSuffix);
+//                 YunPathInfo pi = FileStorageUtil.saveFile(siteId, env, file, true);
+//                 String url = pi.getUrl();
+//                 url = new AES().encrypt(url);
+//                 return url;
+//             } catch (IOException e) {
+//                 throw new ExamCloudRuntimeException(e);
+//             } finally {
+//                 IOUtils.closeQuietly(in);
+//                 IOUtils.closeQuietly(out);
+//                 try {
+//                     FileUtils.forceDelete(file);
+//                 } catch (IOException e) {
+//                     LOGGER.error("fail to delete file. path=" + filePath);
+//                 }
+//             }
+//
+//         }
+//
+//     }
+//
+// }

+ 9 - 15
examcloud-exchange-service/src/main/java/cn/com/qmth/examcloud/exchange/outer/service/impl/FaceServiceImpl.java

@@ -18,12 +18,10 @@ import cn.com.qmth.examcloud.exchange.outer.service.FaceService;
 import cn.com.qmth.examcloud.reports.commons.bean.OperateReport;
 import cn.com.qmth.examcloud.reports.commons.enums.OperateContent;
 import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
+import cn.com.qmth.examcloud.support.fss.FssFactory;
+import cn.com.qmth.examcloud.support.fss.model.FssFileInfo;
 import cn.com.qmth.examcloud.web.enums.HttpServletRequestAttribute;
-import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
-import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
 import cn.com.qmth.examcloud.web.support.ServletUtil;
-import cn.com.qmth.examcloud.web.upyun.UpyunService;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -63,8 +61,8 @@ public class FaceServiceImpl implements FaceService {
     @Autowired
     StudentCloudService studentCloudService;
 
-    @Autowired
-    UpyunService upyunService;
+    // @Autowired
+    // UpyunService upyunService;
 
     @Autowired
     FaceCloudService faceCloudService;
@@ -85,15 +83,11 @@ public class FaceServiceImpl implements FaceService {
         GetStudentResp resp = studentCloudService.getStudent(req);
         StudentBean student = resp.getStudentInfo();
         identityNumber = student.getIdentityNumber();
-        Long id = student.getId();
 
-        FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
-        env.setFileSuffix(fileSuffix);
-        env.setRootOrgId(String.valueOf(rootOrgId));
-        env.setUserId(String.valueOf(id));
-        //通用存储
-        YunPathInfo pi = FileStorageUtil.saveFile("studentBasePhoto", env, file, true);
-        String photoUrl = pi.getUrl();
+        // 路径规则:/student_base_photo/{rootOrgId}/{userId}/{timeMillis}{fileSuffix}
+        String filePath = String.format("/student_base_photo/%s/%s/%s%s", rootOrgId, student.getId(), System.currentTimeMillis(), fileSuffix);
+        FssFileInfo result = FssFactory.getInstance().writeFile(filePath, file, null);
+        String photoUrl = result.getFileUrl();
 
         String faceToken = detect(photoUrl);
 
@@ -111,7 +105,7 @@ public class FaceServiceImpl implements FaceService {
         request.setRootOrgId(rootOrgId);
         request.setStudentId(student.getId());
         request.setFaceCount(faceCount);
-        request.setPhotoTreatyPath(pi.getRelativePath());
+        request.setPhotoTreatyPath(result.getFilePath());
 
         faceCloudService.saveStudentFace(request);
 

+ 0 - 4
examcloud-exchange-starter/src/main/java/cn/com/qmth/examcloud/exchange/ExchangeApp.java

@@ -1,6 +1,5 @@
 package cn.com.qmth.examcloud.exchange;
 
-import cn.com.qmth.examcloud.support.filestorage.FileStorageUtil;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -42,9 +41,6 @@ public class ExchangeApp {
     public static void main(String[] args) {
         // AppBootstrap.run(ExchangeApp.class, args);
         SpringApplication.run(ExchangeApp.class, args);
-
-        FileStorageUtil.initYunSite();
-        FileStorageUtil.initYunClient();
     }
 
     @Bean(name = "multipartResolver")