邱宇豪
2023-11-03 4c84c3717417ace206ef50369b788bdb9058f204
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?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.thhy.materials.modules.biz.gpsdevice.mapper.GpsDeviceMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.gd_id as gdId,
        t.company_id as companyId,
        t.create_time as createTime,
        t.create_user as createUser,
        t.gd_imei as gdImei,
        t.gd_name as gdName,
        t.is_use as isUse,
        t.remark as remark
    </sql>
 
    <sql id="condition_query">
        <where>
            <trim suffixOverrides=" AND ">
                t.is_use = 1 AND
                <if test="companyId!=null and companyId!=''">
                    t.company_id = #{companyId} AND
                </if>
                <if test="createTime!=null">
                    t.create_time = #{createTime} AND
                </if>
                <if test="createUser!=null and createUser!=''">
                    t.create_user = #{createUser} AND
                </if>
                <if test="gdImei!=null and gdImei!=''">
                    t.gd_imei = #{gdImei} AND
                </if>
                <if test="gdName!=null and gdName!=''">
                    t.gd_name LIKE concat('%',#{gdName},'%') AND
                </if>
                <if test="isUse!=null">
                    t.is_use = #{isUse} AND
                </if>
                <if test="remark!=null and remark!=''">
                    t.remark = #{remark} AND
                </if>
            </trim>
        </where>
    </sql>
 
    <select id="queryById" resultType="com.thhy.materials.modules.biz.gpsdevice.entity.GpsDevice">
        select <include refid="Base_Column_List" />
        from t_gps_device t
        where t.gd_id=#{gdId}
    </select>
 
    <select id="queryVersionById" resultType="integer">
        select version from t_gps_device
        where gd_id=#{gdId}
    </select>
 
    <!--查询列表-->
    <select id="findList" resultType="com.thhy.materials.modules.biz.gpsdevice.entity.GpsDevice">
        SELECT
        <include refid="Base_Column_List" />
        from t_gps_device t
        <include refid="condition_query" />
    </select>
 
    <!--查询列表-->
    <select id="findAll" resultType="com.thhy.materials.modules.biz.gpsdevice.entity.GpsDevice">
        select a.gdId,case when a.count &lt; 1 then a.gdName else CONCAT(a.gdName,'--上次使用过') end as gdName from
        (
        SELECT
        t.gd_id as gdId,
        t.create_time,
        CONCAT(t.gd_name,':',t.gd_imei) as gdName,
        <if test="carId !=null and carId !=''">
            (select count(pipe_out_id) from t_pipe_out where car_id = #{carId} and gd_id = t.gd_id order by create_time desc limit 1) as count
        </if>
        <if test="carId ==null or carId ==''">
            0 as count
        </if>
        from t_gps_device t
        where t.is_use = 1 and t.company_id = #{companyId}
        ) a
        order by a.count desc,a.create_time desc
    </select>
 
    <!--插入操作-->
    <insert id="insert">
        insert into t_gps_device
        <trim prefix="(" suffix=")" suffixOverrides="," >
            <if test="companyId != null">
                company_id,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="createUser != null">
                create_user,
            </if>
            <if test="gdId != null">
                gd_id,
            </if>
            <if test="gdImei != null">
                gd_imei,
            </if>
            <if test="gdName != null">
                gd_name,
            </if>
            <if test="isUse != null">
                is_use,
            </if>
            <if test="remark != null">
                remark,
            </if>
        </trim>
 
        <trim prefix="values (" suffix=")" suffixOverrides="," >
            <if test="companyId != null">
                #{companyId},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="createUser != null">
                #{createUser},
            </if>
            <if test="gdId != null">
                #{gdId},
            </if>
            <if test="gdImei != null">
                #{gdImei},
            </if>
            <if test="gdName != null">
                #{gdName},
            </if>
            <if test="isUse != null">
                #{isUse},
            </if>
            <if test="remark != null">
                #{remark},
            </if>
        </trim>
    </insert>
 
 
    <!--更新操作-->
    <update id="update">
        update t_gps_device
        <set>
            <if test="companyId != null">
                company_id=#{companyId},
            </if>
            <if test="createTime != null">
                create_time=#{createTime},
            </if>
            <if test="createUser != null">
                create_user=#{createUser},
            </if>
            <if test="gdImei != null">
                gd_imei=#{gdImei},
            </if>
            <if test="gdName != null">
                gd_name=#{gdName},
            </if>
            <if test="isUse != null">
                is_use=#{isUse},
            </if>
            <if test="remark != null">
                remark=#{remark},
            </if>
        </set>
        where gd_id=#{gdId}
    </update>
 
    <!--逻辑删除-->
    <update id="deletelogic">
        update t_gps_device
        SET is_use = 0
        where gd_id=#{gdId}
    </update>
 
    <!--根据ID删除-->
    <delete id="deleteById">
        delete from t_gps_device
        where gd_id=#{gdId}
    </delete>
 
    <select id="queryOut" resultType="com.thhy.materials.modules.biz.gpsdevice.entity.PipeOutInfo">
        select pipe_out_id as pipeOutId,gd_imei as gdImei,str_time as startTime,end_time as endTime
        from t_pipe_out where pipe_out_id = #{pipeOutId}
    </select>
 
</mapper>