Bonus-Cloud-AI-V2/bonus-modules/bonus-ai/src/main/resources/mapper/AnnotationTaskMapper.xml

359 lines
19 KiB
XML
Raw Normal View History

2024-11-21 10:18:13 +08:00
<?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.bonus.ai.mapper.AnnotationTaskMapper">
2024-11-24 11:03:01 +08:00
<!-- ResultMap映射 -->
<resultMap id="BaseResultMap" type="com.bonus.ai.domain.dataset.AnnotationTaskEntity">
<id column="task_id" property="taskId" jdbcType="BIGINT"/>
<result column="dataset_id" property="datasetId" jdbcType="BIGINT"/>
<result column="task_name" property="taskName" jdbcType="VARCHAR"/>
<result column="task_uuid" property="taskUuid" jdbcType="VARCHAR"/>
<result column="description" property="taskDesc" jdbcType="VARCHAR"/>
<result column="annotation_scene" property="annotateScene" jdbcType="CHAR"/>
<result column="annotation_type" property="annotateType" jdbcType="CHAR"/>
<result column="labels" property="labels" jdbcType="VARCHAR"/>
2024-11-25 18:10:02 +08:00
<result column="label_studio_project_id" property="labelStudioProjectId" jdbcType="BIGINT"/>
2024-11-25 15:08:17 +08:00
<result column="isStartTeam" property="isStartTeam" jdbcType="CHAR"/>
2024-11-24 11:03:01 +08:00
<result column="annotation_status" property="annotateTaskStatus" jdbcType="CHAR"/>
<result column="del_flag" property="delFlag" jdbcType="CHAR"/>
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
2024-11-21 10:18:13 +08:00
2024-11-25 15:08:17 +08:00
2024-11-24 11:03:01 +08:00
<sql id="selectTaskDetailVo">
select distinct t.task_id, t.task_uuid, t.task_name, t.description, t.annotation_scene, t.annotation_type,
FROM ai_annotation_task t
left join ai_annotation_task_annotator_map a on t.task_id = a.task_id
</sql>
2024-11-24 15:45:25 +08:00
<update id="deleteTaskById">
UPDATE ai_annotation_task
SET del_flag = '1'
WHERE task_id = #{taskId}
</update>
<update id="deleteAnnotator">
UPDATE ai_annotation_task_annotator_map
SET del_flag = '1'
WHERE task_id = #{taskId}
</update>
2024-11-21 10:18:13 +08:00
2024-11-24 11:03:01 +08:00
<!-- TODO 根据标注人id查询所有标注文件列表-->
2024-11-21 10:18:13 +08:00
2024-11-24 11:03:01 +08:00
<!-- TODO 根据审核人id查询所有需要审核文件列表-->
2024-11-21 10:18:13 +08:00
2024-11-25 15:08:17 +08:00
<!-- 根据条件查询标注任务列表 -->
<select id="selectAnnotationTaskList" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" resultMap="BaseResultMap">
SELECT task_id , dataset_id , task_name , task_uuid, description, annotation_scene, annotation_type ,
2024-11-24 11:03:01 +08:00
labels, is_annotation_team AS isStartTeam, annotation_status,
2024-11-25 18:10:02 +08:00
label_studio_project_id, del_flag, create_by , create_time,
2024-11-24 11:03:01 +08:00
update_by , update_time
2024-11-21 10:18:13 +08:00
FROM ai_annotation_task
WHERE del_flag = '0'
2024-11-25 15:08:17 +08:00
<if test="taskId != null">
AND task_id = #{taskId}
</if>
2024-11-21 10:18:13 +08:00
<if test="datasetId != null">
AND dataset_id = #{datasetId}
</if>
<if test="taskName != null and taskName != ''">
AND task_name LIKE CONCAT('%', #{taskName}, '%')
</if>
<if test="annotateScene != null and annotateScene != ''">
AND annotation_scene = #{annotateScene}
</if>
<if test="annotateType != null and annotateType != ''">
AND annotation_type = #{annotateType}
</if>
<if test="annotateTaskStatus != null and annotateTaskStatus != ''">
AND annotation_status = #{annotateTaskStatus}
</if>
</select>
2024-11-26 14:45:07 +08:00
<!-- 我参与的任务 和我创建的 或所有的-->
<select id="selectMyAnnotationTaskList" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" resultMap="BaseResultMap">
SELECT ap.task_id , at.dataset_id , at.task_name , at.task_uuid, at.description, at.annotation_scene, at.annotation_type ,
2024-11-26 14:45:07 +08:00
at.labels, at.is_annotation_team AS isStartTeam, at.annotation_status,
at.label_studio_project_id, at.del_flag, at.create_by , at.create_time,
at.update_by , at.update_time, ad.dataset_name AS datasetName, su.user_name AS ownerName,
SUM(CASE WHEN ap.annotation_status = '0' THEN 1 ELSE 0 END) AS status0Count,
SUM(CASE WHEN ap.annotation_status = '1' THEN 1 ELSE 0 END) AS status1Count,
SUM(CASE WHEN ap.annotation_status = '2' THEN 1 ELSE 0 END) AS status2Count,
SUM(CASE WHEN ap.annotation_status = '3' THEN 1 ELSE 0 END) AS status3Count,
2024-11-27 13:35:02 +08:00
COUNT(*) AS totalCount,
2024-11-27 16:25:18 +08:00
atv.version_name as lastVersionName,
DATE_FORMAT(at.start_time, '%Y-%m-%d %H:%i:%s') AS startTime,
DATE_FORMAT(at.end_time, '%Y-%m-%d %H:%i:%s') AS endTime
2024-11-26 14:45:07 +08:00
FROM ai_annotation_task at
2024-11-27 16:25:18 +08:00
LEFT JOIN ai_annotation_task_annotator_map ap on at.task_id = ap.task_id
LEFT JOIN ai_dataset ad on ad.dataset_id = at.dataset_id
LEFT JOIN sys_user su on su.user_id = at.create_by
2024-11-27 13:35:02 +08:00
LEFT JOIN (
SELECT task_id, dataset_id, version_name
FROM ai_dataset_version
WHERE (task_id, dataset_id, create_time) IN (
SELECT task_id, dataset_id, MAX(create_time)
FROM ai_dataset_version
GROUP BY task_id, dataset_id
)
) atv ON atv.task_id = at.task_id AND atv.dataset_id = at.dataset_id
WHERE at.del_flag = '0' and ap.annotation_status IN ('0', '1', '2','3')
2024-11-27 09:45:03 +08:00
<if test="taskName != null and taskName != ''">
AND at.task_name LIKE CONCAT('%', #{taskName}, '%')
</if>
2024-11-27 16:25:18 +08:00
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND at.start_time >= STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s')
AND STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s') >= at.end_time
</if>
2024-11-26 14:45:07 +08:00
<choose>
2024-11-27 08:17:22 +08:00
<when test="annotatorId != null and annotatorId != '' and reviewerId != null and reviewerId != '' and createBy != null and createBy != ''">
2024-11-26 14:45:07 +08:00
AND (ap.annotator_id = #{annotatorId} or ap.reviewer_id = #{reviewerId} or at.create_by = #{createBy})
</when>
2024-11-27 08:17:22 +08:00
<when test="annotatorId != null and annotatorId != '' and reviewerId != null and reviewerId != '' ">
2024-11-26 14:45:07 +08:00
AND (ap.annotator_id = #{annotatorId} or ap.reviewer_id = #{reviewerId})
</when>
2024-11-27 08:17:22 +08:00
<when test="reviewerId != null and reviewerId != '' and createBy != null and createBy != ''">
2024-11-26 14:45:07 +08:00
AND (ap.reviewer_id = #{reviewerId} or at.create_by = #{createBy})
</when>
2024-11-27 08:17:22 +08:00
<when test="annotatorId != null and annotatorId != '' and createBy != null and createBy != ''">
2024-11-26 14:45:07 +08:00
AND (ap.annotatorId = #{annotatorId} or at.create_by = #{createBy})
</when>
2024-11-27 08:17:22 +08:00
<when test="createBy != null and createBy != ''">
2024-11-26 14:45:07 +08:00
AND (at.create_by = #{createBy} or at.create_by = #{createBy})
</when>
</choose>
GROUP BY ap.task_id
2024-11-26 14:45:07 +08:00
</select>
2024-11-24 11:03:01 +08:00
<!-- 插入标注任务 -->
2024-11-26 12:44:17 +08:00
<insert id="insertAnnotationTask" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" useGeneratedKeys="true" keyProperty="taskId">
2024-11-24 11:03:01 +08:00
INSERT INTO ai_annotation_task
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="datasetId != null">dataset_id,</if>
<if test="taskName != null">task_name,</if>
<if test="taskUuid != null">task_uuid,</if>
<if test="taskDesc != null">description,</if>
<if test="annotateScene != null">annotation_scene,</if>
<if test="annotateType != null">annotation_type,</if>
<if test="labels != null">labels,</if>
<if test="isStartTeam != null">is_annotation_team,</if>
<if test="annotateTaskStatus != null">annotation_status,</if>
2024-11-25 18:10:02 +08:00
<if test="labelStudioProjectId != null">label_studio_project_id,</if>
2024-11-24 11:03:01 +08:00
<if test="delFlag != null">del_flag,</if>
create_time,
<if test="createBy != null">create_by,</if>
2024-11-24 11:03:01 +08:00
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="startTime != null and startTime !=''">start_time,</if>
<if test="endTime != null and endTime !=''">end_time,</if>
2024-11-24 11:03:01 +08:00
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="datasetId != null">#{datasetId},</if>
<if test="taskName != null">#{taskName},</if>
<if test="taskUuid != null">#{taskUuid},</if>
<if test="taskDesc != null">#{taskDesc},</if>
<if test="annotateScene != null">#{annotateScene},</if>
<if test="annotateType != null">#{annotateType},</if>
<if test="labels != null">#{labels},</if>
<if test="isStartTeam != null">#{isStartTeam},</if>
<if test="annotateTaskStatus != null">#{annotateTaskStatus},</if>
2024-11-25 18:10:02 +08:00
<if test="labelStudioProjectId != null">#{labelStudioProjectId},</if>
2024-11-24 11:03:01 +08:00
<if test="delFlag != null">#{delFlag},</if>
sysdate(),
<if test="createBy != null">#{createBy},</if>
2024-11-24 11:03:01 +08:00
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="startTime != null and startTime !=''"> STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s'),</if>
<if test="endTime != null and endTime !=''"> STR_TO_DATE(#{endTime}, '%Y-%m-%d %H:%i:%s'),</if>
2024-11-24 11:03:01 +08:00
</trim>
</insert>
2024-11-27 16:25:18 +08:00
<!-- 插入标注任务,文件和标注人和审核人关联 关系表-->
2024-11-26 12:44:17 +08:00
<insert id="insertAnnotTaskannotator" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
2024-11-24 15:45:25 +08:00
INSERT INTO ai_annotation_task_annotator_map
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null">task_id ,</if>
<if test="fileId != null">file_id ,</if>
<if test="fileUrl != null">file_url ,</if>
<if test="labelStudioTaskId != null">label_studio_task_id,</if>
<if test="annotatorId != null">annotator_id ,</if>
<if test="reviewerId != null">reviewer_id ,</if>
<if test="description != null and description != ''">description ,</if>
<if test="annotationStatus != null">annotation_status ,</if>
<if test="auditFailedReason != null">audit_failed_reason ,</if>
<if test="annotationResult != null">annotation_result ,</if>
<if test="annotationResource != null">annotation_resource, </if>
<if test="annotationTime != null">annotation_time ,</if>
<if test="reviewTime != null">review_time ,</if>
<if test="delFlag != null">del_flag,</if>
create_time,
<if test="createBy != null">create_by,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
2024-11-24 15:45:25 +08:00
</trim>
2024-11-26 12:44:17 +08:00
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null">#{taskId},</if>
<if test="fileId != null">#{fileId},</if>
<if test="fileUrl != null">#{fileUrl},</if>
<if test="labelStudioTaskId != null">#{labelStudioTaskId},</if>
<if test="annotatorId != null">#{annotatorId},</if>
<if test="reviewerId != null">#{reviewerId},</if>
<if test="description != null and description != ''">#{description} ,</if>
<if test="annotationStatus != null">#{annotationStatus},</if>
<if test="auditFailedReason != null">#{auditFailedReason} ,</if>
<if test="annotationResult != null">#{annotationResult},</if>
<if test="annotationResource != null">#{annotationResource},</if>
<if test="annotationTime != null">#{annotationTime} ,</if>
<if test="reviewTime != null">#{reviewTime} ,</if>
<if test="delFlag != null">#{delFlag},</if>
sysdate(),
<if test="createBy != null">#{createBy},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
2024-11-24 15:45:25 +08:00
</trim>
</insert>
2024-11-24 11:03:01 +08:00
2024-11-27 16:25:18 +08:00
<!-- 根据任务ID更新标注任务详情 -->
2024-11-24 11:03:01 +08:00
<update id="updateAnnotationTaskById" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity">
UPDATE ai_annotation_task
<set>
<if test="datasetId != null">dataset_id = #{datasetId},</if>
<if test="taskName != null">task_name = #{taskName},</if>
<if test="taskUuid != null">task_uuid = #{taskUuid},</if>
<if test="taskDesc != null">description = #{taskDesc},</if>
<if test="annotateScene != null">annotation_scene = #{annotateScene},</if>
<if test="annotateType != null">annotation_type = #{annotateType},</if>
<if test="labels != null">labels = #{labels},</if>
<if test="isStartTeam != null">is_annotation_team = #{isStartTeam},</if>
<if test="annotateTaskStatus != null">annotation_status = #{annotateTaskStatus},</if>
2024-11-25 18:10:02 +08:00
<if test="labelStudioProjectId != null">label_studio_project_id = #{labelStudioProjectId},</if>
2024-11-24 11:03:01 +08:00
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="startTime != null and startTime !=''"> start_time = STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s'),</if>
<if test="endTime != null and endTime !=''"> end_time= STR_TO_DATE(#{startTime}, '%Y-%m-%d %H:%i:%s'),</if>
2024-11-24 11:03:01 +08:00
</set>
WHERE task_id = #{taskId}
</update>
2024-11-27 16:25:18 +08:00
<!-- 根据taskid 返回由某人标注 或审核的的文件列表和文件详情-->
2024-11-28 11:33:58 +08:00
<select id="getTaskBasicFile" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" resultType="com.bonus.ai.domain.DataSetBasicFileEntity">
2024-11-26 16:29:55 +08:00
SELECT
distinct adfm.file_id AS fileId,
abf.file_name AS fileName,
abf.file_size AS fileSize,
2024-11-27 16:25:18 +08:00
abf.file_url AS fileUrl,
2024-11-26 16:29:55 +08:00
adfm.create_time AS createTime,
2024-11-29 18:12:35 +08:00
atap.annotation_status AS fileAnnotationStatus,
2024-11-29 18:21:55 +08:00
atap.annotation_result AS annotationResult,
aat.task_id
2024-11-26 16:29:55 +08:00
FROM ai_basic_file abf
LEFT JOIN ai_dataset_file_map adfm ON abf.file_id = adfm.file_id
LEFT JOIN ai_annotation_task aat ON aat.dataset_id= adfm.dataset_id
2024-11-29 18:21:55 +08:00
LEFT JOIN ai_annotation_task_annotator_map atap on atap.task_id = aat.task_id and abf.file_id = atap.file_id
2024-11-26 16:29:55 +08:00
where abf.del_flag = '0' and aat.del_flag = '0' and aat.task_id = #{taskId}
<if test="fileName != null and fileName != ''">
AND abf.file_name like concat('%', #{fileName}, '%')
</if>
<if test="annotatorId != null and annotatorId != ''">
AND atap.annotator_id = #{annotatorId}
</if>
<if test="reviewerId != null and reviewerId != ''">
AND atap.reviewer_id = #{reviewerId}
</if>
2024-12-01 15:43:59 +08:00
<if test="fileAnnotationStatus != null and fileAnnotationStatus != '' ">
2024-11-28 11:33:58 +08:00
AND atap.annotation_status = #{fileAnnotationStatus}
2024-11-26 16:29:55 +08:00
</if>
</select>
2024-11-27 16:25:18 +08:00
<!-- 根据taskid 和fileid 返回审核驳回的原因-->
2024-11-28 11:33:58 +08:00
<select id="getAuditFailReasonByFileId" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" resultType="String">
SELECT
atap.audit_failed_reason
FROM ai_basic_file abf
LEFT JOIN ai_dataset_file_map adfm ON abf.file_id = adfm.file_id
LEFT JOIN ai_annotation_task aat ON aat.dataset_id= adfm.dataset_id
LEFT JOIN ai_annotation_task_annotator_map atap on atap.task_id = aat.task_id
where abf.del_flag = '0' and aat.del_flag = '0' and aat.task_id = #{taskId} and adfm.file_id = #{fileId}
</select>
2024-11-24 11:03:01 +08:00
2024-11-29 17:52:54 +08:00
2024-11-27 16:25:18 +08:00
<!-- 根据任务id和 文件id 更新标注内容和状态 -->
<update id="updateAnnotationInfo" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
UPDATE ai_annotation_task_annotator_map
<set>
2024-11-29 17:28:45 +08:00
<choose>
<when test="annotationResult != null and annotationResult != ''">
2024-11-27 16:25:18 +08:00
annotation_result = #{annotationResult},
annotation_time = sysdate(),
2024-11-29 17:52:54 +08:00
annotation_status = '1',
2024-11-29 17:28:45 +08:00
</when>
2024-12-01 18:13:18 +08:00
<when test="auditFailedReason != null and auditFailedReason != ''">
2024-11-27 16:25:18 +08:00
audit_failed_reason = #{auditFailedReason},
review_time = sysdate(),
annotation_status = '3',
2024-11-29 17:28:45 +08:00
</when>
<when test="annotationStatus != null and annotationStatus == '2'">
2024-11-29 17:52:54 +08:00
annotation_status = #{annotationStatus},
2024-11-27 16:25:18 +08:00
review_time = sysdate(),
2024-11-29 17:28:45 +08:00
</when>
</choose>
2024-11-27 12:19:34 +08:00
<if test="annotationResource != null and annotationResource != ''">annotation_resource = #{annotationResource},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
</set>
2024-11-27 16:25:18 +08:00
WHERE task_id = #{taskId} and file_id = #{fileId}
</update>
2024-11-27 12:19:34 +08:00
<select id="countStatusByTaskId" resultType="com.bonus.ai.domain.dataset.AnnotationFileStatusCount">
SELECT annotation_status, COUNT(*) AS record_count
FROM ai_annotation_task_annotator_map
WHERE task_id = #{taskId}
AND annotation_status IN ('0', '1', '2')
GROUP BY annotation_status
</select>
2024-11-28 10:49:50 +08:00
<select id="getMyNoAnnotationTask" parameterType="Long" resultType="com.bonus.ai.domain.dataset.AnnotationTaskEntity">
2024-11-29 18:26:11 +08:00
SELECT distinct at.task_id AS taskId, at.task_name AS taskName, at.labels as labels
2024-11-28 10:49:50 +08:00
FROM ai_annotation_task at
LEFT JOIN ai_annotation_task_annotator_map ap on at.task_id = ap.task_id
WHERE at.del_flag = '0' and ap.annotation_status IN ('0') and ap.annotator_id = #{annotatorId}
</select>
<select id="getMyNoAuditTask" resultType="com.bonus.ai.domain.dataset.AnnotationTaskEntity">
SELECT distinct at.task_id AS taskId , at.task_name AS taskName
FROM ai_annotation_task at
LEFT JOIN ai_annotation_task_annotator_map ap on at.task_id = ap.task_id
WHERE at.del_flag = '0' and ap.annotation_status IN ('1') and ap.reviewer_id = #{reviewerId}
</select>
2024-11-29 17:52:54 +08:00
<select id="selectAnnotationDetailByTaskFile"
resultType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
SELECT
atam.task_id AS taskId,
atam.file_id AS fileId,
atam.annotation_result AS annotationResult,
atam.annotation_resource AS annotationResource,
atam.annotation_status AS annotationStatus,
atam.annotation_time AS annotationTime,
atam.annotator_id AS annotatorId,
atam.reviewer_id AS reviewerId,
atam.review_time AS reviewTime,
atam.audit_failed_reasonAS auditFailedReason
from ai_annotation_task_annotator_map atam
where atam.del_flag = '0'
<if test="taskId != null and taskId != 0">
AND atam.task_id = #{taskId}
</if>
<if test="fileId != null and fileId != ''">
AND atam.file_id = #{fileId}
</if>
</select>
2024-11-21 10:18:13 +08:00
</mapper>