|
|
|
@ -62,7 +62,7 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
redisService.refreshOnline(userId); |
|
|
|
IeHomeVO vo = new IeHomeVO(); |
|
|
|
vo.setOnlineCount(redisService.onlineCount()); |
|
|
|
vo.setWaitingCount(redisService.waitingCount(profile.getCurrentMode(), "quiet")); |
|
|
|
vo.setWaitingCount(redisService.waitingCount(profile.getCurrentMode(), "quiet", profile.getRegionId(), hasText(profile.getRegionId()))); |
|
|
|
vo.setDailyQuota(profile.getDailyQuota()); |
|
|
|
vo.setUsedQuota((int) redisService.todayUsedQuota(userId)); |
|
|
|
vo.setUnreadCount(totalUnreadCount(userId)); |
|
|
|
@ -139,6 +139,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
profile.setRecentPreference(profile.getCurrentMode()); |
|
|
|
profile.setTargetModePreference(normalizeTargetMode(dto.getTargetModePreference())); |
|
|
|
profile.setTargetGenderPreference(normalizeTargetGender(dto.getTargetGenderPreference())); |
|
|
|
profile.setRegionId(defaultText(dto.getRegionId(), profile.getRegionId())); |
|
|
|
profile.setRegionName(defaultText(dto.getRegionName(), profile.getRegionName())); |
|
|
|
profile.setProfileCompleted(1); |
|
|
|
profile.setLastActiveTime(new Date()); |
|
|
|
profile.setUpdateTime(new Date()); |
|
|
|
@ -147,6 +149,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
statusDTO.setMode(profile.getCurrentMode()); |
|
|
|
statusDTO.setMood("quiet"); |
|
|
|
statusDTO.setStatusText(defaultText(profile.getIntro(), profile.getCurrentMode())); |
|
|
|
statusDTO.setRegionId(profile.getRegionId()); |
|
|
|
statusDTO.setRegionName(profile.getRegionName()); |
|
|
|
statusDTO.setInterestTags(jsonToTags(profile.getInterestTags())); |
|
|
|
updateStatus(userId, statusDTO); |
|
|
|
return toProfileVO(profile); |
|
|
|
@ -163,7 +167,9 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
if (dto.getMood() == null) { |
|
|
|
dto.setMood("quiet"); |
|
|
|
} |
|
|
|
ensureProfile(userId); |
|
|
|
IeUserProfile profile = ensureProfile(userId); |
|
|
|
dto.setRegionId(defaultText(dto.getRegionId(), profile.getRegionId())); |
|
|
|
dto.setRegionName(defaultText(dto.getRegionName(), profile.getRegionName())); |
|
|
|
IeUserStatus status = userStatusMapper.selectOne(new LambdaQueryWrapper<IeUserStatus>() |
|
|
|
.eq(IeUserStatus::getUserId, userId) |
|
|
|
.last("limit 1")); |
|
|
|
@ -176,6 +182,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
status.setMode(dto.getMode()); |
|
|
|
status.setMood(dto.getMood()); |
|
|
|
status.setStatusText(dto.getStatusText()); |
|
|
|
status.setRegionId(dto.getRegionId()); |
|
|
|
status.setRegionName(dto.getRegionName()); |
|
|
|
status.setOnlineStatus(1); |
|
|
|
status.setLastActiveTime(now); |
|
|
|
status.setUpdateTime(now); |
|
|
|
@ -205,14 +213,23 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
} |
|
|
|
IeStatusDTO statusDTO = new IeStatusDTO(); |
|
|
|
BeanUtils.copyProperties(dto == null ? new IeMatchStartDTO() : dto, statusDTO); |
|
|
|
updateStatus(userId, statusDTO); |
|
|
|
|
|
|
|
String mode = normalizeMode(statusDTO.getMode(), profile.getCurrentMode()); |
|
|
|
String targetMode = normalizeTargetMode(dto == null ? null : dto.getTargetMode()); |
|
|
|
String requestedTargetGender = dto == null || dto.getTargetGender() == null ? profile.getTargetGenderPreference() : dto.getTargetGender(); |
|
|
|
String targetGender = normalizeTargetGender(requestedTargetGender); |
|
|
|
String matchScope = normalizeMatchScope(dto == null ? null : dto.getMatchScope()); |
|
|
|
String regionId = defaultText(dto == null ? null : dto.getRegionId(), profile.getRegionId()); |
|
|
|
String regionName = defaultText(dto == null ? null : dto.getRegionName(), profile.getRegionName()); |
|
|
|
boolean regionScope = "school".equals(matchScope); |
|
|
|
if (regionScope && !hasText(regionId)) { |
|
|
|
return fail(userId, dto, "请先选择校区后再匹配本校区用户"); |
|
|
|
} |
|
|
|
statusDTO.setRegionId(regionId); |
|
|
|
statusDTO.setRegionName(regionName); |
|
|
|
updateStatus(userId, statusDTO); |
|
|
|
String mood = statusDTO.getMood() == null ? "quiet" : statusDTO.getMood(); |
|
|
|
List<Long> candidates = candidateUsers(targetMode, mode, mood); |
|
|
|
List<Long> candidates = candidateUsers(targetMode, mode, mood, regionId, regionScope); |
|
|
|
List<MatchCandidate> matchedCandidates = new ArrayList<>(); |
|
|
|
for (Long candidateUserId : candidates) { |
|
|
|
if (candidateUserId == null || candidateUserId.equals(userId)) { |
|
|
|
@ -225,7 +242,7 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
continue; |
|
|
|
} |
|
|
|
IeUserProfile candidateProfile = findProfileByUserId(candidateUserId); |
|
|
|
if (!matchCandidate(candidateProfile, targetMode, targetGender)) { |
|
|
|
if (!matchCandidate(candidateProfile, targetMode, targetGender, regionId, regionScope)) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
matchedCandidates.add(new MatchCandidate(candidateUserId, matchScore(statusDTO, profile, candidateProfile))); |
|
|
|
@ -256,6 +273,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
match.setStatus(3); |
|
|
|
match.setAnonymousName(defaultText(targetProfile.getAnonymousName(), "半匿名漂流者")); |
|
|
|
match.setAvatarText(defaultText(targetProfile.getAvatarText(), "◌")); |
|
|
|
match.setTargetRegionId(targetProfile.getRegionId()); |
|
|
|
match.setTargetRegionName(targetProfile.getRegionName()); |
|
|
|
match.setStateText(targetProfile.getCurrentMode() == null || "i".equals(targetProfile.getCurrentMode()) ? "偏安静,适合慢慢靠近" : "偏轻松,愿意先开场"); |
|
|
|
match.setQuoteText(defaultText(targetProfile.getIntro(), "可以先安静待一会,不用急着找话题。")); |
|
|
|
match.setCreateTime(new Date()); |
|
|
|
@ -274,6 +293,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
vo.setRoomNo(room.getRoomNo()); |
|
|
|
vo.setAvatarUrl(targetProfile.getAvatarUrl()); |
|
|
|
vo.setGender(targetProfile.getGender()); |
|
|
|
vo.setRegionId(targetProfile.getRegionId()); |
|
|
|
vo.setRegionName(targetProfile.getRegionName()); |
|
|
|
vo.setIntro(targetProfile.getIntro()); |
|
|
|
vo.setInterestTags(jsonToTags(targetProfile.getInterestTags())); |
|
|
|
vo.setPersonaImages(jsonToTags(targetProfile.getPersonaImages())); |
|
|
|
@ -349,6 +370,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
vo.setAnonymousName(defaultText(profile.getAnonymousName(), vo.getAnonymousName())); |
|
|
|
vo.setAvatarText(defaultText(profile.getAvatarText(), vo.getAvatarText())); |
|
|
|
vo.setAvatarUrl(profile.getAvatarUrl()); |
|
|
|
vo.setRegionId(defaultText(profile.getRegionId(), vo.getRegionId())); |
|
|
|
vo.setRegionName(defaultText(profile.getRegionName(), vo.getRegionName())); |
|
|
|
vo.setMode(defaultText(profile.getCurrentMode(), vo.getMode())); |
|
|
|
vo.setQuoteText(defaultText(profile.getIntro(), vo.getQuoteText())); |
|
|
|
} |
|
|
|
@ -419,6 +442,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
vo.setTargetUserId(match.getTargetUserId()); |
|
|
|
vo.setAnonymousName(match.getAnonymousName()); |
|
|
|
vo.setAvatarText(match.getAvatarText()); |
|
|
|
vo.setRegionId(match.getTargetRegionId()); |
|
|
|
vo.setRegionName(match.getTargetRegionName()); |
|
|
|
vo.setMode(match.getMode()); |
|
|
|
vo.setMood(match.getMood()); |
|
|
|
vo.setStateText(match.getStateText()); |
|
|
|
@ -469,22 +494,22 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
.last("limit 1")); |
|
|
|
} |
|
|
|
|
|
|
|
private List<Long> candidateUsers(String targetMode, String selfMode, String mood) { |
|
|
|
private List<Long> candidateUsers(String targetMode, String selfMode, String mood, String regionId, boolean regionScope) { |
|
|
|
LinkedHashSet<Long> set = new LinkedHashSet<>(); |
|
|
|
if (!"any".equals(targetMode)) { |
|
|
|
set.addAll(redisService.candidates(targetMode, mood, 50)); |
|
|
|
set.addAll(statusCandidates(targetMode, 50)); |
|
|
|
set.addAll(profileCandidates(targetMode, 50)); |
|
|
|
set.addAll(redisService.candidates(targetMode, mood, regionId, regionScope, 50)); |
|
|
|
set.addAll(statusCandidates(targetMode, regionId, regionScope, 50)); |
|
|
|
set.addAll(profileCandidates(targetMode, regionId, regionScope, 50)); |
|
|
|
return new ArrayList<>(set); |
|
|
|
} |
|
|
|
set.addAll(redisService.candidates(selfMode, mood, 30)); |
|
|
|
set.addAll(redisService.candidates("i".equals(selfMode) ? "e" : "i", mood, 30)); |
|
|
|
set.addAll(redisService.candidates("i", mood, 20)); |
|
|
|
set.addAll(redisService.candidates("e", mood, 20)); |
|
|
|
set.addAll(statusCandidates(selfMode, 30)); |
|
|
|
set.addAll(statusCandidates("i".equals(selfMode) ? "e" : "i", 30)); |
|
|
|
set.addAll(profileCandidates(selfMode, 30)); |
|
|
|
set.addAll(profileCandidates("i".equals(selfMode) ? "e" : "i", 30)); |
|
|
|
set.addAll(redisService.candidates(selfMode, mood, regionId, regionScope, 30)); |
|
|
|
set.addAll(redisService.candidates("i".equals(selfMode) ? "e" : "i", mood, regionId, regionScope, 30)); |
|
|
|
set.addAll(redisService.candidates("i", mood, regionId, regionScope, 20)); |
|
|
|
set.addAll(redisService.candidates("e", mood, regionId, regionScope, 20)); |
|
|
|
set.addAll(statusCandidates(selfMode, regionId, regionScope, 30)); |
|
|
|
set.addAll(statusCandidates("i".equals(selfMode) ? "e" : "i", regionId, regionScope, 30)); |
|
|
|
set.addAll(profileCandidates(selfMode, regionId, regionScope, 30)); |
|
|
|
set.addAll(profileCandidates("i".equals(selfMode) ? "e" : "i", regionId, regionScope, 30)); |
|
|
|
return new ArrayList<>(set); |
|
|
|
} |
|
|
|
|
|
|
|
@ -499,12 +524,14 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
return count != null && count > 0; |
|
|
|
} |
|
|
|
|
|
|
|
private List<Long> statusCandidates(String mode, int limit) { |
|
|
|
List<IeUserStatus> statuses = userStatusMapper.selectList(new LambdaQueryWrapper<IeUserStatus>() |
|
|
|
private List<Long> statusCandidates(String mode, String regionId, boolean regionScope, int limit) { |
|
|
|
LambdaQueryWrapper<IeUserStatus> query = new LambdaQueryWrapper<IeUserStatus>() |
|
|
|
.eq(IeUserStatus::getOnlineStatus, 1) |
|
|
|
.eq(IeUserStatus::getMode, normalizeMode(mode, "i")) |
|
|
|
.eq(regionScope, IeUserStatus::getRegionId, regionId) |
|
|
|
.orderByDesc(IeUserStatus::getLastActiveTime) |
|
|
|
.last("limit " + Math.max(1, Math.min(limit, 100)))); |
|
|
|
.last("limit " + Math.max(1, Math.min(limit, 100))); |
|
|
|
List<IeUserStatus> statuses = userStatusMapper.selectList(query); |
|
|
|
List<Long> users = new ArrayList<>(); |
|
|
|
for (IeUserStatus status : statuses) { |
|
|
|
if (status.getUserId() != null) { |
|
|
|
@ -514,13 +541,15 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
return users; |
|
|
|
} |
|
|
|
|
|
|
|
private List<Long> profileCandidates(String mode, int limit) { |
|
|
|
List<IeUserProfile> profiles = userProfileMapper.selectList(new LambdaQueryWrapper<IeUserProfile>() |
|
|
|
private List<Long> profileCandidates(String mode, String regionId, boolean regionScope, int limit) { |
|
|
|
LambdaQueryWrapper<IeUserProfile> query = new LambdaQueryWrapper<IeUserProfile>() |
|
|
|
.eq(IeUserProfile::getProfileCompleted, 1) |
|
|
|
.eq(IeUserProfile::getCurrentMode, normalizeMode(mode, "i")) |
|
|
|
.eq(IeUserProfile::getIsDeleted, 0) |
|
|
|
.eq(regionScope, IeUserProfile::getRegionId, regionId) |
|
|
|
.orderByDesc(IeUserProfile::getLastActiveTime) |
|
|
|
.last("limit " + Math.max(1, Math.min(limit, 100)))); |
|
|
|
.last("limit " + Math.max(1, Math.min(limit, 100))); |
|
|
|
List<IeUserProfile> profiles = userProfileMapper.selectList(query); |
|
|
|
List<Long> users = new ArrayList<>(); |
|
|
|
for (IeUserProfile profile : profiles) { |
|
|
|
if (profile.getUserId() != null) { |
|
|
|
@ -566,6 +595,8 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
vo.setRecentPreference(profile.getRecentPreference()); |
|
|
|
vo.setTargetModePreference(profile.getTargetModePreference()); |
|
|
|
vo.setTargetGenderPreference(profile.getTargetGenderPreference()); |
|
|
|
vo.setRegionId(profile.getRegionId()); |
|
|
|
vo.setRegionName(profile.getRegionName()); |
|
|
|
vo.setDefaultRoomMinutes(profile.getDefaultRoomMinutes()); |
|
|
|
vo.setDailyQuota(profile.getDailyQuota()); |
|
|
|
vo.setUsedQuota(profile.getUsedQuota()); |
|
|
|
@ -612,10 +643,24 @@ public class IeMatchServiceImpl implements IeMatchService { |
|
|
|
return "any"; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean matchCandidate(IeUserProfile candidateProfile, String selfTargetMode, String selfTargetGender) { |
|
|
|
private String normalizeMatchScope(String value) { |
|
|
|
if ("world".equalsIgnoreCase(value)) { |
|
|
|
return "world"; |
|
|
|
} |
|
|
|
return "school"; |
|
|
|
} |
|
|
|
|
|
|
|
private boolean hasText(String value) { |
|
|
|
return value != null && !value.trim().isEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
private boolean matchCandidate(IeUserProfile candidateProfile, String selfTargetMode, String selfTargetGender, String regionId, boolean regionScope) { |
|
|
|
if (candidateProfile == null) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (regionScope && !Objects.equals(regionId, candidateProfile.getRegionId())) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
String candidateMode = normalizeMode(candidateProfile.getCurrentMode(), "i"); |
|
|
|
if (!"any".equals(selfTargetMode) && !selfTargetMode.equals(candidateMode)) { |
|
|
|
return false; |
|
|
|
|