VehiclePermitMapper.xml
5.32 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
<?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.com.glsx.admin.modules.mapper.VehiclePermitMapper">
<resultMap id="BaseResultMap" type="cn.com.glsx.admin.modules.entity.VehiclePermit">
<!--
WARNING - @mbg.generated
-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="content_id" jdbcType="INTEGER" property="contentId"/>
<result column="accorder_id" jdbcType="INTEGER" property="accorderId"/>
<result column="receiver_id" jdbcType="INTEGER" property="receiverId"/>
<result column="content_type" jdbcType="TINYINT" property="contentType"/>
<result column="permit_type" jdbcType="VARCHAR" property="permitType"/>
<result column="permit_days" jdbcType="INTEGER" property="permitDays"/>
<result column="permit_effective_date" jdbcType="TIMESTAMP" property="permitEffectiveDate"/>
<result column="permit_expired_date" jdbcType="TIMESTAMP" property="permitExpiredDate"/>
<result column="del_flag" jdbcType="TINYINT" property="delFlag"/>
<result column="created_date" jdbcType="TIMESTAMP" property="createdDate"/>
<result column="created_by" jdbcType="INTEGER" property="createdBy"/>
<result column="updated_date" jdbcType="TIMESTAMP" property="updatedDate"/>
<result column="updated_by" jdbcType="INTEGER" property="updatedBy"/>
</resultMap>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
-->
id, content_id, accorder_id, receiver_id, content_type, permit_type, permit_days,
permit_effective_date, permit_expired_date, del_flag, created_date, created_by, updated_date, updated_by
</sql>
<select id="selectByReceiverIdAndContentType" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_vehicle_permit
where del_flag = 0
and receiver_id = #{receiverId}
and content_type = #{contentType}
and permit_effective_date <= now()
and permit_expired_date > now()
</select>
<select id="selectPermitVehicleByReceiverId" resultType="cn.com.glsx.admin.modules.model.view.VehiclePermitDTO">
select concat('v', tvp.content_id) as id,
tvp.accorder_id accorderId,
tv.id vehicleId,
tv.vin,
tv.owner_name ownerName,
concat('u', tv.created_by) as pid,
tvp.permit_days permitDays,
tvp.permit_effective_date permitEffectiveDate,
tvp.permit_expired_date permitExpiredDate,
case
when tvp.permit_days = 0 then '长期'
else concat(tvp.permit_days, '天')
end validTime,
case
when tvp.permit_days = 0 then null
else greatest(ceil(timestampdiff(second, now(), tvp.permit_expired_date) / 86400), 0)
end remainingDays
from t_vehicle_permit tvp
left join t_vehicle tv on tvp.content_id = tv.id
where tvp.del_flag = 0
and tv.del_flag = 0
and tv.created_by is not null
and tvp.receiver_id = #{receiverId}
and tvp.content_type = #{contentType}
and tvp.permit_effective_date <= now()
and tvp.permit_expired_date > now()
</select>
<insert id="insertOrUpdatePermits">
INSERT INTO t_vehicle_permit (content_id, accorder_id, receiver_id, content_type, permit_type,
permit_days, permit_effective_date, permit_expired_date,
del_flag, created_date, created_by)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.contentId},
#{item.accorderId},
#{item.receiverId},
#{item.contentType},
#{item.permitType},
#{item.permitDays},
#{item.permitEffectiveDate},
#{item.permitExpiredDate},
0,
sysdate(),
#{item.createdBy}
)
</foreach>
ON DUPLICATE KEY UPDATE
accorder_id = VALUES(accorder_id),
permit_type = VALUES(permit_type),
permit_days = VALUES(permit_days),
permit_effective_date = VALUES(permit_effective_date),
permit_expired_date = VALUES(permit_expired_date),
del_flag = 0,
updated_date = sysdate(),
updated_by = VALUES(created_by)
</insert>
<delete id="deleteExistedPermit">
delete from t_vehicle_permit
where del_flag = 0
and content_type = #{contentType}
and receiver_id = #{receiverId}
and content_id in
<foreach collection="contentIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</delete>
<delete id="deletePermitByReceiverId">
delete
from t_vehicle_permit
where del_flag = 0
and content_type = #{contentType}
and receiver_id = #{receiverId}
</delete>
</mapper>