支持ams分阵地数据库查询(初版)

develop
yuemian 2024-08-29 11:17:14 +08:00
parent c6ec5bf3f3
commit e7da605061
16 changed files with 376 additions and 169 deletions

View File

@ -1,11 +1,18 @@
package com.bocloud.ams.booter.controller.module;
import java.util.List;
import com.bocloud.ams.entity.module.ModuleRelation;
import com.bocloud.ams.entity.module.RelationCategory;
import com.bocloud.ams.service.module.RelationCategoryService;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.GridBean;
import com.megatron.common.model.Pager;
import com.megatron.common.model.RequestContext;
import com.megatron.common.utils.Common;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -16,17 +23,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bocloud.ams.entity.module.ModuleRelation;
import com.bocloud.ams.entity.module.RelationCategory;
import com.bocloud.ams.service.module.RelationCategoryService;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.GridBean;
import com.megatron.common.model.Pager;
import com.megatron.common.model.RequestContext;
import com.megatron.common.utils.Common;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
@Tag(name = "关联类型分组管理")
@RestController
@ -44,14 +41,16 @@ public class RelationCategoryController {
*/
@GetMapping
@Operation(tags = {"CMC", "CSC"}, summary ="关联类型分组列表")
public GeneralResult<GridBean<RelationCategory>> list(Pager pager) {
return relationCategoryService.list(pager);
public GeneralResult<GridBean<RelationCategory>> list(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return relationCategoryService.list(pager, positionKey);
}
@GetMapping("/all")
@Operation(tags = {"CMC", "CSC"}, summary ="关联类型分组列表(所有)")
public GeneralResult<List<RelationCategory>> listAll(Pager pager) {
return relationCategoryService.listAll(pager.getParams(), pager.getSorter());
public GeneralResult<List<RelationCategory>> listAll(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return relationCategoryService.listAll(pager.getParams(), pager.getSorter(), positionKey);
}
/**
@ -125,8 +124,9 @@ public class RelationCategoryController {
@GetMapping(value = "/{id}/module/relations")
@Operation(tags = {"CMC"}, summary ="关联类型分组模型关系查询")
public GeneralResult<List<ModuleRelation>> moduleRelationList(@PathVariable(value = Common.ID) Long id,
@RequestParam(value = "moduleId") Long moduleId) {
return relationCategoryService.moduleRelationList(id, moduleId);
@RequestParam(value = "moduleId") Long moduleId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return relationCategoryService.moduleRelationList(id, moduleId, positionKey);
}
}

View File

@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bocloud.ams.entity.module.Relation;
@ -40,8 +41,9 @@ public class RelationController {
*/
@GetMapping
@Operation(tags = {"CMC", "CSC"}, summary ="关联类型列表")
public GeneralResult<GridBean<Relation>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
return relationService.list(pager);
public GeneralResult<GridBean<Relation>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return relationService.list(pager, positionKey);
}
/**

View File

@ -1,21 +1,5 @@
package com.bocloud.ams.booter.controller.module;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.bocloud.ams.entity.model.ColumnAndSearchItemModel;
import com.bocloud.ams.entity.model.InstanceTopo;
import com.bocloud.ams.entity.model.PathModel;
@ -27,10 +11,23 @@ import com.megatron.common.model.GridBean;
import com.megatron.common.model.Pager;
import com.megatron.common.model.RequestContext;
import com.megatron.common.utils.Common;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Tag(name = "实例拓扑管理")
@RestController
@ -50,8 +47,9 @@ public class TopologyConfigController {
@GetMapping
@Operation(tags = {"CMC", "CSC"}, summary ="实例拓扑列表")
public GeneralResult<GridBean<TopologyConfig>> list(Pager pager,
@Value(Common.REQ_CONTEXT) RequestContext context) {
return topologyConfigService.list(pager);
@Value(Common.REQ_CONTEXT) RequestContext context,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.list(pager, positionKey);
}
/**
@ -105,8 +103,9 @@ public class TopologyConfigController {
*/
@GetMapping(value = "/{id}")
@Operation(summary = "实例拓扑详情")
public GeneralResult<TopologyConfig> detail(@PathVariable(value = "id") Long id) {
return topologyConfigService.detail(id);
public GeneralResult<TopologyConfig> detail(@PathVariable(value = "id") Long id,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.detail(id, positionKey);
}
/**
@ -119,8 +118,9 @@ public class TopologyConfigController {
@GetMapping(value = "/max/level")
@Operation(summary = "根据起始模型查询最大拓扑层级")
public GeneralResult<Integer> maxLevel(@RequestParam("categoryId") Long categoryId,
@RequestParam("startModuleId") Long startModuleId) {
return topologyConfigService.maxLevel(categoryId, startModuleId);
@RequestParam("startModuleId") Long startModuleId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.maxLevel(categoryId, startModuleId, positionKey);
}
/**
@ -138,9 +138,10 @@ public class TopologyConfigController {
public GeneralResult<List<PathModel>> topologyPath(@RequestParam("categoryId") Long categoryId,
@RequestParam("startModuleId") Long startModuleId, @RequestParam("topologyLevel") Integer topologyLevel,
@RequestParam(value = "ignoreModuleId", required = false) String ignoreModuleId,
@RequestParam(value = "wayModuleId", required = false) String wayModuleId) {
@RequestParam(value = "wayModuleId", required = false) String wayModuleId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.topologyPath(categoryId, startModuleId, topologyLevel, ignoreModuleId,
wayModuleId);
wayModuleId, positionKey);
}
/**
@ -151,8 +152,9 @@ public class TopologyConfigController {
*/
@GetMapping(value = "/{id}/dynamic/item")
@Operation(summary = "获取查询项以及列表项")
public GeneralResult<ColumnAndSearchItemModel> searchItemList(@PathVariable(value = "id") Long id) {
return topologyConfigService.searchItemList(id);
public GeneralResult<ColumnAndSearchItemModel> searchItemList(@PathVariable(value = "id") Long id,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.searchItemList(id, positionKey);
}
/**
@ -163,8 +165,9 @@ public class TopologyConfigController {
*/
@GetMapping(value = "/resource")
@Operation(summary = "查询资源列表")
public GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager) {
return topologyConfigService.resourcelist(pager);
public GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.resourcelist(pager, positionKey);
}
/**
@ -176,8 +179,9 @@ public class TopologyConfigController {
@GetMapping(value = "/{id}/startmodule/instance")
@Operation(summary = "根据实例拓扑id查询对应起始模型的实例集合")
public GeneralResult<List<ResponseInstanceTopologyModel>>
startModuleInstanceList(@PathVariable(value = "id") Long id) {
return topologyConfigService.startModuleInstanceList(id);
startModuleInstanceList(@PathVariable(value = "id") Long id,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.startModuleInstanceList(id, positionKey);
}
/**
@ -189,8 +193,9 @@ public class TopologyConfigController {
*/
@GetMapping("/{id}/export")
@Operation(summary = "实例拓扑资源列表导出")
public GeneralResult<Void> download(@PathVariable Long id, HttpServletResponse response) {
return topologyConfigService.download(id, response);
public GeneralResult<Void> download(@PathVariable Long id, HttpServletResponse response,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.download(id, response, positionKey);
}
/**
@ -203,8 +208,9 @@ public class TopologyConfigController {
@GetMapping(value = "/topo")
@Operation(summary = "全局拓扑")
public GeneralResult<InstanceTopo> topoList(@RequestParam(value = "id") Long id,
@RequestParam(value = "instanceId") Long instanceId) {
return topologyConfigService.topoList(id, instanceId);
@RequestParam(value = "instanceId") Long instanceId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.topoList(id, instanceId, positionKey);
}
/**
@ -217,8 +223,9 @@ public class TopologyConfigController {
@GetMapping(value = "/topo/instances/{instanceId}")
@Operation(summary = "实例资源拓扑")
public GeneralResult<InstanceTopo> topology(@RequestParam(value = "id") Long id,
@PathVariable Long instanceId) {
return topologyConfigService.topology(id, instanceId);
@PathVariable Long instanceId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.topology(id, instanceId, positionKey);
}
/**
@ -231,7 +238,8 @@ public class TopologyConfigController {
@GetMapping(value = "/next/topo")
@Operation(summary = "根据实例id查找下一层级实例拓扑")
public GeneralResult<InstanceTopo> nextTopoList(@RequestParam(value = "id") Long id,
@RequestParam(value = "moduleId") Long moduleId, @RequestParam(value = "instanceId") Long instanceId) {
return topologyConfigService.nextTopoList(id, moduleId, instanceId);
@RequestParam(value = "moduleId") Long moduleId, @RequestParam(value = "instanceId") Long instanceId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return topologyConfigService.nextTopoList(id, moduleId, instanceId, positionKey);
}
}

View File

@ -280,6 +280,19 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listReverse(final String instanceRelationTableName, Long categoryId, List<Long> sourceInstanceIds, List<Long> targetInstanceIds, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = " select a.*, b.relationName relation_name , '1' is_reversed from " + positionKey + "." + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name as relationName from "+positionKey+".ci_module_relation cmr join "+positionKey+".ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId " + " and ( a.source_instance_id in ( :sourceInstanceIds ) or a.target_instance_id in ( :targetInstanceIds ) ) ";
} else {
sql = " select a.*, b.relationName relation_name , '1' is_reversed from " + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name as relationName from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId " + " and ( a.source_instance_id in ( :sourceInstanceIds ) or a.target_instance_id in ( :targetInstanceIds ) ) ";
}
Map<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
params.put("sourceInstanceIds", sourceInstanceIds);
params.put("targetInstanceIds", targetInstanceIds);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listForward(final String instanceRelationTableName, Long categoryId, List<Long> sourceInstanceIds, List<Long> targetInstanceIds) throws Exception {
String sql = "select a.*,b.relationName relation_name from " + instanceRelationTableName + " a join ( select cmr.* , cr.name as relationName from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId" + " and ( a.source_instance_id in ( :sourceInstanceIds ) or a.target_instance_id in ( :targetInstanceIds ) ) ";
Map<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
@ -288,6 +301,19 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listForward(final String instanceRelationTableName, Long categoryId, List<Long> sourceInstanceIds, List<Long> targetInstanceIds, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.*,b.relationName relation_name from " + positionKey + "." + instanceRelationTableName + " a join ( select cmr.* , cr.name as relationName from "+positionKey+".ci_module_relation cmr join "+positionKey+".ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId" + " and ( a.source_instance_id in ( :sourceInstanceIds ) or a.target_instance_id in ( :targetInstanceIds ) ) ";
} else {
sql = "select a.*,b.relationName relation_name from " + instanceRelationTableName + " a join ( select cmr.* , cr.name as relationName from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId" + " and ( a.source_instance_id in ( :sourceInstanceIds ) or a.target_instance_id in ( :targetInstanceIds ) ) ";
}
Map<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
params.put("sourceInstanceIds", sourceInstanceIds);
params.put("targetInstanceIds", targetInstanceIds);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listReverseByInstanceIds(final String instanceRelationTableName, Long categoryId, Long moduleId, Long instanceId) throws Exception {
String sql = " select a.*,b.reverse_name relation_name , '1' is_reversed from " + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.target_module_id = :moduleId " + " and a.target_instance_id = :instanceId ";
Map<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
@ -296,6 +322,19 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listReverseByInstanceIds(final String instanceRelationTableName, Long categoryId, Long moduleId, Long instanceId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = " select a.*,b.reverse_name relation_name , '1' is_reversed from " + positionKey + "." + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from "+positionKey+".ci_module_relation cmr join "+positionKey+".ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.target_module_id = :moduleId " + " and a.target_instance_id = :instanceId ";
} else {
sql = " select a.*,b.reverse_name relation_name , '1' is_reversed from " + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.target_module_id = :moduleId " + " and a.target_instance_id = :instanceId ";
}
Map<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
params.put("instanceId", instanceId);
params.put("categoryId", categoryId);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listForwardByInstanceIds(final String instanceRelationTableName, Long categoryId, Long moduleId, Long instanceId) throws Exception {
String sql = "select a.*,b.name relation_name from " + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.source_module_id = :moduleId " + " and a.source_instance_id = :instanceId ";
Map<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
@ -304,6 +343,19 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listForwardByInstanceIds(final String instanceRelationTableName, Long categoryId, Long moduleId, Long instanceId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.*,b.name relation_name from " + positionKey + "." + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from "+positionKey+".ci_module_relation cmr join "+positionKey+".ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.source_module_id = :moduleId " + " and a.source_instance_id = :instanceId ";
} else {
sql = "select a.*,b.name relation_name from " + instanceRelationTableName + " a join ( select cmr.* , cr.reverse_name from ci_module_relation cmr join ci_relation cr on cmr.relation_id = cr.id where cmr.relation_category_id = :categoryId and cr.category_id = :categoryId ) b on a.module_relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.source_module_id = :moduleId " + " and a.source_instance_id = :instanceId ";
}
Map<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
params.put("instanceId", instanceId);
params.put("categoryId", categoryId);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> queryByInstanceIds(String instanceRelationTable, Long sourceModuleId, List<Long> sourceInstanceIds, Long targetModuleId, List<Long> targetInstanceIds) throws Exception {
String sql = "select a.* from " + instanceRelationTable + " a where is_deleted=0 " + " and source_module_id = :sourceModuleId ";
sql += " and target_module_id = :targetModuleId ";

View File

@ -162,6 +162,16 @@ public class InstanceValueRepository extends BasicGenericDao<InstanceValue, Long
return this.list(InstanceValue.class, sql, params);
}
public List<InstanceValue> queryByInstanceIdsAndPropertyIds(String instanceValueTable, List<Long> instanceIds, List<Long> propertyIds, String positionKey) throws Exception {
if (StringUtils.isNotEmpty(positionKey)) {
instanceValueTable = positionKey + "." + instanceValueTable;
}
final String sql = "select a.* from " + instanceValueTable + " a where a.instance_id in ( :instanceIds ) and a.property_id in ( :propertyIds ) and a.is_deleted = 0 ";
final Map<String, Object> params = MapTools.simpleMap("instanceIds", instanceIds);
params.put("propertyIds", propertyIds);
return this.list(InstanceValue.class, sql, params);
}
public List<InstanceValue> listByPropertyCode(String instanceValueTable, String propertyCode) throws Exception {
String sql = "select a.* from " + instanceValueTable + " a where a.property_code = :propertyCode and a.is_deleted=0 ";
Map<String, Object> params = MapTools.simpleMap("propertyCode", propertyCode);

View File

@ -152,6 +152,16 @@ public class ModuleRelationRepository extends BasicGenericDao<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId));
}
public List<ModuleRelation> queryModuleRealtionAndModuleImage(Long categoryId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "SELECT cm.id as module_id,cm.icon_image, cmr.* FROM "+positionKey+".ci_module_relation cmr ,ci_module cm WHERE (cmr.source_id =cm.id or cmr .target_id =cm.id) and cmr.is_deleted =0 and cmr.relation_category_id = :categoryId ";
} else {
sql = "SELECT cm.id as module_id,cm.icon_image, cmr.* FROM ci_module_relation cmr ,ci_module cm WHERE (cmr.source_id =cm.id or cmr .target_id =cm.id) and cmr.is_deleted =0 and cmr.relation_category_id = :categoryId ";
}
return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId));
}
public List<ModuleRelation> queryModuleList(Long categoryId) throws Exception {
String sql = "select a.* from ci_module_relation a where a.is_deleted=0 and a.relation_category_id = :categoryId";
return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId));
@ -179,6 +189,18 @@ public class ModuleRelationRepository extends BasicGenericDao<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> query(Long relationCategoryId, Long moduleId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* ,r.name relation_name,r.reverse_name relation_reverse_name from " + positionKey + ".ci_module_relation a left join " + positionKey + ".ci_relation r on a.relation_id =r.id where a.is_deleted=0 and a.relation_category_id = :relationCategoryId and (a.source_id = :moduleId OR a.target_id = :moduleId) ";
} else {
sql = "select a.* ,r.name relation_name,r.reverse_name relation_reverse_name from ci_module_relation a left join ci_relation r on a.relation_id =r.id where a.is_deleted=0 and a.relation_category_id = :relationCategoryId and (a.source_id = :moduleId OR a.target_id = :moduleId) ";
}
Map<String, Object> params = MapTools.simpleMap("relationCategoryId", relationCategoryId);
params.put("moduleId", moduleId);
return this.list(ModuleRelation.class, sql, params);
}
public boolean deleteByModuleId(Long moduleId, Long userId) throws Exception {
String sql = " update ci_module_relation set is_deleted = 1 , gmt_modify = :gmtModify , mender_id = :userId where source_id = :moduleId or target_id = :moduleId ";
Map<String, Object> params = MapTools.simpleMap("moduleId", moduleId);

View File

@ -136,6 +136,17 @@ public class PropertyRepository extends BasicGenericDao<Property, Long> {
return this.list(Property.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<Property> listIsTitleByModuleId(Long moduleId, String positionKey) {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* from "+positionKey+".ci_property a where a.is_deleted = 0 and a.module_id = :moduleId and is_title = 1 order by a.order_num";
} else {
sql = "select a.* from ci_property a where a.is_deleted = 0 and a.module_id = :moduleId and is_title = 1 order by a.order_num";
}
// 模型界面显示未隐藏字段
return this.list(Property.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<Property> appointPropertylist(List<Long> ids) {
// 模型界面显示未隐藏字段
String sql = "select a.* from ci_property a where a.is_deleted = 0 and a.id in (:ids) order by a.order_num";

View File

@ -41,6 +41,17 @@ public class RelationCategoryRepository extends BasicGenericDao<RelationCategory
return this.list(RelationCategory.class, sql, getQueryBuilder().getParam(params));
}
public List<RelationCategory> list(List<Param> params, Map<String, String> sorter, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_relation_category a where is_deleted=0 ";
} else {
sql = "select a.* from ci_relation_category a where is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a");
return this.list(RelationCategory.class, sql, getQueryBuilder().getParam(params));
}
public RelationCategory queryByCode(String code) throws Exception {
String sql = "select a.* from ci_relation_category a where a.code = :code and is_deleted=0 ";
List<RelationCategory> list = this.list(RelationCategory.class, sql, MapTools.simpleMap("code", code));
@ -70,12 +81,34 @@ public class RelationCategoryRepository extends BasicGenericDao<RelationCategory
return this.list(RelationCategory.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<RelationCategory> list(Pager pager, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_relation_category a where a.is_deleted=0 ";
} else {
sql = "select a.* from ci_relation_category a where a.is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, pager, "a");
return this.list(RelationCategory.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public int count(List<Param> params) throws Exception {
String sql = "select count(1) from ci_relation_category a where a.is_deleted=0 ";
sql = getQueryBuilder().buildRaw(sql, params, null, "a");
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public int count(List<Param> params, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select count(1) from " + positionKey + ".ci_relation_category a where a.is_deleted=0 ";
} else {
sql = "select count(1) from ci_relation_category a where a.is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, params, null, "a");
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public List<RelationCategory> listByModuleId(Long moduleId) throws Exception {
String sql = "select a.* from ci_relation_category a where is_deleted = 0 and a.id in (select distinct relation_category_id from ci_module_relation where is_deleted=0 and (source_id = :moduleId OR target_id = :moduleId)) order by a.gmt_modify desc";
return this.list(RelationCategory.class, sql, MapTools.simpleMap("moduleId", moduleId));

View File

@ -8,6 +8,7 @@ import com.megatron.common.utils.Common;
import com.megatron.common.utils.MapTools;
import com.megatron.database.core.intf.impl.BasicGenericDao;
import com.megatron.framework.core.CurrentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
@ -43,12 +44,34 @@ public class RelationRepository extends BasicGenericDao<Relation, Long> {
return this.list(Relation.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<Relation> list(Pager pager, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.*,b.name category_name from "+positionKey+".ci_relation a,ci_relation_category b where a.category_id =b.id and a.is_deleted=0 and b.is_deleted=0 ";
} else {
sql = "select a.*,b.name category_name from ci_relation a,ci_relation_category b where a.category_id =b.id and a.is_deleted=0 and b.is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, pager, "a");
return this.list(Relation.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public int count(List<Param> params) throws Exception {
String sql = "select count(1) from ci_relation a,ci_relation_category b where a.category_id =b.id and a.is_deleted=0 and b.is_deleted=0 ";
sql = getQueryBuilder().buildRaw(sql, params, null, "a");
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public int count(List<Param> params, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select count(1) from " + positionKey + ".ci_relation a,ci_relation_category b where a.category_id =b.id and a.is_deleted=0 and b.is_deleted=0 ";
} else {
sql = "select count(1) from ci_relation a,ci_relation_category b where a.category_id =b.id and a.is_deleted=0 and b.is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, params, null, "a");
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public List<SimpleBean> list(List<Param> params, Map<String, String> sorter) throws Exception {
String sql = "select a.* from ci_relation a where is_deleted=0";
sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a");
@ -60,6 +83,22 @@ public class RelationRepository extends BasicGenericDao<Relation, Long> {
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> sorter, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_relation a where is_deleted=0";
} else {
sql = "select a.* from ci_relation a where is_deleted=0";
}
sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a");
List<Relation> list = this.list(Relation.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
for (Relation relation : list) {
beans.add(new SimpleBean(relation.getId(), relation.getName() + "(反向关系名称:" + relation.getReverseName() + ")"));
}
return beans;
}
public Relation queryByCode(String code, Long categoryId) throws Exception {
String sql = "select a.* from ci_relation a where a.code = :code and is_deleted=0 and category_id = :categoryId";
Map<String, Object> params = MapTools.simpleMap("code", code);

View File

@ -35,18 +35,51 @@ public class TopologyConfigRepository extends BasicGenericDao<TopologyConfig, Lo
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public int count(List<Param> params, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = " select count(1) from " + positionKey + ".ci_topology_config a where is_deleted=0 ";
} else {
sql = " select count(1) from ci_topology_config a where is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, params, null, "a");
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public List<TopologyConfig> list(Pager pager) throws Exception {
String sql = "select a.* from ci_topology_config a where is_deleted=0 ";
sql = getQueryBuilder().buildRaw(sql, pager, "a");
return this.list(TopologyConfig.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<TopologyConfig> list(Pager pager, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_topology_config a where is_deleted=0 ";
} else {
sql = "select a.* from ci_topology_config a where is_deleted=0 ";
}
sql = getQueryBuilder().buildRaw(sql, pager, "a");
return this.list(TopologyConfig.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public TopologyConfig query(Long id) throws Exception {
String sql = "select * from ci_topology_config where is_deleted = 0 and id = :id ";
List<TopologyConfig> list = this.list(TopologyConfig.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public TopologyConfig query(Long id, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select * from " + positionKey + ".ci_topology_config where is_deleted = 0 and id = :id ";
} else {
sql = "select * from ci_topology_config where is_deleted = 0 and id = :id ";
}
List<TopologyConfig> list = this.list(TopologyConfig.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public boolean delete(Long id, Long userId) throws Exception {
String sql = " update ci_topology_config set is_deleted = 1 , gmt_modify = :gmtModify , mender_id = :userId where id = :id ";
Map<String, Object> params = MapTools.simpleMap(Common.ID, id);

View File

@ -40,7 +40,7 @@ public interface RelationCategoryService {
* @param pager
* @return
*/
public GeneralResult list(Pager pager);
public GeneralResult list(Pager pager, String positionKey);
/**
*
@ -49,7 +49,7 @@ public interface RelationCategoryService {
* @param sorter
* @return
*/
public GeneralResult listAll(List<Param> param, Map<String, String> sorter);
public GeneralResult listAll(List<Param> param, Map<String, String> sorter, String positionKey);
/***
*
@ -57,7 +57,7 @@ public interface RelationCategoryService {
* @param moduleId
* @return
*/
GeneralResult<List<ModuleRelation>> moduleRelationList(Long id, Long moduleId);
GeneralResult<List<ModuleRelation>> moduleRelationList(Long id, Long moduleId, String positionKey);
GeneralResult listByModuleId(Long moduleId, String positionKey);

View File

@ -36,5 +36,5 @@ public interface RelationService {
* @param pager
* @return
*/
public GeneralResult list(Pager pager);
public GeneralResult list(Pager pager, String positionKey);
}

View File

@ -1,8 +1,5 @@
package com.bocloud.ams.service.module;
import java.util.List;
import java.util.Map;
import com.bocloud.ams.entity.model.ColumnAndSearchItemModel;
import com.bocloud.ams.entity.model.InstanceTopo;
import com.bocloud.ams.entity.model.PathModel;
@ -11,9 +8,11 @@ import com.bocloud.ams.entity.module.TopologyConfig;
import com.megatron.common.model.GeneralResult;
import com.megatron.common.model.GridBean;
import com.megatron.common.model.Pager;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* @author
* @program: bocloud.ams
@ -28,7 +27,7 @@ public interface TopologyConfigService {
* @param pager
* @return
*/
GeneralResult<GridBean<TopologyConfig>> list(Pager pager);
GeneralResult<GridBean<TopologyConfig>> list(Pager pager, String positionKey);
/**
*
@ -63,7 +62,7 @@ public interface TopologyConfigService {
* @param id
* @return
*/
GeneralResult<TopologyConfig> detail(Long id);
GeneralResult<TopologyConfig> detail(Long id, String positionKey);
/**
*
@ -72,7 +71,7 @@ public interface TopologyConfigService {
* @param startModuleId
* @return
*/
GeneralResult<Integer> maxLevel(Long categoryId, Long startModuleId);
GeneralResult<Integer> maxLevel(Long categoryId, Long startModuleId, String positionKey);
/**
*
@ -85,7 +84,7 @@ public interface TopologyConfigService {
* @return
*/
GeneralResult<List<PathModel>> topologyPath(Long categoryId, Long startModuleId, Integer topologyLevel,
String ignoreModuleId, String wayModuleId);
String ignoreModuleId, String wayModuleId, String positionKey);
/**
*
@ -93,7 +92,7 @@ public interface TopologyConfigService {
* @param id
* @return
*/
GeneralResult<ColumnAndSearchItemModel> searchItemList(Long id);
GeneralResult<ColumnAndSearchItemModel> searchItemList(Long id, String positionKey);
/**
*
@ -101,7 +100,7 @@ public interface TopologyConfigService {
* @param pager
* @return
*/
GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager);
GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager, String positionKey);
/**
* id
@ -109,7 +108,7 @@ public interface TopologyConfigService {
* @param id
* @return
*/
GeneralResult<List<ResponseInstanceTopologyModel>> startModuleInstanceList(Long id);
GeneralResult<List<ResponseInstanceTopologyModel>> startModuleInstanceList(Long id, String positionKey);
/**
* R
@ -117,7 +116,7 @@ public interface TopologyConfigService {
*
* @param response
*/
GeneralResult<Void> download(Long id, HttpServletResponse response);
GeneralResult<Void> download(Long id, HttpServletResponse response, String positionKey);
/**
* -
@ -126,7 +125,7 @@ public interface TopologyConfigService {
* @param instanceId
* @return
*/
GeneralResult<InstanceTopo> topoList(Long id, Long instanceId);
GeneralResult<InstanceTopo> topoList(Long id, Long instanceId, String positionKey);
/**
*
@ -135,7 +134,7 @@ public interface TopologyConfigService {
* @param instanceId
* @return
*/
GeneralResult<InstanceTopo> topology(Long id, Long instanceId);
GeneralResult<InstanceTopo> topology(Long id, Long instanceId, String positionKey);
/**
* -id
@ -144,6 +143,6 @@ public interface TopologyConfigService {
* @param instanceId
* @return
*/
GeneralResult<InstanceTopo> nextTopoList(Long id, Long moduleId, Long instanceId);
GeneralResult<InstanceTopo> nextTopoList(Long id, Long moduleId, Long instanceId, String positionKey);
}

View File

@ -170,7 +170,7 @@ public class RelationCategoryServiceImpl implements RelationCategoryService {
}
@Override
public GeneralResult list(Pager pager) {
public GeneralResult list(Pager pager, String positionKey) {
try {
GridBean gridBean;
pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>()));
@ -180,12 +180,12 @@ public class RelationCategoryServiceImpl implements RelationCategoryService {
if (null == simple) {
simple = false;
}
int total = relationCategoryRepository.count(pager.getParams());
int total = relationCategoryRepository.count(pager.getParams(), positionKey);
if (simple) {
List<RelationCategory> beans = relationCategoryRepository.list(pager.getParams(), pager.getSorter());
List<RelationCategory> beans = relationCategoryRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<RelationCategory> list = this.relationCategoryRepository.list(pager);
List<RelationCategory> list = this.relationCategoryRepository.list(pager, positionKey);
gridBean = new GridBean<>(pager.getPage(), pager.getRows(), total, list);
}
return new GeneralResult<>(true, gridBean, "查询成功");
@ -196,12 +196,12 @@ public class RelationCategoryServiceImpl implements RelationCategoryService {
}
@Override
public GeneralResult listAll(List<Param> params, Map<String, String> sorter) {
public GeneralResult listAll(List<Param> params, Map<String, String> sorter, String positionKey) {
try {
params = Optional.ofNullable(params).orElse(new ArrayList<>());
sorter = Optional.ofNullable(sorter).orElse(new HashMap<>());
sorter.put(Common.ID, Common.ONE);
List<RelationCategory> beans = relationCategoryRepository.list(params, sorter);
List<RelationCategory> beans = relationCategoryRepository.list(params, sorter, positionKey);
return new GeneralResult<>(true, beans, "查询成功");
} catch (Exception e) {
log.error("CmdbRelationCategory list query fail:", e);
@ -210,13 +210,13 @@ public class RelationCategoryServiceImpl implements RelationCategoryService {
}
@Override
public GeneralResult<List<ModuleRelation>> moduleRelationList(Long id, Long moduleId) {
public GeneralResult<List<ModuleRelation>> moduleRelationList(Long id, Long moduleId, String positionKey) {
try {
CiModule module = moduleRepository.query(moduleId);
CiModule module = moduleRepository.query(moduleId, positionKey);
if (null == module) {
return GeneralResult.FAILED("模型数据不存在");
}
RelationCategory category = relationCategoryRepository.query(id);
RelationCategory category = relationCategoryRepository.query(id, positionKey);
if (null == category) {
return GeneralResult.FAILED("关联类型分组数据不存在");
}

View File

@ -1,18 +1,5 @@
package com.bocloud.ams.service.module.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import org.apache.commons.beanutils.locale.LocaleBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import com.bocloud.ams.entity.module.ModuleRelation;
import com.bocloud.ams.entity.module.Relation;
import com.bocloud.ams.entity.module.RelationCategory;
@ -27,8 +14,19 @@ import com.megatron.common.model.SimpleBean;
import com.megatron.common.utils.Common;
import com.megatron.framework.lock.AutoCloseLock;
import com.megatron.framework.lock.LockFactory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.locale.LocaleBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
/**
* @Description:
@ -120,19 +118,19 @@ public class RelationServiceImpl implements RelationService {
}
@Override
public GeneralResult list(Pager pager) {
public GeneralResult list(Pager pager, String positionKey) {
try {
GridBean gridBean;
pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>()));
pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>()));
pager.getSorter().put(Common.ID, Common.ONE);
Boolean simple = null == pager.getSimple() ? false : pager.getSimple();
int total = relationRepository.count(pager.getParams());
int total = relationRepository.count(pager.getParams(), positionKey);
if (simple) {
List<SimpleBean> beans = relationRepository.list(pager.getParams(), pager.getSorter());
List<SimpleBean> beans = relationRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<Relation> list = this.relationRepository.list(pager);
List<Relation> list = this.relationRepository.list(pager, positionKey);
gridBean = new GridBean<>(pager.getPage(), pager.getRows(), total, list);
}
return new GeneralResult<>(true, gridBean, "查询成功");

View File

@ -109,19 +109,19 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
private InstanceRepository instanceRepository;
@Override
public GeneralResult<GridBean<TopologyConfig>> list(Pager pager) {
public GeneralResult<GridBean<TopologyConfig>> list(Pager pager, String positionKey) {
try {
pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>()));
pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>()));
pager.getSorter().put(Common.ID, Common.ONE);
int total = topologyConfigRepository.count(pager.getParams());
List<TopologyConfig> list = this.topologyConfigRepository.list(pager);
int total = topologyConfigRepository.count(pager.getParams(), positionKey);
List<TopologyConfig> list = this.topologyConfigRepository.list(pager, positionKey);
for (TopologyConfig config : list) {
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId());
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId(), positionKey);
if (null != relationCategory) {
config.setCategoryName(relationCategory.getName());
}
CiModule startModule = moduleRepository.query(config.getStartModuleId());
CiModule startModule = moduleRepository.query(config.getStartModuleId(), positionKey);
if (null != startModule) {
config.setStartModuleName(startModule.getName());
}
@ -133,7 +133,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
if (StringUtils.isNotEmpty(config.getTopologyPath())) {
List<Long> moduleIds = Arrays.stream(config.getTopologyPath().split(",")).map(Long::valueOf).collect(Collectors.toList());
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds);
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds, positionKey);
String topologyPathName = modules.stream().map(CiModule::getName).collect(Collectors.joining("-"));
config.setTopologyPathName(topologyPathName);
}
@ -221,20 +221,20 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
@Override
public GeneralResult<TopologyConfig> detail(Long id) {
public GeneralResult<TopologyConfig> detail(Long id, String positionKey) {
try {
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if ("PATCH".equalsIgnoreCase(config.getConfigType())) {
String message = this.escapeData(config);
if (null != message) {
return new GeneralResult<>(false, message);
}
} else {
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId());
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId(), positionKey);
if (null != relationCategory) {
config.setCategoryName(relationCategory.getName());
}
CiModule startModule = moduleRepository.query(config.getStartModuleId());
CiModule startModule = moduleRepository.query(config.getStartModuleId(), positionKey);
if (null != startModule) {
config.setStartModuleName(startModule.getName());
}
@ -260,13 +260,13 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<Integer> maxLevel(Long categoryId, Long startModuleId) {
public GeneralResult<Integer> maxLevel(Long categoryId, Long startModuleId, String positionKey) {
RequestInstanceTopologyModel topologyModel = new RequestInstanceTopologyModel();
topologyModel.setCategoryId(categoryId);
topologyModel.setStartModuleId(startModuleId);
try {
//获取起始模型为源id对应的路径集合。
GeneralResult<Map<Boolean, List<List<Long>>>> checkData = this.checkData(topologyModel);
GeneralResult<Map<Boolean, List<List<Long>>>> checkData = this.checkData(topologyModel, positionKey);
if (checkData.isFailed()) {
return new GeneralResult<>(false, checkData.getMessage());
}
@ -303,7 +303,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<List<PathModel>> topologyPath(Long categoryId, Long startModuleId, Integer topologyLevel, String ignoreModuleId, String wayModuleId) {
public GeneralResult<List<PathModel>> topologyPath(Long categoryId, Long startModuleId, Integer topologyLevel, String ignoreModuleId, String wayModuleId, String positionKey) {
try {
RequestInstanceTopologyModel topologyModel = new RequestInstanceTopologyModel();
topologyModel.setCategoryId(categoryId);
@ -319,12 +319,12 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
List<PathModel> pathModels = new ArrayList<>();
//获取起始模型为源id对应的路径集合
GeneralResult<Map<Boolean, List<List<Long>>>> mapGeneralResult = this.checkData(topologyModel);
GeneralResult<Map<Boolean, List<List<Long>>>> mapGeneralResult = this.checkData(topologyModel, positionKey);
if (mapGeneralResult.isFailed()) {
return new GeneralResult<>(false, mapGeneralResult.getMessage());
}
// 转化成返回的数据
List<CiModule> moduleList = moduleRepository.all();
List<CiModule> moduleList = moduleRepository.all(positionKey);
Map<Boolean, List<List<Long>>> data = mapGeneralResult.getData();
for (Boolean aBoolean : data.keySet()) {
if (CollectionUtils.isNotEmpty(data.get(aBoolean))) {
@ -349,10 +349,10 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<ColumnAndSearchItemModel> searchItemList(Long id) {
public GeneralResult<ColumnAndSearchItemModel> searchItemList(Long id, String positionKey) {
try {
ColumnAndSearchItemModel itemModel = new ColumnAndSearchItemModel();
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
@ -361,7 +361,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
List<Long> moduleIds = Arrays.asList(config.getTopologyPath().split(",")).stream().map(moduleId -> Long.parseLong(moduleId)).collect(Collectors.toList());
List<SearchConfigModel> searchConfigs = new ArrayList<>();
// 根据模型id查询模型信息
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds);
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds, positionKey);
if (CollectionUtils.isEmpty(modules)) {
return new GeneralResult<>(false, "没有对应的模型数据");
}
@ -401,7 +401,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
columns.add(columnModel);
}
// 3处理列表集合
List<Property> properties = propertyRepository.listIsTitleByModuleId(moduleIds.get(moduleIds.size() - 1));
List<Property> properties = propertyRepository.listIsTitleByModuleId(moduleIds.get(moduleIds.size() - 1), positionKey);
List<Property> finalProperties = properties.stream().filter(item -> !item.getCode().equals("name")).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(finalProperties)) {
for (Property property : finalProperties) {
@ -423,7 +423,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager) {
public GeneralResult<GridBean<Map<String, Object>>> resourcelist(Pager pager, String positionKey) {
try {
GridBean<Map<String, Object>> gridBean = null;
// 编辑返回数据格式
@ -432,7 +432,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
return new GeneralResult<>(false, "id 不能为空");
}
String id = pager.getParams().get(0).getParam().get("id").toString();
TopologyConfig config = topologyConfigRepository.query(Long.valueOf(id));
TopologyConfig config = topologyConfigRepository.query(Long.valueOf(id), positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
@ -470,7 +470,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
// 拓扑路径最后一个模型的实例表是
String lastInstanceTable = CmdbUtils.CMDB_INSTANCE_VALUE + lastModuleCode.toLowerCase();
// 根据lastInstanceIds以及模型属性为列表项的propertyIds 查询 lastInstanceTable表中的数据
List<Property> properties = propertyRepository.listIsTitleByModuleId(moduleIds.get(moduleIds.size() - 1));
List<Property> properties = propertyRepository.listIsTitleByModuleId(moduleIds.get(moduleIds.size() - 1), positionKey);
//获取需要转义的属性数据
List<Property> propertyList = properties.stream().filter(item -> item.getType().equals(PropertyConstant.PropertyType.SINGLESELECT) || item.getType().equals(PropertyConstant.PropertyType.MULTISELECT) || item.getType().equals(PropertyConstant.PropertyType.RADIO) || item.getType().equals(PropertyConstant.PropertyType.CHECKBOX)).collect(Collectors.toList());
List<Long> propertyIds = properties.stream().filter(item -> !item.getCode().equals("name")).map(Property::getId).collect(Collectors.toList());
@ -503,10 +503,10 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
List<String> list = new ArrayList<>();
List<PropertyItem> propertyItems = new ArrayList<>();
if (null != property.getPropertyPoolId()) {
List<PropertyPoolItem> propertyPoolItems = propertyPoolItemRepository.listByPropertyPoolId(property.getPropertyPoolId());
List<PropertyPoolItem> propertyPoolItems = propertyPoolItemRepository.listByPropertyPoolId(property.getPropertyPoolId(), positionKey);
BeanUtils.copyProperties(propertyPoolItems, propertyItems);
} else {
propertyItems = propertyItemRepository.queryByPropertyId(property.getId());
propertyItems = propertyItemRepository.queryByPropertyId(property.getId(), positionKey);
}
if (CollectionUtils.isNotEmpty(propertyItems)) {
for (String s : listString) {
@ -667,14 +667,14 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<List<ResponseInstanceTopologyModel>> startModuleInstanceList(Long id) {
public GeneralResult<List<ResponseInstanceTopologyModel>> startModuleInstanceList(Long id, String positionKey) {
try {
List<ResponseInstanceTopologyModel> topologyModels = new ArrayList<>();
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
CiModule module = moduleRepository.query(config.getStartModuleId());
CiModule module = moduleRepository.query(config.getStartModuleId(), positionKey);
if (null == module) {
return new GeneralResult<>(false, "没有对应的起始模型!");
}
@ -715,7 +715,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* 3. finishOutputStream,
*/
@Override
public GeneralResult<Void> download(Long id, HttpServletResponse response) {
public GeneralResult<Void> download(Long id, HttpServletResponse response, String positionKey) {
try {
TopologyConfig config = topologyConfigRepository.query(id);
if (null == config) {
@ -726,7 +726,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
// 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
response.setCharacterEncoding("utf-8");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
GeneralResult<ColumnAndSearchItemModel> itemResult = this.searchItemList(id);
GeneralResult<ColumnAndSearchItemModel> itemResult = this.searchItemList(id, positionKey);
if (itemResult.isFailed()) {
return new GeneralResult<>(false, "下载失败");
}
@ -745,7 +745,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
pager.setParams(params);
pager.setPage(1);
pager.setRows(100000);
GeneralResult<GridBean<Map<String, Object>>> resourceResult = this.resourcelist(pager);
GeneralResult<GridBean<Map<String, Object>>> resourceResult = this.resourcelist(pager, positionKey);
if (resourceResult.isFailed()) {
return new GeneralResult<>(false, "下载失败");
}
@ -768,22 +768,22 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<InstanceTopo> topoList(Long id, Long instanceId) {
public GeneralResult<InstanceTopo> topoList(Long id, Long instanceId, String positionKey) {
try {
InstanceTopo topo = new InstanceTopo();
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
CiModule startModule = moduleRepository.query(config.getStartModuleId());
CiModule startModule = moduleRepository.query(config.getStartModuleId(), positionKey);
if (null == startModule) {
return new GeneralResult<>(false, "没有对应的起始模型数据");
}
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId());
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId(), positionKey);
if (null == relationCategory) {
return new GeneralResult<>(false, "没有对应的关系分组数据");
}
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleList(config.getCategoryId());
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleList(config.getCategoryId(), positionKey);
if (CollectionUtils.isEmpty(moduleRelations)) {
return new GeneralResult<>(false, "对应的拓扑图内没有模型关系数据");
}
@ -797,7 +797,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
params.add(param);
Pager pager = new Pager(1, Integer.MAX_VALUE, params, null);
// 获取到实例数据
GeneralResult<GridBean<Map<String, Object>>> result = this.resourcelist(pager);
GeneralResult<GridBean<Map<String, Object>>> result = this.resourcelist(pager, positionKey);
if (result.isFailed()) {
return new GeneralResult<>(false, "查询失败");
}
@ -809,7 +809,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
// 将拓扑路径模型id类型转成Long类型
List<Long> moduleIds = Arrays.asList(config.getTopologyPath().split(",")).stream().map(moduleId -> Long.parseLong(moduleId)).collect(Collectors.toList());
// 根据模型id查询模型信息
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds);
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds, positionKey);
if (CollectionUtils.isEmpty(modules)) {
return new GeneralResult<>(false, "没有对应的模型数据");
}
@ -840,9 +840,9 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
// 通过源实例id的集合和目的实例id的集合以及拓扑路径中模型id的集合 查询出大概范围的数据
List<InstanceRelation> instanceRelations = new ArrayList<>();
if (config.getPathDirection()) {
instanceRelations = instanceRelationRepository.listReverse(relationTable, config.getCategoryId(), new ArrayList<>(targetInstanceIds), new ArrayList<>(sourceInstanceIds));
instanceRelations = instanceRelationRepository.listReverse(relationTable, config.getCategoryId(), new ArrayList<>(targetInstanceIds), new ArrayList<>(sourceInstanceIds), positionKey);
} else {
instanceRelations = instanceRelationRepository.listForward(relationTable, config.getCategoryId(), new ArrayList<>(sourceInstanceIds), new ArrayList<>(targetInstanceIds));
instanceRelations = instanceRelationRepository.listForward(relationTable, config.getCategoryId(), new ArrayList<>(sourceInstanceIds), new ArrayList<>(targetInstanceIds), positionKey);
}
List<InstanceRelationModel> links = new ArrayList<>();
List<InstanceModel> nodes = new ArrayList<>();
@ -873,21 +873,21 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
@Override
public GeneralResult<InstanceTopo> topology(Long id, Long instanceId) {
public GeneralResult<InstanceTopo> topology(Long id, Long instanceId, String positionKey) {
try {
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
CiModule startModule = moduleRepository.query(config.getStartModuleId());
CiModule startModule = moduleRepository.query(config.getStartModuleId(), positionKey);
if (null == startModule) {
return new GeneralResult<>(false, "没有对应的起始模型数据");
}
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId());
RelationCategory relationCategory = relationCategoryRepository.query(config.getCategoryId(), positionKey);
if (null == relationCategory) {
return new GeneralResult<>(false, "没有对应的关系分组数据");
}
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleRealtionAndModuleImage(config.getCategoryId());
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleRealtionAndModuleImage(config.getCategoryId(), positionKey);
if (CollectionUtils.isEmpty(moduleRelations)) {
return new GeneralResult<>(false, "对应的拓扑图内没有模型关系数据");
}
@ -896,7 +896,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
//整理模型图标
Map<Long, ModuleRelation> moduleRelationMap = moduleRelationList.stream().collect(Collectors.toMap(ModuleRelation::getModuleId, Function.identity()));
//获取实例数据
Instance instance = instanceRepository.query(CmdbUtils.CMDB_INSTANCE + startModule.getCode().toLowerCase(), instanceId);
Instance instance = instanceRepository.query(CmdbUtils.CMDB_INSTANCE + startModule.getCode().toLowerCase(), instanceId, positionKey);
if (null == instance) {
return new GeneralResult<>(false, "资源实例数据不存在");
}
@ -913,7 +913,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
nodes.add(instanceModel);
routeNodes.add(instanceModel);
List<InstanceRelationModel> links = Lists.newArrayList();
buildRelation(routeNodes, nodes, links, config, startModule.getId(), relationCategory, instance.getId(), 1, moduleRelationMap, config.getStartType());
buildRelation(routeNodes, nodes, links, config, startModule.getId(), relationCategory, instance.getId(), 1, moduleRelationMap, config.getStartType(), positionKey);
InstanceTopo topo = new InstanceTopo();
topo.setNodes(nodes);
topo.setLinks(links);
@ -924,20 +924,20 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
}
private void buildRelation(List<InstanceModel> routeNodes, List<InstanceModel> nodes, List<InstanceRelationModel> links, TopologyConfig config, Long startModuleId, RelationCategory relationCategory, Long instanceId, int hierarchy, Map<Long, ModuleRelation> moduleRelationMap, String startType) throws Exception {
private void buildRelation(List<InstanceModel> routeNodes, List<InstanceModel> nodes, List<InstanceRelationModel> links, TopologyConfig config, Long startModuleId, RelationCategory relationCategory, Long instanceId, int hierarchy, Map<Long, ModuleRelation> moduleRelationMap, String startType, String positionKey) throws Exception {
//当前当前实例节点所有的关系数据
List<InstanceRelation> instanceRelationsUp = Lists.newArrayList();
List<InstanceRelation> instanceRelationsDown = Lists.newArrayList();
if ("UP".equalsIgnoreCase(startType)) {
List<InstanceRelation> instanceRelations = instanceRelationRepository.queryTargets(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId);
List<InstanceRelation> instanceRelations = instanceRelationRepository.queryTargets(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId, positionKey);
instanceRelationsUp.addAll(instanceRelations);
} else if ("DOWN".equalsIgnoreCase(startType)) {
List<InstanceRelation> instanceRelations = instanceRelationRepository.querySources(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId);
List<InstanceRelation> instanceRelations = instanceRelationRepository.querySources(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId, positionKey);
instanceRelationsDown.addAll(instanceRelations);
} else {
log.info("表名:{},源模型id:{},源实例id:{}", relationCategory.getCode().toLowerCase(), startModuleId, instanceId);
List<InstanceRelation> up = instanceRelationRepository.queryTargets(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId);
List<InstanceRelation> down = instanceRelationRepository.querySources(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId);
List<InstanceRelation> up = instanceRelationRepository.queryTargets(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId, positionKey);
List<InstanceRelation> down = instanceRelationRepository.querySources(CmdbUtils.CMDB_INSTANCE_RELATION + relationCategory.getCode().toLowerCase(), startModuleId, instanceId, positionKey);
instanceRelationsUp.addAll(up);
instanceRelationsDown.addAll(down);
}
@ -977,7 +977,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
routeNodes.add(instanceModel);
//向上查询
if (hierarchy < config.getTopologyLevelUp()) {
buildRelation(routeNodes, nodes, links, config, instanceRelation.getSourceModuleId(), relationCategory, instanceRelation.getSourceInstanceId(), hierarchy + 1, moduleRelationMap, "UP");
buildRelation(routeNodes, nodes, links, config, instanceRelation.getSourceModuleId(), relationCategory, instanceRelation.getSourceInstanceId(), hierarchy + 1, moduleRelationMap, "UP", positionKey);
}
}
for (InstanceRelation instanceRelation : instanceRelationsDown) {
@ -998,7 +998,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
routeNodes.add(instanceModel);
//向下查询
if (hierarchy < config.getTopologyLevelDown()) {
buildRelation(routeNodes, nodes, links, config, instanceRelation.getTargetModuleId(), relationCategory, instanceRelation.getTargetInstanceId(), hierarchy + 1, moduleRelationMap, "DOWN");
buildRelation(routeNodes, nodes, links, config, instanceRelation.getTargetModuleId(), relationCategory, instanceRelation.getTargetInstanceId(), hierarchy + 1, moduleRelationMap, "DOWN", positionKey);
}
}
}
@ -1031,18 +1031,18 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @return
*/
@Override
public GeneralResult<InstanceTopo> nextTopoList(Long id, Long moduleId, Long instanceId) {
public GeneralResult<InstanceTopo> nextTopoList(Long id, Long moduleId, Long instanceId, String positionKey) {
try {
InstanceTopo topo = new InstanceTopo();
TopologyConfig config = topologyConfigRepository.query(id);
TopologyConfig config = topologyConfigRepository.query(id, positionKey);
if (null == config) {
return new GeneralResult<>(false, "没有对应的拓扑实例");
}
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleList(config.getCategoryId());
List<ModuleRelation> moduleRelations = moduleRelationRepository.queryModuleList(config.getCategoryId(), positionKey);
if (CollectionUtils.isEmpty(moduleRelations)) {
return new GeneralResult<>(false, "对应的拓扑图内没有模型关系数据");
}
RelationCategory category = relationCategoryRepository.query(config.getCategoryId());
RelationCategory category = relationCategoryRepository.query(config.getCategoryId(), positionKey);
if (null == category) {
return new GeneralResult<>(false, "没有对应的关系分组数据");
}
@ -1052,10 +1052,10 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
List<Long> moduleIds = new ArrayList<>();
if (null != config.getPathDirection()) {
if (config.getPathDirection()) {
instanceRelations = instanceRelationRepository.listReverseByInstanceIds(relationTable, config.getCategoryId(), moduleId, instanceId);
instanceRelations = instanceRelationRepository.listReverseByInstanceIds(relationTable, config.getCategoryId(), moduleId, instanceId, positionKey);
moduleIds = instanceRelations.stream().map(InstanceRelation::getSourceModuleId).collect(Collectors.toList());
} else {
instanceRelations = instanceRelationRepository.listForwardByInstanceIds(relationTable, config.getCategoryId(), moduleId, instanceId);
instanceRelations = instanceRelationRepository.listForwardByInstanceIds(relationTable, config.getCategoryId(), moduleId, instanceId, positionKey);
moduleIds = instanceRelations.stream().map(InstanceRelation::getTargetModuleId).collect(Collectors.toList());
}
}
@ -1064,7 +1064,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
}
moduleIds.add(moduleId);
// 根据模型id查询模型信息
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds);
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds, positionKey);
if (CollectionUtils.isEmpty(modules)) {
return new GeneralResult<>(false, "没有对应的模型数据");
}
@ -1143,7 +1143,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
* @param topologyModel
* @return
*/
private GeneralResult<Map<Boolean, List<List<Long>>>> checkData(RequestInstanceTopologyModel topologyModel) {
private GeneralResult<Map<Boolean, List<List<Long>>>> checkData(RequestInstanceTopologyModel topologyModel, String positionKey) {
try {
if (null == topologyModel.getCategoryId()) {
return new GeneralResult<>(false, "categoryId参数不能为空");
@ -1152,7 +1152,7 @@ public class TopologyConfigServiceImpl implements TopologyConfigService {
return new GeneralResult<>(false, "startModuleId参数不能为空");
}
// 根据拓扑图分组id查询分组内模型数据
List<ModuleRelation> relations = moduleRelationRepository.queryModuleList(topologyModel.getCategoryId());
List<ModuleRelation> relations = moduleRelationRepository.queryModuleList(topologyModel.getCategoryId(), positionKey);
if (CollectionUtils.isEmpty(relations)) {
return new GeneralResult<>(false, "拓扑图内无拓扑模型!");
}