123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package com.zskk.service;
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.HashMap;
- import java.util.Map;
- import com.alibaba.fastjson.JSON;
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.jfinal.kit.PropKit;
- import jcifs.smb.NtlmPasswordAuthentication;
- import jcifs.smb.SmbFile;
- import jcifs.smb.SmbFileInputStream;
- import okhttp3.FormBody;
- import okhttp3.MediaType;
- import okhttp3.OkHttpClient;
- import okhttp3.Request;
- import okhttp3.RequestBody;
- import okhttp3.Response;
- public class DataService {
-
- private static String GET_EXAM_URL = "https://risserver3.pacsonline.cn/butt/getExam";
-
- private static String SAVE_REPORT_URL = "https://risserver3.pacsonline.cn/butt/saveReport";
-
- private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient();
- public static final MediaType MEDIA_TYPE_MARKDOWN = MediaType.parse("text/x-markdown; charset=utf-8");
-
- /**
- * 获取未出报告的检查列表
- * @param instutionId
- * @param number
- */
- public JSONArray getExamList(Integer number) {
- Map <String,String> map = new HashMap<String,String>();
- map.put("institution_id", PropKit.get("institution_id"));
- map.put("num", number.toString());
- String content = postWithParameters(GET_EXAM_URL, map);
- JSONObject jsonObject = JSON.parseObject(content);
- if (!jsonObject.getString("msg").equals("success")) {
- return null;
- }
- JSONArray jsonArray = JSON.parseArray(jsonObject.getString("data"));
- return jsonArray;
-
- }
-
- /**
- * 写入报告
- * @param instutionId
- * @param number
- */
- public void saveReport(Map <String,String> map) {
- postWithParameters(SAVE_REPORT_URL, map);
-
- }
-
- public static String postWithParameters(String url, Map<String, String> map) {
-
- FormBody.Builder formbody = new FormBody.Builder();
-
- for (Map.Entry<String, String> entry : map.entrySet()) {
- formbody.add(entry.getKey(), entry.getValue());
- }
- RequestBody requestBody = formbody.build();
-
- Request request = new Request.Builder()
- .url(url)
- .post(requestBody)
- .build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- String content = response.body().string();
- return content;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return null;
- }
- }
-
- public static void downloadFileToFolder(String remoteUrl, String shareFolderPath, String fileName, String localDir) {
- InputStream in = null;
- OutputStream out = null;
- try {
- SmbFile remoteFile = new SmbFile(remoteUrl + shareFolderPath + File.separator + 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();
- } finally {
- try {
- out.close();
- in.close();
- System.out.print("11");
- File localFile = new File(localDir + File.separator + fileName);
- Request request = new Request.Builder()
- .url("https://api.github.com/markdown/raw")
- .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, localFile))
- .build();
- try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
- if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
- System.out.println(response.body().string());
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
-
- public static void main(String[] args) {
- // Map <String,String> map = new HashMap<String,String>();
- // map.put("institution_id", "47600001");
- // map.put("num", "10");
- // postWithParameters(GET_EXAM_URL, map);
- downloadFileToFolder("smb://"+"hao:"+"123456@" +"192.168.31.150", "/share/pagkage", "factor1.py", "./tempImg");
- }
- }
|