Explorar o código

fix 客服关联关系

zoujiajian %!s(int64=2) %!d(string=hai) anos
pai
achega
8437273187

+ 3 - 1
netflix-dao/src/main/java/com/cyksj/mapper/corp/CorpFollowDutyRelateMapper.java

@@ -13,5 +13,7 @@ import java.util.List;
  * 创建时间:2023/10/9 17:20
  */
 public interface CorpFollowDutyRelateMapper extends BaseMapper<CorpFollowDutyRelate> {
-	List<CorpFollowDutyRelate> selectCorpFollowRelate(@Param("list") List<String> followIds);
+	List<CorpFollowDutyRelate> selectCorpFollowRelate(@Param("list") List<String> followIds, @Param("isWeekend") Boolean isWeekend);
+
+	List<CorpFollowDutyRelate> selectTodayDutyRelate(@Param("followIds") List<String> followIds, @Param("type") Integer type);
 }

+ 37 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/YhServiceDto.java

@@ -0,0 +1,37 @@
+package com.cyksj.model.dto;
+
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: YhServiceDto
+ * 创建者: JavaZou
+ * 创建时间:2023/10/10 16:12
+ */
+@Getter
+@Setter
+public class YhServiceDto {
+	private String startTime;
+
+	private String endTime;
+
+	private Integer index;
+
+	private List<CustomerServiceDto> select;
+
+
+	@Getter
+	@Setter
+	public static class CustomerServiceDto{
+		private String name;
+
+		private String img;
+
+		private Integer index;
+
+		private String url;
+	}
+}

+ 7 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/CorpFollowDutyRelate.java

@@ -32,4 +32,11 @@ public class CorpFollowDutyRelate extends BaseEntity{
 	private Integer st;
 
 	private Integer et;
+
+	private Integer index;
+
+	/**
+	 * 1工作日,2.周六,3周末
+	 */
+	private Integer type;
 }

+ 9 - 2
netflix-dao/src/main/resources/mapper/CorpFollowDutyRelateMapper.xml

@@ -5,10 +5,17 @@
 
 
     <select id="selectCorpFollowRelate" resultType="com.cyksj.model.entity.CorpFollowDutyRelate">
-        select * from corp_follow_duty_relate where follow_id in
+        select st,et,index from corp_follow_duty_relate where follow_id in
+        <foreach collection="list" item="item" open="(" separator="," close=")">
+            #{item}
+        </foreach> and is_weekend is ${isWeekend} group by st,et,index
+    </select>
+
+    <select id="selectTodayDutyRelate" resultType="com.cyksj.model.entity.CorpFollowDutyRelate">
+        select st,et from corp_follow_duty_relate where follow_id in
         <foreach collection="list" item="item" open="(" separator="," close=")">
             #{item}
         </foreach>
-        and st = (select st from corp_follow_duty_relate order by st limit 1)
+        and type = #{type} group by st,et order by st
     </select>
 </mapper>

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/corp/CorpFollowService.java

@@ -14,4 +14,6 @@ public interface CorpFollowService{
 	void upActiveCode(CorpFollowActiveCode activeCode) throws Exception;
 
 	void deleteActiveCodeById(Long id);
+
+	void syncActiveCodeFollowRelate(String config) throws Exception;
 }

+ 98 - 11
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpFollowActiveCodeFrontServiceImpl.java

@@ -1,7 +1,9 @@
 package com.cyksj.service.corp.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.date.Week;
 import cn.hutool.core.util.RandomUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -17,6 +19,7 @@ import com.cyksj.model.entity.CorpFollowDutyRelate;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
 import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -30,6 +33,7 @@ import java.util.stream.Collectors;
  */
 @Service
 @RequiredArgsConstructor
