CustomerMapper.xml 15.1 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.fw.valhalla.dao.mapper.CustomerMapper">
    <select
            id="getAppPageList"
            resultType="cn.fw.valhalla.domain.vo.customer.CustomerListVO"
            parameterType="cn.fw.valhalla.domain.query.CustomerQueryVO"
    >
        SELECT
        t1.id, name AS ownerName, t1.car_image, t1.plate_no, t1.cus_level, t1.frame_no,
        CONCAT_WS(' ', NULLIF(t1.brand_name, ''), NULLIF(t1.series_name, ''), NULLIF(t1.spec_name, '')) AS carName,
        t1.tags
        FROM customer t1 left join customer_base_info t2 on t1.base_id = t2.id
        <where>
            t1.yn = 1
            <if test="condition.keyword != null and condition.keyword !='' ">
                and (t2.`name` like concat('%', #{condition.keyword}, '%')
                or t1.`plate_no` like concat('%', #{condition.keyword}, '%')
                or t1.`frame_no` like concat('%', #{condition.keyword}, '%'))
            </if>
            <if test="condition.regionCode !=null and condition.regionCode != ''">
                and t2.city_code like concat(#{condition.regionCode}, '%')
            </if>
            <if test="condition.companyName != null and condition.companyName != ''">
                and t2.`company_name` like concat('%', #{condition.keyword}, '%')
            </if>
            <if test="condition != null and condition.levels != null and condition.levels.size > 0">
                and t1.cus_level IN
                <foreach collection="condition.levels" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="condition != null and condition.tags != null and condition.tags.size() > 0">
                and
                <foreach collection="condition.tags" item="item" separator="or" open="(" close=")">
                    t1.tags LIKE concat('%', #{item}, '%')
                </foreach>
            </if>
            <if test="condition.brandId !=null">
                and t1.brand_id = #{condition.brandId}
            </if>
            <if test="condition.seriesId !=null">
                and t1.series_id = #{condition.seriesId}
            </if>
            <if test="condition.specId !=null">
                and t1.spec_id = #{condition.specId}
            </if>
            <if test="condition.gender !=null">
                and t2.gender = #{condition.gender}
            </if>
            <if test="condition.cusType !=null">
                and t2.cus_type = #{condition.cusType}
            </if>
            <if test="condition.month !=null">
                and month(t2.birthday) = #{condition.month}
            </if>
            <if test="condition.endBirthday !=null">
                and t2.birthday >= #{condition.endBirthday}
            </if>
            <if test="condition.startBirthday !=null">
                and t2.birthday &lt;= #{condition.startBirthday}
            </if>
            <if test="condition.leftCreatTime !=null">
                and t1.create_time >= #{condition.leftCreatTime}
            </if>
            <if test="condition.rightCreatTime !=null">
                and t1.create_time &lt;= #{condition.rightCreatTime}
            </if>
            <if test="condition != null and condition.shopIds != null and condition.shopIds.size() > 0">
                and t1.shop_id IN
                <foreach collection="condition.shopIds" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
            <if test="condition.consultantId !=null">
                and t1.adviser_id = #{condition.consultantId}
            </if>
            <if test="condition != null and condition.customerIdList != null and condition.customerIdList.size > 0">
                and t1.id IN
                <foreach collection="condition.customerIdList" item="item" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
        </where>
        order by t1.create_time desc
        limit #{startIndex},#{pageSize};
    </select>

    <select
            id="analyseList"
            resultType="cn.fw.valhalla.domain.dto.StammkundeAnalyseDTO"
            parameterType="cn.fw.valhalla.domain.query.StammkundeAnalyseQueryVO"
    >
        select distinct
        t1.id           customer_id,
        t1.plate_no,
        t2.contact      customer_name,
        t2.address,
        t2.city_code    region_code,
        t2.city_name    region_name,
        t2.lat,
        t2.lng
        from customer t1 inner join customer_base_info t2 on t1.base_id = t2.id
        where  t1.yn = 1 and t1.group_id = #{condition.groupId} and t2.city_code is not null
        <if test="condition.customerIds !=null">
            and  t1.id in
            <foreach collection="condition.customerIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.shopIds !=null">
            and  t1.shop_id in
            <foreach collection="condition.shopIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.minLat !=null">
            and t2.lat >= #{condition.minLat}
        </if>
        <if test="condition.maxLat !=null">
            and t2.lat &lt;= #{condition.maxLat}
        </if>
        <if test="condition.minLng !=null">
            and t2.lng >= #{condition.minLng}
        </if>
        <if test="condition.maxLng !=null">
            and t2.lng &lt;= #{condition.maxLng}
        </if>
    </select>

    <select
            id="queryCustomList"
            resultType="cn.fw.valhalla.domain.dto.CustomerDetailDto"
            parameterType="cn.fw.valhalla.domain.query.CustomCustomerQuery"
    >
        select distinct
        t1.*,
        t2.contact name,
        t2.member_id member_id,
        t2.mobile
        from customer t1 inner join customer_base_info t2 on t1.base_id = t2.id
        left join follow_clue t3 on t1.frame_no=t3.vin and t3.clue_state=2 and t3.clue_type=2
        left join follow_clue t4 on t1.frame_no=t4.vin and t4.clue_state=2 and t4.clue_type=4
        where t1.yn = 1 and t1.group_id = #{condition.groupId}
        and t1.adviser_id is not null
        <if test="condition.shopList !=null and condition.shopList.size() != 0">
            and t1.shop_id in
            <foreach collection="condition.shopList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.excludeCustomerIds !=null and condition.excludeCustomerIds.size() != 0">
            and t1.id not in
            <foreach collection="condition.excludeCustomerIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.includePublic != true">
            and (t1.temporary is null or t1.temporary = 0)
        </if>
        <if test="condition.followType !=null and condition.followType==2">
            and t3.id is not null
        </if>
        <if test="condition.followType !=null and condition.followType==4">
            and t4.id is not null
        </if>
        <if test="condition.frameNo !=null">
            and t1.frame_no = #{condition.frameNo}
        </if>
        <if test="condition.andCondition==true">
            and (
            <trim prefixOverrides="and">
                <if test="condition.minMileage !=null and condition.maxMileage !=null">
                    <if test="condition.minMileage !=null">
                        and t1.current_mileage >= #{condition.minMileage}
                    </if>
                    <if test="condition.maxMileage !=null">
                        and t1.current_mileage &lt;= #{condition.maxMileage}
                    </if>
                </if>

                <if test="condition.minBuyDate !=null and condition.maxBuyDate !=null">
                    <if test="condition.minBuyDate !=null">
                        and t1.buy_date >= #{condition.minBuyDate}
                    </if>
                    <if test="condition.maxBuyDate !=null">
                        and t1.buy_date &lt;= #{condition.maxBuyDate}
                    </if>
                </if>

                <if test="condition.level !=null">
                    and t1.cus_level = #{condition.level}
                </if>
                and t1.adviser_id is not null
            </trim>
            )
        </if>

        <if test="condition.andCondition==false">
            and (
            <trim prefixOverrides="or">
                <if test="condition.minMileage !=null and condition.maxMileage !=null">
                    or (
                    t1.current_mileage is not null
                    <if test="condition.minMileage !=null">
                        and t1.current_mileage >= #{condition.minMileage}
                    </if>
                    <if test="condition.maxMileage !=null">
                        and t1.current_mileage &lt;= #{condition.maxMileage}
                    </if>
                    )
                </if>

                <if test="condition.minBuyDate !=null and condition.maxBuyDate !=null">
                    or (
                    t1.buy_date is not null
                    <if test="condition.minBuyDate !=null">
                        and t1.buy_date >= #{condition.minBuyDate}
                    </if>
                    <if test="condition.maxBuyDate !=null">
                        and t1.buy_date &lt;= #{condition.maxBuyDate}
                    </if>
                    )
                </if>

                <if test="condition.level !=null">
                    or t1.cus_level = #{condition.level}
                </if>
            </trim>
            )
        </if>
    </select>

    <select
            id="queryCustomCount"
            resultType="java.lang.Long"
            parameterType="cn.fw.valhalla.domain.query.CustomCustomerQuery"
    >
        select count(1)
        from customer t1 inner join customer_base_info t2 on t1.base_id = t2.id
        left join follow_clue t3 on t1.frame_no=t3.vin and t3.clue_state=2 and t3.clue_type=2
        left join follow_clue t4 on t1.frame_no=t4.vin and t4.clue_state=2 and t4.clue_type=4
        where t1.yn = 1 and t1.group_id = #{condition.groupId}
        and t1.adviser_id is not null
        <if test="condition.shopList !=null and condition.shopList.size() != 0">
            and t1.shop_id in
            <foreach collection="condition.shopList" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.excludeCustomerIds !=null and condition.excludeCustomerIds.size() != 0">
            and t1.id not in
            <foreach collection="condition.excludeCustomerIds" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
        <if test="condition.includePublic != true">
            and (t1.temporary is null or t1.temporary = 0)
        </if>
        <if test="condition.followType !=null and condition.followType==2">
            and t3.id is not null
        </if>
        <if test="condition.followType !=null and condition.followType==4">
            and t4.id is not null
        </if>
        <if test="condition.frameNo !=null">
            and t1.frame_no = #{condition.frameNo}
        </if>
        <if test="condition.andCondition==true">
            and (
            <trim prefixOverrides="and">
                <if test="condition.minMileage !=null and condition.maxMileage !=null">
                    <if test="condition.minMileage !=null">
                        and t1.current_mileage >= #{condition.minMileage}
                    </if>
                    <if test="condition.maxMileage !=null">
                        and t1.current_mileage &lt;= #{condition.maxMileage}
                    </if>
                </if>

                <if test="condition.minBuyDate !=null and condition.maxBuyDate !=null">
                    <if test="condition.minBuyDate !=null">
                        and t1.buy_date >= #{condition.minBuyDate}
                    </if>
                    <if test="condition.maxBuyDate !=null">
                        and t1.buy_date &lt;= #{condition.maxBuyDate}
                    </if>
                </if>

                <if test="condition.level !=null">
                    and t1.cus_level = #{condition.level}
                </if>
                and t1.adviser_id is not null
            </trim>
            )
        </if>

        <if test="condition.andCondition==false">
            and (
            <trim prefixOverrides="or">
                <if test="condition.minMileage !=null and condition.maxMileage !=null">
                    or (t1.current_mileage is not null
                    <if test="condition.minMileage !=null">
                        and t1.current_mileage >= #{condition.minMileage}
                    </if>
                    <if test="condition.maxMileage !=null">
                        and t1.current_mileage &lt;= #{condition.maxMileage}
                    </if>
                    )
                </if>

                <if test="condition.minBuyDate !=null and condition.maxBuyDate !=null">
                    or (
                    t1.buy_date is not null
                    <if test="condition.minBuyDate !=null">
                        and t1.buy_date >= #{condition.minBuyDate}
                    </if>
                    <if test="condition.maxBuyDate !=null">
                        and t1.buy_date &lt;= #{condition.maxBuyDate}
                    </if>
                    )
                </if>

                <if test="condition.level !=null">
                    or t1.cus_level = #{condition.level}
                </if>
            </trim>
            )
        </if>
    </select>

    <select
            id="queryByKeyword"
            resultType="cn.fw.valhalla.sdk.result.BasicsCustomerDTO"
    >
        select t1.id                                                       customer_id,
               t2.name                                                     customer_name,
               t2.member_id                                                member_id,
               t2.cus_type                                                 cus_type,
               t1.plate_no                                                 plate_no,
               t1.frame_no                                                 frame_no,
               concat_ws(' ', t1.brand_name, t1.series_name, t1.spec_name) car_name,
               t1.shop_id,
               t1.adviser_id
        from customer t1
                 inner join customer_base_info t2 on t1.base_id = t2.id
        where t1.yn = 1
          and (
                    t1.plate_no = #{keyword}
                or right(t1.frame_no, 6) = #{keyword}
                or t2.name = #{keyword}
            )
          and t1.group_id = #{groupId}
    </select>
</mapper>