package com.yihu.jw.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.yihu.jw.entity.base.patient.BasePatientDO; import com.yihu.jw.entity.base.sms.SmsTemplateDO; import com.yihu.jw.entity.base.wx.WxPushLogDO; import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO; import com.yihu.jw.entity.hospital.prescription.WlyyInspectionDO; import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO; import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO; import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao; import com.yihu.jw.hospital.prescription.dao.WlyyInspectionDao; import com.yihu.jw.patient.dao.BasePatientDao; import com.yihu.jw.sms.dao.BaseSmsTemplateDao; import com.yihu.jw.sms.util.ykyy.client.SmsClient; import com.yihu.jw.sms.util.ykyy.vo.ResultMsg; import com.yihu.jw.util.common.IdCardUtil; import com.yihu.jw.util.date.DateUtil; import com.yihu.jw.wechat.dao.WxPushLogDao; import com.yihu.utils.network.HttpResponse; import com.yihu.utils.network.HttpUtils; import org.apache.commons.collections.map.HashedMap; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Date; import java.util.List; import java.util.Map; /** * Created by Trick on 2020/3/19. */ @Service public class YkyySMSService { private static final Logger logger = LoggerFactory.getLogger(YkyySMSService.class); private final String usrCode ="300643"; private final String pw ="T9IHN69DDF"; private final String urlSms ="https://smsapp.wlwx.com"; private final static String url="http://192.168.20.55:10023/ykyy/createSQLQuery"; @Autowired private BaseSmsTemplateDao smsTemplateDao; @Autowired private WlyyInspectionDao inspectionDao; @Autowired private BasePatientDao basePatientDao; @Autowired private WxPushLogDao wxPushLogDao; @Autowired private WlyyHospitalSysDictDao wlyyHospitalSysDictDao; /** * 发送短信验证码 * @param mobile * @param content * @return */ public ResultMsg ykyySendSMS(String mobile, String content){ SmsClient smsClient = new SmsClient(); return smsClient.sendSms("ykyy",usrCode, content,mobile,"yes","","8",urlSms,pw); } public void sendSmsByTempcode(String temlateCode, WlyyOutpatientDO wlyyOutpatientDO, WlyyPrescriptionDO wlyyPrescriptionDO,String doctorMobile){ SmsTemplateDO smsTemplateDO = null; String content=""; String sex = "先生/女士"; String mobile = ""; //由于审方情况比较特殊单独标记下 WxPushLogDO wxPushLogDO = null; WxPushLogDO wxPushLogDODoctor = null; //新增字典判断是否发送短信 String sendMesControl = "1";//1 开启发送短信 0 关闭 WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("ykSmsControl"); if (wlyyHospitalSysDictDO!=null){ sendMesControl = wlyyHospitalSysDictDO.getDictValue(); } if("check_failed".equalsIgnoreCase(temlateCode)){ wxPushLogDO = wxPushLogDao.findByTempNameAndOpenidAndReceiver(temlateCode,wlyyOutpatientDO.getId(),wlyyOutpatientDO.getPatient()); wxPushLogDODoctor = wxPushLogDao.findByTempNameAndOpenidAndReceiver(temlateCode,wlyyOutpatientDO.getId(),wlyyOutpatientDO.getDoctor()); }else { wxPushLogDO = wxPushLogDao.findByTempNameAndOpenid(temlateCode,wlyyOutpatientDO.getId()); } if (wlyyOutpatientDO!=null){ if (StringUtils.isNoneBlank(wlyyOutpatientDO.getIdcard())){ String sexNo = IdCardUtil.getSexForIdcard_new(wlyyOutpatientDO.getIdcard()); if ("1".equalsIgnoreCase(sexNo)){ sex = "先生"; }else if ("2".equalsIgnoreCase(sexNo)){ sex = "女士"; } } BasePatientDO basePatientDO = basePatientDao.findById(wlyyOutpatientDO.getPatient()); if (basePatientDO!=null&&StringUtils.isNoneBlank(basePatientDO.getMobile())){ mobile = basePatientDO.getMobile(); }else { mobile=wlyyOutpatientDO.getMobile(); } } logger.info("temlateCode"+temlateCode+"==mobile:"+mobile); try { if ("prescription_remind".equalsIgnoreCase(temlateCode)){//开具处方提醒 smsTemplateDO = smsTemplateDao.findByClientId("prescription_remind"); if (smsTemplateDO!=null){ content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{时间}}", DateUtil.dateToStrLong(wlyyPrescriptionDO.getCreateTime())) .replace("{{处方编号}}",wlyyPrescriptionDO.getRealOrder()).replace("{{性别}}",sex); if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); } } }else if ("outpatient_remind".equalsIgnoreCase(temlateCode)){//患者发起复诊给医生发送消息 smsTemplateDO = smsTemplateDao.findByClientId("outpatient_remind"); if (smsTemplateDO!=null){ if ("1".equalsIgnoreCase(wlyyOutpatientDO.getType())&&"1".equalsIgnoreCase(wlyyOutpatientDO.getOutpatientType())){ content = smsTemplateDO.getContent(); if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ ykyySendSMS(doctorMobile,smsTemplateDO.getHeader()+content); wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getDoctor()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); } }else if ("2".equalsIgnoreCase(wlyyOutpatientDO.getType())&&"1".equalsIgnoreCase(wlyyOutpatientDO.getOutpatientType())){ content = smsTemplateDO.getContent().replace("图文","视频"); if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ ykyySendSMS(doctorMobile,smsTemplateDO.getHeader()+content); wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getDoctor()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); } } } }else if ("message_remind_paitent".equalsIgnoreCase(temlateCode)){//医生发消息发送短信提醒 smsTemplateDO = smsTemplateDao.findByClientId("message_remind_paitent"); if (smsTemplateDO!=null){ content = smsTemplateDO.getContent().replace("{{医生姓名}}",wlyyOutpatientDO.getDoctorName()); if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); } } }else if ("oneself_pick".equalsIgnoreCase(temlateCode)){//病人自取 smsTemplateDO = smsTemplateDao.findByClientId("oneself_pick"); if (smsTemplateDO!=null){ content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{时间}}",DateUtil.dateToStrLong(wlyyPrescriptionDO.getCreateTime())).replace("{{门诊号码}}",wlyyOutpatientDO.getRealOrder()) .replace("{{性别}}",sex); if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); } } }else if("check_failed".equalsIgnoreCase(temlateCode)){//处方审核失败 smsTemplateDO = smsTemplateDao.findByClientId("check_failed_patient"); if (smsTemplateDO!=null){ content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{处方编号}}",wlyyPrescriptionDO.getRealOrder()).replace("{{性别}}",sex);; if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); } } SmsTemplateDO smsTemplateDO1 = smsTemplateDao.findByClientId("check_failed_doctor"); if (smsTemplateDO1!=null){ String contentDoctor = smsTemplateDO1.getContent().replace("{{医生姓名}}",wlyyOutpatientDO.getDoctorName()).replace("{{时间}}",DateUtil.dateToStrLong(wlyyPrescriptionDO.getCreateTime())) .replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{处方编号}}",wlyyPrescriptionDO.getRealOrder()); if (wxPushLogDODoctor==null&&"1".equalsIgnoreCase(sendMesControl)){ wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getDoctor()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); ykyySendSMS(doctorMobile,smsTemplateDO1.getHeader()+contentDoctor); } } }else if ("check_success_patient".equalsIgnoreCase(temlateCode)){//处方审核通过 smsTemplateDO = smsTemplateDao.findByClientId("check_success_patient"); if (smsTemplateDO!=null&&wlyyOutpatientDO!=null){ content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{处方编号}}",wlyyPrescriptionDO.getRealOrder()).replace("{{性别}}",sex);; if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); } } }else if ("inspection_remind".equalsIgnoreCase(temlateCode)){//处方审核通过 smsTemplateDO = smsTemplateDao.findByClientId("inspection_remind"); if (smsTemplateDO!=null&&wlyyOutpatientDO!=null){ String medicard = ""; Integer brxb = 0; String mzhm ="0"; //如果患者医保卡不为空则用社保卡 否则用mzhm if(StringUtils.isNoneBlank(wlyyOutpatientDO.getCardNo())){ medicard = wlyyOutpatientDO.getCardNo(); JSONArray jsonArray3 = findHisPatient(medicard,false); if(jsonArray3!=null&&jsonArray3.size()>0){ //获取居民信息 JSONObject json = jsonArray3.getJSONObject(0); mzhm = json.getString("mzhm"); }else { medicard=""; } }else { JSONArray jsonArray3 = findHisPatientByIdCard(wlyyOutpatientDO.getIdcard(),false); if(jsonArray3!=null&&jsonArray3.size()>0){ //获取居民信息 JSONObject json = jsonArray3.getJSONObject(0); mzhm = json.getString("mzhm"); } } List list = inspectionDao.findByOutpatientId(wlyyOutpatientDO.getId()); String createTime = ""; if (list!=null&&list.size()>0){ createTime = DateUtil.dateToStrLong(list.get(0).getCreateTime()); } if (StringUtils.isNoneBlank(medicard)){ content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{处方编号}}",createTime).replace("{{门诊号码}}",mzhm) .replace("{{社保卡号}}","【凭社保卡/就诊卡"+medicard+"到院充值预缴金做检查】").replace("{{性别}}",sex).replace("{{时间}}",createTime); }else { content = smsTemplateDO.getContent().replace("{{病人姓名}}",wlyyOutpatientDO.getPatientName()).replace("{{时间}}",createTime).replace("{{门诊号码}}",mzhm) .replace("{{社保卡号}}","【到收费处,凭此条短信中的门诊号码换卡充值预缴金做检查】").replace("{{性别}}",sex);; } if (wxPushLogDO==null&&"1".equalsIgnoreCase(sendMesControl)){ wxPushLogDO = new WxPushLogDO(); wxPushLogDO.setTempName(temlateCode); wxPushLogDO.setOpenid(wlyyOutpatientDO.getId()); wxPushLogDO.setReceiver(wlyyOutpatientDO.getPatient()); wxPushLogDO.setCreateTime(new Date()); wxPushLogDao.save(wxPushLogDO); ykyySendSMS(mobile,smsTemplateDO.getHeader()+content); } } } logger.info("发送后:temlateCode"+temlateCode+"==mobile:"+mobile+"content"+content+"doctorMobile"+doctorMobile); } catch (Exception e) { e.printStackTrace(); System.out.println(temlateCode+"模板发送失败"); } } /** * 获取his病人信息 * @param ssc * @return * @throws Exception */ public JSONArray findHisPatient(String ssc,boolean demoFlag) throws Exception { String sql = "SELECT\n" + "\tx.brid AS \"brid\",\n" + "\tx.mzhm AS \"mzhm\",\n" + "\tx.brxm AS \"brxm\",\n" + "\tx.sfzh AS \"sfzh\",\n" + "\tx.brxz AS \"brxz\",\n" + "\tx.brxb AS \"brxb\",\n" + "\tx.csny as \"csny\",\n" + "\tx.jzkh AS \"jzkh\",\n" + "\tx.jdsj AS \"jdsj\",\n" + "\tx.sjhm AS \"sjhm\",\n" + "\tx.fzxmc AS \"fzxmc\",\n" + "\tx.gzztmc AS \"gzztmc\",\n" + "\tx.lxdz AS \"lxdz\"\n" + "FROM\n" + "\tV_ZKSG_BRCX x\n" + "WHERE\n" + "\tx.jzkh = '"+ssc+"' "; JSONArray array = new JSONArray(); Map params = new HashedMap(); params.put("sql",sql); logger.info("idcard:"+sql); if (demoFlag){ JSONObject jsonObject = new JSONObject(); jsonObject.put("brid","1168517"); jsonObject.put("mzhm","0502452155"); jsonObject.put("brxm","于小童"); jsonObject.put("sfzh","450521199405092535"); jsonObject.put("brxz","自费"); jsonObject.put("brxb","男"); jsonObject.put("csny","1994-05-09"); jsonObject.put("jzkh","2396501"); jsonObject.put("jdsj","2020-06-28 15:15:35"); jsonObject.put("gzztmc","一般"); jsonObject.put("lxdz","厦门市五缘湾"); array.add(jsonObject); }else { HttpResponse response = HttpUtils.doGet(url,params); String content = response.getContent(); logger.info("response:"+content); JSONObject rs = JSON.parseObject(content); Integer status = rs.getInteger("status"); if (status==200){ array = rs.getJSONArray("detailModelList"); } } return array; } /** * 获取his病人信息 * @param idcard * @return * @throws Exception */ public JSONArray findHisPatientByIdCard(String idcard,boolean demoFlag) throws Exception { String sql = "SELECT\n" + "\tx.brid AS \"brid\",\n" + "\tx.mzhm AS \"mzhm\",\n" + "\tx.brxm AS \"brxm\",\n" + "\tx.sfzh AS \"sfzh\",\n" + "\tx.brxz AS \"brxz\",\n" + "\tx.brxb AS \"brxb\",\n" + "\tx.csny as \"csny\",\n" + "\tx.jzkh AS \"jzkh\",\n" + "\tx.jdsj AS \"jdsj\",\n" + "\tx.sjhm AS \"sjhm\",\n" + "\tx.fzxmc AS \"fzxmc\",\n" + "\tx.gzztmc AS \"gzztmc\",\n" + "\tx.lxdz AS \"lxdz\"\n" + "FROM\n" + "\tV_ZKSG_BRCX x\n" + "WHERE\n" + "\tx.sfzh = '"+idcard+"' "; JSONArray array = new JSONArray(); Map params = new HashedMap(); params.put("sql",sql); logger.info("idcard:"+sql); if (demoFlag){ JSONObject jsonObject = new JSONObject(); jsonObject.put("brid","1168517"); jsonObject.put("mzhm","0502452155"); jsonObject.put("brxm","于小童"); jsonObject.put("sfzh","450521199405092535"); jsonObject.put("brxz","自费"); jsonObject.put("brxb","男"); jsonObject.put("csny","1994-05-09"); jsonObject.put("jzkh","2396501"); jsonObject.put("jdsj","2020-06-28 15:15:35"); jsonObject.put("gzztmc","一般"); jsonObject.put("lxdz","厦门市五缘湾"); array.add(jsonObject); }else { HttpResponse response = HttpUtils.doGet(url,params); String content = response.getContent(); logger.info("response:"+content); JSONObject rs = JSON.parseObject(content); Integer status = rs.getInteger("status"); if (status==200){ array = rs.getJSONArray("detailModelList"); } } return array; } }