Commit 44b39962 by zhuht

[chg]顾客组数统计,只统计符合有效顾客定义的记录;

1 parent a7a6b60b
package com.viontech.keliu.dao; package com.viontech.keliu.dao;
import cn.hutool.core.date.DateUtil;
import com.viontech.keliu.entity.DateTimeParam; import com.viontech.keliu.entity.DateTimeParam;
import com.viontech.keliu.entity.Person; import com.viontech.keliu.entity.Person;
import com.viontech.keliu.service.DateTimeParamService; import com.viontech.keliu.service.DateTimeParamService;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import jakarta.annotation.Resource;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
/** /**
* Created with IntelliJ IDEA. * Created with IntelliJ IDEA.
...@@ -65,12 +64,19 @@ public class FaceRecognitionDao { ...@@ -65,12 +64,19 @@ public class FaceRecognitionDao {
String sql = "select account_id,mall_id,gate_id,person_unid,direction,track_time,countdate as countDate,person_type,age,gender," + String sql = "select account_id,mall_id,gate_id,person_unid,direction,track_time,countdate as countDate,person_type,age,gender," +
"counttime as countTime from d_face_recognition where mall_id = :mallId and countdate between :startDate and :endDate and counttime >= :startTime and counttime < :endTime " + "counttime as countTime from d_face_recognition where mall_id = :mallId and countdate between :startDate and :endDate and counttime >= :startTime and counttime < :endTime " +
"and direction in(-1,1,6) and person_type = 0 order by person_unid asc, counttime asc;"; "and direction in(-1,1,6) and person_type = 0 order by person_unid asc, counttime asc;";
String sqlNoMultipleDay = "select account_id,mall_id,gate_id,person_unid,direction,track_time,countdate as countDate,person_type,age,gender," +
"counttime as countTime from d_face_recognition where mall_id = :mallId and countdate = :startDate and counttime >= :startTime and counttime < :endTime " +
"and direction in(-1,1,6) and person_type = 0 order by person_unid asc, counttime asc;";
Map<String, Object> queryMap = new HashMap<>(); Map<String, Object> queryMap = new HashMap<>();
queryMap.put("mallId", mallId); queryMap.put("mallId", mallId);
queryMap.put("startDate", dateTimeParam.getStartDate()); queryMap.put("startDate", dateTimeParam.getStartDate());
queryMap.put("endDate", dateTimeParam.getEndDate()); queryMap.put("endDate", dateTimeParam.getEndDate());
queryMap.put("startTime", dateTimeParam.getStartDateTime()); queryMap.put("startTime", dateTimeParam.getStartDateTime());
queryMap.put("endTime", dateTimeParam.getEndDateTime()); queryMap.put("endTime", dateTimeParam.getEndDateTime());
if (DateUtil.isSameDay(dateTimeParam.getStartDate(), dateTimeParam.getEndDate())) {
return namedParameterJdbcTemplate.query(sqlNoMultipleDay, queryMap, new BeanPropertyRowMapper<>(Person.class));
}
return namedParameterJdbcTemplate.query(sql, queryMap, new BeanPropertyRowMapper<>(Person.class)); return namedParameterJdbcTemplate.query(sql, queryMap, new BeanPropertyRowMapper<>(Person.class));
} }
......
...@@ -89,6 +89,7 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -89,6 +89,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
Long excludePersonTime = getExcludePersonTime(mallId); Long excludePersonTime = getExcludePersonTime(mallId);
Integer filterAttention = getFilterAttention(mallId); Integer filterAttention = getFilterAttention(mallId);
Integer effectVisitorsConfig = getEffectVisitors(mallId);
boolean needFilter = filterAttention == 1; boolean needFilter = filterAttention == 1;
//出入口gateId //出入口gateId
List<Long> gateIds = bGateDao.getMallInOutGateIds(mallId); List<Long> gateIds = bGateDao.getMallInOutGateIds(mallId);
...@@ -250,10 +251,9 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -250,10 +251,9 @@ public class PersonRecordServiceImpl implements PersonRecordService {
} }
//修改统计数据 //修改统计数据
updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter); updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig);
//修改统计数据小时 //修改统计数据小时
updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter); updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig);
if (needFilter) { if (needFilter) {
//修改停留时长 //修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList); updateMallDayResidenceCountData(mallId, countDate, personRecordList);
...@@ -521,8 +521,16 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -521,8 +521,16 @@ public class PersonRecordServiceImpl implements PersonRecordService {
return filterAttention == null ? 0 : Integer.parseInt(filterAttention); return filterAttention == null ? 0 : Integer.parseInt(filterAttention);
} }
/**
* @return 店内停留时间小于X秒的不算有效顾客人数
*/
private Integer getEffectVisitors(Long mallId) {
String effectVisitorsConfig = configParamDao.getConfigParamByMallIdAndConfigKey(mallId, "effectVisitorsConfig");
return effectVisitorsConfig == null ? 0 : Integer.parseInt(effectVisitorsConfig);
}
private void updateFaceRecognitionSta(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter) { private void updateFaceRecognitionSta(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig) {
Map<String, DPersonRecord> personRecordMap = personRecords.stream().collect(Collectors.toMap(DPersonRecord::getPersonUnid, dPersonRecord -> dPersonRecord, (k1, k2) -> k1)); Map<String, DPersonRecord> personRecordMap = personRecords.stream().collect(Collectors.toMap(DPersonRecord::getPersonUnid, dPersonRecord -> dPersonRecord, (k1, k2) -> k1));
//顾客总人数 //顾客总人数
long customerCount = personRecordMap.keySet().size(); long customerCount = personRecordMap.keySet().size();
...@@ -575,7 +583,11 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -575,7 +583,11 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setFemaleStage(femaleStageStr); updateSta.setFemaleStage(femaleStageStr);
CustomerGroupResult customerGroupResult = new CustomerGroupResult(); CustomerGroupResult customerGroupResult = new CustomerGroupResult();
Map<String, List<DPersonRecord>> groupMap = personRecordMap.values().stream().collect(Collectors.groupingBy(DPersonRecord::getGroupUnid)); List<DPersonRecord> visitorsGroupRecordList = personRecordMap.values().stream().toList();
Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(visitorsGroupRecordList, effectVisitorsConfig);
List<DPersonRecord> effectVisitorsRecord = nonEffectVisitorsUnids.isEmpty() ? visitorsGroupRecordList
: visitorsGroupRecordList.stream().filter(r -> !nonEffectVisitorsUnids.contains(r.getPersonUnid())).toList();
Map<String, List<DPersonRecord>> groupMap = effectVisitorsRecord.stream().collect(Collectors.groupingBy(DPersonRecord::getGroupUnid));
groupMap.forEach((k, v) -> { groupMap.forEach((k, v) -> {
calGroup(1, customerGroupResult, v); calGroup(1, customerGroupResult, v);
}); });
...@@ -603,7 +615,33 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -603,7 +615,33 @@ public class PersonRecordServiceImpl implements PersonRecordService {
} }
private void updateFaceRecognitionStaHour(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter) {
/**
* @param recordList 顾客记录
* @param effectVisitorsConfig 有效顾客停留时长配置
* @return 停留时长小于配置值的用户unid
*/
private Set<String> nonEffectVisitorsUnids(List<DPersonRecord> recordList, Integer effectVisitorsConfig) {
if (effectVisitorsConfig == null || effectVisitorsConfig == 0 || CollectionUtils.isEmpty(recordList)) {
return Collections.emptySet();
}
Set<String> nonEffectVisitorUnid = new HashSet<>();
recordList.stream().collect(Collectors.groupingBy(DPersonRecord::getPersonUnid))
.values().forEach(personList -> {
long staySecondSum = personList.stream().filter(p -> p.getArriveTime() != null && p.getLeaveTime() != null)
.mapToLong(p -> DateUtil.between(p.getArriveTime(), p.getLeaveTime(), DateUnit.SECOND)).sum();
if (staySecondSum > 0 && staySecondSum < effectVisitorsConfig) {
nonEffectVisitorUnid.add(personList.get(0).getPersonUnid());
}
});
return nonEffectVisitorUnid;
}
private void updateFaceRecognitionStaHour(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig) {
Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(personRecords, effectVisitorsConfig);
Map<String, List<DPersonRecord>> personUnidMap = personRecords.stream().collect(Collectors.groupingBy(DPersonRecord::getPersonUnid)); Map<String, List<DPersonRecord>> personUnidMap = personRecords.stream().collect(Collectors.groupingBy(DPersonRecord::getPersonUnid));
List<DPersonRecord> personList = new ArrayList<>(); List<DPersonRecord> personList = new ArrayList<>();
personUnidMap.forEach((k, v) -> { personUnidMap.forEach((k, v) -> {
...@@ -665,7 +703,10 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -665,7 +703,10 @@ public class PersonRecordServiceImpl implements PersonRecordService {
CustomerGroupResult customerGroupResult = new CustomerGroupResult(); CustomerGroupResult customerGroupResult = new CustomerGroupResult();
if (!CollectionUtils.isEmpty(dPersonRecords)) { if (!CollectionUtils.isEmpty(dPersonRecords)) {
Map<String, List<DPersonRecord>> groupMap = dPersonRecords.stream().collect(Collectors.groupingBy(DPersonRecord::getGroupUnid));
Map<String, List<DPersonRecord>> groupMap = nonEffectVisitorsUnids.isEmpty() ?
dPersonRecords.stream().collect(Collectors.groupingBy(DPersonRecord::getGroupUnid))
: dPersonRecords.stream().filter(r -> !nonEffectVisitorsUnids.contains(r.getGroupUnid())).collect(Collectors.groupingBy(DPersonRecord::getGroupUnid));
groupMap.forEach((k1, v1) -> { groupMap.forEach((k1, v1) -> {
calGroup(1, customerGroupResult, v1); calGroup(1, customerGroupResult, v1);
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!