|
@@ -0,0 +1,204 @@
|
|
|
+<?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.backendsys.modules.b2c.good.dao.GoodDao">
|
|
|
+
|
|
|
+ <sql id="includeGood">
|
|
|
+ g.id id,
|
|
|
+ g.id good_id,
|
|
|
+ g.uid uid,
|
|
|
+ gc.id category_id,
|
|
|
+ gc.category_name category_name,
|
|
|
+ COALESCE(g.brand_id, -1) brand_id,
|
|
|
+ COALESCE(g.unit_id, -1) unit_id,
|
|
|
+ COALESCE(g.good_thumb, '') good_thumb,
|
|
|
+ COALESCE(g.good_images, '') good_images,
|
|
|
+ gt.good_name good_name,
|
|
|
+ COALESCE(gt.good_description, '') good_description,
|
|
|
+ g.status status,
|
|
|
+ g.is_top is_top,
|
|
|
+ g.create_time create_time,
|
|
|
+ g.update_time update_time
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="includeGoodDetail">
|
|
|
+ g.id id,
|
|
|
+ g.id good_id,
|
|
|
+ g.uid uid,
|
|
|
+ gc.id category_id,
|
|
|
+ gc.category_name category_name,
|
|
|
+ COALESCE(g.brand_id, -1) brand_id,
|
|
|
+ COALESCE(g.unit_id, -1) unit_id,
|
|
|
+ COALESCE(g.good_thumb, '') good_thumb,
|
|
|
+ COALESCE(g.good_images, '') good_images,
|
|
|
+ g.status status,
|
|
|
+ g.is_top is_top,
|
|
|
+ g.create_time create_time,
|
|
|
+ g.update_time update_time
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="includeGoodTranslation">
|
|
|
+ id,
|
|
|
+ good_id,
|
|
|
+ language,
|
|
|
+ good_name,
|
|
|
+ good_description,
|
|
|
+ good_content,
|
|
|
+ COALESCE(meta_keyword, '') meta_keyword,
|
|
|
+ COALESCE(meta_description, '') meta_description
|
|
|
+ </sql>
|
|
|
+ <sql id="leftJoinCategory">
|
|
|
+ LEFT JOIN b2c_good_category_i18n gc ON gc.good_category_id = g.category_id AND gc.language = #{lang}
|
|
|
+ </sql>
|
|
|
+ <sql id="leftJoinTranslations">
|
|
|
+ LEFT JOIN b2c_good_i18n gt ON g.id = gt.good_id
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <sql id="includeGoodDetailFull">
|
|
|
+ g.id id,
|
|
|
+ g.id good_id,
|
|
|
+ gt.language,
|
|
|
+ g.uid uid,
|
|
|
+
|
|
|
+ gc.id category_id,
|
|
|
+ gc.category_name category_name,
|
|
|
+ COALESCE(g.brand_id, -1) brand_id,
|
|
|
+ COALESCE(g.unit_id, -1) unit_id,
|
|
|
+ COALESCE(g.good_thumb, '') good_thumb,
|
|
|
+ COALESCE(g.good_images, '') good_images,
|
|
|
+
|
|
|
+ gt.good_name good_name,
|
|
|
+ COALESCE(gt.good_description, '') good_description,
|
|
|
+ COALESCE(gt.good_content, '') good_content,
|
|
|
+
|
|
|
+ g.status status,
|
|
|
+ g.is_top is_top,
|
|
|
+ g.create_time create_time,
|
|
|
+ g.update_time update_time
|
|
|
+ </sql>
|
|
|
+
|
|
|
+ <resultMap id="resultMapGood" type="java.util.LinkedHashMap">
|
|
|
+ <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
+ <result property="good_id" column="good_id" javaType="java.lang.Long" />
|
|
|
+ <result property="uid" column="uid" />
|
|
|
+ <result property="category_id" column="category_id" javaType="java.lang.Long" />
|
|
|
+ <result property="category_name" column="category_name" />
|
|
|
+ <result property="brand_id" column="brand_id" javaType="java.lang.Long" />
|
|
|
+ <result property="unit_id" column="unit_id" javaType="java.lang.Long" />
|
|
|
+ <result property="good_thumb" column="good_thumb" />
|
|
|
+ <result property="good_images" column="good_images" />
|
|
|
+ <result property="good_name" column="good_name" />
|
|
|
+ <result property="good_description" column="good_description" />
|
|
|
+ <result property="status" column="status" javaType="java.lang.Integer" />
|
|
|
+ <result property="is_top" column="is_top" javaType="java.lang.Integer" />
|
|
|
+ <result property="create_time" column="create_time" />
|
|
|
+ <result property="update_time" column="update_time" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <resultMap id="resultMapGoodDetail" type="java.util.LinkedHashMap">
|
|
|
+ <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
+ <result property="good_id" column="good_id" javaType="java.lang.Long" />
|
|
|
+ <result property="uid" column="uid" />
|
|
|
+ <result property="category_id" column="category_id" javaType="java.lang.Long" />
|
|
|
+ <result property="category_name" column="category_name" />
|
|
|
+ <result property="brand_id" column="brand_id" javaType="java.lang.Long" />
|
|
|
+ <result property="unit_id" column="unit_id" javaType="java.lang.Long" />
|
|
|
+ <result property="good_thumb" column="good_thumb" />
|
|
|
+ <result property="good_images" column="good_images" />
|
|
|
+ <result property="status" column="status" javaType="java.lang.Integer" />
|
|
|
+ <result property="is_top" column="is_top" javaType="java.lang.Integer" />
|
|
|
+ <result property="create_time" column="create_time" />
|
|
|
+ <result property="update_time" column="update_time" />
|
|
|
+ <collection property="translations" javaType="java.util.List"
|
|
|
+ select="queryTranslationsById" column="id">
|
|
|
+ <id property="id" column="id" />
|
|
|
+ <result property="good_name" column="good_name" />
|
|
|
+ <result property="good_description" column="good_description" />
|
|
|
+ <result property="good_content" column="good_content" />
|
|
|
+ <result property="meta_keyword" column="meta_keyword" />
|
|
|
+ <result property="meta_description" column="meta_description" />
|
|
|
+ </collection>
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <resultMap id="resultMapGoodDetailFull" type="java.util.LinkedHashMap">
|
|
|
+ <id property="id" column="id" jdbcType="BIGINT" />
|
|
|
+ <result property="good_id" column="good_id" javaType="java.lang.Long" />
|
|
|
+ <result property="uid" column="uid" />
|
|
|
+ <result property="language" column="language" />
|
|
|
+ <result property="category_id" column="category_id" javaType="java.lang.Long" />
|
|
|
+ <result property="category_name" column="category_name" />
|
|
|
+ <result property="brand_id" column="brand_id" javaType="java.lang.Long" />
|
|
|
+ <result property="unit_id" column="unit_id" javaType="java.lang.Long" />
|
|
|
+ <result property="good_thumb" column="good_thumb" />
|
|
|
+ <result property="good_images" column="good_images" />
|
|
|
+ <result property="good_name" column="good_name" />
|
|
|
+ <result property="good_description" column="good_description" />
|
|
|
+ <result property="good_content" column="good_content" />
|
|
|
+ <result property="meta_keyword" column="meta_keyword" />
|
|
|
+ <result property="meta_description" column="meta_description" />
|
|
|
+ <result property="status" column="status" javaType="java.lang.Integer" />
|
|
|
+ <result property="is_top" column="is_top" javaType="java.lang.Integer" />
|
|
|
+ <result property="create_time" column="create_time" />
|
|
|
+ <result property="update_time" column="update_time" />
|
|
|
+ </resultMap>
|
|
|
+
|
|
|
+ <!-- 查 列表 -->
|
|
|
+ <select id="selectGoodList" resultMap="resultMapGood">
|
|
|
+ SELECT <include refid="includeGood" /> FROM b2c_good g
|
|
|
+ <include refid="leftJoinCategory" />
|
|
|
+ <include refid="leftJoinTranslations" />
|
|
|
+ <where>
|
|
|
+ gt.language = #{lang}
|
|
|
+ <if test="uid != null and uid != ''">
|
|
|
+ AND g.uid = #{uid}
|
|
|
+ </if>
|
|
|
+ <if test="category_id != null and category_id != ''">
|
|
|
+ AND g.category_id = #{category_id}
|
|
|
+ </if>
|
|
|
+ <if test="good_name != null and good_name != ''">
|
|
|
+ AND gt.good_name LIKE CONCAT('%', #{good_name}, '%')
|
|
|
+ </if>
|
|
|
+ <if test="status != null and status != ''">
|
|
|
+ AND g.status = #{status}
|
|
|
+ </if>
|
|
|
+ <if test="create_time_begin != null and create_time_begin != '' and create_time_end != null and create_time_end != ''">
|
|
|
+ AND g.create_time BETWEEN #{create_time_begin} AND #{create_time_end}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ ORDER BY g.is_top = 1 DESC, g.create_time DESC
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查 详情 -->
|
|
|
+ <select id="selectGoodDetail" resultMap="resultMapGoodDetail">
|
|
|
+ SELECT <include refid="includeGoodDetail" />
|
|
|
+ FROM b2c_good g
|
|
|
+ <include refid="leftJoinCategory" />
|
|
|
+ <where>
|
|
|
+ <if test="uid != null and uid != ''">
|
|
|
+ AND g.uid = #{uid}
|
|
|
+ </if>
|
|
|
+ <if test="good_id != null and good_id != ''">
|
|
|
+ AND g.id = #{good_id}
|
|
|
+ </if>
|
|
|
+ </where>
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查 详情 完整 -->
|
|
|
+ <select id="selectGoodDetailFull" resultMap="resultMapGoodDetailFull">
|
|
|
+ SELECT <include refid="includeGoodDetailFull" />
|
|
|
+ FROM b2c_good g
|
|
|
+ <include refid="leftJoinCategory" />
|
|
|
+ <include refid="leftJoinTranslations" />
|
|
|
+ WHERE
|
|
|
+ gt.language = #{lang}
|
|
|
+ AND g.uid = #{uid}
|
|
|
+ AND g.status = #{status}
|
|
|
+ </select>
|
|
|
+
|
|
|
+ <!-- 查 翻译详情 (子查询) -->
|
|
|
+ <select id="queryTranslationsById" resultType="java.util.LinkedHashMap">
|
|
|
+ SELECT <include refid="includeGoodTranslation" />
|
|
|
+ FROM b2c_good_i18n
|
|
|
+ WHERE good_id = #{id}
|
|
|
+ </select>
|
|
|
+
|
|
|
+</mapper>
|