刘韬 3 years ago
parent
commit
2b15a33d4f

+ 3 - 3
DataFusion/src/com/zskk/config/ZskkConfig.java

@@ -109,9 +109,9 @@ public class ZskkConfig extends JFinalConfig {
 		me.add(inData);
 		me.add(inData);
 		
 		
 		//下载检查影像
 		//下载检查影像
-		Cron4jPlugin mvData = new Cron4jPlugin();
-		mvData.addTask("*/1 * * * *", new DownloadTask());
-		me.add(mvData);
+//		Cron4jPlugin mvData = new Cron4jPlugin();
+//		mvData.addTask("*/1 * * * *", new DownloadTask());
+//		me.add(mvData);
 		
 		
 //		//更新患者信息检查影像
 //		//更新患者信息检查影像
 //		Cron4jPlugin ifData = new Cron4jPlugin();
 //		Cron4jPlugin ifData = new Cron4jPlugin();

+ 68 - 104
DataFusion/src/com/zskk/control/ViewController.java

@@ -12,6 +12,7 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.Random;
 
 
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.NodeList;
@@ -68,36 +69,51 @@ public class ViewController extends Controller {
 	}
 	}
 	
 	
 	public void downDcm() {
 	public void downDcm() {
-		try {
-			Request request = new Request.Builder()
-			        .url("http://10.0.25.99:81/DR/DRIMAGE2/1.2.410.200048.22210.20220117214826.1/1")
-			        .build();
-
-			OKHTTP_CLIENT.newCall(request).enqueue(new Callback() {
-			      @Override public void onFailure(Call call, IOException e) {
-			        e.printStackTrace();
-			      }
-
-			      @Override public void onResponse(Call call, Response response) throws IOException {
-			        try (ResponseBody responseBody = response.body()) {
-			          if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
-	                    writeFile(response);
+		String aString ="";
+		String bString ="";
 
 
-//			          Headers responseHeaders = response.headers();
-//			          for (int i = 0, size = responseHeaders.size(); i < size; i++) {
-//			            System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
-//			          }
-//
-//			          System.out.println(responseBody.string());
-			        }
-			      }
-			    });
-			renderNull();
-		} catch (Exception e) {
-			// TODO: handle exception
-			this.renderText(e.toString());
+		List<Record> studyidfinds = Db.use("local").find("select * from study where status =1 or status =2 order by createAt asc limit 1");
+		if (studyidfinds == null) {
+			return;
 		}
 		}
 		
 		
+		for (Record studyidfind : studyidfinds) {
+//			flag++;
+//			if (flag > max) {
+//				continue;
+//			}
+			Date creatDate = studyidfind.getDate("createAt");
+			Date nowDate = new Date(); 
+			Long due = nowDate.getTime() - creatDate.getTime();
+			//延时30min
+			if (due < 1800000) {
+				return;
+			}
+			//状态4:下载中
+			studyidfind.set("status", 4);
+			Db.use("local").update("study", studyidfind);
+			List<Record> dicomfind = Db.use("connected_dicom").find("select * from dicominfo where studyuid=?",studyidfind.getStr("studyuid"));
+			for (Record record : dicomfind) {
+				Request request = new Request.Builder()
+				        .url(record.getStr("URL"))
+				        .build();
+				aString =aString+record.getStr("URL")+"/n";
+				try (Response response = OKHTTP_CLIENT.newCall(request).execute()) {
+				      if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
+
+	                   String cString =  writeFile(response,studyidfind.getStr("studyuid"));
+	                   bString =bString+cString;
+				    } catch (IOException e1) {
+						// TODO Auto-generated catch block
+						e1.printStackTrace();
+				    	continue;
+					}
+				
+			}
+			studyidfind.set("status", 3);
+			Db.use("local").update("study", studyidfind);
+		}
+		renderText(aString+"**************"+bString);
 	}
 	}
 	
 	
 	
 	
@@ -116,84 +132,32 @@ public class ViewController extends Controller {
 			this.renderText(e.toString());
 			this.renderText(e.toString());
 		}
 		}
 	}
 	}
