Bladeren bron

顺丰物流推送模板消息

wangjun 4 jaren geleden
bovenliggende
commit
0db9bd7024

+ 14 - 1
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionExpressageService.java

@ -88,6 +88,8 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
    @Autowired
    private PrescriptionLogDao prescriptionLogDao;
    @Autowired
    PrescriptionService prescriptionService;
    @Autowired
    private SfConfigDao sfConfigDao;
@ -591,7 +593,8 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
            if(!newroutinfolist.isEmpty()){
                prescriptionExpressageLogDao.save(newroutinfolist);
            }
            //向患者微信推送模板写消息
            pushRouteLogToPatient(newroutinfolist);
            //如果路由信息节点包含了"已收件"节点,则修改处方状态为完成,增加物流派送日志为完成
            if(isContainEndRoutInfo){
                //修改处方状态为完成
@ -643,7 +646,17 @@ public class PrescriptionExpressageService extends BaseJpaService<WlyyPrescripti
    }
    //发送微信模板消息
    public void pushRouteLogToPatient(List<WlyyPrescriptionExpressageLogDO> routinfolist){
        for (WlyyPrescriptionExpressageLogDO wlyyPrescriptionExpressageLogDO:routinfolist){
            if ("50".equalsIgnoreCase(wlyyPrescriptionExpressageLogDO.getOpCode())||
                    "204".equalsIgnoreCase(wlyyPrescriptionExpressageLogDO.getOpCode())||
            "80".equalsIgnoreCase(wlyyPrescriptionExpressageLogDO.getOpCode())||"8000".equalsIgnoreCase(wlyyPrescriptionExpressageLogDO.getOpCode())){
                prescriptionService.sendSFWxTemplate(wlyyPrescriptionExpressageLogDO.getOutpatientId(),wlyyPrescriptionExpressageLogDO.getPrescriptionId(),wlyyPrescriptionExpressageLogDO.getOpCode());
            }
        }
    }
    /**
     * 根据收寄地址获取快递费用
     * @param d_province 省份名称

+ 141 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -4657,6 +4657,147 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        }
    }
    /**
     * 发送顺丰物流提醒模板消息
     * @param outpatientId
     */
    public void sendSFWxTemplate(String outpatientId,String prescriptionId,String routeCode){
        String contentMsg = "";
        String first = "";
        String remark = "";
        String patientId = "";
        String drugName = "";
        String remindMsg="";
        String patienName = "";
        String mailNo ="";
        String msgUrl ="";
        WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(outpatientId);
        List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(prescriptionId,1);
        if (wlyyOutpatientDO!=null){
            patientId = wlyyOutpatientDO.getConsumer();
        }
        if (wlyyPrescriptionInfoDOS!=null&&wlyyPrescriptionInfoDOS.size()>0){
            drugName = wlyyPrescriptionInfoDOS.get(0).getDrugName();
        }
        List<WlyyPrescriptionExpressageDO> wlyyPrescriptionExpressageDOS =prescriptionExpressageDao.findByOutpatientId(outpatientId);
        if (wlyyPrescriptionExpressageDOS!=null&&wlyyPrescriptionExpressageDOS.size()>0){
            mailNo = wlyyPrescriptionExpressageDOS.get(0).getMailno();
        }
        switch (routeCode) {
            case "50":
                remindMsg = "已发出";
                break;
            case "204":
                remindMsg = "已在派件";
                break;
            case "80":
                remindMsg = "已签收";
                break;
            case "8000":
                remindMsg = "已签收";
                break;
        }
        BasePatientDO basePatientDO = basePatientDao.findById(patientId);
        if (basePatientDO!=null){
            patienName = basePatientDO.getName();
        }
        if ("xm_ykyy_wx".equalsIgnoreCase(wechatId)){
            List<BasePatientWechatDo> ps = new ArrayList<BasePatientWechatDo>();
            if (StringUtils.isNotEmpty(outpatientId)){
                ps = basePatientWechatDao.findByWechatIdAndPatientId(wechatId, patientId);
            }
            if (ps.isEmpty()) {
                logger.info("该用户" + wlyyOutpatientDO.getConsumerName() + "没有openid,无法推送模版消息,用户ID:" + wlyyOutpatientDO.getPatient() + "wechatId:" + wechatId);
                return;
            }
            WxTemplateConfigDO newConfig = new WxTemplateConfigDO();
            String scene = "sfxxtx";
            WxTemplateConfigDO config = wxTemplateConfigDao.findByWechatIdAndTemplateNameAndSceneAndStatus(wechatId, "template_sf_msg_notice", scene, 1);
            BeanUtils.copyProperties(config, newConfig);
            newConfig.setFirst(config.getFirst().replace("key1",remindMsg));
            newConfig.setKeyword1(config.getKeyword1().replace("key1",patienName).replace("key2",drugName));
            newConfig.setKeyword2("顺丰快递");
            newConfig.setKeyword3(mailNo);
            newConfig.setKeyword4(remindMsg);
            newConfig.setRemark(config.getRemark());
            newConfig.setUrl(newConfig.getUrl().replace("key1",outpatientId).replace("key2",prescriptionId));
            logger.info("=======setUrl========" + newConfig.getUrl());
            WxAccessTokenDO wxAccessTokenDO = wxAccessTokenService.getWxAccessTokenById(wechatId);
            for (BasePatientWechatDo one : ps) {
                logger.info("发送的消息="+ com.alibaba.fastjson.JSONObject.toJSONString(newConfig));
                try {
                    logger.info("调用眼科微信模板消息接口的入参:AccessToken="+wxAccessTokenDO.getAccessToken()+"---Openid="+one.getOpenid());
                    weixinMessagePushUtils.putWxMsg(wxAccessTokenDO.getAccessToken(), one.getOpenid(), newConfig);
                    logger.info("发送成功");
                } catch (Exception e) {
                    e.printStackTrace();
                    logger.info("发送失败,error="+e.getMessage());
                }
                //保存发送模板记录,
                WxPushLogDO wxPushLogDO = new WxPushLogDO();
                wxPushLogDO.setCreateTime(new Date());
                wxPushLogDO.setOpenid(one.getOpenid());
                wxPushLogDO.setReceiver(wlyyOutpatientDO.getConsumer());
                wxPushLogDO.setWechatId(wechatId);
                wxPushLogDO.setReceiverName(wlyyOutpatientDO.getConsumerName());
                wxPushLogDO.setScene(scene);
                wxPushLogDao.save(wxPushLogDO);
            }
        }else {
            first = "您好,您的处方订单物流"+remindMsg;
            contentMsg = "患者"+patienName+"的处方药品订单,"+drugName+"等,当前"+remindMsg+"。物流方:「顺丰快递」,物流单号:"+mailNo+"。";
            logger.info("推送物流模板消息参数first:"+first+"====contentMsg:"+contentMsg);
            msgUrl="/ims-wx/index.html#/returnVisit/logistics?outpatientId="+outpatientId+"&prescriptionCode="+prescriptionId;
            String responseMsg = "";
            if ("xm_xzzx_wx".equalsIgnoreCase(wechatId)) {
                //String prefix="https://www.xmheart.com";
                String prefix = "https://ih.xmheart.com/hlwyy";
                if(StringUtils.isNotEmpty(outpatientId)){
                    responseMsg = xzzxEntranceService.sendMes(wechatId,
                            basePatientDO.getId(),
                            basePatientDO.getIdcard(),
                            first,
                            contentMsg,
                            remark,
                            prefix+msgUrl);
                }
                logger.info("url="+prefix+msgUrl);
                String msg="first:"+first+"contentMsg:"+contentMsg+"remark:"+remark;
                logger.info("发送的信息="+msg);
                logger.info("心脏模板消息发送返回结果:"+responseMsg);
            } else if ("xm_zsyy_wx".equalsIgnoreCase(wechatId)) {
                String prefix = "https://hlwyy.xmzsh.com";
                if (StringUtils.isNotEmpty(outpatientId)) {
                    responseMsg = entranceService.ehospitalNotice(
                            patienName,
                            basePatientDO.getIdcard(),
                            basePatientDO.getMobile(),
                            first,
                            prefix + msgUrl,
                            contentMsg,
                            remark
                    );
                    logger.info("中山发送模板消息返回结果="+responseMsg);
                    System.out.println("结束发送模板消息");
                }
            }
            //保存发送模板记录,
            WxPushLogDO wxPushLogDO = new WxPushLogDO();
            wxPushLogDO.setCreateTime(new Date());
            wxPushLogDO.setReceiver(wlyyOutpatientDO.getConsumer());
            wxPushLogDO.setWechatId(wechatId);
            wxPushLogDO.setReceiverName(wlyyOutpatientDO.getConsumerName());
            wxPushLogDO.setRequest(first+contentMsg+msgUrl);
            wxPushLogDO.setResponse(responseMsg);
            wxPushLogDO.setTempName("顺丰推送的物流消息");
            wxPushLogDao.save(wxPushLogDO);
        }
    }
    public List<WlyyHospitalSysDictDO> findCancelReasonList() {
        return sysDictDao.findByDictName("PatientCancel");

+ 2 - 3
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/EntranceService.java

@ -596,6 +596,7 @@ public class EntranceService {
            if (StringUtils.isNotBlank(ksdm)) {
                sbs.append("<query compy=\"=\" item=\"ADM_SPEC\" splice=\"and\" value=\"'" + ksdm + "'\"/>");
            }
            sbs.append("<query compy=\"\" item=\"icd_name\" splice=\"and\" value=\"is not null\"/>");
            sbs.append("<order item=\"CON_DATE\" sort=\"desc\"/>");
            //查询信息结束
            sbs.append("</MsgInfo></ESBEntry>");
@ -1479,9 +1480,7 @@ public class EntranceService {
            if (StringUtils.isNotBlank(now)) {
                sbs.append("<query compy=\"&lt;\" item=\"ADM_DAT\" splice=\"and\" value=\"'" + now + "'\"/>");
            }
            if (StringUtils.isNotBlank(preday)) {
                sbs.append("<query compy=\"\" item=\"icd_name\" splice=\"and\" value=\"is not null\"/>");
            }
            sbs.append("<query compy=\"\" item=\"icd_name\" splice=\"and\" value=\"is not null\"/>");
            sbs.append("<order item=\"ADM_DAT\" sort=\"desc\"/>");
            //查询信息结束
            sbs.append("</MsgInfo></ESBEntry>");