Commit aa1f4418 by zhuht

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

1 parent 44b39962
......@@ -25,9 +25,13 @@ public class CustomerGroupResult {
private long multipleFamilyGroup; // 多人家庭组
private long multiplePartnerGroup; // 多人伙伴组
private int personGroupMaxNum = 2;
private long threeGroup; // 三人组
private long fourGroup; // 四人组
public long getGroupNum() {
return singleGroup + doubleGroup + multipleGroup;
return singleGroup + doubleGroup + threeGroup + fourGroup + multipleGroup;
}
}
\ No newline at end of file
......@@ -41,6 +41,8 @@ public class DMallDayFaceRecognitionSta {
private Long singleGroupNum;
private Long doubleGroupNum;
private Long threeGroupNum;
private Long fourGroupNum;
private Long multipleGroupNum;
......
......@@ -41,6 +41,8 @@ public class DMallHourFaceRecognitionSta {
private Long singleGroupNum;
private Long doubleGroupNum;
private Long threeGroupNum;
private Long fourGroupNum;
private Long multipleGroupNum;
......@@ -57,7 +59,4 @@ public class DMallHourFaceRecognitionSta {
private Long staffCount;
}
\ No newline at end of file
......@@ -90,6 +90,8 @@ public class PersonRecordServiceImpl implements PersonRecordService {
Long excludePersonTime = getExcludePersonTime(mallId);
Integer filterAttention = getFilterAttention(mallId);
Integer effectVisitorsConfig = getEffectVisitors(mallId);
Integer personGroupMaxNum = getPersonGroupMaxNum(mallId);
boolean needFilter = filterAttention == 1;
//出入口gateId
List<Long> gateIds = bGateDao.getMallInOutGateIds(mallId);
......@@ -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) {
//修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList);
......@@ -529,8 +531,18 @@ public class PersonRecordServiceImpl implements PersonRecordService {
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));
//顾客总人数
long customerCount = personRecordMap.keySet().size();
......@@ -583,6 +595,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setFemaleStage(femaleStageStr);
CustomerGroupResult customerGroupResult = new CustomerGroupResult();
customerGroupResult.setPersonGroupMaxNum(personGroupMaxNum);
List<DPersonRecord> visitorsGroupRecordList = personRecordMap.values().stream().toList();
Set<String> nonEffectVisitorsUnids = nonEffectVisitorsUnids(visitorsGroupRecordList, effectVisitorsConfig);
List<DPersonRecord> effectVisitorsRecord = nonEffectVisitorsUnids.isEmpty() ? visitorsGroupRecordList
......@@ -594,6 +607,8 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setGroupNum(customerGroupResult.getGroupNum());
updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup());
updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup());
updateSta.setThreeGroupNum(customerGroupResult.getThreeGroup());
updateSta.setFourGroupNum(customerGroupResult.getFourGroup());
updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup());
updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup());
updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup());
......@@ -603,16 +618,15 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setAvgReceptionSecond(avgReceptionSecond);
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 = ?;";
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);
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.getThreeGroupNum(), updateSta.getFourGroupNum(), updateSta.getMultipleGroupNum(), updateSta.getFamilyGroupNum(), updateSta.getLoverGroupNum(), updateSta.getPartnerGroupNum(), updateSta.getReceptionCustomerCount(), updateSta.getAvgReceptionSecond(), updateSta.getReceptionGroupCount(), mallId, countDate);
} 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 = ?;";
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);
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.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 {
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);
......@@ -702,6 +716,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setFemaleStage(femaleStageStr);
CustomerGroupResult customerGroupResult = new CustomerGroupResult();
customerGroupResult.setPersonGroupMaxNum(personGroupMaxNum);
if (!CollectionUtils.isEmpty(dPersonRecords)) {
Map<String, List<DPersonRecord>> groupMap = nonEffectVisitorsUnids.isEmpty() ?
......@@ -714,6 +729,8 @@ public class PersonRecordServiceImpl implements PersonRecordService {
updateSta.setGroupNum(customerGroupResult.getGroupNum());
updateSta.setSingleGroupNum(customerGroupResult.getSingleGroup());
updateSta.setDoubleGroupNum(customerGroupResult.getDoubleGroup());
updateSta.setThreeGroupNum(customerGroupResult.getThreeGroup());
updateSta.setFourGroupNum(customerGroupResult.getFourGroup());
updateSta.setMultipleGroupNum(customerGroupResult.getMultipleGroup());
updateSta.setFamilyGroupNum(customerGroupResult.getDoubleFamilyGroup() + customerGroupResult.getMultipleFamilyGroup());
updateSta.setLoverGroupNum(customerGroupResult.getDoubleLoverGroup());
......@@ -723,11 +740,11 @@ public class PersonRecordServiceImpl implements PersonRecordService {
if (!CollectionUtils.isEmpty(updateList)) {
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());
namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources);
} 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());
namedParameterJdbcTemplate.batchUpdate(updateSql, updateSources);
}
......@@ -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) {
if (CollectionUtils.isEmpty(records)) {
return;
......@@ -803,23 +828,37 @@ public class PersonRecordServiceImpl implements PersonRecordService {
result.setSingleGroup(result.getSingleGroup() + add);
} else if (records.size() == 2) {
result.setDoubleGroup(result.getDoubleGroup() + add);
if (records.stream().anyMatch(df -> df.getAge() <= 18 || df.getAge() >= 50)) {
if (isFamily(records)) {
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);
} else {
result.setDoublePartnerGroup(result.getDoublePartnerGroup() + add);
}
} else {
int size = records.size();
if (size == 3 && result.getPersonGroupMaxNum() >= 3) {
result.setThreeGroup(result.getThreeGroup() + add);
} else if (size == 4 && result.getPersonGroupMaxNum() >= 4) {
result.setFourGroup(result.getFourGroup() + add);
} else {
result.setMultipleGroup(result.getMultipleGroup() + add);
if (records.stream().anyMatch(df -> df.getAge() <= 18 || df.getAge() >= 50)) {
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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!