|
@@ -59,7 +59,8 @@ public class DataService {
|
|
|
@Value("${cpSerialNum}")
|
|
|
private String cpSerialNum;
|
|
|
|
|
|
- private static final String bucketName="mooctest-share";
|
|
|
+ private static final String bucketName = "mooctest-share";
|
|
|
+ private static final String imageUrlPrefix = "https://mooctest-site.oss-cn-shanghai.aliyuncs.com/xinchuang/image/";
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -169,31 +170,42 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- bugDetailToFile(bugDetailList,caseId);
|
|
|
+ bugDetailToFile(bugDetailList, caseId);
|
|
|
return bugDetailList;
|
|
|
}
|
|
|
|
|
|
- public List<BugDetail> saveBugDetailFromOss(String filePath,String originalCaseId){
|
|
|
+ public List<BugDetail> saveBugDetailFromOss(String jsonFilePath, String originalCaseId, String cpSerialNum) {
|
|
|
try {
|
|
|
- //从oss下载文件
|
|
|
- URL url = new URL(filePath);
|
|
|
+ //从oss下载json文件
|
|
|
+ URL url = new URL(jsonFilePath);
|
|
|
URLConnection urlConnection = url.openConnection();
|
|
|
HttpURLConnection httpURLConnection = (HttpURLConnection) urlConnection;
|
|
|
- httpURLConnection.setConnectTimeout(1000*5);
|
|
|
+ httpURLConnection.setConnectTimeout(1000 * 5);
|
|
|
httpURLConnection.setRequestProperty("Charset", "UTF-8");
|
|
|
httpURLConnection.connect();
|
|
|
BufferedInputStream bufferedInputStream = new BufferedInputStream(httpURLConnection.getInputStream());
|
|
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
|
|
int result = bufferedInputStream.read();
|
|
|
- while(result != -1) {
|
|
|
+ while (result != -1) {
|
|
|
buf.write((byte) result);
|
|
|
result = bufferedInputStream.read();
|
|
|
}
|
|
|
- String json= buf.toString();
|
|
|
+ String json = buf.toString();
|
|
|
//转为bugDetail
|
|
|
List<BugDetail> bugDetailList = JSON.parseArray(json, BugDetail.class);
|
|
|
- for(BugDetail bugDetail:bugDetailList){
|
|
|
+ for (BugDetail bugDetail : bugDetailList) {
|
|
|
bugDetail.setOriginalCaseId(originalCaseId);
|
|
|
+ //修改图片文件路径为oss路径
|
|
|
+ String imageUrl = bugDetail.getImgUrl();
|
|
|
+ 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(",");
|
|
|
+ }
|
|
|
+ bugDetail.setImgUrl(stringBuilder.toString());
|
|
|
bugDetailDao.save(bugDetail);
|
|
|
}
|
|
|
return bugDetailList;
|
|
@@ -208,35 +220,35 @@ public class DataService {
|
|
|
"description", "img_url",
|
|
|
"score", "parent", "children", "root", "good_num", "good_worker_id", "bad_num", "bad_worker_id",
|
|
|
"test_case_id", "test_case_name", "test_case_front", "test_case_behind", "test_case_description", "test_case_create_time",
|
|
|
- "report_id", "report_name", "report_create_time", "script_location", "report_location", "log_location","device_model", "device_brand", "device_os",
|
|
|
+ "report_id", "report_name", "report_create_time", "script_location", "report_location", "log_location", "device_model", "device_brand", "device_os",
|
|
|
"worker_id",
|
|
|
- "case_app_name","case_paper_type","case_test_type", "case_description", "case_require_doc",
|
|
|
- "case_take_id","originalCaseId","cpSerialNum"};
|
|
|
- File csvFile=exportCsv(titles, bugDetailList,caseId);
|
|
|
- File jsonFile=exportJson(bugDetailList,caseId);
|
|
|
+ "case_app_name", "case_paper_type", "case_test_type", "case_description", "case_require_doc",
|
|
|
+ "case_take_id", "originalCaseId", "cpSerialNum"};
|
|
|
+ File csvFile = exportCsv(titles, bugDetailList, caseId);
|
|
|
+ File jsonFile = exportJson(bugDetailList, caseId);
|
|
|
uploadToOss(csvFile);
|
|
|
uploadToOss(jsonFile);
|
|
|
}
|
|
|
|
|
|
- private File exportJson(List<BugDetail> bugDetailList, String caseId){
|
|
|
+ private File exportJson(List<BugDetail> bugDetailList, String caseId) {
|
|
|
try {
|
|
|
File file = new File("data/output/" + caseId + ".json");
|
|
|
- JSONArray jsonArray=new JSONArray(bugDetailList);
|
|
|
+ JSONArray jsonArray = new JSONArray(bugDetailList);
|
|
|
Writer write = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
|
|
|
write.write(jsonArray.toString());
|
|
|
write.flush();
|
|
|
write.close();
|
|
|
return file;
|
|
|
- }catch (IOException e){
|
|
|
+ } catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
- private <T> File exportCsv(String[] titles, List<T> list,String caseId) {
|
|
|
+ private <T> File exportCsv(String[] titles, List<T> list, String caseId) {
|
|
|
try {
|
|
|
- File file = new File("data/output/"+caseId+".csv");
|
|
|
+ File file = new File("data/output/" + caseId + ".csv");
|
|
|
//构建输出流,同时指定编码
|
|
|
OutputStreamWriter ow = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8);
|
|
|
//csv文件是逗号分隔,除第一个外,每次写入一个单元格数据后需要输入逗号
|
|
@@ -258,7 +270,7 @@ public class DataService {
|
|
|
ow.write("");
|
|
|
} else {
|
|
|
//解决csv文件中对于逗号和双引号的转义问题
|
|
|
- ow.write("\"" + field.get(obj).toString().replaceAll("\"","\"\"") + "\"");
|
|
|
+ ow.write("\"" + field.get(obj).toString().replaceAll("\"", "\"\"") + "\"");
|
|
|
}
|
|
|
ow.write(",");
|
|
|
}
|
|
@@ -274,12 +286,12 @@ public class DataService {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- private void uploadToOss(File file){
|
|
|
- if(file!=null) {
|
|
|
+ private void uploadToOss(File file) {
|
|
|
+ if (file != null) {
|
|
|
OSS ossClient = OssAliyun.initHangZhouOss();
|
|
|
String objectName = "crowd-dataset/" + file.getName();
|
|
|
OssAliyun.uploadFile(ossClient, bucketName, objectName, file);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
System.out.println("file is null");
|
|
|
}
|
|
|
}
|