|
@@ -42,6 +42,8 @@ import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.lang.reflect.Type;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -52,6 +54,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* Created by ROGK on 2017/6/18.
|
|
@@ -275,10 +278,10 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
List<TestCase> validCases = new ArrayList<>();
|
|
|
caseMap.forEach((key, value) -> validCases.add(new TestCase(key, value)));
|
|
|
|
|
|
- String targetPath = System.getProperty("java.io.tmpdir")+File.separator+
|
|
|
- Constants.TARGET_PATH+File.separator+targetId+File.separator;
|
|
|
- String targetContentPath = targetPath+"content"+File.separator;
|
|
|
- String mooctestPath = targetContentPath+File.separator+Constants.MOOCTEST_PATH+File.separator;
|
|
|
+ String targetPath = Paths.get(System.getProperty("java.io.tmpdir"),Constants.TARGET_PATH,
|
|
|
+ targetId+"").toString();
|
|
|
+ String targetContentPath = Paths.get(targetPath,Constants.CONTENT_PATH).toString();
|
|
|
+ String mooctestPath = Paths.get(targetContentPath,Constants.MOOCTEST_PATH).toString();
|
|
|
|
|
|
//删除已有文件
|
|
|
File targetPathFile = new File(targetPath);
|
|
@@ -287,10 +290,12 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
}
|
|
|
|
|
|
//写入文件
|
|
|
- boolean writeSuccess = FileUtils.writingStringToFile(frameCode,targetContentPath+"problem.py") &&
|
|
|
- FileUtils.writingStringToFile(code,mooctestPath+"answer.py") &&
|
|
|
+ boolean writeSuccess = FileUtils.writingStringToFile(frameCode,
|
|
|
+ Paths.get(targetContentPath,Constants.MAIN_NAME).toString()) &&
|
|
|
+ FileUtils.writingStringToFile(code,Paths.get(mooctestPath,
|
|
|
+ Constants.ANSWER_NAME).toString())&&
|
|
|
FileUtils.writingStringToFile(new Gson().toJson(validCases),
|
|
|
- mooctestPath+"testCases.json");
|
|
|
+ Paths.get(mooctestPath,Constants.TEST_CASE_NAME).toString());
|
|
|
|
|
|
//打包上传
|
|
|
if(writeSuccess){
|
|
@@ -298,7 +303,7 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
String url = "";
|
|
|
if(!OSSOn){
|
|
|
//存储target文件到本地服务器
|
|
|
- String zipFilePath = Constants.SAVE_PATH+File.separator+zipFileName;
|
|
|
+ String zipFilePath = Paths.get(Constants.SAVE_PATH,zipFileName).toString();
|
|
|
if(FileUtils.zipMultiFile(targetContentPath,zipFilePath,false)){
|
|
|
url = host+zipFileName;
|
|
|
}else{
|
|
@@ -306,7 +311,7 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
}
|
|
|
}else{
|
|
|
//存储文件到oss
|
|
|
- String zipFilePath = targetPath+zipFileName;
|
|
|
+ String zipFilePath = Paths.get(targetPath,zipFileName).toString();
|
|
|
if(FileUtils.zipMultiFile(targetContentPath,zipFilePath,false)){
|
|
|
InputStream zipStream = null;
|
|
|
try {
|
|
@@ -331,6 +336,14 @@ public class TargetLogicImpl extends BaseLogic implements TargetLogic {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String saveTargetZip(MultipartFile zipFile) throws IOException {
|
|
|
+ Path tmpZipPath = Paths.get(System.getProperty("java.io.tmpdir"),Constants.TARGET_PATH,
|
|
|
+ +System.currentTimeMillis()+"_"+zipFile.getOriginalFilename());
|
|
|
+
|
|
|
+ return ossLogic.saveFileTemp(zipFile,tmpZipPath.toString());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private void setListener(long targetId, long targetType, String url) {
|
|
|
GetTargetGraphEvent event = new GetTargetGraphEvent(targetId, url, targetType);
|