<?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.xinelu.manage.mapper.receiveAddressInfo.ReceiveAddressInfoMapper">

    <resultMap type="ReceiveAddressInfo" id="ReceiveAddressInfoResult">
        <result property="id" column="id"/>
        <result property="patientId" column="patient_id"/>
        <result property="openid" column="openid"/>
        <result property="unionid" column="unionid"/>
        <result property="receiveName" column="receive_name"/>
        <result property="receivePhone" column="receive_phone"/>
        <result property="receiveAddress" column="receive_address"/>
        <result property="areaCode" column="area_code"/>
        <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="defaultAddressFlag" column="default_address_flag"/>
    </resultMap>

    <sql id="selectReceiveAddressInfoVo">
        select id,
               patient_id,
               openid,
               unionid,
               receive_name,
               receive_phone,
               receive_address,
               area_code,
               create_by,
               create_time,
               update_by,
               update_time,
               default_address_flag
        from receive_address_info
    </sql>

    <select id="selectReceiveAddressInfoList" parameterType="ReceiveAddressInfo" resultMap="ReceiveAddressInfoResult">
        <include refid="selectReceiveAddressInfoVo"/>
        <where>
            <if test="patientId != null ">
                and patient_id = #{patientId}
            </if>
            <if test="openid != null  and openid != ''">
                and openid = #{openid}
            </if>
            <if test="unionid != null  and unionid != ''">
                and unionid = #{unionid}
            </if>
            <if test="receiveName != null  and receiveName != ''">
                and receive_name like concat('%', #{receiveName}, '%')
            </if>
            <if test="receivePhone != null  and receivePhone != ''">
                and receive_phone = #{receivePhone}
            </if>
            <if test="receiveAddress != null  and receiveAddress != ''">
                and receive_address = #{receiveAddress}
            </if>
            <if test="areaCode != null  and areaCode != ''">
                and area_code = #{areaCode}
            </if>
        </where>
    </select>

    <select id="selectReceiveAddressInfoById" parameterType="Long"
            resultMap="ReceiveAddressInfoResult">
        <include refid="selectReceiveAddressInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertReceiveAddressInfo" parameterType="ReceiveAddressInfo">
        insert into receive_address_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,
            </if>
            <if test="patientId != null">patient_id,
            </if>
            <if test="openid != null">openid,
            </if>
            <if test="unionid != null">unionid,
            </if>
            <if test="receiveName != null">receive_name,
            </if>
            <if test="receivePhone != null">receive_phone,
            </if>
            <if test="receiveAddress != null">receive_address,
            </if>
            <if test="areaCode != null">area_code,
            </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>
            <if test="defaultAddressFlag != null">default_address_flag,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},
            </if>
            <if test="patientId != null">#{patientId},
            </if>
            <if test="openid != null">#{openid},
            </if>
            <if test="unionid != null">#{unionid},
            </if>
            <if test="receiveName != null">#{receiveName},
            </if>
            <if test="receivePhone != null">#{receivePhone},
            </if>
            <if test="receiveAddress != null">#{receiveAddress},
            </if>
            <if test="areaCode != null">#{areaCode},
            </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>
            <if test="defaultAddressFlag != null">#{defaultAddressFlag},
            </if>
        </trim>
    </insert>

    <update id="updateReceiveAddressInfo" parameterType="ReceiveAddressInfo">
        update receive_address_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
            <if test="openid != null">openid =
                #{openid},
            </if>
            <if test="unionid != null">unionid =
                #{unionid},
            </if>
            <if test="receiveName != null">receive_name =
                #{receiveName},
            </if>
            <if test="receivePhone != null">receive_phone =
                #{receivePhone},
            </if>
            <if test="receiveAddress != null">receive_address =
                #{receiveAddress},
            </if>
            <if test="areaCode != null">area_code =
                #{areaCode},
            </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>
            <if test="defaultAddressFlag != null">default_address_flag =
                #{defaultAddressFlag},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteReceiveAddressInfoById" parameterType="Long">
        delete
        from receive_address_info
        where id = #{id}
    </delete>

    <delete id="deleteReceiveAddressInfoByIds" parameterType="String">
        delete from receive_address_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getReceiveAddressInfo" resultType="int">
        SELECT
            count(1) as receiveCount
        FROM
            receive_address_info
        WHERE
            patient_id = #{patientId}
            AND receive_name = #{receiveName}
            AND receive_phone = #{receivePhone}
            AND receive_address = #{receiveAddress}
    </select>
</mapper>
