mapper.java:
/**
* @Description: 根据摄像机Id查询出入记录
* @Param:
* name 姓名
* monitorId 布控ID
* starttime 开始时间
* endtime 结束时间
* begin 页码
* pageSize 查询数量
* @return:
* @throws Exception
* @author: hw
* @date: 2019/6/11 14:28
*/
List<OutInRecords> queryOutInRecords(@Param("name") String name,@Param("monitorId") String monitorId,
@Param("starttime") String starttime, @Param("endtime") String endtime,
@Param("begin") Integer begin, @Param("pageSize") Integer pageSize);
mapper.xml
<select id="queryOutInRecords" resultMap="OutInRecords" parameterType="map">
select
a_oir.similarity,a_oir.`status`,a_oir.`timestamp`,a_ci.in_out,a_mi.monitor_name,a_si.person_type,a_si.address,a_si.`name`
from aiapp_out_in_record a_oir
LEFT JOIN aiapp_camera_info a_ci ON a_ci.camera_id = a_oir.camera_id
LEFT JOIN aiapp_staff_info a_si ON a_oir.faceimage_id = a_si.faceimage_id
<if test="monitorId != null ">
LEFT JOIN aiapp_monitor_info a_mi ON a_mi.monitor_id = ${monitorId}
</if>
<if test="monitorId == null ">
LEFT JOIN aiapp_monitor_info a_mi ON a_mi.monitor_id = (SELECT a_cm.monitor_id FROM aiapp_camera_monitor a_cm WHERE a_cm.camera_id = a_oir.camera_id)
</if>
<trim prefix="where" prefixOverrides="and">
<if test="monitorId != null ">
AND a_oir.camera_id in (SELECT a_cm.camera_id FROM aiapp_camera_monitor a_cm WHERE a_cm.monitor_id = ${monitorId})
</if>
<if test="name != null ">
AND a_oir.faceimage_id = (SELECT a_si.faceimage_id FROM aiapp_staff_info a_si WHERE a_si.`name` = '${name}')
</if>
<if test="starttime != null and endtime != null">
AND a_oir.`timestamp` BETWEEN ${starttime} and ${endtime}
</if>
<if test="starttime != null and endtime == null">
AND a_oir.`timestamp` > ${starttime}
</if>
<if test="starttime == null and endtime != null">
AND ${starttime} > a_oir.`timestamp`
</if>
</trim>
order by a_oir.`timestamp` desc
<if test="begin != null and pageSize != null">
limit ${begin}, ${pageSize}
</if>
</select>
来源:oschina
链接:https://my.oschina.net/u/4399693/blog/3504054