+@Slf4j
 public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCodeFrontService {
 
 	private final CorpFollowActiveCodeMapper corpFollowActiveCodeMapper;
@@ -56,33 +60,116 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
 		if (StrUtil.isNotBlank(qrCode)) {
 			return qrCode;
 		}
+		Week week = DateUtil.dayOfWeekEnum(DateTime.now());
+		Integer type = 1;
+		if (week == Week.SATURDAY) {
+			type = 2;
+		}
+		if (week == Week.SUNDAY) {
+			type = 3;
+		}
 		String followStr = corpFollowActiveCode.getFollowStr();
 		List<CorpFollow> corpFollows = Jsons.parseList(followStr, CorpFollow.class);
 		List<String> followIds = corpFollows.stream().map(CorpFollow::getUserid).collect(Collectors.toList());
 		String codeStr = corpFollowActiveCode.getCodeStr();
 		List<CorpFollowActiveCodeDto> activeCodeDtos = Jsons.parseList(codeStr, CorpFollowActiveCodeDto.class);
+		if (CollUtil.isEmpty(activeCodeDtos)) {
+			return null;
+		}
+		if (!corpFollowActiveCode.getIsDuty()) {
+			qrCode = activeCodeDtos.get(0).getQrCode();
+			redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
+			return qrCode;
+		}
+		//星期五-->星期六 星期六--->星期天 星期天-->星期一
 		//值班
 		if (corpFollowActiveCode.getIsDuty()) {
+			if (activeCodeDtos.size() == 1) {
+				CorpFollowActiveCodeDto corpFollowActiveCodeDto = activeCodeDtos.get(0);
+				qrCode = corpFollowActiveCodeDto.getQrCode();
+				redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
+				return qrCode;
+			}
 			List<CorpFollowDutyRelate> corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
-					.ge(CorpFollowDutyRelate::getSt, hour)
-					.le(CorpFollowDutyRelate::getEt, hour)
-					.in(CorpFollowDutyRelate::getFollowId, followIds));
-			if (corpFollowDutyRelates.size() > 0) {
+					.eq(CorpFollowDutyRelate::getSt, hour)
+					.eq(CorpFollowDutyRelate::getEt, hour)
+					.eq(CorpFollowDutyRelate::getType, type));
+			if (CollUtil.isNotEmpty(corpFollowDutyRelates)) {
 				qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
 				redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
 				return qrCode;
 			}
-			corpFollowDutyRelates = corpFollowDutyRelateMapper.selectCorpFollowRelate(followIds);
+			Integer index = 1;
+			//未在时间期间
+			//若在当天之前
+			//若在当天之后 寻找下日值班客服
+			List<CorpFollowDutyRelate> todayCorpFollowDuty = corpFollowDutyRelateMapper.selectTodayDutyRelate(followIds, type);
+			CorpFollowDutyRelate relate = todayCorpFollowDuty.get(0);
+			Integer st = relate.getSt();
+			Integer et = relate.getEt();
+			//当天
+			if (hour < st) {
+				qrCode = getActiveQrCode(corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+						.eq(CorpFollowDutyRelate::getSt, st)
+						.eq(CorpFollowDutyRelate::getEt, et)
+						.eq(CorpFollowDutyRelate::getType, type)), activeCodeDtos);
+				redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
+				return qrCode;
+			}
+			//下一天
+			CorpFollowDutyRelate corpFollowDutyRelate = todayCorpFollowDuty.get(todayCorpFollowDuty.size() - 1);
+			Integer f_et = corpFollowDutyRelate.getEt();
+			//如果是周五-->周六 周六下午-->周日 周日下午-->周一
+			if (hour > f_et) {
+				if (week == Week.FRIDAY) {
+					index = 3;
+					corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+							.eq(CorpFollowDutyRelate::getIndex, index)
+							.in(CorpFollowDutyRelate::getFollowId, followIds));
+					if (CollUtil.isEmpty(corpFollowDutyRelates)) {
+						index = 4;
+						corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+								.eq(CorpFollowDutyRelate::getIndex, index)
+								.in(CorpFollowDutyRelate::getFollowId, followIds));
+					}
+					qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
+				} else if (week == Week.SATURDAY) {
+					index = 5;
+					corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+							.eq(CorpFollowDutyRelate::getIndex, index)
+							.in(CorpFollowDutyRelate::getFollowId, followIds));
+					if (CollUtil.isEmpty(corpFollowDutyRelates)) {
+						index = 6;
+						corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+								.eq(CorpFollowDutyRelate::getIndex, index)
+								.in(CorpFollowDutyRelate::getFollowId, followIds));
+					}
+					qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
+				}else {
+					index = 1;
+					corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+							.eq(CorpFollowDutyRelate::getIndex, index)
+							.in(CorpFollowDutyRelate::getFollowId, followIds));
+					if (CollUtil.isEmpty(corpFollowDutyRelates)) {
+						index = 2;
+						corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+								.eq(CorpFollowDutyRelate::getIndex, index)
+								.in(CorpFollowDutyRelate::getFollowId, followIds));
+					}
+					qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
+				}
+				redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
+				return qrCode;
+			}
+			//兜底
+			log.info("当前时间:{}客户通过活动acId:{}未到获取客服活码,进行兜底", DateTime.now(), acId);
+			corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+					.in(CorpFollowDutyRelate::getFollowId, followIds));
 			qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
 			redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
 			return qrCode;
 		}
