<?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.system.mapper.MobileMiddleMapper">
    
    <resultMap type="MobileMiddle" id="MobileMiddleResult">
        <result property="id"    column="id"    />
        <result property="phone"    column="phone"    />
        <result property="provinceId"    column="province_id"    />
        <result property="cityId"    column="city_id"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectMobileMiddleVo">
        select id, phone, province_id, city_id, created_at, updated_at from mobile_middle
    </sql>

    <select id="selectMobileMiddleList" parameterType="MobileMiddle" resultMap="MobileMiddleResult">
        <include refid="selectMobileMiddleVo"/>
        <where>  
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="provinceId != null "> and province_id like concat('%', #{provinceId}, '%')</if>
            <if test="cityId != null "> and city_id like concat('%', #{cityId}, '%')</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectMobileMiddleById" parameterType="Long" resultMap="MobileMiddleResult">
        <include refid="selectMobileMiddleVo"/>
        where id = #{id}
    </select>

    <insert id="insertMobileMiddle" parameterType="MobileMiddle" useGeneratedKeys="true" keyProperty="id">
        insert into mobile_middle
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="phone != null and phone != ''">phone,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="cityId != null">city_id,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="phone != null and phone != ''">#{phone},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateMobileMiddle" parameterType="MobileMiddle">
        update mobile_middle
        <trim prefix="SET" suffixOverrides=",">
            <if test="phone != null and phone != ''">phone = #{phone},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMobileMiddleById" parameterType="Long">
        delete from mobile_middle where id = #{id}
    </delete>

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