|
@@ -17,8 +17,11 @@ import net.yaoyi.gulop.member.auth.util.RemoteFileUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
@@ -361,6 +364,65 @@ public class GigConfigServiceImpl implements GigConfigService {
|
|
|
return CommonResult.ok(apiRespBody);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CommonResult uploadFileByUrl(FileUrlInput urlInput){
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+ ApiRespBody<String> apiRespBody = netSignClient.uploadFileByUrl(urlInput);
|
|
|
+
|
|
|
+ return CommonResult.ok(apiRespBody);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getUploadFileUrl(FileUploadInput uploadInput){
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+ ApiRespBody<FileUploadOutput> apiRespBody = netSignClient.getUploadFileUrl(uploadInput);
|
|
|
+
|
|
|
+ return CommonResult.ok(apiRespBody);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult getFileUploadInput(String url) throws IOException, NoSuchAlgorithmException {
|
|
|
+ FileDto fileDto = RemoteFileUtils.fromUrl(url);
|
|
|
+
|
|
|
+ FileUploadInput uploadInput = new FileUploadInput();
|
|
|
+ // 根据给定的字符串,截取文件的扩展名
|
|
|
+ String extension = fileDto.getFileName() == null ? "" : fileDto.getFileName().substring(fileDto.getFileName().lastIndexOf(".")+1);
|
|
|
+ uploadInput.setFilename(fileDto.getFileName());
|
|
|
+ uploadInput.setExtension(extension);
|
|
|
+ uploadInput.setFilesize((long)fileDto.getFileInputStream().available());
|
|
|
+ uploadInput.setFileType(1);
|
|
|
+ uploadInput.setContentMd5(getContentMD5(fileDto.getFileInputStream()));
|
|
|
+
|
|
|
+
|
|
|
+ return CommonResult.ok(uploadInput);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult uploadFile(String url, String fileUrl) throws Exception {
|
|
|
+ UmsExtConfig config = getConfig();
|
|
|
+ NetSignClient netSignClient = new NetSignClient("https://prev.asign.cn/", config.getExtId(), config.getExtSecret());
|
|
|
+
|
|
|
+ File file = RemoteFileUtils.downloadFileFromUrl(fileUrl);
|
|
|
+
|
|
|
+ ApiRespBody<Void> apiRespBody = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ apiRespBody = netSignClient.uploadFile(url, file);
|
|
|
+ }catch (Exception e){
|
|
|
+ throw new Exception(e);
|
|
|
+ }finally {
|
|
|
+ if(file.exists()){
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return CommonResult.ok(apiRespBody);
|
|
|
+ }
|
|
|
+
|
|
|
//同步状态
|
|
|
public CommonResult signCheck(Long contractId, long userId){
|
|
|
|
|
@@ -624,4 +686,26 @@ public class GigConfigServiceImpl implements GigConfigService {
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算文件的ContentMD5
|
|
|
+ * @return String contentMd5
|
|
|
+ */
|
|
|
+ public static String getContentMD5(InputStream inputStream) throws IOException, NoSuchAlgorithmException {
|
|
|
+ byte[] bytes = getMD5Bytes(inputStream);
|
|
|
+ return Base64.getEncoder().encodeToString(bytes);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取文件MD5二进制数组
|
|
|
+ * @return byte[]
|
|
|
+ */
|
|
|
+ public static byte[] getMD5Bytes(InputStream inputStream) throws IOException, NoSuchAlgorithmException {
|
|
|
+ MessageDigest md5 = MessageDigest.getInstance("MD5");
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int length;
|
|
|
+ while((length = inputStream.read(buffer, 0, 1024)) != -1) {
|
|
|
+ md5.update(buffer, 0, length);
|
|
|
+ }
|
|
|
+ return md5.digest();
|
|
|
+ }
|
|
|
}
|