Authored by mlge

no message

... ... @@ -13,6 +13,7 @@ import com.monitor.cmdb.service.IMObjectInfoService;
import com.monitor.cmdb.service.ITypeInfoService;
import com.monitor.model.domain.MObjectHostInfoModel;
import com.monitor.model.domain.MObjectModel;
import com.monitor.model.domain.PageBean;
import com.monitor.model.page.PageResponse;
import com.monitor.model.request.DependencyRequest;
import com.monitor.model.request.HostInfoReq;
... ... @@ -28,6 +29,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.xml.ws.Response;
import java.util.*;
/**
... ... @@ -160,36 +162,41 @@ public class MObjectInfoCtrl {
public BaseResponse queryMObjectByType(MObjectInfoReq request) {
DEBUG.debug("Query mobjects by typeIds: {}", request.getTypeIds());
List<MObjectInfo> moListByType = new ArrayList<>();
BaseResponse response = null;
String[] typeIds = StringUtils.split(request.getTypeIds(), SPLITOP);
try {
for (String typeId : typeIds) {
if (StringUtils.isNotBlank(typeId)) {
moListByType.addAll(mobjectService.queryMObjectsInfoByType(Integer.parseInt(typeId)));
}
}
if (null != moListByType) {
response = buildPageResponse(request, buildMObjectModelList(moListByType));
}
} catch (Exception e) {
DEBUG.error("Failed to query mobjects by typeIds: {} , eror: {} ", request.getTypeIds(), e);
response = new BaseResponse(400, e.getMessage());
BaseResponse response = new BaseResponse();
DEBUG.info("Query mobjects ,typeIds is {} , and searchHostIps is {}", request.getTypeIds(), request.getHostIps());
//设置分页查询参数
PageBean pageBean = PageBean.initPageInfo(request.getCurrentPage(),request.getPageSize(),null);
//设置查询参数 --typeIds and hostIds
String typeIdsStr = request.getTypeIds();
String hostIdsStr = request.getSearchHostIps();
Map<String,Object> paramMap = new HashMap<>();
if(StringUtils.isNotBlank(typeIdsStr) && !StringUtils.equals("0",typeIdsStr)){
List<String> typeIdList = Arrays.asList(StringUtils.split(typeIdsStr, ","));
paramMap.put("typeIdList", typeIdList);
}
if(StringUtils.isNotBlank(hostIdsStr)){
List<String> hostIpList = Arrays.asList(StringUtils.split(hostIdsStr, ","));
paramMap.put("hostIpList" ,hostIpList);
}
pageBean.setParams(paramMap);
try{
int totalCount = mobjectService.countByCondition(pageBean);
List<MObjectInfo> moListByType = mobjectService.selectPageByCondition(pageBean);
List<MObjectModel> resultList = buildMObjectModelList(moListByType);
PageResponse pageResponse = new PageResponse();
pageResponse.setCurrentPage(request.getCurrentPage());
pageResponse.setPageSize(request.getPageSize());
pageResponse.setTotal(totalCount);
pageResponse.setRows(resultList);
response.setData(pageResponse);
response.setCode(200);
return response;
}catch (Exception e){
DEBUG.error("Query mobjects ,typeIds is {} , and searchHostIps is {}", request.getTypeIds(), request.getHostIps());
response.setCode(200);
return response;
}
return response;
}
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.cmdb.service;
import com.model.MObjectInfo;
import com.monitor.cmdb.service.impl.MObjectInfoServiceImpl;
import com.monitor.model.domain.PageBean;
import com.monitor.model.response.DependencyRep;
import com.response.MysqlMobjectRep;
... ... @@ -40,4 +41,7 @@ public interface IMObjectInfoService {
void updateBindDependency(int typeId,List<String> dependencyList);
int countByCondition(PageBean pageBean);
List<MObjectInfo> selectPageByCondition(PageBean pageBean);
}
... ...
... ... @@ -4,6 +4,7 @@ import com.model.DependencyInfo;
import com.model.MObjectInfo;
import com.model.TypeInfo;
import com.monitor.cmdb.service.IMObjectInfoService;
import com.monitor.model.domain.PageBean;
import com.monitor.model.response.DependencyRep;
import com.monitor.mysql.mapper.MObjectInfoMapper;
import com.monitor.mysql.mapper.MTypeInfoMapper;
... ... @@ -310,6 +311,16 @@ public class MObjectInfoServiceImpl implements IMObjectInfoService {
}
}
@Override
public int countByCondition(PageBean pageBean) {
return mObjectInfoMapper.countByCondition(pageBean);
}
@Override
public List<MObjectInfo> selectPageByCondition(PageBean pageBean) {
return mObjectInfoMapper.selectPageByCondition(pageBean);
}
public Map<String, TypeInfo> queryAllDependencies() {
//重头遍历
... ...
... ... @@ -35,5 +35,7 @@ public class MObjectInfoReq extends PageRequest{
int isType = 1;
private String searchHostIps;//主机Ip --搜索条件(以 ,分隔)
}
... ...
... ... @@ -2,6 +2,7 @@ package com.monitor.mysql.mapper;
import com.model.DependencyInfo;
import com.model.MObjectInfo;
import com.monitor.model.domain.PageBean;
import org.apache.ibatis.annotations.Param;
import java.util.List;
... ... @@ -56,4 +57,8 @@ public interface MObjectInfoMapper {
List<String> selectAllMobjectIps();
void deleteMobjectByHostIps(@Param("deleteHostIpList") List<String> deleteHostIpList);
int countByCondition(PageBean pageBean);
List<MObjectInfo> selectPageByCondition(PageBean pageBean);
}
... ...
... ... @@ -129,4 +129,40 @@
)
</delete>
<select id="countByCondition" resultType="java.lang.Integer">
select count(1) from mobject_info where 1=1
<if test="params.typeIdList != null and params.typeIdList.size() > 0" >
AND type_id in (
<foreach collection="params.typeIdList" separator="," item="typeId" >
#{typeId}
</foreach>
)
</if>
<if test="params.hostIpList != null and params.hostIpList.size() > 0">
AND host_ip in (
<foreach collection="params.hostIpList" separator="," item="hostIp">
#{hostIp}
</foreach>
)
</if>
</select>
<select id="selectPageByCondition" resultMap="mobjectInfoMapper">
select * from mobject_info where 1=1
<if test="params.typeIdList != null and params.typeIdList.size() > 0" >
AND type_id in
<foreach collection="params.typeIdList" separator="," item="typeId" open="(" close=")">
#{typeId}
</foreach>
</if>
<if test="params.hostIpList != null and params.hostIpList.size() > 0">
AND host_ip in
<foreach collection="params.hostIpList" separator="," item="hostIp" open="(" close=")">
#{hostIp}
</foreach>
</if>
order by type_id, host_ip
limit #{startIndex},#{pageSize}
</select>
</mapper>
\ No newline at end of file
... ...