<?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.CustomizedPositionMapper">
    <resultMap  id="BaseResultMap" type="CustomizedPosition" >
        <result    column="position_id"    property="positionId" />
        <result    column="position_type"    property="positionType" />
        <result    column="pattern_id"    property="patternId" />
        <result    column="position_pattern_x"    property="positionPatternX" />
        <result    column="position_pattern_y"    property="positionPatternY" />
        <result    column="position_avatar_x"    property="positionAvatarX" />
        <result    column="position_avatar_y"    property="positionAvatarY" />
        <result    column="position_text_x"    property="positionTextX" />
        <result    column="position_text_y"    property="positionTextY" />
        <result    column="position_status"    property="positionStatus" />
        <result    column="position_create_time"    property="positionCreateTime" />
        <result    column="position_update_time"    property="positionUpdateTime" />
    </resultMap>
    <sql    id="Base_List" >
        t.position_id,
        t.position_type,
        t.pattern_id,
        t.position_pattern_x,
        t.position_pattern_y,
        t.position_avatar_x,
        t.position_avatar_y,
        t.position_text_x,
        t.position_text_y,
        t.position_status,
        t.position_create_time,
        t.position_update_time
    </sql>
    <select id="getCustomizedPositionList" resultMap="BaseResultMap" parameterType="CustomizedPosition" >
        select
        <include refid="Base_List" />
        from tb_iamberry_customized_position t
        <where>
            <if test="positionId != null ">
                AND t.position_id = #{positionId}
            </if >
            <if test="positionType != null ">
                AND t.position_type = #{positionType}
            </if >
            <if test="patternId != null ">
                AND t.pattern_id = #{patternId}
            </if >
            <if test="positionStatus != null ">
                AND t.position_status = #{positionStatus}
            </if >
        </where>
    </select>
    <select id="getCustomizedPositionById" resultMap="BaseResultMap" parameterType="Integer" >
        select
        <include refid="Base_List" />
        from tb_iamberry_customized_position t
        where t.position_id= #{positionId}
    </select>
    <insert id="save" parameterType="CustomizedPosition" >
        insert into
        tb_iamberry_customized_position
        (
        position_type,
        pattern_id,
        position_pattern_x,
        position_pattern_y,
        position_avatar_x,
        position_avatar_y,
        position_text_x,
        position_text_y,
        position_status
        )
        values
        (
        #{positionType},
        #{patternId},
        #{positionPatternX},
        #{positionPatternY},
        #{positionAvatarX},
        #{positionAvatarY},
        #{positionTextX},
        #{positionTextY},
        #{positionStatus}
        )
    </insert>
    <update id="update" parameterType="CustomizedPosition" >
        update
        tb_iamberry_customized_position
        <set >
            <if test="positionType != null ">
                position_type = #{positionType},
            </if >
            <if test="patternId != null ">
                pattern_id = #{patternId},
            </if >
            <if test="positionPatternX != null ">
                position_pattern_x = #{positionPatternX},
            </if >
            <if test="positionPatternY != null ">
                position_pattern_y = #{positionPatternY},
            </if >
            <if test="positionAvatarX != null ">
                position_avatar_x = #{positionAvatarX},
            </if >
            <if test="positionAvatarY != null ">
                position_avatar_y = #{positionAvatarY},
            </if >
            <if test="positionTextX != null ">
                position_text_x = #{positionTextX},
            </if >
            <if test="positionTextY != null ">
                position_text_y = #{positionTextY},
            </if >
            <if test="positionStatus != null ">
                position_status = #{positionStatus},
            </if >
        </set >
        where position_id= #{positionId}
    </update>
    <delete id="delete" parameterType="Integer" >
        delete FROM
        tb_iamberry_customized_position
        where position_id=#{positionId}
    </delete>
    <insert id="saveList" parameterType="java.util.List" >
        insert into
        tb_iamberry_customized_position
        (
        position_type,
        pattern_id,
        position_pattern_x,
        position_pattern_y,
        position_avatar_x,
        position_avatar_y,
        position_text_x,
        position_text_y,
        position_status
        )
        values
        <foreach collection="list" item="node" index="index" separator="," open="" close="">
            (
            #{node.positionType},
            #{node.patternId},
            #{node.positionPatternX},
            #{node.positionPatternY},
            #{node.positionAvatarX},
            #{node.positionAvatarY},
            #{node.positionTextX},
            #{node.positionTextY},
            #{node.positionStatus}
            )
        </foreach >
    </insert>
    <delete id="deleteList" parameterType="String" >
        delete FROM
        tb_iamberry_customized_position
        where position_id  in
        <foreach collection="ids" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach >
    </delete>
</mapper>