|
|
@@ -5,30 +5,22 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
-import com.cyksj.common.constant.Constant;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
-import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeClickRecordMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
|
|
|
-import com.cyksj.mapper.corp.CorpFollowDutyRelateMapper;
|
|
|
import com.cyksj.model.dto.CorpFollowActiveCodeDto;
|
|
|
-import com.cyksj.model.dto.YhServiceDto;
|
|
|
import com.cyksj.model.entity.CorpFollowActiveCode;
|
|
|
import com.cyksj.model.entity.CorpFollowActiveCodeClickRecord;
|
|
|
-import com.cyksj.model.entity.SysConfig;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
|
|
|
+import com.cyksj.service.sys.SysConfigService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.time.DayOfWeek;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.LocalTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -44,13 +36,11 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
|
|
|
private final CorpFollowActiveCodeMapper corpFollowActiveCodeMapper;
|
|
|
|
|
|
- private final CorpFollowDutyRelateMapper corpFollowDutyRelateMapper;
|
|
|
-
|
|
|
private final CorpFollowActiveCodeClickRecordMapper corpFollowActiveCodeClickRecordMapper;
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
- private final SysConfigMapper sysConfigMapper;
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
|
|
|
@Override
|
|
|
public String getCorpActiveQrCode(Long acId) throws Exception {
|
|
|
@@ -88,169 +78,41 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
//星期五-->星期六 星期六--->星期天 星期天-->星期一
|
|
|
//值班
|
|
|
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)
|
|
|
-// .le(CorpFollowDutyRelate::getSt, hour)
|
|
|
-// .ge(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;
|
|
|
-// }
|
|
|
-// Integer index;
|
|
|
-// //未在时间期间
|
|
|
-// //若在当天之前
|
|
|
-// //若在当天之后 寻找下日值班客服
|
|
|
-// List<CorpFollowDutyRelate> todayCorpFollowDuty = corpFollowDutyRelateMapper.selectTodayDutyRelate(followIds, type);
|
|
|
-// if (CollUtil.isEmpty(todayCorpFollowDuty)) {
|
|
|
-// List<CorpFollowDutyRelate> dutyRelateList = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
-// .ne(CorpFollowDutyRelate::getType, type));
|
|
|
-// Integer fType = type;
|
|
|
-// //优化获取下一个工作日 客服
|
|
|
-// List<CorpFollowDutyRelate> collect = dutyRelateList.stream().filter(data -> data.getType() > fType).collect(Collectors.toList());
|
|
|
-// if (CollUtil.isEmpty(collect)) {
|
|
|
-// collect = dutyRelateList;
|
|
|
-// }
|
|
|
-// collect.sort(Comparator.comparing(CorpFollowDutyRelate::getSt));
|
|
|
-// qrCode = getActiveQrCode(collect, activeCodeDtos);
|
|
|
-// redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
|
|
|
-// return qrCode;
|
|
|
-// }
|
|
|
-// 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::getIndexTag, index)
|
|
|
-// .in(CorpFollowDutyRelate::getFollowId, followIds));
|
|
|
-// if (CollUtil.isEmpty(corpFollowDutyRelates)) {
|
|
|
-// index = 4;
|
|
|
-// corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
-// .eq(CorpFollowDutyRelate::getIndexTag, 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::getIndexTag, index)
|
|
|
-// .in(CorpFollowDutyRelate::getFollowId, followIds));
|
|
|
-// if (CollUtil.isEmpty(corpFollowDutyRelates)) {
|
|
|
-// index = 6;
|
|
|
-// corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
-// .eq(CorpFollowDutyRelate::getIndexTag, index)
|
|
|
-// .in(CorpFollowDutyRelate::getFollowId, followIds));
|
|
|
-// }
|
|
|
-// qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
|
|
|
-// }else {
|
|
|
-// index = 1;
|
|
|
-// corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
-// .eq(CorpFollowDutyRelate::getIndexTag, index)
|
|
|
-// .in(CorpFollowDutyRelate::getFollowId, followIds));
|
|
|
-// if (CollUtil.isEmpty(corpFollowDutyRelates)) {
|
|
|
-// index = 2;
|
|
|
-// corpFollowDutyRelates = corpFollowDutyRelateMapper.selectList(Wrappers.lambdaQuery(CorpFollowDutyRelate.class)
|
|
|
-// .eq(CorpFollowDutyRelate::getIndexTag, 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;
|
|
|
qrCode = getDutyServiceCode(activeCodeDtos);
|
|
|
return qrCode;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// public String getActiveQrCode(List<CorpFollowDutyRelate> corpFollowDutyRelates, List<CorpFollowActiveCodeDto> activeCodeDtos) {
|
|
|
-// Integer randNum = 0;
|
|
|
-// if (corpFollowDutyRelates.size() > 1) {
|
|
|
-// randNum = RandomUtil.randomInt(corpFollowDutyRelates.size());
|
|
|
-// }
|
|
|
-// for (CorpFollowActiveCodeDto activeCodeDto : activeCodeDtos) {
|
|
|
-// if (activeCodeDto.getFollowIds().contains(corpFollowDutyRelates.get(randNum).getFollowId())) {
|
|
|
-// return activeCodeDto.getQrCode();
|
|
|
-// }
|
|
|
-// }
|
|
|
-// //兜底
|
|
|
-// randNum = RandomUtil.randomInt(activeCodeDtos.size());
|
|
|
-// CorpFollowActiveCodeDto activeCodeDto = activeCodeDtos.get(randNum);
|
|
|
-// return activeCodeDto.getQrCode();
|
|
|
-// }
|
|
|
-
|
|
|
/**
|
|
|
* 获取对应值班客服的二维码
|
|
|
*/
|
|
|
public String getDutyServiceCode(List<CorpFollowActiveCodeDto> activeCodeDtos) {
|
|
|
- SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
- .eq(SysConfig::getSysKey, Constant.serviceKeys.get(0))
|
|
|
- .last("limit 1"));
|
|
|
- // 用当前日期时间创建一个 LocalDateTime 对象
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
-
|
|
|
- // 获取当前时间
|
|
|
- LocalTime currentTime = now.toLocalTime();
|
|
|
- CorpFollowActiveCodeDto activeCodeDto = null;
|
|
|
-
|
|
|
- if (sysConfig != null) {
|
|
|
- String sysValue = sysConfig.getSysValue();
|
|
|
- if (StrUtil.isNotEmpty(sysValue)) {
|
|
|
+ List<String> dutyServices = sysConfigService.getDutyServices();
|
|
|
+ String chooseFollowId = null;
|
|
|
+ //值班
|
|
|
+ if (CollUtil.isNotEmpty(dutyServices)) {
|
|
|
+ List<String> collectFollow = new ArrayList<>();
|
|
|
+ activeCodeDtos.stream().forEach(e -> {
|
|
|
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);
|
|
|
- //获取值班客服
|
|
|
- YhServiceDto dutyServiceCode = getDutyServiceCode(carryServices, workdayService, saturdayService, sundayServices, currentDayOfWeek, currentTime);
|
|
|
- if (CollUtil.isNotEmpty(dutyServiceCode.getSelect())) {
|
|
|
- List<String> collect_follow = activeCodeDtos.stream().map(CorpFollowActiveCodeDto::getServiceNames).collect(Collectors.toList());
|
|
|
- YhServiceDto.CustomerServiceDto customerServiceDto = dutyServiceCode.getSelect().parallelStream().filter(select -> collect_follow.contains(select.getName())).findAny().get();
|
|
|
- if (customerServiceDto != null) {
|
|
|
- activeCodeDto = activeCodeDtos.stream().filter(active -> active.getServiceNames().equals(customerServiceDto.getName())).findFirst().get();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
+ collectFollow.addAll(JSONUtil.parseArray(e.getFollowIds()).toList(String.class));
|
|
|
+ } catch (Exception ex) {
|
|
|
+ System.out.println(ex.getMessage());
|
|
|
}
|
|
|
+ });
|
|
|
+ List<String> collect = dutyServices.stream().filter(fid -> collectFollow.contains(fid)).collect(Collectors.toList());
|
|
|
+ if (CollUtil.isNotEmpty(collect)) {
|
|
|
+ chooseFollowId = collect.get(RandomUtil.randomInt(collect.size()));
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ CorpFollowActiveCodeDto activeCodeDto = null;
|
|
|
+ if (chooseFollowId != null) {
|
|
|
+ log.info("寻找合适值班客服:{}", chooseFollowId);
|
|
|
+ final String csFollowId = chooseFollowId;
|
|
|
+ activeCodeDto = activeCodeDtos.stream().filter(active -> active.getFollowIds().contains(csFollowId)).findFirst().get();
|
|
|
+ }
|
|
|
+
|
|
|
if (activeCodeDto == null) {
|
|
|
//兜底
|
|
|
Integer randNum = RandomUtil.randomInt(activeCodeDtos.size());
|
|
|
@@ -259,43 +121,4 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
}
|
|
|
return activeCodeDto.getQrCode();
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取工作日
|
|
|
- */
|
|
|
- public YhServiceDto getDutyServiceCode(List<YhServiceDto> carryServices, List<YhServiceDto> workday, List<YhServiceDto> saturday, List<YhServiceDto> sunday, DayOfWeek currentDayOfWeek, LocalTime currentTime) {
|
|
|
- return carryServices.parallelStream().filter(time -> time.isBetween(currentTime)).findAny().orElseGet(() -> {
|
|
|
- return carryServices.stream().filter(time -> time.isAfter(currentTime)).findAny().orElseGet(() -> {
|
|
|
- // 如果没有下一个时间段,获取下一个工作时间段的开始时间
|
|
|
- DayOfWeek nextWorkDay = getNextWorkDay(currentDayOfWeek);
|
|
|
- List<YhServiceDto> nextServices = getDutyService(nextWorkDay, workday, saturday, sunday);
|
|
|
- //获取下一天的早时
|
|
|
- return nextServices.get(0);
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 返回明天星期几 用户获取对应周期工作客服
|
|
|
- */
|
|
|
- private static DayOfWeek getNextWorkDay(DayOfWeek currentDay) {
|
|
|
- // 如果当前是周五,下一个工作日是周一;否则,是当前星期的下一天
|
|
|
- if (currentDay == java.time.DayOfWeek.FRIDAY) {
|
|
|
- return java.time.DayOfWeek.SATURDAY;
|
|
|
- }
|
|
|
- if (currentDay == DayOfWeek.SATURDAY) {
|
|
|
- return DayOfWeek.SUNDAY;
|
|
|
- }
|
|
|
- return DayOfWeek.MONDAY;
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- }
|
|
|
- return workday;
|
|
|
- }
|
|
|
}
|