GoodsMapper.xml 11.7 KB
<?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.yoho.search.dal.GoodsMapper">
    <resultMap id="BaseResultMap" type="com.yoho.search.dal.model.Goods">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="product_id" property="productId" jdbcType="INTEGER"/>
        <result column="factory_sn" property="factorySn" jdbcType="VARCHAR"/>
        <result column="goods_name" property="goodsName" jdbcType="VARCHAR"/>
        <result column="color_id" property="colorId" jdbcType="INTEGER"/>
        <result column="color_name" property="colorName" jdbcType="VARCHAR"/>
        <result column="color_image" property="colorImage" jdbcType="VARCHAR"/>
        <result column="is_down" property="isDown" jdbcType="CHAR"/>
        <result column="match_explain" property="matchExplain"
                jdbcType="VARCHAR"/>
        <result column="view_num" property="viewNum" jdbcType="INTEGER"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="is_default" property="isDefault" jdbcType="CHAR"/>
        <result column="product_skc" property="productSkc" jdbcType="INTEGER"/>
        <result column="first_shelve_time" property="firstShelveTime"
                jdbcType="INTEGER"/>
    </resultMap>
    <resultMap id="goodsResultMap" type="java.util.Map">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="product_id" property="productId" jdbcType="INTEGER"/>
        <result column="color_id" property="colorId" jdbcType="INTEGER"/>
        <result column="color_name" property="colorName" jdbcType="VARCHAR"/>
        <result column="color_image" property="colorImage" jdbcType="VARCHAR"/>
        <result column="is_default" property="isDefault" jdbcType="CHAR"/>
        <result column="product_skc" property="productSkc" jdbcType="INTEGER"/>
        <result column="color_code" property="colorCode" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="cover_1" property="cover1" jdbcType="VARCHAR"/>
        <result column="cover_2" property="cover2" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
		id, product_id, factory_sn, goods_name, color_id,
		color_name,
		color_image, is_down,
		match_explain, view_num, status,
		is_default, product_skc, first_shelve_time
	</sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
            parameterType="java.lang.Integer" timeout="20000">
        select
        <include refid="Base_Column_List"/>
        from goods
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"
            timeout="20000">
		delete from goods
		where id = #{id,jdbcType=INTEGER}
	</delete>
    <insert id="insert" parameterType="com.yoho.search.dal.model.Goods">
		insert ignore into goods (id,
		product_id, factory_sn,
		goods_name, color_id, color_name,
		color_image,
		is_down, match_explain,
		view_num, status, is_default,
		product_skc,
		first_shelve_time)
		values (#{id,jdbcType=INTEGER},
		#{productId,jdbcType=INTEGER},
		#{factorySn,jdbcType=VARCHAR},
		#{goodsName,jdbcType=VARCHAR}, #{colorId,jdbcType=INTEGER},
		#{colorName,jdbcType=VARCHAR},
		#{colorImage,jdbcType=VARCHAR},
		#{isDown,jdbcType=CHAR},
		#{matchExplain,jdbcType=VARCHAR},
		#{viewNum,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
		#{isDefault,jdbcType=CHAR},
		#{productSkc,jdbcType=INTEGER},
		#{firstShelveTime,jdbcType=INTEGER})
	</insert>
    <insert id="insertSelective" parameterType="com.yoho.search.dal.model.Goods"
            timeout="20000">
        insert into goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="productId != null">
                product_id,
            </if>
            <if test="factorySn != null">
                factory_sn,
            </if>
            <if test="goodsName != null">
                goods_name,
            </if>
            <if test="colorId != null">
                color_id,
            </if>
            <if test="colorName != null">
                color_name,
            </if>
            <if test="colorImage != null">
                color_image,
            </if>
            <if test="isDown != null">
                is_down,
            </if>
            <if test="matchExplain != null">
                match_explain,
            </if>
            <if test="viewNum != null">
                view_num,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="isDefault != null">
                is_default,
            </if>
            <if test="productSkc != null">
                product_skc,
            </if>
            <if test="firstShelveTime != null">
                first_shelve_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="productId != null">
                #{productId,jdbcType=INTEGER},
            </if>
            <if test="factorySn != null">
                #{factorySn,jdbcType=VARCHAR},
            </if>
            <if test="goodsName != null">
                #{goodsName,jdbcType=VARCHAR},
            </if>
            <if test="colorId != null">
                #{colorId,jdbcType=INTEGER},
            </if>
            <if test="colorName != null">
                #{colorName,jdbcType=VARCHAR},
            </if>
            <if test="colorImage != null">
                #{colorImage,jdbcType=VARCHAR},
            </if>
            <if test="isDown != null">
                #{isDown,jdbcType=CHAR},
            </if>
            <if test="matchExplain != null">
                #{matchExplain,jdbcType=VARCHAR},
            </if>
            <if test="viewNum != null">
                #{viewNum,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="isDefault != null">
                #{isDefault,jdbcType=CHAR},
            </if>
            <if test="productSkc != null">
                #{productSkc,jdbcType=INTEGER},
            </if>
            <if test="firstShelveTime != null">
                #{firstShelveTime,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.yoho.search.dal.model.Goods"
            timeout="20000">
        update goods
        <set>
            <if test="productId != null">
                product_id = #{productId,jdbcType=INTEGER},
            </if>
            <if test="factorySn != null">
                factory_sn = #{factorySn,jdbcType=VARCHAR},
            </if>
            <if test="goodsName != null">
                goods_name = #{goodsName,jdbcType=VARCHAR},
            </if>
            <if test="colorId != null">
                color_id = #{colorId,jdbcType=INTEGER},
            </if>
            <if test="colorName != null">
                color_name = #{colorName,jdbcType=VARCHAR},
            </if>
            <if test="colorImage != null">
                color_image = #{colorImage,jdbcType=VARCHAR},
            </if>
            <if test="isDown != null">
                is_down = #{isDown,jdbcType=CHAR},
            </if>
            <if test="matchExplain != null">
                match_explain = #{matchExplain,jdbcType=VARCHAR},
            </if>
            <if test="viewNum != null">
                view_num = #{viewNum,jdbcType=INTEGER},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=INTEGER},
            </if>
            <if test="isDefault != null">
                is_default = #{isDefault,jdbcType=CHAR},
            </if>
            <if test="productSkc != null">
                product_skc = #{productSkc,jdbcType=INTEGER},
            </if>
            <if test="firstShelveTime != null">
                first_shelve_time = #{firstShelveTime,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.yoho.search.dal.model.Goods"
            timeout="20000">
		update goods
		set product_id = #{productId,jdbcType=INTEGER},
		factory_sn = #{factorySn,jdbcType=VARCHAR},
		goods_name =
		#{goodsName,jdbcType=VARCHAR},
		color_id = #{colorId,jdbcType=INTEGER},
		color_name = #{colorName,jdbcType=VARCHAR},
		color_image =
		#{colorImage,jdbcType=VARCHAR},
		is_down = #{isDown,jdbcType=CHAR},
		match_explain = #{matchExplain,jdbcType=VARCHAR},
		view_num =
		#{viewNum,jdbcType=INTEGER},
		status = #{status,jdbcType=INTEGER},
		is_default = #{isDefault,jdbcType=CHAR},
		product_skc =
		#{productSkc,jdbcType=INTEGER},
		first_shelve_time =
		#{firstShelveTime,jdbcType=INTEGER}
		where id = #{id,jdbcType=INTEGER}
	</update>
    <select id="selectCount" resultType="java.lang.Integer" timeout="20000">
		SELECT count(1) FROM goods
	</select>
    <select id="selectPageLists" resultMap="BaseResultMap" timeout="20000">
        select
        <include refid="Base_Column_List"/>
        from goods limit #{offset},#{pageSize}
    </select>
    <select id="selectGoodListByProductId" resultMap="goodsResultMap"
            parameterType="java.lang.Integer" timeout="20000">
    <![CDATA[
        SELECT a.id,a.product_id,a.color_id,a.color_name,a.color_image,a.is_default,a.product_skc,b.color_code,a.status,c.cover_1,c.cover_2
        FROM goods a LEFT JOIN product_color b ON a.`color_id`=b.`id` LEFT JOIN 
          (SELECT a.goods_id,GROUP_CONCAT(CASE a.gender_cover WHEN 1 THEN a.image_url END) AS cover_1,GROUP_CONCAT(CASE a.gender_cover WHEN 2 THEN a.image_url END) AS cover_2
           FROM goods_images a WHERE (a.gender_cover <> 0) GROUP BY a.`goods_id`) c ON a.id = c.goods_id  WHERE a.product_id=#{productId,jdbcType=INTEGER}

        ]]>
	</select>
    <resultMap id="ids" type="Integer">
        <result column="id" property="Id" jdbcType="INTEGER"/>
    </resultMap>
    <select id="selectListByProductIds" resultMap="BaseResultMap"
            parameterType="java.lang.Integer" timeout="20000">
        select
        <include refid="Base_Column_List"/>
        from goods
        where product_id in
        <foreach item="item" index="index" collection="list"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="selectByIdsAndStatus" resultMap="BaseResultMap"
            parameterType="java.lang.Integer" timeout="20000">
        select
        <include refid="Base_Column_List"/>
        from goods
        where status=1 AND
        product_id in
        <foreach item="item" index="index" collection="list"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <resultMap id="selectIdByProductIdsMap" type="Integer">
        <result column="id" property="Id" jdbcType="INTEGER"/>
    </resultMap>
    <select id="selectIdByProductIds" resultMap="selectIdByProductIdsMap" timeout="20000">
        select id
        from goods
        WHERE product_id in
        <foreach item="item" index="index" collection="list"
                 open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    
    <select id="selectListByGoodsIds" resultMap="BaseResultMap">
		select
		<include refid="Base_Column_List"/>
		from goods where id in
		<foreach item="item" index="index" collection="list"
				 open="(" separator="," close=")">
			#{item}
		</foreach>
	</select>
</mapper>