Bläddra i källkod

消息自动回复以及转接

wks 10 månader sedan
förälder
incheckning
7b9ebf2885

+ 12 - 0
src/main/java/com/ydtech/modules/admin/service/impl/WechatCustomerServiceImpl.java

@@ -25,11 +25,13 @@ import me.chanjar.weixin.cp.bean.kf.WxCpKfMsgSendRequest;
 import me.chanjar.weixin.cp.bean.kf.WxCpKfServiceStateResp;
 import me.chanjar.weixin.cp.bean.kf.msg.WxCpKfEventMsg;
 import me.chanjar.weixin.cp.bean.kf.msg.WxCpKfTextMsg;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 import org.springframework.util.ObjectUtils;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Slf4j
@@ -51,6 +53,8 @@ public class WechatCustomerServiceImpl implements WechatCustomerService {
 
     private final SysWechatCustomerDutyService sysWechatCustomerDutyService;
 
+    private final StringRedisTemplate redisTemplate;
+
     @Override
     public String customerCallback(String msgSignature, String timestamp, String nonce, String echoStr) {
         WxCryptUtil wxCryptUtil = wechatCustomerComponents.getWxCryptUtil();
@@ -77,6 +81,9 @@ public class WechatCustomerServiceImpl implements WechatCustomerService {
         List<WxCpKfMsgListResp.WxCpKfMsgItem> msgList = wxCpKfMsgListResp.getMsgList();
         WxCpKfMsgListResp.WxCpKfMsgItem wxCpKfMsgItem = wxCpKfMsgListResp.getMsgList().get(msgList.size() - 1);
 
+
+
+
         SysWechatCustomer sysWechatCustomer = sysWechatCustomerService.lambdaQuery().eq(SysWechatCustomer::getOpenKfId, wechatCustomerCallbackVo.getOpenKfId()).one();
         boolean workingHours = workScheduleConfigService.isWorkingHours();
         List<SysWechatCustomerDuty> sysWechatCustomerDuties = sysWechatCustomerDutyService.lambdaQuery()
@@ -98,7 +105,12 @@ public class WechatCustomerServiceImpl implements WechatCustomerService {
                     wxCpKfService.transServiceState(wxCpKfMsgItem.getOpenKfid(), wxCpKfMsgItem.getExternalUserId(), state1, sysWechatCustomer.getReceptionistId());
                     restTimeSendMsg(wxCpKfMsgItem.getExternalUserId(), wxCpKfMsgItem.getOpenKfid());
                 } else if (state1 == 1) {
+                    String s = redisTemplate.opsForValue().get(wxCpKfMsgItem.getMsgId());
+                    if (!ObjectUtils.isEmpty(s)) {
+                        return;
+                    }
                     restTimeSendMsg(wxCpKfMsgItem.getExternalUserId(), wxCpKfMsgItem.getOpenKfid());
+                    redisTemplate.opsForValue().set(wxCpKfMsgItem.getMsgId(), wxCpKfMsgItem.getMsgId(), 1, TimeUnit.MINUTES);
                 } else if (state1 == 3) {
                     state1 = 4;
                     wxCpKfService.transServiceState(wxCpKfMsgItem.getOpenKfid(), wxCpKfMsgItem.getExternalUserId(), state1, sysWechatCustomer.getReceptionistId());