package com.zskk.control; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jfinal.core.Controller; import com.jfinal.kit.PropKit; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.activerecord.dialect.SqlServerDialect; import com.jfinal.plugin.druid.DruidPlugin; import com.zskk.service.DataService; import com.zskk.service.ServiceFactory; import com.zskk.service.ThreadPoolService; import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; public class ViewController extends Controller { private static final MediaType JSON_CODE = MediaType.get("application/json; charset=utf-8"); private static final OkHttpClient OKHTTP_CLIENT = new OkHttpClient(); /** * 在被连接数据库执行sql语句 */ public void executeSql() { try { List d = Db.use("connected").find(this.getPara("sqlstr")); this.renderJson(d); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } /** * 在被连接数据库执行sql语句 */ public void executeSqlUpdate() { try { Integer d = Db.use("connected").update(this.getPara("sqlstr")); this.renderText(d.toString()); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void testConn() { try { DruidPlugin druidPluginConnected = createConnectedDruidPlugin(); druidPluginConnected.start(); // 配置ActiveRecord插件 ActiveRecordPlugin arpConnected = new ActiveRecordPlugin("connected", druidPluginConnected); arpConnected.setDialect(new SqlServerDialect()); arpConnected.start(); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void sd() { try { DataService dService = ServiceFactory.getService(DataService.class); JSONArray jsonArray = dService.getBindList(parseStringToDate(),parseStringToDate()); for (Object object : jsonArray) { try { JSONObject jsonObject = JSON.parseObject(object.toString()); String source = ""; switch (jsonObject.getString("source")) { case "1": source="数字影像云公众号"; break; case "2": source="集成链接"; break; case "3": source="推送短信"; break; default: break; } Record recordei = Db.use("connected").findFirst("select * from examinfo where studyuid=?", jsonObject.getString("studyuid")); Record recordrc = Db.use("connected").findFirst("select * from reportcheck where studyuid=?", jsonObject.getString("studyuid")); Record recordri = Db.use("connected").findFirst("select * from reportinfo where studyuid=?", jsonObject.getString("studyuid")); if (recordei==null || recordrc==null || recordri==null) { continue; } recordei.set("ViewFlag", "1"); recordrc.set("ViewFlag", "1"); recordri.set("ViewFlag", "1"); recordei.set("ViewTime", jsonObject.getString("createdAt")); recordrc.set("ViewTime", jsonObject.getString("createdAt")); recordri.set("ViewTime", jsonObject.getString("createdAt")); recordei.set("ViewName", jsonObject.getString("name") + "_"+ source); recordrc.set("ViewName", jsonObject.getString("name") + "_"+ source); recordri.set("ViewName", jsonObject.getString("name") + "_"+ source); Db.use("connected").update("examinfo", recordei); Db.use("connected").update("reportcheck", recordrc); Db.use("connected").update("reportinfo", recordri); } catch (Exception e) { // TODO: handle exception // continue; renderText(e.toString()); } } } catch (Exception e) { // TODO: handle exception renderText(e.toString()); } renderText("succeed"); } public void st() { try { DataService dService = ServiceFactory.getService(DataService.class); Record record = Db.use("connected").findFirst("select * from reportcheck where studyuid=?",this.getPara("code")); Map params = new HashMap<>(); // 1:exam_id 2:patient_num 3:accession_num 4:study_uid params.put("type", "4"); params.put("institution_id", PropKit.get("institution_id")); params.put("code", record.getStr("studyuid")); // 报告医生姓名 params.put("report_doctor_name", record.getStr("reportdoctor")); // 报告时间 params.put("report_datetime", record.getStr("reportdate")); // 审核医生姓名 params.put("review_doctor_name", record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor")); // 审核时间 params.put("review_datetime", record.getStr("reportdate")); // 确认医生姓名 params.put("confirm_doctor_name", record.getStr("reviewdoctor") == null ? "" : record.getStr("reviewdoctor")); // 确认时间 params.put("confirm_datetime", record.getStr("reportdate")); // 意见建议 params.put("impression", record.getStr("impression")); // 影像所见 params.put("description", record.getStr("description")); // exams表 // 申请科室 params.put("application_department", record.getStr("department")); // 申请医生 params.put("application_doctor", record.getStr("clinicaldoctor")); // 临床诊断 params.put("clin_diag", record.getStr("diagnosis") == null ? "" : record.getStr("diagnosis")); // 症状 params.put("clin_symp", record.getStr("symptom")); // patient_infos表 // 患者姓名 params.put("name", record.getStr("patientname")); // 患者手机号 params.put("phone", record.getStr("phone")); // 患者身份证号 params.put("card_num", record.getStr("idcard")); // 检查结果1阴2阳 params.put("report_result", "0"); // 门诊号住院号 params.put("hopitalized_no", ""); String x =dService.saveReport(params); renderText(x); } catch (Exception e) { // TODO: handle exception renderText(e.toString()); } } public static DruidPlugin createConnectedDruidPlugin() { return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim()); } /** * post请求 * @param url-请求地址 * @param map-参数集合 * @return */ private static String doPost(String url, Map map) { FormBody.Builder builder = new FormBody.Builder(); for (String key : map.keySet()) { builder.add(key, map.get(key)); } RequestBody formBody = builder.build(); Request request = new Request.Builder().url(url).post(formBody).build(); try (Response response = OKHTTP_CLIENT.newCall(request).execute()) { if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); String content = response.body().string(); return content; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } } /** * 日期字符串格式转换 * @param dateStr * @return */ private Date parseStringToDate(String dateStr) { if (dateStr == null) { return new Date(); } SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = null; try { date = sdf.parse(dateStr); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } return date; } private String parseStringToDate() { SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); String timeString = sdf.format(date); return timeString; } public static void main(String[] args) { Map paramsMap=new HashMap(); paramsMap.put("institution_id", "44100001"); String contentString = doPost("https://risserver3.pacsonline.cn/butt/getExam/butt/getExam", paramsMap); System.out.println(contentString); } }