<?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.GoodsInfoDAO">
    <resultMap id="GoodsInfoMap" type="com.jpsoft.shinestar.modules.base.entity.GoodsInfo">
        <id property="id" column="id_"/>
        <result property="name" column="name_"/>
        <result property="desc" column="desc_"/>
        <result property="pic" column="pic_"/>
        <result property="cost" column="cost_"/>
        <result property="type" column="type_"/>
        <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="delFlag" column="del_flag"/>
        <result property="expand1" column="expand_1"/>
        <result property="expand2" column="expand_2"/>
        <result property="scenes" column="scenes_" />
        <result property="isActivation" column="is_activation" />
        <result property="unitPrice" column="unit_price" />
        <result property="unit" column="unit_" />
        <result property="numUnit" column="num_unit"/>


    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.GoodsInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_goods_info
	    (id_,name_,desc_,pic_,cost_,type_,create_by,create_time,update_by,update_time,del_flag,expand_1,expand_2,is_activation,unit_price,unit_,num_unit)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{name,jdbcType=VARCHAR}
            ,#{desc,jdbcType= TIMESTAMP }
            ,#{pic,jdbcType= TIMESTAMP }
            ,#{cost,jdbcType=DECIMAL}
            ,#{type,jdbcType=VARCHAR}
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{expand1,jdbcType=VARCHAR}
            ,#{expand2,jdbcType=VARCHAR}
            ,#{isActivation,jdbcType= NUMERIC }
            ,#{unitPrice,jdbcType=DECIMAL}
            ,#{unit,jdbcType=VARCHAR}
            ,#{numUnit,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_goods_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.GoodsInfo">
        update base_goods_info
        <set>
            <if test="name!=null">
                name_=#{name,jdbcType=VARCHAR },
            </if>
            <if test="desc!=null">
                desc_=#{desc,jdbcType= VARCHAR },
            </if>
            <if test="pic!=null">
                pic_=#{pic,jdbcType=VARCHAR },
            </if>
            <if test="cost!=null">
                cost_=#{cost,jdbcType=DECIMAL},
            </if>
            <if test="type!=null">
                type_=#{type,jdbcType=VARCHAR},
            </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>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="expand1!=null">
                expand_1=#{expand1,jdbcType=VARCHAR },
            </if>
            <if test="expand2!=null">
                expand_2=#{expand2,jdbcType=VARCHAR },
            </if>
            <if test="isActivation!=null">
                is_activation=#{isActivation,jdbcType=NUMERIC },
            </if>
            <if test="unitPrice!=null">
                unit_price=#{unitPrice,jdbcType=NUMERIC },
            </if>
            <if test="unit!=null">
                unit_=#{unit,jdbcType=NUMERIC },
            </if>
            <if test="numUnit!=null">
                num_unit=#{numUnit,jdbcType=NUMERIC },
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="GoodsInfoMap">
        select *
        from base_goods_info
        where id_=#{0} and del_flag = 0
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_goods_info where id_=#{0} and del_flag = 0
    </select>
    <select id="list" resultMap="GoodsInfoMap">
        select id_,name_,desc_,pic_,cost_,type_,create_by,create_time,update_by,update_time,del_flag,expand_1,expand_2,unit_price,unit_,num_unit
        from base_goods_info where del_flag = 0
    </select>
    <select id="findByType" resultMap="GoodsInfoMap">
        <![CDATA[
        select * from base_goods_info
        where del_flag = 0
        and type_ = #{0}
        ]]>
    </select>
    <select id="findBySearch" parameterType="hashmap" resultType="String">
        <![CDATA[
			select id_ from base_goods_info
		]]>
        <where>
            del_flag = 0
            <if test="searchParams.name != null">
                and name_ like #{searchParams.name}
            </if>
            <if test="searchParams.goodTypeId != null">
                and type_ = #{searchParams.goodTypeId}
            </if>
        </where>
    </select>

    <!--expand3作为移动套餐办理地址，不在列表中显示-->
    <select id="search" parameterType="hashmap" resultMap="GoodsInfoMap">
        <![CDATA[
			SELECT * FROM base_goods_info
		]]>
        <where>
            del_flag = 0
            <if test="searchParams.id != null">
                and id_ = #{searchParams.id}
            </if>
            <if test="searchParams.name != null">
                and name_ like #{searchParams.name}
            </if>
            <if test="searchParams.type != null">
                and type_ = #{searchParams.type}
            </if>
            <if test="searchParams.goodInfoIdList != null">
                <foreach collection="searchParams.goodInfoIdList" index="index" item="item" open="and id_ in("
                         separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

</mapper>