Commit 169f3492 by zhuht

[chg]批次统计支持3种模式;

1 parent aa1f4418
......@@ -16,9 +16,11 @@ import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.core.simple.JdbcClient;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestClient;
import java.util.*;
import java.util.function.Function;
......@@ -74,23 +76,34 @@ public class PersonRecordServiceImpl implements PersonRecordService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private JdbcClient jdbcClient;
@Autowired
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Override
public void handlePersonRecord(Long mallId, Date countDate) {
//先删除数据
removeData(mallId, countDate);
List<Person> personList = faceRecognitionDao.queryFaceRecognitionList(mallId, countDate);
if (CollectionUtils.isEmpty(personList)) {
return;
}
//有抓拍记录再删除数据
removeData(mallId, countDate);
// 是否是自定义的汽车严格模式
boolean strictMode = strictModeMallIds != null && strictModeMallIds.contains(mallId);
Long excludePersonTime = getExcludePersonTime(mallId);
Integer filterAttention = getFilterAttention(mallId);
long excludePersonTime = getExcludePersonTime(mallId);
int filterAttention = getFilterAttention(mallId);
Integer effectVisitorsConfig = getEffectVisitors(mallId);
Integer personGroupMaxNum = getPersonGroupMaxNum(mallId);
int batchStatisticsModel = getBatchStatisticsModel(mallId);
if (batchStatisticsModel == 1) {
// 标准模式,所有顾客都参与计算. 直接把有效顾客过滤条件配置改成0.这样统计批次时所有顾客都当有效顾客统计
effectVisitorsConfig = 0;
}
log.info("门店:{} 批次统计,各参数,excludePersonTime: {}, filterAttention: {}, effectVisitorsConfig: {}, personGroupMaxNum: {}, batchStatisticsModel: {}",
mallId, excludePersonTime, filterAttention, effectVisitorsConfig, personGroupMaxNum, batchStatisticsModel);
boolean needFilter = filterAttention == 1;
//出入口gateId
......@@ -152,7 +165,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
}
});
log.info("personInOutDetailList.size:{}", personInOutDetailList.size());
if (CollectionUtils.isEmpty(personInOutDetailList)) {
return;
}
......@@ -199,24 +212,55 @@ public class PersonRecordServiceImpl implements PersonRecordService {
//按personUnid分组
//Map<String, List<DPersonRecord>> personRecordMap = recordList.stream().collect(Collectors.groupingBy(DPersonRecord::getPersonUnid));
List<DPersonRecord> personRecordList = new ArrayList<>();
log.info("开始过滤并保存DPersonRecord. mallId:{}, countDate:{}", mallId, DateUtil.formatDate(countDate));
for (DPersonRecord dPersonRecord : recordList) {
// 根据统计模式,确定是否需要过滤掉人
if (batchStatisticsModel == 3) {
if (needCarFilter(dPersonRecord, needFilter, excludePersonTime, strictMode, filterAttention, mallId)) {
// 需要被汽车模式过滤,不保存,不加入后续统计
continue;
}
}
personRecordList.add(dPersonRecord);
dPersonRecordDao.createDPersonRecordBatch(Collections.singletonList(dPersonRecord));
if (!CollectionUtils.isEmpty(dPersonRecord.getPersonTrackDetailList())) {
dPersonTrackDetailDao.createDPersonTrackDetailBatch(dPersonRecord.getPersonTrackDetailList());
}
}
//修改统计数据
updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
//修改统计数据小时
updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
if (needFilter) {
//修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList);
//修改停留时长分布
updateFaceResidence(mallId, countDate, personRecordList);
}
}
private boolean needCarFilter(DPersonRecord dPersonRecord, boolean needFilter, long excludePersonTime, boolean strictMode, int filterAttention, Long mallId) {
//没有匹配到出
if (dPersonRecord.getLeaveTime() == null) {
//判断在店内的时间
List<DPersonTrackDetail> personTrackDetailList = dPersonRecord.getPersonTrackDetailList();
if (CollectionUtils.isEmpty(personTrackDetailList)) {
continue;
return true;
}
//计算区域的总停留时间,小于10分钟的排除掉
long totalTime = personTrackDetailList.stream().mapToLong(DPersonTrackDetail::getVisitDuration).sum();
if (needFilter && totalTime < excludePersonTime * 60 * 1000) {
continue;
return true;
}
}
//排除掉短时间在店内的记录
if (needFilter && dPersonRecord.getVisitDuration() < excludePersonTime * 60 * 1000) {
continue;
return true;
}
if (strictMode) {
......@@ -226,43 +270,26 @@ public class PersonRecordServiceImpl implements PersonRecordService {
// if (dPersonRecord.getReceptionCount() == 0) {
// continue;
// }
// 没有店内分区的记录,过滤
List<DPersonTrackDetail> personTrackDetailList = dPersonRecord.getPersonTrackDetailList();
if (CollectionUtils.isEmpty(personTrackDetailList)) {
continue;
return true;
}
// 汽车专属门店定制严格模式,必须要在区域呆够指定时间才算关注
List<DPersonTrackDetail> attentionList = personTrackDetailList.stream().filter(v -> v.getVisitDuration() != null && v.getVisitDuration() > strictModeAttentionSecond * 1000L)
.sorted(Comparator.comparing(DPersonTrackDetail::getArriveTime)).toList();
if (attentionList.isEmpty()) {
continue;
return true;
}
dPersonRecord.setAttentionCount(attentionList.size());
dPersonRecord.setAttentionTime(attentionList.get(0).getArriveTime());
}
} else {
// 普通汽车模式
//没有被接待,并且没有看车的排除掉
if (dPersonRecord.getReceptionCount() == 0 && filterAttention == 1 && dPersonRecord.getAttentionCount() == 0) {
continue;
}
return dPersonRecord.getReceptionCount() == 0 && filterAttention == 1 && dPersonRecord.getAttentionCount() == 0;
}
personRecordList.add(dPersonRecord);
dPersonRecordDao.createDPersonRecordBatch(Collections.singletonList(dPersonRecord));
if (!CollectionUtils.isEmpty(dPersonRecord.getPersonTrackDetailList())) {
dPersonTrackDetailDao.createDPersonTrackDetailBatch(dPersonRecord.getPersonTrackDetailList());
}
}
//修改统计数据
updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
//修改统计数据小时
updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
if (needFilter) {
//修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList);
//修改停留时长分布
updateFaceResidence(mallId, countDate, personRecordList);
}
return false;
}
......@@ -524,6 +551,19 @@ public class PersonRecordServiceImpl implements PersonRecordService {
}
/**
*
* @param mallId 门店
* @return 门店的批次统计计算模式。
* 1 标准模式:所有顾客都参与统计。
* 2 有效模式:仅有效顾客参与统计。
* 3 严格模式:延用汽车那一套。根据停留时长,接待,看车等条件过滤
*/
private Integer getBatchStatisticsModel(Long mallId) {
String batchStatisticsModel = configParamDao.getConfigParamByMallIdAndConfigKey(mallId, "batchStatisticsModel");
return batchStatisticsModel == null ? 1 : Integer.parseInt(batchStatisticsModel);
}
/**
* @return 店内停留时间小于X秒的不算有效顾客人数
*/
private Integer getEffectVisitors(Long mallId) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!