<?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.diaoyun.zion.chinafrica.dao.TbCfStationItemDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity" id="tbCfStationItemMap">
        <result property="itemId" column="item_id"/>
        <result property="itemCode" column="item_code"/>
        <result property="itemName" column="item_name"/>
        <result property="itemBrief" column="item_brief"/>
        <result property="itemCategory" column="item_category"/>
        <result property="itemPrice" column="item_price"/>
        <result property="itemUrl" column="item_url"/>
        <result property="itemImg" column="item_img"/>
        <result property="itemNum" column="item_num"/>
        <result property="platformCode" column="platform_code"/>
        <result property="platformName" column="platform_name"/>
        <result property="enableFlag" column="enable_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="itemCategorytwo" column="item_categorytwo"/>
        <result property="itemDescritionId" column="item_descrition_id"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
		select
			`item_id`,
			`item_code`,
			`item_name`,
			`item_brief`,
			`item_category`,
			`item_price`,
			`item_url`,
			`item_img`,
			`item_num`,
			`platform_code`,
			`platform_name`,
			`enable_flag`,
			`create_time`,
			`item_categorytwo`,
			`item_descrition_id`
		from tb_cf_station_item
		where item_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
		select
    		`item_id`,
    		`item_code`,
    		`item_name`,
    		`item_brief`,
    		`item_category`,
    		`item_price`,
    		`item_url`,
    		`item_img`,
    		`item_num`,
    		`platform_code`,
    		`platform_name`,
    		`enable_flag`,
    		`create_time`,
    		`item_categorytwo`,
    		`item_descrition_id`
		from tb_cf_station_item
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by item_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_station_item
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
		insert into tb_cf_station_item(
			`item_id`,
			`item_code`,
			`item_name`,
			`item_brief`,
			`item_category`,
			`item_price`,
			`item_url`,
			`item_img`,
			`item_num`,
			`platform_code`,
			`platform_name`,
			`enable_flag`,
			`create_time`,
			`item_categorytwo`,
			`item_descrition_id`)
		values(
			#{itemId},
			#{itemCode},
			#{itemName},
			#{itemBrief},
			#{itemCategory},
			#{itemPrice},
			#{itemUrl},
			#{itemImg},
			#{itemNum},
			#{platformCode},
			#{platformName},
			#{enableFlag},
			#{createTime},
			#{itemCategorytwo},
			#{itemDescritionId})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
		update tb_cf_station_item 
		<set>
			<if test="itemCode != null">`item_code` = #{itemCode}, </if>
			<if test="itemName != null">`item_name` = #{itemName}, </if>
			<if test="itemBrief != null">`item_brief` = #{itemBrief}, </if>
			<if test="itemCategory != null">`item_category` = #{itemCategory}, </if>
			<if test="itemPrice != null">`item_price` = #{itemPrice}, </if>
			<if test="itemUrl != null">`item_url` = #{itemUrl}, </if>
			<if test="itemImg != null">`item_img` = #{itemImg}, </if>
			<if test="itemNum != null">`item_num` = #{itemNum}, </if>
			<if test="platformCode != null">`platform_code` = #{platformCode}, </if>
			<if test="platformName != null">`platform_name` = #{platformName}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="itemCategorytwo != null">`item_categorytwo` = #{itemCategorytwo}, </if>
			<if test="itemDescritionId != null">`item_descrition_id` = #{itemDescritionId}</if>
		</set>
		where item_id = #{itemId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_station_item where item_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_station_item where item_id in 
		<foreach item="itemId" collection="array" open="(" separator="," close=")">
			#{itemId}
		</foreach>
	</delete>

	<!--获取商品独立站-->
	<select id="getItemStationList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
        select `item_id`,
    		`item_code`,
    		`item_name`,
    		`item_brief`,
    		`item_category`,
    		`item_price`,
    		`item_url`,
    		`item_img`,
    		`item_num`,
    		`platform_code`,
    		`platform_name`,
    		`enable_flag`,
    		`create_time`,
    		`item_categorytwo`,
    		`item_descrition_id`
    		 from tb_cf_station_item
        where enable_flag=1 and item_category = #{categoryId}
        order by item_num desc

    </select>

	<select id="getGoodsTypeList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfStationItemEntity">
		select
			`item_id`,
    		`item_code`,
    		`item_name`,
    		`item_brief`,
    		`item_category`,
    		`item_price`,
    		`item_url`,
    		`item_img`,
    		`item_num`,
    		`platform_code`,
    		`platform_name`,
    		`enable_flag`,
    		`create_time`,
    		`item_categorytwo`,
    		`item_descrition_id`
		from tb_cf_station_item
		where enable_flag=1 and item_category = #{categoryId} order by item_num desc limit 0,4
	</select>

</mapper>