HostInfoMapper.xml
7.58 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?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.monitor.mysql.mapper.HostInfoMapper" >
<resultMap id="BaseResultMap" type="com.model.HostInfo" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="alias" property="alias" jdbcType="VARCHAR" />
<result column="host_ip" property="hostIp" jdbcType="VARCHAR" />
<result column="group_id" property="groupId" jdbcType="INTEGER" />
<result column="cloud_type" property="cloudType" jdbcType="BIT" />
<result column="tags" property="tags" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
<result column="group_name" property="groupName" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, alias, host_ip, group_id, cloud_type, tags, create_time, update_time
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from host_info
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from host_info
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.model.HostInfo" >
insert into host_info (id, alias, host_ip,
group_id, cloud_type, tags,
create_time, update_time)
values (#{id,jdbcType=INTEGER}, #{alias,jdbcType=VARCHAR}, #{hostIp,jdbcType=VARCHAR},
#{groupId,jdbcType=INTEGER}, #{cloudType,jdbcType=BIT}, #{tags,jdbcType=VARCHAR},
now(), now())
</insert>
<insert id="insertSelective" parameterType="com.model.HostInfo" >
insert into host_info
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="alias != null" >
alias,
</if>
<if test="hostIp != null" >
host_ip,
</if>
<if test="groupId != null" >
group_id,
</if>
<if test="cloudType != null" >
cloud_type,
</if>
<if test="tags != null" >
tags,
</if>
<if test="createTime != null" >
create_time,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="alias != null" >
#{alias,jdbcType=VARCHAR},
</if>
<if test="hostIp != null" >
#{hostIp,jdbcType=VARCHAR},
</if>
<if test="groupId != null" >
#{groupId,jdbcType=INTEGER},
</if>
<if test="cloudType != null" >
#{cloudType,jdbcType=BIT},
</if>
<if test="tags != null" >
#{tags,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.model.HostInfo" >
update host_info
<set >
<if test="alias != null" >
alias = #{alias,jdbcType=VARCHAR},
</if>
<if test="hostIp != null" >
host_ip = #{hostIp,jdbcType=VARCHAR},
</if>
<if test="groupId != null" >
group_id = #{groupId,jdbcType=INTEGER},
</if>
<if test="cloudType != null" >
cloud_type = #{cloudType,jdbcType=BIT},
</if>
<if test="tags != null" >
tags = #{tags,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
update_time = now(),
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.model.HostInfo" >
update host_info
set alias = #{alias,jdbcType=VARCHAR},
host_ip = #{hostIp,jdbcType=VARCHAR},
group_id = #{groupId,jdbcType=INTEGER},
cloud_type = #{cloudType,jdbcType=BIT},
tags = #{tags,jdbcType=VARCHAR},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectCountByCodition" resultType="java.lang.Integer">
select
count(1)
from host_info a left join host_group b on a.group_id=b.id
where
1=1
<if test="params.alias != null && params.alias != ''" >
and instr(a.alias, #{params.alias}) > 0
</if>
<if test="params.cloudType != null && params.cloudType != 0" >
and a.cloud_type = #{params.cloudType}
</if>
<if test="params.hostIp != null && params.hostIp != ''" >
and a.host_ip = #{params.hostIp}
</if>
<if test="params.tagsList != null && params.tagsList != ''" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
instr(a.tags, #{item}) > 0
</foreach>
</if>
</select>
<select id="selectHostInfosByCodition" resultMap="BaseResultMap">
select
a.id, a.alias, a.host_ip, a.group_id, a.cloud_type, a.tags, a.create_time, a.update_time,b.group_name
from host_info a left join host_group b on a.group_id=b.id
where
1=1
<if test="params.alias != null && params.alias != ''" >
and instr(a.alias, #{params.alias}) > 0
</if>
<if test="params.cloudType != null && params.cloudType != 0" >
and a.cloud_type = #{params.cloudType}
</if>
<if test="params.hostIp != null && params.hostIp != ''" >
and a.host_ip = #{params.hostIp}
</if>
<if test="params.tagsList != null && params.tagsList != ''" >
and
<foreach collection="params.tagsList" index="index" item="item" separator="and">
instr(a.tags, #{item}) > 0
</foreach>
</if>
order by a.create_time desc
limit #{startIndex},#{pageSize}
</select>
<select id="selectByHostIp" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from host_info
where host_ip = #{hostIp}
</select>
<select id="selectHostInfosByTag" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from host_info
where instr(tags, LOWER(#{tag})) > 0
</select>
<select id="selectHostInfosByTagAndCloudType" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from host_info
where instr(tags, LOWER(#{tag})) > 0
AND cloud_type = #{cloudType}
</select>
<select id="selectHostInfosByIps" resultMap="BaseResultMap">
select host_ip, tags
from host_info
where host_ip in
<foreach item="hostIp" index="index" collection="hostIps" open="("
separator="," close=")">
#{hostIp}
</foreach>
</select>
<update id="updateTagByIps" >
update host_info
set tags = ""
where host_ip in
<foreach item="hostIp" index="index" collection="hostIps" open="("
separator="," close=")">
#{hostIp}
</foreach>
</update>
<update id="updateHostInfoByIp" parameterType="com.model.HostInfo" >
update host_info
set alias = #{alias,jdbcType=VARCHAR},
cloud_type = #{cloudType,jdbcType=BIT},
tags = #{tags,jdbcType=VARCHAR},
update_time = now()
where host_ip = #{hostIp,jdbcType=INTEGER}
</update>
<delete id="deleteByIp" parameterType="java.lang.String" >
delete from host_info
where host_ip = #{ip,jdbcType=VARCHAR}
</delete>
</mapper>