<?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="org.springblade.modules.rwxffkb.mapper.RwxffkbMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="rwxffkbResultMap" type="org.springblade.modules.rwxffkb.entity.RwxffkbEntity">
        <result column="id" property="id"/>
        <result column="rwly" property="rwly"/>
        <result column="rwmc" property="rwmc"/>
        <result column="rwid" property="rwid"/>
        <result column="rwzt" property="rwzt"/>
        <result column="sssq" property="sssq"/>
        <result column="rwjssj" property="rwjssj"/>
        <result column="rwxfsj" property="rwxfsj"/>
        <result column="rwlx" property="rwlx"/>
        <result column="create_user" property="createUser"/>
        <result column="create_dept" property="createDept"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="status" property="status"/>
        <result column="is_deleted" property="isDeleted"/>
    </resultMap>


    <select id="selectRwxffkbPage" resultType="org.springblade.modules.rwxffkb.vo.RwxffkbVO">
        SELECT
            rw.*,
            md.id as mdid,
            md.*
        FROM
            rwxffkb rw
        LEFT JOIN mdjf_dj_new md ON md.id = rw.rwid
        LEFT JOIN blade_dept sq ON sq.id = rw.sssq
        WHERE
            rw.is_deleted = 0
        AND rw.rwzt = #{params.rwzt}
        <if test="null != params.rwzt and '未签收' == params.rwzt">
        AND (#{params.deptId} LIKE '%' || sq.id || '%')
        </if>
        <if test="null != params.rwzt and '已签收' == params.rwzt">
        AND rw.user_id = #{params.userId}
        </if>
        order by rwjssj desc
    </select>


    <select id="exportRwxffkb" resultType="org.springblade.modules.rwxffkb.excel.RwxffkbExcel">
        SELECT * FROM rwxffkb ${ew.customSqlSegment}
    </select>

    <select id="getRwNum" resultType="int">
        SELECT
            COUNT( * ) as rwNum
        FROM
            rwxffkb rw
        LEFT JOIN blade_dept sq ON sq.ID = rw.sssq
        WHERE
            (rw.user_id = #{params.userId} OR (#{params.deptId} LIKE '%' || sq.id || '%'))
        AND rw.rwzt = '未签收'
    </select>

    <update id="updateByIdJl">
        update rwxffkb set rwzt = #{rwzt}, rwjssj = #{rwjssj}, user_id = #{userId}, update_user = #{userId}, update_time = now() where id = #{id}
    </update>
</mapper>
