FollowTaskMapper.xml 8.04 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 *
        from (SELECT t1.id,
        ifnull(t2.plate_no, t3.plate_no)                                                    plate_no,
        t1.type                                                                             type,
        t1.changed                                                                          redistribution,
        case t1.finished when 1 then t1.finish_user when 0 then t1.follow_user end          user_id,
        case t1.finished when 1 then t1.finish_shop when 0 then t1.follow_shop end          shop_id,
        (select count(1) from follow_record t4
                where t4.task_id = t1.id
                  and t4.user_id = if(t1.finished = 1, t1.finish_user, t1.follow_user)
                  and t4.follow_time is not null )                                          times,
        TIMESTAMPDIFF(HOUR, now(), t1.deadline)                                              remaining,
        case t1.finished
        when 1 then 2
        when 0 then 3
        end                                                                                 state,
        t1.finish_time                                                                      finish_time,
        case t1.finished when 1 then null when 0 then t1.deadline end                       defeat_time,
        if((select count(1) from approve_record t5
            where t5.data_id = t1.id and t5.passed = 1) != 0, 1, 3)                         initiative,
        t1.group_id                                                                          group_id,
        t2.id                                                                               customer_id,
        t1.origin_shop,
        t1.finish_shop,
        t1.finished,
        t1.state                                                                             origin_state
        FROM follow_task t1
        left join customer t2 on t1.customer_id = t2.id
        left join accident_pool t3 on t1.customer_id = t3.id
        where t1.state = 3
        and ((t1.finished = 0 and
        t1.deadline >= #{condition.startTime} and t1.deadline &lt; #{condition.endTime}) or
        (t1.finished = 1 and
        t1.finish_time >= #{condition.startTime} and t1.finish_time &lt; #{condition.endTime}))

        union
        SELECT t1.id,
        ifnull(t2.plate_no, t3.plate_no)                                                    plate_no,
        t1.type                                                                             type,
        0                                                                                   redistribution,
        t1.origin_user                                                                      user_id,
        t1.origin_shop                                                                      shop_id,
        (select count(1) from follow_record t4
               where t4.task_id = t1.id
                and t4.user_id = t1.origin_user
                and t4.follow_time is not null)                                             times,
        TIMESTAMPDIFF(HOUR, now(), t1.deadline)                                              remaining,
        case t1.changed
        when 1 then 3
        when 0 then if(t1.finished = 0, 3, 2)
        end                                                                                 state,
        t1.finish_time                                                                      finish_time,
        t1.change_user_time                                                                 defeat_time,
        if((select count(1) from approve_record t5
            where t5.data_id = t1.id and t5.passed = 1) != 0, 1, 2)                         initiative,
        t1.group_id                                                                         group_id,
        t2.id                                                                               customer_id,
        t1.origin_shop,
        t1.finish_shop,
        t1.finished,
        t1.state                                                                             origin_state
        FROM follow_task t1
        left join customer t2 on t1.customer_id = t2.id
        left join accident_pool t3 on t1.customer_id = t3.id
        where t1.state = 3
        and t1.type != 3
        and ((t1.finished = 0 and
        t1.deadline >= #{condition.startTime} and t1.deadline &lt; #{condition.endTime}) or
        (t1.finished = 1 and
        t1.finish_time >= #{condition.startTime} and t1.finish_time &lt; #{condition.endTime}))

        union
        SELECT t1.id,
        ifnull(t2.plate_no, t3.plate_no)                                                    plate_no,
        t1.type                                                                             type,
        t1.changed                                                                          redistribution,
        t1.follow_user                                                                      user_id,
        t1.follow_shop                                                                      shop_id,
        (select count(1) from follow_record t4
               where t4.task_id = t1.id
                 and t4.user_id = t1.follow_user
                 and t4.follow_time is not null)                                            times,
        TIMESTAMPDIFF(HOUR, now(), t1.deadline)                                              remaining,
        1                                                                                   state,
        t1.finish_time                                                                      finish_time,
        null                                                                                defeat_time,
        null                                                                                initiative,
        t1.group_id                                                                         group_id,
        t2.id                                                                               customer_id,
        t1.origin_shop,
        t1.finish_shop,
        t1.finished,
        t1.state                                                                             origin_state
        FROM follow_task t1
        left join customer t2 on t1.customer_id = t2.id
        left join accident_pool t3 on t1.customer_id = t3.id
        where t1.state = 2
        and t1.begin_time &lt; #{condition.endTime}
        and t1.deadline >=  #{condition.endTime}) followPool
        <where>
            <if test="condition.groupId !=null">
                and followPool.group_id = #{condition.groupId}
            </if>
            <if test="condition.plateNo != null and condition.plateNo !='' ">
                and followPool.plate_no like concat('%', #{condition.plateNo}, '%')
            </if>
            <if test="condition.type !=null">
                and followPool.type = #{condition.type}
            </if>
            <if test="condition.shopId !=null">
                and followPool.shop_id = #{condition.shopId}
            </if>
            <if test="condition.userId !=null">
                and followPool.user_id = #{condition.userId}
            </if>
            <if test="condition.redistribution !=null">
                and followPool.redistribution = #{condition.redistribution}
            </if>
            <if test="condition.state !=null">
                and followPool.state = #{condition.state}
            </if>
            <if test="condition.initiative !=null">
                and followPool.initiative = #{condition.initiative}
            </if>
        </where>
        <if test="condition.orderString != null and condition.orderString !='' ">
            ${condition.orderString}
        </if>
        limit #{startIndex},#{pageSize};
    </select>
</mapper>