peng
2026-03-24 ca41db25ab3da9ddd509b79fd783b60d2e66056f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?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.tievd.jyz.mapper.CarInfoMapper">
 
    <select id="pageCarAllInfo" resultType="com.tievd.jyz.entity.vo.CarInfoRespVo">
        select t.*, if(t.monthCount>3,3, IF(t.monthCount=0, 1,2)) client_type
        ,o.oil_position oilPosition, o.higher_phrase higherPhrase
        from (
            select c.*,
            GROUP_CONCAT(DISTINCT lc.label_name) label_name,r.org_code,
            count(if(r.behavior=1 and r.create_time>DATE_SUB(CURRENT_TIMESTAMP,INTERVAL 3 MONTH),1,null)) monthCount,
            count(r.id) appear_count,
            count(IF(r.behavior=1,1,null)) oil_count,
            SUM(r.oil_volume) oil_sum,
            sum(r.spand_time) stay_time,
            count(IF(r.standard=2,1,null)) event_count,
            max(r.start_time) update_time
            from t_car_info c
            left join t_label_car lc on c.license_num=lc.license_num
            LEFT JOIN t_oil_record r on c.license_num=r.license_num
            <where>
                <if test="car.licenseNum != null and car.licenseNum!=''">and c.license_num like concat('%', #{car.licenseNum},'%')</if>
                <if test="car.licensePlace != null and car.licensePlace!=''">and c.license_place like concat('%', #{car.licensePlace},'%') </if>
                <if test="car.modelId != null and car.modelId!=''">and c.model_id = #{car.modelId}</if>
                <if test="car.labelName != null and car.labelName!=''">and lc.label_name = #{car.labelName}</if>
                <if test="car.orgCode != null and car.orgCode!=''">and r.org_code like concat(#{car.orgCode},'%')</if>
            </where>
            GROUP BY c.license_num
        )    t
        left join t_oil_statis o on o.license_num=t.license_num  and o.org_code=t.org_code
        <where>
            <if test="car.oilCountLeft != null">and t.oil_count >= #{car.oilCountLeft}</if>
            <if test="car.oilCountRight != null">and t.oil_count &lt;= #{car.oilCountRight}</if>
            <if test="car.oilSumLeft != null ">and t.oil_sum >= #{car.oilSumLeft}</if>
            <if test="car.oilSumRight != null ">and t.oil_sum &lt;= #{car.oilSumRight}</if>
            <if test="car.clientType != null">and o.client_type = #{car.clientType}</if>
        </where>
        order by t.update_time desc
    </select>
 
</mapper>