<?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.ruoyi.busi.mapper.BusiProdNewMapper">

    <resultMap type="com.ruoyi.busi.vo.ProdNewVO" id="BusiProdNewResult">
        <result property="id" column="id"/>
        <result property="catgId" column="catg_id"/>
        <result property="title" column="title"/>
        <result property="prodTitle" column="prod_title"/>
        <result property="prodKeyword" column="prod_keyword"/>
        <result property="prodDescription" column="prod_description"/>
        <result property="newsFrom" column="news_from"/>
        <result property="mainPic" column="main_pic"/>
        <result property="pics" column="pics"/>
        <result property="description" column="description"/>
        <result property="content" column="content"/>
        <result property="sort" column="sort"/>
        <result property="ifReco" column="if_reco"/>
        <result property="ifPublic" column="if_public"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="creator" column="creator"/>
        <result property="createTime" column="create_time"/>
        <result property="updater" column="updater"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>

        <result property="catgName" column="catg_name"/>
        <result property="userName" column="user_name"/>
    </resultMap>

    <sql id="selectBusiProdNewVo">
        select id,
               catg_id,
               title,
               prod_title,
               prod_keyword,
               prod_description,
               news_from,
               main_pic,
               pics,
               description,
               content,
               sort,
               if_reco,
               if_public,
               tenant_id,
               creator,
               create_time,
               updater,
               update_time,
               del_flag
        from dl_busi_prod_new
    </sql>

    <select id="queryListPage" parameterType="BusiProdNew" resultMap="BusiProdNewResult">
        SELECT
        product.*,
        su.nick_name AS user_name ,
        dbc.catg_name AS catg_name
        FROM
        dl_busi_prod_new product
        LEFT JOIN sys_user su ON product.creator = su.user_id
        LEFT JOIN dl_busi_category dbc ON product.catg_id = dbc.id
        <where>
            product.del_flag = '0'
            AND product.tenant_id = #{entity.tenantId}
            <if test="entity.ifReco != null">
                AND product.if_reco = #{entity.ifReco}
            </if>
            <if test="entity.ifPublic != null">
                AND product.if_public = #{entity.ifPublic}
            </if>
            <if test="entity.catgId != null  and entity.catgId != ''">
                AND product.catg_id = #{entity.catgId}
            </if>
            <if test="entity.title != null  and entity.title != ''">
                AND product.title like concat('%', #{entity.title},
                '%')
            </if>
            <if test="entity.newsFrom != null  and entity.newsFrom != ''">
                AND product.news_from like concat('%',
                #{entity.newsFrom}, '%')
            </if>
        </where>
        ORDER BY product.sort DESC
    </select>
    <select id="selectMaxSort" resultType="java.lang.Long">
        SELECT
            MAX( sort )
        FROM
            dl_busi_prod_new
        WHERE
            del_flag = '0'
          AND tenant_id = #{tenantId}
    </select>
</mapper>