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

331 lines
18 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,
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
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
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')
<if test="taskName != null and taskName != ''">
AND at.task_name LIKE CONCAT('%', #{taskName}, '%')
</if>
<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>
<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>
<!-- 插入标注任务 -->
<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>
create_time,
<if test="createBy != null">create_by,</if>
<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>
</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>
sysdate(),
<if test="createBy != null">#{createBy},</if>
<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>
</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="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>
</trim>
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>
</trim>
</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>
<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>
</set>
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,
abf.file_url AS fileUrl,
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>
<!-- 根据taskid 和fileid 返回审核驳回的原因-->
<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和 文件id 更新标注内容和状态 -->
<update id="updateAnnotationInfo" parameterType="com.bonus.ai.domain.dataset.AnnotationTaskAnnotatorEntity">
UPDATE ai_annotation_task_annotator_map
<set>
<if test="annotationResult != null and annotationResult != ''">
annotation_result = #{annotationResult},
annotation_time = sysdate(),
annotateTaskStatus = '1',
</if>
<if test="auditFailedReason != null and auditFailedReason == ''">
audit_failed_reason = #{auditFailedReason},
review_time = sysdate(),
annotation_status = '3',
</if>
<if test="annotateTaskStatus != null and annotateTaskStatus == '2'">
annotateTaskStatus = #{annotateTaskStatus},
review_time = sysdate(),
</if>
<if test="annotationResource != null and annotationResource != ''">annotation_resource = #{annotationResource},</if>
<if test="labelStudioProjectId != null">label_studio_project_id = #{labelStudioProjectId},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
</set>
WHERE task_id = #{taskId} and file_id = #{fileId}
</update>
<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>
<select id="getMyNoAnnotationTask" parameterType="Long" 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 ('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>
</mapper>