<?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.cmvr.aima.mapper.AimaPhoneMapper">
    
    <resultMap type="AimaPhone" id="AimaPhoneResult">
        <result property="id"    column="id"    />
        <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="remark"    column="remark"    />
        <result property="phoneName"    column="phone_name"    />
        <result property="phoneModel"    column="phone_model"    />
        <result property="osSystem"    column="os_system"    />
        <result property="osVersion"    column="os_version"    />
        <result property="specifications"    column="specifications"    />
        <result property="manufacturer"    column="manufacturer"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectAimaPhoneVo">
        select id, create_by, create_time, update_by, update_time, remark, phone_name, phone_model, os_system, os_version, specifications, manufacturer, status from aima_phone
    </sql>

    <select id="selectAimaPhoneList" parameterType="AimaPhone" resultMap="AimaPhoneResult">
        <include refid="selectAimaPhoneVo"/>
        <where>  
            <if test="phoneName != null  and phoneName != ''"> and phone_name like concat('%', #{phoneName}, '%')</if>
            <if test="phoneModel != null  and phoneModel != ''"> and phone_model like concat('%', #{phoneModel}, '%')</if>
            <if test="osSystem != null  and osSystem != ''"> and os_system = #{osSystem}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectAimaPhoneById" parameterType="String" resultMap="AimaPhoneResult">
        <include refid="selectAimaPhoneVo"/>
        where id = #{id}
    </select>

    <insert id="insertAimaPhone" parameterType="AimaPhone">
        insert into aima_phone
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</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="remark != null">remark,</if>
            <if test="phoneName != null">phone_name,</if>
            <if test="phoneModel != null">phone_model,</if>
            <if test="osSystem != null">os_system,</if>
            <if test="osVersion != null">os_version,</if>
            <if test="specifications != null">specifications,</if>
            <if test="manufacturer != null">manufacturer,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</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="remark != null">#{remark},</if>
            <if test="phoneName != null">#{phoneName},</if>
            <if test="phoneModel != null">#{phoneModel},</if>
            <if test="osSystem != null">#{osSystem},</if>
            <if test="osVersion != null">#{osVersion},</if>
            <if test="specifications != null">#{specifications},</if>
            <if test="manufacturer != null">#{manufacturer},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateAimaPhone" parameterType="AimaPhone">
        update aima_phone
        <trim prefix="SET" suffixOverrides=",">
            <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="remark != null">remark = #{remark},</if>
            <if test="phoneName != null">phone_name = #{phoneName},</if>
            <if test="phoneModel != null">phone_model = #{phoneModel},</if>
            <if test="osSystem != null">os_system = #{osSystem},</if>
            <if test="osVersion != null">os_version = #{osVersion},</if>
            <if test="specifications != null">specifications = #{specifications},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAimaPhoneById" parameterType="String">
        delete from aima_phone where id = #{id}
    </delete>

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