|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
|