|
|
@@ -1,21 +1,23 @@
|
|
|
package com.goafanti.Interview.service.impl;
|
|
|
|
|
|
+import com.goafanti.Interview.bo.OutPublicAidUid;
|
|
|
import com.goafanti.Interview.bo.UpdateUserBo;
|
|
|
import com.goafanti.Interview.service.UserArchivesInterviewService;
|
|
|
import com.goafanti.common.dao.PublicReleaseMapper;
|
|
|
import com.goafanti.common.dao.UserArchivesInterviewMapper;
|
|
|
import com.goafanti.common.dao.UserArchivesMapper;
|
|
|
+import com.goafanti.common.dao.UserFirstInterviewMapper;
|
|
|
import com.goafanti.common.model.UserArchives;
|
|
|
import com.goafanti.common.model.UserArchivesInterview;
|
|
|
+import com.goafanti.common.model.UserFirstInterview;
|
|
|
import com.goafanti.core.mybatis.BaseMybatisDao;
|
|
|
import com.goafanti.core.mybatis.page.Pagination;
|
|
|
import com.goafanti.customer.bo.MyUserDetailsBo;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 客户档案面谈表(UserArchivesInterview)表服务实现类
|
|
|
@@ -31,6 +33,8 @@ public class UserArchivesInterviewServiceImpl extends BaseMybatisDao<UserArchive
|
|
|
private UserArchivesMapper userArchivesMapper;
|
|
|
@Resource
|
|
|
private PublicReleaseMapper publicReleaseMapper;
|
|
|
+ @Resource
|
|
|
+ private UserFirstInterviewMapper userFirstInterviewMapper;
|
|
|
|
|
|
@Override
|
|
|
public Pagination<UserArchivesInterview> list(UserArchivesInterview userArchivesInterview, Integer pageNo, Integer pageSize) {
|
|
|
@@ -111,19 +115,19 @@ public class UserArchivesInterviewServiceImpl extends BaseMybatisDao<UserArchive
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
private void addUserArchivesInterview(UpdateUserBo in) {
|
|
|
List<UserArchivesInterview> list = userArchivesInterviewMapper.selectByUidAid(in.getUid(), in.getAid());
|
|
|
UserArchivesInterview userArchivesInterview = new UserArchivesInterview();
|
|
|
if (list.isEmpty()){
|
|
|
- userArchivesInterview.setUid(in.getUid());
|
|
|
- userArchivesInterview.setAid(in.getAid());
|
|
|
userArchivesInterview.setCounts(1);
|
|
|
}else {
|
|
|
userArchivesInterview = list.get(0);
|
|
|
userArchivesInterview.setCounts(userArchivesInterview.getCounts() + 1);
|
|
|
- userArchivesInterview.setUid(in.getUid());
|
|
|
- userArchivesInterview.setAid(in.getAid());
|
|
|
}
|
|
|
+ userArchivesInterview.setUid(in.getUid());
|
|
|
+ userArchivesInterview.setAid(in.getAid());
|
|
|
userArchivesInterview.setEarlyCommunication(in.getEarlyCommunication());
|
|
|
userArchivesInterview.setCustomerDemand(in.getCustomerDemand());
|
|
|
userArchivesInterview.setInterviewIdeas(in.getInterviewIdeas());
|
|
|
@@ -133,4 +137,101 @@ public class UserArchivesInterviewServiceImpl extends BaseMybatisDao<UserArchive
|
|
|
userArchivesInterview.setFollowUpPlan(in.getFollowUpPlan());
|
|
|
userArchivesInterviewMapper.insert(userArchivesInterview);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object pushUserFirstInterview(){
|
|
|
+ try {
|
|
|
+ // 获取所有公共发布记录
|
|
|
+ List<OutPublicAidUid> publicReleases = publicReleaseMapper.selectAllAidUid();
|
|
|
+
|
|
|
+ if (publicReleases == null || publicReleases.isEmpty()) {
|
|
|
+ return 1; // 如果没有数据,直接返回
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按 aid 分组
|
|
|
+ Map<String, List<OutPublicAidUid>> groupedByAid = groupByAid(publicReleases);
|
|
|
+
|
|
|
+ // 按 uid 进一步分组,并计算每个用户的首次发布时间
|
|
|
+ List<UserFirstInterview> res = calculateUserFirstInterviews(groupedByAid);
|
|
|
+
|
|
|
+ // 批量插入数据库
|
|
|
+ insertInBatches(res, 100);
|
|
|
+
|
|
|
+ return 1;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 异常处理
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("Error during processing user first interview", e);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+private Map<String, List<OutPublicAidUid>> groupByAid(List<OutPublicAidUid> publicReleases) {
|
|
|
+ return publicReleases.stream()
|
|
|
+ .filter(Objects::nonNull) // 过滤掉空对象
|
|
|
+ .collect(Collectors.groupingBy(OutPublicAidUid::getAid));
|
|
|
+}
|
|
|
+
|
|
|
+private List<UserFirstInterview> calculateUserFirstInterviews(Map<String, List<OutPublicAidUid>> groupedByAid) {
|
|
|
+ long currentTime = System.currentTimeMillis(); // 提前获取当前时间戳
|
|
|
+ List<UserFirstInterview> res = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<OutPublicAidUid>> entry : groupedByAid.entrySet()) {
|
|
|
+ String aid = entry.getKey();
|
|
|
+ List<OutPublicAidUid> aids = entry.getValue();
|
|
|
+
|
|
|
+ Map<String, List<OutPublicAidUid>> groupedByUid = aids.stream()
|
|
|
+ .filter(Objects::nonNull) // 过滤掉空对象
|
|
|
+ .collect(Collectors.groupingBy(OutPublicAidUid::getUid));
|
|
|
+
|
|
|
+ for (Map.Entry<String, List<OutPublicAidUid>> uidEntry : groupedByUid.entrySet()) {
|
|
|
+ String uid = uidEntry.getKey();
|
|
|
+ List<OutPublicAidUid> list = uidEntry.getValue();
|
|
|
+
|
|
|
+ UserFirstInterview in = findEarliestRelease(list, currentTime, aid, uid);
|
|
|
+ if (in != null) {
|
|
|
+ res.add(in);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+}
|
|
|
+
|
|
|
+private UserFirstInterview findEarliestRelease(List<OutPublicAidUid> list, long currentTime, String aid, String uid) {
|
|
|
+ UserFirstInterview in = null;
|
|
|
+ long earliestTime = Long.MAX_VALUE;
|
|
|
+
|
|
|
+ for (OutPublicAidUid e : list) {
|
|
|
+ if (e == null || e.getReleaseStart() == null) {
|
|
|
+ continue; // 跳过空对象或无效的时间
|
|
|
+ }
|
|
|
+
|
|
|
+ long releaseStartTime = e.getReleaseStart().getTime();
|
|
|
+ if (releaseStartTime < earliestTime && releaseStartTime < currentTime) {
|
|
|
+ earliestTime = releaseStartTime;
|
|
|
+ in = new UserFirstInterview();
|
|
|
+ in.setFirstTime(e.getReleaseStart());
|
|
|
+ in.setUid(uid);
|
|
|
+ in.setAid(aid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return in;
|
|
|
+}
|
|
|
+
|
|
|
+private void insertInBatches(List<UserFirstInterview> res, int batchSize) {
|
|
|
+ int total = res.size();
|
|
|
+ for (int i = 0; i < total; i += batchSize) {
|
|
|
+ int end = Math.min(i + batchSize, total);
|
|
|
+ List<UserFirstInterview> batch = res.subList(i, end);
|
|
|
+ try {
|
|
|
+ userFirstInterviewMapper.insertBatch(batch);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 批量插入失败时的处理
|
|
|
+ e.printStackTrace();
|
|
|
+ throw new RuntimeException("Error inserting batch into database", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
}
|