|
@@ -3,26 +3,32 @@ package com.cyksj.service.corp.impl;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
-import cn.hutool.core.date.Week;
|
|
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
|
|
+import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeClickRecordMapper;
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeClickRecordMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
|
|
import com.cyksj.mapper.corp.CorpFollowActiveCodeMapper;
|
|
|
import com.cyksj.mapper.corp.CorpFollowDutyRelateMapper;
|
|
import com.cyksj.mapper.corp.CorpFollowDutyRelateMapper;
|
|
|
import com.cyksj.model.dto.CorpFollowActiveCodeDto;
|
|
import com.cyksj.model.dto.CorpFollowActiveCodeDto;
|
|
|
|
|
+import com.cyksj.model.dto.YhServiceDto;
|
|
|
import com.cyksj.model.entity.CorpFollowActiveCode;
|
|
import com.cyksj.model.entity.CorpFollowActiveCode;
|
|
|
import com.cyksj.model.entity.CorpFollowActiveCodeClickRecord;
|
|
import com.cyksj.model.entity.CorpFollowActiveCodeClickRecord;
|
|
|
-import com.cyksj.model.entity.CorpFollowDutyRelate;
|
|
|
|
|
|
|
+import com.cyksj.model.entity.SysConfig;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
|
|
import com.cyksj.service.corp.CorpFollowActiveCodeFrontService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
-import java.util.Comparator;
|
|
|
|
|
|
|
+import java.time.DayOfWeek;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,6 +50,8 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
|
|
|
|
|
private final RedisService redisService;
|
|
private final RedisService redisService;
|
|
|
|
|
|
|
|
|
|
+ private final SysConfigMapper sysConfigMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public String getCorpActiveQrCode(Long acId) throws Exception {
|
|
public String getCorpActiveQrCode(Long acId) throws Exception {
|
|
|
CorpFollowActiveCode corpFollowActiveCode = corpFollowActiveCodeMapper.selectById(acId);
|
|
CorpFollowActiveCode corpFollowActiveCode = corpFollowActiveCodeMapper.selectById(acId);
|
|
@@ -53,25 +61,22 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
CorpFollowActiveCodeClickRecord clickRecord = new CorpFollowActiveCodeClickRecord();
|
|
CorpFollowActiveCodeClickRecord clickRecord = new CorpFollowActiveCodeClickRecord();
|
|
|
clickRecord.setAcId(acId);
|
|
clickRecord.setAcId(acId);
|
|
|
corpFollowActiveCodeClickRecordMapper.insert(clickRecord);
|
|
corpFollowActiveCodeClickRecordMapper.insert(clickRecord);
|
|
|
-
|
|
|
|
|
- int hour = DateUtil.thisHour(true);
|
|
|
|
|
- String activeCodeKey = RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getNameFormat(acId, hour);
|
|
|
|
|
- String qrCode = redisService.getStr(activeCodeKey);
|
|
|
|
|
- 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 qrCode;
|
|
|
|
|
+ String activeCodeKey = null;
|
|
|
|
|
+ List<CorpFollowActiveCodeDto> activeCodeDtos = null;
|
|
|
|
|
+ if (!corpFollowActiveCode.getIsDuty()) {
|
|
|
|
|
+ int hour = DateUtil.thisHour(true);
|
|
|
|
|
+ activeCodeKey = RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getNameFormat(acId, hour);
|
|
|
|
|
+ qrCode = redisService.getStr(activeCodeKey);
|
|
|
|
|
+ if (StrUtil.isNotBlank(qrCode)) {
|
|
|
|
|
+ return qrCode;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
String followStr = corpFollowActiveCode.getFollowStr();
|
|
String followStr = corpFollowActiveCode.getFollowStr();
|
|
|
List<String> followIds = Jsons.parseList(followStr, String.class);
|
|
List<String> followIds = Jsons.parseList(followStr, String.class);
|
|
|
String codeStr = corpFollowActiveCode.getCodeStr();
|
|
String codeStr = corpFollowActiveCode.getCodeStr();
|
|
|
- List<CorpFollowActiveCodeDto> activeCodeDtos = Jsons.parseList(codeStr, CorpFollowActiveCodeDto.class);
|
|
|
|
|
|
|
+ activeCodeDtos = Jsons.parseList(codeStr, CorpFollowActiveCodeDto.class);
|
|
|
if (CollUtil.isEmpty(activeCodeDtos)) {
|
|
if (CollUtil.isEmpty(activeCodeDtos)) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
@@ -83,122 +88,214 @@ public class CorpFollowActiveCodeFrontServiceImpl implements CorpFollowActiveCod
|
|
|
//星期五-->星期六 星期六--->星期天 星期天-->星期一
|
|
//星期五-->星期六 星期六--->星期天 星期天-->星期一
|
|
|
//值班
|
|
//值班
|
|
|
if (corpFollowActiveCode.getIsDuty()) {
|
|
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));
|
|
|
|
|
|
|
+// 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)) {
|
|
|
|
|
+ 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();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- qrCode = getActiveQrCode(corpFollowDutyRelates, activeCodeDtos);
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
}
|
|
}
|
|
|
- redisService.set(activeCodeKey, qrCode, RedisService.key.CORP_FOLLOW_ACTIVE_CODE_KEY.getTimeout());
|
|
|
|
|
- return qrCode;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+ if (activeCodeDto == null) {
|
|
|
//兜底
|
|
//兜底
|
|
|
- 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;
|
|
|
|
|
|
|
+ Integer randNum = RandomUtil.randomInt(activeCodeDtos.size());
|
|
|
|
|
+ log.info("当前时间段:{}未找到对应活码客服,兜底选择", DateUtil.hour(DateTime.now(), true));
|
|
|
|
|
+ activeCodeDto = activeCodeDtos.get(randNum);
|
|
|
}
|
|
}
|
|
|
- return null;
|
|
|
|
|
|
|
+ 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);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public String getActiveQrCode(List<CorpFollowDutyRelate> corpFollowDutyRelates, List<CorpFollowActiveCodeDto> activeCodeDtos) {
|
|
|
|
|
- Integer randNum = 0;
|
|
|
|
|
- if (corpFollowDutyRelates.size() > 1) {
|
|
|
|
|
- randNum = RandomUtil.randomInt(corpFollowDutyRelates.size());
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 返回明天星期几 用户获取对应周期工作客服
|
|
|
|
|
+ */
|
|
|
|
|
+ private static DayOfWeek getNextWorkDay(DayOfWeek currentDay) {
|
|
|
|
|
+ // 如果当前是周五,下一个工作日是周一;否则,是当前星期的下一天
|
|
|
|
|
+ if (currentDay == java.time.DayOfWeek.FRIDAY) {
|
|
|
|
|
+ return java.time.DayOfWeek.SATURDAY;
|
|
|
}
|
|
}
|
|
|
- for (CorpFollowActiveCodeDto activeCodeDto : activeCodeDtos) {
|
|
|
|
|
- if (activeCodeDto.getFollowIds().contains(corpFollowDutyRelates.get(randNum).getFollowId())) {
|
|
|
|
|
- return activeCodeDto.getQrCode();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (currentDay == DayOfWeek.SATURDAY) {
|
|
|
|
|
+ return DayOfWeek.SUNDAY;
|
|
|
}
|
|
}
|
|
|
- //兜底
|
|
|
|
|
- randNum = RandomUtil.randomInt(activeCodeDtos.size());
|
|
|
|
|
- CorpFollowActiveCodeDto activeCodeDto = activeCodeDtos.get(randNum);
|
|
|
|
|
- return activeCodeDto.getQrCode();
|
|
|
|
|
|
|
+ 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;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|