-	
-	public void tempmatch() {
-        String fileName2String ="";
-
-//		 List<String> files = new ArrayList<String>();
-//	        File file = new File("/home/zskk/CFIND_XML");
-//	        File[] tempList = file.listFiles();
-//	        for (int m = 0; m < tempList.length; m++) {
-//	            if (tempList[m].isFile()) {
-//	                files.add(tempList[m].toString());
-//	                //文件名,不包含路径
-//	                String fileName = tempList[m].getName();
-//	               fileName2String = fileName2String+fileName+"**";
-	               File fin_floder = new File("/home/zskk/CFIND_XML/tt51.xml");
-	       		// 创建从文件读取数据的FileInputStream流
-	       		FileInputStream fin;
-	       		try {
-	       			fin = new FileInputStream(fin_floder);
-	       			InputStreamReader isr = null;
-	       			isr = new InputStreamReader(fin);
-	       			BufferedReader raf = null;
-	       			raf = new BufferedReader(isr);
-	       			String xmlContent = null;
-	       			xmlContent = raf.readLine();
-	       			xmlContent = xmlContent.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
-	       			xmlContent = "<zskk>" + xmlContent + "</zskk>";
-	       			XmlHelper xmlHelper = XmlHelper.of(xmlContent);
-	       			fileName2String = xmlContent;
-	       			// NativeDicomModel节点列表
-	       			NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel");
-	       			for (int i = 0; i < nativeDicomModelList.getLength(); i++) {
-	       				String qString = "";
-	       				String studyuidString = "";
-	       				String modalitiesString = "";
-	       				// DicomAttribute节点列表
-	       				NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute");
-	       				for (int j = 0; j < dicomAttributeList.getLength(); j++) {
-	       					// DicomAttribute节点属性列表
-	       					NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes();
-	       					if (attributeMap != null && attributeMap.getLength() > 0) {
-	       						for (int k = 0; k < attributeMap.getLength(); k++) {
-	       							if (attributeMap.item(k).getNodeName().equals("tag")) {
-	       								// 获取studyuid
-	       								if (attributeMap.item(k).getNodeValue().equals("0020000D")) {
-	       									studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
-	       									continue;
-	       								}
-	       								// 获取检查类型
-	       								if (attributeMap.item(k).getNodeValue().equals("00080061")) {
-	       									modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
-	       								}
-	       							}
-	       						}
-	       					}
-	       				}
-	       				Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
-	       						studyuidString);
-	       				if (studyidfind == null) {
-	       					Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString)
-	       							.set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime());
-	       					Db.use("local").save("study", studyinfo);
-	       				}
-	       			}
-	       		} catch (IOException e) {
-	       			// TODO Auto-generated catch block
-	       			e.printStackTrace();
-	    			this.renderText(e.toString());
-
-	       		}
-//	            }
-//	            if (tempList[m].isDirectory()) {
-//	                //这里就不递归了,
-//	            }
-//	            
-//	            }
-			this.renderText(fileName2String);
+	private String writeFile(Response response, String uid) {
+        InputStream is = response.body().byteStream();;
+        FileOutputStream fos = null;
+        String path = "/home/lenovo/CFIND_XML";
+        Random r = new Random();
+        Integer ran1 = r.nextInt(100000);
+        File file = new File(path, uid+ran1.toString());
+        try {
+            fos = new FileOutputStream(file);
+            byte[] bytes = new byte[1024];
+            int len = 0;
+            while (-1 != (len = is.read(bytes))) {
+            	fos.write(bytes, 0, len);
+            	}
+            fos.flush();
+            fos.close();
+            is.close();
+            File filentemp = new File(path, uid+ran1.toString());
+            File filen = new File(path, uid+ran1.toString()+".dcm");
+            filentemp.renameTo(filen);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "0";
 
 
-	}
+    }
 	public static DruidPlugin createConnectedDruidPlugin() {
 	public static DruidPlugin createConnectedDruidPlugin() {
 
 
 		return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
 		return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());