|
@@ -60,9 +60,11 @@ public class DataService {
|
|
|
@Value("${cpSerialNum}")
|
|
|
private String cpSerialNum;
|
|
|
|
|
|
- private static final String bucketName = "mooctest-site";
|
|
|
- private static final String imageUrlPrefix = "https://mooctest-site.oss-cn-shanghai.aliyuncs.com/xinchuang/image/";
|
|
|
+ @Value("${oss.bucketName}")
|
|
|
+ private String bucketName;
|
|
|
|
|
|
+ @Value("${oss.imageUrlPrefix}")
|
|
|
+ private String ossImageUrlPrefix;
|
|
|
|
|
|
/**
|
|
|
* 根据caseId获取对应bug信息
|
|
@@ -177,21 +179,13 @@ public class DataService {
|
|
|
|
|
|
public List<BugDetail> saveBugDetailFromOss(MultipartFile sourceZipFile, MultipartFile sourceJsonFile, String originalCaseId, String cpSerialNum) {
|
|
|
try {
|
|
|
-// //从oss下载json文件
|
|
|
-// URL url = new URL(jsonFilePath);
|
|
|
-// URLConnection urlConnection = url.openConnection();
|
|
|
-// HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
|
|
|
-// httpURLConnection.setConnectTimeout(1000 * 5);
|
|
|
-// httpURLConnection.setRequestProperty("Charset", "UTF-8");
|
|
|
-// httpURLConnection.connect();
|
|
|
-
|
|
|
//读取文件流并保存在本地
|
|
|
- String prefix="/Users/xujiawei/crowd/crowdsource-backend/";
|
|
|
- String zipFilePath=prefix+"xinchuangdata/input/imageZip/"+originalCaseId+"/"+cpSerialNum+"/"+originalCaseId+".zip";
|
|
|
+ String prefix="/Users/xujiawei/crowd/crowdsource-backend";
|
|
|
+ String zipFilePath=prefix+"/xinchuangdata/input/imageZip/"+originalCaseId+"/"+cpSerialNum+"/"+originalCaseId+".zip";
|
|
|
File zipFile=new File(zipFilePath);
|
|
|
if(!zipFile.getParentFile().exists()) { zipFile.getParentFile().mkdirs(); }
|
|
|
if(!sourceZipFile.isEmpty()) { sourceZipFile.transferTo(zipFile); }
|
|
|
- String jsonFilePath=prefix+"xinchuangdata/input/"+originalCaseId+"/"+cpSerialNum+"/"+originalCaseId+".json";
|
|
|
+ String jsonFilePath=prefix+"/xinchuangdata/input/"+originalCaseId+"/"+cpSerialNum+"/"+originalCaseId+".json";
|
|
|
File jsonFile=new File(jsonFilePath);
|
|
|
if(!jsonFile.getParentFile().exists()) { jsonFile.getParentFile().mkdirs(); }
|
|
|
if(!sourceJsonFile.isEmpty()) { sourceJsonFile.transferTo(jsonFile); }
|
|
@@ -213,16 +207,18 @@ public class DataService {
|
|
|
String[] imageUrlArray = imageUrl.split(",");
|
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
|
for (String imageUrlStr : imageUrlArray) {
|
|
|
- String[] filePath = imageUrlStr.split("/");
|
|
|
- String fileName = filePath[filePath.length - 1];
|
|
|
- String newImageUrl = imageUrlPrefix + originalCaseId + "/" + cpSerialNum + "/" + fileName;
|
|
|
- stringBuilder.append(newImageUrl).append(",");
|
|
|
+ if(!"".equals(imageUrl)) {
|
|
|
+ String[] filePath = imageUrlStr.split("/");
|
|
|
+ String fileName = filePath[filePath.length - 1];
|
|
|
+ String newImageUrl = ossImageUrlPrefix + originalCaseId + "/" + cpSerialNum + "/" + fileName;
|
|
|
+ stringBuilder.append(newImageUrl).append(",");
|
|
|
+ }
|
|
|
}
|
|
|
bugDetail.setImgUrl(stringBuilder.toString());
|
|
|
bugDetailDao.save(bugDetail);
|
|
|
}
|
|
|
//解压图片文件,上传至oss
|
|
|
- String destPath=prefix+"xinchuangdata/input/imageUnzip/"+originalCaseId+"/"+cpSerialNum;
|
|
|
+ String destPath=prefix+"/xinchuangdata/input/imageUnzip/"+originalCaseId+"/"+cpSerialNum;
|
|
|
File unzipFile=new File(destPath);
|
|
|
if(!unzipFile.getParentFile().exists()) { unzipFile.getParentFile().mkdirs(); }
|
|
|
unZip(zipFile,destPath,originalCaseId,cpSerialNum);
|
|
@@ -304,7 +300,7 @@ public class DataService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private static void uploadToOss(String objectName,File file) {
|
|
|
+ private void uploadToOss(String objectName,File file) {
|
|
|
if (file != null) {
|
|
|
OSS ossClient = OssAliyun.initShangHaiOss();
|
|
|
OssAliyun.uploadFile(ossClient, bucketName, objectName, file);
|
|
@@ -321,7 +317,7 @@ public class DataService {
|
|
|
* @throws RuntimeException 解压失败会抛出运行时异常
|
|
|
*/
|
|
|
|
|
|
- public static void unZip(File srcFile, String destDirPath,String originalCaseId,String fromCpSerialNum) throws RuntimeException {
|
|
|
+ private void unZip(File srcFile, String destDirPath,String originalCaseId,String fromCpSerialNum) throws RuntimeException {
|
|
|
long start = System.currentTimeMillis();
|
|
|
// 判断源文件是否存在
|
|
|
if (!srcFile.exists()) {
|
|
@@ -380,11 +376,6 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// public static void main(String[] args){
|
|
|
-// File a=new File("/Users/xujiawei/crowd/crowdsource-backend/data/a.zip");
|
|
|
-// unZip(a,"/Users/xujiawei/crowd/crowdsource-backend/data/test","1","test");
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
|