Commit aa1f4418 by zhuht

[chg]顾客组数统计,根据配置统计三人组和四人组;

1 parent 44b39962
...@@ -25,9 +25,13 @@ public class CustomerGroupResult { ...@@ -25,9 +25,13 @@ public class CustomerGroupResult {
private long multipleFamilyGroup; // 多人家庭组 private long multipleFamilyGroup; // 多人家庭组
private long multiplePartnerGroup; // 多人伙伴组 private long multiplePartnerGroup; // 多人伙伴组
private int personGroupMaxNum = 2;
private long threeGroup; // 三人组
private long fourGroup; // 四人组
public long getGroupNum() { public long getGroupNum() {
return singleGroup + doubleGroup + multipleGroup; return singleGroup + doubleGroup + threeGroup + fourGroup + multipleGroup;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -41,6 +41,8 @@ public class DMallDayFaceRecognitionSta { ...@@ -41,6 +41,8 @@ public class DMallDayFaceRecognitionSta {
private Long singleGroupNum; private Long singleGroupNum;
private Long doubleGroupNum; private Long doubleGroupNum;
private Long threeGroupNum;
private Long fourGroupNum;
private Long multipleGroupNum; private Long multipleGroupNum;
......
...@@ -41,6 +41,8 @@ public class DMallHourFaceRecognitionSta { ...@@ -41,6 +41,8 @@ public class DMallHourFaceRecognitionSta {
private Long singleGroupNum; private Long singleGroupNum;
private Long doubleGroupNum; private Long doubleGroupNum;
private Long threeGroupNum;
private Long fourGroupNum;
private Long multipleGroupNum; private Long multipleGroupNum;
...@@ -57,7 +59,4 @@ public class DMallHourFaceRecognitionSta { ...@@ -57,7 +59,4 @@ public class DMallHourFaceRecognitionSta {
private Long staffCount; private Long staffCount;
} }
\ No newline at end of file \ No newline at end of file
...@@ -90,6 +90,8 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -90,6 +90,8 @@ 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); Integer effectVisitorsConfig = getEffectVisitors(mallId);
Integer personGroupMaxNum = getPersonGroupMaxNum(mallId);
boolean needFilter = filterAttention == 1; boolean needFilter = filterAttention == 1;
//出入口gateId //出入口gateId
List<Long> gateIds = bGateDao.getMallInOutGateIds(mallId); List<Long> gateIds = bGateDao.getMallInOutGateIds(mallId);
...@@ -251,9 +253,9 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -251,9 +253,9 @@ public class PersonRecordServiceImpl implements PersonRecordService {
} }
//修改统计数据 //修改统计数据
updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig); updateFaceRecognitionSta(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
//修改统计数据小时 //修改统计数据小时
updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig); updateFaceRecognitionStaHour(mallId, countDate, personRecordList, needFilter, effectVisitorsConfig, personGroupMaxNum);
if (needFilter) { if (needFilter) {
//修改停留时长 //修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList); updateMallDayResidenceCountData(mallId, countDate, personRecordList);
...@@ -529,8 +531,18 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -529,8 +531,18 @@ public class PersonRecordServiceImpl implements PersonRecordService {
return effectVisitorsConfig == null ? 0 : Integer.parseInt(effectVisitorsConfig); return effectVisitorsConfig == null ? 0 : Integer.parseInt(effectVisitorsConfig);
} }
/**
*
* @param mallId 门店
* @return 每批次可统计的最大人数。默认为2,超过2人的批次都算到多人组里。
*/
private Integer getPersonGroupMaxNum(Long mallId) {
String personGroupMaxNum = configParamDao.getConfigParamByMallIdAndConfigKey(mallId, "personGroupMaxNum");
return personGroupMaxNum == null ? 2 : Integer.parseInt(personGroupMaxNum);
}
private void updateFaceRecognitionSta(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig) {
private void updateFaceRecognitionSta(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig, Integer personGroupMaxNum) {
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();
...@@ -583,6 +595,7 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -583,6 +595,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setFemaleStage(femaleStageStr); updateSta.setFemaleStage(femaleStageStr);
CustomerGroupResult customerGroupResult = new CustomerGroupResult(); CustomerGroupResult customerGroupResult = new CustomerGroupResult();
customerGroupResult.setPersonGroupMaxNum(personGroupMaxNum);
List<DPersonRecord> visitorsGroupRecordList = personRecordMap.values().stream().toList(); List<DPersonRecord> visitorsGroupRecordList = personRecordMap.values().stream().toList();
Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(visitorsGroupRecordList, effectVisitorsConfig); Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(visitorsGroupRecordList, effectVisitorsConfig);
List<DPersonRecord> effectVisitorsRecord = nonEffectVisitorsUnids.isEmpty() ? visitorsGroupRecordList List<DPersonRecord> effectVisitorsRecord = nonEffectVisitorsUnids.isEmpty() ? visitorsGroupRecordList
...@@ -594,6 +607,8 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -594,6 +607,8 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setGroupNum(customerGroupResult.getGroupNum()); updateSta.setGroupNum(customerGroupResult.getGroupNum());
updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup()); updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup());
updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup()); updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup());
updateSta.setThreeGroupNum(customerGroupResult.getThreeGroup());
updateSta.setFourGroupNum(customerGroupResult.getFourGroup());
updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup()); updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup());
updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup()); updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup());
updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup()); updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup());
...@@ -603,16 +618,15 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -603,16 +618,15 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setAvgReceptionSecond(avgReceptionSecond); updateSta.setAvgReceptionSecond(avgReceptionSecond);
if (needFilter) { if (needFilter) {
// 需要过滤时,更新顾客人数相关字段 // 需要过滤时,更新顾客人数相关字段
String updateSql = "update d_mall_day_face_recognition_sta set person_count = ?,custom_count = ?,male_count = ?,female_count = ?,male_stage = ?, female_stage = ?, group_num = ?, single_group_num = ?, double_group_num = ?, multiple_group_num = ?, family_group_num = ?, lover_group_num = ?, partner_group_num = ? ,reception_customer_count = ?, avg_reception_second = ? ,reception_group_count = ? where mall_id = ? and countdate = ?;"; String updateSql = "update d_mall_day_face_recognition_sta set person_count = ?,custom_count = ?,male_count = ?,female_count = ?,male_stage = ?, female_stage = ?, group_num = ?, single_group_num = ?, double_group_num = ?, three_group_num = ?, four_group_num = ?, multiple_group_num = ?, family_group_num = ?, lover_group_num = ?, partner_group_num = ? ,reception_customer_count = ?, avg_reception_second = ? ,reception_group_count = ? where mall_id = ? and countdate = ?;";
jdbcTemplate.update(updateSql, updateSta.getPersonCount(), updateSta.getCustomCount(), updateSta.getMaleCount(), updateSta.getFemaleCount(), updateSta.getMaleStage(), updateSta.getFemaleStage(), updateSta.getGroupNum(), updateSta.getSingleGroupNum(), updateSta.getDoubleGroupNum(), updateSta.getMultipleGroupNum(), updateSta.getFamilyGroupNum(), updateSta.getLoverGroupNum(), updateSta.getPartnerGroupNum(), updateSta.getReceptionCustomerCount(), updateSta.getAvgReceptionSecond(), updateSta.getReceptionGroupCount(), mallId, countDate); jdbcTemplate.update(updateSql, updateSta.getPersonCount(), updateSta.getCustomCount(), updateSta.getMaleCount(), updateSta.getFemaleCount(), updateSta.getMaleStage(), updateSta.getFemaleStage(), updateSta.getGroupNum(), updateSta.getSingleGroupNum(), updateSta.getDoubleGroupNum(), updateSta.getThreeGroupNum(), updateSta.getFourGroupNum(), updateSta.getMultipleGroupNum(), updateSta.getFamilyGroupNum(), updateSta.getLoverGroupNum(), updateSta.getPartnerGroupNum(), updateSta.getReceptionCustomerCount(), updateSta.getAvgReceptionSecond(), updateSta.getReceptionGroupCount(), mallId, countDate);
} else { } else {
// 不过滤时,只更新批次相关 // 不过滤时,只更新批次相关
String updateSql = "update d_mall_day_face_recognition_sta set group_num = ?, single_group_num = ?, double_group_num = ?, multiple_group_num = ?, family_group_num = ?, lover_group_num = ?, partner_group_num = ?, reception_customer_count = ?, avg_reception_second = ? ,reception_group_count = ? where mall_id = ? and countdate = ?;"; String updateSql = "update d_mall_day_face_recognition_sta set group_num = ?, single_group_num = ?, double_group_num = ?, three_group_num = ?, four_group_num = ?, multiple_group_num = ?, family_group_num = ?, lover_group_num = ?, partner_group_num = ?, reception_customer_count = ?, avg_reception_second = ? ,reception_group_count = ? where mall_id = ? and countdate = ?;";
jdbcTemplate.update(updateSql, updateSta.getGroupNum(), updateSta.getSingleGroupNum(), updateSta.getDoubleGroupNum(), updateSta.getMultipleGroupNum(), updateSta.getFamilyGroupNum(), updateSta.getLoverGroupNum(), updateSta.getPartnerGroupNum(), updateSta.getReceptionCustomerCount(), updateSta.getAvgReceptionSecond(), updateSta.getReceptionGroupCount(), mallId, countDate); jdbcTemplate.update(updateSql, updateSta.getGroupNum(), updateSta.getSingleGroupNum(), updateSta.getDoubleGroupNum(), updateSta.getThreeGroupNum(), updateSta.getFourGroupNum(), updateSta.getMultipleGroupNum(), updateSta.getFamilyGroupNum(), updateSta.getLoverGroupNum(), updateSta.getPartnerGroupNum(), updateSta.getReceptionCustomerCount(), updateSta.getAvgReceptionSecond(), updateSta.getReceptionGroupCount(), mallId, countDate);
} }
} }
} }
...@@ -638,7 +652,7 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -638,7 +652,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
return nonEffectVisitorUnid; return nonEffectVisitorUnid;
} }
private void updateFaceRecognitionStaHour(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig) { private void updateFaceRecognitionStaHour(Long mallId, Date countDate, List<DPersonRecord> personRecords, boolean needFilter, Integer effectVisitorsConfig, Integer personGroupMaxNum) {
Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(personRecords, effectVisitorsConfig); Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(personRecords, effectVisitorsConfig);
...@@ -702,6 +716,7 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -702,6 +716,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setFemaleStage(femaleStageStr); updateSta.setFemaleStage(femaleStageStr);
CustomerGroupResult customerGroupResult = new CustomerGroupResult(); CustomerGroupResult customerGroupResult = new CustomerGroupResult();
customerGroupResult.setPersonGroupMaxNum(personGroupMaxNum);
if (!CollectionUtils.isEmpty(dPersonRecords)) { if (!CollectionUtils.isEmpty(dPersonRecords)) {
Map<String, List<DPersonRecord>> groupMap = nonEffectVisitorsUnids.isEmpty() ? Map<String, List<DPersonRecord>> groupMap = nonEffectVisitorsUnids.isEmpty() ?
...@@ -714,6 +729,8 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -714,6 +729,8 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setGroupNum(customerGroupResult.getGroupNum()); updateSta.setGroupNum(customerGroupResult.getGroupNum());
updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup()); updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup());
updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup()); updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup());
updateSta.setThreeGroupNum(customerGroupResult.getThreeGroup());
updateSta.setFourGroupNum(customerGroupResult.getFourGroup());
updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup()); updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup());
updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup()); updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup());
updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup()); updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup());
...@@ -723,11 +740,11 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -723,11 +740,11 @@ public class PersonRecordServiceImpl implements PersonRecordService {
if (!CollectionUtils.isEmpty(updateList)) { if (!CollectionUtils.isEmpty(updateList)) {
if (needFilter) { if (needFilter) {
String updateSql = "update d_mall_hour_face_recognition_sta set person_count = :personCount,custom_count = :customCount,male_count = :maleCount,female_count = :femaleCount,male_stage = :maleStage, female_stage = :femaleStage, group_num = :groupNum, single_group_num = :singleGroupNum, double_group_num = :doubleGroupNum, multiple_group_num = :multipleGroupNum, family_group_num = :familyGroupNum, lover_group_num = :loverGroupNum, partner_group_num = :partnerGroupNum where mall_id = :mallId and countdate = :countdate and counttime = :counttime;"; String updateSql = "update d_mall_hour_face_recognition_sta set person_count = :personCount,custom_count = :customCount,male_count = :maleCount,female_count = :femaleCount,male_stage = :maleStage, female_stage = :femaleStage, group_num = :groupNum, single_group_num = :singleGroupNum, double_group_num = :doubleGroupNum, three_group_num = :threeGroupNum, four_group_num = :fourGroupNum, multiple_group_num = :multipleGroupNum, family_group_num = :familyGroupNum, lover_group_num = :loverGroupNum, partner_group_num = :partnerGroupNum where mall_id = :mallId and countdate = :countdate and counttime = :counttime;";
SqlParameterSource[] updateSources = SqlParameterSourceUtils.createBatch(updateList.toArray()); SqlParameterSource[] updateSources = SqlParameterSourceUtils.createBatch(updateList.toArray());
namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources); namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources);
} else { } else {
String updateSql = "update d_mall_hour_face_recognition_sta set group_num = :groupNum, single_group_num = :singleGroupNum, double_group_num = :doubleGroupNum, multiple_group_num = :multipleGroupNum, family_group_num = :familyGroupNum, lover_group_num = :loverGroupNum, partner_group_num = :partnerGroupNum where mall_id = :mallId and countdate = :countdate and counttime = :counttime;"; String updateSql = "update d_mall_hour_face_recognition_sta set group_num = :groupNum, single_group_num = :singleGroupNum, double_group_num = :doubleGroupNum, three_group_num = :threeGroupNum, four_group_num = :fourGroupNum, multiple_group_num = :multipleGroupNum, family_group_num = :familyGroupNum, lover_group_num = :loverGroupNum, partner_group_num = :partnerGroupNum where mall_id = :mallId and countdate = :countdate and counttime = :counttime;";
SqlParameterSource[] updateSources = SqlParameterSourceUtils.createBatch(updateList.toArray()); SqlParameterSource[] updateSources = SqlParameterSourceUtils.createBatch(updateList.toArray());
namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources); namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources);
} }
...@@ -795,6 +812,14 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -795,6 +812,14 @@ public class PersonRecordServiceImpl implements PersonRecordService {
} }
/**
* 统计每种分组有多少。默认只有单人组,双人组,多人组。
* 如果特别配置了,可能需要三人组和四人组
*
* @param add 增量
* @param result 统计结果
* @param records 每组里的记录
*/
public void calGroup(int add, CustomerGroupResult result, List<DPersonRecord> records) { public void calGroup(int add, CustomerGroupResult result, List<DPersonRecord> records) {
if (CollectionUtils.isEmpty(records)) { if (CollectionUtils.isEmpty(records)) {
return; return;
...@@ -803,23 +828,37 @@ public class PersonRecordServiceImpl implements PersonRecordService { ...@@ -803,23 +828,37 @@ public class PersonRecordServiceImpl implements PersonRecordService {
result.setSingleGroup(result.getSingleGroup() + add); result.setSingleGroup(result.getSingleGroup() + add);
} else if (records.size() == 2) { } else if (records.size() == 2) {
result.setDoubleGroup(result.getDoubleGroup() + add); result.setDoubleGroup(result.getDoubleGroup() + add);
if (records.stream().anyMatch(df -> df.getAge() <= 18 || df.getAge() >= 50)) { if (isFamily(records)) {
result.setDoubleFamilyGroup(result.getDoubleFamilyGroup() + add); result.setDoubleFamilyGroup(result.getDoubleFamilyGroup() + add);
} else if (records.stream().map(DPersonRecord::getGender).collect(Collectors.toSet()).size() == 2) { } else if (isLover(records)) {
result.setDoubleLoverGroup(result.getDoubleLoverGroup() + add); result.setDoubleLoverGroup(result.getDoubleLoverGroup() + add);
} else { } else {
result.setDoublePartnerGroup(result.getDoublePartnerGroup() + add); result.setDoublePartnerGroup(result.getDoublePartnerGroup() + add);
} }
} else { } else {
result.setMultipleGroup(result.getMultipleGroup() + add); int size = records.size();
if (size == 3 && result.getPersonGroupMaxNum() >= 3) {
if (records.stream().anyMatch(df -> df.getAge() <= 18 || df.getAge() >= 50)) { result.setThreeGroup(result.getThreeGroup() + add);
result.setMultipleFamilyGroup(result.getMultipleFamilyGroup() + add); } else if (size == 4 && result.getPersonGroupMaxNum() >= 4) {
result.setFourGroup(result.getFourGroup() + add);
} else { } else {
result.setMultiplePartnerGroup(result.getMultiplePartnerGroup() + add); result.setMultipleGroup(result.getMultipleGroup() + add);
if (isFamily(records)) {
result.setMultipleFamilyGroup(result.getMultipleFamilyGroup() + add);
} else {
result.setMultiplePartnerGroup(result.getMultiplePartnerGroup() + add);
}
} }
} }
} }
private boolean isFamily(List<DPersonRecord> records) {
return records.stream().anyMatch(df -> df.getAge() <= 18 || df.getAge() >= 50);
}
private boolean isLover(List<DPersonRecord> records) {
return records.stream().map(DPersonRecord::getGender).collect(Collectors.toSet()).size() == 2;
}
} }
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!