123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- package com.zskk.control;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.security.KeyManagementException;
- import java.security.NoSuchAlgorithmException;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.UUID;
- import java.util.regex.Matcher;
- import org.apache.commons.io.IOUtils;
- import org.apache.http.NameValuePair;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.entity.UrlEncodedFormEntity;
- import org.apache.http.client.methods.CloseableHttpResponse;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.impl.client.CloseableHttpClient;
- import org.apache.http.impl.client.HttpClients;
- import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
- import org.apache.http.message.BasicNameValuePair;
- import com.alibaba.fastjson.JSON;
- import com.jfinal.core.Controller;
- import com.jfinal.plugin.activerecord.Db;
- import com.jfinal.plugin.activerecord.Record;
- import com.zskk.model.Doctors;
- import com.zskk.model.Exams;
- import com.zskk.model.PatientInfos;
- import com.zskk.model.Report;
- import com.zskk.model.Studies;
- public class ViewController extends Controller {
- private static final PoolingHttpClientConnectionManager POOL_CM = new PoolingHttpClientConnectionManager();
- private static final String CAHR_CODE = "UTF-8";
-
- /**
- * 在被连接数据库执行sql语句
- */
- public void executeSql() {
- try {
- List<Record> d = Db.use("connected").find("select * from (select * from reportinfo order by REPORTDATE desc) where rownum <= 20");
- this.renderJson(d);
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- /**
- * 在被连接数据库执行sql语句
- */
- public void test2() {
- try {
- test();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- public void executeSql2() {
- try {
- String sqlString = this.getPara("str");
- List<Record> d = Db.use("connected").find(sqlString);
- this.renderJson(d);
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- public void testTask() {
- try {
- //List<Record> d = Db.use("connected").find(this.getPara("sqlStr"));
- 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");
- List<Record> examds = new ArrayList<>();
- for (Exams exams2 : exams) {
- Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId());
- Record record = Db.use("connected").findFirst("select * from caller where STUDYUID=?",studies.getStudyuid());
- if (record == null) {
- continue;
- }
- examds.add(record);
- Report report = new Report().use("zskk");
- report.setId(creatId());
- report.setReportDatetime(aaa(record.getStr("REPORTDATE")));
- report.setImpression(record.getStr("IMPRESSION"));
- report.setDescription(record.getStr("DESCRIPTION"));
- report.setExamId(exams2.getId());
- report.setCreatedAt(new Date());
- if (record.getStr("FITEM_RESULT_CODE") != null) {
- //report.setReportResult(record.getStr("FITEM_RESULT_CODE").contains("阴")?"1":"2");
- }
- report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR")));
- report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
- report.setReviewDatetime(aaa(record.getStr("REPORTDATE")));
- report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR")));
- report.setConfirmDatetime(aaa(record.getStr("REPORTDATE")));
- // report.save();
- PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId());
- patientInfos.setName(record.getStr("PATIENTNAME"));
- // patientInfos.update();
- }
- this.renderJson(examds);
- } catch (Exception e) {
- // TODO: handle exception
- this.renderText(e.toString());
- }
- }
-
- private String creatId() {
- UUID id = UUID.randomUUID();
- String[] idd =id.toString().split("-");
- return idd[0]+idd[1]+idd[2];
- }
-
- private String getDoctorIdByName(String name) {
- if (name == null) {
- return "1";
- }
- Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=73090001",name);
- if (doctors == null) {
- return "1";
- }
- return doctors.getId();
- }
-
- private Date aaa(String timestr) {
- if (timestr == null) {
- return new Date();
- }
- SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = null;
- try {
- date = sdf.parse(timestr);
- } catch (ParseException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return date;
- }
-
- public void test() throws IOException {
- //第一步:创建服务地址
- URL url = new URL("http://10.84.138.254:8080/services/getReportByStudyuid?wsdl");
- //第二步:打开一个通向服务地址的连接
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- //第三步:设置参数
- //3.1发送方式设置:POST必须大写
- connection.setRequestMethod("POST");
- //3.2设置数据格式:content-type
- connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
- //3.3设置输入输出,因为默认新创建的connection没有读写权限,
- connection.setDoInput(true);
- connection.setDoOutput(true);
-
- //第四步:组织SOAP数据,发送请求
- String soapXML = getXML("17321242779");
- OutputStream os = connection.getOutputStream();
- os.write(soapXML.getBytes());
- //第五步:接收服务端响应,打印
- int responseCode = connection.getResponseCode();
- if(200 == responseCode){//表示服务端响应成功
- InputStream is = connection.getInputStream();
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
-
- StringBuilder sb = new StringBuilder();
- String temp = null;
- while(null != (temp = br.readLine())){
- sb.append(temp);
- }
-
- /**
- * 打印结果
- */
- System.out.println(sb.toString());
- render(String.valueOf(responseCode));
- is.close();
- isr.close();
- br.close();
- }
- os.close();
-
- }
-
- public static String getXML(String phone){
-
- String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
- +"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2003/XMLSchema-instance\" "
- +"xmlns:web=\"http://WebXml.com.cn/\" "
- +"xmlns:xsd=\"http://www.w3.org/2003/XMLSchema\" "
- +"xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
- +"<request>"
- +"<studyuid>"
- +"0200355"
- +"</studyuid>"
- +"</request>"
- +"</soap:Envelope>";
- return soapXML;
- }
-
- }
|