<?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.ruoyi.system.mapper.task.ext.TkRoundSubtaskExtMapper">
    <select id="selectByParam" resultType="com.ruoyi.system.domain.task.TkRoundSubtask">
        SELECT
        tk_round_subtask.id as id, task_id as taskId, obj_id as objId, grid_id as gridId, obj_name objName, code, tk_round_subtask.time as time, tk_round_subtask.`status` as status, tk_round_subtask.`result` as result, remark, create_by as createBy, create_time as createTime,
        update_by as updateBy, update_name as updateName, update_time as updateTime, content, file_path as filePath,
        tk_round_task.origin as origin,
        tk_round_task.`name` as taskName
        FROM tk_round_subtask
        INNER JOIN tk_round_task ON tk_round_subtask.task_id = tk_round_task.id
        WHERE tk_round_subtask.obj_id = #{objId}
        <if test='startTime!=null'>
            and tk_round_subtask.time &gt;= #{startTime}
        </if>
        <if test='endTime != null '>
            and tk_round_subtask.time &lt;= #{endTime}
        </if>
        <if test='status != null '>
            <if test='status != 3 '>
                and tk_round_subtask.status = #{status}
            </if>
            <if test='status == 3 '>
                and tk_round_subtask.status != 0
            </if>
        </if>
        <if test='origin != null '>
            and tk_round_task.origin = #{origin}
        </if>
        ORDER by tk_round_subtask.time desc
    </select>

    <select id="countByDxlx" resultType="java.lang.Integer">
        SELECT
        Count(*)
        FROM
        tk_round_subtask
        INNER JOIN tk_round_task ON tk_round_subtask.task_id = tk_round_task.id
        WHERE
            tk_round_subtask.dxlx = #{dxlx}
    </select>

    <select id="getSubTaskNumByDXLX" resultType="com.ruoyi.system.domain.task.TkRoundSubtask">
        SELECT
            tk_round_subtask.dxlx AS `dxlx`,
            count( tk_round_subtask.`status`) AS total,
            count( CASE WHEN tk_round_subtask.`status` = 2 THEN 1 END ) AS unusual
        FROM
            tk_round_subtask
        GROUP BY `dxlx` ASC
    </select>
</mapper>