package com.zskk.control; 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.model.Doctors; import com.zskk.model.Exams; import com.zskk.model.PatientInfos; import com.zskk.model.Report; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.UUID; public class ViewController extends Controller { /** * 在被连接数据库执行sql语句 */ public void executeSql() { try { List 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()); } } public void executeSql2() { try { String sqlString = this.getPara("str"); List d = Db.use("connected").find(sqlString); this.renderJson(d); } catch (Exception e) { // TODO: handle exception this.renderText(e.toString()); } } public void executeSql3() { 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 static DruidPlugin createConnectedDruidPlugin() { return new DruidPlugin(PropKit.get("jdbcUrl_connected"), PropKit.get("user_connected"),PropKit.get("password_connected").trim()); } public void testTask() { try { //List d = Db.use("connected").find(this.getPara("sqlStr")); List exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=81069903 order by createdAt desc limit 50"); List examds = new ArrayList<>(); for (Exams exams2 : exams) { // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId()); Record record = Db.use("connected").findFirst("select * from hhris.view_reportinfo where ACCESSIONNUMBER=?",exams2.getAccessionNum()); if (record == null) { continue; } Report report = new Report().use("zskk"); report.setId(creatId()); report.setReportDatetime(parseStringToDate(record.getStr("REPORTDATE"))); if (record.getStr("IMPRESSION") == null && record.getStr("DESCRIPTION") == null) { continue; } report.setImpression(new String(record.getStr("DESCRIPTION").getBytes("windows-1252"),"GBK")); report.setDescription(new String(record.getStr("IMPRESSION").getBytes("windows-1252"),"GBK")); report.setExamId(exams2.getId()); report.setCreatedAt(new Date()); report.setReportDoctorId(getDoctorIdByName(new String(record.getStr("REPORTDOCTOR").getBytes("windows-1252"),"GBK"))); report.setReviewDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK"))); report.setReviewDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK"))); report.setConfirmDoctorId(getDoctorIdByName(new String(record.getStr("REVIEWDOCTOR").getBytes("windows-1252"),"GBK"))); report.setConfirmDatetime(parseStringToDate(new String(record.getStr("REPORTDATE").getBytes("windows-1252"),"GBK"))); report.save(); PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId()); patientInfos.setName(new String(record.getStr("PATIENTNAME").getBytes("windows-1252"),"GBK")); patientInfos.update(); exams2.setClinDoctors(new String(record.getStr("CLINICALDOCTOR").getBytes("windows-1252"),"GBK")); exams2.setExamStatus(9); exams2.update(); examds.add(record); } 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=81069903",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; } 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; } }