<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.PersonPopedomIconDAO">
    <resultMap id="PersonPopedomIconMap" type="com.jpsoft.shinestar.modules.base.entity.PersonPopedomIcon">
        <id property="id" column="id_"/>
        <result property="personPopedomId" column="person_popedom_id"/>
        <result property="iconId" column="icon_id"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonPopedomIcon">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_person_popedom_icon
	    (id_,person_popedom_id,icon_id,del_flag,create_by,create_time,update_by,update_time)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personPopedomId,jdbcType=VARCHAR}
            ,#{iconId,jdbcType=VARCHAR}
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_person_popedom_icon where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <delete id="deleteByPersonPopedomId">
        delete from base_person_popedom_icon where person_popedom_id=#{personPopedomId,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonPopedomIcon">
        update base_person_popedom_icon
        <set>
            <if test="personPopedomId!=null">
                person_popedom_id=#{personPopedomId,jdbcType=VARCHAR},
            </if>
            <if test="iconId!=null">
                icon_id=#{iconId,jdbcType=VARCHAR},
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="PersonPopedomIconMap">
        select * from base_person_popedom_icon where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_person_popedom_icon where id_=#{0}
    </select>
    <select id="list" resultMap="PersonPopedomIconMap">
        select * from base_person_popedom_icon
    </select>
    <select id="search" parameterType="hashmap" resultMap="PersonPopedomIconMap">
        <![CDATA[
			select * from base_person_popedom_icon
		]]>
        <where>
            <if test="searchParams.id != null">
                and ID_ like #{searchParams.id}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findByPersonPopedomId" resultMap="PersonPopedomIconMap">
        select * from base_person_popedom_icon
        where person_popedom_id=#{0}
        and del_flag=0
        order by create_time asc
    </select>

    <select id="findByPersonIdAndIconName" resultMap="PersonPopedomIconMap">
        <![CDATA[

        select a.* from base_person_popedom_icon a
        left join base_person_popedom b on a.person_popedom_id = b.id_
        left join base_icon_info c on a.icon_id = c.id_
        where a.del_flag = 0
        and b.person_id = #{personId}
        and c.icon_name = #{iconName}
        limit 1
        ]]>
    </select>
</mapper>