|
@ -3,11 +3,23 @@ package com.yihu.jw.wechat.service;
|
|
|
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.ConsultDo;
|
|
|
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.order.BusinessOrderDO;
|
|
|
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
|
|
|
import com.yihu.jw.hospital.prescription.dao.OutpatientDao;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService;
|
|
|
import com.yihu.jw.hospital.prescription.service.entrance.YkyyEntranceService;
|
|
|
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.web.Envelop;
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
@ -75,6 +87,18 @@ public class WxTemplateService {
|
|
|
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;
|
|
|
|
|
|
|
|
|
/**
|
|
@ -196,6 +220,109 @@ public class WxTemplateService {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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){
|
|
|
long nd = 1000 * 24 * 60 * 60;
|
|
|
long nh = 1000 * 60 * 60;
|
|
|
long nm = 1000 * 60;
|
|
|
|
|
|
Long diff = businessOrderDO.getCreateTime().getTime()- new Date().getTime();
|
|
|
Long min = diff % nd % nh / nm;
|
|
|
if (min==Long.parseLong(close)){
|
|
|
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();
|
|
|
long nd = 1000 * 24 * 60 * 60;
|
|
|
long nh = 1000 * 60 * 60;
|
|
|
long nm = 1000 * 60;
|
|
|
|
|
|
Long diff = businessOrderDO.getCreateTime().getTime()- new Date().getTime();
|
|
|
Long min = diff % nd % nh / nm;
|
|
|
if (min==Long.parseLong(remind)){
|
|
|
//判断是否发送过
|
|
|
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);
|