FaceRecognitionDao.java 3.36 KB
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;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 *
 * @author: zhuhai
 * Date: 2023-12-21
 * Time: 16:54
 */
@Repository
public class FaceRecognitionDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    @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 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("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 = :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;";
        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));
    }

}