<?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.srs.stureg.mapper.PayMoneyMapper">
    
    <resultMap type="PayMoney" id="PayMoneyResult">
        <result property="id"    column="id"    />
        <result property="costName"    column="cost_name"    />
        <result property="shouIdPayAmount"    column="shouIdPayAmount"    />
        <result property="amountPaid"    column="amountPaid"    />
        <result property="deferAmount"    column="deferAmount"    />
        <result property="fromAmount"    column="fromAmount"    />
        <result property="completion"    column="completion"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <resultMap id="PayMoneySrsRegInfoResult" type="PayMoney" extends="PayMoneyResult">
        <collection property="srsRegInfoList" notNullColumn="sub_register_id" javaType="java.util.List" resultMap="SrsRegInfoResult" />
    </resultMap>

    <resultMap type="SrsRegInfo" id="SrsRegInfoResult">
        <result property="registerId"    column="sub_register_id"    />
        <result property="userName"    column="sub_user_name"    />
        <result property="sex"    column="sub_sex"    />
        <result property="nation"    column="sub_nation"    />
        <result property="politicsStatus"    column="sub_politics_status"    />
        <result property="height"    column="sub_height"    />
        <result property="weight"    column="sub_weight"    />
        <result property="graduateSchool"    column="sub_graduate_school"    />
        <result property="schoolAddress"    column="sub_school_address"    />
        <result property="familyContactName"    column="sub_family_contact_name"    />
        <result property="relation"    column="sub_relation"    />
        <result property="familyContactPhone"    column="sub_family_contact_phone"    />
        <result property="domicileAddress"    column="sub_domicile_address"    />
        <result property="homeAdress"    column="sub_home_adress"    />
        <result property="status"    column="sub_status"    />
        <result property="createBy"    column="sub_create_by"    />
        <result property="createTime"    column="sub_create_time"    />
        <result property="updateBy"    column="sub_update_by"    />
        <result property="updateTime"    column="sub_update_time"    />
    </resultMap>

    <sql id="selectPayMoneyVo">
        select id, cost_name, shouIdPayAmount, amountPaid, deferAmount, fromAmount, completion, status, create_by, create_time, update_by, update_time from srs_pay
    </sql>

    <select id="selectPayMoneyList" parameterType="PayMoney" resultMap="PayMoneyResult">
        <include refid="selectPayMoneyVo"/>
        <where>  
            <if test="costName != null  and costName != ''"> and cost_name like concat('%', #{costName}, '%')</if>
            <if test="shouIdPayAmount != null "> and shouIdPayAmount = #{shouIdPayAmount}</if>
            <if test="amountPaid != null "> and amountPaid = #{amountPaid}</if>
            <if test="deferAmount != null "> and deferAmount = #{deferAmount}</if>
            <if test="fromAmount != null "> and fromAmount = #{fromAmount}</if>
            <if test="completion != null "> and completion = #{completion}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectPayMoneyById" parameterType="Long" resultMap="PayMoneySrsRegInfoResult">
        select a.id, a.cost_name, a.shouIdPayAmount, a.amountPaid, a.deferAmount, a.fromAmount, a.completion, a.status, a.create_by, a.create_time, a.update_by, a.update_time,
 b.register_id as sub_register_id, b.user_name as sub_user_name, b.sex as sub_sex, b.nation as sub_nation, b.politics_status as sub_politics_status, b.height as sub_height, b.weight as sub_weight, b.graduate_school as sub_graduate_school, b.school_address as sub_school_address, b.family_contact_name as sub_family_contact_name, b.relation as sub_relation, b.family_contact_phone as sub_family_contact_phone, b.domicile_address as sub_domicile_address, b.home_adress as sub_home_adress, b.status as sub_status, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time
        from srs_pay a
        left join srs_reg_info b on b.register_id = a.id
        where a.id = #{id}
    </select>
        
    <insert id="insertPayMoney" parameterType="PayMoney" useGeneratedKeys="true" keyProperty="id">
        insert into srs_pay
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="costName != null">cost_name,</if>
            <if test="shouIdPayAmount != null">shouIdPayAmount,</if>
            <if test="amountPaid != null">amountPaid,</if>
            <if test="deferAmount != null">deferAmount,</if>
            <if test="fromAmount != null">fromAmount,</if>
            <if test="completion != null">completion,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="costName != null">#{costName},</if>
            <if test="shouIdPayAmount != null">#{shouIdPayAmount},</if>
            <if test="amountPaid != null">#{amountPaid},</if>
            <if test="deferAmount != null">#{deferAmount},</if>
            <if test="fromAmount != null">#{fromAmount},</if>
            <if test="completion != null">#{completion},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updatePayMoney" parameterType="PayMoney">
        update srs_pay
        <trim prefix="SET" suffixOverrides=",">
            <if test="costName != null">cost_name = #{costName},</if>
            <if test="shouIdPayAmount != null">shouIdPayAmount = #{shouIdPayAmount},</if>
            <if test="amountPaid != null">amountPaid = #{amountPaid},</if>
            <if test="deferAmount != null">deferAmount = #{deferAmount},</if>
            <if test="fromAmount != null">fromAmount = #{fromAmount},</if>
            <if test="completion != null">completion = #{completion},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePayMoneyById" parameterType="Long">
        delete from srs_pay where id = #{id}
    </delete>

    <delete id="deletePayMoneyByIds" parameterType="String">
        delete from srs_pay where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    
    <delete id="deleteSrsRegInfoByRegisterIds" parameterType="String">
        delete from srs_reg_info where register_id in 
        <foreach item="registerId" collection="array" open="(" separator="," close=")">
            #{registerId}
        </foreach>
    </delete>

    <delete id="deleteSrsRegInfoByRegisterId" parameterType="Long">
        delete from srs_reg_info where register_id = #{registerId}
    </delete>

    <insert id="batchSrsRegInfo">
        insert into srs_reg_info( register_id, user_name, sex, nation, politics_status, height, weight, graduate_school, school_address, family_contact_name, relation, family_contact_phone, domicile_address, home_adress, status, create_by, create_time, update_by, update_time) values
		<foreach item="item" index="index" collection="list" separator=",">
            ( #{item.registerId}, #{item.userName}, #{item.sex}, #{item.nation}, #{item.politicsStatus}, #{item.height}, #{item.weight}, #{item.graduateSchool}, #{item.schoolAddress}, #{item.familyContactName}, #{item.relation}, #{item.familyContactPhone}, #{item.domicileAddress}, #{item.homeAdress}, #{item.status}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime})
        </foreach>
    </insert>
</mapper>