ViewController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package com.zskk.control;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.InputStreamReader;
  6. import java.io.OutputStream;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.security.KeyManagementException;
  11. import java.security.NoSuchAlgorithmException;
  12. import java.text.ParseException;
  13. import java.text.SimpleDateFormat;
  14. import java.util.ArrayList;
  15. import java.util.Date;
  16. import java.util.HashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.UUID;
  20. import java.util.regex.Matcher;
  21. import org.apache.commons.io.IOUtils;
  22. import org.apache.http.NameValuePair;
  23. import org.apache.http.client.ClientProtocolException;
  24. import org.apache.http.client.entity.UrlEncodedFormEntity;
  25. import org.apache.http.client.methods.CloseableHttpResponse;
  26. import org.apache.http.client.methods.HttpPost;
  27. import org.apache.http.impl.client.CloseableHttpClient;
  28. import org.apache.http.impl.client.HttpClients;
  29. import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
  30. import org.apache.http.message.BasicNameValuePair;
  31. import com.alibaba.fastjson.JSON;
  32. import com.jfinal.core.Controller;
  33. import com.jfinal.plugin.activerecord.Db;
  34. import com.jfinal.plugin.activerecord.Record;
  35. import com.zskk.model.Doctors;
  36. import com.zskk.model.Exams;
  37. import com.zskk.model.PatientInfos;
  38. import com.zskk.model.Report;
  39. import com.zskk.model.Studies;
  40. public class ViewController extends Controller {
  41. private static final PoolingHttpClientConnectionManager POOL_CM = new PoolingHttpClientConnectionManager();
  42. private static final String CAHR_CODE = "UTF-8";
  43. /**
  44. * 在被连接数据库执行sql语句
  45. */
  46. public void executeSql() {
  47. try {
  48. List<Record> d = Db.use("connected").find("select * from (select * from reportinfo order by REPORTDATE desc) where rownum <= 20");
  49. this.renderJson(d);
  50. } catch (Exception e) {
  51. // TODO: handle exception
  52. this.renderText(e.toString());
  53. }
  54. }
  55. /**
  56. * 在被连接数据库执行sql语句
  57. */
  58. public void test2() {
  59. try {
  60. test();
  61. } catch (IOException e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. }
  65. }
  66. public void executeSql2() {
  67. try {
  68. String sqlString = this.getPara("str");
  69. List<Record> d = Db.use("connected").find(sqlString);
  70. this.renderJson(d);
  71. } catch (Exception e) {
  72. // TODO: handle exception
  73. this.renderText(e.toString());
  74. }
  75. }
  76. public void testTask() {
  77. try {
  78. //List<Record> d = Db.use("connected").find(this.getPara("sqlStr"));
  79. List<Exams> exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=73090001 order by createdAt desc limit 50");
  80. List<Record> examds = new ArrayList<>();
  81. for (Exams exams2 : exams) {
  82. Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
  83. Record record = Db.use("connected").findFirst("select * from caller where STUDYUID=?",studies.getStudyuid());
  84. if (record == null) {
  85. continue;
  86. }
  87. examds.add(record);
  88. Report report = new Report().use("zskk");
  89. report.setId(creatId());
  90. report.setReportDatetime(aaa(record.getStr("REPORTDATE")));
  91. report.setImpression(record.getStr("IMPRESSION"));
  92. report.setDescription(record.getStr("DESCRIPTION"));
  93. report.setExamId(exams2.getId());
  94. report.setCreatedAt(new Date());
  95. if (record.getStr("FITEM_RESULT_CODE") != null) {
  96. //report.setReportResult(record.getStr("FITEM_RESULT_CODE").contains("阴")?"1":"2");
  97. }
  98. report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
  99. report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  100. report.setReviewDatetime(aaa(record.getStr("REPORTDATE")));
  101. report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
  102. report.setConfirmDatetime(aaa(record.getStr("REPORTDATE")));
  103. // report.save();
  104. PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
  105. patientInfos.setName(record.getStr("PATIENTNAME"));
  106. // patientInfos.update();
  107. }
  108. this.renderJson(examds);
  109. } catch (Exception e) {
  110. // TODO: handle exception
  111. this.renderText(e.toString());
  112. }
  113. }
  114. private String creatId() {
  115. UUID id = UUID.randomUUID();
  116. String[] idd =id.toString().split("-");
  117. return idd[0]+idd[1]+idd[2];
  118. }
  119. private String getDoctorIdByName(String name) {
  120. if (name == null) {
  121. return "1";
  122. }
  123. Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=73090001",name);
  124. if (doctors == null) {
  125. return "1";
  126. }
  127. return doctors.getId();
  128. }
  129. private Date aaa(String timestr) {
  130. if (timestr == null) {
  131. return new Date();
  132. }
  133. SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  134. Date date = null;
  135. try {
  136. date = sdf.parse(timestr);
  137. } catch (ParseException e) {
  138. // TODO Auto-generated catch block
  139. e.printStackTrace();
  140. }
  141. return date;
  142. }
  143. public void test() throws IOException {
  144. //第一步:创建服务地址
  145. URL url = new URL("http://10.84.138.254:8080/services/getReportByStudyuid?wsdl");
  146. //第二步:打开一个通向服务地址的连接
  147. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  148. //第三步:设置参数
  149. //3.1发送方式设置:POST必须大写
  150. connection.setRequestMethod("POST");
  151. //3.2设置数据格式:content-type
  152. connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
  153. //3.3设置输入输出,因为默认新创建的connection没有读写权限,
  154. connection.setDoInput(true);
  155. connection.setDoOutput(true);
  156. //第四步:组织SOAP数据,发送请求
  157. String soapXML = getXML("17321242779");
  158. OutputStream os = connection.getOutputStream();
  159. os.write(soapXML.getBytes());
  160. //第五步:接收服务端响应,打印
  161. int responseCode = connection.getResponseCode();
  162. if(200 == responseCode){//表示服务端响应成功
  163. InputStream is = connection.getInputStream();
  164. InputStreamReader isr = new InputStreamReader(is);
  165. BufferedReader br = new BufferedReader(isr);
  166. StringBuilder sb = new StringBuilder();
  167. String temp = null;
  168. while(null != (temp = br.readLine())){
  169. sb.append(temp);
  170. }
  171. /**
  172. * 打印结果
  173. */
  174. System.out.println(sb.toString());
  175. render(String.valueOf(responseCode));
  176. is.close();
  177. isr.close();
  178. br.close();
  179. }
  180. os.close();
  181. }
  182. public static String getXML(String phone){
  183. String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
  184. +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2003/XMLSchema-instance\" "
  185. +"xmlns:web=\"http://WebXml.com.cn/\" "
  186. +"xmlns:xsd=\"http://www.w3.org/2003/XMLSchema\" "
  187. +"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
  188. +"<request>"
  189. +"<studyuid>"
  190. +"0200355"
  191. +"</studyuid>"
  192. +"</request>"
  193. +"</soap:Envelope>";
  194. return soapXML;
  195. }
  196. }