<?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.hzs.system.home.mapper.HoProductDetailsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.system.home.param.HoProductDetailsParam">
        <id column="PK_ID" property="pkId" />
    <result column="pkAreaClassifyName" property="pkAreaClassifyName" />
        <result column="PICTURE" property="picture" />
        <result column="TITLE_NAME" property="titleName" />
        <result column="CONTENT" property="content" />
        <result column="SORT" property="sort" />
        <result column="TWO_LEVEL_TITLE" property="twoLevelTitle" />
        <result column="COVER_ADDRESS" property="coverAddress" />


    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, PICTURE, TITLE_NAME, CONTENT, PK_HO_PRODUCT_RANGE, SORT, TYPE
    </sql>


    <!--会员端-查询商品展示下拉选-->
    <select id="selectBelowProductDetailsList" parameterType="com.hzs.system.home.param.HoProductDetailsParam"
            resultType="com.hzs.system.home.param.HoProductDetailsParam">
        SELECT
        b.PK_ID,
        b.CLASSIFY_NAME pkAreaClassifyName,
        b.CLASSIFY_IMG picture,
        b.MODIFIED_TIME,
        max(b.sort) sort
        FROM
        HO_PRODUCT_DETAILS a
        INNER JOIN BD_AREA_CLASSIFY b ON a.PK_AREA_CLASSIFY = b.PK_ID
        where a.DEL_FLAG = 0 and b.DEL_FLAG = 0 and b.IS_RECOMMEND=0
        <if test="pkCountry != null">
            AND a.PK_COUNTRY = #{pkCountry}
        </if>
        GROUP BY
        b.PK_ID,
        b.CLASSIFY_NAME,
        b.CLASSIFY_IMG,
        b.MODIFIED_TIME
        ORDER BY sort, b.MODIFIED_TIME DESC
    </select>

<!--    查询站点配置商品列表-->
    <select id="queryProductList" parameterType="com.hzs.system.home.param.HoProductDetailsParam"
            resultType="com.hzs.system.home.vo.HoProductDetailsVO">
        SELECT
        a.PK_ID pkId,
        a.PICTURE picture,
        a.TITLE_NAME titleName,
        a.CONTENT content,
        a.PK_AREA_CLASSIFY pkAreaClassify,
        a.SORT sort,
        a.CREATION_TIME creationTime,
        a.TWO_LEVEL_TITLE twoLevelTitle,
        b.CLASSIFY_NAME pkAreaClassifyName,
        b.CLASSIFY_IMG classifyImg
        FROM
        HO_PRODUCT_DETAILS a
        INNER JOIN BD_AREA_CLASSIFY b ON a.PK_AREA_CLASSIFY = b.PK_ID
        where a.DEL_FLAG = 0 and b.DEL_FLAG = 0 and b.IS_RECOMMEND=0
        <if test="pkCountry != null">
            AND a.PK_COUNTRY = #{pkCountry}
        </if>
        <if test="titleName != null and titleName!=''">
            AND a.TITLE_NAME like #{titleName}||'%'
        </if>
        <if test="startDate != null and endDate != null">
            and a.creation_time between #{startDate, jdbcType=TIMESTAMP} and #{endDate, jdbcType=TIMESTAMP}
        </if>
        ORDER BY a.SORT

    </select>

</mapper>
