Files
pj_service_cloud/pjcloud-upms/pjcloud-upms-biz/src/main/resources/mapper/SysUserFaceMapper.xml
T
2026-09-10 15:34:34 +08:00

226 lines
8.7 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.admin.mapper.SysUserFaceMapper">
<sql id="selectA">
select a.id,
a.auto_code,
a.user_id,
a.process_id,
a.process_status,
a.face_img,
a.quality_score,
a.quality_status,
a.quality_checked_at,
a.quality_error_code,
a.quality_device_id,
a.create_by,
a.create_time,
a.update_by,
a.update_time,
a.del_flag,
a.tenant_id,
a.process_time,
</sql>
<sql id="whereA">
a.del_flag = '0'
<if test="pa.userId != null">
and a.user_id = #{pa.userId}
</if>
<if test="pa.userIds != null and pa.userIds.size() != 0">
and a.user_id in
<foreach collection="pa.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="pa.processStatus != null">
and a.process_status = #{pa.processStatus}
</if>
<!-- 固定 0.60 阈值与终端默认在库阈值、PC 列表质量标签的分类规则保持一致。 -->
<if test="pa.qualityCategory != null and pa.qualityCategory != ''">
<choose>
<when test="pa.qualityCategory == 'qualified'">
and a.quality_status = 'detected' and a.quality_score &gt;= 0.60
</when>
<when test="pa.qualityCategory == 'low'">
and a.quality_status = 'detected' and a.quality_score &lt; 0.60
</when>
<when test="pa.qualityCategory == 'failed'">
and a.quality_status = 'failed'
</when>
<when test="pa.qualityCategory == 'pending'">
and a.quality_status is null
</when>
</choose>
</if>
<if test="pa.isProcessIdNotNull != null and pa.isProcessIdNotNull == true ">
and a.process_id is not null
</if>
</sql>
<select id="scopePageList" resultType="com.bsd.pjcloud.admin.api.vo.SysUserFaceVo">
<include refid="selectA"/>
u.name as username,
u.avatar as userAvatar,
u.phone as userMobile,
u.dept_id as userDeptId,
u.dept_id as deptId,
d.name as deptName
from sys_user_face a
inner join sys_user u on u.user_id = a.user_id and u.del_flag = '0'
inner join sys_dept d on d.dept_id = u.dept_id and d.del_flag = '0'
<where>
<include refid="whereA"/>
<if test="pa.username != null and pa.username != '' ">
and u.name LIKE CONCAT('%', #{pa.username}, '%')
</if>
<if test="pa.phone != null and pa.phone != '' ">
and u.phone LIKE CONCAT('%', #{pa.phone}, '%')
</if>
</where>
order by a.create_time desc , a.id desc
</select>
<select id="selectAllCount" resultType="java.lang.Long">
select count(0) from sys_user_face
</select>
<select id="groupConcatFaces" resultType="com.bsd.pjcloud.admin.api.vo.SysUserFaceVo">
select a.user_id, group_concat(a.face_img) as faceImgs
from sys_user_face a
<where>
del_flag = '0'
<if test="pa.userIds != null and pa.userIds.size() != 0">
and user_id in
<foreach collection="pa.userIds" index="index" item="v" open="(" separator="," close=")">
#{v}
</foreach>
</if>
</where>
GROUP BY a.user_id
</select>
<select id="allPageJoin" resultType="com.bsd.pjcloud.admin.api.vo.SysUserFaceVo">
<include refid="selectA"/>
u.name as username,
u.phone as userMobile,
u.avatar as userAvatar,
d.dept_id as deptId,
d.name as deptName
from sys_user_face a
inner join sys_user u on u.user_id = a.user_id and u.del_flag = '0'
inner join sys_dept d on d.dept_id = u.dept_id and d.del_flag = '0'
<where>
<if test="pa.userId != null">
and a.user_id = #{pa.userId}
</if>
<if test="pa.userIds != null and pa.userIds.size() != 0">
and a.user_id in
<foreach collection="pa.userIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
<if test="pa.processStatus != null">
and a.process_status = #{pa.processStatus}
</if>
<if test="pa.isProcessIdNotNull != null and pa.isProcessIdNotNull == true ">
and a.process_id is not null
</if>
<if test="pa.deptIds != null and pa.deptIds.size() != 0">
<choose>
<when test="pa.isInclude != null and pa.isInclude == true">
and d.dept_id IN
</when>
<when test="pa.isInclude != null and pa.isInclude == false">
and d.dept_id NOT IN
</when>
<otherwise>
and d.dept_id IN
</otherwise>
</choose>
<foreach collection="pa.deptIds" item="v" open="(" close=")" separator=",">
#{v}
</foreach>
</if>
</where>
order by a.create_time desc, a.id desc
</select>
<select id="countSyncDuplicateAutoCodes" resultType="java.lang.Long">
select count(0)
from (
select cast(a.auto_code as unsigned) as numeric_auto_code
from sys_user_face a
inner join sys_user u on u.user_id = a.user_id and u.del_flag = '0'
inner join sys_dept d on d.dept_id = u.dept_id and d.del_flag = '0'
where a.del_flag = '0'
and a.process_status = #{processStatus}
and a.auto_code regexp '^[0-9]+$'
and d.dept_id in
<foreach collection="deptIds" item="deptId" open="(" close=")" separator=",">
#{deptId}
</foreach>
group by cast(a.auto_code as unsigned)
having count(0) &gt; 1
) duplicate_codes
</select>
<select id="selectSyncSnapshotMaxId" resultType="java.lang.Long">
select coalesce(max(a.id), 0)
from sys_user_face a
inner join sys_user u on u.user_id = a.user_id and u.del_flag = '0'
where a.del_flag = '0'
and a.process_status = #{processStatus}
and u.dept_id in
<foreach collection="deptIds" item="deptId" open="(" close=")" separator=",">
#{deptId}
</foreach>
<if test="userId != null">
and a.user_id = #{userId}
</if>
</select>
<select id="listSyncSnapshotRecords" resultType="com.bsd.pjcloud.admin.api.vo.SysUserFaceSyncRecordVo">
select a.id,
a.auto_code as sampleId,
a.user_id as userId,
u.name as username,
d.dept_id as deptId,
d.name as deptName,
a.face_img as faceImg,
coalesce(a.update_time, a.create_time) as sourceUpdatedAt
from sys_user_face a
inner join sys_user u on u.user_id = a.user_id and u.del_flag = '0'
inner join sys_dept d on d.dept_id = u.dept_id and d.del_flag = '0'
where a.del_flag = '0'
and a.process_status = #{processStatus}
and a.id &gt; #{afterId}
and a.id &lt;= #{snapshotMaxId}
and d.dept_id in
<foreach collection="deptIds" item="deptId" open="(" close=")" separator=",">
#{deptId}
</foreach>
<if test="userId != null">
and a.user_id = #{userId}
</if>
order by a.id asc
limit #{fetchSize}
</select>
<select id="listStatusCounts" resultType="com.bsd.pjcloud.admin.api.vo.SysUserFaceStatusCountVo">
select user_id as userId,
sum(case when process_status = #{availableStatus} then 1 else 0 end) as availableCount,
sum(case when process_status = #{pendingStatus} then 1 else 0 end) as pendingCount
from sys_user_face
where del_flag = '0'
and user_id in
<foreach collection="userIds" item="userId" open="(" separator="," close=")">
#{userId}
</foreach>
and process_status in (#{availableStatus}, #{pendingStatus})
group by user_id
</select>
</mapper>