diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/association/AutoRelationRuleController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/association/AutoRelationRuleController.java index 233becc..a33455d 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/association/AutoRelationRuleController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/association/AutoRelationRuleController.java @@ -9,6 +9,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.association.AutoRelationRule; @@ -39,8 +40,8 @@ public class AutoRelationRuleController { */ @Operation(tags = {"CMC"}, summary = "关联规则列表") @GetMapping - public GeneralResult> list(Pager pager) { - return autoRelationRuleService.list(pager); + public GeneralResult> list(Pager pager, @RequestParam(value = "positionKey", required = false) String positionKey) { + return autoRelationRuleService.list(pager, positionKey); } /** @@ -80,8 +81,9 @@ public class AutoRelationRuleController { */ @Operation(tags = {"CMC"}, summary = "关联规则详情") @GetMapping(value = "/{id}") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { - return autoRelationRuleService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return autoRelationRuleService.detail(id, positionKey); } /** @@ -92,8 +94,9 @@ public class AutoRelationRuleController { */ @Operation(tags = {"CMC"}, summary = "关联规则明细详情") @GetMapping(value = "/{id}/items/{itemId}") - public GeneralResult itemDetail(@PathVariable("itemId") Long itemId) { - return autoRelationRuleService.itemDetail(itemId); + public GeneralResult itemDetail(@PathVariable("itemId") Long itemId, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return autoRelationRuleService.itemDetail(itemId, positionKey); } /** diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/audit/OperationalAuditController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/audit/OperationalAuditController.java index bed20a4..41ba3ea 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/audit/OperationalAuditController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/audit/OperationalAuditController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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.audit.OperationalAudit; @@ -33,8 +34,9 @@ public class OperationalAuditController { */ @Operation(tags = {"CMC"}, summary = "操作审计列表") @GetMapping - public GeneralResult> operationalAudit(Pager pager) { - return operationalAuditService.list(pager); + public GeneralResult> operationalAudit(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return operationalAuditService.list(pager, positionKey); } /** @@ -45,13 +47,15 @@ public class OperationalAuditController { */ @Operation(tags = {"CMC"}, summary = "操作审计详情") @GetMapping(value = "/{id}") - public GeneralResult operationalAudit(@PathVariable(value = Common.ID) Long id) { - return operationalAuditService.deatil(id); + public GeneralResult operationalAudit(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return operationalAuditService.detail(id, positionKey); } @Operation(tags = {"CMC"}, summary = "操作审计备份列表") @GetMapping(value = "/bak") - public GeneralResult> operationalAuditBak(Pager pager) { - return operationalAuditService.bakList(pager); + public GeneralResult> operationalAuditBak(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return operationalAuditService.bakList(pager, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryController.java index 9cebe0b..20784ad 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryController.java @@ -1,16 +1,5 @@ package com.bocloud.ams.booter.controller.collection; -import java.util.Map; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.GetMapping; -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.RestController; - import com.bocloud.ams.entity.collection.CollectionHistory; import com.bocloud.ams.entity.model.CollectionHistoryModel; import com.bocloud.ams.service.collection.CollectionHistoryService; @@ -19,9 +8,19 @@ 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.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +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.Map; @RestController @RequestMapping("/v1/collection/history") @@ -34,14 +33,16 @@ public class CollectionHistoryController { @Operation(tags = {"CMC"}, summary = "实例采集历史列表") @GetMapping("/instances") public GeneralResult>> list(Pager pager, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return collectionHistoryService.instances(pager, context.getTarget()); + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryService.instances(pager, context.getTarget(), positionKey); } @Operation(tags = {"CMC"}, summary = "采集历史列表") @GetMapping - public GeneralResult> history(Pager pager) { - return collectionHistoryService.list(pager); + public GeneralResult> history(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryService.list(pager, positionKey); } @Operation(tags = {"CMC"}, summary = "采集历史新增") @@ -67,15 +68,17 @@ public class CollectionHistoryController { @Operation(tags = {"CMC"}, summary = "采集历史备份列表") @GetMapping("/backup") - public GeneralResult> backupHistory(Pager pager) { - return collectionHistoryService.backupHistory(pager); + public GeneralResult> backupHistory(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryService.backupHistory(pager, positionKey); } @Operation(tags = {"CMC"}, summary = "实例采集历史备份列表") @GetMapping("/backup/instances") public GeneralResult>> backupList(Pager pager, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return collectionHistoryService.backupList(pager, context.getTarget()); + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryService.backupList(pager, context.getTarget(), positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryItemController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryItemController.java index d589783..7377930 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryItemController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionHistoryItemController.java @@ -3,6 +3,7 @@ package com.bocloud.ams.booter.controller.collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; 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.collection.CollectionHistoryItem; @@ -24,14 +25,16 @@ public class CollectionHistoryItemController { @Operation(tags = {"CMC"}, summary = "采集历史条目列表") @GetMapping - public GeneralResult> historyItems(Pager pager) { - return collectionHistoryItemService.list(pager); + public GeneralResult> historyItems(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryItemService.list(pager, positionKey); } @Operation(tags = {"CMC"}, summary = "实例采集历史条目备份列表") @GetMapping("/backup") - public GeneralResult> backupHistoryItems(Pager pager) { - return collectionHistoryItemService.backupHistoryItems(pager); + public GeneralResult> backupHistoryItems(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionHistoryItemService.backupHistoryItems(pager, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskController.java index 9a4c125..07d1a8b 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskController.java @@ -4,15 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.ApplicationListener; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PatchMapping; -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.RestController; +import org.springframework.web.bind.annotation.*; import com.bocloud.ams.entity.collection.CollectionTask; import com.bocloud.ams.entity.model.OperateParam; @@ -56,8 +48,9 @@ public class CollectionTaskController implements ApplicationListener> list(Pager pager) { - return collectionTaskService.list(pager); + public GeneralResult> list(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskService.list(pager, positionKey); } /** @@ -123,8 +116,9 @@ public class CollectionTaskController implements ApplicationListener detail(@PathVariable(value = Common.ID) Long id) { - return collectionTaskService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskService.detail(id, positionKey); } /** diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskInstanceController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskInstanceController.java index 351aa9d..206a22c 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskInstanceController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTaskInstanceController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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.collection.CollectionTaskInstance; @@ -32,26 +33,30 @@ public class CollectionTaskInstanceController { */ @Operation(tags = {"CMC"}, summary = "采集任务实例列表") @GetMapping - public GeneralResult> list(Pager pager) { - return collectionTaskInstanceService.list(pager); + public GeneralResult> list(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskInstanceService.list(pager, positionKey); } @GetMapping(value = "/{id}") @Operation(tags = {"CMC", "CSC"}, summary = "采集任务实例详情") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { - return collectionTaskInstanceService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskInstanceService.detail(id, positionKey); } @Operation(tags = {"CMC"}, summary = "采集任务实例备份列表") @GetMapping("/backup") - public GeneralResult> bakList(Pager pager) { - return collectionTaskInstanceService.bakList(pager); + public GeneralResult> bakList(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskInstanceService.bakList(pager, positionKey); } @GetMapping(value = "/{name}/{id}") @Operation(tags = {"CMC", "CSC"}, summary = "采集任务实例备份详情") public GeneralResult bakDetail(@PathVariable(value = Common.ID) Long id, - @PathVariable(value = Common.NAME) String name) { - return collectionTaskInstanceService.bakDetail(id, name); + @PathVariable(value = Common.NAME) String name, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTaskInstanceService.bakDetail(id, name, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTemplateController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTemplateController.java index a28b203..1b412c5 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTemplateController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/collection/CollectionTemplateController.java @@ -9,6 +9,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.collection.CollectionComponent; @@ -39,8 +40,9 @@ public class CollectionTemplateController { */ @Operation(tags = {"CMC"}, summary = "采集插件组件列表") @GetMapping(value = "/components") - public GeneralResult> components(Pager pager) { - return collectionTemplateService.components(pager); + public GeneralResult> components(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTemplateService.components(pager, positionKey); } /** @@ -51,8 +53,9 @@ public class CollectionTemplateController { */ @Operation(tags = {"CMC"}, summary = "采集插件列表") @GetMapping - public GeneralResult> list(Pager pager) { - return collectionTemplateService.list(pager); + public GeneralResult> list(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTemplateService.list(pager, positionKey); } /** @@ -107,7 +110,8 @@ public class CollectionTemplateController { */ @GetMapping(value = "/{id}") @Operation(tags = {"CMC", "CSC"}, summary = "采集插件详情") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { - return collectionTemplateService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return collectionTemplateService.detail(id, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/config/CmdbConfigController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/config/CmdbConfigController.java index d60ad1a..0504204 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/config/CmdbConfigController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/config/CmdbConfigController.java @@ -1,9 +1,14 @@ package com.bocloud.ams.booter.controller.config; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - +import com.alibaba.fastjson.JSONArray; +import com.bocloud.ams.entity.config.CmdbConfig; +import com.bocloud.ams.service.config.CmdbConfigService; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.RequestContext; +import com.megatron.common.model.Result; +import com.megatron.common.utils.Common; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; @@ -13,16 +18,9 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.alibaba.fastjson.JSONArray; -import com.bocloud.ams.entity.config.CmdbConfig; -import com.bocloud.ams.service.config.CmdbConfigService; -import com.megatron.common.model.GeneralResult; -import com.megatron.common.model.RequestContext; -import com.megatron.common.model.Result; -import com.megatron.common.utils.Common; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; @RestController @RequestMapping("/v1/cmdb/configs") @@ -56,8 +54,9 @@ public class CmdbConfigController { @Operation(summary = "配置中心配置批量查询") public GeneralResult> getByCodes( @RequestParam(value = "category", required = false) String category, - @RequestParam(value = "codes", required = false) ArrayList codes) { - return cmdbConfigService.listConfigs(category, codes); + @RequestParam(value = "codes", required = false) ArrayList codes, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return cmdbConfigService.listConfigs(category, codes, positionKey); } /** @@ -68,8 +67,9 @@ public class CmdbConfigController { */ @GetMapping("/tree") @Operation(summary = "配置中心配置类型树") - public GeneralResult listCategoryTree(@RequestParam(value = "category") String category) { - return cmdbConfigService.listCategoryTree(category); + public GeneralResult listCategoryTree(@RequestParam(value = "category") String category, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return cmdbConfigService.listCategoryTree(category, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceAuthoryController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceAuthoryController.java index 1b264e2..f71bc62 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceAuthoryController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceAuthoryController.java @@ -9,6 +9,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.instance.InstanceAuthority; @@ -37,8 +38,9 @@ public class InstanceAuthoryController { */ @Operation(tags = {"CMC"}, summary = "实例权限列表") @GetMapping - public GeneralResult> list(Pager pager) { - return instanceAuthorityService.list(pager); + public GeneralResult> list(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceAuthorityService.list(pager, positionKey); } /*** diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceController.java index 05dd11e..a3d2fef 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceController.java @@ -1,13 +1,19 @@ package com.bocloud.ams.booter.controller.instance; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URLEncoder; -import java.util.Base64; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - +import com.alibaba.fastjson.JSONObject; +import com.bocloud.ams.entity.instance.Instance; +import com.bocloud.ams.entity.model.InstanceBean; +import com.bocloud.ams.entity.model.InstanceTopo; +import com.bocloud.ams.service.instance.InstanceService; +import com.megatron.common.model.GeneralResult; +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.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.DeleteMapping; @@ -21,21 +27,13 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import com.alibaba.fastjson.JSONObject; -import com.bocloud.ams.entity.instance.Instance; -import com.bocloud.ams.entity.model.InstanceBean; -import com.bocloud.ams.entity.model.InstanceTopo; -import com.bocloud.ams.service.instance.InstanceService; -import com.megatron.common.model.GeneralResult; -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.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.extern.slf4j.Slf4j; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URLEncoder; +import java.util.Base64; +import java.util.HashMap; +import java.util.List; +import java.util.Map; @Slf4j @RestController @@ -49,8 +47,9 @@ public class InstanceController { @Operation(tags = {"CMC"}, summary = "实例列表") @GetMapping public GeneralResult>> list(Pager pager, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return instanceService.list(pager, context.getTarget()); + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceService.list(pager, context.getTarget(), positionKey); } /*** @@ -127,17 +126,22 @@ public class InstanceController { @Operation(tags = {"CMC"}, summary = "实例详情") @GetMapping(value = "/{id}") public GeneralResult detail(@PathVariable(value = Common.ID) Long id, - @RequestParam(value = "moduleCode") String moduleCode) { - return instanceService.detail(id, moduleCode); + @RequestParam(value = "moduleCode") String moduleCode, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceService.detail(id, moduleCode, positionKey); } @Operation(summary = "实例导出") @GetMapping(value = "/export") public void export(@RequestParam(value = "moduleId") Long moduleId, - @RequestParam(value = "moduleCode") String moduleCode, @RequestParam(value = "type") String type, - HttpServletRequest request, HttpServletResponse response, @Value(Common.REQ_CONTEXT) RequestContext context) { + @RequestParam(value = "moduleCode") String moduleCode, + @RequestParam(value = "type") String type, + HttpServletRequest request, + HttpServletResponse response, + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { @SuppressWarnings("unchecked") - GeneralResult GeneralResult = instanceService.export(moduleId, moduleCode, type, context.getTarget()); + GeneralResult GeneralResult = instanceService.export(moduleId, moduleCode, type, context.getTarget(), positionKey); if (GeneralResult.isSuccess()) { String content = null; try { @@ -218,9 +222,11 @@ public class InstanceController { @Operation(summary = "实例拓扑") @GetMapping(value = "/{id}/topo") public GeneralResult topo(@PathVariable(value = Common.ID) Long id, - @RequestParam(value = "relationCategoryId") Long relationCategoryId, - @RequestParam(value = "moduleId") Long moduleId, @Value(Common.REQ_CONTEXT) RequestContext context) { - return instanceService.topo(id, relationCategoryId, moduleId, context.getTarget()); + @RequestParam(value = "relationCategoryId") Long relationCategoryId, + @RequestParam(value = "moduleId") Long moduleId, + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceService.topo(id, relationCategoryId, moduleId, context.getTarget(), positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceHistoryController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceHistoryController.java index 4ef36e4..88d50b4 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceHistoryController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceHistoryController.java @@ -3,6 +3,7 @@ package com.bocloud.ams.booter.controller.instance; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; 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.instance.InstanceHistory; @@ -29,8 +30,9 @@ public class InstanceHistoryController { */ @Operation(tags = {"CMC"}, summary = "实例变更记录列表") @GetMapping - public GeneralResult> history(Pager pager) { - return instanceHistoryService.list(pager); + public GeneralResult> history(Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceHistoryService.list(pager, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceRelationHistoryRecordController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceRelationHistoryRecordController.java index ffa6814..4a9e6fc 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceRelationHistoryRecordController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/instance/InstanceRelationHistoryRecordController.java @@ -1,16 +1,5 @@ package com.bocloud.ams.booter.controller.instance; -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -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.RestController; - import com.bocloud.ams.entity.instance.InstanceRelationHistoryRecord; import com.bocloud.ams.entity.model.InstanceRelationHistoryPreflightModel; import com.bocloud.ams.service.instance.InstanceRelationHistoryRecordService; @@ -19,9 +8,19 @@ 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.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +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; @RestController @RequestMapping("/v1/instances/relations/history") @@ -41,8 +40,9 @@ public class InstanceRelationHistoryRecordController { @GetMapping @Operation(tags = {"CMC", "CSC"}, summary = "关联历史列表") public GeneralResult> list(Pager pager, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return instanceRelationHistoryRecordService.list(pager); + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return instanceRelationHistoryRecordService.list(pager, positionKey); } @PutMapping("/{id}/preflight") diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleController.java index d371e2e..d9ebc43 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleController.java @@ -1,19 +1,5 @@ package com.bocloud.ams.booter.controller.module; -import java.util.List; - -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 com.bocloud.ams.entity.association.AutoRelationRule; import com.bocloud.ams.entity.model.PropertyModel; import com.bocloud.ams.entity.module.CiModule; @@ -27,9 +13,21 @@ 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.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; @RestController @RequestMapping("/v1/module") @@ -53,8 +51,9 @@ public class ModuleController { @GetMapping("/collections") @Operation(tags = {"CMC", "CSC"}, summary = "模型列表") public GeneralResult> getModelList(Pager pager, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return moduleService.getModelList(pager); + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.getModelList(pager, positionKey); } /** @@ -64,8 +63,8 @@ public class ModuleController { */ @GetMapping @Operation(tags = {"CMC"}, summary = "模型列表(全部)") - public GeneralResult> list() { - return moduleService.list(); + public GeneralResult> list(@RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.list(positionKey); } /** @@ -76,8 +75,9 @@ public class ModuleController { */ @GetMapping(value = "/{id}") @Operation(tags = {"CMC"}, summary = "模型详情") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { - return moduleService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.detail(id, positionKey); } /** @@ -130,8 +130,9 @@ public class ModuleController { */ @GetMapping(value = "/{id}/relation/category") @Operation(tags = {"CMC"}, summary = "模型关联分组查询") - public GeneralResult> listRelationCategory(@PathVariable(value = Common.ID) Long id) { - return relationCategoryService.listByModuleId(id); + public GeneralResult> listRelationCategory(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return relationCategoryService.listByModuleId(id, positionKey); } /** @@ -156,8 +157,9 @@ public class ModuleController { */ @GetMapping(value = "/{id}/properties") @Operation(summary = "模型属性查询") - public GeneralResult property(@PathVariable(value = Common.ID) Long id) { - return moduleService.property(id); + public GeneralResult property(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.property(id, positionKey); } /** @@ -170,8 +172,9 @@ public class ModuleController { @GetMapping(value = "/{moduleId}/list") @Operation(summary = "模型属性列表") public GeneralResult> propertyList(@PathVariable(value = "moduleId") Long moduleId, - Pager pager) { - return moduleService.propertyList(moduleId, pager); + Pager pager, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.propertyList(moduleId, pager, positionKey); } /** @@ -191,16 +194,14 @@ public class ModuleController { /** * 首页统计模型总数-服务器、虚拟机、网络设备、安全设别 - * - * @param model - * @param id * @param context * @return */ @GetMapping(value = "/statistics") @Operation(summary = "首页统计模型总数") - public GeneralResult statistics(@Value(Common.REQ_CONTEXT) RequestContext context) { - return moduleService.statistics(context); + public GeneralResult statistics(@Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleService.statistics(context, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleGroupController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleGroupController.java index 84afba1..c70214f 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleGroupController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleGroupController.java @@ -1,7 +1,12 @@ package com.bocloud.ams.booter.controller.module; -import java.util.List; - +import com.bocloud.ams.entity.module.ModuleGroup; +import com.bocloud.ams.service.module.ModuleGroupService; +import com.megatron.common.model.GeneralResult; +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.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.DeleteMapping; @@ -14,14 +19,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.ModuleGroup; -import com.bocloud.ams.service.module.ModuleGroupService; -import com.megatron.common.model.GeneralResult; -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 @@ -39,8 +37,9 @@ public class ModuleGroupController { @GetMapping(value = "/collections") @Operation(tags = {"CMC"}, summary = "模型分组采集结构查询") public GeneralResult> collections(@RequestParam(value = "category") String category, - @RequestParam(value = "moduleName", required = false) String moduleName) { - return moduleGroupService.collections(category, moduleName); + @RequestParam(value = "moduleName", required = false) String moduleName, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.collections(category, moduleName, positionKey); } /** @@ -50,8 +49,8 @@ public class ModuleGroupController { */ @GetMapping(value = "/roots") @Operation(tags = {"CMC"}, summary = "模型分组根节点结构查询") - public GeneralResult> queryRoot() { - return moduleGroupService.queryRoot(); + public GeneralResult> queryRoot(@RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.queryRoot(positionKey); } /** @@ -61,8 +60,8 @@ public class ModuleGroupController { */ @GetMapping @Operation(tags = {"CMC"}, summary = "模型分组所有分组节点查询") - public GeneralResult> queryRootChildren() { - return moduleGroupService.queryRootChildren(); + public GeneralResult> queryRootChildren(@RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.queryRootChildren(positionKey); } /** @@ -74,9 +73,10 @@ public class ModuleGroupController { @GetMapping(value = "/{groupId}/children") @Operation(tags = {"CMC"}, summary = "模型分组子级数据(下级节点和模型数据)查询") public GeneralResult queryChildren(@PathVariable(value = "groupId") Long groupId, - @RequestParam(value = "menu", required = false) String menu, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return moduleGroupService.queryChildren(groupId, menu, context); + @RequestParam(value = "menu", required = false) String menu, + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.queryChildren(groupId, menu, context, positionKey); } /** @@ -87,8 +87,9 @@ public class ModuleGroupController { */ @GetMapping(value = "/{id}") @Operation(tags = {"CMC"}, summary = "模型分组详情") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { - return moduleGroupService.detail(id); + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.detail(id, positionKey); } /** @@ -138,8 +139,8 @@ public class ModuleGroupController { */ @GetMapping(value = "/list") @Operation(tags = {"CMC"}, summary = "模型分组查询") - public GeneralResult> querylist() { - return moduleGroupService.querylist(); + public GeneralResult> querylist(@RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.querylist(positionKey); } /** @@ -151,9 +152,10 @@ public class ModuleGroupController { @GetMapping(value = "/{groupId}/root/children") @Operation(tags = {"CMC"}, summary = "模型分组子级及父级数据(下级节点和模型数据)查询") public GeneralResult> queryRootChildren(@PathVariable(value = "groupId") Long groupId, - @RequestParam(value = "menu", required = false) String menu, - @Value(Common.REQ_CONTEXT) RequestContext context) { - return moduleGroupService.queryRootChildren(groupId, menu, context); + @RequestParam(value = "menu", required = false) String menu, + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleGroupService.queryRootChildren(groupId, menu, context, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleRelationController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleRelationController.java index 2687068..2f3646a 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleRelationController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/ModuleRelationController.java @@ -1,7 +1,16 @@ package com.bocloud.ams.booter.controller.module; -import java.util.List; - +import com.bocloud.ams.entity.model.ModuleTopo; +import com.bocloud.ams.entity.module.CiModule; +import com.bocloud.ams.entity.module.ModuleRelation; +import com.bocloud.ams.service.module.ModuleRelationService; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.Pager; +import com.megatron.common.model.RequestContext; +import com.megatron.common.utils.Common; +import com.megatron.common.utils.ResultTools; +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; @@ -15,18 +24,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.model.ModuleTopo; -import com.bocloud.ams.entity.module.CiModule; -import com.bocloud.ams.entity.module.ModuleRelation; -import com.bocloud.ams.service.module.ModuleRelationService; -import com.megatron.common.model.GeneralResult; -import com.megatron.common.model.Pager; -import com.megatron.common.model.RequestContext; -import com.megatron.common.utils.Common; -import com.megatron.common.utils.ResultTools; - -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; @Tag(name = "模型关系管理") @RestController @@ -39,8 +37,10 @@ public class ModuleRelationController { @GetMapping(value = "/relevancy") @Operation(tags = {"CMC", "CSC"}, summary = "根据拓扑,模型数据查询模型关系") public GeneralResult relevancy(@RequestParam("relationCategoryId") Long relationCategoryId, - @RequestParam("sourceId") Long sourceId, @RequestParam("targetId") Long targetId) { - return moduleRelationService.relevancy(relationCategoryId, sourceId, targetId); + @RequestParam("sourceId") Long sourceId, + @RequestParam("targetId") Long targetId, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleRelationService.relevancy(relationCategoryId, sourceId, targetId, positionKey); } /** @@ -53,11 +53,12 @@ public class ModuleRelationController { @GetMapping(value = "/topo") @Operation(tags = {"CMC", "CSC"}, summary = "根据模型ID和关联类型分组查询模型关系拓扑") public GeneralResult list(@RequestParam("moduleId") Long moduleId, - @RequestParam("relationCategoryId") Long relationCategoryId) { + @RequestParam("relationCategoryId") Long relationCategoryId, + @RequestParam(value = "positionKey", required = false) String positionKey) { if (null == moduleId || 0 == moduleId || null == relationCategoryId || 0 == relationCategoryId) { return ResultTools.formatErrResult(); } else { - return moduleRelationService.list(moduleId, relationCategoryId); + return moduleRelationService.list(moduleId, relationCategoryId, positionKey); } } @@ -69,13 +70,14 @@ public class ModuleRelationController { */ @GetMapping(value = "/{relationCategoryId}/topo") @Operation(tags = {"CMC", "CSC"}, summary = "根据关联类型分组ID查询模型拓扑") - public GeneralResult listAll(@PathVariable(value = "relationCategoryId") Long relationCategoryId) { + public GeneralResult listAll(@PathVariable(value = "relationCategoryId") Long relationCategoryId, + @RequestParam(value = "positionKey", required = false) String positionKey) { if (null == relationCategoryId || 0 == relationCategoryId) { return ResultTools.formatErrResult(); } - return moduleRelationService.listByCategoryId(relationCategoryId); + return moduleRelationService.listByCategoryId(relationCategoryId, positionKey); } @@ -87,13 +89,14 @@ public class ModuleRelationController { */ @GetMapping(value = "/{id}") @Operation(tags = {"CMC", "CSC"}, summary = "模型关系详情") - public GeneralResult detail(@PathVariable(value = Common.ID) Long id) { + public GeneralResult detail(@PathVariable(value = Common.ID) Long id, + @RequestParam(value = "positionKey", required = false) String positionKey) { if (null == id || 0 == id) { return ResultTools.formatErrResult(); } - return moduleRelationService.detail(id); + return moduleRelationService.detail(id, positionKey); } @@ -161,8 +164,9 @@ public class ModuleRelationController { */ @GetMapping(value = "/{relationCategoryId}/module") @Operation(tags = {"CMC", "CSC"}, summary = "关联类型分组id查询模型集合") - public GeneralResult> moduleList(@PathVariable(value = "relationCategoryId") Long relationCategoryId) { - return moduleRelationService.moduleList(relationCategoryId); + public GeneralResult> moduleList(@PathVariable(value = "relationCategoryId") Long relationCategoryId, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleRelationService.moduleList(relationCategoryId, positionKey); } private boolean paramsCheck(ModuleRelation record) { @@ -184,8 +188,10 @@ public class ModuleRelationController { @GetMapping(value = "/instances") @Operation(tags = {"CMC"}, summary = "模型关系实例列表") - public GeneralResult instances(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) { - return moduleRelationService.instances(pager, context.getTarget()); + public GeneralResult instances(Pager pager, + @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return moduleRelationService.instances(pager, context.getTarget(), positionKey); } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyController.java index 8b27e32..ee84cb1 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyController.java @@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; 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.Property; @@ -29,8 +30,9 @@ public class PropertyController { */ @GetMapping(value = "/{propertyId}") @Operation(summary = "模型属性详情") - public GeneralResult propertyDetail(@PathVariable(value = "propertyId") Long propertyId) { - return propertyService.detail(propertyId); + public GeneralResult propertyDetail(@PathVariable(value = "propertyId") Long propertyId, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return propertyService.detail(propertyId, positionKey); } } diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyPoolController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyPoolController.java index c10e96e..5310efa 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyPoolController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/PropertyPoolController.java @@ -11,6 +11,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.PropertyPool; @@ -42,8 +43,9 @@ public class PropertyPoolController { */ @GetMapping @Operation(tags = {"CMC", "CSC"}, summary = "属性池列表") - public GeneralResult> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) { - return propertyPoolService.list(pager); + public GeneralResult> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return propertyPoolService.list(pager, positionKey); } /** diff --git a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/RegularExpressionController.java b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/RegularExpressionController.java index b2e6a56..2c8fb84 100644 --- a/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/RegularExpressionController.java +++ b/bocloud.ams.booter/src/main/java/com/bocloud/ams/booter/controller/module/RegularExpressionController.java @@ -1,20 +1,18 @@ package com.bocloud.ams.booter.controller.module; -import java.util.List; - +import com.bocloud.ams.entity.module.RegularExpression; +import com.bocloud.ams.service.module.RegularExpressionService; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.utils.Common; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; 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.RegularExpression; -import com.bocloud.ams.service.module.RegularExpressionService; -import com.megatron.common.model.GeneralResult; -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 @@ -31,7 +29,8 @@ public class RegularExpressionController { */ @GetMapping @Operation(tags = {"CMC"}, summary ="正则表达式列表") - public GeneralResult> list(@RequestParam(value = Common.TYPE) String type) { - return regularExpressionService.list(type); + public GeneralResult> list(@RequestParam(value = Common.TYPE) String type, + @RequestParam(value = "positionKey", required = false) String positionKey) { + return regularExpressionService.list(type, positionKey); } } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/TableLogRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/TableLogRepository.java index 20dd4ed..03d4562 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/TableLogRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/TableLogRepository.java @@ -4,6 +4,7 @@ import com.bocloud.ams.entity.TableLog; 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; @@ -25,4 +26,15 @@ public class TableLogRepository extends BasicGenericDao { List list = this.list(TableLog.class, sql, MapTools.simpleMap("templateTable", templateTable)); return list; } + + public List query(String templateTable, String positionKey) { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select * from ci_table_log a where a.template_table = :templateTable and status='SUCCESS' and is_deleted = 0 "; + }else { + sql = "select * from "+positionKey+".ci_table_log a where a.template_table = :templateTable and status='SUCCESS' and is_deleted = 0 "; + } + List list = this.list(TableLog.class, sql, MapTools.simpleMap("templateTable", templateTable)); + return list; + } } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemRepository.java index a03abc4..be41993 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemRepository.java @@ -5,6 +5,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; @@ -41,10 +42,37 @@ public class AutoRelationRuleItemRepository extends BasicGenericDao queryByRuleId(Long ruleId, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select b.name source_field_name,b.code source_field_code,b.type source_field_type, c.name target_field_name, c.code target_field_code,c.type target_field_type, a.* " + + " from ci_auto_relation_rule_item a LEFT JOIN ci_property b ON a.source_field = b.id LEFT JOIN ci_property c ON a.target_field = c.id where a.is_deleted=0 and a.relation_rule_id = :ruleId "; + } else { + sql = "select b.name source_field_name,b.code source_field_code,b.type source_field_type, c.name target_field_name, c.code target_field_code,c.type target_field_type, a.* from " + positionKey + "." + + "ci_auto_relation_rule_item a LEFT JOIN " + positionKey + "." + + "ci_property b ON a.source_field = b.id LEFT JOIN " + positionKey + "." + + "ci_property c ON a.target_field = c.id " + positionKey + "." + + "where a.is_deleted=0 and a.relation_rule_id = :ruleId "; + } + + return this.list(AutoRelationRuleItem.class, sql, MapTools.simpleMap("ruleId", ruleId)); + } + public AutoRelationRuleItem query(Long id) throws Exception { String sql = "select * from ci_auto_relation_rule_item where id = :id"; List list = this.list(AutoRelationRuleItem.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public AutoRelationRuleItem query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select * from ci_auto_relation_rule_item where id = :id"; + } else { + sql = "select * from "+positionKey+".ci_auto_relation_rule_item where id = :id"; + } + List list = this.list(AutoRelationRuleItem.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemValueRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemValueRepository.java index 753e258..318468a 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemValueRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleItemValueRepository.java @@ -4,6 +4,7 @@ import com.bocloud.ams.entity.association.AutoRelationRuleItemValue; 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; @@ -37,6 +38,16 @@ public class AutoRelationRuleItemValueRepository extends BasicGenericDao queryByItemId(Long itemId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select * from " + positionKey + ".ci_auto_relation_rule_item_value where is_deleted=0 and item_id = :itemId "; + } else { + sql = "select * from ci_auto_relation_rule_item_value where is_deleted=0 and item_id = :itemId "; + } + return this.list(AutoRelationRuleItemValue.class, sql, MapTools.simpleMap("itemId", itemId)); + } + public List queryAllByItemId(Long itemId) throws Exception { String sql = "select a.*,if(a.source_module_id is not null ,sp.code,spi.code) source_field_code," + " if(a.target_module_id is not null ,tp.code,tpi.code) target_field_code," + " if(a.source_module_id is not null ,sp.name,spi.name) source_field_name," + " if(a.target_module_id is not null ,tp.name,tpi.name) target_field_name ," + " if(a.source_module_id is not null ,sp.type,spi.type) source_field_type," + " if(a.target_module_id is not null ,tp.type,tpi.type) target_field_type " + " from ci_auto_relation_rule_item_value a " + " left join ci_property sp on a.source_property_id =sp.id and sp.is_deleted =0 " + " left join ci_property tp on a.target_property_id =tp.id and tp.is_deleted =0 " + " left join ci_property_item spi on a.source_property_id = spi.id and spi.is_deleted =0 " + " left join ci_property_item tpi on a.target_property_id = tpi.id and tpi.is_deleted =0 " + " where a.is_deleted=0 and a.item_id = :itemId"; return this.list(AutoRelationRuleItemValue.class, sql, MapTools.simpleMap("itemId", itemId)); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleRepository.java index 037340f..df608b7 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/association/AutoRelationRuleRepository.java @@ -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; @@ -39,6 +40,22 @@ public class AutoRelationRuleRepository extends BasicGenericDao list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select b.name source_module_name,c.name target_module_name,d.name cmdb_relation_category_name, e.name cmdb_relation_name, a.* from " + positionKey + "." + + "ci_auto_relation_rule a LEFT JOIN " + positionKey + "." + + "ci_module b ON a.source_module_id = b.id LEFT JOIN " + positionKey + "." + + "ci_module c ON a.target_module_id = c.id LEFT JOIN " + positionKey + "." + + "ci_relation_category d ON a.relation_category_id = d.id LEFT JOIN " + positionKey + "." + + "ci_module_relation e ON a.module_relation_id = e.id where a.is_deleted = 0 "; + } else { + sql = "select b.name source_module_name,c.name target_module_name,d.name cmdb_relation_category_name, e.name cmdb_relation_name, a.* from ci_auto_relation_rule a LEFT JOIN ci_module b ON a.source_module_id = b.id LEFT JOIN ci_module c ON a.target_module_id = c.id LEFT JOIN ci_relation_category d ON a.relation_category_id = d.id LEFT JOIN ci_module_relation e ON a.module_relation_id = e.id where a.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(AutoRelationRule.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public List list(List params, Map sorter) throws Exception { String sql = "select a.id,a.name from ci_auto_relation_rule a where 1=1"; sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); @@ -50,18 +67,56 @@ public class AutoRelationRuleRepository extends BasicGenericDao list(List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.id,a.name from " + positionKey + ".ci_auto_relation_rule a where 1=1"; + } else { + sql = "select a.id,a.name from ci_auto_relation_rule a where 1=1"; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); + List list = this.list(AutoRelationRule.class, sql, getQueryBuilder().getParam(params)); + List beans = new ArrayList<>(); + for (AutoRelationRule rule : list) { + beans.add(new SimpleBean(rule.getId(), rule.getName())); + } + return beans; + } + public AutoRelationRule query(Long id) throws Exception { String sql = "select * from ci_auto_relation_rule where is_deleted=0 and id = :id"; List list = this.list(AutoRelationRule.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public AutoRelationRule query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select * from " + positionKey + ".ci_auto_relation_rule where is_deleted=0 and id = :id"; + } else { + sql = "select * from ci_auto_relation_rule where is_deleted=0 and id = :id"; + } + List list = this.list(AutoRelationRule.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_auto_relation_rule where is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, params, null, ""); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from ci_auto_relation_rule where is_deleted=0 "; + } else { + sql = "select count(1) from " + positionKey + ".ci_auto_relation_rule where is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, ""); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public int countSameName(String name) throws Exception { String sql = "select count(1) from ci_auto_relation_rule where is_deleted=0 and name = :name "; return this.countQuery(sql, MapTools.simpleMap("name", name)).intValue(); @@ -98,6 +153,17 @@ public class AutoRelationRuleRepository extends BasicGenericDao list = this.list(AutoRelationRule.class, sql, MapTools.simpleMap("moduleRelationId", moduleRelationId)); + return list.isEmpty() ? null : list.get(0); + } + public List queryByModuleIdAndCategoryId(Long moduleId, Long relationCategoryId) throws Exception { String sql = "select a.* from ci_auto_relation_rule a where a.is_deleted=0 and a.relation_category_id = :relationCategoryId and (a.source_module_id= :moduleId or a.target_module_id = :moduleId) order by a.gmt_modify desc"; Map params = MapTools.simpleMap("relationCategoryId", relationCategoryId); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditBakRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditBakRepository.java index c2e3887..f68421b 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditBakRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditBakRepository.java @@ -8,6 +8,7 @@ import com.megatron.common.model.Param; 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; @@ -98,6 +99,17 @@ public class OperationalAuditBakRepository extends BasicGenericDao= :leftTime and a.gmt_create <= :rightTime "; + Map params = new HashMap<>(); + params.put("leftTime", leftTime); + params.put("rightTime", rightTime); + return this.countQuery(sql, params).intValue(); + } + public int count(List params, List finalInstanceTableNames) throws Exception { String sql = ""; if (finalInstanceTableNames.size() == 1) { @@ -118,6 +130,43 @@ public class OperationalAuditBakRepository extends BasicGenericDao params, List finalInstanceTableNames, String positionKey) throws Exception { + String sql = ""; + if (StringUtils.isEmpty(positionKey)) { + if (finalInstanceTableNames.size() == 1) { + sql = "select count(1) from " + finalInstanceTableNames.get(0) + " b where b.is_deleted = 0"; + } else { + sql = "select count(1) from ("; + for (int i = 0; i < finalInstanceTableNames.size(); i++) { + if (i > 0) { + sql += " union all "; + } + sql += "(select * from " + finalInstanceTableNames.get(i) + " a where a.is_deleted = 0 )"; + + } + sql += ") b where 1=1 "; + } + } else { + if (finalInstanceTableNames.size() == 1) { + sql = "select count(1) from " + positionKey + "." + finalInstanceTableNames.get(0) + " b where b.is_deleted = 0"; + } else { + sql = "select count(1) from ("; + for (int i = 0; i < finalInstanceTableNames.size(); i++) { + if (i > 0) { + sql += " union all "; + } + sql += "(select * from " + positionKey + "." + finalInstanceTableNames.get(i) + " a where a.is_deleted = 0 )"; + + } + sql += ") b where 1=1 "; + } + } + + sql = getQueryBuilder().buildRaw(sql, params, null, "b"); + Map paramMap = getQueryBuilder().getParam(params); + return this.countQuery(sql, paramMap).intValue(); + } + public List list(Pager pager, List finalInstanceTableNames) throws Exception { String sql = ""; @@ -140,4 +189,43 @@ public class OperationalAuditBakRepository extends BasicGenericDao list(Pager pager, List finalInstanceTableNames, String positionKey) throws Exception { + + String sql = ""; + if (StringUtils.isEmpty(positionKey)) { + if (finalInstanceTableNames.size() == 1) { + sql = "select * from " + finalInstanceTableNames.get(0) + " b where b.is_deleted = 0"; + } else { + sql = "select * from ("; + for (int i = 0; i < finalInstanceTableNames.size(); i++) { + if (i > 0) { + sql += " union all "; + } + sql += "(select * from " + finalInstanceTableNames.get(i) + " a where a.is_deleted = 0 )"; + + } + sql += ") b where 1=1 "; + } + } else { + if (finalInstanceTableNames.size() == 1) { + sql = "select * from " + positionKey + "." + finalInstanceTableNames.get(0) + " b where b.is_deleted = 0"; + } else { + sql = "select * from ("; + for (int i = 0; i < finalInstanceTableNames.size(); i++) { + if (i > 0) { + sql += " union all "; + } + sql += "(select * from " + positionKey + "." + finalInstanceTableNames.get(i) + " a where a.is_deleted = 0 )"; + + } + sql += ") b where 1=1 "; + } + } + + + sql = getQueryBuilder().buildRaw(sql, pager, "b"); + + return this.list(OperationalAuditBak.class, sql); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditRepository.java index eb7a82e..0b9d2b2 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/audit/OperationalAuditRepository.java @@ -7,6 +7,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; @@ -34,18 +35,53 @@ public class OperationalAuditRepository extends BasicGenericDao params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select count(1) from " + positionKey + ".ci_operational_audit where is_deleted = 0 "; + } else { + sql = "select count(1) from ci_operational_audit where is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, ""); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public List list(Pager pager) throws Exception { String sql = "select * from ci_operational_audit where is_deleted = 0 "; sql = getQueryBuilder().buildRaw(sql, pager, null); return this.list(OperationalAudit.class, sql); } + public List list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select * from " + positionKey + ".ci_operational_audit where is_deleted = 0 "; + } else { + sql = "select * from ci_operational_audit where is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, null); + return this.list(OperationalAudit.class, sql); + } + public OperationalAudit query(Long id) throws Exception { String sql = "select * from ci_operational_audit where is_deleted=0 and id = :id"; List list = this.list(OperationalAudit.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public OperationalAudit query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select * from " + positionKey + ".ci_operational_audit where is_deleted=0 and id = :id"; + } else { + sql = "select * from ci_operational_audit where is_deleted=0 and id = :id"; + } + + List list = this.list(OperationalAudit.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + + public List list(List params) throws Exception { String sql = "select * from ci_operational_audit a where 1 = 1"; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionComponentRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionComponentRepository.java index 95b4d65..2aa8e3c 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionComponentRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionComponentRepository.java @@ -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; @@ -36,6 +37,21 @@ public class CollectionComponentRepository extends BasicGenericDao list(int page, int rows, List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select ccc.*,cm.name as module_name, cp.name as property_name from " + positionKey + "." + + "ci_collection_component ccc left join " + positionKey + "." + + "ci_module cm on ccc.module_id = cm.id left join " + positionKey + "." + + "ci_property cp on ccc.property_id = cp.id " + + "where ccc.is_deleted = 0 "; + } else { + sql = "select ccc.*,cm.name as module_name, cp.name as property_name from ci_collection_component ccc left join ci_module cm on ccc.module_id = cm.id left join ci_property cp on ccc.property_id = cp.id where ccc.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "ccc"); + return this.list(CollectionComponent.class, sql, getQueryBuilder().getParam(params)); + } + public List list(List params, Map sorter) throws Exception { String sql = "select a.id,a.name from ci_collection_component a where a.is_deleted=0"; sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); @@ -47,12 +63,39 @@ public class CollectionComponentRepository extends BasicGenericDao list(List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select a.id,a.name from ci_collection_component a where a.is_deleted=0"; + } else { + sql = "select a.id,a.name from " + positionKey + ".ci_collection_component a where a.is_deleted=0"; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); + List list = this.list(CollectionComponent.class, sql, getQueryBuilder().getParam(params)); + List beans = new ArrayList<>(); + for (CollectionComponent component : list) { + beans.add(new SimpleBean(component.getId(), component.getName())); + } + return beans; + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_collection_component 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 params, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from ci_collection_component a where a.is_deleted=0 "; + } else { + sql = "select count(1) from " + positionKey + ".ci_collection_component a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public CollectionComponent query(Long id) throws Exception { String sql = "select * from ci_collection_component where id = :id and is_deleted = 0"; List list = this.list(CollectionComponent.class, sql, MapTools.simpleMap(Common.ID, id)); @@ -64,6 +107,20 @@ public class CollectionComponentRepository extends BasicGenericDao queryByTemplateId(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select ccc.*,cm.name as module_name, cp.name as property_name from ci_collection_component ccc left join ci_module cm on ccc.module_id = cm.id left join ci_property cp on cp.id = ccc.property_id where ccc.template_id = :id and ccc.is_deleted = 0 "; + } else { + sql = "select ccc.*,cm.name as module_name, cp.name as property_name from " + positionKey + "." + + "ci_collection_component ccc left join " + positionKey + "." + + "ci_module cm on ccc.module_id = cm.id left join " + positionKey + "." + + "ci_property cp on cp.id = ccc.property_id " + + "where ccc.template_id = :id and ccc.is_deleted = 0 "; + } + return this.list(CollectionComponent.class, sql, MapTools.simpleMap(Common.ID, id)); + } + public List queryByTemplateId(Long id, String types, String parameterType) throws Exception { String sql = "select * from ci_collection_component where template_id = :id and type in(:type) and is_deleted = 0"; Map params = MapTools.simpleMap(Common.ID, id); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryItemRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryItemRepository.java index 3cd04a1..681a3d1 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryItemRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryItemRepository.java @@ -6,6 +6,7 @@ import com.megatron.common.model.Param; 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; @@ -32,12 +33,38 @@ public class CollectionHistoryItemRepository extends BasicGenericDao list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.* from (select a.*,cp.name as property_name from " + positionKey + "." + + "ci_collection_history_item a left join " + positionKey + "." + + "ci_property cp on a.property_id = cp.id) a where 1=1 "; + } else { + sql = "select a.* from (select a.*,cp.name as property_name from ci_collection_history_item a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(CollectionHistoryItem.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from (select a.*,cp.name as property_name from ci_collection_history_item a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(List params, String positionKey) throws Exception { + String sql; + if (!StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from (select a.*,cp.name as property_name from " + positionKey + "." + + "ci_collection_history_item a left join " + positionKey + "." + + "ci_property cp on a.property_id = cp.id) a where 1=1 "; + } else { + sql = "select count(1) from (select a.*,cp.name as property_name from ci_collection_history_item a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public List listByHistoryId(Long historyId) throws Exception { String sql = "select a.* from ci_collection_history_item a where a.history_id = :historyId"; return this.list(CollectionHistoryItem.class, sql, MapTools.simpleMap("historyId", historyId)); @@ -60,10 +87,28 @@ public class CollectionHistoryItemRepository extends BasicGenericDao list(String tableName, Pager pager, String positionKey) throws Exception { + if (StringUtils.isNotBlank(positionKey)) { + tableName = positionKey + "." + tableName; + } + String sql = "select a.* from (select a.*,cp.name as property_name from " + tableName + " a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(CollectionHistoryItem.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(String tableName, List params) throws Exception { String sql = "select count(1) from (select a.*,cp.name as property_name from " + tableName + " a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(String tableName, List params, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + tableName = positionKey + "." + tableName; + } + String sql = "select count(1) from (select a.*,cp.name as property_name from " + tableName + " a left join ci_property cp on a.property_id = cp.id) a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryRepository.java index 4175cde..0c70f36 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionHistoryRepository.java @@ -7,6 +7,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; @@ -36,18 +37,52 @@ public class CollectionHistoryRepository extends BasicGenericDao queryByIdAndType(Long taskInstanceId, String type, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select a.* from ci_collection_history a where a.task_instance_id = :taskInstanceId and a.type = :type "; + } else { + sql = "select a.* from "+positionKey+".ci_collection_history a where a.task_instance_id = :taskInstanceId and a.type = :type "; + } + Map params = MapTools.simpleMap("taskInstanceId", taskInstanceId); + params.put("type", type); + return list(CollectionHistory.class, sql, params); + } + public List list(Pager pager) throws Exception { String sql = "select a.* from ci_collection_history a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, pager, "a"); return this.list(CollectionHistory.class, sql, getQueryBuilder().getParam(pager.getParams())); } + public List list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select a.* from ci_collection_history a where 1=1 "; + } else { + sql = "select a.* from "+positionKey+".ci_collection_history a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(CollectionHistory.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_collection_history a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from ci_collection_history a where 1=1 "; + } else { + sql = "select count(1) from "+positionKey+".ci_collection_history a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public CollectionHistory query(Long id) throws Exception { String sql = "select a.* from ci_collection_history a where a.id = :id "; List list = this.list(CollectionHistory.class, sql, MapTools.simpleMap(Common.ID, id)); @@ -77,16 +112,44 @@ public class CollectionHistoryRepository extends BasicGenericDao queryByIdAndType(String tableName, Long taskInstanceId, String type, String positionKey) throws Exception { + if (!StringUtils.isEmpty(positionKey)) { + tableName = positionKey + "." + tableName; + } + String sql = "select a.* from " + tableName + " a where a.task_instance_id = :taskInstanceId and a.type = :type "; + Map params = MapTools.simpleMap("taskInstanceId", taskInstanceId); + params.put("type", type); + return list(CollectionHistory.class, sql, params); + } + public int count(String tableName, List params) throws Exception { String sql = "select count(1) from " + tableName + " a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(String tableName, List params, String positionKey) throws Exception { + if (!StringUtils.isEmpty(positionKey)) { + tableName = positionKey + "." + tableName; + } + String sql = "select count(1) from " + tableName + " a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public List list(String tableName, Pager pager) throws Exception { String sql = "select a.* from " + tableName + " a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, pager, "a"); return this.list(CollectionHistory.class, sql, getQueryBuilder().getParam(pager.getParams())); } + public List list(String tableName, Pager pager, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + tableName = positionKey + "." + tableName; + } + String sql = "select a.* from " + tableName + " a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(CollectionHistory.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskInstanceRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskInstanceRepository.java index da41787..b4c9610 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskInstanceRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskInstanceRepository.java @@ -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,6 +44,21 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao list(int page, int rows, List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select cti.id,cti.name,cti.type,cti.status,cti.is_deleted,cti.gmt_create,cti.gmt_modify,cti.creator_id,cti.mender_id,cti.uuid,cti.code,cti.timeout,cti.graph,cti.cron,cti.task_id,cti.gmt_finish,cti.finish_time,cti.input,cti.collection_finish,cti.collection_time,cti.collection_status, cct.module_id as module_id, cm.code as module_code from ci_collection_task_instance cti left join ci_collection_task cct on cti.task_id = cct.id left join ci_module cm on cct.module_id = cm.id where cti.is_deleted = 0 "; + } else { + sql = "select cti.id,cti.name,cti.type,cti.status,cti.is_deleted,cti.gmt_create,cti.gmt_modify,cti.creator_id,cti.mender_id,cti.uuid,cti.code,cti.timeout,cti.graph,cti.cron,cti.task_id,cti.gmt_finish,cti.finish_time,cti.input,cti.collection_finish,cti.collection_time,cti.collection_status, cct.module_id as module_id, cm.code as module_code from " + positionKey + "." + + "ci_collection_task_instance cti left join " + positionKey + "." + + "ci_collection_task cct on cti.task_id = cct.id left join " + positionKey + "." + + "ci_module cm on cct.module_id = cm.id " + + "where cti.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "cti"); + return this.list(CollectionTaskInstance.class, sql, getQueryBuilder().getParam(params)); + } + public List list(List params, Map sorter) throws Exception { String sql = "select a.id,a.name from ci_collection_task_instance a where a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); @@ -54,12 +70,39 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao list(List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select a.id,a.name from ci_collection_task_instance a where a.is_deleted=0 "; + } else { + sql = "select a.id,a.name " + positionKey + ".from ci_collection_task_instance a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); + List list = this.list(CollectionTaskInstance.class, sql, getQueryBuilder().getParam(params)); + List beans = new ArrayList<>(); + for (CollectionTaskInstance instance : list) { + beans.add(new SimpleBean(instance.getId(), instance.getName())); + } + return beans; + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_collection_task_instance a where a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int countByPositionKey(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select count(1) from " + positionKey + ".ci_collection_task_instance a where a.is_deleted=0 "; + } else { + sql = "select count(1) from ci_collection_task_instance a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public List list(List params) throws Exception { String sql = "select * from ci_collection_task_instance a where a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); @@ -73,6 +116,17 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public CollectionTaskInstance queryByTaskId(String taskId) throws Exception { String sql = "select * from ci_collection_task_instance where uuid = :uuid and is_deleted = 0"; List list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.UUID, taskId)); @@ -94,18 +148,55 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao query(String taskInstanceBakName, String leftTime, String rightTime, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + taskInstanceBakName = positionKey + "." + taskInstanceBakName; + } + String sql = "select id from " + taskInstanceBakName + " a where a.is_deleted = 0 and a.gmt_create >= :leftTime and a.gmt_create <= :rightTime "; + Map params = new HashMap<>(); + params.put("leftTime", leftTime); + params.put("rightTime", rightTime); + List list = this.list(CollectionTaskInstance.class, sql, params); + return list; + } + public List list(Pager pager, String taskInstanceBakName) throws Exception { String sql = "select cti.id,cti.name,cti.type,cti.status,cti.is_deleted,cti.gmt_create,cti.gmt_modify,cti.creator_id,cti.mender_id,cti.uuid,cti.code,cti.timeout,cti.graph,cti.cron,cti.task_id,cti.gmt_finish,cti.finish_time,cti.input,cti.collection_finish,cti.collection_time,cti.collection_status, cct.module_id as module_id, cm.code as module_code , '" + taskInstanceBakName + "' AS table_name from " + taskInstanceBakName + " cti left join ci_collection_task cct on cti.task_id = cct.id left join ci_module cm on cct.module_id = cm.id where cti.is_deleted = 0 "; sql = getQueryBuilder().buildRaw(sql, pager, "cti"); return this.list(CollectionTaskInstance.class, sql); } + public List list(Pager pager, String taskInstanceBakName, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select cti.id,cti.name,cti.type,cti.status,cti.is_deleted,cti.gmt_create,cti.gmt_modify,cti.creator_id,cti.mender_id,cti.uuid,cti.code,cti.timeout,cti.graph,cti.cron,cti.task_id,cti.gmt_finish,cti.finish_time,cti.input,cti.collection_finish,cti.collection_time,cti.collection_status, cct.module_id as module_id, cm.code as module_code , '" + taskInstanceBakName + "' AS table_name from " + positionKey + "." + taskInstanceBakName + " cti left join " + positionKey + "." + + "ci_collection_task cct on cti.task_id = cct.id left join " + positionKey + "." + + "ci_module cm on cct.module_id = cm.id where cti.is_deleted = 0 "; + + } else { + sql = "select cti.id,cti.name,cti.type,cti.status,cti.is_deleted,cti.gmt_create,cti.gmt_modify,cti.creator_id,cti.mender_id,cti.uuid,cti.code,cti.timeout,cti.graph,cti.cron,cti.task_id,cti.gmt_finish,cti.finish_time,cti.input,cti.collection_finish,cti.collection_time,cti.collection_status, cct.module_id as module_id, cm.code as module_code , '" + taskInstanceBakName + "' AS table_name from " + taskInstanceBakName + " cti left join ci_collection_task cct on cti.task_id = cct.id left join ci_module cm on cct.module_id = cm.id where cti.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "cti"); + return this.list(CollectionTaskInstance.class, sql); + } + public List listIdBak(List params, Map sorter, String taskInstanceBakName) throws Exception { String sql = "select cti.id , '" + taskInstanceBakName + "' AS table_name from " + taskInstanceBakName + " cti where cti.is_deleted = 0 "; sql = getQueryBuilder().buildRaw(sql, params, sorter, "cti"); return this.list(CollectionTaskInstance.class, sql); } + public List listIdBak(List params, Map sorter, String taskInstanceBakName, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select cti.id , '" + taskInstanceBakName + "' AS table_name from " + positionKey + "." + taskInstanceBakName + " cti where cti.is_deleted = 0 "; + } else { + sql = "select cti.id , '" + taskInstanceBakName + "' AS table_name from " + taskInstanceBakName + " cti where cti.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, sorter, "cti"); + return this.list(CollectionTaskInstance.class, sql); + } + public int count(List params, String taskInstanceBakName) throws Exception { String sql = "select count(*) from " + taskInstanceBakName + " a where a.is_deleted = 0"; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); @@ -113,10 +204,31 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao params, String taskInstanceBakName, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + taskInstanceBakName = positionKey + "." + taskInstanceBakName; + } + String sql = "select count(*) from " + taskInstanceBakName + " a where a.is_deleted = 0"; + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + Map paramMap = getQueryBuilder().getParam(params); + return this.countQuery(sql, paramMap).intValue(); + } + public CollectionTaskInstance query(Long id, String tableName) throws Exception { String sql = "select * , '" + tableName + "' as table_name from " + tableName + " where id = :id and is_deleted = 0"; List list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public CollectionTaskInstance query(Long id, String tableName, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * , '" + tableName + "' as table_name from " + positionKey + "." + tableName + " where id = :id and is_deleted = 0"; + } else { + sql = "select * , '" + tableName + "' as table_name from " + tableName + " where id = :id and is_deleted = 0"; + } + List list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskRepository.java index ebc2e99..0699980 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTaskRepository.java @@ -31,16 +31,50 @@ public class CollectionTaskRepository extends BasicGenericDao list(int page, int rows, List params, Map sorter) - throws Exception { + throws Exception { String sql = - "select cct.*,c.name as template_name, cm.name as module_name from ci_collection_task cct left join ci_collection_template c on cct.template_id = c.id left join ci_module cm on cct.module_id = cm.id where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + "select cct.*,c.name as template_name, cm.name as module_name from ci_collection_task cct left join ci_collection_template c on cct.template_id = c.id left join ci_module cm on cct.module_id = cm.id where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + sql = getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "cct"); + return this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params)); + } + + public List list(int page, int rows, List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select cct.*,c.name as template_name, cm.name as module_name from " + positionKey + "." + + "ci_collection_task cct left join " + positionKey + "." + + "ci_collection_template c on cct.template_id = c.id left join " + positionKey + "." + + "ci_module cm on cct.module_id = cm.id " + + "where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + } else { + sql = "select cct.*,c.name as template_name, cm.name as module_name from ci_collection_task cct left join ci_collection_template c on cct.template_id = c.id left join ci_module cm on cct.module_id = cm.id where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + } sql = getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "cct"); return this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params)); } public List list(List params, Map sorter) throws Exception { String sql = - "select a.id,a.name from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted = 0 "; + "select a.id,a.name from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted = 0 "; + sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); + List list = this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params)); + List beans = new ArrayList<>(); + for (CollectionTask task : list) { + beans.add(new SimpleBean(task.getId(), task.getName())); + } + return beans; + } + + public List list(List params, Map sorter, String positinKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positinKey)) { + sql = "select a.id,a.name from " + positinKey + "." + + "ci_collection_task a left join " + positinKey + "." + + "ci_module b on a.module_id = b.id " + + "where b.status ='ENABLE' and a.is_deleted = 0 "; + } else { + sql = "select a.id,a.name from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted = 0 "; + } sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); List list = this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params)); List beans = new ArrayList<>(); @@ -52,7 +86,21 @@ public class CollectionTaskRepository extends BasicGenericDao params) throws Exception { String sql = - "select count(1) from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted=0 "; + "select count(1) from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted=0 "; + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + + public int count(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select count(1) from " + positionKey + "." + + "ci_collection_task a left join " + positionKey + "." + + "ci_module b on a.module_id = b.id " + + "where b.status ='ENABLE' and a.is_deleted=0 "; + } else { + sql = "select count(1) from ci_collection_task a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted=0 "; + } sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } @@ -63,6 +111,17 @@ public class CollectionTaskRepository extends BasicGenericDao list = this.list(CollectionTask.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public List queryByTemplateId(Long templateId) throws Exception { String sql = "select * from ci_collection_task where template_id = :templateId and is_deleted = 0"; return this.list(CollectionTask.class, sql, MapTools.simpleMap("templateId", templateId)); @@ -70,7 +129,7 @@ public class CollectionTaskRepository extends BasicGenericDao params = MapTools.simpleMap(Common.ID, id); params.put("gmtModify", new Date()); params.put("userId", userId); @@ -95,7 +154,7 @@ public class CollectionTaskRepository extends BasicGenericDao param = MapTools.simpleMap("id", id); param.put("status", status); param.put("menderId", menderId); @@ -104,8 +163,8 @@ public class CollectionTaskRepository extends BasicGenericDao findScriptTaskByModuleId(Long moduleId) { String sql = - "select c.* from ci_collection_task c,ci_collection_template t where c.template_id =t.id and t.is_deleted =0 and c.is_deleted =0 " - + " and t.collection_type ='script' and t.module_id = :moduleId "; + "select c.* from ci_collection_task c,ci_collection_template t where c.template_id =t.id and t.is_deleted =0 and c.is_deleted =0 " + + " and t.collection_type ='script' and t.module_id = :moduleId "; return this.list(CollectionTask.class, sql, MapTools.simpleMap("moduleId", moduleId)); } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTemplateRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTemplateRepository.java index c4d4079..5aa6b68 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTemplateRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/collection/CollectionTemplateRepository.java @@ -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; @@ -42,6 +43,19 @@ public class CollectionTemplateRepository extends BasicGenericDao list(int page, int rows, List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select cct.*,cm.name as module_name from " + positionKey + "." + + "ci_collection_template cct left join " + positionKey + "." + + "ci_module cm on cct.module_id = cm.id where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + } else { + sql = "select cct.*,cm.name as module_name from ci_collection_template cct left join ci_module cm on cct.module_id = cm.id where cct.is_deleted = 0 and cm.status = 'ENABLE' "; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(page, rows, params, sorter), "cct"); + return this.list(CollectionTemplate.class, sql, getQueryBuilder().getParam(params)); + } + public List list(List params, Map sorter) throws Exception { String sql = "select a.id,a.name,a.collection_type from ci_collection_template a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); @@ -53,18 +67,65 @@ public class CollectionTemplateRepository extends BasicGenericDao list(List params, Map sorter, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select a.id,a.name,a.collection_type from ci_collection_template a left join ci_module b on a.module_id = b.id where b.status ='ENABLE' and a.is_deleted=0 "; + } else { + sql = "select a.id,a.name,a.collection_type from " + positionKey + "." + + "ci_collection_template a left join " + positionKey + "." + + "ci_module b on a.module_id = b.id " + + "where b.status ='ENABLE' and a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); + List list = this.list(CollectionTemplate.class, sql, getQueryBuilder().getParam(params)); + List beans = new ArrayList<>(); + for (CollectionTemplate template : list) { + beans.add(new SimpleBean(template.getId(), template.getName(), template.getCollectionType())); + } + return beans; + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_collection_template a left join ci_module b on a.module_id = b.id where b.status= 'ENABLE' and a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from ci_collection_template a left join ci_module b on a.module_id = b.id where b.status= 'ENABLE' and a.is_deleted=0 "; + } else { + sql = "select count(1) from " + positionKey + "." + + "ci_collection_template a left join " + positionKey + "." + + "ci_module b on a.module_id = b.id " + + "where b.status= 'ENABLE' and a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public CollectionTemplate query(Long id) throws Exception { String sql = "select cct.*,cm.name as module_name from ci_collection_template cct left join ci_module cm on cct.module_id = cm.id where cct.id = :id and cct.is_deleted = 0 "; List list = this.list(CollectionTemplate.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public CollectionTemplate query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select cct.*,cm.name as module_name from ci_collection_template cct left join ci_module cm on cct.module_id = cm.id where cct.id = :id and cct.is_deleted = 0 "; + } else { + sql = "select cct.*,cm.name as module_name from " + positionKey + "." + + "ci_collection_template cct left join " + positionKey + "." + + "ci_module cm on cct.module_id = cm.id " + + "where cct.id = :id and cct.is_deleted = 0 "; + } + List list = this.list(CollectionTemplate.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_collection_template set is_deleted=1,gmt_modify = :gmtModify,mender_id=:userId where id = :id"; Map params = MapTools.simpleMap(Common.ID, id); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/config/CmdbConfigRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/config/CmdbConfigRepository.java index 6a0bd70..961c48b 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/config/CmdbConfigRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/config/CmdbConfigRepository.java @@ -6,6 +6,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; @@ -54,9 +55,29 @@ public class CmdbConfigRepository extends BasicGenericDao { return this.list(CmdbConfig.class, sql, MapTools.simpleMap(Common.CODE, codes)); } + public List listByCodes(Set codes, String positionKey) throws DataBaseException { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select * from ci_cmdb_config where code = :code"; + } else { + sql = "select * from " + positionKey + ".ci_cmdb_config where code = :code"; + } + return this.list(CmdbConfig.class, sql, MapTools.simpleMap(Common.CODE, codes)); + } + public List listByCategory(String category) throws DataBaseException { String sql = "select * from ci_cmdb_config where category = (:category)"; return this.list(CmdbConfig.class, sql, MapTools.simpleMap("category", category)); } + public List listByCategory(String category, String positionKey) throws DataBaseException { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select * from ci_cmdb_config where category = (:category)"; + } else { + sql = "select * from " + positionKey + ".ci_cmdb_config where category = (:category)"; + } + return this.list(CmdbConfig.class, sql, MapTools.simpleMap("category", category)); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceAuthorityRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceAuthorityRepository.java index fc435fb..0609f54 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceAuthorityRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceAuthorityRepository.java @@ -7,6 +7,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; @@ -34,12 +35,34 @@ public class InstanceAuthorityRepository extends BasicGenericDao list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_instance_authority a where a.is_deleted = 0 "; + } else { + sql = "select a.* from ci_instance_authority a where a.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(InstanceAuthority.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_instance_authority 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 params, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = "select count(1) from ci_instance_authority a where a.is_deleted = 0 "; + } else { + sql = "select count(1) from " + positionKey + ".ci_instance_authority a where a.is_deleted = 0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public InstanceAuthority query(Long id) throws Exception { String sql = "select * from ci_instance_authority a where a.id = :id and is_deleted=0 "; List list = this.list(InstanceAuthority.class, sql, MapTools.simpleMap(Common.ID, id)); @@ -113,6 +136,19 @@ public class InstanceAuthorityRepository extends BasicGenericDao listByUserId(Long moduleId, Long instanceId, Long authUserId, String positioonKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positioonKey)) { + sql = "select * from " + positioonKey + ".ci_instance_authority a where is_deleted=0 and a.module_id = :moduleId and a.instance_id = :instanceId " + " and a.user_id = :authUserId "; + } else { + sql = "select * from ci_instance_authority a where is_deleted=0 and a.module_id = :moduleId and a.instance_id = :instanceId " + " and a.user_id = :authUserId "; + } + Map params = MapTools.simpleMap("moduleId", moduleId); + params.put("instanceId", instanceId); + params.put("authUserId", authUserId); + return this.list(InstanceAuthority.class, sql, params); + } + public InstanceAuthority queryByAuth(Long moduleId, Long instanceId, Long authUserId, String auth) throws Exception { String sql = "select * from ci_instance_authority a where is_deleted=0 and a.module_id = :moduleId and a.instance_id = :instanceId " + " and a.user_id = :authUserId and a.auths like '%" + auth + "%'"; Map params = MapTools.simpleMap("moduleId", moduleId); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceHistoryRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceHistoryRepository.java index 0f65b6c..34ccb33 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceHistoryRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceHistoryRepository.java @@ -6,6 +6,7 @@ import com.megatron.common.model.Param; 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; @@ -32,12 +33,34 @@ public class InstanceHistoryRepository extends BasicGenericDao list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_instance_history a where 1=1 "; + } else { + sql = "select a.* from ci_instance_history a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(InstanceHistory.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_instance_history a where 1=1 "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); } + public int count(List params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select count(1) from " + positionKey + ".ci_instance_history a where 1=1 "; + } else { + sql = "select count(1) from ci_instance_history a where 1=1 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public List listByInstanceId(Long moduleId, Long instanceId) throws Exception { String sql = "select a.* from ci_instance_history a where module_id = :moduleId and instance_id = :instanceId "; Map params = MapTools.simpleMap("moduleId", moduleId); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationHistoryRecordRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationHistoryRecordRepository.java index 0170f98..b9b0866 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationHistoryRecordRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationHistoryRecordRepository.java @@ -7,6 +7,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; @@ -33,12 +34,34 @@ public class InstanceRelationHistoryRecordRepository extends BasicGenericDao list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.*,b.name module_relation_name,c.name relation_category_name from "+positionKey+".ci_instance_relation_history_record a " + " left join "+positionKey+".ci_module_relation b on a.module_relation_id =b.id " + " left join "+positionKey+".ci_relation_category c on a.relation_category_id =c.id " + " where a.is_deleted=0 "; + } else { + sql = "select a.*,b.name module_relation_name,c.name relation_category_name from ci_instance_relation_history_record a " + " left join ci_module_relation b on a.module_relation_id =b.id " + " left join ci_relation_category c on a.relation_category_id =c.id " + " where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(InstanceRelationHistoryRecord.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_instance_relation_history_record 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 params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select count(1) from " + positionKey + ".ci_instance_relation_history_record a where a.is_deleted=0 "; + } else { + sql = "select count(1) from ci_instance_relation_history_record a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public InstanceRelationHistoryRecord query(Long id) throws Exception { String sql = "select a.*,b.name module_name from ci_instance_relation_history_record a left join ci_module b on a.module_id =b.id where a.id = :id and a.is_deleted=0 "; List list = this.list(InstanceRelationHistoryRecord.class, sql, MapTools.simpleMap(Common.ID, id)); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationRepository.java index d35c0d0..cde89ac 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRelationRepository.java @@ -1,6 +1,5 @@ package com.bocloud.ams.repository.instance; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.instance.InstanceRelation; import com.bocloud.ams.repository.utils.CmdbUtils; @@ -10,6 +9,7 @@ import com.megatron.common.utils.MapTools; import com.megatron.database.core.intf.impl.BasicGenericDao; import com.megatron.framework.core.CurrentService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.stereotype.Repository; @@ -118,6 +118,25 @@ public class InstanceRelationRepository extends BasicGenericDao query(String instanceRelationTable, Long sourceModuleId, Long sourceInstanceId, Long targetModuleId, Long targetInstanceId, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + instanceRelationTable = positionKey + "." + instanceRelationTable; + } + String sql = "select a.* from " + instanceRelationTable + " a where is_deleted=0 " + " and source_module_id = :sourceModuleId "; + sql += " and target_module_id = :targetModuleId "; + Map params = MapTools.simpleMap("sourceModuleId", sourceModuleId); + params.put("targetModuleId", targetModuleId); + if (null != sourceInstanceId) { + sql += " and source_instance_id = :sourceInstanceId "; + params.put("sourceInstanceId", sourceInstanceId); + } + if (null != targetInstanceId) { + sql += " and target_instance_id = :targetInstanceId "; + params.put("targetInstanceId", targetInstanceId); + } + return this.list(InstanceRelation.class, sql, params); + } + public InstanceRelation queryById(String instanceRelationTable, Long id) throws Exception { String sql = "select a.* from " + instanceRelationTable + " a where id = :id and is_deleted=0 "; List list = this.list(InstanceRelation.class, sql, MapTools.simpleMap(Common.ID, id)); @@ -222,6 +241,18 @@ public class InstanceRelationRepository extends BasicGenericDao querySources(String instanceRelationTable, Long moduleId, Long instanceId, String positonKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positonKey)) { + sql = "select a.*,b.source_type,b.target_type,b.relation_id,b.name relation_name from " + positonKey + "." + instanceRelationTable + " a " + " left join " + positonKey + ".ci_module_relation 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.source_type,b.target_type,b.relation_id,b.name relation_name from " + instanceRelationTable + " a " + " left join ci_module_relation 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 params = MapTools.simpleMap("moduleId", moduleId); + params.put("instanceId", instanceId); + return this.list(InstanceRelation.class, sql, params); + } + public List queryTargets(String instanceRelationTable, Long moduleId, Long instanceId) throws Exception { String sql = "select a.*,b.source_type,b.target_type,b.relation_id,b.name relation_name,'1' is_reversed from " + instanceRelationTable + " a " + " left join ci_module_relation 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 params = MapTools.simpleMap("moduleId", moduleId); @@ -229,6 +260,18 @@ public class InstanceRelationRepository extends BasicGenericDao queryTargets(String instanceRelationTable, Long moduleId, Long instanceId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.*,b.source_type,b.target_type,b.relation_id,b.name relation_name,'1' is_reversed from " + positionKey + "." + instanceRelationTable + " a " + " left join " + positionKey + ".ci_module_relation 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.source_type,b.target_type,b.relation_id,b.name relation_name,'1' is_reversed from " + instanceRelationTable + " a " + " left join ci_module_relation 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 params = MapTools.simpleMap("moduleId", moduleId); + params.put("instanceId", instanceId); + return this.list(InstanceRelation.class, sql, params); + } + public List listReverse(final String instanceRelationTableName, Long categoryId, List sourceInstanceIds, List targetInstanceIds) throws Exception { String 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 params = MapTools.simpleMap("categoryId", categoryId); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRepository.java index 054eb3a..2e58bdc 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceRepository.java @@ -9,6 +9,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; @@ -93,6 +94,22 @@ public class InstanceRepository extends BasicGenericDao { return this.list(sql, paramMap); } + public List> list(Pager pager, String instanceTable, String instanceValueTable, Long userId, boolean hasAdminRole, String positionKey) throws Exception { + String moduleId = CmdbUtils.getField(pager.getParams(), "moduleId"); + if (moduleId == null) { + throw new Exception("查询失败"); + } + if (StringUtils.isNotEmpty(positionKey)) { + instanceTable = positionKey + "." + instanceTable; + instanceValueTable = positionKey + "." + instanceValueTable; + } + String sql = buildSql(instanceTable, instanceValueTable, moduleId, userId, hasAdminRole); + sql = "select a.* from (" + sql + ") a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + Map paramMap = getQueryBuilder().getParam(pager.getParams()); + return this.list(sql, paramMap); + } + public int count(List params, String instanceTable, String instanceValueTable, Long userId, boolean hasAdminRole) throws Exception { String moduleId = CmdbUtils.getField(params, "moduleId"); if (moduleId == null) { @@ -105,6 +122,22 @@ public class InstanceRepository extends BasicGenericDao { return this.countQuery(sql, param).intValue(); } + public int count(List params, String instanceTable, String instanceValueTable, Long userId, boolean hasAdminRole, String positionKey) throws Exception { + String moduleId = CmdbUtils.getField(params, "moduleId"); + if (moduleId == null) { + throw new Exception("查询失败"); + } + if (StringUtils.isNotEmpty(positionKey)) { + instanceTable = positionKey + "." + instanceTable; + instanceValueTable = positionKey + "." + instanceValueTable; + } + String sql = buildSql(instanceTable, instanceValueTable, moduleId, userId, hasAdminRole); + sql = "select count(1) from (" + sql + ") a where 1=1 "; + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + Map param = getQueryBuilder().getParam(params); + return this.countQuery(sql, param).intValue(); + } + public Instance queryByUuid(String instanceTable, String uuid, Long moduleId) throws Exception { String sql = "select a.* from " + instanceTable + " a where a.uuid = :uuid and module_id = :moduleId and is_deleted=0 "; Map params = MapTools.simpleMap(Common.UUID, uuid); @@ -124,6 +157,15 @@ public class InstanceRepository extends BasicGenericDao { return list.isEmpty() ? null : list.get(0); } + public Instance query(String instanceTable, Long id, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + instanceTable = positionKey + "." + instanceTable; + } + String sql = "select a.* from " + instanceTable + " a where id = :id and is_deleted=0 "; + List list = this.list(Instance.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public boolean remove(Long id, String instanceTable, Long userId) throws Exception { String sql = "update " + instanceTable + " set is_deleted=1,gmt_modify = :gmtModify,mender_id=:userId where id = :id"; Map params = MapTools.simpleMap(Common.ID, id); @@ -171,6 +213,19 @@ public class InstanceRepository extends BasicGenericDao { return this.list(sql, MapTools.simpleMap("ids", ids)); } + public List> listAll(String instanceTable, String instanceValueTable, Long moduleId, List ids, Long userId, boolean hasAdminRole, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + instanceTable = positionKey + "." + instanceTable; + instanceValueTable = positionKey + "." + instanceValueTable; + } + String sql = buildSql(instanceTable, instanceValueTable, String.valueOf(moduleId), userId, hasAdminRole); + sql = "select a.* from (" + sql + ") a where 1=1 "; + if (null != ids && !ids.isEmpty()) { + sql += "and a.id in (:ids)"; + } + return this.list(sql, MapTools.simpleMap("ids", ids)); + } + public List queryByModuleId(String instanceTable, String instanceValueTable, Long moduleId, String propertyCode) throws Exception { String sql = "select a.id,a.uuid,a.module_id,a.module_code,b.property_value name from " + instanceTable + " a left join " + instanceValueTable + " b on a.id = b.instance_id " + " where a.module_id = :moduleId and b.property_code = :propertyCode and a.is_deleted=0 "; Map params = MapTools.simpleMap("moduleId", moduleId); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceValueRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceValueRepository.java index a9f798b..b67c4e5 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceValueRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/instance/InstanceValueRepository.java @@ -9,6 +9,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; @@ -95,6 +96,14 @@ public class InstanceValueRepository extends BasicGenericDao listByInstanceId(Long instanceId, String instanceValueTable, String positionKey) throws Exception { + if (StringUtils.isNotEmpty(positionKey)) { + instanceValueTable = positionKey + "." + instanceValueTable; + } + String sql = "select a.* from " + instanceValueTable + " a where a.is_deleted=0 and a.instance_id=:instanceId"; + return this.list(InstanceValue.class, sql, MapTools.simpleMap("instanceId", instanceId)); + } + public boolean remove(Long id, String instanceValueTable, Long userId) throws Exception { String sql = "update " + instanceValueTable + " set is_deleted=1,gmt_modify = :gmtModify,mender_id=:userId where id = :id"; Map params = MapTools.simpleMap(Common.ID, id); @@ -135,6 +144,17 @@ public class InstanceValueRepository extends BasicGenericDao params = MapTools.simpleMap("propertyCode", propertyCode); + params.put("instanceId", instanceId); + List list = this.list(InstanceValue.class, sql, params); + return list.isEmpty() ? null : list.get(0); + } + public List queryByInstanceIdsAndPropertyIds(String instanceValueTable, List instanceIds, List propertyIds) throws Exception { 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 params = MapTools.simpleMap("instanceIds", instanceIds); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleGroupRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleGroupRepository.java index 561ab4d..23574ba 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleGroupRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleGroupRepository.java @@ -5,6 +5,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; @@ -36,12 +37,34 @@ public class ModuleGroupRepository extends BasicGenericDao { 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); } + + public List queryRoot(String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from " + positionKey + ".ci_module_group where is_deleted =0 and parent_id =0 ORDER BY gmt_create DESC "; + } else { + 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); + } + public List queryRootInName(List 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 params = MapTools.simpleMap("name", nameList); return this.list(ModuleGroup.class, sql, params); } + public List queryRootInName(List nameList, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from "+positionKey+".ci_module_group where is_deleted =0 and parent_id =0 and name in (:name) ORDER BY gmt_create DESC "; + } else { + sql = "select * from ci_module_group where is_deleted =0 and parent_id =0 and name in (:name) ORDER BY gmt_create DESC "; + } + Map params = MapTools.simpleMap("name", nameList); + return this.list(ModuleGroup.class, sql, params); + } + public List 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 "; return this.list(ModuleGroup.class, sql, MapTools.simpleMap("id", id)); @@ -52,6 +75,11 @@ public class ModuleGroupRepository extends BasicGenericDao { return this.list(ModuleGroup.class, sql, null); } + public List all(String positionKey) throws Exception { + String sql = "select * from " + positionKey + ".ci_module_group where is_deleted=0 "; + return this.list(ModuleGroup.class, sql, null); + } + public int countSameNameOrCode(String name, String code) throws Exception { String sql = "select count(1) from ci_module_group where is_deleted=0 "; if (null != code) { @@ -70,9 +98,30 @@ public class ModuleGroupRepository extends BasicGenericDao { return list.isEmpty() ? null : list.get(0); } + public ModuleGroup query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from " + positionKey + ".ci_module_group a where a.id = :id and is_deleted=0 "; + } else { + sql = "select * from ci_module_group a where a.id = :id and is_deleted=0 "; + } + List list = this.list(ModuleGroup.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public List queryByIds(List ids) throws Exception { String sql = "select * from ci_module_group a where a.id in (:ids) and is_deleted=0 "; return this.list(ModuleGroup.class, sql, MapTools.simpleMap("ids", ids)); } + public List queryByIds(List ids, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from " + positionKey + ".ci_module_group a where a.id in (:ids) and is_deleted=0 "; + } else { + sql = "select * from ci_module_group a where a.id in (:ids) and is_deleted=0 "; + } + return this.list(ModuleGroup.class, sql, MapTools.simpleMap("ids", ids)); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRelationRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRelationRepository.java index fdfedcf..4366c8b 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRelationRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRelationRepository.java @@ -7,6 +7,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; @@ -53,6 +54,17 @@ public class ModuleRelationRepository extends BasicGenericDao list = this.list(ModuleRelation.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public ModuleRelation query(Long relationCategoryId, Long sourceModuleId, Long targetModuleId) throws Exception { String sql = "select a.* from ci_module_relation a where a.relation_category_id = :relationCategoryId and a.source_id = :sourceModuleId and a.target_id = :targetModuleId and is_deleted=0 "; Map params = MapTools.simpleMap("relationCategoryId", relationCategoryId); @@ -62,6 +74,20 @@ public class ModuleRelationRepository extends BasicGenericDao params = MapTools.simpleMap("relationCategoryId", relationCategoryId); + params.put("sourceModuleId", sourceModuleId); + params.put("targetModuleId", targetModuleId); + List list = this.list(ModuleRelation.class, sql, params); + return list.isEmpty() ? null : list.get(0); + } + public List list(List params, Map sorter) throws Exception { String sql = "select a.* from ci_module_relation a where is_deleted=0"; sql = getQueryBuilder().buildRaw(sql, new Pager(1, Integer.MAX_VALUE, params, sorter), "a"); @@ -75,6 +101,18 @@ public class ModuleRelationRepository extends BasicGenericDao list(Long moduleId, Long categoryId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.*,b.name relation_name,b.code relation_code from " + positionKey + ".ci_module_relation a join " + positionKey + ".ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId" + " and a.source_id=:moduleId "; + } else { + sql = "select a.*,b.name relation_name,b.code relation_code from ci_module_relation a join ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId" + " and a.source_id=:moduleId "; + } + Map params = MapTools.simpleMap("categoryId", categoryId); + params.put("moduleId", moduleId); + return this.list(ModuleRelation.class, sql, params); + } + public List listReverse(Long moduleId, Long categoryId) throws Exception { String sql = " select a.*,b.reverse_name relation_name,b.code relation_code,'1' is_reversed from ci_module_relation a join ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId " + " and a.target_id=:moduleId "; Map params = MapTools.simpleMap("categoryId", categoryId); @@ -82,11 +120,33 @@ public class ModuleRelationRepository extends BasicGenericDao listReverse(Long moduleId, Long categoryId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = " select a.*,b.reverse_name relation_name,b.code relation_code,'1' is_reversed from " + positionKey + ".ci_module_relation a join " + positionKey + ".ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId " + " and a.target_id=:moduleId "; + } else { + sql = " select a.*,b.reverse_name relation_name,b.code relation_code,'1' is_reversed from ci_module_relation a join ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId " + " and a.target_id=:moduleId "; + } + Map params = MapTools.simpleMap("categoryId", categoryId); + params.put("moduleId", moduleId); + return this.list(ModuleRelation.class, sql, params); + } + public List listByCategoryId(Long categoryId) throws Exception { String sql = "select a.*,b.name relation_name,b.code relation_code from ci_module_relation a join ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId"; return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId)); } + public List listByCategoryId(Long categoryId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.*,b.name relation_name,b.code relation_code from " + positionKey + ".ci_module_relation a join " + positionKey + ".ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId"; + } else { + sql = "select a.*,b.name relation_name,b.code relation_code from ci_module_relation a join ci_relation b on a.relation_id=b.id where a.is_deleted = 0 and b.is_deleted=0 and a.relation_category_id = :categoryId"; + } + return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId)); + } + public List queryModuleRealtionAndModuleImage(Long categoryId) throws Exception { String 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)); @@ -97,6 +157,16 @@ public class ModuleRelationRepository extends BasicGenericDao queryModuleList(Long categoryI, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_module_relation a where a.is_deleted=0 and a.relation_category_id = :categoryId"; + } else { + 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)); + } + public List queryByModuleId(Long moduleId) throws Exception { String sql = "select a.*, m1.name source_name,m2.name target_name from ci_module_relation a" + " left join ci_module m1 on m1.id=a.source_id " + " left join ci_module m2 on m2.id=a.target_id " + " where a.is_deleted=0 and (a.source_id = :moduleId OR a.target_id = :moduleId) "; return this.list(ModuleRelation.class, sql, MapTools.simpleMap("moduleId", moduleId)); @@ -134,4 +204,16 @@ public class ModuleRelationRepository extends BasicGenericDao queryAll(Long relationCategoryId, Long moduleId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.*,sb.name source_name ,rb.name target_name,r.name relation_name ,r.reverse_name relation_reverse_name from " + positionKey + ".ci_module_relation a," + positionKey + ".ci_module sb," + positionKey + ".ci_module rb," + positionKey + ".ci_relation r " + " where a.is_deleted=0 and a.source_id=sb.id and a.target_id =rb.id and a.relation_id =r.id and a.relation_category_id = :relationCategoryId and (a.source_id = :moduleId OR a.target_id = :moduleId) "; + } else { + sql = "select a.*,sb.name source_name ,rb.name target_name,r.name relation_name ,r.reverse_name relation_reverse_name from ci_module_relation a,ci_module sb,ci_module rb,ci_relation r " + " where a.is_deleted=0 and a.source_id=sb.id and a.target_id =rb.id and a.relation_id =r.id and a.relation_category_id = :relationCategoryId and (a.source_id = :moduleId OR a.target_id = :moduleId) "; + } + Map params = MapTools.simpleMap("relationCategoryId", relationCategoryId); + params.put("moduleId", moduleId); + return this.list(ModuleRelation.class, sql, params); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRepository.java index fd6cef1..1b2b699 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/ModuleRepository.java @@ -7,6 +7,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; @@ -33,12 +34,34 @@ public class ModuleRepository extends BasicGenericDao { return this.list(CiModule.class, sql, getQueryBuilder().getParam(pager.getParams())); } + public List list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.* from ci_module a where a.position_key=:positionKey "; + } else { + sql = "select a.* from ci_module a where a.position_key=:positionKey "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(CiModule.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_module 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 params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select count(1) from " + positionKey + ".ci_module a where a.is_deleted=0 "; + } else { + sql = "select count(1) from ci_module a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public boolean delete(Long id, Long userId) throws Exception { String sql = "update ci_module set is_deleted = 1, gmt_modify = :gmtModify, mender_id = :menderId where id = :id "; Map params = MapTools.simpleMap(Common.ID, id); @@ -55,6 +78,19 @@ public class ModuleRepository extends BasicGenericDao { return this.list(CiModule.class, sql, null); } + public List existCollectionTemplate(String moduleName, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "SELECT cm.* FROM " + positionKey + ".ci_module cm WHERE cm.status = 'ENABLE' and cm.is_deleted = 0 AND EXISTS (SELECT * FROM " + positionKey + ".ci_collection_template cct WHERE cct.is_deleted = 0 AND cm.id = cct.module_id) "; + } else { + sql = "SELECT cm.* FROM ci_module cm WHERE cm.status = 'ENABLE' and cm.is_deleted = 0 AND EXISTS (SELECT * FROM ci_collection_template cct WHERE cct.is_deleted = 0 AND cm.id = cct.module_id) "; + } + if (null != moduleName) { + sql += " AND cm.name LIKE '%" + moduleName + "%'"; + } + return this.list(CiModule.class, sql, null); + } + public List existCollectionTask(String moduleName) throws Exception { String sql = "SELECT cm.* FROM ci_module cm WHERE cm.status = 'ENABLE' and cm.is_deleted = 0 AND EXISTS (SELECT * FROM ci_collection_task cct WHERE cct.is_deleted = 0 AND cm.id = cct.module_id) "; if (null != moduleName) { @@ -63,11 +99,34 @@ public class ModuleRepository extends BasicGenericDao { return this.list(CiModule.class, sql, null); } + public List existCollectionTask(String moduleName, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "SELECT cm.* FROM " + positionKey + ".ci_module cm WHERE cm.status = 'ENABLE' and cm.is_deleted = 0 AND EXISTS (SELECT * FROM " + positionKey + ".ci_collection_task cct WHERE cct.is_deleted = 0 AND cm.id = cct.module_id) "; + } else { + sql = "SELECT cm.* FROM ci_module cm WHERE cm.status = 'ENABLE' and cm.is_deleted = 0 AND EXISTS (SELECT * FROM ci_collection_task cct WHERE cct.is_deleted = 0 AND cm.id = cct.module_id) "; + } + if (null != moduleName) { + sql += " AND cm.name LIKE '%" + moduleName + "%'"; + } + return this.list(CiModule.class, sql, null); + } + public List all() throws Exception { String sql = "select * from ci_module where is_deleted=0 "; return this.list(CiModule.class, sql, null); } + public List all(String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select * from " + positionKey + ".ci_module where is_deleted=0 "; + } else { + sql = "select * from ci_module where is_deleted=0 "; + } + return this.list(CiModule.class, sql, null); + } + public List queryByGroupId(Long groupId) throws Exception { String sql = "select * from ci_module where is_deleted=0 and module_group_id = :groupId ORDER BY gmt_create DESC"; return this.list(CiModule.class, sql, MapTools.simpleMap("groupId", groupId)); @@ -79,6 +138,17 @@ public class ModuleRepository extends BasicGenericDao { return list.isEmpty() ? null : list.get(0); } + public CiModule query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isEmpty(positionKey)) { + sql = " select a.* from ci_module a where a.id = :id and a.is_deleted=0 "; + } else { + sql = " select a.* from " + positionKey + ".ci_module a where a.id = :id and a.is_deleted=0 "; + } + List list = this.list(CiModule.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public int countSameNameOrCode(String name, String code) throws Exception { String sql = "select count(1) from ci_module where is_deleted=0 "; if (null != code) { @@ -96,6 +166,16 @@ public class ModuleRepository extends BasicGenericDao { return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids)); } + public List listByIds(List ids, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_module a where a.is_deleted = 0 and a.id in (:ids) "; + } else { + sql = "select a.* from ci_module a where a.is_deleted = 0 and a.id in (:ids) "; + } + return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids)); + } + /** * order by field (id, :ids)按照查询的ids顺序返回数据 * @@ -108,6 +188,17 @@ public class ModuleRepository extends BasicGenericDao { return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids)); } + public List queryModuleListByIds(List ids, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from " + positionKey + ".ci_module where is_deleted = 0 and id in (:ids) order by field (id, :ids)"; + } else { + sql = "select * from ci_module where is_deleted = 0 and id in (:ids) order by field (id, :ids)"; + } + return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids)); + } + + public CiModule queryByCode(String code) throws Exception { String sql = "select * from ci_module a where a.code = :code and is_deleted=0 "; List list = this.list(CiModule.class, sql, MapTools.simpleMap("code", code)); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyGroupRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyGroupRepository.java index 68f996c..f41d3cd 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyGroupRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyGroupRepository.java @@ -4,6 +4,7 @@ import com.bocloud.ams.entity.module.PropertyGroup; 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; @@ -38,4 +39,14 @@ public class PropertyGroupRepository extends BasicGenericDao listByModuleId(Long moduleId, String positionKey) { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from "+positionKey+".ci_property_group a where a.module_id = :moduleId and a.is_deleted = 0"; + } else { + sql = "select a.* from ci_property_group a where a.module_id = :moduleId and a.is_deleted = 0"; + } + return this.list(PropertyGroup.class, sql, MapTools.simpleMap("moduleId", moduleId)); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyItemRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyItemRepository.java index cd10f57..e8ae89a 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyItemRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyItemRepository.java @@ -4,6 +4,7 @@ import com.bocloud.ams.entity.module.PropertyItem; 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; @@ -38,11 +39,32 @@ public class PropertyItemRepository extends BasicGenericDao return this.list(PropertyItem.class, sql, MapTools.simpleMap("moduleId", moduleId)); } + public List queryByModuleId(Long moduleId, String positionKey) { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_property_item a where a.module_id = :moduleId and a.is_deleted = 0"; + } else { + sql = "select a.* from ci_property_item a where a.module_id = :moduleId and a.is_deleted = 0"; + + } + return this.list(PropertyItem.class, sql, MapTools.simpleMap("moduleId", moduleId)); + } + public List queryByPropertyId(Long propertyId) { String sql = "select a.* from ci_property_item a where a.property_id = :propertyId and a.is_deleted = 0"; return this.list(PropertyItem.class, sql, MapTools.simpleMap("propertyId", propertyId)); } + public List queryByPropertyId(Long propertyId, String positionKey) { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_property_item a where a.property_id = :propertyId and a.is_deleted = 0"; + } else { + sql = "select a.* from ci_property_item a where a.property_id = :propertyId and a.is_deleted = 0"; + } + return this.list(PropertyItem.class, sql, MapTools.simpleMap("propertyId", propertyId)); + } + public List queryByModuleIdAndPropertyIds(Long moduleId, List propertyIds) { String sql = "select a.* from ci_property_item a where a.module_id = :moduleId and a.property_id in(:propertyIds) and a.is_deleted = 0"; Map paramMap = MapTools.simpleMap("propertyIds", propertyIds); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolItemRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolItemRepository.java index 65cb239..340f04e 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolItemRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolItemRepository.java @@ -5,6 +5,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; @@ -53,6 +54,16 @@ public class PropertyPoolItemRepository extends BasicGenericDao listByPropertyPoolId(Long propertyPoolId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from "+positionKey+".ci_property_pool_item a where a.is_deleted=0 and a.property_pool_id = :propertyPoolId"; + } else { + sql = "select a.* from ci_property_pool_item a where a.is_deleted=0 and a.property_pool_id = :propertyPoolId"; + } + return this.list(PropertyPoolItem.class, sql, MapTools.simpleMap("propertyPoolId", propertyPoolId)); + } + public List listByPropertyPoolIds(List propertyPoolIds) throws Exception { String sql = "select a.* from ci_property_pool_item a where a.is_deleted=0 and a.property_pool_id in (:propertyPoolIds)"; return this.list(PropertyPoolItem.class, sql, MapTools.simpleMap("propertyPoolIds", propertyPoolIds)); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolRepository.java index 0974a75..7d243b1 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyPoolRepository.java @@ -7,6 +7,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; @@ -41,18 +42,51 @@ public class PropertyPoolRepository extends BasicGenericDao return this.list(PropertyPool.class, sql, getQueryBuilder().getParam(pager.getParams())); } + public List list(Pager pager, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select a.*,c.expression from "+positionKey+".ci_property_pool a left join "+positionKey+".ci_regular_expression c on a.regexp_id=c.id where a.is_deleted=0 "; + } else { + sql = "select a.*,c.expression from ci_property_pool a left join ci_regular_expression c on a.regexp_id=c.id where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + return this.list(PropertyPool.class, sql, getQueryBuilder().getParam(pager.getParams())); + } + public int count(List params) throws Exception { String sql = "select count(1) from ci_property_pool 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 params, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotBlank(positionKey)) { + sql = "select count(1) from "+positionKey+".ci_property_pool a where a.is_deleted=0 "; + } else { + sql = "select count(1) from ci_property_pool a where a.is_deleted=0 "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue(); + } + public PropertyPool query(Long id) throws Exception { String sql = "select a.*,c.expression from ci_property_pool a left join ci_regular_expression c on a.regexp_id=c.id where a.id = :id and a.is_deleted=0 "; List list = this.list(PropertyPool.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public PropertyPool query(Long id, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.*,c.expression from "+positionKey+".ci_property_pool a left join "+positionKey+".ci_regular_expression c on a.regexp_id=c.id where a.id = :id and a.is_deleted=0 "; + } else { + sql = "select a.*,c.expression from ci_property_pool a left join ci_regular_expression c on a.regexp_id=c.id where a.id = :id and a.is_deleted=0 "; + } + List list = this.list(PropertyPool.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public PropertyPool queryByCode(String code) throws Exception { String sql = "select a.* from ci_property_pool a where a.code = :code and a.is_deleted=0 "; List list = this.list(PropertyPool.class, sql, MapTools.simpleMap("code", code)); diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyRepository.java index 5737ae5..e837907 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/PropertyRepository.java @@ -7,6 +7,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; @@ -42,12 +43,35 @@ public class PropertyRepository extends BasicGenericDao { return this.list(Property.class, sql, MapTools.simpleMap("moduleId", moduleId)); } + public List listNotHiddenByCmdbModuleId(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 order by a.order_num"; + } else { + sql = "select a.* from ci_property a where a.is_deleted = 0 and a.module_id = :moduleId order by a.order_num"; + } + // 模型界面显示未隐藏字段 + return this.list(Property.class, sql, MapTools.simpleMap("moduleId", moduleId)); + } + public Property query(Long id) { String sql = "select * from ci_property a where a.id = :id and is_deleted=0 "; List list = this.list(Property.class, sql, MapTools.simpleMap(Common.ID, id)); return list.isEmpty() ? null : list.get(0); } + public Property query(Long id, String positionKey) { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from "+positionKey+".ci_property a where a.id = :id and is_deleted=0 "; + } else { + sql = "select * from ci_property a where a.id = :id and is_deleted=0 "; + + } + List list = this.list(Property.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public Property queryByCode(Long moduleId, String code) throws Exception { String sql = "select * from ci_property a where a.module_id = :moduleId and a.code = :code and a.is_deleted=0 "; Map params = MapTools.simpleMap("moduleId", moduleId); @@ -72,6 +96,19 @@ public class PropertyRepository extends BasicGenericDao { return this.list(Property.class, sql, paramMap); } + public List list(final Pager pager, final Long moduleId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from "+positionKey+".ci_property a where a.module_id = :moduleId and a.is_deleted=0 and a.type not in ('SINGLELINETABLE','MULTILINETABLE') "; + } else { + sql = "select * from ci_property a where a.module_id = :moduleId and a.is_deleted=0 and a.type not in ('SINGLELINETABLE','MULTILINETABLE') "; + } + sql = getQueryBuilder().buildRaw(sql, pager, "a"); + Map paramMap = getQueryBuilder().getParam(pager.getParams()); + paramMap.put("moduleId", moduleId); + return this.list(Property.class, sql, paramMap); + } + public int count(final List params, final Long moduleId) throws Exception { String sql = "select count(1) from ci_property a where a.module_id = :moduleId and a.is_deleted=0 and a.type not in ('SINGLELINETABLE','MULTILINETABLE') "; sql = getQueryBuilder().buildRaw(sql, params, null, "a"); @@ -80,6 +117,19 @@ public class PropertyRepository extends BasicGenericDao { return this.countQuery(sql, param).intValue(); } + public int count(final List params, final Long moduleId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select count(1) from "+positionKey+".ci_property a where a.module_id = :moduleId and a.is_deleted=0 and a.type not in ('SINGLELINETABLE','MULTILINETABLE') "; + } else { + sql = "select count(1) from ci_property a where a.module_id = :moduleId and a.is_deleted=0 and a.type not in ('SINGLELINETABLE','MULTILINETABLE') "; + } + sql = getQueryBuilder().buildRaw(sql, params, null, "a"); + Map param = getQueryBuilder().getParam(params); + param.put("moduleId", moduleId); + return this.countQuery(sql, param).intValue(); + } + public List listIsTitleByModuleId(Long moduleId) { // 模型界面显示未隐藏字段 String 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"; diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RegularExpressionRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RegularExpressionRepository.java index 8093c01..c3b4d69 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RegularExpressionRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RegularExpressionRepository.java @@ -5,6 +5,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; @@ -31,9 +32,30 @@ public class RegularExpressionRepository extends BasicGenericDao list = this.list(RegularExpression.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public List listAll() throws Exception { String sql = "select * from ci_regular_expression where is_deleted = 0"; return this.list(RegularExpression.class, sql, new HashMap(10)); } + public List listAll(String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select * from "+positionKey+".ci_regular_expression where is_deleted = 0"; + } else { + sql = "select * from ci_regular_expression where is_deleted = 0"; + } + return this.list(RegularExpression.class, sql, new HashMap(10)); + } + } diff --git a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RelationCategoryRepository.java b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RelationCategoryRepository.java index 29666ab..cb62179 100644 --- a/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RelationCategoryRepository.java +++ b/bocloud.ams.repository/src/main/java/com/bocloud/ams/repository/module/RelationCategoryRepository.java @@ -7,6 +7,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; @@ -52,6 +53,17 @@ public class RelationCategoryRepository extends BasicGenericDao list = this.list(RelationCategory.class, sql, MapTools.simpleMap(Common.ID, id)); + return list.isEmpty() ? null : list.get(0); + } + public List list(Pager pager) throws Exception { String sql = "select a.* from ci_relation_category a where a.is_deleted=0 "; sql = getQueryBuilder().buildRaw(sql, pager, "a"); @@ -69,6 +81,16 @@ public class RelationCategoryRepository extends BasicGenericDao listByModuleId(Long moduleId, String positionKey) throws Exception { + String sql; + if (StringUtils.isNotEmpty(positionKey)) { + sql = "select a.* from " + positionKey + ".ci_relation_category a where is_deleted = 0 and a.id in (select distinct relation_category_id from " + positionKey + ".ci_module_relation where is_deleted=0 and (source_id = :moduleId OR target_id = :moduleId)) order by a.gmt_modify desc"; + } else { + 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)); + } + public RelationCategory queryByName(String name) throws Exception { String sql = "select a.* from ci_relation_category a where a.name = :name and is_deleted=0 "; diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/AutoRelationRuleService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/AutoRelationRuleService.java index 775a12e..ad33a4f 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/AutoRelationRuleService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/AutoRelationRuleService.java @@ -14,17 +14,17 @@ import java.util.List; * @Description: */ public interface AutoRelationRuleService { - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); GeneralResult save(AutoRelationRule rule, Long target); GeneralResult modify(Long id, AutoRelationRule rule, Long target); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); GeneralResult remove(Long id, Long target); - GeneralResult itemDetail(Long itemId); + GeneralResult itemDetail(Long itemId, String positionKey); GeneralResult> list(Long moduleId, Long relationCategoryId); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/impl/AutoRelationRuleServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/impl/AutoRelationRuleServiceImpl.java index c7cad3f..dc272ed 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/impl/AutoRelationRuleServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/association/impl/AutoRelationRuleServiceImpl.java @@ -1,18 +1,5 @@ package com.bocloud.ams.service.association.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.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.util.Assert; - import com.bocloud.ams.entity.association.AutoRelationRule; import com.bocloud.ams.entity.association.AutoRelationRuleItem; import com.bocloud.ams.entity.association.AutoRelationRuleItemValue; @@ -28,8 +15,19 @@ import com.megatron.common.utils.Common; import com.megatron.common.utils.GridHelper; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; - import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.Assert; + +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; /** * @Author liuyuanyuan @@ -52,24 +50,24 @@ public class AutoRelationRuleServiceImpl implements AutoRelationRuleService { private RedisTemplate redisTemplate; @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> list(Pager pager, String positionKey) { GridBean gridBean; 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 = this.autoRelationRuleRepository.count(pager.getParams()); + int total = this.autoRelationRuleRepository.count(pager.getParams(), positionKey); if (pager.getSimple()) { - List beans = this.autoRelationRuleRepository.list(pager.getParams(), pager.getSorter()); + List beans = this.autoRelationRuleRepository.list(pager.getParams(), pager.getSorter(), positionKey); gridBean = new GridBean<>(1, 1, total, beans); } else { - List list = this.autoRelationRuleRepository.list(pager); + List list = this.autoRelationRuleRepository.list(pager, positionKey); for (AutoRelationRule rule : list) { rule.setCreator(redisTemplate.opsForValue().get("User_Name_" + rule.getCreatorId())); - List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId()); + List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId(), positionKey); for (AutoRelationRuleItem item : items) { List values = - autoRelationRuleItemValueRepository.queryByItemId(item.getId()); + autoRelationRuleItemValueRepository.queryByItemId(item.getId(), positionKey); item.setValues(values); } rule.setItems(items); @@ -162,17 +160,17 @@ public class AutoRelationRuleServiceImpl implements AutoRelationRuleService { } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - AutoRelationRule relationRule = autoRelationRuleRepository.query(id); + AutoRelationRule relationRule = autoRelationRuleRepository.query(id, positionKey); if (null == relationRule) { return new GeneralResult<>(false, "数据不存在"); } // 查询规则明细数据 - List items = autoRelationRuleItemRepository.queryByRuleId(id); + List items = autoRelationRuleItemRepository.queryByRuleId(id, positionKey); for (AutoRelationRuleItem item : items) { List values = - autoRelationRuleItemValueRepository.queryByItemId(item.getId()); + autoRelationRuleItemValueRepository.queryByItemId(item.getId(), positionKey); item.setValues(values); } relationRule.setItems(items); @@ -205,13 +203,13 @@ public class AutoRelationRuleServiceImpl implements AutoRelationRuleService { } @Override - public GeneralResult itemDetail(Long itemId) { + public GeneralResult itemDetail(Long itemId, String positionKey) { try { - AutoRelationRuleItem ruleItem = autoRelationRuleItemRepository.query(itemId); + AutoRelationRuleItem ruleItem = autoRelationRuleItemRepository.query(itemId, positionKey); if (null == ruleItem) { return new GeneralResult<>(false, "规则明细数据不存在"); } - List itemValues = autoRelationRuleItemValueRepository.queryByItemId(itemId); + List itemValues = autoRelationRuleItemValueRepository.queryByItemId(itemId, positionKey); ruleItem.setValues(itemValues); return new GeneralResult<>(true, ruleItem, "查询成功"); } catch (Exception e) { diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/OperationalAuditService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/OperationalAuditService.java index 76b0ff8..9bc573a 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/OperationalAuditService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/OperationalAuditService.java @@ -16,9 +16,9 @@ import java.util.Map; */ public interface OperationalAuditService { - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); - GeneralResult deatil(Long id); + GeneralResult detail(Long id, String positionKey); /** * @@ -36,6 +36,6 @@ public interface OperationalAuditService { Map beforeMap, Map afterMap); - GeneralResult> bakList(Pager pager); + GeneralResult> bakList(Pager pager, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/impl/OperationalAuditServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/impl/OperationalAuditServiceImpl.java index 525313e..e978483 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/impl/OperationalAuditServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/audit/impl/OperationalAuditServiceImpl.java @@ -10,11 +10,14 @@ import com.bocloud.ams.repository.audit.OperationalAuditBakRepository; import com.bocloud.ams.repository.audit.OperationalAuditRepository; import com.bocloud.ams.repository.utils.CmdbUtils; import com.bocloud.ams.service.audit.OperationalAuditService; -import com.megatron.common.model.*; +import com.megatron.common.model.GeneralResult; +import com.megatron.common.model.GridBean; +import com.megatron.common.model.Pager; +import com.megatron.common.model.Param; +import com.megatron.common.model.Sign; import com.megatron.common.utils.Common; import com.megatron.common.utils.DateTools; import com.megatron.common.utils.GridHelper; -import com.megatron.common.utils.ListTool; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -27,7 +30,12 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -49,14 +57,14 @@ public class OperationalAuditServiceImpl implements OperationalAuditService { private TableLogRepository tableLogRepository; @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> 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); List params = pager.getParams(); - int total = operationalAuditRepository.count(params); - List audits = operationalAuditRepository.list(pager); + int total = operationalAuditRepository.count(params, positionKey); + List audits = operationalAuditRepository.list(pager, positionKey); for (OperationalAudit audit : audits) { audit.setOperator(redisTemplate.opsForValue().get("User_Name_" + audit.getCreatorId())); } @@ -69,9 +77,9 @@ public class OperationalAuditServiceImpl implements OperationalAuditService { } @Override - public GeneralResult deatil(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - OperationalAudit audit = operationalAuditRepository.query(id); + OperationalAudit audit = operationalAuditRepository.query(id, positionKey); if (null == audit) { return new GeneralResult<>(false, "记录不存在"); } @@ -142,7 +150,7 @@ public class OperationalAuditServiceImpl implements OperationalAuditService { } @Override - public GeneralResult> bakList(Pager pager) { + public GeneralResult> bakList(Pager pager, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.getSorter().put(Common.ID, Common.ONE); @@ -164,14 +172,14 @@ public class OperationalAuditServiceImpl implements OperationalAuditService { } List list = new ArrayList<>(); //根据模板表查询出所有日志表 然后 使用并行流查询包含参数日期的库表 - List tableLogs = tableLogRepository.query(CmdbUtils.CMDB_OPERATIONAL_AUDIT_BAK); + List tableLogs = tableLogRepository.query(CmdbUtils.CMDB_OPERATIONAL_AUDIT_BAK, positionKey); String finalTimeGet = startTime; String finalTimeLet = endTime; //获取到数据中包含所查询的日期的历史备份表 List tableList = tableLogs.parallelStream().map(item -> item.getName()).filter(item -> { int count = 0; try { - count = operationalAuditBakRepository.queryCount(item, finalTimeGet, finalTimeLet); + count = operationalAuditBakRepository.queryCount(item, finalTimeGet, finalTimeLet, positionKey); } catch (Exception e) { log.error("查询操作审计备份表数量异常",e); } @@ -179,8 +187,8 @@ public class OperationalAuditServiceImpl implements OperationalAuditService { }).collect(Collectors.toList()); int total = 0; if(CollectionUtils.isNotEmpty(tableList)){ - total = operationalAuditBakRepository.count(pager.getParams(), tableList); - list = operationalAuditBakRepository.list(pager, tableList); + total = operationalAuditBakRepository.count(pager.getParams(), tableList, positionKey); + list = operationalAuditBakRepository.list(pager, tableList, positionKey); for (OperationalAuditBak audit : list) { audit.setOperator(redisTemplate.opsForValue().get("User_Name_" + audit.getCreatorId())); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryItemService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryItemService.java index a5ea9d8..dca90ee 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryItemService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryItemService.java @@ -15,7 +15,7 @@ import com.megatron.common.model.Pager; **/ public interface CollectionHistoryItemService { - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); - GeneralResult> backupHistoryItems(Pager pager); + GeneralResult> backupHistoryItems(Pager pager, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryService.java index 622d5dd..d3face9 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionHistoryService.java @@ -18,9 +18,9 @@ import java.util.Map; **/ public interface CollectionHistoryService { - GeneralResult>> instances(Pager pager, Long userId); + GeneralResult>> instances(Pager pager, Long userId, String positionKey); - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); GeneralResult create(CollectionHistory history); @@ -32,8 +32,8 @@ public interface CollectionHistoryService { GeneralResult batchModify(CollectionHistoryModel historyModel, Long userId); - GeneralResult> backupHistory(Pager pager); + GeneralResult> backupHistory(Pager pager, String positionKey); - GeneralResult>> backupList(Pager pager, Long userId); + GeneralResult>> backupList(Pager pager, Long userId, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskInstanceService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskInstanceService.java index 267af39..34ad1e3 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskInstanceService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskInstanceService.java @@ -19,11 +19,11 @@ public interface CollectionTaskInstanceService { GeneralResult queryByTaskId(String taskId); - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); - GeneralResult> bakList(Pager pager); + GeneralResult> bakList(Pager pager, String positionKey); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); - GeneralResult bakDetail(Long id,String name); + GeneralResult bakDetail(Long id,String name, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskService.java index 35407c3..1df3f28 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTaskService.java @@ -21,7 +21,7 @@ public interface CollectionTaskService { GeneralResult isValid(String expression); - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); GeneralResult save(CollectionTask task, RequestContext context); @@ -29,7 +29,7 @@ public interface CollectionTaskService { GeneralResult modifyType(Long id, RequestContext context); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); GeneralResult remove(Long id, Long target); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTemplateService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTemplateService.java index 4620bcf..3d6c4ac 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTemplateService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/CollectionTemplateService.java @@ -13,15 +13,15 @@ import com.megatron.common.model.Pager; */ public interface CollectionTemplateService { - GeneralResult> components(Pager pager); + GeneralResult> components(Pager pager, String positionKey); - GeneralResult> list(Pager pager); + GeneralResult> list(Pager pager, String positionKey); GeneralResult save(CollectionTemplate template, Long target); GeneralResult modify(CollectionTemplate template, Long target); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); GeneralResult remove(Long id, Long target); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryItemServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryItemServiceImpl.java index 8140c1d..0a07a09 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryItemServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryItemServiceImpl.java @@ -26,13 +26,13 @@ public class CollectionHistoryItemServiceImpl implements CollectionHistoryItemSe private CollectionHistoryItemRepository historyItemRepository; @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> 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 = this.historyItemRepository.count(pager.getParams()); - List list = this.historyItemRepository.list(pager); + int total = this.historyItemRepository.count(pager.getParams(), positionKey); + List list = this.historyItemRepository.list(pager, positionKey); GridBean gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list); return new GeneralResult<>(true, gridBean, "查询成功"); } catch (Exception e) { @@ -42,7 +42,7 @@ public class CollectionHistoryItemServiceImpl implements CollectionHistoryItemSe } @Override - public GeneralResult> backupHistoryItems(Pager pager) { + public GeneralResult> backupHistoryItems(Pager pager, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -56,7 +56,7 @@ public class CollectionHistoryItemServiceImpl implements CollectionHistoryItemSe map.remove("tableName"); } } - int total = this.historyItemRepository.count(tableName,pager.getParams()); + int total = this.historyItemRepository.count(tableName,pager.getParams(), positionKey); List list = this.historyItemRepository.list(tableName,pager); GridBean gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list); return new GeneralResult<>(true, gridBean, "查询成功"); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryServiceImpl.java index 308bf41..4f11248 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionHistoryServiceImpl.java @@ -1,20 +1,5 @@ package com.bocloud.ams.service.collection.impl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import org.apache.commons.beanutils.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.collection.CollectionHistory; @@ -51,8 +36,21 @@ import com.megatron.common.utils.GridHelper; import com.megatron.common.utils.JSONTools; 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.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @Slf4j @Service("collectionHistoryService") @@ -82,7 +80,7 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { private PropertyRepository propertyRepository; @Override - public GeneralResult>> instances(Pager pager, Long userId) { + public GeneralResult>> instances(Pager pager, Long userId, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -123,7 +121,7 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { } // 拼接查询条件 if (null != historyType) { - List historyList = historyRepository.queryByIdAndType(taskInstanceId, historyType); + List historyList = historyRepository.queryByIdAndType(taskInstanceId, historyType, positionKey); List historyIds = historyList.stream().map(history -> history.getInstanceId()).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(historyIds)) { @@ -135,9 +133,9 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { pager.getParams().add(inParam); String table = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); - total = instanceRepository.count(pager.getParams(), table, valueTable, userId, true); - list = this.instanceRepository.list(pager, table, valueTable, userId, true); - instanceService.convertInstanceValue(list, moduleId, userId, true); + total = instanceRepository.count(pager.getParams(), table, valueTable, userId, true, positionKey); + list = this.instanceRepository.list(pager, table, valueTable, userId, true, positionKey); + instanceService.convertInstanceValue(list, moduleId, userId, true, positionKey); } } GridBean> bean = new GridBean<>(pager.getPage(), pager.getRows(), total, list); @@ -158,13 +156,13 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { } @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> 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 = this.historyRepository.count(pager.getParams()); - List list = this.historyRepository.list(pager); + int total = this.historyRepository.count(pager.getParams(), positionKey); + List list = this.historyRepository.list(pager, positionKey); GridBean gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list); return new GeneralResult<>(true, gridBean, "查询成功"); } catch (Exception e) { @@ -391,7 +389,7 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { } @Override - public GeneralResult> backupHistory(Pager pager) { + public GeneralResult> backupHistory(Pager pager, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -408,8 +406,8 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { if(StringUtils.isEmpty(tableName)){ return new GeneralResult<>(false, "备份表参数必传"); } - int total = this.historyRepository.count(tableName,pager.getParams()); - List list = this.historyRepository.list(tableName,pager); + int total = this.historyRepository.count(tableName,pager.getParams(), positionKey); + List list = this.historyRepository.list(tableName,pager, positionKey); int i = tableName.lastIndexOf("_"); String substring = tableName.substring(i+1); for (CollectionHistory collectionHistory : list) { @@ -424,7 +422,7 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { } @Override - public GeneralResult>> backupList(Pager pager, Long userId) { + public GeneralResult>> backupList(Pager pager, Long userId, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -477,7 +475,7 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { } // 拼接查询条件 if (null != historyType) { - List historyList = historyRepository.queryByIdAndType(tableName,taskInstanceId, historyType); + List historyList = historyRepository.queryByIdAndType(tableName,taskInstanceId, historyType, positionKey); List historyIds = historyList.stream().map(history -> history.getInstanceId()).collect(Collectors.toList()); if (CollectionUtils.isNotEmpty(historyIds)) { HashMap inMap = Maps.newHashMap(); @@ -488,14 +486,14 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService { pager.getParams().add(inParam); String table = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); - total = instanceRepository.count(pager.getParams(), table, valueTable, userId, true); - list = this.instanceRepository.list(pager, table, valueTable, userId, true); + total = instanceRepository.count(pager.getParams(), table, valueTable, userId, true, positionKey); + list = this.instanceRepository.list(pager, table, valueTable, userId, true, positionKey); int i = tableName.lastIndexOf("_"); String substring = tableName.substring(i+1); for (Map map : list) { map.put("tableName","ci_collection_history_item_bak_"+substring); } - instanceService.convertInstanceValue(list, moduleId, userId, true); + instanceService.convertInstanceValue(list, moduleId, userId, true, positionKey); } } GridBean> bean = new GridBean<>(pager.getPage(), pager.getRows(), total, list); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskInstanceServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskInstanceServiceImpl.java index c8a8236..41fef3e 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskInstanceServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskInstanceServiceImpl.java @@ -117,20 +117,25 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance } @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> list(Pager pager, String positionKey) { GridBean gridBean; 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 = this.collectionTaskInstanceRepository.count(pager.getParams()); + int total = 0; + if (StringUtils.isNotEmpty(positionKey)) { + total = this.collectionTaskInstanceRepository.countByPositionKey(pager.getParams(), positionKey); + } else { + total = this.collectionTaskInstanceRepository.count(pager.getParams()); + } if (pager.getSimple()) { List beans = - this.collectionTaskInstanceRepository.list(pager.getParams(), pager.getSorter()); + this.collectionTaskInstanceRepository.list(pager.getParams(), pager.getSorter(), positionKey); gridBean = new GridBean<>(1, 1, total, beans); } else { List list = this.collectionTaskInstanceRepository.list(pager.getPage(), - pager.getRows(), pager.getParams(), pager.getSorter()); + pager.getRows(), pager.getParams(), pager.getSorter(), positionKey); list.forEach(instance -> instance .setCreator(redisTemplate.opsForValue().get("User_Name_" + instance.getCreatorId()))); gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list); @@ -143,7 +148,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance } @Override - public GeneralResult> bakList(Pager pager) { + public GeneralResult> bakList(Pager pager, String positionKey) { GridBean gridBean; try { long start = System.currentTimeMillis(); @@ -168,7 +173,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance } int total = 0; //根据模板表查询出所有日志表 然后 使用并行流查询包含参数日期的库表 - List tableLogs = tableLogRepository.query("ci_collection_task_instance_bak"); + List tableLogs = tableLogRepository.query("ci_collection_task_instance_bak", positionKey); List tableNames = tableLogs.stream().map(TableLog::getName).collect(Collectors.toList()); String finalTimeGet = startTime; String finalTimeLet = endTime; @@ -177,7 +182,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance List tableList = tableNames.parallelStream().filter(item -> { List query = new ArrayList<>(); try { - query = collectionTaskInstanceRepository.query(item, finalTimeGet, finalTimeLet); + query = collectionTaskInstanceRepository.query(item, finalTimeGet, finalTimeLet, positionKey); } catch (Exception e) { e.printStackTrace(); } @@ -189,7 +194,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance //long start2 = System.currentTimeMillis(); List totals = tableList.parallelStream().map(item -> { try { - return collectionTaskInstanceRepository.count(pager.getParams(), item); + return collectionTaskInstanceRepository.count(pager.getParams(), item, positionKey); } catch (Exception e) { e.printStackTrace(); } @@ -203,7 +208,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance List collectionTaskInstances = tableList.stream().map(item -> CompletableFuture.supplyAsync(() -> { try { - return this.collectionTaskInstanceRepository.listIdBak(pager.getParams(), pager.getSorter(), item); + return this.collectionTaskInstanceRepository.listIdBak(pager.getParams(), pager.getSorter(), item, positionKey); } catch (Exception e) { e.printStackTrace(); } @@ -231,7 +236,7 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance String ids = collectMaps.get(item).stream().map(m -> m.getId().toString()).collect(Collectors.joining(",")); Pager pg = new Pager(null, null, new ArrayList(), null); pg.getParams().add(new Param(MapTools.simpleMap("id", ids), Sign.IN)); - return this.collectionTaskInstanceRepository.list(pg, item); + return this.collectionTaskInstanceRepository.list(pg, item, positionKey); } catch (Exception e) { e.printStackTrace(); } @@ -258,9 +263,15 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - CollectionTaskInstance instance = this.collectionTaskInstanceRepository.query(id); + CollectionTaskInstance instance = null; + if (StringUtils.isEmpty(positionKey)) { + instance = this.collectionTaskInstanceRepository.query(id); + + } else { + instance = this.collectionTaskInstanceRepository.queryByPositionKey(id, positionKey); + } Assert.notNull(instance, "数据不存在!"); List successes = Lists.newArrayList(); List failures = Lists.newArrayList(); @@ -302,9 +313,9 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance } @Override - public GeneralResult bakDetail(Long id, String name) { + public GeneralResult bakDetail(Long id, String name, String positionKey) { try { - CollectionTaskInstance instance = this.collectionTaskInstanceRepository.query(id, name); + CollectionTaskInstance instance = this.collectionTaskInstanceRepository.query(id, name, positionKey); Assert.notNull(instance, "数据不存在!"); List successes = Lists.newArrayList(); List failures = Lists.newArrayList(); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskServiceImpl.java index d78ba66..7c21846 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTaskServiceImpl.java @@ -1,32 +1,5 @@ package com.bocloud.ams.service.collection.impl; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import java.util.stream.Collectors; - -import org.apache.commons.lang3.StringUtils; -import org.apache.curator.framework.recipes.leader.LeaderLatchListener; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.scheduling.Trigger; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.scheduling.support.CronExpression; -import org.springframework.scheduling.support.CronTrigger; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.collection.CollectionComponent; @@ -69,8 +42,33 @@ import com.megatron.framework.core.CurrentService; import com.megatron.framework.http.core.HttpMethod; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; - import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.apache.curator.framework.recipes.leader.LeaderLatchListener; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.scheduling.Trigger; +import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; +import org.springframework.scheduling.support.CronExpression; +import org.springframework.scheduling.support.CronTrigger; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; +import java.util.stream.Collectors; /** * @Author liuyuanyuan @@ -112,19 +110,18 @@ public class CollectionTaskServiceImpl implements CollectionTaskService { private PropertyRepository propertyRepository; @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> list(Pager pager, String positionKey) { GridBean gridBean; 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 = this.collectionTaskRepository.count(pager.getParams()); + int total = this.collectionTaskRepository.count(pager.getParams(), positionKey); if (pager.getSimple()) { - List beans = this.collectionTaskRepository.list(pager.getParams(), pager.getSorter()); + List beans = this.collectionTaskRepository.list(pager.getParams(), pager.getSorter(), positionKey); gridBean = new GridBean<>(1, 1, total, beans); } else { - List list = this.collectionTaskRepository.list(pager.getPage(), pager.getRows(), - pager.getParams(), pager.getSorter()); + List list = this.collectionTaskRepository.list(pager.getPage(), pager.getRows(), pager.getParams(), pager.getSorter(), positionKey); list.forEach( task -> task.setCreator(redisTemplate.opsForValue().get("User_Name_" + task.getCreatorId()))); gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list); @@ -602,9 +599,9 @@ public class CollectionTaskServiceImpl implements CollectionTaskService { } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - CollectionTask task = this.collectionTaskRepository.query(id); + CollectionTask task = this.collectionTaskRepository.query(id, positionKey); Assert.notNull(task, "数据不存在!"); task.setCreator(redisTemplate.opsForValue().get("User_Name_" + task.getCreatorId())); if (null != task.getMenderId()) { diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTemplateServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTemplateServiceImpl.java index 961e770..551e370 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTemplateServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/collection/impl/CollectionTemplateServiceImpl.java @@ -1,18 +1,5 @@ package com.bocloud.ams.service.collection.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 java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.collection.CollectionComponent; import com.bocloud.ams.entity.collection.CollectionTask; @@ -31,8 +18,19 @@ import com.megatron.common.utils.Common; import com.megatron.common.utils.GridHelper; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; - import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +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 java.util.stream.Collectors; /** * @Author liuyuanyuan @@ -54,15 +52,15 @@ public class CollectionTemplateServiceImpl implements CollectionTemplateService private CollectionTaskRepository collectionTaskRepository; @Override - public GeneralResult> components(Pager pager) { + public GeneralResult> components(Pager pager, String positionKey) { GridBean gridBean; 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 = this.collectionComponentRepository.count(pager.getParams()); + int total = this.collectionComponentRepository.count(pager.getParams(), positionKey); if (pager.getSimple()) { - List beans = this.collectionComponentRepository.list(pager.getParams(), pager.getSorter()); + List beans = this.collectionComponentRepository.list(pager.getParams(), pager.getSorter(), positionKey); gridBean = new GridBean<>(1, 1, total, beans); } else { List list = this.collectionComponentRepository.list(pager.getPage(), @@ -79,24 +77,23 @@ public class CollectionTemplateServiceImpl implements CollectionTemplateService } @Override - public GeneralResult> list(Pager pager) { + public GeneralResult> list(Pager pager, String positionKey) { GridBean gridBean; 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 = this.collectionTemplateRepository.count(pager.getParams()); + int total = this.collectionTemplateRepository.count(pager.getParams(), positionKey); if (pager.getSimple()) { - List beans = this.collectionTemplateRepository.list(pager.getParams(), pager.getSorter()); + List beans = this.collectionTemplateRepository.list(pager.getParams(), pager.getSorter(), positionKey); gridBean = new GridBean<>(1, 1, total, beans); } else { - List list = this.collectionTemplateRepository.list(pager.getPage(), pager.getRows(), - pager.getParams(), pager.getSorter()); + List list = this.collectionTemplateRepository.list(pager.getPage(), pager.getRows(), pager.getParams(), pager.getSorter(), positionKey); list.forEach(template -> { template.setCreator(redisTemplate.opsForValue().get("User_Name_" + template.getCreatorId())); List components = null; try { - components = collectionComponentRepository.queryByTemplateId(template.getId()); + components = collectionComponentRepository.queryByTemplateId(template.getId(), positionKey); } catch (Exception e) { log.error("Query Collection Components list fail:", e); } @@ -219,9 +216,9 @@ public class CollectionTemplateServiceImpl implements CollectionTemplateService } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - CollectionTemplate template = collectionTemplateRepository.query(id); + CollectionTemplate template = collectionTemplateRepository.query(id, positionKey); template.setCreator(redisTemplate.opsForValue().get("User_Name_" + template.getCreatorId())); Assert.notNull(template, "数据不存在!"); List components = collectionComponentRepository.queryByTemplateId(id); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/CmdbConfigService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/CmdbConfigService.java index 48115f3..1fd910b 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/CmdbConfigService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/CmdbConfigService.java @@ -29,8 +29,8 @@ public interface CmdbConfigService { */ Result batchUpdate(List list, RequestContext context); - GeneralResult> listConfigs(String category, List codes); + GeneralResult> listConfigs(String category, List codes, String positionKey); - GeneralResult listCategoryTree(String category); + GeneralResult listCategoryTree(String category, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/impl/CmdbConfigServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/impl/CmdbConfigServiceImpl.java index 4bae6d6..c967daf 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/impl/CmdbConfigServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/config/impl/CmdbConfigServiceImpl.java @@ -105,13 +105,13 @@ public class CmdbConfigServiceImpl implements CmdbConfigService { } @Override - public GeneralResult> listConfigs(String category, List codes) { + public GeneralResult> listConfigs(String category, List codes, String positionKey) { try { List configs; if (StringUtils.hasText(category)) { - configs = cmdbConfigRepository.listByCategory(category); + configs = cmdbConfigRepository.listByCategory(category, positionKey); } else { - configs = cmdbConfigRepository.listByCodes(new HashSet<>(codes)); + configs = cmdbConfigRepository.listByCodes(new HashSet<>(codes), positionKey); } Map configMap = configs.stream().collect(Collectors.toMap(CmdbConfig::getCode, Function.identity())); @@ -128,9 +128,9 @@ public class CmdbConfigServiceImpl implements CmdbConfigService { } @Override - public GeneralResult listCategoryTree(String category) { + public GeneralResult listCategoryTree(String category, String positionKey) { try { - List configs = cmdbConfigRepository.listByCategory(category); + List configs = cmdbConfigRepository.listByCategory(category, positionKey); Map> configMap = configs.stream().collect(Collectors.groupingBy(CmdbConfig::getSubclass)); JSONArray jsonArray = new JSONArray(); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceAuthorityService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceAuthorityService.java index e0b0377..7aee1a7 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceAuthorityService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceAuthorityService.java @@ -4,8 +4,6 @@ import com.bocloud.ams.entity.instance.InstanceAuthority; import com.megatron.common.model.GeneralResult; import com.megatron.common.model.Pager; -import java.util.List; - /** * @ClassName: CmdbInstanceAuthorityService * @Description @@ -16,7 +14,7 @@ import java.util.List; public interface InstanceAuthorityService { - GeneralResult list(Pager pager); + GeneralResult list(Pager pager, String positionKey); GeneralResult create(InstanceAuthority authority, Long userId); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceHistoryService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceHistoryService.java index 9b796f9..a38d7d9 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceHistoryService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceHistoryService.java @@ -14,7 +14,7 @@ import com.megatron.common.model.Pager; public interface InstanceHistoryService { - GeneralResult list(Pager pager); + GeneralResult list(Pager pager, String positionKey); GeneralResult create(InstanceHistory history, Long userId); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceRelationHistoryRecordService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceRelationHistoryRecordService.java index 33dd6dd..4fd3fc7 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceRelationHistoryRecordService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceRelationHistoryRecordService.java @@ -28,7 +28,7 @@ public interface InstanceRelationHistoryRecordService { * @param pager * @return */ - public GeneralResult list(Pager pager); + public GeneralResult list(Pager pager, String positionKey); public GeneralResult cancel(Long id, RequestContext context); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceService.java index 7cf0c0f..bc668a6 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/InstanceService.java @@ -9,7 +9,6 @@ import com.megatron.common.model.Pager; import com.megatron.common.model.RequestContext; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; import java.util.List; import java.util.Map; @@ -26,7 +25,7 @@ public interface InstanceService { GeneralResult dropTable(String moduleCode, Long userId); - GeneralResult list(Pager pager, Long userId); + GeneralResult list(Pager pager, Long userId, String positionKey); GeneralResult create(JSONObject instance, Long userId, boolean isAutoRelation); @@ -38,9 +37,9 @@ public interface InstanceService { GeneralResult batchModify(InstanceBean instanceModel, Long userId); - GeneralResult detail(Long id, String moduleCode); + GeneralResult detail(Long id, String moduleCode, String positionKey); - GeneralResult export(Long moduleId, String moduleCode, String type, Long userId); + GeneralResult export(Long moduleId, String moduleCode, String type, Long userId, String positionKey); GeneralResult download(Long moduleId, String moduleCode, String type, Long userId); @@ -48,10 +47,10 @@ public interface InstanceService { GeneralResult initInstance(JSONObject object, String type); - GeneralResult topo(Long id, Long relationCategoryId, Long moduleId, Long userId); + GeneralResult topo(Long id, Long relationCategoryId, Long moduleId, Long userId, String positionKey); boolean checkAdminRole(Long userId); - void convertInstanceValue(List> list, Long moduleId, Long userId, boolean hasAdminRole) throws Exception; + void convertInstanceValue(List> list, Long moduleId, Long userId, boolean hasAdminRole, String positionKey) throws Exception; } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceAuthorityServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceAuthorityServiceImpl.java index 23e2ccf..fc315a5 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceAuthorityServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceAuthorityServiceImpl.java @@ -46,13 +46,13 @@ public class InstanceAuthorityServiceImpl implements InstanceAuthorityService { private RedisTemplate redisTemplate; @Override - public GeneralResult list(Pager pager) { + public GeneralResult 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 = this.instanceAuthorityRepository.count(pager.getParams()); - List list = this.instanceAuthorityRepository.list(pager); + int total = this.instanceAuthorityRepository.count(pager.getParams(), positionKey); + List list = this.instanceAuthorityRepository.list(pager, positionKey); for (InstanceAuthority authority : list) { String roleName = redisTemplate.opsForValue().get("Role_Name_" + authority.getRoleId()); if (StringUtils.isEmpty(authority.getAuths())) { diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceHistoryServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceHistoryServiceImpl.java index 7135fd6..2f55c13 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceHistoryServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceHistoryServiceImpl.java @@ -1,24 +1,22 @@ package com.bocloud.ams.service.instance.impl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Optional; - -import com.megatron.common.model.GridBean; -import com.megatron.common.model.Pager; -import com.megatron.common.utils.Common; -import com.megatron.common.utils.GridHelper; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.bocloud.ams.entity.enums.InstanceEnum; import com.bocloud.ams.entity.instance.InstanceHistory; import com.bocloud.ams.repository.instance.InstanceHistoryRepository; import com.bocloud.ams.service.instance.InstanceHistoryService; import com.megatron.common.model.GeneralResult; - +import com.megatron.common.model.GridBean; +import com.megatron.common.model.Pager; +import com.megatron.common.utils.Common; +import com.megatron.common.utils.GridHelper; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; @Slf4j @Service("instanceHistoryService") @@ -28,13 +26,13 @@ public class InstanceHistoryServiceImpl implements InstanceHistoryService { private InstanceHistoryRepository instanceHistoryRepository; @Override - public GeneralResult list(Pager pager) { + public GeneralResult 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 = this.instanceHistoryRepository.count(pager.getParams()); - List list = this.instanceHistoryRepository.list(pager); + int total = this.instanceHistoryRepository.count(pager.getParams(), positionKey); + List list = this.instanceHistoryRepository.list(pager, positionKey); for (InstanceHistory history : list) { if (InstanceEnum.catalog.INSTANCE.name().equals(history.getCatalog())) { history.setCatalog(InstanceEnum.catalog.INSTANCE.getValue()); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceRelationHistoryRecordServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceRelationHistoryRecordServiceImpl.java index cf0b0af..d956e6b 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceRelationHistoryRecordServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceRelationHistoryRecordServiceImpl.java @@ -81,14 +81,14 @@ public class InstanceRelationHistoryRecordServiceImpl implements InstanceRelatio } @Override - public GeneralResult list(Pager pager) { + public GeneralResult 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); pager.getSorter().put("id", Common.ONE); - int total = instanceRelationHistoryRecordRepository.count(pager.getParams()); - List list = this.instanceRelationHistoryRecordRepository.list(pager); + int total = instanceRelationHistoryRecordRepository.count(pager.getParams(), positionKey); + List list = this.instanceRelationHistoryRecordRepository.list(pager, positionKey); if (CollectionUtils.isNotEmpty(list)) { list.forEach(template -> { template diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java index 502aaf8..2f1d9dc 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/instance/impl/InstanceServiceImpl.java @@ -159,7 +159,7 @@ public class InstanceServiceImpl implements InstanceService { } @Override - public GeneralResult list(Pager pager, Long userId) { + public GeneralResult list(Pager pager, Long userId, String positionKey) { try { List> list = new ArrayList<>(); if (CollectionUtils.isEmpty(pager.getParams())) { @@ -207,9 +207,9 @@ public class InstanceServiceImpl implements InstanceService { String table = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); boolean hasAdminRole = checkAdminRole(userId); - int total = instanceRepository.count(pager.getParams(), table, valueTable, userId, hasAdminRole); - list = this.instanceRepository.list(pager, table, valueTable, userId, hasAdminRole); - convertInstanceValue(list, moduleId, userId, hasAdminRole); + int total = instanceRepository.count(pager.getParams(), table, valueTable, userId, hasAdminRole, positionKey); + list = this.instanceRepository.list(pager, table, valueTable, userId, hasAdminRole, positionKey); + convertInstanceValue(list, moduleId, userId, hasAdminRole, null); GridBean> bean = new GridBean<>(pager.getPage(), pager.getRows(), total, list); return new GeneralResult<>(true, bean, "查询成功"); } catch (Exception e) { @@ -1004,12 +1004,12 @@ public class InstanceServiceImpl implements InstanceService { } @Override - public GeneralResult detail(Long id, String moduleCode) { + public GeneralResult detail(Long id, String moduleCode, String positionKey) { try { String table = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); - Instance instance = instanceRepository.query(table, id); - List values = instanceValueRepository.listByInstanceId(id, valueTable); + Instance instance = instanceRepository.query(table, id, positionKey); + List values = instanceValueRepository.listByInstanceId(id, valueTable, positionKey); // instance.setInstanceObject(CmdbUtils.instanceValueRowToCol(instanceValues)); // convertInstanceValue(instance.getInstanceObject(), instance.getModuleId()); instance.setInstanceValues(values); @@ -1021,11 +1021,11 @@ public class InstanceServiceImpl implements InstanceService { } @Override - public GeneralResult export(Long moduleId, String moduleCode, String type, Long userId) { + public GeneralResult export(Long moduleId, String moduleCode, String type, Long userId, String positionKey) { Workbook workbook = null; try { boolean hasAdminRole = checkAdminRole(userId); - CiModule module = moduleRepository.query(moduleId); + CiModule module = moduleRepository.query(moduleId, positionKey); if (null == module) { return new GeneralResult<>(false, "模型数据不存在"); } @@ -1035,7 +1035,7 @@ public class InstanceServiceImpl implements InstanceService { String table = CmdbUtils.CMDB_INSTANCE + module.getCode().toLowerCase(); String valueTable = CmdbUtils.CMDB_INSTANCE_VALUE + module.getCode().toLowerCase(); List> instances = - instanceRepository.listAll(table, valueTable, module.getId(), null, userId, hasAdminRole); + instanceRepository.listAll(table, valueTable, module.getId(), null, userId, hasAdminRole, positionKey); List properties = queryModulePropertys(module.getId()); String fileName = module.getName() + "-实例.xls"; if ("2007".equals(type)) { @@ -1742,12 +1742,12 @@ public class InstanceServiceImpl implements InstanceService { * @throws Exception */ @Override - public void convertInstanceValue(List> list, Long moduleId, Long userId, boolean hasAdminRole) + public void convertInstanceValue(List> list, Long moduleId, Long userId, boolean hasAdminRole, String positionKey) throws Exception { if (ListTool.isEmpty(list)) { return; } - List properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId); + List properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId, positionKey); Map propertyMap = new HashMap<>(); for (Property property : properties) { propertyMap.put(property.getCode(), property); @@ -1819,7 +1819,7 @@ public class InstanceServiceImpl implements InstanceService { authManage = true; } else { List authorities = instanceAuthorityRepository.listByUserId(moduleId, - Long.valueOf(instanceValue.get(Common.ID).toString()), userId); + Long.valueOf(instanceValue.get(Common.ID).toString()), userId, positionKey); for (InstanceAuthority authority : authorities) { if (StringUtils.isNotEmpty(authority.getAuths()) && authority.getAuths().contains(InstanceEnum.authority.EDIT.getValue())) { @@ -2018,7 +2018,7 @@ public class InstanceServiceImpl implements InstanceService { List properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId); List items = propertyItemRepository.queryByModuleId(moduleId); for (Property property : properties) { - propertyService.propertyHandle(property, items); + propertyService.propertyHandle(property, items, null); } PropertyModel model = new PropertyModel(moduleId, groups, properties); return new GeneralResult<>(true, model, "查询属性成功"); @@ -2029,14 +2029,14 @@ public class InstanceServiceImpl implements InstanceService { } @Override - public GeneralResult topo(Long id, Long relationCategoryId, Long moduleId, Long userId) { + public GeneralResult topo(Long id, Long relationCategoryId, Long moduleId, Long userId, String positionKey) { try { - RelationCategory relationCategory = relationCategoryRepository.query(relationCategoryId); + RelationCategory relationCategory = relationCategoryRepository.query(relationCategoryId, positionKey); if (null == relationCategory) { return new GeneralResult<>(false, "关系分类不存在"); } String relationCategoryCode = relationCategory.getCode(); - CiModule module = moduleRepository.query(moduleId); + CiModule module = moduleRepository.query(moduleId, positionKey); if (null == module) { return new GeneralResult<>(false, "模型不存在"); } @@ -2045,13 +2045,13 @@ public class InstanceServiceImpl implements InstanceService { String instanceTable = CmdbUtils.CMDB_INSTANCE + moduleCode.toLowerCase(); String instanceValueTable = CmdbUtils.CMDB_INSTANCE_VALUE + moduleCode.toLowerCase(); String instanceRelationTable = CmdbUtils.CMDB_INSTANCE_RELATION + relationCategoryCode.toLowerCase(); - Instance instance = instanceRepository.query(instanceTable, id); - InstanceValue instanceValue = instanceValueRepository.query(instanceValueTable, Common.NAME, id); + Instance instance = instanceRepository.query(instanceTable, id, positionKey); + InstanceValue instanceValue = instanceValueRepository.query(instanceValueTable, Common.NAME, id, positionKey); if (null == instance || null == instanceValue) { return new GeneralResult<>(false, "实例不存在"); } List moduleRelations = - moduleRelationRepository.queryAll(relationCategory.getId(), moduleId); + moduleRelationRepository.queryAll(relationCategory.getId(), moduleId, positionKey); if (CollectionUtils.isEmpty(moduleRelations)) { InstanceTopo topo = new InstanceTopo(); // 查询当前实例 @@ -2076,9 +2076,9 @@ public class InstanceServiceImpl implements InstanceService { } List instanceRelations = new ArrayList<>(); List sourceInstanceRelations = - instanceRelationRepository.querySources(instanceRelationTable, moduleId, id); + instanceRelationRepository.querySources(instanceRelationTable, moduleId, id, positionKey); List targetInstanceRelations = - instanceRelationRepository.queryTargets(instanceRelationTable, moduleId, id); + instanceRelationRepository.queryTargets(instanceRelationTable, moduleId, id, positionKey); instanceRelations.addAll(sourceInstanceRelations); instanceRelations.addAll(targetInstanceRelations); // 所有实例 moduleCode+"-"+moduleId+"-"+instanceId @@ -2130,7 +2130,7 @@ public class InstanceServiceImpl implements InstanceService { Long insId = Long.valueOf(insSplit[2]); module = moduleRepository.query(insModuleId); instanceValueTable = CmdbUtils.CMDB_INSTANCE_VALUE + insModuleCode.toLowerCase(); - instanceValue = instanceValueRepository.query(instanceValueTable, Common.NAME, insId); + instanceValue = instanceValueRepository.query(instanceValueTable, Common.NAME, insId, positionKey); if (null == module || null == instanceValue) { continue; } @@ -2205,7 +2205,7 @@ public class InstanceServiceImpl implements InstanceService { JSONObject instanceValueObj = new JSONObject(); for (int j = startIndex; j < lastColumn; j++) { Cell cell = row.getCell(j); - Property property = headerProperty.get(new Integer(j)); + Property property = headerProperty.get(j); if (null != property) { String propertyType = property.getType(); String propertyCode = property.getCode(); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleGroupService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleGroupService.java index e72db69..f37aa06 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleGroupService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleGroupService.java @@ -13,23 +13,23 @@ import java.util.List; */ public interface ModuleGroupService { - GeneralResult> collections(String category, String moduleName); + GeneralResult> collections(String category, String moduleName, String positionKey); - GeneralResult> queryRoot(); + GeneralResult> queryRoot(String positionKey); - GeneralResult> queryRootChildren(); + GeneralResult> queryRootChildren(String positionKey); GeneralResult save(ModuleGroup group, Long target); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); GeneralResult modify(ModuleGroup group, Long target); - GeneralResult queryChildren(Long groupId, String menu, RequestContext context); + GeneralResult queryChildren(Long groupId, String menu, RequestContext context, String positionKey); GeneralResult remove(Long id, Long userId); - GeneralResult> querylist(); + GeneralResult> querylist(String positionKey); - GeneralResult> queryRootChildren(Long groupId, String menu, RequestContext context); + GeneralResult> queryRootChildren(Long groupId, String menu, RequestContext context, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleRelationService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleRelationService.java index 21a3046..c275ff2 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleRelationService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleRelationService.java @@ -25,7 +25,7 @@ public interface ModuleRelationService { */ public GeneralResult modify(ModuleRelation relation, Long userId); - public GeneralResult detail(Long id); + public GeneralResult detail(Long id, String positionKey); /** * 删除 @@ -41,14 +41,14 @@ public interface ModuleRelationService { * @param moduleId 模型id * @param relationCategoryId 关联类型分组id */ - GeneralResult list(Long moduleId, Long relationCategoryId); + GeneralResult list(Long moduleId, Long relationCategoryId, String positionKey); /** * 查询所有 * * @param relationCategoryId 关联类型分组id */ - GeneralResult listByCategoryId(Long relationCategoryId); + GeneralResult listByCategoryId(Long relationCategoryId, String positionKey); /** * @param relationCategoryId @@ -56,7 +56,7 @@ public interface ModuleRelationService { * @param targetId * @Description: 根据拓扑,模型数据查询模型关系 */ - GeneralResult relevancy(Long relationCategoryId, Long sourceId, Long targetId); + GeneralResult relevancy(Long relationCategoryId, Long sourceId, Long targetId, String positionKey); /** * 关联类型分组id查询模型集合 @@ -64,7 +64,7 @@ public interface ModuleRelationService { * @param relationCategoryId * @return */ - GeneralResult> moduleList(Long relationCategoryId); + GeneralResult> moduleList(Long relationCategoryId, String positionKey); /*** * 根据模型关系及指定模型获取模型实例 @@ -72,5 +72,5 @@ public interface ModuleRelationService { * @param userId * @return */ - GeneralResult instances(Pager pager, Long userId); + GeneralResult instances(Pager pager, Long userId, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleService.java index abdc232..54d5a22 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/ModuleService.java @@ -18,11 +18,11 @@ import java.util.List; */ public interface ModuleService { - GeneralResult> getModelList(Pager pager); + GeneralResult> getModelList(Pager pager, String positionKey); - GeneralResult> list(); + GeneralResult> list( String positionKey); - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); GeneralResult save(CiModule module, Long target); @@ -30,11 +30,11 @@ public interface ModuleService { GeneralResult modify(CiModule module, Long target); - GeneralResult property(Long id); + GeneralResult property(Long id, String positionKey); - GeneralResult> propertyList(Long moduleId, Pager pager); + GeneralResult> propertyList(Long moduleId, Pager pager, String positionKey); GeneralResult modifyProperty(PropertyModel model, Long id, RequestContext context); - GeneralResult statistics(RequestContext context); + GeneralResult statistics(RequestContext context, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyPoolService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyPoolService.java index 8da3172..58f1296 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyPoolService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyPoolService.java @@ -43,5 +43,5 @@ public interface PropertyPoolService { * @param pager * @return */ - public GeneralResult list(Pager pager); + public GeneralResult list(Pager pager, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyService.java index 5095d14..76394f3 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/PropertyService.java @@ -1,10 +1,11 @@ package com.bocloud.ams.service.module; -import java.util.List; import com.bocloud.ams.entity.module.Property; import com.bocloud.ams.entity.module.PropertyItem; import com.megatron.common.model.GeneralResult; +import java.util.List; + /** * @Author 胡立伟 * @Date 2022/5/9 0009 18:28 @@ -12,7 +13,7 @@ import com.megatron.common.model.GeneralResult; */ public interface PropertyService { - GeneralResult detail(Long id); + GeneralResult detail(Long id, String positionKey); - void propertyHandle(final Property property, final List items) throws Exception; + void propertyHandle(final Property property, final List items, String positionKey) throws Exception; } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RegularExpressionService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RegularExpressionService.java index 950b950..04ac7bd 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RegularExpressionService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RegularExpressionService.java @@ -19,5 +19,5 @@ public interface RegularExpressionService { * * @return */ - GeneralResult> list(String type); + GeneralResult> list(String type, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RelationCategoryService.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RelationCategoryService.java index ccc5f20..92a0e52 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RelationCategoryService.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/RelationCategoryService.java @@ -59,6 +59,6 @@ public interface RelationCategoryService { */ GeneralResult> moduleRelationList(Long id, Long moduleId); - GeneralResult listByModuleId(Long moduleId); + GeneralResult listByModuleId(Long moduleId, String positionKey); } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleGroupServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleGroupServiceImpl.java index c894d2d..6dbf652 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleGroupServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleGroupServiceImpl.java @@ -58,10 +58,10 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { private ThreadPoolTaskExecutor threadPoolTaskExecutor; @Override - public GeneralResult> collections(String category, String moduleName) { + public GeneralResult> collections(String category, String moduleName, String positionKey) { try { // 获取模型分组所有数据 - List groups = moduleGroupRepository.all(); + List groups = moduleGroupRepository.all(positionKey); if (CollectionUtils.isEmpty(groups)) { return new GeneralResult<>(true, groups, "查询成功"); } @@ -72,13 +72,13 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { groups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId)); if ("template".equalsIgnoreCase(category)) { // 查询模型下存在采集模板的模型 - List template = moduleRepository.existCollectionTemplate(moduleName); + List template = moduleRepository.existCollectionTemplate(moduleName, positionKey); Map> moduleMap = template.stream().collect(Collectors.groupingBy(CiModule::getGroupId)); this.getTree(parents, groupMap, moduleMap); } else if ("task".equalsIgnoreCase(category)) { // 查询模型下存在采集任务的模型 - List task = moduleRepository.existCollectionTask(moduleName); + List task = moduleRepository.existCollectionTask(moduleName, positionKey); Map> moduleMap = task.stream().collect(Collectors.groupingBy(CiModule::getGroupId)); this.getTree(parents, groupMap, moduleMap); } @@ -125,20 +125,20 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { } @Override - public GeneralResult> queryRoot() { + public GeneralResult> queryRoot(String positionKey) { try { - List rootGroups = moduleGroupRepository.queryRoot(); + List rootGroups = moduleGroupRepository.queryRoot(positionKey); if (CollectionUtils.isEmpty(rootGroups)) { return new GeneralResult<>(true, rootGroups, "查询成功"); } List rootGroupIds = rootGroups.stream().map(ModuleGroup::getId).collect(Collectors.toList()); // 获取模型分组所有数据 - List moduleGroups = moduleGroupRepository.all(); + List moduleGroups = moduleGroupRepository.all(positionKey); // 获取根节点的子节点集合 List children = moduleGroups.stream().filter(item -> rootGroupIds.contains(item.getParentId())) .collect(Collectors.toList()); // 获取模型所有数据 - List modules = moduleRepository.all(); + List modules = moduleRepository.all(positionKey); // 对模型根据groupId进行分组 Map> moduleMap = modules.stream().filter(item -> null != item.getGroupId()) .collect(Collectors.groupingBy(CiModule::getGroupId)); @@ -161,10 +161,10 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { } @Override - public GeneralResult> queryRootChildren() { + public GeneralResult> queryRootChildren(String positionKey) { try { // 获取模型分组所有数据 - List groups = moduleGroupRepository.all(); + List groups = moduleGroupRepository.all(positionKey); List parent = groups.stream().filter(item -> item.getParentId().equals(0L)).collect(Collectors.toList()); // 对模型分组根据parentId进行分组 @@ -210,9 +210,9 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - ModuleGroup group = moduleGroupRepository.query(id); + ModuleGroup group = moduleGroupRepository.query(id, positionKey); return new GeneralResult<>(true, group, "查询成功"); } catch (Exception e) { log.error("moduleGroupService detail fail:", e); @@ -264,10 +264,10 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { } @Override - public GeneralResult queryChildren(Long groupId, String menu, RequestContext context) { + public GeneralResult queryChildren(Long groupId, String menu, RequestContext context, String positionKey) { try { // 获取模型分组所有数据 - List groups = moduleGroupRepository.all(); + List groups = moduleGroupRepository.all(positionKey); ModuleGroup group = groups.stream().filter(item -> item.getId().equals(groupId)).findFirst().orElse(null); if (null == group) { return new GeneralResult<>(false, "不存在此分组!"); @@ -276,7 +276,7 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { Map> groupMap = groups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId)); // 获取模型所有数据 - List modules = moduleRepository.all(); + List modules = moduleRepository.all(positionKey); if ("resource".equalsIgnoreCase(menu)) { modules = modules.stream().filter(item -> ModuleConstant.STATUS_ENABLE.equals(item.getStatus())) .collect(Collectors.toList()); @@ -414,19 +414,19 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { * @return 返回各分组中模型数量 */ @Override - public GeneralResult> querylist() { + public GeneralResult> querylist(String positionKey) { try { // 获取根数据 - List rootGroups = moduleGroupRepository.queryRoot(); + List rootGroups = moduleGroupRepository.queryRoot(positionKey); if (CollectionUtils.isEmpty(rootGroups)) { return new GeneralResult<>(true, rootGroups, "查询成功"); } // 获取模型分组所有数据 - List moduleGroups = moduleGroupRepository.all(); + List moduleGroups = moduleGroupRepository.all(positionKey); // 对模型分组根据parentId进行分组 Map> groupMap = moduleGroups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId)); - List modules = moduleRepository.all(); + List modules = moduleRepository.all(positionKey); Map> moduleMap = modules.stream().collect(Collectors.groupingBy(CiModule::getGroupId)); for (ModuleGroup group : rootGroups) { this.getGroupTree(group, groupMap, moduleMap); @@ -486,16 +486,16 @@ public class ModuleGroupServiceImpl implements ModuleGroupService { @Override - public GeneralResult> queryRootChildren(Long groupId , String menu, RequestContext context) { + public GeneralResult> queryRootChildren(Long groupId , String menu, RequestContext context, String positionKey) { try { - List rootGroups = moduleGroupRepository.queryRoot(); + List rootGroups = moduleGroupRepository.queryRoot(positionKey); if (CollectionUtils.isEmpty(rootGroups)) { return new GeneralResult<>(true, rootGroups, "查询成功"); } // 获取模型分组所有数据 - List groups = moduleGroupRepository.all(); + List groups = moduleGroupRepository.all(positionKey); // 获取模型所有数据 - List modules = moduleRepository.all(); + List modules = moduleRepository.all(positionKey); // 对模型根据groupId进行分组 Map> moduleMap = modules.stream().filter(item -> null != item.getGroupId()) .collect(Collectors.groupingBy(CiModule::getGroupId)); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleRelationServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleRelationServiceImpl.java index e508869..852d37d 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleRelationServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleRelationServiceImpl.java @@ -1,26 +1,5 @@ package com.bocloud.ams.service.module.impl; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import org.apache.commons.beanutils.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.bocloud.ams.entity.association.AutoRelationRule; import com.bocloud.ams.entity.association.AutoRelationRuleItem; import com.bocloud.ams.entity.association.AutoRelationRuleItemValue; @@ -50,8 +29,18 @@ import com.megatron.common.model.Param; 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.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @Description: 模型关系管理 @@ -268,18 +257,18 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - ModuleRelation relation = moduleRelationRepository.query(id); + ModuleRelation relation = moduleRelationRepository.query(id, positionKey); if (null == relation) { return new GeneralResult<>(false, "模型关系查询失败,数据不存在"); } // 查询关联规则信息 - AutoRelationRule rule = autoRelationRuleRepository.queryByModuleRelationId(id); + AutoRelationRule rule = autoRelationRuleRepository.queryByModuleRelationId(id, positionKey); if (null != rule) { - List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId()); + List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId(), positionKey); for (AutoRelationRuleItem item : items) { - item.setValues(autoRelationRuleItemValueRepository.queryByItemId(item.getId())); + item.setValues(autoRelationRuleItemValueRepository.queryByItemId(item.getId(), positionKey)); } relation.setRuleItemList(items); } @@ -324,23 +313,23 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { } @Override - public GeneralResult list(Long moduleId, Long relationCategoryId) { + public GeneralResult list(Long moduleId, Long relationCategoryId, String positionKey) { try { if (null == moduleId || null == relationCategoryId) { return GeneralResult.FAILED("模型id或拓扑id不可为空"); } - CiModule module = moduleRepository.query(moduleId); + CiModule module = moduleRepository.query(moduleId, positionKey); if (null == module) { return GeneralResult.FAILED("该模型不存在"); } - RelationCategory category = relationCategoryRepository.query(relationCategoryId); + RelationCategory category = relationCategoryRepository.query(relationCategoryId, positionKey); if (null == category) { return GeneralResult.FAILED("该拓扑不存在"); } // 正向关系 - List relations = moduleRelationRepository.list(moduleId, relationCategoryId); + List relations = moduleRelationRepository.list(moduleId, relationCategoryId, positionKey); // 反向关系isReverse - List reverseRelations = moduleRelationRepository.listReverse(moduleId, relationCategoryId); + List reverseRelations = moduleRelationRepository.listReverse(moduleId, relationCategoryId, positionKey); relations.addAll(reverseRelations); // 所有模型ids Set moduleSet = new HashSet<>(); @@ -373,7 +362,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { if (moduleSet.size() > 0) { List ids = new ArrayList<>(); ids.addAll(moduleSet); - nodes = moduleRepository.listByIds(ids); + nodes = moduleRepository.listByIds(ids, positionKey); } ModuleTopo topo = new ModuleTopo(nodes, links); return new GeneralResult<>(true, topo, "查询模型关系成功!"); @@ -384,17 +373,17 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { } @Override - public GeneralResult listByCategoryId(Long relationCategoryId) { + public GeneralResult listByCategoryId(Long relationCategoryId, String positionKey) { try { if (null == relationCategoryId) { return GeneralResult.FAILED("拓扑id不可为空"); } - RelationCategory relationCategory = relationCategoryRepository.query(relationCategoryId); + RelationCategory relationCategory = relationCategoryRepository.query(relationCategoryId, positionKey); if (null == relationCategory) { return GeneralResult.FAILED("该拓扑不存在"); } // 正向找关系 - List relations = moduleRelationRepository.listByCategoryId(relationCategoryId); + List relations = moduleRelationRepository.listByCategoryId(relationCategoryId, positionKey); // 所有模型ids Set moduleSet = new HashSet<>(); List links = new ArrayList<>(); @@ -416,7 +405,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { if (moduleSet.size() > 0) { List ids = new ArrayList<>(); ids.addAll(moduleSet); - nodes = moduleRepository.listByIds(ids); + nodes = moduleRepository.listByIds(ids, positionKey); } // 处理nodes和links ModuleTopo topo = new ModuleTopo(nodes, links); @@ -428,7 +417,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { } @Override - public GeneralResult relevancy(Long relationCategoryId, Long sourceId, Long targetId) { + public GeneralResult relevancy(Long relationCategoryId, Long sourceId, Long targetId, String positionKey) { try { if (null == relationCategoryId) { return new GeneralResult<>(false, "缺少拓扑参数"); @@ -439,14 +428,14 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { if (null == targetId) { return new GeneralResult<>(false, "缺少目标模型参数"); } - ModuleRelation relation = moduleRelationRepository.query(relationCategoryId, sourceId, targetId); + ModuleRelation relation = moduleRelationRepository.query(relationCategoryId, sourceId, targetId, positionKey); if (null != relation) { // 查询关联规则信息 - AutoRelationRule rule = autoRelationRuleRepository.queryByModuleRelationId(relation.getId()); + AutoRelationRule rule = autoRelationRuleRepository.queryByModuleRelationId(relation.getId(), positionKey); if (null != rule) { - List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId()); + List items = autoRelationRuleItemRepository.queryByRuleId(rule.getId(), positionKey); for (AutoRelationRuleItem item : items) { - item.setValues(autoRelationRuleItemValueRepository.queryByItemId(item.getId())); + item.setValues(autoRelationRuleItemValueRepository.queryByItemId(item.getId(), positionKey)); } relation.setRuleItemList(items); } @@ -465,9 +454,9 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { * @return */ @Override - public GeneralResult> moduleList(Long relationCategoryId) { + public GeneralResult> moduleList(Long relationCategoryId, String positionKey) { try { - List relations = moduleRelationRepository.queryModuleList(relationCategoryId); + List relations = moduleRelationRepository.queryModuleList(relationCategoryId, positionKey); if (CollectionUtils.isEmpty(relations)) { return new GeneralResult<>(true, new ArrayList(), "查询成功"); } @@ -477,7 +466,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { List moduleIds = Stream.of(sourceIds, targetIds).flatMap(Collection::stream).filter(Objects::nonNull) .distinct().collect(Collectors.toList()); // 获取模型集合 - List modules = moduleRepository.queryModuleListByIds(moduleIds); + List modules = moduleRepository.queryModuleListByIds(moduleIds, positionKey); return new GeneralResult<>(true, modules, "查询成功"); } catch (Exception e) { log.error("CmdbModuleRelation modules query fail:", e); @@ -486,7 +475,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { } @Override - public GeneralResult instances(Pager pager, Long userId) { + public GeneralResult instances(Pager pager, Long userId, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -516,11 +505,11 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { paramMap.remove("instanceId"); } } - ModuleRelation moduleRelation = moduleRelationRepository.query(id); + ModuleRelation moduleRelation = moduleRelationRepository.query(id, positionKey); if (null == moduleRelation) { return GeneralResult.FAILED("模型关系不存在"); } - CiModule module = moduleRepository.query(moduleId); + CiModule module = moduleRepository.query(moduleId, positionKey); if (null == module) { return GeneralResult.FAILED("模型不存在"); } @@ -559,12 +548,12 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { List relations = null; Map relationMap = new HashMap<>(); if (CmdbUtils.INSTANCE_RELATION_TYPE_SOURCE.equals(finalInstanceType)) { - relations = instanceRelationRepository.query(relationTable, finalModuleId, null, moduleId, instanceId); + relations = instanceRelationRepository.query(relationTable, finalModuleId, null, moduleId, instanceId, positionKey); for (InstanceRelation relation : relations) { relationMap.put(relation.getSourceInstanceId(), relation); } } else if (CmdbUtils.INSTANCE_RELATION_TYPE_TARGET.equals(finalInstanceType)) { - relations = instanceRelationRepository.query(relationTable, moduleId, instanceId, finalModuleId, null); + relations = instanceRelationRepository.query(relationTable, moduleId, instanceId, finalModuleId, null, positionKey); for (InstanceRelation relation : relations) { relationMap.put(relation.getTargetInstanceId(), relation); } @@ -573,9 +562,9 @@ public class ModuleRelationServiceImpl implements ModuleRelationService { boolean hasAdminRole = instanceService.checkAdminRole(userId); // 查询可被关联的模型实例 List> list = - instanceRepository.list(pager, instanceTable, valueTable, userId, hasAdminRole); - int total = instanceRepository.count(pager.getParams(), instanceTable, valueTable, userId, hasAdminRole); - instanceService.convertInstanceValue(list, moduleId, userId, hasAdminRole); + instanceRepository.list(pager, instanceTable, valueTable, userId, hasAdminRole, positionKey); + int total = instanceRepository.count(pager.getParams(), instanceTable, valueTable, userId, hasAdminRole, positionKey); + instanceService.convertInstanceValue(list, moduleId, userId, hasAdminRole, positionKey); for (Map instance : list) { // 判断被关联的模型实例是否已关联 InstanceRelation existRelation = relationMap.get(instance.get("id")); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java index 73cc5bf..4eb84b9 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/ModuleServiceImpl.java @@ -1,34 +1,7 @@ package com.bocloud.ams.service.module.impl; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -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.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.transaction.interceptor.TransactionAspectSupport; -import org.springframework.util.Assert; - import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.collection.CollectionComponent; import com.bocloud.ams.entity.enums.PropertyType; import com.bocloud.ams.entity.model.PropertyModel; @@ -53,6 +26,7 @@ import com.bocloud.ams.repository.module.RegularExpressionRepository; import com.bocloud.ams.repository.module.TopologyConfigRepository; import com.bocloud.ams.repository.utils.CmdbUtils; import com.bocloud.ams.service.instance.InstanceService; +import com.bocloud.ams.service.internal.CmpInternalService; import com.bocloud.ams.service.module.ModuleService; import com.bocloud.ams.service.module.PropertyService; import com.bocloud.ams.service.utils.ModuleConstant; @@ -66,11 +40,33 @@ import com.megatron.common.model.RequestContext; import com.megatron.common.model.Sign; import com.megatron.common.utils.Common; import com.megatron.common.utils.ListTool; +import com.megatron.common.utils.MapTools; import com.megatron.framework.lock.AutoCloseLock; import com.megatron.framework.lock.LockFactory; - import lombok.extern.slf4j.Slf4j; -import org.yaml.snakeyaml.Yaml; +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.locale.LocaleBeanUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.transaction.interceptor.TransactionAspectSupport; +import org.springframework.util.Assert; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @author 胡立伟 @@ -116,7 +112,7 @@ public class ModuleServiceImpl implements ModuleService { private CmpInternalService cmpInternalService; @Override - public GeneralResult> getModelList(Pager pager) { + public GeneralResult> getModelList(Pager pager, String positionKey) { try { pager.setParams(Optional.ofNullable(pager.getParams()).orElse(new ArrayList<>())); pager.setSorter(Optional.ofNullable(pager.getSorter()).orElse(new HashMap<>())); @@ -135,7 +131,12 @@ public class ModuleServiceImpl implements ModuleService { Long groupId = Long.valueOf((Integer) parMap.get("moduleGroupId")); if (parMap.get("flag").equals(true)) { // 递归获取所有子groupId - List groups = moduleGroupRepository.all(); + List groups = new ArrayList<>(); + if (StringUtils.isEmpty(positionKey)) { + groups = moduleGroupRepository.all(); + } else { + groups = moduleGroupRepository.all(positionKey); + } Map> groupMap = groups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId)); List groupIds = new ArrayList<>(); @@ -159,11 +160,11 @@ public class ModuleServiceImpl implements ModuleService { params.add(newParam); } } - int total = moduleRepository.count(pager.getParams()); - List modules = this.moduleRepository.list(pager); + int total = moduleRepository.count(pager.getParams(), positionKey); + List modules = this.moduleRepository.list(pager, positionKey); if (CollectionUtils.isNotEmpty(modules)) { List groupIds = modules.stream().map(CiModule::getGroupId).collect(Collectors.toList()); - List groups = moduleGroupRepository.queryByIds(groupIds); + List groups = moduleGroupRepository.queryByIds(groupIds, positionKey); if (CollectionUtils.isNotEmpty(groups)) { for (CiModule module : modules) { ModuleGroup group = groups.stream().filter(item -> item.getId().equals(module.getGroupId())) @@ -183,9 +184,9 @@ public class ModuleServiceImpl implements ModuleService { } @Override - public GeneralResult> list() { + public GeneralResult> list( String positionKey) { try { - List modules = moduleRepository.all(); + List modules = moduleRepository.all(positionKey); List list = modules.stream().filter(item -> ModuleConstant.STATUS_ENABLE.equals(item.getStatus())) .collect(Collectors.toList()); return new GeneralResult<>(true, list, "查询成功!"); @@ -196,9 +197,9 @@ public class ModuleServiceImpl implements ModuleService { } @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - CiModule module = moduleRepository.query(id); + CiModule module = moduleRepository.query(id, positionKey); return new GeneralResult<>(true, module, "查询成功"); } catch (Exception e) { log.error("moduleService detail fail:", e); @@ -371,13 +372,13 @@ public class ModuleServiceImpl implements ModuleService { } @Override - public GeneralResult property(Long moduleId) { + public GeneralResult property(Long moduleId, String positionKey) { try { - List groups = propertyGroupRepository.listByModuleId(moduleId); - List properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId); - List items = propertyItemRepository.queryByModuleId(moduleId); + List groups = propertyGroupRepository.listByModuleId(moduleId, positionKey); + List properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId, positionKey); + List items = propertyItemRepository.queryByModuleId(moduleId, positionKey); for (Property property : properties) { - propertyService.propertyHandle(property, items); + propertyService.propertyHandle(property, items, positionKey); } PropertyModel model = new PropertyModel(moduleId, groups, properties); return new GeneralResult<>(true, model, "查询属性成功"); @@ -388,16 +389,16 @@ public class ModuleServiceImpl implements ModuleService { } @Override - public GeneralResult> propertyList(Long moduleId, Pager pager) { + public GeneralResult> propertyList(Long moduleId, 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("id", Common.ONE); - int total = propertyRepository.count(pager.getParams(), moduleId); - List properties = propertyRepository.list(pager, moduleId); + int total = propertyRepository.count(pager.getParams(), moduleId, positionKey); + List properties = propertyRepository.list(pager, moduleId, positionKey); for (Property property : properties) { if (null != property.getPropertyPoolId()) { - PropertyPool pool = propertyPoolRepository.query(property.getPropertyPoolId()); + PropertyPool pool = propertyPoolRepository.query(property.getPropertyPoolId(), positionKey); this.copyProperties(property, pool); } property.setPropertyId(property.getId()); @@ -427,17 +428,17 @@ public class ModuleServiceImpl implements ModuleService { } @Override - public GeneralResult statistics(RequestContext context) { + public GeneralResult statistics(RequestContext context, String positionKey) { try { List nameList = Arrays.asList("网络设备", "物理服务器", "安全设备"); //查询根节点 - List rootGroups = moduleGroupRepository.queryRootInName(nameList); + List rootGroups = moduleGroupRepository.queryRootInName(nameList, positionKey); Map resultMap = new HashMap<>(); for (ModuleGroup rootGroup : rootGroups) { //获取每个模型的所有实例总数 - getInstaceCount(rootGroup, resultMap, context.getTarget()); + getInstaceCount(rootGroup, resultMap, context.getTarget(), positionKey); } //查询云主机总数 @@ -465,7 +466,7 @@ public class ModuleServiceImpl implements ModuleService { } } - private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, Long userId) throws Exception { + private void getInstaceCount(ModuleGroup rootGroup, Map resultMap, Long userId, String positionKey) throws Exception { //获取当前ModuleGroup下所有的modle Pager pager = new Pager(); List modelParamList = new ArrayList<>(); @@ -478,7 +479,7 @@ public class ModuleServiceImpl implements ModuleService { pager.setRows(Integer.MAX_VALUE); modelParamList.add(modelParam); pager.setParams(modelParamList); - GeneralResult> modelList = getModelList(pager); + GeneralResult> modelList = getModelList(pager, positionKey); if (modelList.isFailed()) { log.info("modelList:{}", JSON.toJSONString(modelList)); throw new Exception("查询实例失败"); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyPoolServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyPoolServiceImpl.java index 6ca9a20..2121dd4 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyPoolServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyPoolServiceImpl.java @@ -1,23 +1,5 @@ package com.bocloud.ams.service.module.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.TimeUnit; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -import org.apache.commons.beanutils.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.module.Property; import com.bocloud.ams.entity.module.PropertyItem; @@ -35,8 +17,24 @@ import com.megatron.common.model.Pager; 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.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * @Description: 属性池实现类 @@ -336,13 +334,13 @@ public class PropertyPoolServiceImpl implements PropertyPoolService { } @Override - public GeneralResult list(Pager pager) { + public GeneralResult 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 = propertyPoolRepository.count(pager.getParams()); - List list = this.propertyPoolRepository.list(pager); + int total = propertyPoolRepository.count(pager.getParams(), positionKey); + List list = this.propertyPoolRepository.list(pager, positionKey); if (CollectionUtils.isNotEmpty(list)) { for (PropertyPool pool : list) { dealPoolItem(pool); diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyServiceImpl.java index efeaeb3..23953bf 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/PropertyServiceImpl.java @@ -1,18 +1,5 @@ package com.bocloud.ams.service.module.impl; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.bocloud.ams.entity.module.Property; @@ -29,8 +16,19 @@ import com.bocloud.ams.service.module.PropertyService; import com.bocloud.ams.service.utils.PropertyConstant; import com.megatron.common.model.GeneralResult; import com.megatron.common.utils.Common; - import lombok.extern.slf4j.Slf4j; +import org.apache.commons.beanutils.BeanUtilsBean; +import org.apache.commons.beanutils.locale.LocaleBeanUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; /** * @Author 胡立伟 @@ -55,14 +53,14 @@ public class PropertyServiceImpl implements PropertyService { RegularExpressionRepository regularExpressionRepository; @Override - public GeneralResult detail(Long id) { + public GeneralResult detail(Long id, String positionKey) { try { - Property property = propertyRepository.query(id); + Property property = propertyRepository.query(id, positionKey); if (null == property) { return new GeneralResult<>(false, "没有此模型"); } - List items = propertyItemRepository.queryByPropertyId(id); - this.propertyHandle(property, items); + List items = propertyItemRepository.queryByPropertyId(id, positionKey); + this.propertyHandle(property, items, positionKey); return new GeneralResult<>(true, property, "查询成功"); } catch (Exception e) { log.error("propertyService detail fail:", e); @@ -71,12 +69,12 @@ public class PropertyServiceImpl implements PropertyService { } @Override - public void propertyHandle(Property property, List items) throws Exception { + public void propertyHandle(Property property, List items, String positionKey) throws Exception { // 判断当前属性是否是引用池中的属性 if (null != property.getPropertyPoolId()) { - PropertyPool pool = propertyPoolRepository.query(property.getPropertyPoolId()); + PropertyPool pool = propertyPoolRepository.query(property.getPropertyPoolId(), positionKey); this.copyProperties(property, pool); - List poolItems = propertyPoolItemRepository.listByPropertyPoolId(pool.getId()); + List poolItems = propertyPoolItemRepository.listByPropertyPoolId(pool.getId(), positionKey); List propertyItems = new ArrayList<>(); if (CollectionUtils.isNotEmpty(poolItems)) { for (PropertyPoolItem poolItem : poolItems) { @@ -96,7 +94,7 @@ public class PropertyServiceImpl implements PropertyService { this.handleProperty(property, items); } if (property.getRegexpId() != null) { - property.setRegularExpression(regularExpressionRepository.query(property.getRegexpId())); + property.setRegularExpression(regularExpressionRepository.query(property.getRegexpId(), positionKey)); } } diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RegularExpressionServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RegularExpressionServiceImpl.java index 2166ff0..b4ba23c 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RegularExpressionServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RegularExpressionServiceImpl.java @@ -1,18 +1,16 @@ package com.bocloud.ams.service.module.impl; -import java.util.List; -import java.util.stream.Collectors; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - import com.bocloud.ams.entity.module.RegularExpression; import com.bocloud.ams.repository.module.RegularExpressionRepository; import com.bocloud.ams.service.module.RegularExpressionService; import com.bocloud.ams.service.utils.PropertyConstant; import com.megatron.common.model.GeneralResult; - import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; /** * CiRegularExpression Service实现层 @@ -29,7 +27,7 @@ public class RegularExpressionServiceImpl implements RegularExpressionService { private RegularExpressionRepository regularExpressionRepository; @Override - public GeneralResult> list(final String type) { + public GeneralResult> list(final String type, String positionKey) { try { List expressions = regularExpressionRepository.listAll(); // 模型属性的类别为数据加密的单独处理 diff --git a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RelationCategoryServiceImpl.java b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RelationCategoryServiceImpl.java index a3df794..3a6d20e 100644 --- a/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RelationCategoryServiceImpl.java +++ b/bocloud.ams.service/src/main/java/com/bocloud/ams/service/module/impl/RelationCategoryServiceImpl.java @@ -1,19 +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.Map; -import java.util.Optional; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.beanutils.locale.LocaleBeanUtils; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - import com.bocloud.ams.entity.module.CiModule; import com.bocloud.ams.entity.module.ModuleRelation; import com.bocloud.ams.entity.module.Relation; @@ -35,8 +21,20 @@ import com.megatron.common.model.Param; 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.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; /** * @Description: 关联类型分组管理 @@ -232,9 +230,9 @@ public class RelationCategoryServiceImpl implements RelationCategoryService { } @Override - public GeneralResult listByModuleId(Long moduleId) { + public GeneralResult listByModuleId(Long moduleId, String positionKey) { try { - List list = relationCategoryRepository.listByModuleId(moduleId); + List list = relationCategoryRepository.listByModuleId(moduleId, positionKey); return new GeneralResult<>(true, list, "查询成功"); } catch (Exception e) { log.error("CmdbRelationCategory list query by moduleId fail:", e);