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

346 lines
17 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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">
<!-- 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"/>
<result column="label_studio_project_id" property="labelStudioProjectId" jdbcType="BIGINT"/>
<result column="isStartTeam" property="isStartTeam" jdbcType="CHAR"/>
<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>
<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>
<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>
<!-- TODO 根据标注人id查询所有标注文件列表-->
<!-- TODO 根据审核人id查询所有需要审核文件列表-->
<!-- 根据条件查询标注任务列表 -->
<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 ,
labels, is_annotation_team AS isStartTeam, annotation_status,
label_studio_project_id, del_flag, create_by , create_time,
update_by , update_time
FROM ai_annotation_task
WHERE del_flag = '0'
<if test="taskId != null">
AND task_id = #{taskId}
</if>
<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>
<!-- 我参与的任务 和我创建的 或所有的-->
<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 ,
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
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')
<choose>
<when test="annotatorId != null and annotatorId != '' and reviewerId != null and reviewerId != '' and createBy != null and createBy != ''">
AND (ap.annotator_id = #{annotatorId} or ap.reviewer_id = #{reviewerId} or at.create_by = #{createBy})
</when>
<when test="annotatorId != null and annotatorId != '' and reviewerId != null and reviewerId != '' ">
AND (ap.annotator_id = #{annotatorId} or ap.reviewer_id = #{reviewerId})
</when>
<when test="reviewerId != null and reviewerId != '' and createBy != null and createBy != ''">
AND (ap.reviewer_id = #{reviewerId} or at.create_by = #{createBy})
</when>
<when test="annotatorId != null and annotatorId != '' and createBy != null and createBy != ''">
AND (ap.annotatorId = #{annotatorId} or at.create_by = #{createBy})
</when>
<when test="createBy != null and createBy != ''">
AND (at.create_by = #{createBy} or at.create_by = #{createBy})
</when>
</choose>
GROUP BY ap.task_id
</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>-->
<!-- <select id="selectAnnotationTaskListUUID" resultType="com.bonus.ai.domain.dataset.AnnotationTaskEntity">-->
<!-- SELECT label_studio_project_id, task_id, task_uuid FROM ai_annotation_task where del_flag = 0-->
<!-- </select>-->
<!-- 插入标注任务 -->
<insert id="insertAnnotationTask" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskEntity" useGeneratedKeys="true" keyProperty="taskId">
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>
<if test="labelStudioProjectId != null">label_studio_project_id,</if>
<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>
<if test="labelStudioProjectId != null">#{labelStudioProjectId},</if>
<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>
<insert id="insertAnnotTaskannotator" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
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="annotationResult != null">
annotation_result ,
</if>
<if test="annotationResource != null">
annotation_resource ,
</if>
</trim>
VALUES
<!-- <foreach collection="list" index="index" item="entity" separator=",">-->
<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 entity.description != ''">
#{description} ,
</if>
<if test="annotationStatus != null">
#{annotationStatus},
</if>
<if test="annotationResult != null">
#{annotationResult},
</if>
<if test="annotationResource != null">
#{annotationResource},
</if>
</trim>
<!-- </foreach>-->
</insert>
<!-- 根据任务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>
<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>
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>
<!-- 根据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>
<!-- 根据任务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>
</mapper>