<?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.web.modules.industrypolicy.mapper.BizSubsidyGrantRecordMapper">

    <resultMap type="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord" id="BizSubsidyGrantRecordResult">
        <id     property="id"                  column="id"/>
        <result property="subsidyProjectName"  column="subsidy_project_name"/>
        <result property="subsidyType"         column="subsidy_type"/>
        <result property="recipientName"       column="recipient_name"/>
        <result property="idCard"              column="id_card"/>
        <result property="contactPhone"        column="contact_phone"/>
        <result property="bankAccount"         column="bank_account"/>
        <result property="subsidyAmount"       column="subsidy_amount"/>
        <result property="grantDate"           column="grant_date"/>
        <result property="createBy"            column="create_by"/>
        <result property="createTime"          column="create_time"/>
        <result property="updateBy"            column="update_by"/>
        <result property="updateTime"          column="update_time"/>
        <result property="remark"              column="remark"/>
    </resultMap>

    <sql id="selectVo">
        select id, subsidy_project_name, subsidy_type, recipient_name, id_card, contact_phone,
               bank_account, subsidy_amount, grant_date,
               create_by, create_time, update_by, update_time, remark
        from biz_subsidy_grant_record
    </sql>

    <select id="selectBizSubsidyGrantRecordById" parameterType="long" resultMap="BizSubsidyGrantRecordResult">
        <include refid="selectVo"/>
        where id = #{id}
    </select>

    <select id="selectBizSubsidyGrantRecordList" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord" resultMap="BizSubsidyGrantRecordResult">
        <include refid="selectVo"/>
        <where>
            <if test="recipientName != null and recipientName != ''">
                and recipient_name like concat('%', #{recipientName}, '%')
            </if>
            <if test="subsidyType != null">
                and subsidy_type = #{subsidyType}
            </if>
            <if test="startDate != null and startDate != ''">
                and grant_date &gt;= #{startDate}
            </if>
            <if test="endDate != null and endDate != ''">
                and grant_date &lt;= #{endDate}
            </if>
        </where>
        order by grant_date desc, create_time desc, id desc
    </select>

    <insert id="insertBizSubsidyGrantRecord" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord" useGeneratedKeys="true" keyProperty="id">
        insert into biz_subsidy_grant_record (
            subsidy_project_name, subsidy_type, recipient_name, id_card, contact_phone,
            bank_account, subsidy_amount, grant_date,
            create_by, create_time, remark
        ) values (
            #{subsidyProjectName}, #{subsidyType}, #{recipientName}, #{idCard}, #{contactPhone},
            #{bankAccount}, #{subsidyAmount}, #{grantDate},
            #{createBy}, sysdate(), #{remark}
        )
    </insert>

    <update id="updateBizSubsidyGrantRecord" parameterType="com.ruoyi.web.modules.industrypolicy.domain.BizSubsidyGrantRecord">
        update biz_subsidy_grant_record set
            subsidy_project_name = #{subsidyProjectName},
            subsidy_type = #{subsidyType},
            recipient_name = #{recipientName},
            id_card = #{idCard},
            contact_phone = #{contactPhone},
            bank_account = #{bankAccount},
            subsidy_amount = #{subsidyAmount},
            grant_date = #{grantDate},
            update_by = #{updateBy},
            update_time = sysdate(),
            remark = #{remark}
        where id = #{id}
    </update>

    <delete id="deleteBizSubsidyGrantRecordByIds" parameterType="long">
        delete from biz_subsidy_grant_record where id in
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
