|
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
import com.cyksj.common.constant.Constant;
|
|
|
|
|
+import com.cyksj.common.service.CropDutyServiceDateService;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.mapper.SysConfigMapper;
|
|
import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.model.dto.DefaultShopConfig;
|
|
import com.cyksj.model.dto.DefaultShopConfig;
|
|
@@ -60,85 +61,74 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper,SysConfig>
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public List<String> getDutyServices() {
|
|
|
|
|
|
|
+ public List<String> getDutyServices() throws Exception {
|
|
|
SysConfig sysConfig = this.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
SysConfig sysConfig = this.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
|
|
.eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
|
|
|
.last("limit 1"));
|
|
.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());
|
|
List<YhServiceDto> collect = carryServices.stream().filter(time -> time.isBetween(currentTime)).collect(Collectors.toList());
|
|
|
if (CollUtil.isEmpty(collect)) {
|
|
if (CollUtil.isEmpty(collect)) {
|
|
|
collect = carryServices.stream().filter(time -> time.isAfter(currentTime)).collect(Collectors.toList());
|
|
collect = carryServices.stream().filter(time -> time.isAfter(currentTime)).collect(Collectors.toList());
|
|
|
if (CollUtil.isEmpty(collect)) {
|
|
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")));
|
|
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;
|
|
return collect;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|