ViewController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package com.zskk.control;
  2. import com.jfinal.core.Controller;
  3. import com.jfinal.kit.PropKit;
  4. import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
  5. import com.jfinal.plugin.activerecord.Db;
  6. import com.jfinal.plugin.activerecord.Record;
  7. import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;
  8. import com.jfinal.plugin.druid.DruidPlugin;
  9. import com.zskk.model.Doctors;
  10. import com.zskk.model.Exams;
  11. import com.zskk.model.PatientInfos;
  12. import com.zskk.model.Report;
  13. import com.zskk.model.Studies;
  14. import com.zskk.service.ServiceFactory;
  15. import com.zskk.service.WeixinService;
  16. import java.text.ParseException;
  17. import java.text.SimpleDateFormat;
  18. import java.util.ArrayList;
  19. import java.util.Date;
  20. import java.util.List;
  21. import java.util.UUID;
  22. public class ViewController extends Controller {
  23. /**
  24. * 在被连接数据库执行sql语句
  25. */
  26. public void executeSql() {
  27. try {
  28. List<Record> d = Db.use("connected").find("select * from (select * from reportinfo order by REPORTDATE desc) where rownum <= 20");
  29. this.renderJson(d);
  30. } catch (Exception e) {
  31. // TODO: handle exception
  32. this.renderText(e.toString());
  33. }
  34. }
  35. public void executeSql2() {
  36. try {
  37. String sqlString = this.getPara("str");
  38. List<Record> d = Db.use("connected").find(sqlString);
  39. this.renderJson(d);
  40. } catch (Exception e) {
  41. // TODO: handle exception
  42. this.renderText(e.toString());
  43. }
  44. }
  45. public void executeSql3() {
  46. try {
  47. DruidPlugin druidPluginConnected = createConnectedDruidPlugin();
  48. druidPluginConnected.start();
  49. // 配置ActiveRecord插件
  50. ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected);
  51. arpConnected.setDialect(new SqlServerDialect());
  52. arpConnected.start();
  53. } catch (Exception e) {
  54. // TODO: handle exception
  55. this.renderText(e.toString());
  56. }
  57. }
  58. public static DruidPlugin createConnectedDruidPlugin() {
  59. return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim());
  60. }
  61. public void testTask() {
  62. try {
  63. List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=81069902 order by createdAt desc limit 30");
  64. for (Exams exams2 : exams) {
  65. try {
  66. Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  67. Record record = Db.use("connected").findFirst("select * from PACSONLINE_Interface where STUDYUID=?",studies.getStudyuid());
  68. if (record == null) {
  69. continue;
  70. }
  71. Report report = new Report().use("zskk");
  72. report.setId(creatId());
  73. report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  74. if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) {
  75. continue;
  76. }
  77. report.setImpression(record.getStr("IMPRESSION"));
  78. report.setDescription(record.getStr("DESCRIPTION"));
  79. report.setExamId(exams2.getId());
  80. report.setCreatedAt(new Date());
  81. report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
  82. report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  83. report.setReviewDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  84. report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  85. report.setConfirmDatetime(parseStringToDate(record.getStr("REPORTDATE")));
  86. report.save();
  87. PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  88. patientInfos.setName(record.getStr("PATIENTNAME"));
  89. // patientInfos.setPhone(record.getStr("telephone"));
  90. patientInfos.setCardNum(record.getStr("IDCARD"));
  91. patientInfos.update();
  92. exams2.setExamStatus(9);
  93. exams2.setApplicationDepartment(record.getStr("DEPARTMENT"));
  94. exams2.setApplicationDoctor(record.getStr("CLINICALDOCTOR"));
  95. exams2.update();
  96. WeixinService wService = ServiceFactory.getService(WeixinService.class);
  97. wService.requestWeixinQrcode(report.getId());
  98. } catch (Exception e) {
  99. // TODO: handle exception
  100. continue;
  101. }
  102. }
  103. } catch (Exception e) {
  104. // TODO: handle exception
  105. this.renderText(e.toString());
  106. }
  107. }
  108. private String creatId() {
  109. UUID id = UUID.randomUUID();
  110. String[] idd =id.toString().split("-");
  111. return idd[0]+idd[1]+idd[2];
  112. }
  113. private String getDoctorIdByName(String name) {
  114. if (name == null) {
  115. return null;
  116. }
  117. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=81069902 and realname<>''", name);
  118. if (doctors == null) {
  119. Doctors newDoctors = new Doctors().use("zskk");
  120. newDoctors.setId(creatId());
  121. newDoctors.setUsername("none");
  122. newDoctors.setRealname(name);
  123. newDoctors.setPassword("123456");
  124. newDoctors.setInstitutionId("81069902");
  125. newDoctors.setCreatedAt(new Date());
  126. newDoctors.setUpdatedAt(new Date());
  127. newDoctors.save();
  128. return newDoctors.getId();
  129. }
  130. return doctors.getId();
  131. }
  132. private Date parseStringToDate(String dateStr) {
  133. if (dateStr == null) {
  134. return new Date();
  135. }
  136. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  137. Date date = null;
  138. try {
  139. date = sdf.parse(dateStr);
  140. } catch (ParseException e) {
  141. // TODO Auto-generated catch block
  142. e.printStackTrace();
  143. }
  144. return date;
  145. }
  146. }