统计拓客投流

master
wjt wjt 2 years ago
parent 22e92da2a2
commit f183683bb3

@ -206,7 +206,7 @@ public interface ClueMiddleRepository extends JpaRepository<ClueMiddle, Long>, 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<ClueMiddle> queryClueByClueType(String startTime, String endTime, List<Integer> clueType);
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.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<ReportToker> list = dealData(beginOfDay, endOfDay);
reportTokerRepository.saveAll(list);
log.info("拓客投流统计 结束------------------{}", DateUtil.date());
}
public List<ReportToker> dealData(String beginOfDay, String endOfDay) {
@ -43,9 +47,6 @@ public class ReportSync {
List<Integer> clueTypes = Arrays.asList(ClueTypeConstants.TOKER_TYPE);
List<ClueMiddle> clueMiddles = clueMiddleRepository.queryClueByClueType(beginOfDay, endOfDay, clueTypes);
List<ReportToker> list = new ArrayList<>();
int intention = 0;
int notIntention = 0;
int notTurnOn = 0;
//按人员id分组
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);
for (Long memberId : mapByUserId.keySet()) {
List<ClueMiddle> 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<Long, List<ClueMiddle>> mapByTaskId = new HashMap<>(clueMiddlesByUserId.stream().collect(Collectors.groupingBy(ClueMiddle::getTaskId, Collectors.toList())));
for (Long taskId : mapByTaskId.keySet()) {
List<ClueMiddle> 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);
}
}

Loading…
Cancel
Save