Showing
6 changed files
with
93 additions
and
28 deletions
@@ -13,6 +13,7 @@ import com.monitor.cmdb.service.IMObjectInfoService; | @@ -13,6 +13,7 @@ import com.monitor.cmdb.service.IMObjectInfoService; | ||
13 | import com.monitor.cmdb.service.ITypeInfoService; | 13 | import com.monitor.cmdb.service.ITypeInfoService; |
14 | import com.monitor.model.domain.MObjectHostInfoModel; | 14 | import com.monitor.model.domain.MObjectHostInfoModel; |
15 | import com.monitor.model.domain.MObjectModel; | 15 | import com.monitor.model.domain.MObjectModel; |
16 | +import com.monitor.model.domain.PageBean; | ||
16 | import com.monitor.model.page.PageResponse; | 17 | import com.monitor.model.page.PageResponse; |
17 | import com.monitor.model.request.DependencyRequest; | 18 | import com.monitor.model.request.DependencyRequest; |
18 | import com.monitor.model.request.HostInfoReq; | 19 | import com.monitor.model.request.HostInfoReq; |
@@ -28,6 +29,7 @@ import org.springframework.beans.BeanUtils; | @@ -28,6 +29,7 @@ import org.springframework.beans.BeanUtils; | ||
28 | import org.springframework.beans.factory.annotation.Autowired; | 29 | import org.springframework.beans.factory.annotation.Autowired; |
29 | import org.springframework.web.bind.annotation.*; | 30 | import org.springframework.web.bind.annotation.*; |
30 | 31 | ||
32 | +import javax.xml.ws.Response; | ||
31 | import java.util.*; | 33 | import java.util.*; |
32 | 34 | ||
33 | /** | 35 | /** |
@@ -160,36 +162,41 @@ public class MObjectInfoCtrl { | @@ -160,36 +162,41 @@ public class MObjectInfoCtrl { | ||
160 | 162 | ||
161 | 163 | ||
162 | public BaseResponse queryMObjectByType(MObjectInfoReq request) { | 164 | public BaseResponse queryMObjectByType(MObjectInfoReq request) { |
163 | - | ||
164 | - DEBUG.debug("Query mobjects by typeIds: {}", request.getTypeIds()); | ||
165 | - | ||
166 | - List<MObjectInfo> moListByType = new ArrayList<>(); | ||
167 | - | ||
168 | - BaseResponse response = null; | ||
169 | - | ||
170 | - String[] typeIds = StringUtils.split(request.getTypeIds(), SPLITOP); | ||
171 | - | ||
172 | - try { | ||
173 | - for (String typeId : typeIds) { | ||
174 | - | ||
175 | - if (StringUtils.isNotBlank(typeId)) { | ||
176 | - | ||
177 | - moListByType.addAll(mobjectService.queryMObjectsInfoByType(Integer.parseInt(typeId))); | ||
178 | - } | ||
179 | - } | ||
180 | - if (null != moListByType) { | ||
181 | - | ||
182 | - response = buildPageResponse(request, buildMObjectModelList(moListByType)); | ||
183 | - } | ||
184 | - } catch (Exception e) { | ||
185 | - | ||
186 | - DEBUG.error("Failed to query mobjects by typeIds: {} , eror: {} ", request.getTypeIds(), e); | ||
187 | - | ||
188 | - response = new BaseResponse(400, e.getMessage()); | 165 | + BaseResponse response = new BaseResponse(); |
166 | + DEBUG.info("Query mobjects ,typeIds is {} , and searchHostIps is {}", request.getTypeIds(), request.getHostIps()); | ||
167 | + //设置分页查询参数 | ||
168 | + PageBean pageBean = PageBean.initPageInfo(request.getCurrentPage(),request.getPageSize(),null); | ||
169 | + //设置查询参数 --typeIds and hostIds | ||
170 | + String typeIdsStr = request.getTypeIds(); | ||
171 | + String hostIdsStr = request.getSearchHostIps(); | ||
172 | + Map<String,Object> paramMap = new HashMap<>(); | ||
173 | + if(StringUtils.isNotBlank(typeIdsStr) && !StringUtils.equals("0",typeIdsStr)){ | ||
174 | + List<String> typeIdList = Arrays.asList(StringUtils.split(typeIdsStr, ",")); | ||
175 | + paramMap.put("typeIdList", typeIdList); | ||
176 | + } | ||
177 | + if(StringUtils.isNotBlank(hostIdsStr)){ | ||
178 | + List<String> hostIpList = Arrays.asList(StringUtils.split(hostIdsStr, ",")); | ||
179 | + paramMap.put("hostIpList" ,hostIpList); | ||
180 | + } | ||
181 | + pageBean.setParams(paramMap); | ||
182 | + try{ | ||
183 | + int totalCount = mobjectService.countByCondition(pageBean); | ||
184 | + List<MObjectInfo> moListByType = mobjectService.selectPageByCondition(pageBean); | ||
185 | + List<MObjectModel> resultList = buildMObjectModelList(moListByType); | ||
186 | + PageResponse pageResponse = new PageResponse(); | ||
187 | + pageResponse.setCurrentPage(request.getCurrentPage()); | ||
188 | + pageResponse.setPageSize(request.getPageSize()); | ||
189 | + pageResponse.setTotal(totalCount); | ||
190 | + pageResponse.setRows(resultList); | ||
191 | + response.setData(pageResponse); | ||
192 | + response.setCode(200); | ||
193 | + return response; | ||
194 | + }catch (Exception e){ | ||
195 | + DEBUG.error("Query mobjects ,typeIds is {} , and searchHostIps is {}", request.getTypeIds(), request.getHostIps()); | ||
196 | + response.setCode(200); | ||
197 | + return response; | ||
189 | } | 198 | } |
190 | 199 | ||
191 | - | ||
192 | - return response; | ||
193 | } | 200 | } |
194 | 201 | ||
195 | 202 |
@@ -2,6 +2,7 @@ package com.monitor.cmdb.service; | @@ -2,6 +2,7 @@ package com.monitor.cmdb.service; | ||
2 | 2 | ||
3 | import com.model.MObjectInfo; | 3 | import com.model.MObjectInfo; |
4 | import com.monitor.cmdb.service.impl.MObjectInfoServiceImpl; | 4 | import com.monitor.cmdb.service.impl.MObjectInfoServiceImpl; |
5 | +import com.monitor.model.domain.PageBean; | ||
5 | import com.monitor.model.response.DependencyRep; | 6 | import com.monitor.model.response.DependencyRep; |
6 | import com.response.MysqlMobjectRep; | 7 | import com.response.MysqlMobjectRep; |
7 | 8 | ||
@@ -40,4 +41,7 @@ public interface IMObjectInfoService { | @@ -40,4 +41,7 @@ public interface IMObjectInfoService { | ||
40 | 41 | ||
41 | void updateBindDependency(int typeId,List<String> dependencyList); | 42 | void updateBindDependency(int typeId,List<String> dependencyList); |
42 | 43 | ||
44 | + int countByCondition(PageBean pageBean); | ||
45 | + | ||
46 | + List<MObjectInfo> selectPageByCondition(PageBean pageBean); | ||
43 | } | 47 | } |
@@ -4,6 +4,7 @@ import com.model.DependencyInfo; | @@ -4,6 +4,7 @@ import com.model.DependencyInfo; | ||
4 | import com.model.MObjectInfo; | 4 | import com.model.MObjectInfo; |
5 | import com.model.TypeInfo; | 5 | import com.model.TypeInfo; |
6 | import com.monitor.cmdb.service.IMObjectInfoService; | 6 | import com.monitor.cmdb.service.IMObjectInfoService; |
7 | +import com.monitor.model.domain.PageBean; | ||
7 | import com.monitor.model.response.DependencyRep; | 8 | import com.monitor.model.response.DependencyRep; |
8 | import com.monitor.mysql.mapper.MObjectInfoMapper; | 9 | import com.monitor.mysql.mapper.MObjectInfoMapper; |
9 | import com.monitor.mysql.mapper.MTypeInfoMapper; | 10 | import com.monitor.mysql.mapper.MTypeInfoMapper; |
@@ -310,6 +311,16 @@ public class MObjectInfoServiceImpl implements IMObjectInfoService { | @@ -310,6 +311,16 @@ public class MObjectInfoServiceImpl implements IMObjectInfoService { | ||
310 | } | 311 | } |
311 | } | 312 | } |
312 | 313 | ||
314 | + @Override | ||
315 | + public int countByCondition(PageBean pageBean) { | ||
316 | + return mObjectInfoMapper.countByCondition(pageBean); | ||
317 | + } | ||
318 | + | ||
319 | + @Override | ||
320 | + public List<MObjectInfo> selectPageByCondition(PageBean pageBean) { | ||
321 | + return mObjectInfoMapper.selectPageByCondition(pageBean); | ||
322 | + } | ||
323 | + | ||
313 | 324 | ||
314 | public Map<String, TypeInfo> queryAllDependencies() { | 325 | public Map<String, TypeInfo> queryAllDependencies() { |
315 | //重头遍历 | 326 | //重头遍历 |
@@ -2,6 +2,7 @@ package com.monitor.mysql.mapper; | @@ -2,6 +2,7 @@ package com.monitor.mysql.mapper; | ||
2 | 2 | ||
3 | import com.model.DependencyInfo; | 3 | import com.model.DependencyInfo; |
4 | import com.model.MObjectInfo; | 4 | import com.model.MObjectInfo; |
5 | +import com.monitor.model.domain.PageBean; | ||
5 | import org.apache.ibatis.annotations.Param; | 6 | import org.apache.ibatis.annotations.Param; |
6 | 7 | ||
7 | import java.util.List; | 8 | import java.util.List; |
@@ -56,4 +57,8 @@ public interface MObjectInfoMapper { | @@ -56,4 +57,8 @@ public interface MObjectInfoMapper { | ||
56 | List<String> selectAllMobjectIps(); | 57 | List<String> selectAllMobjectIps(); |
57 | 58 | ||
58 | void deleteMobjectByHostIps(@Param("deleteHostIpList") List<String> deleteHostIpList); | 59 | void deleteMobjectByHostIps(@Param("deleteHostIpList") List<String> deleteHostIpList); |
60 | + | ||
61 | + int countByCondition(PageBean pageBean); | ||
62 | + | ||
63 | + List<MObjectInfo> selectPageByCondition(PageBean pageBean); | ||
59 | } | 64 | } |
@@ -129,4 +129,40 @@ | @@ -129,4 +129,40 @@ | ||
129 | ) | 129 | ) |
130 | </delete> | 130 | </delete> |
131 | 131 | ||
132 | + <select id="countByCondition" resultType="java.lang.Integer"> | ||
133 | + select count(1) from mobject_info where 1=1 | ||
134 | + <if test="params.typeIdList != null and params.typeIdList.size() > 0" > | ||
135 | + AND type_id in ( | ||
136 | + <foreach collection="params.typeIdList" separator="," item="typeId" > | ||
137 | + #{typeId} | ||
138 | + </foreach> | ||
139 | + ) | ||
140 | + </if> | ||
141 | + <if test="params.hostIpList != null and params.hostIpList.size() > 0"> | ||
142 | + AND host_ip in ( | ||
143 | + <foreach collection="params.hostIpList" separator="," item="hostIp"> | ||
144 | + #{hostIp} | ||
145 | + </foreach> | ||
146 | + ) | ||
147 | + </if> | ||
148 | + </select> | ||
149 | + | ||
150 | + <select id="selectPageByCondition" resultMap="mobjectInfoMapper"> | ||
151 | + select * from mobject_info where 1=1 | ||
152 | + <if test="params.typeIdList != null and params.typeIdList.size() > 0" > | ||
153 | + AND type_id in | ||
154 | + <foreach collection="params.typeIdList" separator="," item="typeId" open="(" close=")"> | ||
155 | + #{typeId} | ||
156 | + </foreach> | ||
157 | + </if> | ||
158 | + <if test="params.hostIpList != null and params.hostIpList.size() > 0"> | ||
159 | + AND host_ip in | ||
160 | + <foreach collection="params.hostIpList" separator="," item="hostIp" open="(" close=")"> | ||
161 | + #{hostIp} | ||
162 | + </foreach> | ||
163 | + </if> | ||
164 | + order by type_id, host_ip | ||
165 | + limit #{startIndex},#{pageSize} | ||
166 | + </select> | ||
167 | + | ||
132 | </mapper> | 168 | </mapper> |
-
Please register or login to post a comment