|
|
@@ -1,5 +1,6 @@
|
|
|
package com.sqx.modules.app.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONException;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
@@ -71,6 +72,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.http.client.utils.DateUtils;
|
|
|
+import org.apache.ibatis.jdbc.Null;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
@@ -1498,92 +1501,187 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
|
|
* @param userId 用户ID(企业用户,对应user_type=2)
|
|
|
* @return 包含各指标今日数据及较昨日变化的Map
|
|
|
*/
|
|
|
- public HashMap<String, Object> userYesterdayData(Long userId,Integer dateType,Integer postPushId) {
|
|
|
- HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
- LocalDateTime todayStart;
|
|
|
- LocalDateTime todayEnd;
|
|
|
- LocalDateTime yesterdayStart;
|
|
|
- LocalDateTime yesterdayEnd;
|
|
|
- if (dateType==1) {
|
|
|
- // 1. 定义时间范围:今日00:00:00至23:59:59
|
|
|
- todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
|
|
|
- todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
|
|
|
-
|
|
|
- // 2. 定义昨日时间范围:昨日00:00:00至23:59:59(用于计算较昨日变化)
|
|
|
- yesterdayStart = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN);
|
|
|
- yesterdayEnd = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX);
|
|
|
- }else {
|
|
|
- LocalDate today = LocalDate.now();
|
|
|
- // 本周一 00:00:00
|
|
|
- LocalDate thisWeekMonday = today.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
|
|
|
- // 本周日 23:59:59
|
|
|
- LocalDate thisWeekSunday = today.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
|
|
|
- todayStart = LocalDateTime.of(thisWeekMonday, LocalTime.MIN);
|
|
|
- todayEnd = LocalDateTime.of(thisWeekSunday, LocalTime.MAX);
|
|
|
-
|
|
|
- // 上周一 00:00:00
|
|
|
- LocalDate lastWeekMonday = thisWeekMonday.minusWeeks(1);
|
|
|
- // 上周日 23:59:59
|
|
|
- LocalDate lastWeekSunday = thisWeekSunday.minusWeeks(1);
|
|
|
- yesterdayStart = LocalDateTime.of(lastWeekMonday, LocalTime.MIN);
|
|
|
- yesterdayEnd = LocalDateTime.of(lastWeekSunday, LocalTime.MAX);
|
|
|
+ public HashMap<String, Object> userYesterdayData(Long userId,LocalDateTime todayStart, LocalDateTime todayEnd, Integer postPushId) {
|
|
|
+
|
|
|
+ HashMap<String, Object> resultMap = new HashMap<>();
|
|
|
+ boolean isCalculateDiff = false; // 是否计算「今日-昨日」差值(默认不计算)
|
|
|
+ LocalDateTime yesterdayStart = null;
|
|
|
+ LocalDateTime yesterdayEnd = null;
|
|
|
+
|
|
|
+ // -------------------------- 1. 时间参数处理(核心改造)--------------------------
|
|
|
+ if (todayStart == null && todayEnd == null) {
|
|
|
+ // 场景1:未传时间 → 用今日+昨日时间范围,计算差值
|
|
|
+ isCalculateDiff = true;
|
|
|
+ // 今日:00:00:00 ~ 23:59:59
|
|
|
+ todayStart = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
|
|
|
+ todayEnd = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
|
|
|
+ // 昨日:00:00:00 ~ 23:59:59
|
|
|
+ yesterdayStart = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN);
|
|
|
+ yesterdayEnd = LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MAX);
|
|
|
+ } else {
|
|
|
+ // 场景2:传了时间 → 校验时间合理性,不计算差值
|
|
|
+ Assert.notNull(todayStart, "传入时间时,todayStart不能为空");
|
|
|
+ Assert.notNull(todayEnd, "传入时间时,todayEnd不能为空");
|
|
|
+ Assert.isTrue(!todayStart.isAfter(todayEnd), "todayStart不能晚于todayEnd");
|
|
|
+ }
|
|
|
+
|
|
|
+ // -------------------------- 2. 公共查询条件准备 --------------------------
|
|
|
+ // 「看过我」所需的:当前用户发布的岗位ID列表
|
|
|
+ List<Long> myPostIds = new ArrayList<>();
|
|
|
+ List<Object> postIdObjs = postPushService.listObjs(
|
|
|
+ new QueryWrapper<PostPush>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .select("post_push_id")
|
|
|
+ );
|
|
|
+ if (postIdObjs != null && !postIdObjs.isEmpty()) {
|
|
|
+ myPostIds = postIdObjs.stream()
|
|
|
+ .map(obj -> Long.valueOf(obj.toString()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // -------------------------- 3. 指标查询(按需求差异化处理)--------------------------
|
|
|
+ // 3.1 我看过(企业查看求职者数量)
|
|
|
+ int currentISaw = userBrowseService.count(
|
|
|
+ new QueryWrapper<UserBrowse>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("browse_type", 2)
|
|
|
+ .between("update_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("iSaw", currentISaw);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayISaw = userBrowseService.count(
|
|
|
+ new QueryWrapper<UserBrowse>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("browse_type", 2)
|
|
|
+ .between("update_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("tyIsaw", currentISaw - yesterdayISaw);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.2 看过我(求职者查看企业岗位数量)
|
|
|
+ int currentSawMe = 0;
|
|
|
+ if (!myPostIds.isEmpty()) {
|
|
|
+ currentSawMe = userBrowseService.count(
|
|
|
+ new QueryWrapper<UserBrowse>()
|
|
|
+ .in("post_push_id", myPostIds)
|
|
|
+ .eq("post_push_id", postPushId) // 筛选指定岗位
|
|
|
+ .between("update_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ }
|
|
|
+ resultMap.put("sawMe", currentSawMe);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdaySawMe = 0;
|
|
|
+ if (!myPostIds.isEmpty()) {
|
|
|
+ yesterdaySawMe = userBrowseService.count(
|
|
|
+ new QueryWrapper<UserBrowse>()
|
|
|
+ .in("post_push_id", myPostIds)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("update_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
}
|
|
|
+ resultMap.put("tySawMe", currentSawMe - yesterdaySawMe);
|
|
|
+ }
|
|
|
|
|
|
+ // 3.3 我沟通(企业主动发起沟通数量)
|
|
|
+ int currentICommunicated = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("type", 2)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("iCommunicated", currentICommunicated);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayICommunicated = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("type", 2)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("tyICommunicated", currentICommunicated - yesterdayICommunicated);
|
|
|
+ }
|
|
|
|
|
|
- // 4. 统计各指标今日数据及昨日数据
|
|
|
- // 4.1 我看过(当前企业查看的求职者数量)
|
|
|
- int todayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",todayStart,todayEnd));
|
|
|
- int yesterdayISaw = userBrowseService.count(new QueryWrapper<UserBrowse>().eq("user_id",userId).eq("browse_type",2).between("update_time",yesterdayStart,yesterdayEnd));
|
|
|
- resultMap.put("iSaw", todayISaw);
|
|
|
- resultMap.put("tyIsaw",todayISaw-yesterdayISaw);
|
|
|
+ // 3.4 求职者沟通(求职者主动发起沟通数量)
|
|
|
+ int currentCandidateCommunicated = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("type", 1)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("candidateCommunicated", currentCandidateCommunicated);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayCandidateCommunicated = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("type", 1)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("tyCandidateCommunicated", currentCandidateCommunicated - yesterdayCandidateCommunicated);
|
|
|
+ }
|
|
|
|
|
|
- // 4.2 看过我(求职者查看当前企业的数量)
|
|
|
- List<Object> postIdObjs = postPushService.listObjs(
|
|
|
- new QueryWrapper<PostPush>()
|
|
|
- .eq("user_id", userId) // 筛选“我发布的岗位”
|
|
|
- .select("post_push_id")); // 只查岗位ID);
|
|
|
- if (postIdObjs == null || postIdObjs.isEmpty()) {
|
|
|
- resultMap.put("sawMe",0);
|
|
|
- resultMap.put("tySawMe",0);
|
|
|
- }
|
|
|
- List<Long> myPostIds = postIdObjs.stream()
|
|
|
- .map(obj -> Long.valueOf(obj.toString()))
|
|
|
- .collect(Collectors.toList());
|
|
|
- int todaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdaySawMe = userBrowseService.count(new QueryWrapper<UserBrowse>().in("post_push_id",myPostIds).between("update_time",yesterdayStart,yesterdayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("sawMe",todaySawMe);
|
|
|
- resultMap.put("tySawMe",todaySawMe-yesterdaySawMe);
|
|
|
-
|
|
|
- // 4.3 我沟通(企业主动发起的沟通数量)
|
|
|
- int todayICommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdayICommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",2).between("create_time",yesterdayStart,yesterdayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("iCommunicated",todayICommunicated);
|
|
|
- resultMap.put("tyICommunicated",todayICommunicated-yesterdayICommunicated);
|
|
|
- // 4.4 求职者沟通(求职者主动发起的沟通数量)
|
|
|
- int todayCandidateCommunicated =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdayCandidateCommunicated = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("type",1).between("create_time",yesterdayStart,yesterdayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("candidateCommunicated", todayCandidateCommunicated);
|
|
|
- resultMap.put("tyCandidateCommunicated",todayCandidateCommunicated-yesterdayCandidateCommunicated);
|
|
|
-
|
|
|
- // 4.5 收获简历(企业收到的简历数量,对应is_send_resumes=1)
|
|
|
- int todayReceivedResumes = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdayReceivedResumes =chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).eq("is_send_resumes",1).between("update_time",yesterdayStart,yesterdayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("receivedResumes", todayReceivedResumes);
|
|
|
- resultMap.put("tyReceivedResumes",todayReceivedResumes-yesterdayReceivedResumes);
|
|
|
-
|
|
|
- // 4.6 交换电话微信(电话/微信交换成功数量,对应is_send_phone=1或is_send_wx=1)
|
|
|
- int todayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdayExchangedContact = chatConversationService.count(new QueryWrapper<ChatConversation>().eq("focused_user_id",userId).and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1)) .between("update_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("exchangedContact", todayExchangedContact);
|
|
|
- resultMap.put("tyExchangeContact",todayExchangedContact-yesterdayExchangedContact);
|
|
|
-
|
|
|
- // 4.7 接受面试(求职者接受面试的数量,需结合status字段定义)
|
|
|
- int todayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",todayStart,todayEnd).eq("post_push_id",postPushId));
|
|
|
- int yesterdayAcceptedInterview = interviewRecordService.count(new QueryWrapper<InterviewRecord>().eq("user_id",userId).eq("status",2).between("create_time",yesterdayStart,yesterdayEnd).eq("post_push_id",postPushId));
|
|
|
- resultMap.put("acceptedInterview", todayAcceptedInterview);
|
|
|
- resultMap.put("tyAcceptedInterview",todayAcceptedInterview-yesterdayAcceptedInterview);
|
|
|
-
|
|
|
-
|
|
|
- return resultMap;
|
|
|
+ // 3.5 收获简历(企业收到简历数量)
|
|
|
+ int currentReceivedResumes = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("is_send_resumes", 1)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("update_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("receivedResumes", currentReceivedResumes);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayReceivedResumes = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("is_send_resumes", 1)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("update_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("tyReceivedResumes", currentReceivedResumes - yesterdayReceivedResumes);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3.6 交换电话微信(修复原Bug:昨日查询用昨日时间范围)
|
|
|
+ int currentExchangedContact = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1))
|
|
|
+ .between("update_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("exchangedContact", currentExchangedContact);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayExchangedContact = chatConversationService.count(
|
|
|
+ new QueryWrapper<ChatConversation>()
|
|
|
+ .eq("focused_user_id", userId)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .and(qw -> qw.eq("is_send_phone", 1).or().eq("is_send_wx", 1))
|
|
|
+ .between("update_time", yesterdayStart, yesterdayEnd) // 原代码误用todayStart,现已修正
|
|
|
+ );
|
|
|
+ resultMap.put("tyExchangeContact", currentExchangedContact - yesterdayExchangedContact);
|
|
|
}
|
|
|
+
|
|
|
+ // 3.7 接受面试(求职者接受面试数量)
|
|
|
+ int currentAcceptedInterview = interviewRecordService.count(
|
|
|
+ new QueryWrapper<InterviewRecord>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("status", 2)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", todayStart, todayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("acceptedInterview", currentAcceptedInterview);
|
|
|
+ if (isCalculateDiff) {
|
|
|
+ int yesterdayAcceptedInterview = interviewRecordService.count(
|
|
|
+ new QueryWrapper<InterviewRecord>()
|
|
|
+ .eq("user_id", userId)
|
|
|
+ .eq("status", 2)
|
|
|
+ .eq("post_push_id", postPushId)
|
|
|
+ .between("create_time", yesterdayStart, yesterdayEnd)
|
|
|
+ );
|
|
|
+ resultMap.put("tyAcceptedInterview", currentAcceptedInterview - yesterdayAcceptedInterview);
|
|
|
+ }
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
}
|