Browse Source

fix 节假日值班

zoujiajian 2 years ago
parent
commit
a71f122449

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/CorpFollowServiceDto.java

@@ -15,5 +15,7 @@ public class CorpFollowServiceDto {
 
 	private String name;
 
+	private Integer indx;
+
 	private String followId;
 }

+ 3 - 1
netflix-dao/src/main/java/com/cyksj/model/dto/YhServiceDto.java

@@ -25,7 +25,7 @@ public class YhServiceDto {
 	private Integer index;
 
 	/**
-	 * workday工作日 Saturday周六 Sunday周日
+	 * workday工作日 Saturday周六 Sunday周日 holiday节假日
 	 */
 	private String sign;
 
@@ -37,6 +37,8 @@ public class YhServiceDto {
 
 	private String sortTime;
 
+	private String date;
+
 
 	@Getter
 	@Setter

+ 65 - 0
netflix-service/src/main/java/com/cyksj/common/service/CropDutyServiceDateService.java

@@ -0,0 +1,65 @@
+package com.cyksj.common.service;
+
+
+import cn.hutool.core.collection.CollUtil;
+import com.cyksj.model.dto.YhServiceDto;
+
+import java.time.DayOfWeek;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * 项目名: netflix-job
+ * 文件名: DateUtils
+ * 创建者: JavaZou
+ * 创建时间:2023/12/25 13:52
+ */
+public class CropDutyServiceDateService {
+
+	public static DayOfWeek getNextWorkDay(DayOfWeek currentDay) {
+		// 如果当前是周五,下一个工作日是周一;否则,是当前星期的下一天
+		if (currentDay == DayOfWeek.FRIDAY) {
+			return DayOfWeek.SATURDAY;
+		}
+		if (currentDay == DayOfWeek.SATURDAY) {
+			return DayOfWeek.SUNDAY;
+		}
+		return DayOfWeek.MONDAY;
+	}
+
+
+	/**
+	 * 返回明天星期几 用户获取对应周期工作客服
+	 */
+	public static List<YhServiceDto> getDutyService(DayOfWeek nextWorkDay, List<YhServiceDto> workday, List<YhServiceDto> sunday, List<YhServiceDto> saturday, Map<String, List<YhServiceDto>> holidyDateMap, LocalDateTime now) {
+		List<YhServiceDto> holidayServiceIfHoliday = getHolidayServiceIfHoliday(now, holidyDateMap);
+		if (holidayServiceIfHoliday != null) {
+			return holidayServiceIfHoliday;
+		}
+		if (nextWorkDay == DayOfWeek.SATURDAY) {
+			return Optional.ofNullable(saturday).orElse(Optional.ofNullable(sunday).orElse(workday));
+		}
+		if (nextWorkDay == DayOfWeek.SUNDAY) {
+			return Optional.ofNullable(sunday).orElse(workday);
+		}
+		return workday;
+	}
+
+
+	public static List<YhServiceDto> getHolidayServiceIfHoliday(LocalDateTime now, Map<String, List<YhServiceDto>> holidyDateMap) {
+		if (holidyDateMap == null) {
+			return null;
+		}
+		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
+		String nowDate = now.format(formatter);
+
+		List<YhServiceDto> holidayServices = holidyDateMap.get(nowDate);
+		if (CollUtil.isNotEmpty(holidayServices)) {
+			return holidayServices;
+		}
+		return null;
+	}
+}

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

@@ -87,7 +87,7 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
 	/**
 	 * 获取对应值班客服的二维码
 	 */
-	public String getDutyServiceCode(List<CorpFollowActiveCodeDto> activeCodeDtos) {
+	public String getDutyServiceCode(List<CorpFollowActiveCodeDto> activeCodeDtos) throws Exception {
 		if (activeCodeDtos.size() == 1) {
 			return activeCodeDtos.get(0).getQrCode();
 		}

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/sys/SysConfigService.java

@@ -17,5 +17,5 @@ public interface SysConfigService extends IService<SysConfig> {
 	 */
 	String getDefaultShopConfigByType(String type);
 
-	List<String> getDutyServices();
+	List<String> getDutyServices() throws Exception;
 }

+ 48 - 57
netflix-service/src/main/java/com/cyksj/service/sys/impl/SysConfigServiceImpl.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cyksj.common.constant.Constant;
+import com.cyksj.common.service.CropDutyServiceDateService;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.mapper.SysConfigMapper;
 import com.cyksj.model.dto.DefaultShopConfig;
@@ -60,85 +61,74 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig>
 
 
 	@Override
-	public List<String> getDutyServices() {
+	public List<String> getDutyServices() throws Exception {
 		SysConfig sysConfig = this.getOne(Wrappers.lambdaQuery(SysConfig.class)
 				.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
 				.last("limit 1"));
-		// 用当前日期时间创建一个 LocalDateTime 对象
-		LocalDateTime now = LocalDateTime.now();
 
-		// 获取当前时间
-		LocalTime currentTime = now.toLocalTime();
+		List<YhServiceDto> yhServiceDtos = null;
 
-		if (sysConfig != null) {
-			String sysValue = sysConfig.getSysValue();
-			if (StrUtil.isNotEmpty(sysValue)) {
-				try {
-					List<YhServiceDto> yhServiceDtos = Jsons.parseList(sysValue, YhServiceDto.class);
-					Map<String, List<YhServiceDto>> dutyServices = yhServiceDtos.stream().collect(Collectors.groupingBy(YhServiceDto::getSign));
-					DayOfWeek currentDayOfWeek = now.getDayOfWeek();
-					List<YhServiceDto> workdayService = dutyServices.get("workday");
-
-					if (CollUtil.isNotEmpty(workdayService)) {
-						List<YhServiceDto> saturdayService = dutyServices.get("Saturday");
-						List<YhServiceDto> sundayServices = dutyServices.get("Sunday");
-
-						List<YhServiceDto> carryServices = getDutyService(currentDayOfWeek, workdayService, saturdayService, sundayServices);
-						//获取值班客服
-						List<YhServiceDto> dutyServiceCodes = getDutyServiceCode(carryServices, workdayService, saturdayService, sundayServices, currentDayOfWeek, currentTime);
-						if (CollUtil.isNotEmpty(dutyServiceCodes)) {
-							Set<String> collectFollow = new HashSet<>();
-							for (YhServiceDto dutyServiceCode : dutyServiceCodes) {
-								dutyServiceCode.getSelect().stream().filter(e -> StrUtil.isNotBlank(e.getFollowId())).forEach(cs -> collectFollow.add(cs.getFollowId()));
-							}
-							return new ArrayList<>(collectFollow);
-						}
-					}
-				} catch (Exception e) {
-				}
-			}
+		if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
+			yhServiceDtos = Jsons.parseList(sysConfig.getSysValue(), YhServiceDto.class);
 		}
-		return null;
-	}
 
+		final List<YhServiceDto> dtoCs = yhServiceDtos;
 
+		List<YhServiceDto> workdayServices = null;
+		List<YhServiceDto> saturdayServices = null;
+		List<YhServiceDto> sundayServices = null;
+		Map<String, List<YhServiceDto>> holidayDateMap = null;
 
-	/**
-	 * 返回明天星期几 用户获取对应周期工作客服
-	 */
-	private static DayOfWeek getNextWorkDay(DayOfWeek currentDay) {
-		// 如果当前是周五,下一个工作日是周一;否则,是当前星期的下一天
-		if (currentDay == java.time.DayOfWeek.FRIDAY) {
-			return java.time.DayOfWeek.SATURDAY;
-		}
-		if (currentDay == DayOfWeek.SATURDAY) {
-			return DayOfWeek.SUNDAY;
+		if (CollUtil.isNotEmpty(dtoCs)) {
+			Map<String, List<YhServiceDto>> dutyServices = yhServiceDtos.stream().collect(Collectors.groupingBy(YhServiceDto::getSign));
+			workdayServices = dutyServices.get("workday");
+			saturdayServices = dutyServices.get("Saturday");
+			sundayServices = dutyServices.get("Sunday");
+
+			List<YhServiceDto> holidayServices = dutyServices.get("holiday");
+			if (CollUtil.isNotEmpty(holidayServices)) {
+				holidayDateMap = holidayServices.stream().collect(Collectors.groupingBy(YhServiceDto::getDate));
+			}
 		}
-		return DayOfWeek.MONDAY;
+		LocalDateTime now = LocalDateTime.now();
+		List<String> dutyServices = getDutyServices(workdayServices, saturdayServices, sundayServices, holidayDateMap, now);
+		return dutyServices;
 	}
 
-	private List<YhServiceDto> getDutyService(DayOfWeek nextWorkDay, List<YhServiceDto> workday, List<YhServiceDto> saturday, List<YhServiceDto> sunday) {
-		if (nextWorkDay == DayOfWeek.SATURDAY) {
-			return Optional.ofNullable(saturday).orElse(Optional.ofNullable(sunday).orElse(workday));
-		}
-		if (nextWorkDay == DayOfWeek.SUNDAY) {
-			return Optional.ofNullable(sunday).orElse(workday);
+
+
+	public List<String> getDutyServices(List<YhServiceDto> workday, List<YhServiceDto> saturday, List<YhServiceDto> sunday, Map<String, List<YhServiceDto>> holidayDateMap, LocalDateTime now) {
+		if (CollUtil.isNotEmpty(workday)) {
+			DayOfWeek currentDayOfWeek = now.getDayOfWeek();
+
+			List<YhServiceDto> carryServices = CropDutyServiceDateService.getDutyService(currentDayOfWeek, workday, saturday, sunday, holidayDateMap, now);
+			//获取值班客服
+			List<YhServiceDto> dutyServiceCodes = getTimeDutyServices(carryServices, workday, saturday, sunday, holidayDateMap, currentDayOfWeek, now);
+			if (CollUtil.isNotEmpty(dutyServiceCodes)) {
+				Set<String> collectFollow = new HashSet<>();
+				for (YhServiceDto dutyServiceCode : dutyServiceCodes) {
+					dutyServiceCode.getSelect().stream().filter(e -> StrUtil.isNotBlank(e.getFollowId())).forEach(cs -> collectFollow.add(cs.getFollowId()));
+				}
+				return new ArrayList<>(collectFollow);
+			}
 		}
-		return workday;
+		return null;
 	}
 
-
 	/**
-	 * 获取工作日
+	 * 获取当前时间段值班的客服
 	 */
-	public List<YhServiceDto> getDutyServiceCode(List<YhServiceDto> carryServices, List<YhServiceDto> workday, List<YhServiceDto> saturday, List<YhServiceDto> sunday, DayOfWeek currentDayOfWeek, LocalTime currentTime) {
+	public List<YhServiceDto> getTimeDutyServices(List<YhServiceDto> carryServices, List<YhServiceDto> workday, List<YhServiceDto> saturday, List<YhServiceDto> sunday, Map<String, List<YhServiceDto>> holidayDateMap, DayOfWeek currentDayOfWeek, LocalDateTime now) {
+		// 获取当前时间
+		LocalTime currentTime = now.toLocalTime();
+
 		List<YhServiceDto> collect = carryServices.stream().filter(time -> time.isBetween(currentTime)).collect(Collectors.toList());
 		if (CollUtil.isEmpty(collect)) {
 			collect = carryServices.stream().filter(time -> time.isAfter(currentTime)).collect(Collectors.toList());
 			if (CollUtil.isEmpty(collect)) {
 				// 如果没有下一个时间段,获取下一个工作时间段的开始时间
-				DayOfWeek nextWorkDay = getNextWorkDay(currentDayOfWeek);
-				collect = getDutyService(nextWorkDay, workday, saturday, sunday);
+				DayOfWeek nextWorkDay = CropDutyServiceDateService.getNextWorkDay(currentDayOfWeek);
+				collect = CropDutyServiceDateService.getDutyService(nextWorkDay, workday, saturday, sunday, holidayDateMap, now.plusDays(1));
 			}
 			collect.sort(Comparator.comparing(e -> DateUtil.parse(e.getSortTime() == null ? e.getStartTime() : e.getSortTime(), "HH:mm")));
 			//获取下一天的早时
@@ -146,4 +136,5 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig>
 		}
 		return collect;
 	}
+
 }