UpdateTask.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.zskk.task;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Date;
  9. import org.w3c.dom.NamedNodeMap;
  10. import org.w3c.dom.NodeList;
  11. import com.jfinal.plugin.activerecord.Db;
  12. import com.jfinal.plugin.activerecord.Record;
  13. import com.jfinal.plugin.cron4j.ITask;
  14. import com.zskk.tools.XmlHelper;
  15. public class UpdateTask implements ITask {
  16. @Override
  17. public void run() {
  18. // TODO Auto-generated method stub
  19. String dateString = parseStringToDate();
  20. String fileString = dateString.replace("0", "o");
  21. File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + fileString + "1.xml");
  22. // 创建从文件读取数据的FileInputStream流
  23. FileInputStream fin;
  24. try {
  25. fin = new FileInputStream(fin_floder);
  26. InputStreamReader isr = null;
  27. isr = new InputStreamReader(fin);
  28. BufferedReader raf = null;
  29. raf = new BufferedReader(isr);
  30. String xmlContent = null;
  31. xmlContent = raf.readLine();
  32. xmlContent = xmlContent.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
  33. xmlContent = "<zskk>" + xmlContent + "</zskk>";
  34. xmlContent = xmlContent.replace("&#0", "");
  35. XmlHelper xmlHelper = XmlHelper.of(xmlContent);
  36. // NativeDicomModel节点列表
  37. NodeList nativeDicomModelList = xmlHelper.getNodeList("/zskk/NativeDicomModel");
  38. for (int i = 0; i < nativeDicomModelList.getLength(); i++) {
  39. String qString = "";
  40. String studyuidString = "";
  41. String modalitiesString = "";
  42. // DicomAttribute节点列表
  43. NodeList dicomAttributeList = xmlHelper.getNodeList(nativeDicomModelList.item(i), "DicomAttribute");
  44. for (int j = 0; j < dicomAttributeList.getLength(); j++) {
  45. // DicomAttribute节点属性列表
  46. NamedNodeMap attributeMap = dicomAttributeList.item(j).getAttributes();
  47. if (attributeMap != null && attributeMap.getLength() > 0) {
  48. for (int k = 0; k < attributeMap.getLength(); k++) {
  49. if (attributeMap.item(k).getNodeName().equals("tag")) {
  50. // 获取studyuid
  51. if (attributeMap.item(k).getNodeValue().equals("0020000D")) {
  52. studyuidString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  53. continue;
  54. }
  55. // 获取检查类型
  56. if (attributeMap.item(k).getNodeValue().equals("00080061")) {
  57. modalitiesString = xmlHelper.getString(dicomAttributeList.item(j), "Value");
  58. }
  59. }
  60. }
  61. }
  62. }
  63. Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
  64. studyuidString);
  65. if (studyidfind == null) {
  66. Record studyinfo = new Record().set("studyuid", studyuidString).set("modalities", modalitiesString)
  67. .set("status", 1).set("createAt", parseStringToDateTime()).set("updateAt", parseStringToDateTime());
  68. Db.use("local").save("study", studyinfo);
  69. }
  70. }
  71. } catch (IOException e) {
  72. // TODO Auto-generated catch block
  73. e.printStackTrace();
  74. }
  75. }
  76. @Override
  77. public void stop() {
  78. // TODO Auto-generated method stub
  79. }
  80. /**
  81. * 日期字符串格式转换年月日
  82. *
  83. * @param dateStr
  84. * @return
  85. */
  86. private String parseStringToDate() {
  87. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  88. Date date = new Date();
  89. long dInteger = date.getTime();
  90. String daString = sdf.format(new Date(dInteger));
  91. return daString;
  92. }
  93. /**
  94. * 日期字符串格式转换年月日时分秒
  95. *
  96. * @param dateStr
  97. * @return
  98. */
  99. private String parseStringToDateTime() {
  100. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  101. Date date = new Date();
  102. String daString = sdf.format(date);
  103. return daString;
  104. }
  105. }