| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | |
| | | /** |
| | | * 妇幼随访消息发送器。 |
| | | * |
| | |
| | | |
| | | public MchFollowupSendOutcome sendSms(MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | String phone = plan == null ? null : plan.getPhone(); |
| | | String content = item == null ? null : item.getContent(); |
| | | String content = item == null ? null : renderContent(item.getContent(), plan, item); |
| | | if (StringUtils.isBlank(phone)) { |
| | | return MchFollowupSendOutcome.skip("手机号为空"); |
| | | } |
| | |
| | | message.setIdCard(plan.getIdcardno()); |
| | | message.setMobile(phone); |
| | | message.setMedCardNo(plan.getSourceBizNo()); |
| | | message.setTitleName(item.getTitleName()); |
| | | message.setContent(item.getContent()); |
| | | message.setTitleName(renderContent(item.getTitleName(), plan, item)); |
| | | message.setContent(renderContent(item.getContent(), plan, item)); |
| | | message.setUrl(item.getUrl()); |
| | | |
| | | String requestBody = requestSummary("wechat", phone, item.getTemplateId()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 渲染妇幼随访内容占位符。当前支持: |
| | | * ${patname}、${patid}、${phone}、${idcardno}、${plannedFollowTime}、 |
| | | * ${sourceBizNo}、${archiveType}、${orgid}、${seq}。 |
| | | */ |
| | | String renderContent(String text, MchFollowupPlan plan, MchFollowupPlanItem item) { |
| | | if (StringUtils.isBlank(text) || plan == null) { |
| | | return text; |
| | | } |
| | | String result = text; |
| | | result = result.replace("${patname}", nvl(plan.getPatname())); |
| | | result = result.replace("${patid}", plan.getPatid() == null ? "" : String.valueOf(plan.getPatid())); |
| | | result = result.replace("${phone}", nvl(plan.getPhone())); |
| | | result = result.replace("${idcardno}", nvl(plan.getIdcardno())); |
| | | result = result.replace("${sourceBizNo}", nvl(plan.getSourceBizNo())); |
| | | result = result.replace("${archiveType}", nvl(plan.getArchiveType())); |
| | | result = result.replace("${orgid}", nvl(plan.getOrgid())); |
| | | result = result.replace("${seq}", item == null || item.getSeq() == null ? "" : String.valueOf(item.getSeq())); |
| | | if (plan.getPlannedFollowTime() != null) { |
| | | result = result.replace("${plannedFollowTime}", |
| | | new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(plan.getPlannedFollowTime())); |
| | | } else { |
| | | result = result.replace("${plannedFollowTime}", ""); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private String nvl(String value) { |
| | | return value == null ? "" : value; |
| | | } |
| | | |
| | | private String requestSummary(String sendType, String phone, Long templateId) { |
| | | return "sendType=" + sendType |
| | | + ";phone=" + maskPhone(phone) |