<?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.mosty.common.task.mapper.SysTaskMapper">

    <resultMap id="BaseResultMap" type="com.mosty.common.task.entity.SysTask">
        <id property="id" column="id" jdbcType="BIGINT"/>
        <result property="rwlx" column="rwlx" jdbcType="INTEGER"/>
        <result property="rwjjcd" column="rwjjcd" jdbcType="INTEGER"/>
        <result property="rwmc" column="rwmc" jdbcType="VARCHAR"/>
        <result property="rwnr" column="rwnr" jdbcType="VARCHAR"/>
        <result property="rwzdsj" column="rwzdsj" jdbcType="TIMESTAMP"/>
        <result property="rwwcsj" column="rwwcsj" jdbcType="TIMESTAMP"/>
        <result property="rwyqwcsj" column="rwyqwcsj" jdbcType="TIMESTAMP"/>
        <result property="rwcjrsfzh" column="rwcjrsfzh" jdbcType="VARCHAR"/>
        <result property="rwcjrxm" column="rwcjrxm" jdbcType="VARCHAR"/>
        <result property="rwcjrdw" column="rwcjrdw" jdbcType="VARCHAR"/>
        <result property="rwcjrdwId" column="rwcjrdw_id" jdbcType="BIGINT"/>
        <result property="rwcjrdh" column="rwcjrdh" jdbcType="VARCHAR"/>
        <result property="rwcjrgz" column="rwcjrgz" jdbcType="INTEGER"/>
        <result property="rwzxzt" column="rwzxzt" jdbcType="INTEGER"/>
        <result property="rwlyxt" column="rwlyxt" jdbcType="VARCHAR"/>
        <result property="rwUrl" column="rw_url" jdbcType="VARCHAR"/>
        <result property="bz" column="bz" jdbcType="VARCHAR"/>
        <result property="xtZxbz" column="xt_zxbz" jdbcType="INTEGER"/>
        <result property="xtZxyy" column="xt_zxyy" jdbcType="VARCHAR"/>
        <result property="xtCjsj" column="xt_cjsj" jdbcType="TIMESTAMP"/>
        <result property="xtLrsj" column="xt_lrsj" jdbcType="TIMESTAMP"/>
        <result property="xtLrrxm" column="xt_lrrxm" jdbcType="VARCHAR"/>
        <result property="xtLrrid" column="xt_lrrid" jdbcType="BIGINT"/>
        <result property="xtLrrbm" column="xt_lrrbm" jdbcType="VARCHAR"/>
        <result property="xtLrrbmid" column="xt_lrrbmid" jdbcType="VARCHAR"/>
        <result property="xtLrip" column="xt_lrip" jdbcType="VARCHAR"/>
        <result property="xtZhxgsj" column="xt_zhxgsj" jdbcType="TIMESTAMP"/>
        <result property="xtZhxgrxm" column="xt_zhxgrxm" jdbcType="VARCHAR"/>
        <result property="xtZhxgid" column="xt_zhxgid" jdbcType="BIGINT"/>
        <result property="xtZhxgrbm" column="xt_zhxgrbm" jdbcType="VARCHAR"/>
        <result property="xtZhxgrbmid" column="xt_zhxgrbmid" jdbcType="BIGINT"/>
        <result property="xtZhxgrip" column="xt_zhxgrip" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,rwlx,rwjjcd,
        rwmc,rwnr,rwzdsj,
        rwwcsj,rwyqwcsj,rwcjrsfzh,
        rwcjrxm,rwcjrdw,rwcjrdw_id,
        rwcjrdh,rwcjrgz,rwzxzt,
        rwlyxt,rw_url,bz,
        xt_zxbz,xt_zxyy,xt_cjsj,
        xt_lrsj,xt_lrrxm,xt_lrrid,
        xt_lrrbm,xt_lrrbmid,xt_lrip,
        xt_zhxgsj,xt_zhxgrxm,xt_zhxgid,
        xt_zhxgrbm,xt_zhxgrbmid,xt_zhxgrip
    </sql>
    <select id="countByUser" resultType="java.lang.Long">
        select
        count(1)
        FROM
        sys_task st
        LEFT JOIN
        sys_task_item sti ON sti.rw_id = st.id
        WHERE
        sti.rwjsrsfzh=#{param.idCardNo}
        AND st.zxlx =1
        <if test="param.startTime !=null and param.startTime!=''">
            and
            <![CDATA[st.rwzdsj >= #{param.startTime}]]>
        </if>
        <if test="param.endTime !=null and param.endTime!=''">
            and
            <![CDATA[st.rwzdsj <= #{param.endTime}]]>
        </if>
        <if test="param.source!=null and param.source!=''">
            AND st.rwlyxt =#{param.source}
        </if>
        <if test="param.taskType!=null and param.taskType!=''">
            AND st.rwlx =#{param.taskType}
        </if>
        <if test="param.taskName!=null and param.taskName!=''">
            AND st.rwmc like concat('%', #{param.taskName}, '%')
        </if>
        <if test="param.taskStatus!=null and param.taskStatus!=''">
            AND sti.rwzt = #{param.taskStatus}
        </if>
    </select>

    <select id="countByDept" resultType="java.lang.Long">
        select
        count(1)
        FROM
        sys_task st
        LEFT JOIN
        sys_task_item sti ON sti.rw_id = st.id
        WHERE
        sti.rwjsrbm_id=#{param.deptId}
        AND st.zxlx =2
        <if test="param.startTime !=null and param.startTime!=''">
            and
            <![CDATA[st.rwzdsj >= #{param.startTime}]]>
        </if>
        <if test="param.endTime !=null and param.endTime!=''">
            and
            <![CDATA[st.rwzdsj <= #{param.endTime}]]>
        </if>
        <if test="param.source!=null and param.source!=''">
            AND st.rwlyxt =#{param.source}
        </if>
        <if test="param.taskType!=null and param.taskType!=''">
            AND st.rwlx =#{param.taskType}
        </if>
        <if test="param.taskName!=null and param.taskName!=''">
            AND st.rwmc like concat('%', #{param.taskName}, '%')
        </if>
        <if test="param.taskStatus!=null and param.taskStatus!=''">
            AND sti.rwzt = #{param.taskStatus}
        </if>

    </select>
    <!--分页查询-->
    <select id="findByList" resultType="com.mosty.common.task.entity.vo.SysTaskItemVO">
        select
        sti.id,
        st.rwlx ,
        st.rw_url AS rwUrl,
        st.rwmc,
        st.rwnr,
        st.rwyqwcsj,
        st.rwlyxt,
        st.rwly_id,
        sti.rwjsrsfzh AS idCardNo
        FROM
        sys_task st
        LEFT JOIN
        sys_task_item sti ON sti.rw_id = st.id
        WHERE
        sti.rwjsrsfzh=#{param.idCardNo}
        AND st.zxlx =1
        <if test="param.startTime !=null and param.startTime!=''">
            and
            <![CDATA[st.rwzdsj >= #{param.startTime}]]>
        </if>
        <if test="param.endTime !=null and param.endTime!=''">
            and
            <![CDATA[st.rwzdsj <= #{param.endTime}]]>
        </if>
        <if test="param.source!=null and param.source!=''">
            AND st.rwlyxt =#{param.source}
        </if>
        <if test="param.taskType!=null and param.taskType!=''">
            AND st.rwlx =#{param.taskType}
        </if>
        <if test="param.taskName!=null and param.taskName!=''">
            AND st.rwmc like concat('%', #{param.taskName}, '%')
        </if>
        <if test="param.taskStatus!=null and param.taskStatus!=''">
            AND sti.rwzt = #{param.taskStatus}
        </if>
        UNION
        select
        sti.id,
        st.rwlx ,
        st.rwly_id,
        st.rw_url AS rwUrl,
        st.rwmc,
        st.rwnr,
        st.rwyqwcsj,
        st.rwlyxt,
        sti.rwjsrsfzh AS idCardNo
        FROM
        sys_task st
        LEFT JOIN
        sys_task_item sti ON sti.rw_id = st.id
        WHERE
        sti.rwjsrbm_id=#{param.deptId}
        AND st.zxlx =2
        <if test="param.startTime !=null and param.startTime!=''">
            and
            <![CDATA[st.rwzdsj >= #{param.startTime}]]>
        </if>
        <if test="param.endTime !=null and param.endTime!=''">
            and
            <![CDATA[st.rwzdsj <= #{param.endTime}]]>
        </if>
        <if test="param.source!=null and param.source!=''">
            AND st.rwlyxt =#{param.source}
        </if>
        <if test="param.taskType!=null and param.taskType!=''">
            AND st.rwlx =#{param.taskType}
        </if>
        <if test="param.taskName!=null and param.taskName!=''">
            AND st.rwmc like concat('%', #{param.taskName}, '%')
        </if>
        <if test="param.taskStatus!=null and param.taskStatus!=''">
            AND sti.rwzt = #{param.taskStatus}
        </if>
        ORDER BY id DESC
    </select>
</mapper>
