<?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.iamberry.wechat.service.mapper.CustomizedToothMapper">
    <resultMap  id="BaseResultMap" type="CustomizedTooth" >
        <result    column="tooth_id"    property="toothId" />
        <result    column="user_open_id"    property="userOpenId" />
        <result    column="product_id"    property="productId" />
        <result    column="color_id"    property="colorId" />
        <result    column="tooth_color_id"    property="toothColorId" />
        <result    column="tooth_pattern_id"    property="toothPatternId" />
        <result    column="tooth_position_id"    property="toothPositionId" />
        <result    column="tooth_text"    property="toothText" />
        <result    column="tooth_avatar_img"    property="toothAvatarImg" />
        <result    column="tooth_img"    property="toothImg" />
        <result    column="tooth_code_img"    property="toothCodeImg" />
        <result    column="tooth_type"    property="toothType" />
        <result    column="tooth_status"    property="toothStatus" />
        <result    column="tooth_create_time"    property="toothCreateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.tooth_id,
        t.user_open_id,
        t.product_id,
        t.color_id,
        t.tooth_color_id,
        t.tooth_pattern_id,
        t.tooth_position_id,
        t.tooth_text,
        t.tooth_avatar_img,
        t.tooth_img,
        t.tooth_code_img,
        t.tooth_type,
        t.tooth_status,
        t.tooth_create_time
    </sql>
    <select id="getCustomizedToothList" resultMap="BaseResultMap" parameterType="CustomizedTooth" >
        select
        <include refid="Base_List" />
        from tb_iamberry_customized_tooth t
        <where>
            <if test="toothId != null ">
                AND t.tooth_id = #{toothId}
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                AND t.user_open_id  like  CONCAT ('%',#{userOpenId},'%')
            </if >
            <if test="productId != null ">
                AND t.product_id = #{productId}
            </if >
            <if test="colorId != null ">
                AND t.color_id = #{colorId}
            </if >
            <if test="toothColorId != null ">
                AND t.tooth_color_id = #{toothColorId}
            </if >
            <if test="toothPatternId != null ">
                AND t.tooth_pattern_id = #{toothPatternId}
            </if >
            <if test="toothPositionId != null ">
                AND t.tooth_position_id = #{toothPositionId}
            </if >
            <if test="toothText != null and toothText != ''">
                AND t.tooth_text  like  CONCAT ('%',#{toothText},'%')
            </if >
            <if test="toothAvatarImg != null and toothAvatarImg != ''">
                AND t.tooth_avatar_img  like  CONCAT ('%',#{toothAvatarImg},'%')
            </if >
            <if test="toothImg != null and toothImg != ''">
                AND t.tooth_img  like  CONCAT ('%',#{toothImg},'%')
            </if >
            <if test="toothType != null ">
                AND t.tooth_type = #{toothType}
            </if >
            <if test="toothStatus != null ">
                AND t.tooth_status = #{toothStatus}
            </if >
        </where>
    </select>
    <select id="getCustomizedToothById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_customized_tooth t
        where t.tooth_id= #{toothId}
    </select>
    <insert id="save" keyProperty="toothId" useGeneratedKeys="true" parameterType="CustomizedTooth" >
        insert into
        tb_iamberry_customized_tooth
        (
        tooth_id,
        user_open_id,
        product_id,
        color_id,
        tooth_color_id,
        tooth_pattern_id,
        tooth_position_id,
        tooth_text,
        tooth_avatar_img,
        tooth_img,
        tooth_code_img,
        tooth_type,
        tooth_status
        )
        values
        (
        #{toothId},
        #{userOpenId},
        #{productId},
        #{colorId},
        #{toothColorId},
        #{toothPatternId},
        #{toothPositionId},
        #{toothText},
        #{toothAvatarImg},
        #{toothImg},
        #{toothCodeImg},
        #{toothType},
        #{toothStatus}
        )
    </insert>
    <update id="update" parameterType="CustomizedTooth" >
        update
        tb_iamberry_customized_tooth
        <set >
            <if test="toothId != null ">
                tooth_id = #{toothId},
            </if >
            <if test="userOpenId != null and userOpenId != ''">
                user_open_id = #{userOpenId},
            </if >
            <if test="productId != null ">
                product_id = #{productId},
            </if >
            <if test="colorId != null ">
                color_id = #{colorId},
            </if >
            <if test="toothColorId != null ">
                tooth_color_id = #{toothColorId},
            </if >
            <if test="toothPatternId != null ">
                tooth_pattern_id = #{toothPatternId},
            </if >
            <if test="toothPositionId != null ">
                tooth_position_id = #{toothPositionId},
            </if >
            <if test="toothText != null and toothText != ''">
                tooth_text = #{toothText},
            </if >
            <if test="toothAvatarImg != null and toothAvatarImg != ''">
                tooth_avatar_img = #{toothAvatarImg},
            </if >
            <if test="toothImg != null and toothImg != ''">
                tooth_img = #{toothImg},
            </if >
            <if test="toothType != null ">
                tooth_type = #{toothType},
            </if >
            <if test="toothStatus != null ">
                tooth_status = #{toothStatus},
            </if >
        </set >
        where tooth_id= #{toothId}
    </update>
</mapper>