diff --git a/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java b/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java index 6679b1f9..1ee9e72d 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java +++ b/services/ad-platform-source/src/main/java/com/baiye/module/dao/ClueMiddleRepository.java @@ -206,7 +206,7 @@ public interface ClueMiddleRepository extends JpaRepository, J * @param clueType 线索类型 * @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 queryClueByClueType(String startTime, String endTime, List clueType); List findByTaskIdAndMemberStatus(Long taskId, int memberStatus); diff --git a/services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java b/services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java index 9e6bc5c5..e3282757 100644 --- a/services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java +++ b/services/ad-platform-source/src/main/java/com/baiye/task/ReportSync.java @@ -9,6 +9,7 @@ import com.baiye.module.dao.ReportTokerRepository; import com.baiye.module.entity.ClueMiddle; import com.baiye.module.entity.ReportToker; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -20,6 +21,7 @@ import java.util.stream.Collectors; */ @RequiredArgsConstructor @Component +@Slf4j public class ReportSync { private final ClueMiddleRepository clueMiddleRepository; private final UserClient userClient; @@ -28,14 +30,16 @@ public class ReportSync { /** * 每天晚上23点,定时统计外呼信息 */ - @Scheduled(cron = "0 0 23 * * ? ") // @Scheduled(cron = "0 0/1 * * * ? ") + @Scheduled(cron = "0 0 23 * * ? ") public void reportToker() { + log.info("拓客投流统计 开始------------------{}", DateUtil.date()); //当前时间 String beginOfDay = DateUtil.formatDateTime(DateUtil.yesterday()); String endOfDay = DateUtil.formatDateTime(DateUtil.date()); List list = dealData(beginOfDay, endOfDay); reportTokerRepository.saveAll(list); + log.info("拓客投流统计 结束------------------{}", DateUtil.date()); } public List dealData(String beginOfDay, String endOfDay) { @@ -43,9 +47,6 @@ public class ReportSync { List clueTypes = Arrays.asList(ClueTypeConstants.TOKER_TYPE); List clueMiddles = clueMiddleRepository.queryClueByClueType(beginOfDay, endOfDay, clueTypes); List list = new ArrayList<>(); - int intention = 0; - int notIntention = 0; - int notTurnOn = 0; //按人员id分组 HashMap> mapByUserId = new HashMap<>(clueMiddles.stream().collect(Collectors.groupingBy(ClueMiddle::getMemberId, Collectors.toList()))); @@ -53,21 +54,29 @@ public class ReportSync { Map userNameList = userClient.findById(userIds); for (Long memberId : mapByUserId.keySet()) { List clueMiddlesByUserId = mapByUserId.get(memberId); - for (ClueMiddle clueMiddle : clueMiddlesByUserId) { - //标签 - String sourceLabel = clueMiddle.getSourceLabel().get(0); - switch (sourceLabel) { - case SourceLabelConstants.INTENTION: - intention += 1; - break; - case SourceLabelConstants.NOT_INTENTION: - notIntention += 1; - break; - case SourceLabelConstants.NOT_TURN_ON: - notTurnOn += 1; - break; - default: - break; + //任务分组 + HashMap> mapByTaskId = new HashMap<>(clueMiddlesByUserId.stream().collect(Collectors.groupingBy(ClueMiddle::getTaskId, Collectors.toList()))); + for (Long taskId : mapByTaskId.keySet()) { + List clueMiddlesByTaskId = mapByTaskId.get(taskId); + int intention = 0; + int notIntention = 0; + int notTurnOn = 0; + for (ClueMiddle clueMiddle : clueMiddlesByTaskId) { + //标签 + String sourceLabel = clueMiddle.getSourceLabel().get(0); + switch (sourceLabel) { + case SourceLabelConstants.INTENTION: + intention += 1; + break; + case SourceLabelConstants.NOT_INTENTION: + notIntention += 1; + break; + case SourceLabelConstants.NOT_TURN_ON: + notTurnOn += 1; + break; + default: + break; + } } ReportToker reportToker = new ReportToker(); reportToker.setIntention(intention); @@ -76,7 +85,7 @@ public class ReportSync { reportToker.setCreateTime(DateUtil.date()); reportToker.setMemberId(memberId); reportToker.setMemberName(userNameList.get(memberId)); - reportToker.setTaskId(clueMiddle.getTaskId()); + reportToker.setTaskId(taskId); list.add(reportToker); } }