| | |
| | | continue; |
| | | } |
| | | ServiceSubtaskStatistic statistic = getStatistic(serviceSubtaskList, serviceSubtaskCountReq.getFollowUpCountStyle(), serviceSubtaskCountReq.getVisitCount()); |
| | | // hzszlyy:前端不改字段,直接把累计值回填到原 manual/voice/sms/weChat 及 Again 字段 |
| | | applySiteCumulativeOverride(statistic); |
| | | if ("taskid".equals(groupKey)) { |
| | | applyTaskGroupInfo(statistic, serviceSubtaskList); |
| | | } |
| | |
| | | }//二次出院随访 |
| | | else if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() > 1) { |
| | | applyAgainFollowUpExtraStatistics(serviceSubtaskStatistic, serviceSubtask); |
| | | applyAgainCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle); |
| | | //再次应随访 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) { |
| | | serviceSubtaskStatistic.setNeedFollowUpAgain(serviceSubtaskStatistic.getNeedFollowUpAgain() + 1L); |
| | |
| | | /** 发送方式编码:微信 */ |
| | | private static final String PREACHFORM_WECHAT = "5"; |
| | | |
| | | /** 累计位图:语音 */ |
| | | private static final int CUMULATIVE_MASK_VOICE = 1; |
| | | /** 累计位图:微信 */ |
| | | private static final int CUMULATIVE_MASK_WECHAT = 1 << 1; |
| | | /** 累计位图:短信 */ |
| | | private static final int CUMULATIVE_MASK_SMS = 1 << 2; |
| | | /** 累计位图:人工 */ |
| | | private static final int CUMULATIVE_MASK_MANUAL = 1 << 3; |
| | | /** 需要把累计值回填到原字段的站点 */ |
| | | private static final String SITE_HZSZLYY = "hzszlyy"; |
| | | |
| | | /** |
| | | * 首次随访「累计发送方式」统计。 |
| | | * <p> |
| | |
| | | if (!isCumulativePreachformCountable(serviceSubtask, followUpCountStyle)) { |
| | | return; |
| | | } |
| | | int mask = resolveCumulativePreachformMask(serviceSubtask); |
| | | if ((mask & CUMULATIVE_MASK_VOICE) != 0) { |
| | | statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_WECHAT) != 0) { |
| | | statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_SMS) != 0) { |
| | | statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_MANUAL) != 0) { |
| | | statistic.setManualCumulative(statistic.getManualCumulative() + 1L); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 再次随访「累计发送方式」统计,口径与 {@link #applyFirstCumulativePreachformStatistics} 一致。 |
| | | */ |
| | | private void applyAgainCumulativePreachformStatistics(ServiceSubtaskStatistic statistic, |
| | | ServiceSubtask serviceSubtask, |
| | | String followUpCountStyle) { |
| | | if (serviceSubtask.getVisitCount() == null || serviceSubtask.getVisitCount() <= 1) { |
| | | return; |
| | | } |
| | | if (!isCumulativePreachformCountable(serviceSubtask, followUpCountStyle)) { |
| | | return; |
| | | } |
| | | int mask = resolveCumulativePreachformMask(serviceSubtask); |
| | | if ((mask & CUMULATIVE_MASK_VOICE) != 0) { |
| | | statistic.setVoiceAgainCumulative(statistic.getVoiceAgainCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_WECHAT) != 0) { |
| | | statistic.setWeChatAgainCumulative(statistic.getWeChatAgainCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_SMS) != 0) { |
| | | statistic.setSmsAgainCumulative(statistic.getSmsAgainCumulative() + 1L); |
| | | } |
| | | if ((mask & CUMULATIVE_MASK_MANUAL) != 0) { |
| | | statistic.setManualAgainCumulative(statistic.getManualAgainCumulative() + 1L); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 计算某条子任务“已进入过”的发送方式位图。 |
| | | * <p> |
| | | * current_preachform 为空取第一个;= -1 视为全部遍历完;不在顺序里时退化为精确匹配。 |
| | | */ |
| | | private int resolveCumulativePreachformMask(ServiceSubtask serviceSubtask) { |
| | | List<String> order = splitPreachformOrder(serviceSubtask.getPreachform()); |
| | | String current = StringUtils.isNotBlank(serviceSubtask.getCurrentPreachform()) |
| | | ? serviceSubtask.getCurrentPreachform().trim() |
| | | : (order.isEmpty() ? null : order.get(0)); |
| | | if (order.isEmpty()) { |
| | | // 没有顺序时退化为“当前方式精确匹配”,与 SQL 的 normalizedPreachformExpr = '' 分支一致 |
| | | if (current != null) { |
| | | increaseExactCumulative(statistic, current); |
| | | } |
| | | return; |
| | | return exactCumulativeMask(current); |
| | | } |
| | | int currentPosition; |
| | | if ("-1".equals(current)) { |
| | | // -1 表示所有发送方式都已遍历完,相当于停在最后一个位置 |
| | | currentPosition = order.size(); |
| | | } else { |
| | | int currentIndex = order.indexOf(current); |
| | | if (currentIndex < 0) { |
| | | // 历史异常值不在配置顺序里:只按精确匹配兜底,避免把前后方式都算进去 |
| | | increaseExactCumulative(statistic, current); |
| | | return; |
| | | return exactCumulativeMask(current); |
| | | } |
| | | currentPosition = currentIndex + 1; |
| | | } |
| | | int mask = 0; |
| | | if (reachedPreachform(order, PREACHFORM_VOICE, currentPosition)) { |
| | | statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L); |
| | | mask |= CUMULATIVE_MASK_VOICE; |
| | | } |
| | | if (reachedPreachform(order, PREACHFORM_WECHAT, currentPosition)) { |
| | | statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L); |
| | | mask |= CUMULATIVE_MASK_WECHAT; |
| | | } |
| | | if (reachedPreachform(order, PREACHFORM_SMS, currentPosition)) { |
| | | statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L); |
| | | mask |= CUMULATIVE_MASK_SMS; |
| | | } |
| | | if (reachedPreachform(order, PREACHFORM_MANUAL, currentPosition)) { |
| | | statistic.setManualCumulative(statistic.getManualCumulative() + 1L); |
| | | mask |= CUMULATIVE_MASK_MANUAL; |
| | | } |
| | | return mask; |
| | | } |
| | | |
| | | private int exactCumulativeMask(String current) { |
| | | if (PREACHFORM_MANUAL.equals(current)) { |
| | | return CUMULATIVE_MASK_MANUAL; |
| | | } |
| | | if (PREACHFORM_VOICE.equals(current)) { |
| | | return CUMULATIVE_MASK_VOICE; |
| | | } |
| | | if (PREACHFORM_SMS.equals(current)) { |
| | | return CUMULATIVE_MASK_SMS; |
| | | } |
| | | if (PREACHFORM_WECHAT.equals(current)) { |
| | | return CUMULATIVE_MASK_WECHAT; |
| | | } |
| | | return 0; |
| | | } |
| | | |
| | | private boolean isCumulativePreachformCountable(ServiceSubtask serviceSubtask, String followUpCountStyle) { |
| | |
| | | return position >= 0 && currentPosition >= position + 1; |
| | | } |
| | | |
| | | private void increaseExactCumulative(ServiceSubtaskStatistic statistic, String current) { |
| | | if (PREACHFORM_MANUAL.equals(current)) { |
| | | statistic.setManualCumulative(statistic.getManualCumulative() + 1L); |
| | | } else if (PREACHFORM_VOICE.equals(current)) { |
| | | statistic.setVoiceCumulative(statistic.getVoiceCumulative() + 1L); |
| | | } else if (PREACHFORM_SMS.equals(current)) { |
| | | statistic.setSmsCumulative(statistic.getSmsCumulative() + 1L); |
| | | } else if (PREACHFORM_WECHAT.equals(current)) { |
| | | statistic.setWeChatCumulative(statistic.getWeChatCumulative() + 1L); |
| | | /** |
| | | * hzszlyy 站点保持前端字段不变:把累计值回填到原 manual/voice/sms/weChat 及 Again 字段。 |
| | | * <p> |
| | | * 其它站点不覆盖,继续使用原来的“当前方式精确匹配”口径。 |
| | | */ |
| | | private void applySiteCumulativeOverride(ServiceSubtaskStatistic statistic) { |
| | | if (!SITE_HZSZLYY.equals(active)) { |
| | | return; |
| | | } |
| | | statistic.setManual(nvlLong(statistic.getManualCumulative())); |
| | | statistic.setVoice(nvlLong(statistic.getVoiceCumulative())); |
| | | statistic.setSms(nvlLong(statistic.getSmsCumulative())); |
| | | statistic.setWeChat(nvlLong(statistic.getWeChatCumulative())); |
| | | statistic.setManualAgain(nvlLong(statistic.getManualAgainCumulative())); |
| | | statistic.setVoiceAgain(nvlLong(statistic.getVoiceAgainCumulative())); |
| | | statistic.setSmsAgain(nvlLong(statistic.getSmsAgainCumulative())); |
| | | statistic.setWeChatAgain(nvlLong(statistic.getWeChatAgainCumulative())); |
| | | } |
| | | |
| | | /** |
| | | * 超链接下钻的发送方式条件。 |
| | | * <p> |
| | | * hzszlyy 站点的前端不改字段,仍点原来的 manualInfo/voiceInfo/..., |
| | | * 后端改用累计口径;其它站点保持 current_preachform 精确匹配。 |
| | | */ |
| | | private void applyPreachformInfoCondition(ServiceSubtaskCountReq serviceSubtaskCountReq, |
| | | int visitCount, |
| | | String preachform) { |
| | | serviceSubtaskCountReq.setVisitCount(visitCount); |
| | | if (SITE_HZSZLYY.equals(active)) { |
| | | serviceSubtaskCountReq.setCumulativePreachform(preachform); |
| | | } else { |
| | | serviceSubtaskCountReq.setCurrentPreachform(preachform); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | //再次出院随访 |
| | | if (serviceSubtask.getVisitCount() != null && serviceSubtask.getVisitCount() > 1) { |
| | | applyAgainCumulativePreachformStatistics(serviceSubtaskStatistic, serviceSubtask, followUpCountStyle); |
| | | //再次应随访 |
| | | if (serviceSubtask.getSendstate() != null && serviceSubtask.getSendstate() != 4) { |
| | | serviceSubtaskStatistic.setNeedFollowUpAgain(serviceSubtaskStatistic.getNeedFollowUpAgain() + 1L); |
| | |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Arrays.asList(5L, 7L))); |
| | | break; |
| | | case "manualInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setCurrentPreachform("1"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_MANUAL); |
| | | break; |
| | | case "voiceInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setCurrentPreachform("3"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_VOICE); |
| | | break; |
| | | case "smsInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setCurrentPreachform("4"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_SMS); |
| | | break; |
| | | case "weChatInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 1, PREACHFORM_WECHAT); |
| | | break; |
| | | // 累计口径:按 preachform 的执行顺序,current_preachform 位于该方式及之后即计入 |
| | | case "voiceCumulativeInfo": |
| | |
| | | serviceSubtaskCountReq.setSendstates(new ArrayList<>(Arrays.asList(5L, 7L))); |
| | | break; |
| | | case "manualAgainInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setCurrentPreachform("1"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_MANUAL); |
| | | break; |
| | | case "voiceAgainInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setCurrentPreachform("3"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_VOICE); |
| | | break; |
| | | case "smsAgainInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setCurrentPreachform("4"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_SMS); |
| | | break; |
| | | case "weChatAgainInfo": |
| | | serviceSubtaskCountReq.setVisitCount(2); |
| | | serviceSubtaskCountReq.setCurrentPreachform("5"); |
| | | applyPreachformInfoCondition(serviceSubtaskCountReq, 2, PREACHFORM_WECHAT); |
| | | break; |
| | | case "manualAgainSuccessInfo": |
| | | serviceSubtaskCountReq.setVisitCount(1); |