zoujiajian преди 1 година
родител
ревизия
9057bef108
променени са 1 файла, в които са добавени 27 реда и са изтрити 9 реда
  1. 27 9
      netflix-service/src/main/java/com/cyksj/service/corp/kf/impl/CorpKfServiceImpl.java

+ 27 - 9
netflix-service/src/main/java/com/cyksj/service/corp/kf/impl/CorpKfServiceImpl.java

@@ -238,15 +238,10 @@ public class CorpKfServiceImpl implements CorpKfService {
 	@Override
 	public List<CorpKfDutyServicersStatusView> getDutyFollowByOpenKfId(long cmsUserId, String openKfId) throws Exception {
 		Boolean isRoot = cmsUserService.isRootRole(cmsUserId);
-		List<CorpKfAccountFollow> corpKfAccountFollows = corpKfAccountFollowMapper.selectList(Wrappers.lambdaQuery(CorpKfAccountFollow.class)
-				.eq(CorpKfAccountFollow::getOpenKfId, openKfId));
-		if (corpKfAccountFollows.isEmpty()) {
-			return new ArrayList<>();
-		}
 		//目前时间段需要值班的客服
-		Set<String> thisHourDutyFollows = new HashSet<>();
-		for (CorpKfAccountFollow corpKfAccountFollow : corpKfAccountFollows) {
-			thisHourDutyFollows.addAll(Jsons.parseList(corpKfAccountFollow.getUserIdList(), String.class));
+		Set<String> dutyFollowIds = getThisHourDutyFollowIds(openKfId);
+		if (dutyFollowIds.isEmpty()) {
+			return new ArrayList<>();
 		}
 		CorpKfServicerResp corpKfServicerResp = wxCorpOps.getKfServicerList(yhlxWxCorpConfig.getCorpId(), openKfId);
 		List<CorpKfServicerResp.CorpKfServicer> servicerList = corpKfServicerResp.getServicerList();
@@ -260,7 +255,7 @@ public class CorpKfServiceImpl implements CorpKfService {
 		List<CorpKfDutyServicersStatusView> views = new ArrayList<>();
 		CorpKfDutyServicersStatusView corpKfDutyServicersStatusView = null;
 		//查看目前时间段值班人员情况
-		for (String thisHourDutyFollow : thisHourDutyFollows) {
+		for (String thisHourDutyFollow : dutyFollowIds) {
 			LambdaQueryWrapper<CorpFollow> wrapper = Wrappers.lambdaQuery(CorpFollow.class)
 					.eq(CorpFollow::getUserid, thisHourDutyFollow);
 			//非root 只查询当前用户当前时间段值班情况
@@ -361,4 +356,27 @@ public class CorpKfServiceImpl implements CorpKfService {
 			return false;
 		}).collect(Collectors.toList());
 	}
+
+	/**
+	 * 获取当前值班客服
+	 */
+	public Set<String> getThisHourDutyFollowIds(String openKfId) throws Exception {
+		DateTime now = DateTime.now();
+		String thisHourDate = DateUtil.format(now, "HH:mm");
+		//星期天为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)
+				.eq(CorpKfAccountFollow::getDutyWeek, dayOfWeek));
+
+		//目前时间段需要值班的客服
+		Set<String> thisHourDutyFollows = new HashSet<>();
+		for (CorpKfAccountFollow corpKfAccountFollow : corpKfAccountFollows) {
+			thisHourDutyFollows.addAll(Jsons.parseList(corpKfAccountFollow.getUserIdList(), String.class));
+		}
+		return thisHourDutyFollows;
+	}
 }