-		if (CollUtil.isEmpty(activeCodeDtos)) {
-			return null;
-		}
-		qrCode = activeCodeDtos.get(0).getQrCode();
-		redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
-		return qrCode;
+		return null;
 	}
 
 

+ 37 - 0
netflix-service/src/main/java/com/cyksj/service/corp/impl/CorpFollowServiceImpl.java

@@ -1,6 +1,8 @@
 package com.cyksj.service.corp.impl;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.constant.Constant;
@@ -8,9 +10,11 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
 import com.cyksj.mapper.corp.CorpFollowDutyRelateMapper;
+import com.cyksj.model.dto.YhServiceDto;
 import com.cyksj.model.entity.CmsUser;
 import com.cyksj.model.entity.CorpFollow;
 import com.cyksj.model.entity.CorpFollowActiveCode;
+import com.cyksj.model.entity.CorpFollowDutyRelate;
 import com.cyksj.service.corp.CorpFollowDynamicConfigService;
 import com.cyksj.service.corp.CorpFollowService;
 import com.cyksj.service.mange.cms.CmsUserManager;
@@ -138,4 +142,37 @@ public class CorpFollowServiceImpl implements CorpFollowService {
 				.set(CorpFollowActiveCode::getDeleted, false)
 				.eq(CorpFollowActiveCode::getDeleted, true));
 	}
+
+	@Override
+	public void syncActiveCodeFollowRelate(String config) throws Exception {
+		if (StrUtil.isEmpty(config)) {
+			return;
+		}
+		List<YhServiceDto> yhServiceDtos = Jsons.parseList(config, YhServiceDto.class);
+		yhServiceDtos.forEach(data -> {
+			DateTime stTime = DateUtil.parse(data.getStartTime(), "HH:mm");
+			int st = stTime.hour(true);
+			DateTime etTime = DateUtil.parse(data.getEndTime(), "HH:mm");
+			int et = etTime.hour(true);
+			List<YhServiceDto.CustomerServiceDto> select = data.getSelect();
+			select.forEach(cs -> {
+				String name = cs.getName();
+				CorpFollowDutyRelate relate = Optional.ofNullable(corpFollowDutyRelateMapper.selectOne(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
+						.eq(CorpFollowDutyRelate::getServiceName, name).last("limit 1"))).orElse(new CorpFollowDutyRelate());
+				relate.setServiceName(name);
+				relate.setSt(st);
+				relate.setEt(et);
+				Integer index = cs.getIndex();
+				relate.setIndex(index);
+				//1工作日,2.周六,3周末
+				Integer type = index <= 2 ? 1 : index <= 4 ? 2 : 3;
+				relate.setType(type);
+				if (relate.getId() == null) {
+					corpFollowDutyRelateMapper.insert(relate);
+				} else {
+					corpFollowDutyRelateMapper.updateById(relate);
+				}
+			});
+		});
+	}
 }

+ 8 - 0
netflix-web/src/main/java/com/cyksj/web/controller/sys/SysConfigController.java

@@ -18,6 +18,7 @@ import com.cyksj.model.entity.HelpQuestion;
 import com.cyksj.model.entity.HelpQuestionClassification;
 import com.cyksj.model.entity.SysConfig;
 import com.cyksj.model.views.HelpQuestionClassificationView;
+import com.cyksj.service.corp.CorpFollowService;
 import com.cyksj.service.sys.SysConfigService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -42,6 +43,8 @@ public class SysConfigController {
 
 	private final HelpQuestionClassificationMapper helpQuestionClassificationMapper;
 
+	private final CorpFollowService corpFollowService;
+
 	@GetMapping("/get")
 	public Result<SysConfig> get(String key) {
 		SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class).eq(SysConfig::getSysKey, key).last(" limit 1"));
@@ -78,6 +81,11 @@ public class SysConfigController {
 			}
 		}
 
+		if (Constant.serviceKeys.get(0).equals(sysConfig.getSysKey())) {
+			//同步活码客服关联配置
+			corpFollowService.syncActiveCodeFollowRelate(sysConfig.getSysValue());
+		}
+
 		sysConfigService.updateById(sysConfig);
 
 		return GatewayResponse.SUCCESS.newBuilder().toResult(sysConfig);