<?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.mall.mapper.MallMemberRegisterMapper">

    <resultMap type="MallMemberRegister" id="MallMemberRegisterResult">
        <result property="id"    column="id"    />
        <result property="registerPhone"    column="register_phone"    />
        <result property="shopName"    column="shop_name"    />
        <result property="personName"    column="person_name"    />
        <result property="province"    column="province"    />
        <result property="city"    column="city"    />
        <result property="area"    column="area"    />
        <result property="address"    column="address"    />
        <result property="password"    column="password"    />
        <result property="status"    column="status"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="shopImage"    column="shop_image"    />
        <result property="salesmanId"    column="salesman_id"    />
    </resultMap>

    <sql id="selectMallMemberRegisterVo">
        select id, register_phone, shop_name, person_name, province, city, area, address, password,
               shop_image, status, create_at, update_at, del_flag, salesman_id
        from mall_member_register
    </sql>

    <select id="selectMallMemberRegisterList" parameterType="MallMemberRegister" resultMap="MallMemberRegisterResult">
        <include refid="selectMallMemberRegisterVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="registerPhone != null  and registerPhone != ''"> and register_phone like concat('%',#{registerPhone},'%')</if>
            <if test="shopName != null  and shopName != ''"> and shop_name like concat('%', #{shopName}, '%')</if>
            <if test="personName != null  and personName != ''"> and person_name like concat('%', #{personName}, '%')</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="params.beginCreateAt != null and params.beginCreateAt != '' and params.endCreateAt != null and params.endCreateAt != ''">
                and #{params.beginCreateAt} &lt;= DATE_FORMAT(`create_at`,'%Y-%m-%d')
                and #{params.endCreateAt} &gt;= DATE_FORMAT(`create_at`,'%Y-%m-%d')
            </if>
            <if test="updateAt != null  and updateAt != ''"> and update_at = #{updateAt}</if>
            <if test="salesmanId != null  and salesmanId != ''"> and salesman_id = #{salesmanId}</if>
            and del_flag = '0'
        </where>
        order by status asc,create_at desc
    </select>

    <select id="selectMallMemberRegisterById" parameterType="Integer" resultMap="MallMemberRegisterResult">
        <include refid="selectMallMemberRegisterVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallMemberRegister" parameterType="MallMemberRegister" useGeneratedKeys="true" keyProperty="id">
        insert into mall_member_register
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="registerPhone != null">register_phone,</if>
            <if test="shopName != null">shop_name,</if>
            <if test="personName != null">person_name,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="area != null">area,</if>
            <if test="address != null">address,</if>
            <if test="password != null">password,</if>
            <if test="status != null">status,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="shopImage != null">shop_image,</if>
            <if test="salesmanId != null">salesman_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="registerPhone != null">#{registerPhone},</if>
            <if test="shopName != null">#{shopName},</if>
            <if test="personName != null">#{personName},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="area != null">#{area},</if>
            <if test="address != null">#{address},</if>
            <if test="password != null">#{password},</if>
            <if test="status != null">#{status},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="shopImage != null">#{shopImage},</if>
            <if test="salesmanId != null">#{salesmanId},</if>
         </trim>
    </insert>

    <update id="updateMallMemberRegister" parameterType="MallMemberRegister">
        update mall_member_register
        <trim prefix="SET" suffixOverrides=",">
            <if test="registerPhone != null">register_phone = #{registerPhone},</if>
            <if test="shopName != null">shop_name = #{shopName},</if>
            <if test="personName != null">person_name = #{personName},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="area != null">area = #{area},</if>
            <if test="address != null">address = #{address},</if>
            <if test="password != null">password = #{password},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="shopImage != null">shop_image = #{shopImage},</if>
            <if test="salesmanId != null">salesman_id = #{salesmanId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallMemberRegisterById" parameterType="Integer">
        <!--delete from mall_member_register where id = #{id}-->
        update mall_member_register set del_flag = '1' where id = #{id}
    </delete>

    <delete id="deleteMallMemberRegisterByIds" parameterType="String">
        <!--delete from mall_member_register where id in-->
        update mall_member_register set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
