<?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.demo.mapper.BrandMapper">
    <resultMap type="com.ruoyi.demo.entity.Brand" id="BrandResult">
        <result property="brandId" column="brand_id"/>
        <result property="brandImg" column="brand_img"/>
        <result property="brandName" column="brand_name"/>
        <result property="industryCode" column="industry_code"/>
        <result property="enterpriseUsci" column="enterprise_usci"/>
        <result property="perCapitaConsumption" column="per_capita_consumption"/>
        <result property="commentCount" column="comment_count"/>
        <result property="score" column="score"/>
        <result property="menuInfo" column="menu_info"/>
        <result property="indexScore" column="index_score"/>
        <result property="contact" column="contact"/>
        <result property="telephone" column="telephone"/>
        <result property="createDate" column="create_date"/>
        <result property="audit" column="audit"/>
        <result property="collectPerson" column="collect_person"/>
        <result property="collectTime" column="collect_time"/>
        <result property="enterTime" column="enter_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="hash" column="hash"/>
        <result property="showDelete" column="show_delete"/>
    </resultMap>
    <resultMap type="com.ruoyi.demo.entity.bo.BrandSearch" id="BrandSearchResult">
        <result property="brandId" column="brand_id"/>
        <result property="brandImg" column="brand_img"/>
        <result property="brandName" column="brand_name"/>
        <result property="indexScore" column="index_score"/>
        <result property="enterpriseName" column="enterprise_usci"/>
        <result property="coverCityCount" column="cover_city_count"/>
        <result property="total" column="total"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
    <resultMap type="com.ruoyi.demo.entity.bo.BrandAddrDistribution" id="AddrDisResult">
        <result property="addrCode" column="addr_code"/>
        <result property="count" column="count"/>
    </resultMap>
    <select id="searchByIndustryCodeList" resultMap="BrandResult">
        select * from ddt_brand where industry_code = #{industryCode} and brand_id <![CDATA[<>]]> #{brandId} and show_delete=0
    </select>
    <select id="searchSearchByMulti" resultMap="BrandSearchResult">
        SELECT
            db.brand_id as brand_id,
            db.brand_name as brand_name,
            brand_img,
            enterprise_usci,
            index_score,
            cover_city_count,
            total,
            bbs.update_time as update_time
        FROM
            `ddt_brand` db,
            `bl_brand_statistics` bbs
        WHERE
            bbs.brand_id = db.brand_id and show_delete=0
        <if test="text != null">
            AND db.brand_name LIKE concat('%',#{text},'%')
        </if>
        <if test="industryCode != null">
            <foreach collection="industryCode" item="industry_code" open="AND db.industry_code IN (" separator="," close=")">
                #{industry_code,jdbcType=VARCHAR}
            </foreach>
        </if>
        <if test="countDown != null">
            AND #{countDown} <![CDATA[<=]]> total
        </if>
        <if test="countUp">
            AND total <![CDATA[<=]]> #{countUp}
        </if>
        <if test="coverDown != null">
            AND #{coverDown} <![CDATA[<=]]> cover_city_count
        </if>
        <if test="coverUp != null">
            AND cover_city_count <![CDATA[<=]]> #{coverUp}
        </if>
    </select>
    <select id="list" parameterType="com.ruoyi.demo.entity.vo.BrandVo" resultType="com.ruoyi.demo.entity.Brand">
        select * from ddt_brand
        <where>
            <if test="brandName != null and brandName != ''">
                and brand_name like concat('%',#{brandName},'%')
            </if>
            <if test="showDelete != -1">
                and show_delete = #{showDelete}
            </if>
            <if test="industryCode != null and industryCode != ''">
                and industry_code = #{industryCode}
            </if>
        </where>
    </select>
    <update id="recoverBrand" parameterType="java.lang.String" >
        update ddt_brand set show_delete = 0 where brand_id = #{brand_id}
    </update>
    <select id="selectCountByYear" resultType="java.lang.Integer">
    SELECT
        COUNT(*)
    FROM
        `ddt_brand`
    WHERE
        show_delete = 0
      AND DATE_FORMAT(create_date, '%Y') = #{year}
    <if test="industryCodes != null">
        <foreach collection="industryCodes" item="code" open="AND industry_code in (" separator="," close=")">
            #{code,jdbcType=VARCHAR}
        </foreach>
    </if>;
</select>
</mapper>
