CustomerCluePoolMapper.xml 13.4 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.CustomerCluePoolMapper">
    <select
            id="clueList"
            resultType="cn.fw.valhalla.domain.dto.CustomerCluePoolDTO"
            parameterType="cn.fw.valhalla.domain.query.CustomerCluePoolQueryVO"
    >
        SELECT t2.id                            customer_id,
        if(t1.clue_type=3 , t3.plate_no, t2.plate_no) plate_no,
        t1.clue_type                     type,
        t1.frame_no                      frame_no,
        t2.buy_date                      buy_date,
        t2.arrival_time                  arrival_time,
        t2.insurance_expires             insurance_expires,
        t1.add_time                      add_time,
        t1.start_time                    create_date,
        t1.deadline                      deadline,
        t1.clue_status                   clue_status,
        t1.close_time                    close_time,
        t1.original_user_id              original_user_id,
        t1.original_user_name            original_user,
        t1.original_shop_id              original_shop_id,
        t1.original_shop_name            original_shop,
        t1.finish_user_id                finish_user_id,
        t1.finish_user_name              finish_user,
        t1.finish_shop_id                finish_shop_id,
        t1.finish_shop_name              finish_shop,
        t4.expires                       loan_expires
        FROM customer_clue_pool t1
        left join customer t2 on t1.referer_id = t2.id
        left join accident_pool t3 on t1.referer_id = t3.id
        left join customer_loan_info t4 on t2.frame_no = t4.frame_no and t2.group_id = t4.group_id
        <where>
                t1.clue_status != 1
            <if test="condition.type !=null">
                and t1.clue_type = #{condition.type}
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
            <if test="condition.frameNo !=null and condition.frameNo != ''">
                and t1.frame_no like concat('%', #{condition.frameNo}, '%')
            </if>
            <if test="condition.userId !=null">
                and t1.original_user_id = #{condition.userId}
            </if>
            <if test="condition.userName !=null and condition.userName != ''">
                and t1.original_user_name like concat('%', #{condition.userName}, '%')
            </if>
            <if test="condition.comUserId !=null">
                and t1.finish_user_id = #{condition.comUserId}
            </if>
            <if test="condition.comUserName !=null and condition.comUserName != ''">
                and t1.finish_user_name like concat('%', #{condition.comUserName}, '%')
            </if>
            <if test="condition.plateNo != null and condition.plateNo !=''">
                and (t2.plate_no like concat('%', #{condition.plateNo}, '%') or t3.plate_no like concat('%', #{condition.plateNo}, '%'))
            </if>
            <if test="condition.startTime !=null">
                and DATE_FORMAT(t1.start_time, '%Y-%m') = DATE_FORMAT(#{condition.startTime}, '%Y-%m')
            </if>
            <if test="condition.closeTime1 !=null">
                and DATE_FORMAT(t1.close_time, '%Y-%m-%d') >= DATE_FORMAT(#{condition.closeTime1}, '%Y-%m-%d')
            </if>
            <if test="condition.closeTime2 !=null">
                and DATE_FORMAT(t1.close_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{condition.closeTime2}, '%Y-%m-%d')
            </if>
            <if test="condition.deadline1 !=null">
                and DATE_FORMAT(t1.start_time, '%Y-%m-%d') &lt; DATE_FORMAT(#{condition.deadline1}, '%Y-%m-%d')
                and DATE_FORMAT(t1.deadline, '%Y-%m-%d') >= DATE_FORMAT(#{condition.deadline1}, '%Y-%m-%d')
            </if>
            <if test="condition.deadline2 !=null">
                and DATE_FORMAT(t1.deadline, '%Y-%m-%d') &lt;= DATE_FORMAT(#{condition.deadline2}, '%Y-%m-%d')
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 1">
                and t4.expires > now()
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 0">
                and t4.expires &lt;= now()
            </if>
            <if test="condition.shopIds !=null">
                and  t1.original_shop_id in
                <foreach collection="condition.shopIds" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.comShops !=null">
                and  t1.finish_shop_id in
                <foreach collection="condition.comShops" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.status !=null and condition.status ==2">
                and t1.clue_status = 2
            </if>
            <if test="condition.status !=null and condition.status ==3">
                and (
                    t1.clue_status = 3 and  t1.finish_shop_id in
                    <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                        #{id}
                    </foreach>
                )
            </if>
            <if test="condition.status !=null and condition.status ==4">
                and ((
                        t1.clue_status = 3 and  t1.finish_shop_id not in
                        <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                            #{id}
                        </foreach>
                    ) or t1.clue_status = 4
                )
            </if>
        </where>
        <if test="condition.orderString != null and condition.orderString !='' ">
            ${condition.orderString}
        </if>
        limit #{startIndex},#{pageSize};
    </select>

    <select
            id="clueListCount"
            resultType="java.lang.Long"
            parameterType="cn.fw.valhalla.domain.query.CustomerCluePoolQueryVO"
    >
        SELECT
        count(t1.id)
        FROM customer_clue_pool t1
        left join customer t2 on t1.referer_id = t2.id
        left join accident_pool t3 on t1.referer_id = t3.id
        left join customer_loan_info t4 on t2.frame_no = t4.frame_no and t2.group_id = t4.group_id
        <where>
            t1.clue_status != 1
            <if test="condition.type !=null">
                and t1.clue_type = #{condition.type}
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
            <if test="condition.frameNo !=null and condition.frameNo != ''">
                and t1.frame_no like concat('%', #{condition.frameNo}, '%')
            </if>
            <if test="condition.userId !=null">
                and t1.original_user_id = #{condition.userId}
            </if>
            <if test="condition.userName !=null and condition.userName != ''">
                and t1.original_user_name like concat('%', #{condition.userName}, '%')
            </if>
            <if test="condition.comUserId !=null">
                and t1.finish_user_id = #{condition.comUserId}
            </if>
            <if test="condition.comUserName !=null and condition.comUserName != ''">
                and t1.finish_user_name like concat('%', #{condition.comUserName}, '%')
            </if>
            <if test="condition.plateNo != null and condition.plateNo !=''">
                and (t2.plate_no like concat('%', #{condition.plateNo}, '%') or t3.plate_no like concat('%', #{condition.plateNo}, '%'))
            </if>
            <if test="condition.startTime !=null">
                and DATE_FORMAT(t1.start_time, '%Y-%m') = DATE_FORMAT(#{condition.startTime}, '%Y-%m')
            </if>
            <if test="condition.closeTime1 !=null">
                and DATE_FORMAT(t1.close_time, '%Y-%m-%d') >= DATE_FORMAT(#{condition.closeTime1}, '%Y-%m-%d')
            </if>
            <if test="condition.closeTime2 !=null">
                and DATE_FORMAT(t1.close_time, '%Y-%m-%d') &lt;= DATE_FORMAT(#{condition.closeTime2}, '%Y-%m-%d')
            </if>
            <if test="condition.deadline1 !=null">
                and DATE_FORMAT(t1.start_time, '%Y-%m-%d') &lt; DATE_FORMAT(#{condition.deadline1}, '%Y-%m-%d')
                and DATE_FORMAT(t1.deadline, '%Y-%m-%d') >= DATE_FORMAT(#{condition.deadline1}, '%Y-%m-%d')
            </if>
            <if test="condition.deadline2 !=null">
                and DATE_FORMAT(t1.deadline, '%Y-%m-%d') &lt;= DATE_FORMAT(#{condition.deadline2}, '%Y-%m-%d')
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 1">
                and t4.expires > now()
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 0">
                and t4.expires &lt;= now()
            </if>
            <if test="condition.comShops !=null">
                and  t1.finish_shop_id in
                <foreach collection="condition.comShops" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.shopIds !=null">
                and  t1.original_shop_id in
                <foreach collection="condition.shopIds" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.status !=null and condition.status ==2">
                and t1.clue_status = 2
            </if>
            <if test="condition.status !=null and condition.status ==3">
                and (
                t1.clue_status = 3 and  t1.finish_shop_id in
                <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
                )
            </if>
            <if test="condition.status !=null and condition.status ==4">
                and ((
                t1.clue_status = 3 and  t1.finish_shop_id not in
                <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
                ) or t1.clue_status = 4
                )
            </if>
        </where>
    </select>

    <select
            id="completeNum"
            resultType="java.lang.Long"
    >
        SELECT
        count(t1.id)
        FROM customer_clue_pool t1
        left join customer t2 on t1.referer_id = t2.id
        left join accident_pool t3 on t1.referer_id = t3.id
        <where>
            DATE_FORMAT(t1.close_time, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m')
            and  t1.original_shop_id in
            <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            and (
            t1.clue_status = 3 and  t1.finish_shop_id in
            <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            )
            <if test="condition.type !=null">
                and t1.clue_type = #{condition.type}
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
        </where>
    </select>


    <select
            id="defeatNum"
            resultType="java.lang.Long"
    >
        SELECT
        count(t1.id)
        FROM customer_clue_pool t1
        left join customer t2 on t1.referer_id = t2.id
        left join accident_pool t3 on t1.referer_id = t3.id
        <where>
            DATE_FORMAT(t1.close_time, '%Y-%m') = DATE_FORMAT(now(), '%Y-%m')
            and  t1.original_shop_id in
            <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            and ((
            t1.clue_status = 3 and  t1.finish_shop_id not in
            <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            ) or t1.clue_status = 4
            )
            <if test="condition.type !=null">
                and t1.clue_type = #{condition.type}
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
        </where>
    </select>

    <select
            id="onGoingNum"
            resultType="java.lang.Long"
    >
        SELECT
        count(t1.id)
        FROM customer_clue_pool t1
        left join customer t2 on t1.referer_id = t2.id
        left join accident_pool t3 on t1.referer_id = t3.id
        <where>
            t1.clue_status = 2
            and  t1.original_shop_id in
            <foreach collection="condition.scope" item="id" index="index" open="(" close=")" separator=",">
                #{id}
            </foreach>
            <if test="condition.type !=null">
                and t1.clue_type = #{condition.type}
            </if>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
        </where>
    </select>
</mapper>