ReceptionHomePageMaterialConfigMapper.xml 10.2 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="cn.com.glsx.dj.mindworkplate.mapper.ReceptionHomePageMaterialConfigMapper">
    <resultMap id="BaseResultMap" type="cn.com.glsx.dj.mindworkplate.model.ReceptionHomePageMaterialConfig">
        <!--
          WARNING - @mbg.generated
        -->
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="business_type" property="businessType" jdbcType="INTEGER"/>
        <result column="created_by" property="createdBy" jdbcType="VARCHAR"/>
        <result column="created_date" property="createdDate" jdbcType="TIMESTAMP"/>
        <result column="updated_by" property="updatedBy" jdbcType="VARCHAR"/>
        <result column="updated_date" property="updatedDate" jdbcType="TIMESTAMP"/>
        <result column="deleted_flag" property="deletedFlag" jdbcType="CHAR"/>
    </resultMap>
    <resultMap id="dtoMap" extends="BaseResultMap"
               type="cn.com.glsx.dj.mindworkplate.dto.ReceptionHomePageMaterialConfigDTO">
        <result column="merchant_name" property="merchantName" jdbcType="VARCHAR"/>
        <result column="brand_name" property="brandName" jdbcType="VARCHAR"/>
        <result column="sub_brand_name" property="subBrandName" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
        -->
        id, business_type, created_by, created_date, updated_by, updated_date, deleted_flag
    </sql>
    <select id="findHomePageConfigPage2" resultMap="dtoMap">
        select rhpmc.*,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 1 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS merchant_name,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 2 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS brand_name,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 3 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS sub_brand_name
        from reception_home_page_material_config rhpmc
        left join reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
        left join reception_home_page_config_rel rhpcr1 on rhpmc.id = rhpcr1.config_id and rhpcr1.deleted_flag = 'N' and
        rhpcr1.rel_type = 1
        left join reception_home_page_config_rel rhpcr2 on rhpmc.id = rhpcr2.config_id and rhpcr2.deleted_flag = 'N' and
        rhpcr2.rel_type = 2
        left join reception_home_page_config_rel rhpcr3 on rhpmc.id = rhpcr3.config_id and rhpcr3.deleted_flag = 'N' and
        rhpcr3.rel_type = 3 and rhpcr3.rel_parent_id = rhpcr2.id
        where rhpmc.deleted_flag = 'N'
        <if test="condition.merchantId != null">
            and (rhpcr1.rel_business_id = -1 or rhpcr1.rel_business_id = #{condition.merchantId})
        </if>
        <if test="condition.brandId != null">
            and (rhpcr2.rel_business_id = -1 or rhpcr2.rel_business_id = #{condition.brandId})
            <if test="condition.subBrandId != null">
                and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id = #{condition.subBrandId})
            </if>
        </if>
        group by rhpmc.id
        order by rhpmc.created_date desc
    </select>
    <select id="findHomePageConfigPage" resultMap="dtoMap">
        select rhpmc.*,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 1 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS merchant_name,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 2 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS brand_name,
        GROUP_CONCAT(DISTINCT
        CASE WHEN rhpcr.rel_type = 3 THEN rhpcr.rel_item_name END
        SEPARATOR ',') AS sub_brand_name
        from reception_home_page_material_config rhpmc
        left join reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
        where rhpmc.deleted_flag = 'N'
        and rhpmc.id in (select rhpmc.id from reception_home_page_material_config rhpmc
        LEFT JOIN reception_home_page_config_rel rhpcr on rhpmc.id = rhpcr.config_id and rhpcr.deleted_flag = 'N'
        where rhpmc.deleted_flag = 'N'
        <if test="condition.merchantName != null and condition.merchantName != ''">
            and rhpcr.rel_type = 1 and (rhpcr.rel_business_id = -1
            or rhpcr.rel_item_name like concat('%', #{condition.merchantName}, '%'))
        </if>
        <if test="condition.merchantId != null">
            and rhpcr.rel_type = 1 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.merchantId})
        </if>
        <if test="condition.brandId != null">
            and rhpcr.rel_type = 2 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.brandId})
        </if>
        <if test="condition.subBrandId != null">
            and rhpcr.rel_type = 3 and (rhpcr.rel_business_id = -1 or rhpcr.rel_business_id = #{condition.subBrandId})
        </if>
        group by rhpmc.id)
        group by rhpmc.id
        order by rhpmc.created_date desc
    </select>
    <select id="findHomePageVersionByCondition" resultMap="dtoMap">
        select rhpmc.id,rhpcr1.rel_business_id merchantId,rhpcr1.rel_item_name merchantName,
        rhpcr2.rel_business_id brandId,rhpcr2.rel_item_name brandName,
        rhpcr3.rel_business_id subBrandId,rhpcr3.rel_item_name subBrandName
        from reception_home_page_material_config rhpmc
        left join reception_home_page_config_rel rhpcr1 on rhpmc.id = rhpcr1.config_id and rhpcr1.deleted_flag = 'N' and
        rhpcr1.rel_type = 1
        left join reception_home_page_config_rel rhpcr2 on rhpmc.id = rhpcr2.config_id and rhpcr2.deleted_flag = 'N' and
        rhpcr2.rel_type = 2
        left join reception_home_page_config_rel rhpcr3 on rhpmc.id = rhpcr3.config_id and rhpcr3.deleted_flag = 'N' and
        rhpcr3.rel_type = 3 and rhpcr3.rel_parent_id = rhpcr2.rel_business_id
        where rhpmc.deleted_flag = 'N'
        and (rhpcr1.rel_business_id = -1
        <if test="condition.merchantId != null">
            or rhpcr1.rel_business_id = #{condition.merchantId}
        </if>
        )
        <if test="condition.brandId != null">
            and (rhpcr2.rel_business_id = -1
            or rhpcr2.rel_business_id = #{condition.brandId}
            <if test="condition.subBrandId != null">
                and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id = #{condition.subBrandId}
                or (rhpcr2.rel_business_id is not null and rhpcr3.rel_business_id is null))
            </if>
            )
        </if>
        <if test="condition.brandIdList != null and !condition.brandIdList.isEmpty()">
            and (rhpcr2.rel_business_id = -1
            or rhpcr2.rel_business_id IN
            <foreach item="id" collection="condition.brandIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
            <if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
                and (rhpcr3.rel_business_id = -1 or rhpcr3.rel_business_id IN
                <foreach item="id" collection="condition.subBrandIdList" open="(" separator="," close=")">
                    #{id}
                </foreach>
                or (rhpcr2.rel_business_id is not null and rhpcr3.rel_business_id is null))
            </if>
            )
        </if>
        group by rhpmc.id order by rhpcr3.rel_business_id desc,rhpcr2.rel_business_id desc,rhpcr1.rel_business_id desc
        limit 1
    </select>
    <select id="selectConfigByBusinessIds" resultMap="dtoMap">
        SELECT t.*,
        CASE WHEN r1.rel_type = 1 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS merchant_name,
        CASE WHEN r1.rel_type = 2 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS brand_name,
        CASE WHEN r1.rel_type = 3 and r1.rel_business_id != -1 THEN r1.rel_item_name END AS sub_brand_name,
        CASE WHEN r1.rel_type = 1 and r1.rel_business_id != -1 THEN 3
        WHEN r1.rel_type = 2 and r1.rel_business_id != -1 THEN 2
        WHEN r1.rel_type = 3 and r1.rel_business_id != -1 THEN 1
        ELSE 4 END AS sort_priority
        from reception_home_page_material_config t
        left join reception_home_page_config_rel r1 on t.id = r1.config_id
        WHERE r1.deleted_flag = 'N' and t.deleted_flag = 'N'
        AND (
        <if test="condition.brandIdList != null and !condition.brandIdList.isEmpty()">
            (r1.rel_type = 2 AND (r1.rel_business_id IN
            <foreach item="id" collection="condition.brandIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
            OR r1.rel_business_id = -1))
            <if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
                OR
            </if>
        </if>
        <if test="condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()">
            (r1.rel_type = 3
            AND (
            (r1.rel_business_id IN
            <foreach item="id" collection="condition.subBrandIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
            ) OR r1.rel_business_id = -1
            OR
            EXISTS (
            SELECT 1
            FROM reception_home_page_config_rel r2
            WHERE r2.rel_type = 2
            AND r2.rel_business_id = -1
            AND r2.rel_parent_id = r1.rel_parent_id ) ) )
            <!--            <if test="condition.merchantIdList != null and !condition.merchantIdList.isEmpty()">-->
            <!--                OR-->
            <!--            </if>-->
        </if>
        <if test="condition.merchantIdList != null and !condition.merchantIdList.isEmpty()
                    and ((condition.brandIdList != null and !condition.brandIdList.isEmpty())
                    or (condition.subBrandIdList != null and !condition.subBrandIdList.isEmpty()))">
            or (r1.rel_type = 1 AND (r1.rel_business_id IN
            <foreach item="id" collection="condition.merchantIdList" open="(" separator="," close=")">
                #{id}
            </foreach>
            ) and r1.rel_business_id != -1)
        </if>
        )
        group by t.id having count(t.id) > 1
        ORDER BY sort_priority ASC
    </select>
</mapper>