ViewController.java 5.2 KB

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