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

346 lines
17 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,
COUNT(*) AS totalCount
2024-11-26 14:45:07 +08:00
FROM ai_annotation_task at
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
WHERE at.del_flag = '0' and ap.annotation_status IN ('0', '1', '2','3')
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>
<!-- <select id="getDatasetList" parameterType="com.bonus.ai.domain.dataset.DataSetEntity" resultMap="DatasetResult">-->
<!-- <include refid="selectDatasetVo"/>-->
<!-- <where>-->
<!-- and ad.del_flag = '0'-->
<!-- <if test="datasetName != null and datasetName != ''">-->
<!-- AND ad.dataset_name like concat('%', #{datasetName}, '%')-->
<!-- </if>-->
<!-- <if test="dataType != null and dataType != ''">-->
<!-- AND ad.data_type = #{dataType}-->
<!-- </if>-->
<!-- <if test="annotationStatus != null and annotationStatus != ''">-->
<!-- AND ad.annotation_status = #{annotationStatus}-->
<!-- </if>-->
<!-- <if test="isPublic != null and isPublic != ''">-->
<!-- AND ad.is_public = #{isPublic}-->
<!-- </if>-->
<!-- <if test="createBy != null and createBy != ''">-->
<!-- AND ad.create_by = #{createBy}-->
<!-- </if>-->
<!-- </where>-->
<!-- order by create_time desc-->
<!-- </select>-->
2024-11-25 15:08:17 +08:00
<!-- <select id="selectAnnotationTaskListUUID" resultType="com.bonus.ai.domain.dataset.AnnotationTaskEntity">-->
2024-11-25 18:10:02 +08:00
<!-- SELECT label_studio_project_id, task_id, task_uuid FROM ai_annotation_task where del_flag = 0-->
2024-11-25 15:08:17 +08:00
<!-- </select>-->
2024-11-21 10:18:13 +08:00
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>
<if test="createBy != null">create_by,</if>
create_time,
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</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>
<if test="createBy != null">#{createBy},</if>
sysdate(),
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
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=",">
2024-11-26 12:44:17 +08:00
<if test="taskId != null">
task_id ,
2024-11-25 18:10:02 +08:00
</if>
2024-11-26 12:44:17 +08:00
<if test="fileId != null">
file_id ,
2024-11-25 18:10:02 +08:00
</if>
<if test="fileUrl != null">
2024-11-26 12:44:17 +08:00
file_url ,
2024-11-25 18:10:02 +08:00
</if>
<if test="labelStudioTaskId != null">
2024-11-26 12:44:17 +08:00
label_studio_task_id,
2024-11-25 18:10:02 +08:00
</if>
2024-11-24 15:45:25 +08:00
<if test="annotatorId != null">
2024-11-26 12:44:17 +08:00
annotator_id ,
2024-11-24 15:45:25 +08:00
</if>
<if test="reviewerId != null">
2024-11-26 12:44:17 +08:00
reviewer_id ,
2024-11-24 15:45:25 +08:00
</if>
<if test="description != null and description != ''">
2024-11-26 12:44:17 +08:00
description ,
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationStatus != null">
2024-11-26 12:44:17 +08:00
annotation_status ,
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationResult != null">
2024-11-26 12:44:17 +08:00
annotation_result ,
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationResource != null">
2024-11-26 12:44:17 +08:00
annotation_resource ,
2024-11-24 15:45:25 +08:00
</if>
</trim>
2024-11-26 12:44:17 +08:00
VALUES
<!-- <foreach collection="list" index="index" item="entity" separator=",">-->
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="taskId != null">
#{taskId},
</if>
2024-11-25 18:10:02 +08:00
<if test="fileId != null">
2024-11-26 12:44:17 +08:00
#{fileId},
2024-11-25 18:10:02 +08:00
</if>
<if test="fileUrl != null">
2024-11-26 12:44:17 +08:00
#{fileUrl},
2024-11-25 18:10:02 +08:00
</if>
<if test="labelStudioTaskId != null">
2024-11-26 12:44:17 +08:00
#{labelStudioTaskId},
2024-11-25 18:10:02 +08:00
</if>
2024-11-24 15:45:25 +08:00
<if test="annotatorId != null">
2024-11-26 12:44:17 +08:00
#{annotatorId},
2024-11-24 15:45:25 +08:00
</if>
<if test="reviewerId != null">
2024-11-26 12:44:17 +08:00
#{reviewerId},
2024-11-24 15:45:25 +08:00
</if>
2024-11-26 12:44:17 +08:00
<if test="description != null and entity.description != ''">
#{description} ,
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationStatus != null">
2024-11-26 12:44:17 +08:00
#{annotationStatus},
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationResult != null">
2024-11-26 12:44:17 +08:00
#{annotationResult},
2024-11-24 15:45:25 +08:00
</if>
<if test="annotationResource != null">
2024-11-26 12:44:17 +08:00
#{annotationResource},
2024-11-24 15:45:25 +08:00
</if>
</trim>
2024-11-26 12:44:17 +08:00
<!-- </foreach>-->
2024-11-24 15:45:25 +08:00
</insert>
2024-11-24 11:03:01 +08:00
<!-- 根据任务ID更新标注任务 -->
<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>
update_time = sysdate(),
</set>
WHERE task_id = #{taskId}
</update>
<!-- 根据任务ID删除标注任务 (逻辑删除) -->
<update id="deleteAnnotationTaskById" parameterType="long">
UPDATE ai_annotation_task
SET del_flag = '1'
WHERE task_id = #{taskId}
</update>
2024-11-26 16:29:55 +08:00
<!-- 根据taskid 返回由某人标注 或审核的的文件列表-->
<select id="getTaskBasicFile" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" resultType="com.bonus.ai.domain.DataSetBasicFileEntity">
SELECT
distinct adfm.file_id AS fileId,
abf.file_name AS fileName,
abf.file_size AS fileSize,
adfm.create_time AS createTime,
atap.annotation_status AS annotationStatus
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}
<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>
<if test="fileAnnotationStatus != null and fileAnnotationStatus != '5'">
AND atap.annotation_status = #{fileAnnotationStatus}
</if>
</select>
<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
<!-- 根据任务ID更新标注任务 -->
<update id="updateAnnotationInfo" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
UPDATE ai_annotation_task_annotator_map
<set>
<if test="annotation_result != null">annotation_result = #{annotationResult},</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>
<if test="labelStudioProjectId != null">label_studio_project_id = #{labelStudioProjectId},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
</set>
WHERE task_id = #{taskId}
</update>
<!-- resultMap="statusCountResultMap"-->
<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-21 10:18:13 +08:00
</mapper>