UpdateTask.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.zskk.task;
  2. import java.io.BufferedReader;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. import java.util.List;
  11. import org.w3c.dom.NamedNodeMap;
  12. import org.w3c.dom.NodeList;
  13. import com.jfinal.plugin.activerecord.Db;
  14. import com.jfinal.plugin.activerecord.Record;
  15. import com.jfinal.plugin.cron4j.ITask;
  16. import com.zskk.tools.XmlHelper;
  17. public class UpdateTask implements ITask {
  18. @Override
  19. public void run() {
  20. // TODO Auto-generated method stub
  21. String dateString = parseStringToDate();
  22. String fileString = dateString.replace("0", "o");
  23. File fin_floder = new File("/home/zskk/CFIND_XML/STUDYUID_" + fileString + "1.xml");
  24. // 创建从文件读取数据的FileInputStream流
  25. FileInputStream fin;
  26. try {
  27. fin = new FileInputStream(fin_floder);
  28. InputStreamReader isr = null;
  29. isr = new InputStreamReader(fin);
  30. BufferedReader raf = null;
  31. raf = new BufferedReader(isr);
  32. String s = null;
  33. s = raf.readLine();
  34. s = s.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
  35. s = "<zskk>" + s + "</zskk>";
  36. System.out.println(s);
  37. XmlHelper xmlHelper = XmlHelper.of(s);
  38. NodeList nodeList = xmlHelper.getNodeList("/zskk/NativeDicomModel/DicomAttribute");
  39. for (int i = 0; i < nodeList.getLength(); i++) {
  40. NamedNodeMap as = nodeList.item(i).getAttributes();
  41. if (as != null && as.getLength() > 0) {
  42. for (int j = 0; j < as.getLength(); j++) {
  43. if (as.item(j).getNodeName().equals("tag")) {
  44. if (as.item(j).getNodeValue().equals("0020000D")) {
  45. // String b = xmlHelper.getString("/zskk/NativeDicomModel[" + i + "]/DicomAttribute[" + j + "]/Value");
  46. // System.out.println(xmlHelper.getString(nodeList.item(i), "Value"));
  47. String studyuidString = xmlHelper.getString(nodeList.item(i), "Value");
  48. Record studyidfind = Db.use("local").findFirst("select * from study where studyuid = ?",
  49. studyuidString);
  50. if (studyidfind == null) {
  51. Record studyinfo = new Record().set("studyuid", studyuidString);
  52. Db.use("local").save("study", studyinfo);
  53. }
  54. }
  55. }
  56. }
  57. }
  58. }
  59. } catch (IOException e) {
  60. // TODO Auto-generated catch block
  61. e.printStackTrace();
  62. }
  63. }
  64. @Override
  65. public void stop() {
  66. // TODO Auto-generated method stub
  67. }
  68. /**
  69. * 日期字符串格式转换
  70. *
  71. * @param dateStr
  72. * @return
  73. */
  74. private String parseStringToDate() {
  75. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  76. Date date = new Date();
  77. long dInteger = date.getTime() - 86400000;
  78. String daString = sdf.format(new Date(dInteger));
  79. return daString;
  80. }
  81. }