package com.zskk.task; import com.jfinal.plugin.activerecord.Db; import com.jfinal.plugin.activerecord.Record; import com.jfinal.plugin.cron4j.ITask; import com.zskk.model.*; import com.zskk.service.ServiceFactory; import com.zskk.service.WeixinService; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.UUID; public class DataTask implements ITask { @Override public void run() { // TODO Auto-generated method stub try { List exams = Exams.dao.use("zskk").find("SELECT * FROM pacsonline.exams where exam_status=3 and institution_id=04500002 order by createdAt desc limit 30"); for (Exams exams2 : exams) { try { // Studies studies = Studies.dao.use("zskk").findById(exams2.getStudyId()); Record record = Db.use("connected").findFirst("select * from (SELECT * FROM zlhis.zskk_reportinfo zs INNER JOIN zlhis.zskk_reportinfo_1 zskk ON zs.ACCESSIONNUMBER = zskk.ACCESSIONNUMBER order by REPORTDATE desc ) 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(record.getStr("IMPRESSION")); report.setDescription(record.getStr("DESCRIPTION")); report.setExamId(exams2.getId()); report.setCreatedAt(new Date()); report.setReportDoctorId(getDoctorIdByName(record.getStr("REPORTDOCTOR"))); report.setReviewDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR"))); report.setReviewDatetime(parseStringToDate(record.getStr("REPORTDATE"))); report.setConfirmDoctorId(getDoctorIdByName(record.getStr("REVIEWDOCTOR"))); report.setConfirmDatetime(parseStringToDate(record.getStr("REPORTDATE"))); report.save(); PatientInfos patientInfos = PatientInfos.dao.use("zskk").findById(exams2.getPatientId()); patientInfos.setName(record.getStr("PATIENTNAME")); patientInfos.setPhone(record.getStr("PHONE")); patientInfos.setCardNum(record.getStr("IDCARD")); patientInfos.update(); exams2.setExamStatus(9); exams2.setApplicationDepartment(record.getStr("DEPARTMENT")); exams2.setApplicationDoctor(record.getStr("CLINICALDOCTOR")); exams2.setClinDiag(record.getStr("DIAGNOSIS")); exams2.update(); WeixinService wService = ServiceFactory.getService(WeixinService.class); wService.requestWeixinQrcode(report.getId()); } catch (Exception e) { // TODO: handle exception continue; } } } catch (Exception e) { // TODO: handle exception } } @Override public void stop() { // TODO Auto-generated method stub } 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 null; } Doctors doctors = Doctors.dao.use("zskk").findFirst("SELECT * FROM doctors where instr(?,realname) and institution_id=04500002 and realname<>''",name); if (doctors == null) { Doctors newDoctors = new Doctors().use("zskk"); newDoctors.setId(creatId()); newDoctors.setUsername("none"); newDoctors.setRealname(name); newDoctors.setPassword("123456"); newDoctors.setInstitutionId("04500002"); newDoctors.setCreatedAt(new Date()); newDoctors.setUpdatedAt(new Date()); newDoctors.save(); return newDoctors.getId(); //return null; } return doctors.getId(); } 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; } }