<?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.MallMemberCmsMapper">

    <resultMap type="MallMemberCms" id="MallMemberCmsResult">
        <result property="id"    column="id"    />
        <result property="cmsCode"    column="cms_code"    />
        <result property="phone"    column="phone"    />
        <result property="status"    column="status"    />
        <result property="createAt"    column="create_at"    />
    </resultMap>

    <sql id="selectMallMemberCmsVo">
        select id, cms_code, phone, status, create_at from mall_member_cms
    </sql>

    <select id="selectMallMemberCmsList" parameterType="MallMemberCms" resultMap="MallMemberCmsResult">
        <include refid="selectMallMemberCmsVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="cmsCode != null  and cmsCode != ''"> and cms_code = #{cmsCode}</if>
            <if test="phone != null  and phone != ''"> and phone = #{phone}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
        </where>
    </select>

    <select id="selectMallMemberCmsById" parameterType="Long" resultMap="MallMemberCmsResult">
        <include refid="selectMallMemberCmsVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallMemberCms" parameterType="MallMemberCms" useGeneratedKeys="true" keyProperty="id">
        insert into mall_member_cms
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="cmsCode != null">cms_code,</if>
            <if test="phone != null">phone,</if>
            <if test="status != null">status,</if>
            <if test="createAt != null">create_at,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="cmsCode != null">#{cmsCode},</if>
            <if test="phone != null">#{phone},</if>
            <if test="status != null">#{status},</if>
            <if test="createAt != null">#{createAt},</if>
        </trim>
    </insert>

    <update id="resetCmsCode" parameterType="MallMemberCms">
        update mall_member_cms SET status = '1' where phone = #{phone} and status = '0'
    </update>

    <update id="updateMallMemberCms" parameterType="MallMemberCms">
        update mall_member_cms
        <trim prefix="SET" suffixOverrides=",">
            <if test="cmsCode != null">cms_code = #{cmsCode},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallMemberCmsById" parameterType="Long">
        delete from mall_member_cms where id = #{id}
    </delete>

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

    <select id="getCmsByPhone" resultMap="MallMemberCmsResult">
        <include refid="selectMallMemberCmsVo"/>
        where cms_code = #{cmsCode} and phone = #{phone} and status = '0'
    </select>
</mapper>
