|
@@ -4,7 +4,9 @@ import java.io.BufferedReader;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
@@ -22,7 +24,9 @@ import com.jfinal.plugin.activerecord.Db;
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
import com.zskk.tools.XmlHelper;
|
|
|
|
|
|
+import jcifs.smb.SmbFile;
|
|
|
import okhttp3.FormBody;
|
|
|
+import okhttp3.MultipartBody;
|
|
|
import okhttp3.OkHttpClient;
|
|
|
import okhttp3.Request;
|
|
|
import okhttp3.RequestBody;
|
|
@@ -102,6 +106,57 @@ public class DataService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void downloadFileToFolder(String remoteUrl, String shareFolderPath, String fileName, String localDir,Record recoeRecord) {
|
|
|
+ InputStream in = null;
|
|
|
+ OutputStream out = null;
|
|
|
+ try {
|
|
|
+ SmbFile remoteFile = new SmbFile(remoteUrl + shareFolderPath + "/" + fileName);
|
|
|
+ File localFile = new File(localDir + File.separator + fileName);
|
|
|
+ localFile.getParentFile().mkdirs();
|
|
|
+ in = new BufferedInputStream(new SmbFileInputStream(remoteFile));
|
|
|
+ out = new BufferedOutputStream(new FileOutputStream(localFile));
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ while (in.read(buffer) != -1) {
|
|
|
+ out.write(buffer);
|
|
|
+ buffer = new byte[1024];
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+ e.fillInStackTrace();
|
|
|
+ } finally {
|
|
|
+ File localFile = new File(localDir + File.separator + fileName);
|
|
|
+ try {
|
|
|
+ out.close();
|
|
|
+ in.close();
|
|
|
+ System.out.print("11");
|
|
|
+
|
|
|
+ RequestBody requestBody = new MultipartBody.Builder()
|
|
|
+ .setType(MultipartBody.FORM)
|
|
|
+ .addFormDataPart("file", localFile.getName(),
|
|
|
+ RequestBody.create(MEDIA_TYPE_MARKDOWN, localFile))
|
|
|
+ .build();
|
|
|
+
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url("http://127.0.0.1:8080/df/view/upload")
|
|
|
+ .post(requestBody)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
|
|
|
+ if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
|
|
|
+
|
|
|
+ System.out.println(response.body().string());
|
|
|
+ localFile.delete();
|
|
|
+ recoeRecord.set("pmh", "1");
|
|
|
+ Db.use("connected").update("reportinfo", "IMAGESFILENAME",recoeRecord);
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+// localFile.delete();
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) throws IOException, ParserConfigurationException {
|
|
|
|
|
|
File fin_floder = new File("/Users/liutao/Desktop/tt121.xml");
|