|
|
@ -9,9 +9,9 @@ import com.fr.json.JSONObject; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.log.FineLoggerFactory; |
|
|
|
import com.fr.stable.CommonUtils; |
|
|
|
import com.fr.stable.CommonUtils; |
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
import com.fr.stable.EncodeConstants; |
|
|
|
import com.fr.stable.ProductConstants; |
|
|
|
|
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
import com.fr.third.jodd.datetime.JDateTime; |
|
|
|
import com.fr.third.org.apache.http.HttpEntity; |
|
|
|
import com.fr.third.org.apache.http.HttpEntity; |
|
|
|
import com.fr.third.org.apache.http.HttpResponse; |
|
|
|
import com.fr.third.org.apache.http.HttpResponse; |
|
|
|
import com.fr.third.org.apache.http.client.HttpClient; |
|
|
|
import com.fr.third.org.apache.http.client.HttpClient; |
|
|
@ -27,6 +27,7 @@ import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
import java.util.UUID; |
|
|
|
|
|
|
|
|
|
|
|
import static com.fr.third.org.apache.http.HttpStatus.SC_OK; |
|
|
|
import static com.fr.third.org.apache.http.HttpStatus.SC_OK; |
|
|
|
|
|
|
|
|
|
|
@ -41,41 +42,16 @@ public class FileEntityBuilder { |
|
|
|
private static final String ATTR_SIGNATURE = "signature"; |
|
|
|
private static final String ATTR_SIGNATURE = "signature"; |
|
|
|
private static final String ATTR_KEY = "key"; |
|
|
|
private static final String ATTR_KEY = "key"; |
|
|
|
private static final String FOCUS_POINT_FILE_ROOT_PATH = "FocusPoint"; |
|
|
|
private static final String FOCUS_POINT_FILE_ROOT_PATH = "FocusPoint"; |
|
|
|
/** |
|
|
|
|
|
|
|
* 文件名 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String fileName; |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 文件的完整路径 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private String pathName; |
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文件夹路径 |
|
|
|
* 文件夹路径 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private String folderName; |
|
|
|
private String folderName; |
|
|
|
|
|
|
|
|
|
|
|
public FileEntityBuilder(String fileName, String pathName, String folderName) { |
|
|
|
public FileEntityBuilder(String folderName) { |
|
|
|
this.fileName = fileName; |
|
|
|
|
|
|
|
this.pathName = pathName; |
|
|
|
|
|
|
|
this.folderName = folderName; |
|
|
|
this.folderName = folderName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String getFileName() { |
|
|
|
|
|
|
|
return fileName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setFileName(String fileName) { |
|
|
|
|
|
|
|
this.fileName = fileName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getPathName() { |
|
|
|
|
|
|
|
return pathName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPathName(String pathName) { |
|
|
|
|
|
|
|
this.pathName = pathName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getFolderName() { |
|
|
|
public String getFolderName() { |
|
|
|
return folderName; |
|
|
|
return folderName; |
|
|
|
} |
|
|
|
} |
|
|
@ -97,14 +73,19 @@ public class FileEntityBuilder { |
|
|
|
return zipFile; |
|
|
|
return zipFile; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void generateFile(JSONArray jsonArray, String pathName) { |
|
|
|
public void generateFile(JSONArray jsonArray, String folderName) { |
|
|
|
|
|
|
|
if (jsonArray.size() == 0) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
String content = jsonArray.toString(); |
|
|
|
String content = jsonArray.toString(); |
|
|
|
File file = new File(pathName + ".json"); |
|
|
|
String fileName = String.valueOf(UUID.randomUUID()); |
|
|
|
|
|
|
|
File file = new File(folderName + File.separator + fileName + ".json"); |
|
|
|
StableUtils.makesureFileExist(file); |
|
|
|
StableUtils.makesureFileExist(file); |
|
|
|
FileOutputStream out = new FileOutputStream(file); |
|
|
|
FileOutputStream out = new FileOutputStream(file); |
|
|
|
InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); |
|
|
|
InputStream in = new ByteArrayInputStream(content.getBytes(EncodeConstants.ENCODING_UTF_8)); |
|
|
|
IOUtils.copyBinaryTo(in, out); |
|
|
|
IOUtils.copyBinaryTo(in, out); |
|
|
|
|
|
|
|
in.close(); |
|
|
|
out.close(); |
|
|
|
out.close(); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
|
|
@ -112,7 +93,7 @@ public class FileEntityBuilder { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void deleteFileAndZipFile(File zipFile, String pathName) { |
|
|
|
public void deleteFileAndZipFile(File zipFile, String pathName) { |
|
|
|
File file = new File(StableUtils.pathJoin(ProductConstants.getEnvHome(), pathName)); |
|
|
|
File file = new File(pathName); |
|
|
|
CommonUtils.deleteFile(file); |
|
|
|
CommonUtils.deleteFile(file); |
|
|
|
CommonUtils.deleteFile(zipFile); |
|
|
|
CommonUtils.deleteFile(zipFile); |
|
|
|
} |
|
|
|
} |
|
|
@ -124,9 +105,10 @@ public class FileEntityBuilder { |
|
|
|
* @throws IOException |
|
|
|
* @throws IOException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static void uploadFile(File file, String keyFileName) throws IOException { |
|
|
|
public static void uploadFile(File file, String keyFileName) throws IOException { |
|
|
|
|
|
|
|
String today = new JDateTime().toString("YYYY-MM-DD"); |
|
|
|
HttpClient httpclient = new DefaultHttpClient(); |
|
|
|
HttpClient httpclient = new DefaultHttpClient(); |
|
|
|
try { |
|
|
|
try { |
|
|
|
String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator +keyFileName); |
|
|
|
String signedUrl = generateSignedUploadUrl(FOCUS_POINT_FILE_ROOT_PATH + File.separator + today + File.separator +keyFileName); |
|
|
|
if(StringUtils.isEmpty(signedUrl)){ |
|
|
|
if(StringUtils.isEmpty(signedUrl)){ |
|
|
|
FineLoggerFactory.getLogger().error("signedUrl is null."); |
|
|
|
FineLoggerFactory.getLogger().error("signedUrl is null."); |
|
|
|
return; |
|
|
|
return; |
|
|
|