|
|
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.config.corp.YHLXWxCorpConfig;
|
|
|
import com.cyksj.mapper.corp.CorpFollowMapper;
|
|
|
@@ -12,12 +13,13 @@ import com.cyksj.mapper.corp.kf.CorpKfAccountFollowDutyStatusMapper;
|
|
|
import com.cyksj.mapper.corp.kf.CorpKfAccountFollowMapper;
|
|
|
import com.cyksj.mapper.corp.kf.CorpKfAccountMapper;
|
|
|
import com.cyksj.mapper.corp.kf.CorpKfAccountSessionConfigMapper;
|
|
|
-import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.kf.WxCpKfAccountAdd;
|
|
|
-import com.cyksj.model.kf.WxCpKfAccountAddResp;
|
|
|
-import com.cyksj.model.kf.WxCpKfAccountDel;
|
|
|
-import com.cyksj.model.kf.WxCpKfAccountUpd;
|
|
|
+import com.cyksj.model.entity.CorpFollow;
|
|
|
+import com.cyksj.model.entity.CorpKfAccount;
|
|
|
+import com.cyksj.model.entity.CorpKfAccountFollow;
|
|
|
+import com.cyksj.model.entity.CorpKfAccountSessionConfig;
|
|
|
+import com.cyksj.model.kf.*;
|
|
|
import com.cyksj.model.request.corp.kf.CorpKfDutyReq;
|
|
|
+import com.cyksj.model.views.CorpKfDutyServicersStatusView;
|
|
|
import com.cyksj.service.corp.WxCorpOps;
|
|
|
import com.cyksj.service.corp.kf.CorpKfService;
|
|
|
import com.cyksj.service.mange.cms.service.CmsUserService;
|
|
|
@@ -25,9 +27,11 @@ import com.google.common.collect.Lists;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 项目名: yhlxj2
|
|
|
@@ -95,13 +99,19 @@ public class CorpKfServiceImpl implements CorpKfService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void setKfAccountRuleOrAutoReply(CorpKfAccountSessionConfig CorpKfAccountSessionConfig) {
|
|
|
- Long id = CorpKfAccountSessionConfig.getId();
|
|
|
+ public void setKfAccountRuleOrAutoReply(CorpKfAccountSessionConfig corpKfAccountSessionConfig) {
|
|
|
+ CorpKfAccountSessionConfig db = corpKfAccountSessionConfigMapper.selectOne(Wrappers.lambdaQuery(CorpKfAccountSessionConfig.class)
|
|
|
+ .eq(CorpKfAccountSessionConfig::getOpenKfId, corpKfAccountSessionConfig.getOpenKfId())
|
|
|
+ .last("limit 1"));
|
|
|
+ if (db != null) {
|
|
|
+ corpKfAccountSessionConfig.setId(db.getId());
|
|
|
+ }
|
|
|
+ Long id = corpKfAccountSessionConfig.getId();
|
|
|
if (id == null) {
|
|
|
- corpKfAccountSessionConfigMapper.insert(CorpKfAccountSessionConfig);
|
|
|
+ corpKfAccountSessionConfigMapper.insert(corpKfAccountSessionConfig);
|
|
|
return;
|
|
|
}
|
|
|
- corpKfAccountSessionConfigMapper.updateById(CorpKfAccountSessionConfig);
|
|
|
+ corpKfAccountSessionConfigMapper.updateById(corpKfAccountSessionConfig);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -120,24 +130,74 @@ public class CorpKfServiceImpl implements CorpKfService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void servicerCommute(long cmsUserId, String openKfId) {
|
|
|
- String thisHourDate = DateUtil.format(DateTime.now(), "HH:mm:ss");
|
|
|
- corpKfAccountFollowMapper.selectOne(Wrappers.lambdaQuery(CorpKfAccountFollow.class)
|
|
|
+ public void servicerCommute(long cmsUserId, String openKfId, Boolean status) throws Exception {
|
|
|
+ CorpKfServicerResp corpKfServicerResp = wxCorpOps.getKfServicerList(yhlxWxCorpConfig.getCorpId(), openKfId);
|
|
|
+ List<String> followIds = corpFollowMapper.selectList(Wrappers.lambdaQuery(CorpFollow.class)
|
|
|
+ .eq(CorpFollow::getCmsUserId, cmsUserId)).stream().map(CorpFollow::getUserid).collect(Collectors.toList());
|
|
|
+ if (followIds.isEmpty()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("未关联企业微信成员");
|
|
|
+ }
|
|
|
+ //接待人员列表
|
|
|
+ List<CorpKfServicerResp.CorpKfServicer> servicerList = corpKfServicerResp.getServicerList();
|
|
|
+ List<String> delDutyFollowId = new ArrayList<>();
|
|
|
+ //下班
|
|
|
+ if (!status) {
|
|
|
+ for (CorpKfServicerResp.CorpKfServicer servicer : servicerList) {
|
|
|
+ if (servicer.getUserid() != null) {
|
|
|
+ if (followIds.contains(servicer.getUserid())) {
|
|
|
+ delDutyFollowId.add(servicer.getUserid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!delDutyFollowId.isEmpty()) {
|
|
|
+ wxCorpOps.delCorpKfServicer(openKfId, delDutyFollowId);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //上班
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ String thisHourDate = DateUtil.format(now, "HH:mm:ss");
|
|
|
+ //星期天为1
|
|
|
+ int dayOfWeek = DateUtil.dayOfWeek(now);
|
|
|
+ //是否值班期
|
|
|
+ List<CorpKfAccountFollow> corpKfAccountFollows = corpKfAccountFollowMapper.selectList(Wrappers.lambdaQuery(CorpKfAccountFollow.class)
|
|
|
.eq(CorpKfAccountFollow::getOpenKfId, openKfId)
|
|
|
.le(CorpKfAccountFollow::getStartTime, thisHourDate)
|
|
|
.ge(CorpKfAccountFollow::getEndTime, thisHourDate)
|
|
|
- .apply(""));
|
|
|
- CorpKfAccountFollowDutyStatus corpKfAccountFollowDutyStatus = corpKfAccountFollowDutyStatusMapper.selectOne(Wrappers.lambdaQuery(CorpKfAccountFollowDutyStatus.class)
|
|
|
- .eq(CorpKfAccountFollowDutyStatus::getCmsUserId, cmsUserId)
|
|
|
- .eq(CorpKfAccountFollowDutyStatus::getOpenKfId, openKfId)
|
|
|
- .last("limit 1"));
|
|
|
- if (corpKfAccountFollowDutyStatus == null) {
|
|
|
- corpKfAccountFollowDutyStatus = new CorpKfAccountFollowDutyStatus();
|
|
|
+ .apply(" and JSON_CONTAINS(duty_week,'\"%s\"')", dayOfWeek));
|
|
|
+ //无需值班
|
|
|
+ if (corpKfAccountFollows.isEmpty()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("非值班时间");
|
|
|
}
|
|
|
+ //目前时间段需要值班的客服
|
|
|
+ Set<String> thisHourDutyFollows = new HashSet<>();
|
|
|
+ for (CorpKfAccountFollow corpKfAccountFollow : corpKfAccountFollows) {
|
|
|
+ thisHourDutyFollows.addAll(Jsons.parseList(corpKfAccountFollow.getUserIdList(), String.class));
|
|
|
+ }
|
|
|
+ String dutyFollowId = null;
|
|
|
+ for (String followId : followIds) {
|
|
|
+ if (thisHourDutyFollows.contains(followId)) {
|
|
|
+ dutyFollowId = followId;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (dutyFollowId == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("无关联企业成员");
|
|
|
+ }
|
|
|
+ Set<String> dutyFollowIds = new HashSet<>();
|
|
|
+ for (CorpKfServicerResp.CorpKfServicer corpKfServicer : servicerList) {
|
|
|
+ String userid = corpKfServicer.getUserid();
|
|
|
+ if (userid != null) {
|
|
|
+ dutyFollowIds.add(userid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dutyFollowIds.add(dutyFollowId);
|
|
|
+ wxCorpOps.addCorpKfServicer(openKfId, dutyFollowIds);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<CorpKfAccountFollowDutyStatus> getDutyFollowByOpenKfId(long cmsUserId, String openKfId) throws Exception {
|
|
|
+ public List<CorpKfDutyServicersStatusView> getDutyFollowByOpenKfId(long cmsUserId, String openKfId) throws Exception {
|
|
|
+ Boolean isRoot = cmsUserService.isRootRole(cmsUserId);
|
|
|
DateTime now = DateTime.now();
|
|
|
String thisHourDate = DateUtil.format(now, "HH:mm:ss");
|
|
|
//星期天为1
|
|
|
@@ -153,23 +213,46 @@ public class CorpKfServiceImpl implements CorpKfService {
|
|
|
return Lists.newArrayList();
|
|
|
}
|
|
|
//目前时间段需要值班的客服
|
|
|
- Set<String> follows = new HashSet<>();
|
|
|
+ Set<String> thisHourDutyFollows = new HashSet<>();
|
|
|
for (CorpKfAccountFollow corpKfAccountFollow : corpKfAccountFollows) {
|
|
|
- follows.addAll(Jsons.parseList(corpKfAccountFollow.getUserIdList(), String.class));
|
|
|
+ thisHourDutyFollows.addAll(Jsons.parseList(corpKfAccountFollow.getUserIdList(), String.class));
|
|
|
}
|
|
|
- List<CorpFollow> cmsUserFollows = corpFollowMapper.selectList(Wrappers.lambdaQuery(CorpFollow.class)
|
|
|
- .in(CorpFollow::getUserid, follows)
|
|
|
- .eq(CorpFollow::getCmsUserId, cmsUserId));
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- LambdaQueryWrapper<CorpKfAccountFollowDutyStatus> queryWrapper = Wrappers.lambdaQuery(CorpKfAccountFollowDutyStatus.class)
|
|
|
- .eq(CorpKfAccountFollowDutyStatus::getOpenKfId, openKfId);
|
|
|
- if (!cmsUserService.isRootRole(cmsUserId)) {
|
|
|
- queryWrapper.eq(CorpKfAccountFollowDutyStatus::getCmsUserId, cmsUserId);
|
|
|
+ CorpKfServicerResp corpKfServicerResp = wxCorpOps.getKfServicerList(yhlxWxCorpConfig.getCorpId(), openKfId);
|
|
|
+ List<CorpKfServicerResp.CorpKfServicer> servicerList = corpKfServicerResp.getServicerList();
|
|
|
+ //目前值班客服id
|
|
|
+ List<String> corpKfDutyServiceIds = new ArrayList<>();
|
|
|
+ for (CorpKfServicerResp.CorpKfServicer servicer : servicerList) {
|
|
|
+ if (servicer.getUserid() != null && servicer.getStatus() == 0) {
|
|
|
+ corpKfDutyServiceIds.add(servicer.getUserid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<CorpKfDutyServicersStatusView> views = new ArrayList<>();
|
|
|
+ CorpKfDutyServicersStatusView corpKfDutyServicersStatusView = null;
|
|
|
+ //查看目前时间段值班人员情况
|
|
|
+ for (String thisHourDutyFollow : thisHourDutyFollows) {
|
|
|
+ LambdaQueryWrapper<CorpFollow> wrapper = Wrappers.lambdaQuery(CorpFollow.class)
|
|
|
+ .eq(CorpFollow::getUserid, thisHourDutyFollow);
|
|
|
+ //非root 只查询当前用户当前时间段值班情况
|
|
|
+ if (!isRoot) {
|
|
|
+ wrapper.eq(CorpFollow::getCmsUserId, cmsUserId);
|
|
|
+ }
|
|
|
+ CorpFollow corpFollow = corpFollowMapper.selectOne(wrapper
|
|
|
+ .last("limit 1"));
|
|
|
+ if (corpFollow == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ corpKfDutyServicersStatusView = new CorpKfDutyServicersStatusView();
|
|
|
+ corpKfDutyServicersStatusView.setNickname(corpFollow.getName());
|
|
|
+ corpKfDutyServicersStatusView.setCmsUserId(corpFollow.getCmsUserId());
|
|
|
+ if (!corpKfDutyServiceIds.contains(thisHourDutyFollow)) {
|
|
|
+ //未值班
|
|
|
+ corpKfDutyServicersStatusView.setStatus(0);
|
|
|
+ } else {
|
|
|
+ corpKfDutyServicersStatusView.setStatus(1);
|
|
|
+ }
|
|
|
+ views.add(corpKfDutyServicersStatusView);
|
|
|
}
|
|
|
- List<CorpKfAccountFollowDutyStatus> dutyStatuses = corpKfAccountFollowDutyStatusMapper.selectList(queryWrapper);
|
|
|
- return dutyStatuses;
|
|
|
+ return views;
|
|
|
}
|
|
|
|
|
|
@Override
|