CarBrandMapper.xml 2.98 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="com.bs.cardata.mapper.CarBrandMapper">

    <!-- 结果映射 -->
    <resultMap id="BaseResultMap" type="com.bs.cardata.entity.Carbrand">
        <id column="bid" property="bid"/>
        <result column="brand" property="brand"/>
        <result column="brand_code" property="brandCode"/>
        <result column="bra_country" property="braCountry"/>
        <result column="identifying_photo" property="identifyingPhoto"/>
        <result column="bra_letter" property="braLetter"/>
        <result column="last_operator_name" property="lastOperatorName"/>
        <result column="last_operator_id" property="lastOperatorId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="autohome_id" property="autohomeId"/>
        <result column="operator_type" property="operatorType"/>
        <result column="is_used" property="isUsed"/>
        <result column="parent_id" property="parentId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        bid, brand, brand_code, bra_country, identifying_photo, bra_letter,
        last_operator_name, last_operator_id, create_time, update_time,
        autohome_id, operator_type, is_used, parent_id
    </sql>

    <select id="getCarBrandInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM bs_carbrand
        WHERE parent_id > 0
        <if test="autohomeId != null and autohomeId != ''">
            AND autohome_id = #{autohomeId}
        </if>
        <if test="brand != null and brand != ''">
            AND brand = #{brand}
        </if>
        LIMIT 1
    </select>

    <select id="getCarBrandForParent" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM bs_carbrand
        WHERE parent_id = -2 
          AND autohome_id = #{autohomeId}
          AND is_used = 0
        LIMIT 1
    </select>

    <!-- 根据指定SQL查询所有品牌车型数据 -->
    <select id="selectAllBrandHierarchyData" resultType="com.bs.cardata.dto.CarBrandRawDataDto">
        SELECT 
            pb.brand AS parentName, pb.bid as parentId, pb.bra_letter as parentLetter, pb.identifying_photo as parentPhoto,
            chb.brand AS childName, chb.bid AS childId, chb.bra_letter as childLetter,
            pcs.carseries, pcs.csid, pcs.series_letter
        FROM 
            bs_carbrand AS chb
        INNER JOIN 
            bs_carbrand AS pb ON chb.parent_id = pb.bid and pb.is_used = 0
        LEFT JOIN 
            platform_carseries AS pcs ON chb.bid = pcs.brand_id and pcs.is_used = 0
        WHERE 
            chb.parent_id > 0 and chb.is_used = 0
            AND pb.parent_id = -2
        ORDER BY 
            pb.bra_letter, 
            chb.brand, 
            pcs.carseries
    </select>

</mapper>