<?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.mdjfry.mapper.MdjfRyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="mdjfryResultMap" type="org.springblade.modules.mdjfry.entity.MdjfRyEntity">
        <result column="id" property="id"/>
        <result column="jf_id" property="jfId"/>
        <result column="xm" property="xm"/>
        <result column="xb" property="xb"/>
        <result column="sfzh" property="sfzh"/>
        <result column="lxdh" property="lxdh"/>
        <result column="lb" property="lb"/>
    </resultMap>


    <select id="selectmdjfRyPage" resultMap="mdjfryResultMap">
        select * from mdjf_ry where is_deleted = 0 and jf_id = #{mdjfry.jfId}
    </select>


    <select id="exportmdjfRy" resultType="org.springblade.modules.mdjfry.excel.MdjfRyExcel">
        SELECT * FROM mdjf_ry ${ew.customSqlSegment}
    </select>

    <select id="getRyByMdId" resultType="org.springblade.modules.mdjfry.entity.MdjfRyEntity">
        SELECT
            *
        FROM
            mdjf_ry
        WHERE
            is_deleted = 0
          AND jf_id = #{id}
    </select>

    <update id="updateLkry" parameterType="java.lang.String">
        UPDATE mdjf_ry
        SET sflk = 1
        WHERE
            #{ryids} LIKE'%' || id || '%'
    </update>

    <update id="updateAllQmzp" parameterType="java.util.Map">
        <foreach collection="qmzpMap" item="qmzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
                qmzp = #{qmzp}
            WHERE
                id :: text = #{key}
        </foreach>
    </update>

    <update id="updateAllHfzp" parameterType="java.util.Map">
        <foreach collection="hfzpMap" item="hfzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
            hfzp = #{hfzp}
            WHERE
            id :: text = #{key}
        </foreach>
    </update>

    <update id="updateAllRyzp" parameterType="java.util.Map">
        <foreach collection="ryzpMap" item="ryzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
            ryzp = #{ryzp}
            WHERE
            id :: text = #{key}
        </foreach>
    </update>

    <insert id="updateAllPj">
        INSERT INTO jdrh.mdjf_pj (id, jf_id, tj_id, ry_id, pj, create_user, create_dept, update_user)
        VALUES (#{id}, #{jfId}, #{tjId}, #{ryId}, #{pj}, #{createUser}, #{createDept}, #{updateUser})
    </insert>

    <select id="getRyByMdIdJl" resultMap="mdjfryResultMap">
        select * from mdjf_ry_new where is_deleted = 0 and jf_id = #{mdid}
    </select>

    <insert id="saveJl">
        INSERT INTO jdrh.mdjf_ry
        (id, jf_id, xm, xb, sfzh, lxdh, lb, create_user, create_dept, create_time, update_user, update_time, status, is_deleted, ryzp, sflk, qmzp, hfzp)
        VALUES(#{id},
        #{jfId},
        #{xm},#{xb},
        #{sfzh},
        #{lxdh},
        #{lb},
        #{createUser},
        #{createDept},
        #{createTime},
        #{updateUser},
        #{updateTime},
        #{status},
        #{isDeleted},
        #{ryzp},
        #{sflk},
        #{qmzp},
        #{hfzp});
    </insert>

    <update id="updateAllQmzpJl" parameterType="java.util.Map">
        <foreach collection="qmzpMap" item="qmzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
            qmzp = #{qmzp}
            WHERE
            id :: text = #{key}
        </foreach>
    </update>

    <update id="updateAllRyzpJl" parameterType="java.util.Map">
        <foreach collection="ryzpMap" item="ryzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
            ryzp = #{ryzp}
            WHERE
            id :: text = #{key}
        </foreach>
    </update>

    <update id="updateAllHfzpJl" parameterType="java.util.Map">
        <foreach collection="hfzpMap" item="hfzp" index="key" separator=";">
            UPDATE mdjf_ry
            SET
            hfzp = #{hfzp}
            WHERE
            id :: text = #{key}
        </foreach>
    </update>
</mapper>
