소스 검색

fix 轮流接待客服

zoujiajian 1 년 전
부모
커밋
e690b84f02

+ 2 - 1
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -855,7 +855,8 @@ public class RedisService {
         NETFLIX_CHANGE_TICKET_KEY("netflix_change_ticket_key:", "奈飞更换车票key", 60l),
         CORP_KF_ACCOUNT_URL("corp_kf_account_url:", "微信客服url:", 60 * 60 * 6),
         CORP_KF_SESSION_KEY("corp_kf_session_key:%s:%s", "微信会话key", 3l),
-        CORP_KF_SEESION_ASSIGN_KEY("corp_kf_seesion_assign_key", "微信会话分配key", 60 * 60 * 24l)
+        CORP_KF_SEESION_ASSIGN_KEY("corp_kf_seesion_assign_key", "微信会话分配key", 60 * 60 * 24l),
+        CORP_KF_SEESION_SERVICER("corp_kf_seesion_servicer", "目前接待的客服", 60 * 60 * 12l)
         ;
 
         private String name;

+ 18 - 8
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpServiceImpl.java

@@ -1020,25 +1020,35 @@ public class CorpServiceImpl implements CorpService {
 			return;
 		}
 		//接待客服
-		CorpKfServicerDto corpKfServicerDto = null;
 		Integer assignType = corpKfAccountSessionConfig.getAssignType();
+		String servicerUserid = null;
 		if (assignType != null && assignType == 1) {
+			if (!redisService.hasKey(RedisService.key.CORP_KF_SEESION_ASSIGN_KEY.getName())) {
+				redisService.setNx(RedisService.key.CORP_KF_SEESION_ASSIGN_KEY.getName(), 0, RedisService.key.CORP_KF_SEESION_ASSIGN_KEY.getTimeout());
+			}
 			//轮流分配
 			Long incr = redisService.incr(RedisService.key.CORP_KF_SEESION_ASSIGN_KEY.getName(), 1l);
 			int index = incr.intValue() % corpKfServiceIds.size();
-			Optional<CorpKfServicerDto> first = filterKfCs.stream().filter(f -> f.getServicerUserid().equals(corpKfServiceIds.get(index))).findFirst();
-			if (first.isPresent()) {
-				corpKfServicerDto = first.get();
-				log.info("目前轮流接待的客服为:{}", corpKfServicerDto.getServicerUserid());
+			log.info("目前轮流incr是:{},接待人员list:{},轮流的下标:{}", incr, corpKfServiceIds.size(), index);
+			servicerUserid = corpKfServiceIds.get(index);
+			String present_servicer = redisService.getStr(RedisService.key.CORP_KF_SEESION_SERVICER.getName());
+			//目前接待客服重复 轮询至下一个
+			if (present_servicer != null && present_servicer.equals(servicerUserid)) {
+				log.info("轮流重复接待的下标:{}客服为:{}", index, servicerUserid);
+				incr = redisService.incr(RedisService.key.CORP_KF_SEESION_ASSIGN_KEY.getName(), 1l);
+				index = incr.intValue() % corpKfServiceIds.size();
+				servicerUserid = corpKfServiceIds.get(index);
 			}
+			log.info("目前轮流接待的下标:{}客服为:{}", index, servicerUserid);
+			redisService.set(RedisService.key.CORP_KF_SEESION_SERVICER.getName(), servicerUserid);
 		}
 		//未找到可轮流接待的客服
-		if (corpKfServicerDto == null) {
+		if (servicerUserid == null) {
 			//选择第一个分配接待
-			corpKfServicerDto = filterKfCs.get(0);
+			servicerUserid = filterKfCs.get(0).getServicerUserid();
 		}
 		//变更会话状态
-		transCorpKfSessionToServicer(corpId, openKfId, null, corpKfServicerDto.getServicerUserid(), externalUserid, null, 3, sendDate, msgid);
+		transCorpKfSessionToServicer(corpId, openKfId, null, servicerUserid, externalUserid, null, 3, sendDate, msgid);
 	}
 
 	private Boolean enterQueueIfExistsQueues(String openKfId, String externalUserid, CorpKfAccountSessionConfig corpKfAccountSessionConfig, Set<String> dutyFollowIds) throws Exception {