Commit 6f4b0fab by 朱海

[chg]d_person_record记录生成按照营业时间过滤

1 parent f9f593c3
package com.viontech.keliu.dao;
import com.viontech.keliu.entity.DateTimeParam;
import com.viontech.keliu.entity.Person;
import com.viontech.keliu.service.DateTimeParamService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.boot.autoconfigure.batch.BatchProperties;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
......@@ -34,29 +36,42 @@ public class FaceRecognitionDao {
@Resource
private BGateDao bGateDao;
@Resource
private DateTimeParamService dateTimeParamService;
public List<Person> queryGateFaceRecognitionList(Long mallId, Date countDate) {
List<Long> gateIds = bGateDao.getMallInsideGateIds(mallId);
if (CollectionUtils.isEmpty(gateIds)) {
return null;
}
DateTimeParam dateTimeParam = dateTimeParamService.getDateTimeParam(mallId, countDate);
String sql = "select account_id,mall_id,gate_id,person_unid,direction,countdate as countDate," +
"counttime as countTime from d_face_recognition " +
"where mall_id = :mallId and countdate = :countDate and gate_id in(:gateIds) " +
"where mall_id = :mallId and countdate between :startDate and :endDate and counttime >= :startTime and counttime < :endTime and gate_id in(:gateIds) " +
"and person_type = 0 and direction in(-1,1,6) order by person_unid asc,counttime asc;";
Map<String, Object> queryMap = new HashMap<>();
queryMap.put("mallId", mallId);
queryMap.put("countDate", countDate);
queryMap.put("startDate", dateTimeParam.getStartDate());
queryMap.put("endDate", dateTimeParam.getEndDate());
queryMap.put("startTime", dateTimeParam.getStartDateTime());
queryMap.put("endTime", dateTimeParam.getEndDateTime());
queryMap.put("gateIds", gateIds);
return namedParameterJdbcTemplate.query(sql, queryMap, new BeanPropertyRowMapper<>(Person.class));
}
public List<Person> queryFaceRecognitionList(Long mallId, Date countDate) {
DateTimeParam dateTimeParam = dateTimeParamService.getDateTimeParam(mallId, countDate);
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 = ? and countdate = ? " +
"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) order by person_unid asc, counttime asc;";
return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Person.class), mallId, countDate);
Map<String, Object> queryMap = new HashMap<>();
queryMap.put("mallId", mallId);
queryMap.put("startDate", dateTimeParam.getStartDate());
queryMap.put("endDate", dateTimeParam.getEndDate());
queryMap.put("startTime", dateTimeParam.getStartDateTime());
queryMap.put("endTime", dateTimeParam.getEndDateTime());
return namedParameterJdbcTemplate.query(sql, queryMap, new BeanPropertyRowMapper<>(Person.class));
}
}
\ No newline at end of file
package com.viontech.keliu.entity;
import lombok.Data;
import java.util.Date;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-03-23
* Time: 10:50
*/
@Data
public class DateTimeParam {
private Date startDate;
private Date endDate;
private Date startDateTime;
private Date endDateTime;
}
\ No newline at end of file
package com.viontech.keliu.entity;
import lombok.Data;
import java.util.Date;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2024-01-16
* Time: 10:50
*/
@Data
public class MallBusinessTime {
private Long accountId;
private Long mallId;
/**
* 营业开始时间
*/
private Date startTime;
/**
* 营业结束时间
*/
private Date endTime;
private Date countDate;
/**
* 配置类型,0:普通周几的配置,为0时week字段不能为空; 1:指定日期的配置,为1 时custom_date字段不能为空
*/
private Integer type;
}
\ No newline at end of file
package com.viontech.keliu.service;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.viontech.keliu.entity.DateTimeParam;
import com.viontech.keliu.entity.MallBusinessTime;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* Created with IntelliJ IDEA.
*
* @author: zhuhai
* Date: 2023-03-23
* Time: 10:51
*/
@Service
@Slf4j
public class DateTimeParamService {
/**
* Calendar 中 1 是周日,2 是周一,3 是周二,4 是周三,5 是周四,6 是周五,7 是周六
* 下标 0 占位用
*/
public static final int[] WEEKS = {0, 7, 1, 2, 3, 4, 5, 6};
@Resource
private JdbcTemplate jdbcTemplate;
public MallBusinessTime getMallOpenTimeByDate(Long mallId, Date date) {
// 查出指定的日期和周几的营业时间配置
String sql = "select mall_id,account_id,start_time,end_time,type from b_mall_business_hours where mall_id = ? and (custom_date = ? or week = ?)";
List<MallBusinessTime> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(MallBusinessTime.class), mallId, DateUtil.beginOfDay(date), WEEKS[DateUtil.dayOfWeek(date)]);
if (CollectionUtils.isEmpty(list)) {
log.error("商场营业时间配置缺失:{}", mallId);
return null;
}
MallBusinessTime customB = list.stream().filter(b -> b.getType() == 1).findFirst().orElse(null);
if (customB != null) {
return getRealBusinessTime(customB, date);
}
MallBusinessTime weekB = list.stream().filter(b -> b.getType() == 0).findFirst().orElse(null);
if (weekB != null) {
return getRealBusinessTime(weekB, date);
}
log.error("商场营业时间配置不完整:{}", mallId);
return null;
}
/**
* 组装countDate对应的营业时间范围
* @param mallBusinessTime
* @param countDate
* @return
*/
private MallBusinessTime getRealBusinessTime(MallBusinessTime mallBusinessTime, Date countDate) {
Date startTime = mallBusinessTime.getStartTime();
Date endTime = mallBusinessTime.getEndTime();
String formatDate = DateUtil.formatDate(countDate);
String beginDateTimeFormat = formatDate + " " + DateUtil.formatTime(startTime);
String endDateTimeFormat = formatDate + " " + DateUtil.formatTime(endTime);
DateTime beginDateTime = DateUtil.parseDateTime(beginDateTimeFormat);
DateTime endDateTime = DateUtil.parseDateTime(endDateTimeFormat);
//如果是跨天的
if (startTime.getTime() >= endTime.getTime()) {
endDateTime = DateUtil.offsetDay(endDateTime, 1);
}
mallBusinessTime.setStartTime(beginDateTime);
mallBusinessTime.setEndTime(endDateTime);
mallBusinessTime.setCountDate(countDate);
return mallBusinessTime;
}
/**
* 根据营业时间获取需要查询的日期范围
* @param mallId
* @param countDate
* @return
*/
public DateTimeParam getDateTimeParam(Long mallId, Date countDate) {
MallBusinessTime mallBusinessTime = getMallOpenTimeByDate(mallId, countDate);
Date shopBeginDate = DateUtil.beginOfDay(countDate);
Date shopEndDate = DateUtil.endOfDay(countDate);
if (mallBusinessTime != null) {
shopBeginDate = mallBusinessTime.getStartTime();
shopEndDate = mallBusinessTime.getEndTime();
}
Date startDate = DateUtil.beginOfDay(countDate);
Date endDate = startDate;
long days = DateUtil.betweenDay(shopBeginDate, shopEndDate, true);
//跨天
if (days > 0 && !shopEndDate.equals(DateUtil.beginOfDay(shopEndDate))) {
endDate = DateUtil.offsetDay(endDate, 1);
}
DateTimeParam dateTimeParam = new DateTimeParam();
dateTimeParam.setStartDate(startDate);
dateTimeParam.setEndDate(endDate);
dateTimeParam.setStartDateTime(shopBeginDate);
dateTimeParam.setEndDateTime(shopEndDate);
log.info("mallId:{},获取countDate:{} 的时间范围:{}", mallId, countDate, dateTimeParam);
return dateTimeParam;
}
}
\ No newline at end of file
......@@ -182,7 +182,6 @@ public class PersonRecordServiceImpl implements PersonRecordService {
return personList;
}*/
List<DPersonBatch> personBatchList = dPersonBatchDao.getPersonBatchList(mallId, countDate);
if (CollectionUtils.isNotEmpty(personBatchList)) {
Map<String, String> batchMap = personBatchList.stream().collect(Collectors.toMap(v -> v.getPersonUnid(), DPersonBatch::getBatchId, (v1, v2) -> v1));
for (PersonInOutDetail personInOutDetail : personList) {
String key = personInOutDetail.getPersonUnid();
......@@ -195,7 +194,7 @@ public class PersonRecordServiceImpl implements PersonRecordService {
resultList.add(personInOutDetail);
}
}
return resultList;
/*if (CollectionUtils.isNotEmpty(personBatchMallIds) && personBatchMallIds.contains(mallId)) {
//先判断是否从全天分析获取了批次信息,如果有,使用全天分析的批次结果
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!