FollowTaskMapper.xml 7.59 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.FollowTaskMapper">
    <select
            id="followList"
            resultType="cn.fw.valhalla.domain.dto.FollowPoolDTO"
            parameterType="cn.fw.valhalla.domain.query.FollowPoolQueryVO"
    >
        SELECT t1.id,
        ifnull(t3.plate_no, t4.plate_no)        plate_no,
        t2.expires                              loan_expires,
        t1.type                                 type,
        t1.follow_user                          user_id,
        t1.follow_shop                          shop_id,
        t1.create_time                          start_time,
        t3.buy_date                             buy_date,
        t3.insurance_expires                    insurance_expires,
        t3.arrival_time                         arrival_time,
        (select count(1)
        from follow_record w2
        where w2.task_id = t1.id
        and w2.follow_time is not null)         times,
        TIMESTAMPDIFF(HOUR, now(), t1.deadline) remaining,
        t1.redistribution                       redistribution,
        t1.state                                state,
        if(t1.state = 2, t1.close_time, null)   finish_time,
        if(t1.state = 3, t1.close_time, null)   defeat_time,
        t1.reason                               initiative,
        t1.group_id                             group_id
        FROM follow_task t1
        left join customer t3 on t1.customer_id = t3.id
        left join accident_pool t4 on t1.customer_id = t4.id
        left join customer_loan_info t2 on t3.frame_no = t2.frame_no and t3.group_id = t2.group_id
        <where>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
            <if test="condition.userId !=null">
                and t1.follow_user = #{condition.userId}
            </if>
            <if test="condition.plateNo != null and condition.plateNo !='' ">
                and (t3.plate_no like concat('%', #{condition.plateNo}, '%') or t4.plate_no like concat('%', #{condition.plateNo}, '%'))
            </if>
            <if test="condition.type !=null">
                and t1.type = #{condition.type}
            </if>
            <if test="condition.shopIds !=null">
                and  t1.follow_shop in
                <foreach collection="condition.shopIds" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.closed !=null and condition.closed == 1">
                and t1.state != 1
            </if>
            <if test="condition.closed !=null and condition.closed == 0">
                and t1.state = 1
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 1">
                and t2.expires > now()
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 0">
                and t2.expires &lt;= now()
            </if>
            <if test="condition.startTime1 !=null">
                and t1.create_time >= #{condition.startTime1}
            </if>
            <if test="condition.startTime2 !=null">
                and t1.create_time &lt;=  #{condition.startTime2}
            </if>
            <if test="condition.closeTime1 !=null">
                and t1.close_time >= #{closeTime1}
            </if>
            <if test="condition.closeTime2 !=null">
                and t1.close_time &lt;= #{closeTime2}
            </if>
            <if test="condition.state !=null">
                and t1.state = #{condition.state}
            </if>
            <if test="condition.redistribution !=null">
                and t1.redistribution = #{condition.redistribution}
            </if>
            <if test="condition.initiative !=null">
                and t1.reason = #{condition.initiative}
            </if>
        </where>
        <if test="condition.orderString != null and condition.orderString !='' ">
            ${condition.orderString}
        </if>
        limit #{startIndex},#{pageSize};
    </select>

    <select
            id="followListCount"
            resultType="java.lang.Long"
            parameterType="cn.fw.valhalla.domain.query.FollowPoolQueryVO"
    >
        SELECT count(t1.id)
        FROM follow_task t1
        left join customer t3 on t1.customer_id = t3.id
        left join accident_pool t4 on t1.customer_id = t4.id
        left join customer_loan_info t2 on t3.frame_no = t2.frame_no and t3.group_id = t2.group_id
        <where>
            <if test="condition.groupId !=null">
                and t1.group_id = #{condition.groupId}
            </if>
            <if test="condition.userId !=null">
                and t1.follow_user = #{condition.userId}
            </if>
            <if test="condition.plateNo != null and condition.plateNo !='' ">
                and (t3.plate_no like concat('%', #{condition.plateNo}, '%') or t4.plate_no like concat('%', #{condition.plateNo}, '%'))
            </if>
            <if test="condition.type !=null">
                and t1.type = #{condition.type}
            </if>
            <if test="condition.shopIds !=null">
                and  t1.follow_shop in
                <foreach collection="condition.shopIds" item="id" index="index" open="(" close=")" separator=",">
                    #{id}
                </foreach>
            </if>
            <if test="condition.closed !=null and condition.closed == 1">
                and t1.state != 1
            </if>
            <if test="condition.closed !=null and condition.closed == 0">
                and t1.state = 1
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 1">
                and t2.expires > now()
            </if>
            <if test="condition.loanCustomer !=null and condition.loanCustomer == 0">
                and t2.expires &lt;= now()
            </if>
            <if test="condition.startTime1 !=null">
                and t1.create_time >= #{condition.startTime1}
            </if>
            <if test="condition.startTime2 !=null">
                and t1.create_time &lt;=  #{condition.startTime2}
            </if>
            <if test="condition.completeTime1 !=null or condition.completeTime2 !=null">
                and (
                t1.state = 2
                <if test="condition.completeTime1 !=null">
                    and t1.close_time >= #{condition.completeTime1}
                </if>
                <if test="condition.completeTime2 !=null">
                    and t1.close_time &lt;= #{condition.completeTime2}
                </if>
                )
            </if>
            <if test="condition.defeatTime1 !=null or condition.defeatTime2 !=null">
                and (
                t1.state = 3
                <if test="condition.defeatTime1 !=null">
                    and t1.close_time >= #{condition.defeatTime1}
                </if>
                <if test="condition.defeatTime2 !=null">
                    and t1.close_time &lt;= #{condition.defeatTime2}
                </if>
                )
            </if>
            <if test="condition.state !=null">
                and t1.state = #{condition.state}
            </if>
            <if test="condition.redistribution !=null">
                and t1.redistribution = #{condition.redistribution}
            </if>
            <if test="condition.initiative !=null">
                and t1.reason = #{condition.initiative}
            </if>
        </where>
    </select>
</mapper>