统计拓客投流

master
wjt wjt 2 years ago
parent 22e92da2a2
commit f183683bb3

@ -206,7 +206,7 @@ public interface ClueMiddleRepository extends JpaRepository<ClueMiddle, Long>, J
* @param clueType 线 * @param clueType 线
* @return * @return
*/ */
@Query(value = " select * from tb_clue_middle as t where t.label_time >= ?1 and t.label_time< ?2 and t.clue_stage in ?3", nativeQuery = true) @Query(value = " select * from tb_clue_middle as t where t.label_time >= ?1 and t.label_time< ?2 and t.clue_type in ?3", nativeQuery = true)
List<ClueMiddle> queryClueByClueType(String startTime, String endTime, List<Integer> clueType); List<ClueMiddle> queryClueByClueType(String startTime, String endTime, List<Integer> clueType);
List<ClueMiddle> findByTaskIdAndMemberStatus(Long taskId, int memberStatus); List<ClueMiddle> findByTaskIdAndMemberStatus(Long taskId, int memberStatus);

@ -9,6 +9,7 @@ import com.baiye.module.dao.ReportTokerRepository;
import com.baiye.module.entity.ClueMiddle; import com.baiye.module.entity.ClueMiddle;
import com.baiye.module.entity.ReportToker; import com.baiye.module.entity.ReportToker;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -20,6 +21,7 @@ import java.util.stream.Collectors;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
@Component @Component
@Slf4j
public class ReportSync { public class ReportSync {
private final ClueMiddleRepository clueMiddleRepository; private final ClueMiddleRepository clueMiddleRepository;
private final UserClient userClient; private final UserClient userClient;
@ -28,14 +30,16 @@ public class ReportSync {
/** /**
* 23 * 23
*/ */
@Scheduled(cron = "0 0 23 * * ? ")
// @Scheduled(cron = "0 0/1 * * * ? ") // @Scheduled(cron = "0 0/1 * * * ? ")
@Scheduled(cron = "0 0 23 * * ? ")
public void reportToker() { public void reportToker() {
log.info("拓客投流统计 开始------------------{}", DateUtil.date());
//当前时间 //当前时间
String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday()); String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday());
String endOfDay = DateUtil.formatDateTime(DateUtil.date()); String endOfDay = DateUtil.formatDateTime(DateUtil.date());
List<ReportToker> list = dealData(beginOfDay, endOfDay); List<ReportToker> list = dealData(beginOfDay, endOfDay);
reportTokerRepository.saveAll(list); reportTokerRepository.saveAll(list);
log.info("拓客投流统计 结束------------------{}", DateUtil.date());
} }
public List<ReportToker> dealData(String beginOfDay, String endOfDay) { public List<ReportToker> dealData(String beginOfDay, String endOfDay) {
@ -43,9 +47,6 @@ public class ReportSync {
List<Integer> clueTypes = Arrays.asList(ClueTypeConstants.TOKER_TYPE); List<Integer> clueTypes = Arrays.asList(ClueTypeConstants.TOKER_TYPE);
List<ClueMiddle> clueMiddles = clueMiddleRepository.queryClueByClueType(beginOfDay, endOfDay, clueTypes); List<ClueMiddle> clueMiddles = clueMiddleRepository.queryClueByClueType(beginOfDay, endOfDay, clueTypes);
List<ReportToker> list = new ArrayList<>(); List<ReportToker> list = new ArrayList<>();
int intention = 0;
int notIntention = 0;
int notTurnOn = 0;
//按人员id分组 //按人员id分组
HashMap<Long, List<ClueMiddle>> mapByUserId = new HashMap<>(clueMiddles.stream().collect(Collectors.groupingBy(ClueMiddle::getMemberId, Collectors.toList()))); HashMap<Long, List<ClueMiddle>> mapByUserId = new HashMap<>(clueMiddles.stream().collect(Collectors.groupingBy(ClueMiddle::getMemberId, Collectors.toList())));
@ -53,21 +54,29 @@ public class ReportSync {
Map<Long, String> userNameList = userClient.findById(userIds); Map<Long, String> userNameList = userClient.findById(userIds);
for (Long memberId : mapByUserId.keySet()) { for (Long memberId : mapByUserId.keySet()) {
List<ClueMiddle> clueMiddlesByUserId = mapByUserId.get(memberId); List<ClueMiddle> clueMiddlesByUserId = mapByUserId.get(memberId);
for (ClueMiddle clueMiddle : clueMiddlesByUserId) { //任务分组
//标签 HashMap<Long, List<ClueMiddle>> mapByTaskId = new HashMap<>(clueMiddlesByUserId.stream().collect(Collectors.groupingBy(ClueMiddle::getTaskId, Collectors.toList())));
String sourceLabel = clueMiddle.getSourceLabel().get(0); for (Long taskId : mapByTaskId.keySet()) {
switch (sourceLabel) { List<ClueMiddle> clueMiddlesByTaskId = mapByTaskId.get(taskId);
case SourceLabelConstants.INTENTION: int intention = 0;
intention += 1; int notIntention = 0;
break; int notTurnOn = 0;
case SourceLabelConstants.NOT_INTENTION: for (ClueMiddle clueMiddle : clueMiddlesByTaskId) {
notIntention += 1; //标签
break; String sourceLabel = clueMiddle.getSourceLabel().get(0);
case SourceLabelConstants.NOT_TURN_ON: switch (sourceLabel) {
notTurnOn += 1; case SourceLabelConstants.INTENTION:
break; intention += 1;
default: break;
break; case SourceLabelConstants.NOT_INTENTION:
notIntention += 1;
break;
case SourceLabelConstants.NOT_TURN_ON:
notTurnOn += 1;
break;
default:
break;
}
} }
ReportToker reportToker = new ReportToker(); ReportToker reportToker = new ReportToker();
reportToker.setIntention(intention); reportToker.setIntention(intention);
@ -76,7 +85,7 @@ public class ReportSync {
reportToker.setCreateTime(DateUtil.date()); reportToker.setCreateTime(DateUtil.date());
reportToker.setMemberId(memberId); reportToker.setMemberId(memberId);
reportToker.setMemberName(userNameList.get(memberId)); reportToker.setMemberName(userNameList.get(memberId));
reportToker.setTaskId(clueMiddle.getTaskId()); reportToker.setTaskId(taskId);
list.add(reportToker); list.add(reportToker);
} }
} }

Loading…
Cancel
Save