TruckCreditMapper.xml
6.7 KB
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
<?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.trash.business.mapper.TruckCreditMapper">
<resultMap type="com.trash.business.domain.TruckCredit" id="TruckCreditResult">
<result property="id" column="id" />
<result property="companyId" column="company_id" />
<result property="licensePlate" column="license_plate"/>
<result property="reason" column="reason" />
<result property="status" column="status" />
<result property="lostCredit" column="lost_credit" />
<result property="objectId" column="object_id" />
<result property="createBy" column="create_by" />
<result property="createType" column="create_type" />
<result property="time" column="time" />
</resultMap>
<sql id="selectTruckCreditVo">
select id, company_id,time,license_plate, reason, status, lost_credit, object_id, create_by,create_type from truck_credit
</sql>
<select id="selectTruckCreditList" parameterType="TruckCredit" resultMap="TruckCreditResult">
<include refid="selectTruckCreditVo"/>
<where>
<if test="companyId != null and companyId != ''"> and company_id = #{companyId}</if>
<if test="licensePlate != null and licensePlate != ''"> and license_plate = #{licensePlate}</if>
<if test="reason != null and reason != ''"> and reason = #{reason}</if>
<if test="status != null "> and status = #{status}</if>
<if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
<if test="objectId != null and objectId != ''"> and object_id = #{objectId}</if>
<if test="time != null "> and DATE_FORMAT(time,("%y%m%d")) = DATE_FORMAT(#{time},("%y%m%d"))</if>
<if test="ids != null ">
and object_id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
order by time DESC
</select>
<select id="selectTruckCreditByObjectId" parameterType="String" resultMap="TruckCreditResult">
<include refid="selectTruckCreditVo"/>
where object_id = #{objectId} and status = 0
</select>
<select id="selectTruckCreditById" parameterType="Long" resultMap="TruckCreditResult">
<include refid="selectTruckCreditVo"/>
where id = #{id}
</select>
<insert id="insertTruckCredit" parameterType="TruckCredit" useGeneratedKeys="true" keyProperty="id">
insert into truck_credit
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="companyId != null">company_id,</if>
<if test="licensePlate != null">license_plate,</if>
<if test="reason != null">reason,</if>
<if test="status != null">status,</if>
<if test="lostCredit != null">lost_credit,</if>
<if test="objectId != null">object_id,</if>
<if test="createBy != null">create_by,</if>
<if test="time != null">time,</if>
<if test="createType != null">create_type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="companyId != null">#{companyId},</if>
<if test="licensePlate != null">#{licensePlate},</if>
<if test="reason != null">#{reason},</if>
<if test="status != null">#{status},</if>
<if test="lostCredit != null">#{lostCredit},</if>
<if test="objectId != null">#{objectId},</if>
<if test="createBy != null">#{createBy},</if>
<if test="time != null">#{time},</if>
<if test="createType != null">#{createType},</if>
</trim>
</insert>
<update id="updateTruckCredit" parameterType="TruckCredit">
update truck_credit
<trim prefix="SET" suffixOverrides=",">
<if test="companyId != null">company_id = #{companyId},</if>
<if test="licensePlate != null">
license_plate = #{licensePlate},</if>
<if test="reason != null">reason = #{reason},</if>
<if test="status != null">status = #{status},</if>
<if test="lostCredit != null">lost_credit = #{lostCredit},</if>
<if test="objectId != null">object_id = #{objectId},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="time != null">time = #{time},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteTruckCreditById" parameterType="Long">
delete from truck_credit where id = #{id}
</delete>
<delete id="deleteTruckCreditByIds" parameterType="String">
delete from truck_credit where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<select id="getNames" parameterType="TruckCredit" resultType="String">
select DISTINCT license_plate from truck_credit
<where>
<if test="licensePlate != null and licensePlate != ''"> and license_plate like concat('%',#{licensePlate},'%')</if>
<if test="status != null "> and status = #{status}</if>
<if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
</where>
</select>
<select id="getCompanys" parameterType="TruckCredit" resultType="String">
select DISTINCT company_id from truck_credit
<where>
<if test="companyId != null and companyId != ''"> and company_id like concat('%',#{companyId},'%')</if>
<if test="status != null "> and status = #{status}</if>
<if test="lostCredit != null "> and lost_credit = #{lostCredit}</if>
</where>
</select>
<select id="selectTruckCreditHistory" parameterType="TruckCredit" resultMap="TruckCreditResult">
SELECT t1.*
FROM truck_credit t1
INNER JOIN (
SELECT license_plate, MAX(id) as max_id
FROM truck_credit
GROUP BY license_plate
) t2 ON t1.license_plate = t2.license_plate AND t1.id = t2.max_id
<where>
<if test="companyId != null and companyId != ''"> and t1.company_id like concat('%',#{companyId},'%')</if>
<if test="licensePlate != null and licensePlate != ''"> and t1.license_plate like concat('%', #{licensePlate}, '%')</if>
<if test="ids != null and ids.size() > 0">
and t1.object_id in
<foreach item="id" collection="ids" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</where>
ORDER BY id desc
</select>
</mapper>