|  | @ -0,0 +1,474 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.service.channel;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.doctor.dao.BaseDoctorDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.im.ConsultTeamDo;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.wx.*;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionInfoDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.order.BusinessOrderDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionDiagnosisDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.dao.PrescriptionInfoDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.PrescriptionLogService;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
 | 
	
		
			
				|  |  | import com.yihu.jw.im.service.ImService;
 | 
	
		
			
				|  |  | import com.yihu.jw.oauth.OauthSsoService;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.BusinessOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.ConsultOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.order.dao.ConsultTeamOrderDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionDiagnosisVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionInfoVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.Envelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.date.DateUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.WeixinMessagePushUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.RSAEncrypt;
 | 
	
		
			
				|  |  | import com.yihu.jw.utils.hibernate.HibenateUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.BasePatientWechatDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxPushLogDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxTemplateConfigDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.dao.WxTemplateDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.wechat.service.WxAccessTokenService;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.BeanUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.net.URLEncoder;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by Administrator on 2017/5/19 0019.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class UnSettledHISPrescriptionService {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     private Logger logger= LoggerFactory.getLogger(UnSettledHISPrescriptionService.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxTemplateConfigDao wxTemplateConfigDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxTemplateDao wxTemplateDao;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxAccessTokenService wxAccessTokenService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WeixinMessagePushUtils weixinMessagePushUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Value("${wechat.id}")
 | 
	
		
			
				|  |  |     private String wechatId;
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao basePatientDao;
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientWechatDao basePatientWechatDao;
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private OauthSsoService oauthSsoService;
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private XzzxEntranceService xzzxEntranceService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private YkyyEntranceService ykyyEntranceService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WxPushLogDao wxPushLogDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private HibenateUtils hibenateUtils;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WlyyHospitalSysDictDao hospitalSysDictDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ConsultOrderDao consultOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BusinessOrderDao businessOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ConsultTeamOrderDao consultTeamOrderDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private OutpatientDao outpatientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BaseDoctorDao doctorDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionLogService prescriptionLogService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ImService imService;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionDao prescriptionDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionInfoDao prescriptionInfoDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PrescriptionDiagnosisDao prescriptionDiagnosisDao;
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送微信模版消息-小程序视频
 | 
	
		
			
				|  |  |      * @param sender_id 发送者ID
 | 
	
		
			
				|  |  |      * @param sender_name 发送者姓名
 | 
	
		
			
				|  |  |      * @param reciver_id 接收者ID
 | 
	
		
			
				|  |  |      * @param reciver_name 接收者姓名
 | 
	
		
			
				|  |  |      * @param session_id 会话ID
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendWeTempMesMiniProgram(String sender_id, String sender_name, String reciver_id, String reciver_name,String session_id)throws Exception {
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findById(reciver_id);
 | 
	
		
			
				|  |  |         if(basePatientDO!=null){
 | 
	
		
			
				|  |  |             List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,reciver_id);
 | 
	
		
			
				|  |  |             if(ps.isEmpty()){
 | 
	
		
			
				|  |  |                 logger.info("该用户"+reciver_name+"没有openid,无法推送模版消息,用户ID:"+reciver_id+"wechatId:"+wechatId);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 for (BasePatientWechatDo basePatientWechatDo:ps){
 | 
	
		
			
				|  |  |                     if("xm_xzzx_wx".equals(wechatId)){
 | 
	
		
			
				|  |  |                         String getAuthCode = oauthSsoService.getSsoPublic(wechatId,basePatientDO.getId());
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |                         JSONObject jsonObject = new JSONObject();
 | 
	
		
			
				|  |  |                         jsonObject.put("name",basePatientDO.getName());
 | 
	
		
			
				|  |  |                         jsonObject.put("idcard",basePatientDO.getIdcard());
 | 
	
		
			
				|  |  |                         jsonObject.put("mobile",basePatientDO.getMobile());
 | 
	
		
			
				|  |  |                         jsonObject.put("openid",basePatientWechatDo.getOpenid());
 | 
	
		
			
				|  |  |                         String authCode = jsonObject.toJSONString();
 | 
	
		
			
				|  |  |                         String jm = URLEncoder.encode(RSAEncrypt.encrypt(authCode,getAuthCode),"utf-8");
 | 
	
		
			
				|  |  |                         String miniprogramUrl = "pages/room/room?patientCode="+reciver_id+"&doctorName="+sender_name+"&role=patient&roomID="+session_id+"&template=1v1&debugMode=false&cloudenv=PRO&authCode="+jm+"&code="+wechatId+"&appId="+basePatientDO.getId();
 | 
	
		
			
				|  |  |                         //心脏中心模版消息推送接口
 | 
	
		
			
				|  |  |                         logger.info("心脏中心小程序跳转URL:"+miniprogramUrl);
 | 
	
		
			
				|  |  |                         xzzxEntranceService.sendXCXMes(wechatId,
 | 
	
		
			
				|  |  |                                 basePatientDO.getId(),
 | 
	
		
			
				|  |  |                                 basePatientDO.getIdcard(),
 | 
	
		
			
				|  |  |                                 sender_name+"主任医生已向您发起视频通话邀请,请点击详情进入视频诊室。",
 | 
	
		
			
				|  |  |                                 "点击消息进入视频诊室接听视频通话,开始视频咨询",
 | 
	
		
			
				|  |  |                                 "",miniprogramUrl,"wx53f6bb4ac081d840");
 | 
	
		
			
				|  |  |                     }else{
 | 
	
		
			
				|  |  |                         WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_consult_notice","spthtx",1);
 | 
	
		
			
				|  |  |                         config.setFirst(config.getFirst().replace("key1",sender_name));
 | 
	
		
			
				|  |  |                         config.setPagepath(config.getPagepath()+""+reciver_id+"&doctorName="+sender_name+"&role=patient&roomID="+session_id+"&template=1v1&debugMode=false&cloudenv=PRO");
 | 
	
		
			
				|  |  |                         weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),basePatientWechatDo.getOpenid(),config);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             throw new Exception("接收者ID错误,无法找到该账号");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return "success";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 查询HIS的01表中的审方状态,如果已审方,且未结算,则推送一条模板消息给居民,让居民进行支付结算。
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void unSettledHISPrescription() throws Exception{
 | 
	
		
			
				|  |  |         if("xm_ykyy_wx".equals(wechatId)){
 | 
	
		
			
				|  |  |             //获取审核失败
 | 
	
		
			
				|  |  |             JSONArray jsonArray = ykyyEntranceService.getNoUnsettledPrescription();
 | 
	
		
			
				|  |  |             if(jsonArray!=null&&jsonArray.size()>0) {
 | 
	
		
			
				|  |  |                 for (int i = 0; i<jsonArray.size(); i++){
 | 
	
		
			
				|  |  |                     JSONObject json = jsonArray.getJSONObject(i);
 | 
	
		
			
				|  |  |                     String cfsb = json.getString("CFSB");
 | 
	
		
			
				|  |  |                     //查找对应的处方
 | 
	
		
			
				|  |  |                     String sql = "SELECT w.OUTPATIENT_ID,w.ID,w.DOCTOR_NAME from WLYY_PRESCRIPTION w WHERE REAL_ORDER = '"+cfsb+"' ORDER BY w.CREATE_TIME desc";
 | 
	
		
			
				|  |  |                     List<Map<String, Object>> pre = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |                     if(pre!=null && pre.size()>0){
 | 
	
		
			
				|  |  |                         String prescriptionId = pre.get(0).get("ID").toString();
 | 
	
		
			
				|  |  |                         //修改处方状态
 | 
	
		
			
				|  |  |                         String updateSql = "update WLYY_PRESCRIPTION set status = 11 where id = '"+prescriptionId+"'";
 | 
	
		
			
				|  |  |                         hibenateUtils.updateBySql(updateSql);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //获取已审核未结算的处方
 | 
	
		
			
				|  |  |             JSONArray array = ykyyEntranceService.getUnsettledPrescription();
 | 
	
		
			
				|  |  |             //发送模板
 | 
	
		
			
				|  |  |             if(array!=null&&array.size()>0) {
 | 
	
		
			
				|  |  |                 for (int i = 0; i<array.size(); i++){
 | 
	
		
			
				|  |  |                     JSONObject json = array.getJSONObject(i);
 | 
	
		
			
				|  |  |                     String brid = json.getString("BRID");
 | 
	
		
			
				|  |  |                     String cfsb = json.getString("CFSB");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //查找居民信息
 | 
	
		
			
				|  |  |                     BasePatientDO patientDO = ykyyEntranceService.findPatientByMapingCode(brid);
 | 
	
		
			
				|  |  |                     if(patientDO!=null){
 | 
	
		
			
				|  |  |                         //查找对应的处方
 | 
	
		
			
				|  |  |                         String sql = "SELECT w.OUTPATIENT_ID,w.ID,w.DOCTOR_NAME from WLYY_PRESCRIPTION w WHERE REAL_ORDER = '"+cfsb+"' ORDER BY w.CREATE_TIME desc";
 | 
	
		
			
				|  |  |                         List<Map<String, Object>> pre = hibenateUtils.createSQLQuery(sql);
 | 
	
		
			
				|  |  |                         if(pre!=null && pre.size()>0){
 | 
	
		
			
				|  |  |                             String outpatientId = pre.get(0).get("OUTPATIENT_ID").toString();
 | 
	
		
			
				|  |  |                             String prescriptionId = pre.get(0).get("ID").toString();
 | 
	
		
			
				|  |  |                             String doctorName = pre.get(0).get("DOCTOR_NAME").toString();
 | 
	
		
			
				|  |  |                             //判断是否发送过
 | 
	
		
			
				|  |  |                             String countSql = "SELECT id from WX_PUSH_LOG w WHERE w.RECEIVER = '"+patientDO.getId()
 | 
	
		
			
				|  |  |                                     +"' and w.OPENID = '"+prescriptionId+"' and w.scene = 'djsxxtz' and w.WECHAT_ID='"+wechatId+"'";
 | 
	
		
			
				|  |  |                             List<Map<String, Object>> count = hibenateUtils.createSQLQuery(countSql);
 | 
	
		
			
				|  |  |                             if(count==null || count.size() == 0){
 | 
	
		
			
				|  |  |                                 List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,patientDO.getId());
 | 
	
		
			
				|  |  |                                 if(ps.isEmpty()){
 | 
	
		
			
				|  |  |                                     logger.info("该用户"+patientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+patientDO.getId()+"wechatId:"+wechatId);
 | 
	
		
			
				|  |  |                                 }else{
 | 
	
		
			
				|  |  |                                     //修改处方状态
 | 
	
		
			
				|  |  |                                     String updateSql = "update WLYY_PRESCRIPTION set status = 20 where id = '"+prescriptionId+"' and status = 10";
 | 
	
		
			
				|  |  |                                     hibenateUtils.updateBySql(updateSql);
 | 
	
		
			
				|  |  |                                     prescriptionLogService.addPrescriptionLog(prescriptionId,20,2,"system","system","",new Date());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                     ps.stream().forEach(one->{
 | 
	
		
			
				|  |  |                                         WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_unsettled_notice","djsxxtz",1);
 | 
	
		
			
				|  |  |                                         WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
 | 
	
		
			
				|  |  |                                         BeanUtils.copyProperties(config,newConfig);
 | 
	
		
			
				|  |  |                                         newConfig.setFirst(config.getFirst().replace("key1",patientDO.getName()));
 | 
	
		
			
				|  |  |                                         newConfig.setUrl(config.getUrl()+""+outpatientId);
 | 
	
		
			
				|  |  |                                         newConfig.setKeyword3(doctorName);
 | 
	
		
			
				|  |  |                                         WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
 | 
	
		
			
				|  |  |                                         logger.info("=======setUrl========"+newConfig.getUrl());
 | 
	
		
			
				|  |  |                                         weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(),one.getOpenid(),newConfig);
 | 
	
		
			
				|  |  |                                     });
 | 
	
		
			
				|  |  |                                     //保存发送模板记录,
 | 
	
		
			
				|  |  |                                     WxPushLogDO wxPushLogDO = new WxPushLogDO();
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setOpenid(prescriptionId);
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setReceiver(patientDO.getId());
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setWechatId(wechatId);
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setReceiverName(patientDO.getName());
 | 
	
		
			
				|  |  |                                     wxPushLogDO.setScene("djsxxtz");
 | 
	
		
			
				|  |  |                                     wxPushLogDao.save(wxPushLogDO);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 WlyyPrescriptionDO wlyyPrescriptionDO = prescriptionDao.findOne(prescriptionId);
 | 
	
		
			
				|  |  |                                 JSONObject object = (JSONObject) JSONObject.toJSON(wlyyPrescriptionDO);
 | 
	
		
			
				|  |  |                                 logger.info("wlyyPrescriptionDO参数入参"+object.toJSONString());
 | 
	
		
			
				|  |  |                                 WlyyPrescriptionVO prescriptionVO = JSONObject.toJavaObject(object,WlyyPrescriptionVO.class);
 | 
	
		
			
				|  |  |                                 List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(wlyyPrescriptionDO.getId(),1);
 | 
	
		
			
				|  |  |                                 List<WlyyPrescriptionInfoVO> wlyyPrescriptionInfoVOS = new ArrayList<>();
 | 
	
		
			
				|  |  |                                 for (WlyyPrescriptionInfoDO wlyyPrescriptionInfoDO:wlyyPrescriptionInfoDOS){
 | 
	
		
			
				|  |  |                                     JSONObject jsonObject = (JSONObject) JSONObject.toJSON(wlyyPrescriptionInfoDO);
 | 
	
		
			
				|  |  |                                     logger.info("wlyyPrescriptionInfoDO参数入参"+jsonObject.toJSONString());
 | 
	
		
			
				|  |  |                                     WlyyPrescriptionInfoVO prescriptionInfoVO = JSONObject.toJavaObject(jsonObject,WlyyPrescriptionInfoVO.class);
 | 
	
		
			
				|  |  |                                     wlyyPrescriptionInfoVOS.add(prescriptionInfoVO);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 prescriptionVO.setInfoVOs(wlyyPrescriptionInfoVOS);
 | 
	
		
			
				|  |  |                                 List<WlyyPrescriptionDiagnosisDO> wlyyPrescriptionDiagnosisDOS = prescriptionDiagnosisDao.findByPrescriptionId(wlyyPrescriptionDO.getId(),1);
 | 
	
		
			
				|  |  |                                 List<WlyyPrescriptionDiagnosisVO> wlyyPrescriptionDiagnosisVOS = new ArrayList<>();
 | 
	
		
			
				|  |  |                                 for (WlyyPrescriptionDiagnosisDO wlyyPrescriptionDiagnosisDO:wlyyPrescriptionDiagnosisDOS){
 | 
	
		
			
				|  |  |                                     JSONObject jsonObject = (JSONObject) JSONObject.toJSON(wlyyPrescriptionDiagnosisDO);
 | 
	
		
			
				|  |  |                                     logger.info("wlyyPrescriptionDiagnosisDO参数入参"+jsonObject.toJSONString());
 | 
	
		
			
				|  |  |                                     WlyyPrescriptionDiagnosisVO prescriptionDiagnosisVO = JSONObject.toJavaObject(jsonObject,WlyyPrescriptionDiagnosisVO.class);
 | 
	
		
			
				|  |  |                                     wlyyPrescriptionDiagnosisVOS.add(prescriptionDiagnosisVO);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                                 prescriptionVO.setDiagnosisVOs(wlyyPrescriptionDiagnosisVOS);
 | 
	
		
			
				|  |  |                                 imService.pushPrescriptionImMessage(prescriptionVO);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public void updateStatusByPayTime() throws Exception{
 | 
	
		
			
				|  |  |         if("xm_ykyy_wx".equals(wechatId)){
 | 
	
		
			
				|  |  |             WlyyHospitalSysDictDO wlyyHospitalSysDictDO = hospitalSysDictDao.findById("PAY_TIME");
 | 
	
		
			
				|  |  |             if (wlyyHospitalSysDictDO!=null){
 | 
	
		
			
				|  |  |                 String remind = wlyyHospitalSysDictDO.getDictValue();
 | 
	
		
			
				|  |  |                 String close = wlyyHospitalSysDictDO.getDictCode();
 | 
	
		
			
				|  |  |                 List<BusinessOrderDO> businessOrderDOS = businessOrderDao.selectByStatus(0);
 | 
	
		
			
				|  |  |                 //关闭处理
 | 
	
		
			
				|  |  |                 for (BusinessOrderDO businessOrderDO:businessOrderDOS){
 | 
	
		
			
				|  |  |                     Calendar cal= Calendar.getInstance();
 | 
	
		
			
				|  |  |                     cal.setTime(businessOrderDO.getCreateTime());
 | 
	
		
			
				|  |  |                     cal.add(Calendar.MINUTE,Integer.parseInt(close));
 | 
	
		
			
				|  |  |                     Long now = new Date().getTime();
 | 
	
		
			
				|  |  |                     Long min = cal.getTime().getTime();
 | 
	
		
			
				|  |  |                     logger.info("关闭处理cal="+cal);
 | 
	
		
			
				|  |  |                     if (min==now){
 | 
	
		
			
				|  |  |                         String orderCategory = businessOrderDO.getOrderCategory();
 | 
	
		
			
				|  |  |                         String relationCode = businessOrderDO.getRelationCode();
 | 
	
		
			
				|  |  |                         if (orderCategory.equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |                             ConsultTeamDo consultTeamDo = consultTeamOrderDao.findByConsult(relationCode);
 | 
	
		
			
				|  |  |                             consultTeamDo.setStatus(-1);
 | 
	
		
			
				|  |  |                             consultTeamOrderDao.save(consultTeamDo);
 | 
	
		
			
				|  |  |                         }else if (orderCategory.equalsIgnoreCase("2")){
 | 
	
		
			
				|  |  |                             WlyyOutpatientDO outpatientDO = outpatientDao.findById(relationCode);
 | 
	
		
			
				|  |  |                             outpatientDO.setStatus("-1");
 | 
	
		
			
				|  |  |                             outpatientDao.save(outpatientDO);
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 //提醒处理
 | 
	
		
			
				|  |  |                 for (BusinessOrderDO businessOrderDO:businessOrderDOS){
 | 
	
		
			
				|  |  |                     String orderCategory = businessOrderDO.getOrderCategory();
 | 
	
		
			
				|  |  |                     String relationCode = businessOrderDO.getRelationCode();
 | 
	
		
			
				|  |  |                     String orderType =businessOrderDO.getOrderType()+"";
 | 
	
		
			
				|  |  |                     String doctor = businessOrderDO.getDoctor();
 | 
	
		
			
				|  |  |                     String patient= businessOrderDO.getPatient();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     Calendar cal= Calendar.getInstance();
 | 
	
		
			
				|  |  |                     cal.setTime(businessOrderDO.getCreateTime());
 | 
	
		
			
				|  |  |                     cal.add(Calendar.MINUTE,Integer.parseInt(remind));
 | 
	
		
			
				|  |  |                     Long now = new Date().getTime();
 | 
	
		
			
				|  |  |                     Long min = cal.getTime().getTime();
 | 
	
		
			
				|  |  |                     logger.info("提醒处理cal="+cal);
 | 
	
		
			
				|  |  |                     if (min==now){
 | 
	
		
			
				|  |  |                         //判断是否发送过
 | 
	
		
			
				|  |  |                         String countSql = "SELECT id from WX_PUSH_LOG w WHERE w.RECEIVER = '"+patient
 | 
	
		
			
				|  |  |                                 +"' and w.OPENID = '"+relationCode+"' and w.scene = 'zxzfts' and w.WECHAT_ID='"+wechatId+"'";
 | 
	
		
			
				|  |  |                         List<Map<String, Object>> count = hibenateUtils.createSQLQuery(countSql);
 | 
	
		
			
				|  |  |                         if(count==null || count.size() == 0){
 | 
	
		
			
				|  |  |                             BasePatientDO patientDO = basePatientDao.findById(patient);
 | 
	
		
			
				|  |  |                             BaseDoctorDO doctorDO = doctorDao.findById(doctor);
 | 
	
		
			
				|  |  |                             List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,patient);
 | 
	
		
			
				|  |  |                             if(ps.isEmpty()){
 | 
	
		
			
				|  |  |                                 logger.info("该用户"+patientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+patientDO.getId()+"wechatId:"+wechatId);
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                                 ps.stream().forEach(one->{
 | 
	
		
			
				|  |  |                                     WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_unsettled_notice","zxzfts",1);
 | 
	
		
			
				|  |  |                                     WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
 | 
	
		
			
				|  |  |                                     BeanUtils.copyProperties(config,newConfig);
 | 
	
		
			
				|  |  |                                     String name = "";
 | 
	
		
			
				|  |  |                                     String condition="";
 | 
	
		
			
				|  |  |                                     if (orderCategory.equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |                                         if (orderType.equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |                                             name="图文咨询";
 | 
	
		
			
				|  |  |                                         }else if (orderType.equalsIgnoreCase("3")){
 | 
	
		
			
				|  |  |                                             name="视频咨询";
 | 
	
		
			
				|  |  |                                         }
 | 
	
		
			
				|  |  |                                         condition = "&consultCode="+relationCode;
 | 
	
		
			
				|  |  |                                     }else if (orderCategory.equalsIgnoreCase("2")){
 | 
	
		
			
				|  |  |                                         if (orderType.equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |                                             name="图文咨询";
 | 
	
		
			
				|  |  |                                         }else if (orderType.equalsIgnoreCase("3")){
 | 
	
		
			
				|  |  |                                             name="视频咨询";
 | 
	
		
			
				|  |  |                                         }
 | 
	
		
			
				|  |  |                                         condition = "&outpatientId="+relationCode;
 | 
	
		
			
				|  |  |                                     }
 | 
	
		
			
				|  |  |                                     newConfig.setFirst(config.getFirst().replace("key1",patientDO.getName()).replace("key2",name));
 | 
	
		
			
				|  |  |                                     newConfig.setUrl(config.getUrl()+""+condition);
 | 
	
		
			
				|  |  |                                     newConfig.setKeyword3(doctorDO.getName());
 | 
	
		
			
				|  |  |                                     newConfig.setKeyword1(name);
 | 
	
		
			
				|  |  |                                     WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
 | 
	
		
			
				|  |  |                                     logger.info("=======setUrl========"+newConfig.getUrl());
 | 
	
		
			
				|  |  |                                     weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(),one.getOpenid(),newConfig);
 | 
	
		
			
				|  |  |                                 });
 | 
	
		
			
				|  |  |                                 //保存发送模板记录,
 | 
	
		
			
				|  |  |                                 WxPushLogDO wxPushLogDO = new WxPushLogDO();
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setOpenid(relationCode);
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setReceiver(patientDO.getId());
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setWechatId(wechatId);
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setReceiverName(patientDO.getName());
 | 
	
		
			
				|  |  |                                 wxPushLogDO.setScene("zxzfts");
 | 
	
		
			
				|  |  |                                 wxPushLogDao.save(wxPushLogDO);
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     public String sendWeTempMesTest(String wechatId,String openid)throws Exception{
 | 
	
		
			
				|  |  |         WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_survey","test",1);
 | 
	
		
			
				|  |  |         config.setFirst(config.getFirst().replace("key1","小明"));
 | 
	
		
			
				|  |  |         config.setKeyword2("2018-08-21");
 | 
	
		
			
				|  |  |         weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),openid,config);
 | 
	
		
			
				|  |  |         return "success";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public Envelop getAllTemp(String wechatId){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         String url ="https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token="+wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken();
 | 
	
		
			
				|  |  |         String result = HttpUtil.sendGet(url);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject tempJsons = JSON.parseObject(result);
 | 
	
		
			
				|  |  |         //获取所有本地模板
 | 
	
		
			
				|  |  |         List<String> localTemps = findAllTempDos(wechatId);
 | 
	
		
			
				|  |  |         //解析公众号模板
 | 
	
		
			
				|  |  |         JSONArray temps = tempJsons.getJSONArray("template_list");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<WxTemplateDO> savelist = new ArrayList<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if(temps!=null&&!temps.isEmpty()){
 | 
	
		
			
				|  |  |             for(int i=0;i<temps.size();i++){
 | 
	
		
			
				|  |  |                 JSONObject tp = (JSONObject) temps.get(i);
 | 
	
		
			
				|  |  |                 String tpid = tp.getString("template_id");
 | 
	
		
			
				|  |  |                 if(!localTemps.contains(tpid)){
 | 
	
		
			
				|  |  |                     WxTemplateDO wxTemplateDO = new WxTemplateDO();
 | 
	
		
			
				|  |  |                     wxTemplateDO.setWechatId(wechatId);
 | 
	
		
			
				|  |  |                     wxTemplateDO.setTemplateId(tpid);
 | 
	
		
			
				|  |  |                     wxTemplateDO.setTitle(tp.getString("title"));
 | 
	
		
			
				|  |  |                     wxTemplateDO.setContent(tp.getString("content"));
 | 
	
		
			
				|  |  |                     wxTemplateDO.setStatus(1);
 | 
	
		
			
				|  |  |                     wxTemplateDO.setCreateTime(new Date());
 | 
	
		
			
				|  |  |                     savelist.add(wxTemplateDO);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             wxTemplateDao.save(savelist);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return Envelop.getSuccess(BaseRequestMapping.WeChat.api_success);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<String> findAllTempDos(String wechatId){
 | 
	
		
			
				|  |  |         List<WxTemplateDO> list =  wxTemplateDao.findByWxId(wechatId);
 | 
	
		
			
				|  |  |         List<String> rs = new ArrayList<>();
 | 
	
		
			
				|  |  |         if(list!=null&&list.size()>0){
 | 
	
		
			
				|  |  |             for(WxTemplateDO wxTemplateDO:list){
 | 
	
		
			
				|  |  |                 rs.add(wxTemplateDO.getTemplateId());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return rs;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 发送微信模版消息
 | 
	
		
			
				|  |  |      * @param userName
 | 
	
		
			
				|  |  |      * @param senderName
 | 
	
		
			
				|  |  |      * @param idCard
 | 
	
		
			
				|  |  |      * @param phone
 | 
	
		
			
				|  |  |      * @param title
 | 
	
		
			
				|  |  |      * @param content
 | 
	
		
			
				|  |  |      * @param contentString
 | 
	
		
			
				|  |  |      * @param url
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String sendWxTemple(String userName, String senderName,
 | 
	
		
			
				|  |  |                              String idCard, String phone, String title,
 | 
	
		
			
				|  |  |                              String content, String contentString,
 | 
	
		
			
				|  |  |                              String url) throws Exception{
 | 
	
		
			
				|  |  |         BasePatientDO basePatientDO = basePatientDao.findByIdcard(idCard);
 | 
	
		
			
				|  |  |         if(basePatientDO!=null){
 | 
	
		
			
				|  |  |             List<BasePatientWechatDo> ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId,basePatientDO.getId());
 | 
	
		
			
				|  |  |             if(ps.isEmpty()){
 | 
	
		
			
				|  |  |                 logger.info("该用户"+basePatientDO.getName()+"没有openid,无法推送模版消息,用户ID:"+basePatientDO.getId()+"wechatId:"+wechatId);
 | 
	
		
			
				|  |  |             }else{
 | 
	
		
			
				|  |  |                 for (BasePatientWechatDo basePatientWechatDo:ps){
 | 
	
		
			
				|  |  |                         WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId,"template_im_notice","zxtx",1);
 | 
	
		
			
				|  |  |                         config.setFirst(config.getFirst().replace("key1",userName));
 | 
	
		
			
				|  |  |                         config.setKeyword1(contentString);
 | 
	
		
			
				|  |  |                         config.setKeyword2(DateUtil.dateToStrLong(new Date()));
 | 
	
		
			
				|  |  |                         config.setUrl(url);
 | 
	
		
			
				|  |  |                         weixinMessagePushUtils.putWxMsg(wxAccessTokenService.getWxAccessTokenById(wechatId).getAccessToken(),basePatientWechatDo.getOpenid(),config);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             throw new Exception("接收者ID错误,无法找到该账号");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "success";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |