ViewController.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package com.zskk.control;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.UUID;
  8. import com.jfinal.core.Controller;
  9. import com.jfinal.plugin.activerecord.Db;
  10. import com.jfinal.plugin.activerecord.Record;
  11. import com.zskk.model.Doctors;
  12. import com.zskk.model.Exams;
  13. import com.zskk.model.PatientInfos;
  14. import com.zskk.model.Report;
  15. import com.zskk.model.Studies;
  16. import com.zskk.service.ServiceFactory;
  17. import com.zskk.service.WeixinService;
  18. public class ViewController extends Controller {
  19. /**
  20. * 在被连接数据库执行sql语句
  21. */
  22. public void executeSql() {
  23. try {
  24. List<Record> d = Db.use("connected").find("select * from (select * from reportinfo order by REPORTDATE desc) where rownum <= 20");
  25. this.renderJson(d);
  26. } catch (Exception e) {
  27. // TODO: handle exception
  28. this.renderText(e.toString());
  29. }
  30. }
  31. public void executeSql2() {
  32. try {
  33. String sqlString = this.getPara("str");
  34. List<Record> d = Db.use("connected").find(sqlString);
  35. this.renderJson(d);
  36. } catch (Exception e) {
  37. // TODO: handle exception
  38. this.renderText(e.toString());
  39. }
  40. }
  41. public void testTask() {
  42. try {
  43. //List<Record> d = Db.use("connected").find(this.getPara("sqlStr"));
  44. // List<Exams> examsd = new ArrayList<Exams>();
  45. List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=44000003 order by createdAt desc limit 100");
  46. for (Exams exams2 : exams) {
  47. Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  48. Record recordTemp = Db.use("connected").findFirst("select * from v_all_img_idx@PACSINTERFACE where F_STU_UID=?",studies.getStudyuid());
  49. if (recordTemp == null) {
  50. continue;
  51. }
  52. Record record = Db.use("connected").findFirst("select * from yxjK where STUDYUID=?",recordTemp.getStr("F_STU_NO"));
  53. if (record == null) {
  54. continue;
  55. }
  56. Report report = new Report().use("zskk");
  57. report.setId(creatId());
  58. report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  59. if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) {
  60. continue;
  61. }
  62. // report.setImpression(record.getStr("IMPRESSION"));
  63. // report.setDescription(record.getStr("DESCRIPTION"));
  64. // report.setExamId(exams2.getId());
  65. // report.setCreatedAt(new Date());
  66. // report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
  67. // report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  68. // report.setReviewDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  69. // report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  70. // report.setConfirmDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  71. // report.save();
  72. // PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  73. // patientInfos.setName(record.getStr("PATIENTNAME"));
  74. // patientInfos.setPhone(record.getStr("PHONE"));
  75. // patientInfos.setCardNum(record.getStr("IDCARD"));
  76. // patientInfos.update();
  77. // exams2.setApplicationDepartment(record.getStr("DEPATMENT"));
  78. // exams2.setApplicationDoctor(record.getStr("CLINICALDOCTOR"));
  79. // exams2.setExamStatus(9);
  80. // exams2.update();
  81. // WeixinService wService = ServiceFactory.getService(WeixinService.class);
  82. // wService.requestWeixinQrcode(report.getId());
  83. // examsd.add(exams2);
  84. }
  85. this.renderJson(exams);
  86. } catch (Exception e) {
  87. // TODO: handle exception
  88. String aaString = "";
  89. StackTraceElement[] stackTraceElements=Thread.currentThread().getStackTrace();
  90. System.out.println("The stackTraceElements length:"+stackTraceElements.length);
  91. for(int i=0;i<stackTraceElements.length;i++){
  92. int d = stackTraceElements[i].getLineNumber();
  93. aaString = aaString + String.valueOf(d)+"***"+stackTraceElements[i].getMethodName()+"****";
  94. }
  95. this.renderText(aaString+e.toString());
  96. }
  97. }
  98. private String creatId() {
  99. UUID id = UUID.randomUUID();
  100. String[] idd =id.toString().split("-");
  101. return idd[0]+idd[1]+idd[2];
  102. }
  103. private String getDoctorIdByName(String name) {
  104. if (name == null) {
  105. return "1";
  106. }
  107. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=44000003",name);
  108. if (doctors == null) {
  109. return "1";
  110. }
  111. return doctors.getId();
  112. }
  113. private Date parseStringToDate(String dateStr) {
  114. if (dateStr == null) {
  115. return new Date();
  116. }
  117. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  118. Date date = null;
  119. try {
  120. date = sdf.parse(dateStr);
  121. } catch (ParseException e) {
  122. // TODO Auto-generated catch block
  123. e.printStackTrace();
  124. }
  125. return date;
  126. }
  127. }