<?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="cn.cslg.report.mapper.TaskMapper">
    <select id="queryTasks" resultType="cn.cslg.report.common.model.vo.TaskReportVO">
        select a.* ,b.TYPE as reportType,b.SIGN_PATENT_NO as signPatentNo, b.NAME as reportName from TASK a left join
        REPORT b on
        a.REPORT_ID=b.ID
        <where>
            <if test="param.type !=null">
                and a.TYPE =#{param.type}
            </if>
            <if test="param.taskStatuses !=null and param.taskStatuses.size>0">
                and a.TASK_STATUS in
                <foreach collection="param.taskStatuses" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.ids !=null and param.ids.size()!=0 ">
                and a.CREATE_ID in
                <foreach collection="param.ids" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.handleIds !=null and param.handleIds.size()!=0 ">
                and a.HANDLE_PERSON_ID in
                <foreach collection="param.handleIds" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="param.taskName !=null and param.taskName !=''">
                and a.TASK_NAME like concat('%', #{param.taskName}, '%')

            </if>

            <if test="param.roleInTask !=null and param.roleInTask == 0">
                and a.CREATE_ID=#{param.loginId}

            </if>
            <if test="param.roleInTask !=null and param.roleInTask == 1">
                and a.HANDLE_PERSON_ID=#{param.loginId}
            </if>
        </where>
        order by a.id desc
    </select>
</mapper>