From 5ee20feac141169568e8eeca9989534d4a672181 Mon Sep 17 00:00:00 2001 From: WendyYang Date: Mon, 17 Apr 2023 15:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=94=B5=E8=AF=9D=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E5=9B=9E=E5=A1=AB=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pmapi/meeting/entity/dto/YxtCallBackDTO.java | 43 ++++++++++++++++ .../meeting/task/ExpertCallResultRewriteTask.java | 57 ++++++++++------------ 2 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/YxtCallBackDTO.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/YxtCallBackDTO.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/YxtCallBackDTO.java new file mode 100644 index 0000000..4a1a5a2 --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/entity/dto/YxtCallBackDTO.java @@ -0,0 +1,43 @@ +/** + * Copyright 2023 json.cn + */ +package com.ningdatech.pmapi.meeting.entity.dto; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + *

+ * 电话结果回调内容 + *

+ * + * @author WendyYang + * @since 2023/4/17 + **/ +@Data +public class YxtCallBackDTO { + + private Integer duration; + + private String pressKey; + + private String receiveNumber; + + private LocalDateTime dialEndTime; + + private Integer resultCode; + + private Integer retryNumber; + + private String failCode; + + private LocalDateTime dialBeginTime; + + private String sendNumber; + + private String failReason; + + private String transactionId; + +} \ No newline at end of file diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertCallResultRewriteTask.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertCallResultRewriteTask.java index 518c69a..92be74b 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertCallResultRewriteTask.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/task/ExpertCallResultRewriteTask.java @@ -1,7 +1,6 @@ package com.ningdatech.pmapi.meeting.task; import cn.hutool.core.util.ObjectUtil; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -14,6 +13,7 @@ import com.ningdatech.pmapi.meeting.entity.domain.ExpertInviteRule; import com.ningdatech.pmapi.meeting.entity.domain.Meeting; import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert; import com.ningdatech.pmapi.meeting.entity.dto.RandomInviteRuleDTO; +import com.ningdatech.pmapi.meeting.entity.dto.YxtCallBackDTO; import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum; import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertInviteTypeEnum; import com.ningdatech.pmapi.meeting.helper.YxtCallOrSmsHelper; @@ -28,7 +28,6 @@ import com.ningdatech.yxt.model.cmd.SendSmsCmd.SendSmsContext; import com.ningdatech.yxt.service.ISysMsgRecordDetailService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Component; @@ -69,6 +68,8 @@ public class ExpertCallResultRewriteTask { private final IExpertUserFullInfoService userFullInfoService; private final static int MINUTES_CALL_RESULT_FEEDBACK = 15; + private static final String AGREE_KEY = "1"; + @PostConstruct public void initTask() { if (!randomInviteProperties.getEnable()) { @@ -77,7 +78,8 @@ public class ExpertCallResultRewriteTask { } Instant startTime = Instant.now().plus(randomInviteProperties.getResultRewriteFixedRate(), ChronoUnit.MINUTES); // 处理电话结果回填 - scheduler.scheduleAtFixedRate(this::rewritePhoneCallResult, startTime, Duration.ofMinutes(randomInviteProperties.getResultRewriteFixedRate())); + Duration fixedRate = Duration.ofMinutes(randomInviteProperties.getResultRewriteFixedRate()); + scheduler.scheduleAtFixedRate(this::rewritePhoneCallResult, startTime, fixedRate); } @@ -101,7 +103,7 @@ public class ExpertCallResultRewriteTask { if (!randomRuleIds.isEmpty()) { List inviteRules = inviteRuleService.listByIds(randomRuleIds); inviteRules.forEach(w -> { - RandomInviteRuleDTO rule = JSON.parseObject(w.getInviteRule(), RandomInviteRuleDTO.class); + RandomInviteRuleDTO rule = JSONObject.parseObject(w.getInviteRule(), RandomInviteRuleDTO.class); callbackMinutes.put(w.getId(), rule.getWaitForCallbackMinutes()); }); } @@ -172,44 +174,37 @@ public class ExpertCallResultRewriteTask { } } - private static Optional getStatusByMsgRecordDetail(SysMsgRecordDetail msgRecordDetail, int minutes, LocalDateTime createOn) { - LocalDateTime time = LocalDateTime.now().minusMinutes(minutes); - String callBackJson = msgRecordDetail.getCallBackJson(); - if (StrUtils.isBlank(callBackJson) && time.isBefore(createOn)) { + private static Optional getStatusByMsgRecordDetail(SysMsgRecordDetail mrd, int minutes, LocalDateTime createOn) { + LocalDateTime limitTime = LocalDateTime.now().minusMinutes(minutes); + String callBackJson = mrd.getCallBackJson(); + boolean waiting = limitTime.isBefore(createOn); + boolean hasCallBack = StrUtils.isBlank(callBackJson); + if (!hasCallBack && waiting) { return Optional.empty(); } ExpertAttendStatusEnum status; - if (StrUtils.isNotBlank(callBackJson)) { + if (hasCallBack) { try { - JSONObject callbackObject = JSON.parseObject(callBackJson); - Date dialBeginTime = callbackObject.getDate("dialBeginTime"); + YxtCallBackDTO callback = JSONObject.parseObject(callBackJson, YxtCallBackDTO.class); + LocalDateTime dialBeginTime = callback.getDialBeginTime(); if (dialBeginTime == null) { return Optional.empty(); } - Integer resultCode = callbackObject.getInteger("resultCode"); + Integer resultCode = callback.getResultCode(); if (resultCode != null && resultCode == 0) { - String pressKeyStr = callbackObject.getString("pressKey"); - if (Objects.nonNull(pressKeyStr)) { - pressKeyStr = pressKeyStr.replaceAll("\\*", "").trim(); - } - Integer pressKey = null; - if (StringUtils.isNotBlank(pressKeyStr)) { - pressKey = Integer.parseInt(pressKeyStr); + String pressKey = callback.getPressKey(); + if (pressKey != null) { + pressKey = pressKey.replaceAll("\\*", "").trim(); } - if (pressKey == null) { - if (time.isBefore(createOn)) { - return Optional.empty(); - } - status = REFUSED; - } else { - if (pressKey == 1) { - status = AGREED; - } else { - status = REFUSED; - } + if (StrUtils.isBlank(pressKey) && waiting) { + return Optional.empty(); } + status = AGREE_KEY.equals(pressKey) ? AGREED : REFUSED; } else { - status = UNANSWERED; + if (waiting) { + return Optional.empty(); + } + status = REFUSED; } } catch (Exception e) { log.error("获取电话回调结果异常", e);