首页查询资源详情接口
parent
10ec801de3
commit
1d25f1355b
|
@ -189,4 +189,18 @@ public class ModuleController {
|
||||||
return moduleService.modifyProperty(model, id, context);
|
return moduleService.modifyProperty(model, id, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 首页统计模型总数-服务器、虚拟机、网络设备、安全设别
|
||||||
|
*
|
||||||
|
* @param model
|
||||||
|
* @param id
|
||||||
|
* @param context
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping(value = "/statistics")
|
||||||
|
@Operation(summary = "首页统计模型总数")
|
||||||
|
public GeneralResult statistics(@Value(Common.REQ_CONTEXT) RequestContext context) {
|
||||||
|
return moduleService.statistics(context);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,11 @@ public class ModuleGroupRepository extends BasicGenericDao<ModuleGroup, Long> {
|
||||||
String sql = "select * from ci_module_group where is_deleted =0 and parent_id =0 ORDER BY gmt_create DESC ";
|
String sql = "select * from ci_module_group where is_deleted =0 and parent_id =0 ORDER BY gmt_create DESC ";
|
||||||
return this.list(ModuleGroup.class, sql, null);
|
return this.list(ModuleGroup.class, sql, null);
|
||||||
}
|
}
|
||||||
|
public List<ModuleGroup> queryRootInName(List<String> nameList) throws Exception {
|
||||||
|
String sql = "select * from ci_module_group where is_deleted =0 and parent_id =0 and name in (:name) ORDER BY gmt_create DESC ";
|
||||||
|
Map<String, Object> params = MapTools.simpleMap("name", nameList);
|
||||||
|
return this.list(ModuleGroup.class, sql, params);
|
||||||
|
}
|
||||||
|
|
||||||
public List<ModuleGroup> queryChildren(Long id) throws Exception {
|
public List<ModuleGroup> queryChildren(Long id) throws Exception {
|
||||||
String sql = "select * from ci_module_group where is_deleted =0 and parent_id = :id ORDER BY gmt_create DESC ";
|
String sql = "select * from ci_module_group where is_deleted =0 and parent_id = :id ORDER BY gmt_create DESC ";
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.bocloud.ams.service.internal;
|
||||||
|
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bocloud.cmp.boot.model.BocloudToken;
|
||||||
|
import com.megatron.common.model.GeneralResult;
|
||||||
|
import com.megatron.framework.core.CurrentService;
|
||||||
|
import com.megatron.framework.http.core.ServiceFactory;
|
||||||
|
import com.megatron.framework.http.model.RemoteService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import com.megatron.framework.http.core.HttpMethod;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
public class CmpInternalService implements InitializingBean {
|
||||||
|
|
||||||
|
|
||||||
|
private Map<String, Object> headers = new HashMap<>(4);
|
||||||
|
private static final com.megatron.framework.core.Service SERVICE = com.megatron.framework.core.Service.create("cmp");
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CurrentService currentService;
|
||||||
|
@Autowired
|
||||||
|
private ServiceFactory serviceFactory;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public GeneralResult<JSONObject> list(Map<String,Object> params) {
|
||||||
|
String url = "/v1/vms";
|
||||||
|
log.info("params:{}", JSON.toJSONString(params));
|
||||||
|
RemoteService remoteService = serviceFactory.build(SERVICE, url, HttpMethod.GET, headers, params);
|
||||||
|
GeneralResult<?> result = remoteService.invoke();
|
||||||
|
log.info("result:{}",JSON.toJSONString(result));
|
||||||
|
if (result.isFailed()) {
|
||||||
|
return new GeneralResult<>(false, result.getMessage());
|
||||||
|
}
|
||||||
|
String data = JSONObject.toJSONString(result.getData());
|
||||||
|
return new GeneralResult<>(true, JSONObject.parseObject(data), "success");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
|
||||||
|
this.headers.put(BocloudToken.INTERNAL_TOKEN, currentService.getToken());
|
||||||
|
this.headers.put("source", currentService.getService().getName());
|
||||||
|
}
|
||||||
|
}
|
|
@ -35,4 +35,6 @@ public interface ModuleService {
|
||||||
GeneralResult<GridBean<Property>> propertyList(Long moduleId, Pager pager);
|
GeneralResult<GridBean<Property>> propertyList(Long moduleId, Pager pager);
|
||||||
|
|
||||||
GeneralResult<Void> modifyProperty(PropertyModel model, Long id, RequestContext context);
|
GeneralResult<Void> modifyProperty(PropertyModel model, Long id, RequestContext context);
|
||||||
|
|
||||||
|
GeneralResult statistics(RequestContext context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.bocloud.ams.service.internal.CmpInternalService;
|
||||||
|
import com.megatron.common.utils.MapTools;
|
||||||
import org.apache.commons.beanutils.BeanUtilsBean;
|
import org.apache.commons.beanutils.BeanUtilsBean;
|
||||||
import org.apache.commons.beanutils.locale.LocaleBeanUtils;
|
import org.apache.commons.beanutils.locale.LocaleBeanUtils;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -107,6 +110,8 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
private CollectionComponentRepository collectionComponentRepository;
|
private CollectionComponentRepository collectionComponentRepository;
|
||||||
@Autowired
|
@Autowired
|
||||||
private ModuleGroupRepository moduleGroupRepository;
|
private ModuleGroupRepository moduleGroupRepository;
|
||||||
|
@Autowired
|
||||||
|
private CmpInternalService cmpInternalService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GeneralResult<GridBean<CiModule>> getModelList(Pager pager) {
|
public GeneralResult<GridBean<CiModule>> getModelList(Pager pager) {
|
||||||
|
@ -125,7 +130,7 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Map<String, Object> parMap = iterator.next().getParam();
|
Map<String, Object> parMap = iterator.next().getParam();
|
||||||
if (parMap.containsKey("moduleGroupId") && parMap.containsKey("flag")) {
|
if (parMap.containsKey("moduleGroupId") && parMap.containsKey("flag")) {
|
||||||
Long groupId = Long.valueOf((Integer)parMap.get("moduleGroupId"));
|
Long groupId = Long.valueOf((Integer) parMap.get("moduleGroupId"));
|
||||||
if (parMap.get("flag").equals(true)) {
|
if (parMap.get("flag").equals(true)) {
|
||||||
// 递归获取所有子groupId
|
// 递归获取所有子groupId
|
||||||
List<ModuleGroup> groups = moduleGroupRepository.all();
|
List<ModuleGroup> groups = moduleGroupRepository.all();
|
||||||
|
@ -419,6 +424,45 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GeneralResult statistics(RequestContext context) {
|
||||||
|
try {
|
||||||
|
List<String> nameList = Arrays.asList("网络设备", "物理服务器", "安全设备");
|
||||||
|
//查询根节点
|
||||||
|
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRootInName(nameList);
|
||||||
|
log.info("moduleGroups:{}", JSON.toJSONString("moduleGroups"));
|
||||||
|
|
||||||
|
//查询出所有根节点下的子节点
|
||||||
|
|
||||||
|
List<Long> rootGroupIds = rootGroups.stream().map(ModuleGroup::getId).collect(Collectors.toList());
|
||||||
|
// 获取模型分组所有数据
|
||||||
|
List<ModuleGroup> moduleGroups = moduleGroupRepository.all();
|
||||||
|
// 获取根节点的子节点集合
|
||||||
|
List<ModuleGroup> children = moduleGroups.stream().filter(item -> rootGroupIds.contains(item.getParentId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
log.info("children:{}", JSON.toJSONString(children));
|
||||||
|
|
||||||
|
//查询云主机总数
|
||||||
|
Pager pager = new Pager();
|
||||||
|
pager.setPage(1);
|
||||||
|
pager.setRows(Integer.MAX_VALUE);
|
||||||
|
List<Param> paramList = new ArrayList<>();
|
||||||
|
Param param = new Param();
|
||||||
|
param.setParam(MapTools.simpleMap("isTemplate",false));
|
||||||
|
param.setSign(Sign.EQ);
|
||||||
|
paramList.add(param);
|
||||||
|
pager.setParams(paramList);
|
||||||
|
GeneralResult<JSONObject> list = cmpInternalService.list(pager.toMap());
|
||||||
|
log.info("list:{}", JSON.toJSONString(list));
|
||||||
|
|
||||||
|
|
||||||
|
return new GeneralResult<>(true, "查询成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("查询失败", e);
|
||||||
|
return new GeneralResult<>(false, "查询失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private GeneralResult baseModifyProperty(Long moduleId, List<PropertyGroup> groups, List<Property> properties,
|
private GeneralResult baseModifyProperty(Long moduleId, List<PropertyGroup> groups, List<Property> properties,
|
||||||
Long userId) throws Exception {
|
Long userId) throws Exception {
|
||||||
CiModule module = moduleRepository.query(moduleId);
|
CiModule module = moduleRepository.query(moduleId);
|
||||||
|
@ -522,7 +566,7 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
}
|
}
|
||||||
// 3-update:更新数据
|
// 3-update:更新数据
|
||||||
for (Property property : updateProperties) {
|
for (Property property : updateProperties) {
|
||||||
if(null != property.getPropertyPoolId()){
|
if (null != property.getPropertyPoolId()) {
|
||||||
property.setGmtModify(new Date());
|
property.setGmtModify(new Date());
|
||||||
property.setMenderId(userId);
|
property.setMenderId(userId);
|
||||||
propertyRepository.update(property);
|
propertyRepository.update(property);
|
||||||
|
@ -530,7 +574,7 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
}
|
}
|
||||||
// 获取新增item数据
|
// 获取新增item数据
|
||||||
List<PropertyItem> addItems = new ArrayList<>();
|
List<PropertyItem> addItems = new ArrayList<>();
|
||||||
if (!Common.ONE.equals(property.getTableType())){
|
if (!Common.ONE.equals(property.getTableType())) {
|
||||||
addItems = property.getItemList().stream().filter(item -> null == item.getId()).collect(Collectors.toList());
|
addItems = property.getItemList().stream().filter(item -> null == item.getId()).collect(Collectors.toList());
|
||||||
addItems.stream().forEach(item -> {
|
addItems.stream().forEach(item -> {
|
||||||
item.setModuleId(property.getModuleId());
|
item.setModuleId(property.getModuleId());
|
||||||
|
@ -546,14 +590,15 @@ public class ModuleServiceImpl implements ModuleService {
|
||||||
// 获取更新的item数据
|
// 获取更新的item数据
|
||||||
List<PropertyItem> updateItems = new ArrayList<>();
|
List<PropertyItem> updateItems = new ArrayList<>();
|
||||||
List<Long> updateItemIds = new ArrayList<>();
|
List<Long> updateItemIds = new ArrayList<>();
|
||||||
if (!Common.ONE.equals(property.getTableType())){
|
if (!Common.ONE.equals(property.getTableType())) {
|
||||||
updateItems = property.getItemList().stream().filter(item -> null != item.getId()).collect(Collectors.toList());
|
updateItems = property.getItemList().stream().filter(item -> null != item.getId()).collect(Collectors.toList());
|
||||||
updateItems.stream().forEach(item -> {
|
updateItems.stream().forEach(item -> {
|
||||||
item.setMenderId(userId);
|
item.setMenderId(userId);
|
||||||
if (CollectionUtils.isNotEmpty(item.getItemList())) {
|
if (CollectionUtils.isNotEmpty(item.getItemList())) {
|
||||||
// 表格属性中结构项数据的下拉选项数据 转成 JSON 存储
|
// 表格属性中结构项数据的下拉选项数据 转成 JSON 存储
|
||||||
item.setItemValue(JSON.toJSONString(item.getItemList()));
|
item.setItemValue(JSON.toJSONString(item.getItemList()));
|
||||||
} updateItemIds.add(item.getId());
|
}
|
||||||
|
updateItemIds.add(item.getId());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 根据当前属性id查询出之前的item
|
// 根据当前属性id查询出之前的item
|
||||||
|
|
Loading…
Reference in New Issue