Commit a9a5bf21 by 毛树良

[chg]d_person_record表按照店内停留时间和是否看车进行过滤:处理停留时长、停留时长分布

1 parent aa1cc9e5
package com.viontech.keliu.entity;
import lombok.Data;
import java.util.Date;
@Data
public class DFaceResidence {
private Long id;
/**
* 商场id
*/
private Long mallId;
/**
* 集团id
*/
private Long accountId;
/**
* 数据日期(yyyy-MM-dd)
*/
private Date countdate;
/**
* 对应人脸抓拍unid
*/
private String personUnid;
/**
* 进店时间
*/
private Date arriveTime;
/**
* 离店时间
*/
private Date leaveTime;
/**
* 滞留时间(毫秒)
*/
private Long residenceTime;
/**
* 年龄(按进店抓拍的算)
*/
private Integer age;
/**
* 性别(按进店抓拍的算)
*/
private Integer gender;
}
package com.viontech.keliu.entity;
import lombok.Data;
import java.util.Date;
@Data
public class DMallDayResidenceCountData {
private Long id;
private Long mallId;
private Long accountId;
/**
* 总滞留人次
*/
private Integer personNum;
/**
* 总滞留时间
*/
private Long totalResidenceTime;
private Date countDate;
}
package com.viontech.keliu.service.impl;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.viontech.keliu.dao.BGateDao;
......@@ -10,15 +11,7 @@ import com.viontech.keliu.dao.DPersonReceptionDao;
import com.viontech.keliu.dao.DPersonRecordDao;
import com.viontech.keliu.dao.DPersonTrackDetailDao;
import com.viontech.keliu.dao.FaceRecognitionDao;
import com.viontech.keliu.entity.CustomerGroupResult;
import com.viontech.keliu.entity.DMallDayFaceRecognitionSta;
import com.viontech.keliu.entity.DMallHourFaceRecognitionSta;
import com.viontech.keliu.entity.DPersonBatch;
import com.viontech.keliu.entity.DPersonReception;
import com.viontech.keliu.entity.DPersonRecord;
import com.viontech.keliu.entity.DPersonTrackDetail;
import com.viontech.keliu.entity.Person;
import com.viontech.keliu.entity.PersonInOutDetail;
import com.viontech.keliu.entity.*;
import com.viontech.keliu.service.PersonRecordService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
......@@ -225,6 +218,10 @@ public class PersonRecordServiceImpl implements PersonRecordService {
//修改统计数据小时
updateFaceRecognitionStaHour(mallId, countDate, personRecordList);
//修改停留时长
updateMallDayResidenceCountData(mallId, countDate, personRecordList);
//修改停留时长分布
updateFaceResidence(mallId, countDate, personRecordList);
}
......@@ -640,6 +637,50 @@ public class PersonRecordServiceImpl implements PersonRecordService {
}
private void updateMallDayResidenceCountData(Long mallId, Date countDate, List<DPersonRecord> personRecords) {
// 过滤出匹配上进出的人员记录
List<DPersonRecord> matchInOutPersonRecords = personRecords.stream().filter(d -> d.getArriveTime() != null && d.getLeaveTime() != null).collect(Collectors.toList());
Long totalResidenceTime = 0L;
for (DPersonRecord personRecord : matchInOutPersonRecords) {
long residenceTime = DateUtil.between(personRecord.getArriveTime(), personRecord.getLeaveTime(), DateUnit.SECOND);
totalResidenceTime = totalResidenceTime + residenceTime;
}
DMallDayResidenceCountData updateSta = new DMallDayResidenceCountData();
updateSta.setMallId(mallId);
updateSta.setCountDate(countDate);
updateSta.setPersonNum(matchInOutPersonRecords.size());
updateSta.setTotalResidenceTime(totalResidenceTime);
// 更新停留时长
String updateSql = "update d_mall_day_residence_count_data set person_num = ?,total_residence_time = ? where mall_id = ? and count_date = ?;";
jdbcTemplate.update(updateSql, updateSta.getPersonNum(), updateSta.getTotalResidenceTime(), mallId, countDate);
}
private void updateFaceResidence(Long mallId, Date countDate, List<DPersonRecord> personRecords) {
// 过滤出匹配上进出的人员记录
List<DPersonRecord> matchInOutPersonRecords = personRecords.stream().filter(d -> d.getArriveTime() != null && d.getLeaveTime() != null).collect(Collectors.toList());
// 查询已有数据
String sql = "select id,mall_id,countdate,person_unid from d_face_residence where mall_id = ? and countdate = ?;";
List<DFaceResidence> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(DFaceResidence.class), mallId, countDate);
if (CollectionUtils.isEmpty(list)) {
return;
}
// 过滤掉的人员记录id
List<DFaceResidence> deleteFaceResidences = new ArrayList<>();
for (DFaceResidence dFaceResidence : list) {
if (!matchInOutPersonRecords.contains(dFaceResidence.getPersonUnid())) {
deleteFaceResidences.add(dFaceResidence);
}
}
// 删除过滤掉人员的数据
if (CollectionUtils.isNotEmpty(deleteFaceResidences)) {
String deleteSql = "delete from d_face_residence where mall_id = :mallId and countdate = :countdate and id = :id;";
SqlParameterSource[] updateSources = SqlParameterSourceUtils.createBatch(deleteFaceResidences.toArray());
namedParameterJdbcTemplate.batchUpdate(deleteSql, updateSources);
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!