hjg
2023-10-08 a966b5abe5fb804464fe1cd09053a03fe94877fd
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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.mandi.fendan.mapper.Fd_VehicleMapper">
    <select id="getList1" parameterType="java.util.Map" resultType="java.util.Map">
        <choose>
            <when test="pagesize &gt; 0 ">
                select top ${pagesize} *
            </when>
            <otherwise>
                select *
            </otherwise>
        </choose> from ( select row_number()
        <choose>
            <when test="sort!=null and sort!='' ">
                over (order by ${sort} )
            </when>
            <otherwise>
                over (order by a.id desc )
            </otherwise>
        </choose>
        as rownumber,a.*,b.name as companyName from fd_vehicle a left join fd_company b on a.companyNo=b.companyNo
        <where>
            <if test="type !=null ">
                and a.type=#{type}
            </if>
            <if test="status !=null ">
                and a.status=#{status}
            </if>
            <if test="state !=null ">
                and a.state=#{state}
            </if>
            <if test="companyNo !=null and companyNo !='' ">
                and a.companyNo =#{companyNo} 
            </if>
            <if test="vehicleId !=null and vehicleId !='' ">
                and a.vehicleId like '%'+#{vehicleId}+'%'
            </if>
        </where>
        ) as a where rownumber > #{pagesize}*#{page}
    </select>
    <select id="getList2" parameterType="java.util.Map" resultType="java.util.Map">
        <choose>
            <when test="pagesize &gt; 0 ">
                select top ${pagesize} *
            </when>
            <otherwise>
                select *
            </otherwise>
        </choose>
        from ( select row_number()
        <choose>
            <when test="sort!=null and sort!='' ">
                over (order by ${sort} )
            </when>
            <otherwise>
                over (order by a.id desc )
            </otherwise>
        </choose>
        as rownumber,a.*,b.name as companyName from fd_vehicle a left join fd_company b on a.companyNo=b.companyNo
        <where>
            <if test="type !=null ">
                and a.type=#{type}
            </if>
            <if test="status !=null ">
                and a.status=#{status}
            </if>
            <if test="companyNo !=null and companyNo !='' ">
                and a.companyNo =#{companyNo} 
            </if>
            <if test="vehicleId !=null and vehicleId !='' ">
                and a.vehicleId like '%'+#{vehicleId}+'%'
            </if>
        </where>
        ) as a where rownumber > #{pagesize}*#{page}
 
    </select>
 
    <select id="getPages" parameterType="Map" resultType="int">
        select count(1) from fd_vehicle a left join fd_company b on a.companyNo=b.companyNo
        <where>
            <if test="type !=null ">
                and a.type=#{type}
            </if>
            <if test="status !=null ">
                and a.status=#{status}
            </if>
            <if test="companyNo !=null and companyNo !='' ">
                and a.companyNo =#{companyNo} 
            </if>
            <if test="vehicleId !=null and vehicleId !='' ">
                and a.vehicleId like '%'+#{vehicleId}+'%'
            </if>
        </where> 
    </select>
    
    <select id="getCompanyVehicle" parameterType="map" resultType="map"> 
        SELECT top 5 a.*,0 fdCnum,0 fdCweight,0 fdnum,0 fdweight from fd_vehicle a 
        <where>
            a.type='公司车'
            <choose>
                <when test="companyNo !=null and companyNo !='' ">
                    and a.companyNo =#{companyNo}     
                </when>
                <otherwise>
                     and ( a.companyNo is null or a.companyNo='') 
                </otherwise>
            </choose>
            <if test="vehicleId!=null and vehicleId!=''">
                and a.vehicleId like '%'+#{vehicleId}+'%'    
            </if>
        </where>
              UNION ALL 
        SELECT top 5 a.*,0 fdCnum,0 fdCweight,0 fdnum,0 fdweight from fd_vehicle a LEFT JOIN fd_company_vehicle  b on a.vehicleId=b.vehicleId 
        <where>
            a.type='临时车'
            <choose>
                <when test="companyNo !=null and companyNo !='' ">
                    and b.companyNo =#{companyNo}     
                </when>
                <otherwise>
                     and ( a.companyNo is null or a.companyNo='') 
                </otherwise>
            </choose>    
            <if test="vehicleId!=null and vehicleId!=''">
                and a.vehicleId like '%'+#{vehicleId}+'%'
            </if>
        </where>
    </select>
</mapper>