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

develop
yuemian 2024-08-29 09:38:51 +08:00
parent 70803db54c
commit 3590df533c
85 changed files with 1977 additions and 699 deletions

View File

@ -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<GridBean<AutoRelationRule>> list(Pager pager) {
return autoRelationRuleService.list(pager);
public GeneralResult<GridBean<AutoRelationRule>> 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<AutoRelationRule> detail(@PathVariable(value = Common.ID) Long id) {
return autoRelationRuleService.detail(id);
public GeneralResult<AutoRelationRule> 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<AutoRelationRuleItem> itemDetail(@PathVariable("itemId") Long itemId) {
return autoRelationRuleService.itemDetail(itemId);
public GeneralResult<AutoRelationRuleItem> itemDetail(@PathVariable("itemId") Long itemId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return autoRelationRuleService.itemDetail(itemId, positionKey);
}
/**

View File

@ -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<GridBean<OperationalAudit>> operationalAudit(Pager pager) {
return operationalAuditService.list(pager);
public GeneralResult<GridBean<OperationalAudit>> 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> operationalAudit(@PathVariable(value = Common.ID) Long id) {
return operationalAuditService.deatil(id);
public GeneralResult<OperationalAudit> 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<GridBean<OperationalAuditBak>> operationalAuditBak(Pager pager) {
return operationalAuditService.bakList(pager);
public GeneralResult<GridBean<OperationalAuditBak>> operationalAuditBak(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return operationalAuditService.bakList(pager, positionKey);
}
}

View File

@ -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<GridBean<Map<String, Object>>> 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<GridBean<CollectionHistory>> history(Pager pager) {
return collectionHistoryService.list(pager);
public GeneralResult<GridBean<CollectionHistory>> 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<GridBean<CollectionHistory>> backupHistory(Pager pager) {
return collectionHistoryService.backupHistory(pager);
public GeneralResult<GridBean<CollectionHistory>> backupHistory(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionHistoryService.backupHistory(pager, positionKey);
}
@Operation(tags = {"CMC"}, summary = "实例采集历史备份列表")
@GetMapping("/backup/instances")
public GeneralResult<GridBean<Map<String, Object>>> 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);
}
}

View File

@ -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<GridBean<CollectionHistoryItem>> historyItems(Pager pager) {
return collectionHistoryItemService.list(pager);
public GeneralResult<GridBean<CollectionHistoryItem>> historyItems(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionHistoryItemService.list(pager, positionKey);
}
@Operation(tags = {"CMC"}, summary = "实例采集历史条目备份列表")
@GetMapping("/backup")
public GeneralResult<GridBean<CollectionHistoryItem>> backupHistoryItems(Pager pager) {
return collectionHistoryItemService.backupHistoryItems(pager);
public GeneralResult<GridBean<CollectionHistoryItem>> backupHistoryItems(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionHistoryItemService.backupHistoryItems(pager, positionKey);
}
}

View File

@ -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<Application
*/
@Operation(tags = {"CMC"}, summary = "采集任务列表")
@GetMapping
public GeneralResult<GridBean<CollectionTask>> list(Pager pager) {
return collectionTaskService.list(pager);
public GeneralResult<GridBean<CollectionTask>> list(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionTaskService.list(pager, positionKey);
}
/**
@ -123,8 +116,9 @@ public class CollectionTaskController implements ApplicationListener<Application
*/
@GetMapping(value = "/{id}")
@Operation(tags = {"CMC", "CSC"}, summary = "采集任务详情")
public GeneralResult<CollectionTask> detail(@PathVariable(value = Common.ID) Long id) {
return collectionTaskService.detail(id);
public GeneralResult<CollectionTask> detail(@PathVariable(value = Common.ID) Long id,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionTaskService.detail(id, positionKey);
}
/**

View File

@ -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<GridBean<CollectionTaskInstance>> list(Pager pager) {
return collectionTaskInstanceService.list(pager);
public GeneralResult<GridBean<CollectionTaskInstance>> 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<CollectionTaskInstance> detail(@PathVariable(value = Common.ID) Long id) {
return collectionTaskInstanceService.detail(id);
public GeneralResult<CollectionTaskInstance> 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<GridBean<CollectionTaskInstance>> bakList(Pager pager) {
return collectionTaskInstanceService.bakList(pager);
public GeneralResult<GridBean<CollectionTaskInstance>> 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<CollectionTaskInstance> 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);
}
}

View File

@ -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<GridBean<CollectionComponent>> components(Pager pager) {
return collectionTemplateService.components(pager);
public GeneralResult<GridBean<CollectionComponent>> 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<GridBean<CollectionTemplate>> list(Pager pager) {
return collectionTemplateService.list(pager);
public GeneralResult<GridBean<CollectionTemplate>> 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<CollectionTemplate> detail(@PathVariable(value = Common.ID) Long id) {
return collectionTemplateService.detail(id);
public GeneralResult<CollectionTemplate> detail(@PathVariable(value = Common.ID) Long id,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return collectionTemplateService.detail(id, positionKey);
}
}

View File

@ -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<Map<String, String>> getByCodes(
@RequestParam(value = "category", required = false) String category,
@RequestParam(value = "codes", required = false) ArrayList<String> codes) {
return cmdbConfigService.listConfigs(category, codes);
@RequestParam(value = "codes", required = false) ArrayList<String> 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<JSONArray> listCategoryTree(@RequestParam(value = "category") String category) {
return cmdbConfigService.listCategoryTree(category);
public GeneralResult<JSONArray> listCategoryTree(@RequestParam(value = "category") String category,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return cmdbConfigService.listCategoryTree(category, positionKey);
}
}

View File

@ -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<GridBean<InstanceAuthority>> list(Pager pager) {
return instanceAuthorityService.list(pager);
public GeneralResult<GridBean<InstanceAuthority>> list(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return instanceAuthorityService.list(pager, positionKey);
}
/***

View File

@ -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<Map<String, Object>>> 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<Instance> 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<InstanceTopo> 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);
}
}

View File

@ -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<GridBean<InstanceHistory>> history(Pager pager) {
return instanceHistoryService.list(pager);
public GeneralResult<GridBean<InstanceHistory>> history(Pager pager,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return instanceHistoryService.list(pager, positionKey);
}
}

View File

@ -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<GridBean<InstanceRelationHistoryRecord>> 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")

View File

@ -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<GridBean<CiModule>> 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<CiModule>> list() {
return moduleService.list();
public GeneralResult<List<CiModule>> 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<CiModule> detail(@PathVariable(value = Common.ID) Long id) {
return moduleService.detail(id);
public GeneralResult<CiModule> 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<List<RelationCategory>> listRelationCategory(@PathVariable(value = Common.ID) Long id) {
return relationCategoryService.listByModuleId(id);
public GeneralResult<List<RelationCategory>> 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<PropertyModel> property(@PathVariable(value = Common.ID) Long id) {
return moduleService.property(id);
public GeneralResult<PropertyModel> 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<GridBean<Property>> 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);
}
}

View File

@ -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<List<ModuleGroup>> 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<List<ModuleGroup>> queryRoot() {
return moduleGroupService.queryRoot();
public GeneralResult<List<ModuleGroup>> 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<List<ModuleGroup>> queryRootChildren() {
return moduleGroupService.queryRootChildren();
public GeneralResult<List<ModuleGroup>> 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<ModuleGroup> 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<ModuleGroup> detail(@PathVariable(value = Common.ID) Long id) {
return moduleGroupService.detail(id);
public GeneralResult<ModuleGroup> 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<List<ModuleGroup>> querylist() {
return moduleGroupService.querylist();
public GeneralResult<List<ModuleGroup>> 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<List<ModuleGroup>> 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);
}
}

View File

@ -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<ModuleRelation> 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<ModuleTopo> 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<ModuleTopo> listAll(@PathVariable(value = "relationCategoryId") Long relationCategoryId) {
public GeneralResult<ModuleTopo> 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<List<CiModule>> moduleList(@PathVariable(value = "relationCategoryId") Long relationCategoryId) {
return moduleRelationService.moduleList(relationCategoryId);
public GeneralResult<List<CiModule>> 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);
}

View File

@ -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<Property> propertyDetail(@PathVariable(value = "propertyId") Long propertyId) {
return propertyService.detail(propertyId);
public GeneralResult<Property> propertyDetail(@PathVariable(value = "propertyId") Long propertyId,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return propertyService.detail(propertyId, positionKey);
}
}

View File

@ -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<GridBean<PropertyPool>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
return propertyPoolService.list(pager);
public GeneralResult<GridBean<PropertyPool>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return propertyPoolService.list(pager, positionKey);
}
/**

View File

@ -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<RegularExpression>> list(@RequestParam(value = Common.TYPE) String type) {
return regularExpressionService.list(type);
public GeneralResult<List<RegularExpression>> list(@RequestParam(value = Common.TYPE) String type,
@RequestParam(value = "positionKey", required = false) String positionKey) {
return regularExpressionService.list(type, positionKey);
}
}

View File

@ -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<TableLog, Long> {
List<TableLog> list = this.list(TableLog.class, sql, MapTools.simpleMap("templateTable", templateTable));
return list;
}
public List<TableLog> 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<TableLog> list = this.list(TableLog.class, sql, MapTools.simpleMap("templateTable", templateTable));
return list;
}
}

View File

@ -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<AutoRelation
return this.list(AutoRelationRuleItem.class, sql, MapTools.simpleMap("ruleId", ruleId));
}
public List<AutoRelationRuleItem> 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<AutoRelationRuleItem> 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<AutoRelationRuleItem> list = this.list(AutoRelationRuleItem.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
}

View File

@ -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<AutoRel
return this.list(AutoRelationRuleItemValue.class, sql, MapTools.simpleMap("itemId", itemId));
}
public List<AutoRelationRuleItemValue> 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<AutoRelationRuleItemValue> 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));

View File

@ -8,6 +8,7 @@ import com.megatron.common.utils.Common;
import com.megatron.common.utils.MapTools;
import com.megatron.database.core.intf.impl.BasicGenericDao;
import com.megatron.framework.core.CurrentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
@ -39,6 +40,22 @@ public class AutoRelationRuleRepository extends BasicGenericDao<AutoRelationRule
return this.list(AutoRelationRule.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<AutoRelationRule> 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<SimpleBean> list(List<Param> params, Map<String, String> 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<AutoRelationRule
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> 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<AutoRelationRule> list = this.list(AutoRelationRule.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> 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<AutoRelationRule> 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<AutoRelationRule> list = this.list(AutoRelationRule.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public int count(List<Param> 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<Param> 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<AutoRelationRule
return list.isEmpty() ? null : list.get(0);
}
public AutoRelationRule queryByModuleRelationId(Long moduleRelationId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select * from " + positionKey + ".ci_auto_relation_rule where is_deleted=0 and module_relation_id = :moduleRelationId";
} else {
sql = "select * from ci_auto_relation_rule where is_deleted=0 and module_relation_id = :moduleRelationId";
}
List<AutoRelationRule> list = this.list(AutoRelationRule.class, sql, MapTools.simpleMap("moduleRelationId", moduleRelationId));
return list.isEmpty() ? null : list.get(0);
}
public List<AutoRelationRule> 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<String, Object> params = MapTools.simpleMap("relationCategoryId", relationCategoryId);

View File

@ -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<OperationalAu
return this.countQuery(sql, params).intValue();
}
public int queryCount(String tableName, String leftTime, String rightTime, String positionKey) throws Exception {
if (!StringUtils.isEmpty(positionKey)) {
tableName = positionKey + "." + tableName;
}
String sql = "select count(1) from " + tableName + " a where a.is_deleted = 0 and a.gmt_create >= :leftTime and a.gmt_create <= :rightTime ";
Map<String, Object> params = new HashMap<>();
params.put("leftTime", leftTime);
params.put("rightTime", rightTime);
return this.countQuery(sql, params).intValue();
}
public int count(List<Param> params, List<String> finalInstanceTableNames) throws Exception {
String sql = "";
if (finalInstanceTableNames.size() == 1) {
@ -118,6 +130,43 @@ public class OperationalAuditBakRepository extends BasicGenericDao<OperationalAu
return this.countQuery(sql, paramMap).intValue();
}
public int count(List<Param> params, List<String> 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<String, Object> paramMap = getQueryBuilder().getParam(params);
return this.countQuery(sql, paramMap).intValue();
}
public List<OperationalAuditBak> list(Pager pager, List<String> finalInstanceTableNames) throws Exception {
String sql = "";
@ -140,4 +189,43 @@ public class OperationalAuditBakRepository extends BasicGenericDao<OperationalAu
return this.list(OperationalAuditBak.class, sql);
}
public List<OperationalAuditBak> list(Pager pager, List<String> 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);
}
}

View File

@ -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<OperationalAudit
return this.countQuery(sql, getQueryBuilder().getParam(params)).intValue();
}
public int count(List<Param> params, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select count(1) from " + positionKey + ".ci_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<OperationalAudit> 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<OperationalAudit> 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<OperationalAudit> 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<OperationalAudit> list = this.list(OperationalAudit.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public List<OperationalAudit> list(List<Param> params) throws Exception {
String sql = "select * from ci_operational_audit a where 1 = 1";
sql = getQueryBuilder().buildRaw(sql, params, null, "a");

View File

@ -8,6 +8,7 @@ import com.megatron.common.utils.Common;
import com.megatron.common.utils.MapTools;
import com.megatron.database.core.intf.impl.BasicGenericDao;
import com.megatron.framework.core.CurrentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
@ -36,6 +37,21 @@ public class CollectionComponentRepository extends BasicGenericDao<CollectionCom
return this.list(CollectionComponent.class, sql, getQueryBuilder().getParam(params));
}
public List<CollectionComponent> list(int page, int rows, List<Param> params, Map<String, String> 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<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionCom
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionComponent> list = this.list(CollectionComponent.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
for (CollectionComponent component : list) {
beans.add(new SimpleBean(component.getId(), component.getName()));
}
return beans;
}
public int count(List<Param> 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<Param> 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<CollectionComponent> list = this.list(CollectionComponent.class, sql, MapTools.simpleMap(Common.ID, id));
@ -64,6 +107,20 @@ public class CollectionComponentRepository extends BasicGenericDao<CollectionCom
return this.list(CollectionComponent.class, sql, MapTools.simpleMap(Common.ID, id));
}
public List<CollectionComponent> 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<CollectionComponent> 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<String, Object> params = MapTools.simpleMap(Common.ID, id);

View File

@ -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<CollectionH
return this.list(CollectionHistoryItem.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<CollectionHistoryItem> 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<Param> 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<Param> 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<CollectionHistoryItem> 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<CollectionH
return this.list(CollectionHistoryItem.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<CollectionHistoryItem> 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<Param> 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<Param> 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();
}
}

View File

@ -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<CollectionHisto
return list(CollectionHistory.class, sql, params);
}
public List<CollectionHistory> 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<String, Object> params = MapTools.simpleMap("taskInstanceId", taskInstanceId);
params.put("type", type);
return list(CollectionHistory.class, sql, params);
}
public List<CollectionHistory> 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<CollectionHistory> 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<Param> 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<Param> 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<CollectionHistory> list = this.list(CollectionHistory.class, sql, MapTools.simpleMap(Common.ID, id));
@ -77,16 +112,44 @@ public class CollectionHistoryRepository extends BasicGenericDao<CollectionHisto
return list(CollectionHistory.class, sql, params);
}
public List<CollectionHistory> 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<String, Object> params = MapTools.simpleMap("taskInstanceId", taskInstanceId);
params.put("type", type);
return list(CollectionHistory.class, sql, params);
}
public int count(String tableName, List<Param> 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<Param> 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<CollectionHistory> 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<CollectionHistory> 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()));
}
}

View File

@ -8,6 +8,7 @@ import com.megatron.common.utils.Common;
import com.megatron.common.utils.MapTools;
import com.megatron.database.core.intf.impl.BasicGenericDao;
import com.megatron.framework.core.CurrentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
@ -43,6 +44,21 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao<Collection
return this.list(CollectionTaskInstance.class, sql, getQueryBuilder().getParam(params));
}
public List<CollectionTaskInstance> list(int page, int rows, List<Param> params, Map<String, String> 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<SimpleBean> list(List<Param> params, Map<String, String> 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<Collection
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionTaskInstance> list = this.list(CollectionTaskInstance.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
for (CollectionTaskInstance instance : list) {
beans.add(new SimpleBean(instance.getId(), instance.getName()));
}
return beans;
}
public int count(List<Param> 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<Param> 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<CollectionTaskInstance> list(List<Param> 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<Collection
return list.isEmpty() ? null : list.get(0);
}
public CollectionTaskInstance queryByPositionKey(Long id, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select * from " + positionKey + ".ci_collection_task_instance where id = :id and is_deleted = 0";
} else {
sql = "select * from ci_collection_task_instance where id = :id and is_deleted = 0";
}
List<CollectionTaskInstance> 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<CollectionTaskInstance> list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.UUID, taskId));
@ -94,18 +148,55 @@ public class CollectionTaskInstanceRepository extends BasicGenericDao<Collection
return list;
}
public List<CollectionTaskInstance> 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<String, Object> params = new HashMap<>();
params.put("leftTime", leftTime);
params.put("rightTime", rightTime);
List<CollectionTaskInstance> list = this.list(CollectionTaskInstance.class, sql, params);
return list;
}
public List<CollectionTaskInstance> 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<CollectionTaskInstance> 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<CollectionTaskInstance> listIdBak(List<Param> params, Map<String, String> 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<CollectionTaskInstance> listIdBak(List<Param> params, Map<String, String> 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<Param> 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<Collection
return this.countQuery(sql, paramMap).intValue();
}
public int count(List<Param> 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<String, Object> 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<CollectionTaskInstance> 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<CollectionTaskInstance> list = this.list(CollectionTaskInstance.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
}

View File

@ -31,16 +31,50 @@ public class CollectionTaskRepository extends BasicGenericDao<CollectionTask, Lo
}
public List<CollectionTask> list(int page, int rows, List<Param> params, Map<String, String> 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<CollectionTask> list(int page, int rows, List<Param> params, Map<String, String> 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<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionTask> list = this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
for (CollectionTask task : list) {
beans.add(new SimpleBean(task.getId(), task.getName()));
}
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionTask> list = this.list(CollectionTask.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
@ -52,7 +86,21 @@ public class CollectionTaskRepository extends BasicGenericDao<CollectionTask, Lo
public int count(List<Param> 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<Param> 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<CollectionTask, Lo
return list.isEmpty() ? null : list.get(0);
}
public CollectionTask query(Long id, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select * from " + positionKey + ".ci_collection_task where id = :id and is_deleted = 0";
} else {
sql = "select * from ci_collection_task where id = :id and is_deleted = 0";
}
List<CollectionTask> list = this.list(CollectionTask.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public List<CollectionTask> 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<CollectionTask, Lo
public boolean delete(Long id, Long userId) throws Exception {
String sql =
"update ci_collection_task set is_deleted=1,gmt_modify = :gmtModify,mender_id=:userId where id = :id";
"update ci_collection_task set is_deleted=1,gmt_modify = :gmtModify,mender_id=:userId where id = :id";
Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
params.put("gmtModify", new Date());
params.put("userId", userId);
@ -95,7 +154,7 @@ public class CollectionTaskRepository extends BasicGenericDao<CollectionTask, Lo
public Integer changeStatus(Long id, String status, Long menderId) {
String sql =
"update ci_collection_task set status =:status , mender_id = :menderId ,gmt_modify = now() where id = :id and is_deleted = 0";
"update ci_collection_task set status =:status , mender_id = :menderId ,gmt_modify = now() where id = :id and is_deleted = 0";
Map<String, Object> param = MapTools.simpleMap("id", id);
param.put("status", status);
param.put("menderId", menderId);
@ -104,8 +163,8 @@ public class CollectionTaskRepository extends BasicGenericDao<CollectionTask, Lo
public List<CollectionTask> 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));
}

View File

@ -8,6 +8,7 @@ import com.megatron.common.utils.Common;
import com.megatron.common.utils.MapTools;
import com.megatron.database.core.intf.impl.BasicGenericDao;
import com.megatron.framework.core.CurrentService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;
@ -42,6 +43,19 @@ public class CollectionTemplateRepository extends BasicGenericDao<CollectionTemp
return this.list(CollectionTemplate.class, sql, getQueryBuilder().getParam(params));
}
public List<CollectionTemplate> list(int page, int rows, List<Param> params, Map<String, String> 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<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionTemp
return beans;
}
public List<SimpleBean> list(List<Param> params, Map<String, String> 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<CollectionTemplate> list = this.list(CollectionTemplate.class, sql, getQueryBuilder().getParam(params));
List<SimpleBean> beans = new ArrayList<>();
for (CollectionTemplate template : list) {
beans.add(new SimpleBean(template.getId(), template.getName(), template.getCollectionType()));
}
return beans;
}
public int count(List<Param> 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<Param> 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<CollectionTemplate> 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<CollectionTemplate> 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<String, Object> params = MapTools.simpleMap(Common.ID, id);

View File

@ -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<CmdbConfig, Long> {
return this.list(CmdbConfig.class, sql, MapTools.simpleMap(Common.CODE, codes));
}
public List<CmdbConfig> listByCodes(Set<String> 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<CmdbConfig> 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<CmdbConfig> 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));
}
}

View File

@ -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<InstanceAuthori
return this.list(InstanceAuthority.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<InstanceAuthority> 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<Param> 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<Param> 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<InstanceAuthority> list = this.list(InstanceAuthority.class, sql, MapTools.simpleMap(Common.ID, id));
@ -113,6 +136,19 @@ public class InstanceAuthorityRepository extends BasicGenericDao<InstanceAuthori
return this.list(InstanceAuthority.class, sql, params);
}
public List<InstanceAuthority> 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<String, Object> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);

View File

@ -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<InstanceHistory,
return this.list(InstanceHistory.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<InstanceHistory> 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<Param> 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<Param> 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<InstanceHistory> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);

View File

@ -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<Ins
return this.list(InstanceRelationHistoryRecord.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<InstanceRelationHistoryRecord> 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<Param> 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<Param> 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<InstanceRelationHistoryRecord> list = this.list(InstanceRelationHistoryRecord.class, sql, MapTools.simpleMap(Common.ID, id));

View File

@ -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<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> 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<String, Object> 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<InstanceRelation> list = this.list(InstanceRelation.class, sql, MapTools.simpleMap(Common.ID, id));
@ -222,6 +241,18 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
params.put("instanceId", instanceId);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
@ -229,6 +260,18 @@ public class InstanceRelationRepository extends BasicGenericDao<InstanceRelation
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
params.put("instanceId", instanceId);
return this.list(InstanceRelation.class, sql, params);
}
public List<InstanceRelation> listReverse(final String instanceRelationTableName, Long categoryId, List<Long> sourceInstanceIds, List<Long> 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<String, Object> params = MapTools.simpleMap("categoryId", categoryId);

View File

@ -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<Instance, Long> {
return this.list(sql, paramMap);
}
public List<Map<String, Object>> 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<String, Object> paramMap = getQueryBuilder().getParam(pager.getParams());
return this.list(sql, paramMap);
}
public int count(List<Param> 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<Instance, Long> {
return this.countQuery(sql, param).intValue();
}
public int count(List<Param> 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<String, Object> 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<String, Object> params = MapTools.simpleMap(Common.UUID, uuid);
@ -124,6 +157,15 @@ public class InstanceRepository extends BasicGenericDao<Instance, Long> {
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<Instance> 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<String, Object> params = MapTools.simpleMap(Common.ID, id);
@ -171,6 +213,19 @@ public class InstanceRepository extends BasicGenericDao<Instance, Long> {
return this.list(sql, MapTools.simpleMap("ids", ids));
}
public List<Map<String, Object>> listAll(String instanceTable, String instanceValueTable, Long moduleId, List<Long> 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<Instance> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);

View File

@ -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<InstanceValue, Long
return this.list(InstanceValue.class, sql, MapTools.simpleMap("instanceId", instanceId));
}
public List<InstanceValue> 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<String, Object> params = MapTools.simpleMap(Common.ID, id);
@ -135,6 +144,17 @@ public class InstanceValueRepository extends BasicGenericDao<InstanceValue, Long
return list.isEmpty() ? null : list.get(0);
}
public InstanceValue query(String instanceValueTable, String propertyCode, Long instanceId, String positionKey) throws Exception {
if (StringUtils.isNotEmpty(positionKey)) {
instanceValueTable = positionKey + "." + instanceValueTable;
}
String sql = "select a.* from " + instanceValueTable + " a where property_code = :propertyCode and instance_id = :instanceId and is_deleted=0 ";
Map<String, Object> params = MapTools.simpleMap("propertyCode", propertyCode);
params.put("instanceId", instanceId);
List<InstanceValue> list = this.list(InstanceValue.class, sql, params);
return list.isEmpty() ? null : list.get(0);
}
public List<InstanceValue> queryByInstanceIdsAndPropertyIds(String instanceValueTable, List<Long> instanceIds, List<Long> 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<String, Object> params = MapTools.simpleMap("instanceIds", instanceIds);

View File

@ -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<ModuleGroup, Long> {
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<ModuleGroup> 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<ModuleGroup> queryRootInName(List<String> nameList) throws Exception {
String sql = "select * from ci_module_group where is_deleted =0 and parent_id =0 and name in (:name) ORDER BY gmt_create DESC ";
Map<String, Object> params = MapTools.simpleMap("name", nameList);
return this.list(ModuleGroup.class, sql, params);
}
public List<ModuleGroup> queryRootInName(List<String> 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<String, Object> params = MapTools.simpleMap("name", nameList);
return this.list(ModuleGroup.class, sql, params);
}
public List<ModuleGroup> queryChildren(Long id) throws Exception {
String sql = "select * from ci_module_group where is_deleted =0 and parent_id = :id ORDER BY gmt_create DESC ";
return this.list(ModuleGroup.class, sql, MapTools.simpleMap("id", id));
@ -52,6 +75,11 @@ public class ModuleGroupRepository extends BasicGenericDao<ModuleGroup, Long> {
return this.list(ModuleGroup.class, sql, null);
}
public List<ModuleGroup> 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<ModuleGroup, Long> {
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<ModuleGroup> list = this.list(ModuleGroup.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public List<ModuleGroup> queryByIds(List<Long> 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<ModuleGroup> queryByIds(List<Long> 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));
}
}

View File

@ -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<ModuleRelation, Lo
return list.isEmpty() ? null : list.get(0);
}
public ModuleRelation query(Long id, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotBlank(positionKey)) {
sql = "select a.*,sm.name source_name,tm.name target_name,c.name relation_category_name,CONCAT(a.source_type,'-',a.target_type) rule from " + positionKey + ".ci_module_relation a " + " left join " + positionKey + ".ci_module sm on a.source_id =sm.id and sm.is_deleted =0 " + " left join " + positionKey + ".ci_module tm on a.target_id =tm.id and tm.is_deleted =0 " + " left join " + positionKey + ".ci_relation_category c on a.relation_category_id =c.id and c.is_deleted =0 " + " where a.id = :id and a.is_deleted=0 ";
} else {
sql = "select a.*,sm.name source_name,tm.name target_name,c.name relation_category_name,CONCAT(a.source_type,'-',a.target_type) rule from ci_module_relation a " + " left join ci_module sm on a.source_id =sm.id and sm.is_deleted =0 " + " left join ci_module tm on a.target_id =tm.id and tm.is_deleted =0 " + " left join ci_relation_category c on a.relation_category_id =c.id and c.is_deleted =0 " + " where a.id = :id and a.is_deleted=0 ";
}
List<ModuleRelation> 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<String, Object> params = MapTools.simpleMap("relationCategoryId", relationCategoryId);
@ -62,6 +74,20 @@ public class ModuleRelationRepository extends BasicGenericDao<ModuleRelation, Lo
return list.isEmpty() ? null : list.get(0);
}
public ModuleRelation query(Long relationCategoryId, Long sourceModuleId, Long targetModuleId, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_module_relation a where a.relation_category_id = :relationCategoryId and a.source_id = :sourceModuleId and a.target_id = :targetModuleId and is_deleted=0 ";
} else {
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<String, Object> params = MapTools.simpleMap("relationCategoryId", relationCategoryId);
params.put("sourceModuleId", sourceModuleId);
params.put("targetModuleId", targetModuleId);
List<ModuleRelation> list = this.list(ModuleRelation.class, sql, params);
return list.isEmpty() ? null : list.get(0);
}
public List<ModuleRelation> list(List<Param> params, Map<String, String> 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<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> 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<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
params.put("moduleId", moduleId);
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> 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<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
@ -82,11 +120,33 @@ public class ModuleRelationRepository extends BasicGenericDao<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> 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<String, Object> params = MapTools.simpleMap("categoryId", categoryId);
params.put("moduleId", moduleId);
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> 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<ModuleRelation> 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<ModuleRelation> 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<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, MapTools.simpleMap("categoryId", categoryId));
}
public List<ModuleRelation> 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<ModuleRelation> 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<ModuleRelation, Lo
return this.list(ModuleRelation.class, sql, params);
}
public List<ModuleRelation> 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<String, Object> params = MapTools.simpleMap("relationCategoryId", relationCategoryId);
params.put("moduleId", moduleId);
return this.list(ModuleRelation.class, sql, params);
}
}

View File

@ -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<CiModule, Long> {
return this.list(CiModule.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<CiModule> 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<Param> 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<Param> 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<String, Object> params = MapTools.simpleMap(Common.ID, id);
@ -55,6 +78,19 @@ public class ModuleRepository extends BasicGenericDao<CiModule, Long> {
return this.list(CiModule.class, sql, null);
}
public List<CiModule> 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<CiModule> 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<CiModule, Long> {
return this.list(CiModule.class, sql, null);
}
public List<CiModule> 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<CiModule> all() throws Exception {
String sql = "select * from ci_module where is_deleted=0 ";
return this.list(CiModule.class, sql, null);
}
public List<CiModule> 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<CiModule> 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<CiModule, Long> {
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<CiModule> 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<CiModule, Long> {
return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids));
}
public List<CiModule> listByIds(List<Long> 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<CiModule, Long> {
return this.list(CiModule.class, sql, MapTools.simpleMap("ids", ids));
}
public List<CiModule> queryModuleListByIds(List<Long> 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<CiModule> list = this.list(CiModule.class, sql, MapTools.simpleMap("code", code));

View File

@ -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<PropertyGroup, Long
return this.list(PropertyGroup.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<PropertyGroup> 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));
}
}

View File

@ -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<PropertyItem, Long>
return this.list(PropertyItem.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<PropertyItem> 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<PropertyItem> 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<PropertyItem> 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<PropertyItem> queryByModuleIdAndPropertyIds(Long moduleId, List<Long> 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<String, Object> paramMap = MapTools.simpleMap("propertyIds", propertyIds);

View File

@ -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<PropertyPoolItem
return this.list(PropertyPoolItem.class, sql, MapTools.simpleMap("propertyPoolId", propertyPoolId));
}
public List<PropertyPoolItem> 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<PropertyPoolItem> listByPropertyPoolIds(List<Long> 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));

View File

@ -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<PropertyPool, Long>
return this.list(PropertyPool.class, sql, getQueryBuilder().getParam(pager.getParams()));
}
public List<PropertyPool> 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<Param> 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<Param> 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<PropertyPool> 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<PropertyPool> 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<PropertyPool> list = this.list(PropertyPool.class, sql, MapTools.simpleMap("code", code));

View File

@ -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<Property, Long> {
return this.list(Property.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<Property> 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<Property> 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<Property> 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<String, Object> params = MapTools.simpleMap("moduleId", moduleId);
@ -72,6 +96,19 @@ public class PropertyRepository extends BasicGenericDao<Property, Long> {
return this.list(Property.class, sql, paramMap);
}
public List<Property> 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<String, Object> paramMap = getQueryBuilder().getParam(pager.getParams());
paramMap.put("moduleId", moduleId);
return this.list(Property.class, sql, paramMap);
}
public int count(final List<Param> 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<Property, Long> {
return this.countQuery(sql, param).intValue();
}
public int count(final List<Param> 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<String, Object> param = getQueryBuilder().getParam(params);
param.put("moduleId", moduleId);
return this.countQuery(sql, param).intValue();
}
public List<Property> 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";

View File

@ -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<RegularExpressi
return list.isEmpty() ? null : list.get(0);
}
public RegularExpression query(Long id, String positionKey) {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select * from "+positionKey+".ci_regular_expression a where a.id = :id and is_deleted = 0";
} else {
sql = "select * from ci_regular_expression a where a.id = :id and is_deleted = 0";
}
List<RegularExpression> list = this.list(RegularExpression.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public List<RegularExpression> listAll() throws Exception {
String sql = "select * from ci_regular_expression where is_deleted = 0";
return this.list(RegularExpression.class, sql, new HashMap<String, Object>(10));
}
public List<RegularExpression> 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<String, Object>(10));
}
}

View File

@ -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<RelationCategory
return list.isEmpty() ? null : list.get(0);
}
public RelationCategory query(Long id, String positionKey) throws Exception {
String sql;
if (StringUtils.isNotEmpty(positionKey)) {
sql = "select a.* from " + positionKey + ".ci_relation_category a where a.id = :id and is_deleted=0 ";
} else {
sql = "select a.* from ci_relation_category a where a.id = :id and is_deleted=0 ";
}
List<RelationCategory> list = this.list(RelationCategory.class, sql, MapTools.simpleMap(Common.ID, id));
return list.isEmpty() ? null : list.get(0);
}
public List<RelationCategory> 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<RelationCategory
return this.list(RelationCategory.class, sql, MapTools.simpleMap("moduleId", moduleId));
}
public List<RelationCategory> 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 ";

View File

@ -14,17 +14,17 @@ import java.util.List;
* @Description:
*/
public interface AutoRelationRuleService {
GeneralResult<GridBean<AutoRelationRule>> list(Pager pager);
GeneralResult<GridBean<AutoRelationRule>> list(Pager pager, String positionKey);
GeneralResult<Void> save(AutoRelationRule rule, Long target);
GeneralResult<Void> modify(Long id, AutoRelationRule rule, Long target);
GeneralResult<AutoRelationRule> detail(Long id);
GeneralResult<AutoRelationRule> detail(Long id, String positionKey);
GeneralResult<Void> remove(Long id, Long target);
GeneralResult<AutoRelationRuleItem> itemDetail(Long itemId);
GeneralResult<AutoRelationRuleItem> itemDetail(Long itemId, String positionKey);
GeneralResult<List<AutoRelationRule>> list(Long moduleId, Long relationCategoryId);
}

View File

@ -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<String, String> redisTemplate;
@Override
public GeneralResult<GridBean<AutoRelationRule>> list(Pager pager) {
public GeneralResult<GridBean<AutoRelationRule>> 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<SimpleBean> beans = this.autoRelationRuleRepository.list(pager.getParams(), pager.getSorter());
List<SimpleBean> beans = this.autoRelationRuleRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<AutoRelationRule> list = this.autoRelationRuleRepository.list(pager);
List<AutoRelationRule> list = this.autoRelationRuleRepository.list(pager, positionKey);
for (AutoRelationRule rule : list) {
rule.setCreator(redisTemplate.opsForValue().get("User_Name_" + rule.getCreatorId()));
List<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(rule.getId());
List<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(rule.getId(), positionKey);
for (AutoRelationRuleItem item : items) {
List<AutoRelationRuleItemValue> 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<AutoRelationRule> detail(Long id) {
public GeneralResult<AutoRelationRule> 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<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(id);
List<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(id, positionKey);
for (AutoRelationRuleItem item : items) {
List<AutoRelationRuleItemValue> 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<AutoRelationRuleItem> itemDetail(Long itemId) {
public GeneralResult<AutoRelationRuleItem> 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<AutoRelationRuleItemValue> itemValues = autoRelationRuleItemValueRepository.queryByItemId(itemId);
List<AutoRelationRuleItemValue> itemValues = autoRelationRuleItemValueRepository.queryByItemId(itemId, positionKey);
ruleItem.setValues(itemValues);
return new GeneralResult<>(true, ruleItem, "查询成功");
} catch (Exception e) {

View File

@ -16,9 +16,9 @@ import java.util.Map;
*/
public interface OperationalAuditService {
GeneralResult<GridBean<OperationalAudit>> list(Pager pager);
GeneralResult<GridBean<OperationalAudit>> list(Pager pager, String positionKey);
GeneralResult<OperationalAudit> deatil(Long id);
GeneralResult<OperationalAudit> detail(Long id, String positionKey);
/**
*
@ -36,6 +36,6 @@ public interface OperationalAuditService {
Map<String, Object> beforeMap,
Map<String, Object> afterMap);
GeneralResult<GridBean<OperationalAuditBak>> bakList(Pager pager);
GeneralResult<GridBean<OperationalAuditBak>> bakList(Pager pager, String positionKey);
}

View File

@ -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<GridBean<OperationalAudit>> list(Pager pager) {
public GeneralResult<GridBean<OperationalAudit>> 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<Param> params = pager.getParams();
int total = operationalAuditRepository.count(params);
List<OperationalAudit> audits = operationalAuditRepository.list(pager);
int total = operationalAuditRepository.count(params, positionKey);
List<OperationalAudit> 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<OperationalAudit> deatil(Long id) {
public GeneralResult<OperationalAudit> 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<GridBean<OperationalAuditBak>> bakList(Pager pager) {
public GeneralResult<GridBean<OperationalAuditBak>> 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<OperationalAuditBak> list = new ArrayList<>();
//根据模板表查询出所有日志表 然后 使用并行流查询包含参数日期的库表
List<TableLog> tableLogs = tableLogRepository.query(CmdbUtils.CMDB_OPERATIONAL_AUDIT_BAK);
List<TableLog> tableLogs = tableLogRepository.query(CmdbUtils.CMDB_OPERATIONAL_AUDIT_BAK, positionKey);
String finalTimeGet = startTime;
String finalTimeLet = endTime;
//获取到数据中包含所查询的日期的历史备份表
List<String> 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()));
}

View File

@ -15,7 +15,7 @@ import com.megatron.common.model.Pager;
**/
public interface CollectionHistoryItemService {
GeneralResult<GridBean<CollectionHistoryItem>> list(Pager pager);
GeneralResult<GridBean<CollectionHistoryItem>> list(Pager pager, String positionKey);
GeneralResult<GridBean<CollectionHistoryItem>> backupHistoryItems(Pager pager);
GeneralResult<GridBean<CollectionHistoryItem>> backupHistoryItems(Pager pager, String positionKey);
}

View File

@ -18,9 +18,9 @@ import java.util.Map;
**/
public interface CollectionHistoryService {
GeneralResult<GridBean<Map<String, Object>>> instances(Pager pager, Long userId);
GeneralResult<GridBean<Map<String, Object>>> instances(Pager pager, Long userId, String positionKey);
GeneralResult<GridBean<CollectionHistory>> list(Pager pager);
GeneralResult<GridBean<CollectionHistory>> list(Pager pager, String positionKey);
GeneralResult<Void> create(CollectionHistory history);
@ -32,8 +32,8 @@ public interface CollectionHistoryService {
GeneralResult<String> batchModify(CollectionHistoryModel historyModel, Long userId);
GeneralResult<GridBean<CollectionHistory>> backupHistory(Pager pager);
GeneralResult<GridBean<CollectionHistory>> backupHistory(Pager pager, String positionKey);
GeneralResult<GridBean<Map<String, Object>>> backupList(Pager pager, Long userId);
GeneralResult<GridBean<Map<String, Object>>> backupList(Pager pager, Long userId, String positionKey);
}

View File

@ -19,11 +19,11 @@ public interface CollectionTaskInstanceService {
GeneralResult<CollectionTaskInstance> queryByTaskId(String taskId);
GeneralResult<GridBean<CollectionTaskInstance>> list(Pager pager);
GeneralResult<GridBean<CollectionTaskInstance>> list(Pager pager, String positionKey);
GeneralResult<GridBean<CollectionTaskInstance>> bakList(Pager pager);
GeneralResult<GridBean<CollectionTaskInstance>> bakList(Pager pager, String positionKey);
GeneralResult<CollectionTaskInstance> detail(Long id);
GeneralResult<CollectionTaskInstance> detail(Long id, String positionKey);
GeneralResult<CollectionTaskInstance> bakDetail(Long id,String name);
GeneralResult<CollectionTaskInstance> bakDetail(Long id,String name, String positionKey);
}

View File

@ -21,7 +21,7 @@ public interface CollectionTaskService {
GeneralResult<CollectionTask> isValid(String expression);
GeneralResult<GridBean<CollectionTask>> list(Pager pager);
GeneralResult<GridBean<CollectionTask>> list(Pager pager, String positionKey);
GeneralResult<CollectionTask> save(CollectionTask task, RequestContext context);
@ -29,7 +29,7 @@ public interface CollectionTaskService {
GeneralResult<CollectionTask> modifyType(Long id, RequestContext context);
GeneralResult<CollectionTask> detail(Long id);
GeneralResult<CollectionTask> detail(Long id, String positionKey);
GeneralResult<Void> remove(Long id, Long target);

View File

@ -13,15 +13,15 @@ import com.megatron.common.model.Pager;
*/
public interface CollectionTemplateService {
GeneralResult<GridBean<CollectionComponent>> components(Pager pager);
GeneralResult<GridBean<CollectionComponent>> components(Pager pager, String positionKey);
GeneralResult<GridBean<CollectionTemplate>> list(Pager pager);
GeneralResult<GridBean<CollectionTemplate>> list(Pager pager, String positionKey);
GeneralResult<CollectionTemplate> save(CollectionTemplate template, Long target);
GeneralResult<CollectionTemplate> modify(CollectionTemplate template, Long target);
GeneralResult<CollectionTemplate> detail(Long id);
GeneralResult<CollectionTemplate> detail(Long id, String positionKey);
GeneralResult<Void> remove(Long id, Long target);

View File

@ -26,13 +26,13 @@ public class CollectionHistoryItemServiceImpl implements CollectionHistoryItemSe
private CollectionHistoryItemRepository historyItemRepository;
@Override
public GeneralResult<GridBean<CollectionHistoryItem>> list(Pager pager) {
public GeneralResult<GridBean<CollectionHistoryItem>> 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<CollectionHistoryItem> list = this.historyItemRepository.list(pager);
int total = this.historyItemRepository.count(pager.getParams(), positionKey);
List<CollectionHistoryItem> list = this.historyItemRepository.list(pager, positionKey);
GridBean<CollectionHistoryItem> 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<GridBean<CollectionHistoryItem>> backupHistoryItems(Pager pager) {
public GeneralResult<GridBean<CollectionHistoryItem>> 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<CollectionHistoryItem> list = this.historyItemRepository.list(tableName,pager);
GridBean<CollectionHistoryItem> gridBean = GridHelper.getBean(pager.getPage(), pager.getRows(), total, list);
return new GeneralResult<>(true, gridBean, "查询成功");

View File

@ -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<GridBean<Map<String, Object>>> instances(Pager pager, Long userId) {
public GeneralResult<GridBean<Map<String, Object>>> 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<CollectionHistory> historyList = historyRepository.queryByIdAndType(taskInstanceId, historyType);
List<CollectionHistory> historyList = historyRepository.queryByIdAndType(taskInstanceId, historyType, positionKey);
List<Long> 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<Map<String, Object>> bean = new GridBean<>(pager.getPage(), pager.getRows(), total, list);
@ -158,13 +156,13 @@ public class CollectionHistoryServiceImpl implements CollectionHistoryService {
}
@Override
public GeneralResult<GridBean<CollectionHistory>> list(Pager pager) {
public GeneralResult<GridBean<CollectionHistory>> 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<CollectionHistory> list = this.historyRepository.list(pager);
int total = this.historyRepository.count(pager.getParams(), positionKey);
List<CollectionHistory> list = this.historyRepository.list(pager, positionKey);
GridBean<CollectionHistory> 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<GridBean<CollectionHistory>> backupHistory(Pager pager) {
public GeneralResult<GridBean<CollectionHistory>> 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<CollectionHistory> list = this.historyRepository.list(tableName,pager);
int total = this.historyRepository.count(tableName,pager.getParams(), positionKey);
List<CollectionHistory> 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<GridBean<Map<String, Object>>> backupList(Pager pager, Long userId) {
public GeneralResult<GridBean<Map<String, Object>>> 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<CollectionHistory> historyList = historyRepository.queryByIdAndType(tableName,taskInstanceId, historyType);
List<CollectionHistory> historyList = historyRepository.queryByIdAndType(tableName,taskInstanceId, historyType, positionKey);
List<Long> historyIds = historyList.stream().map(history -> history.getInstanceId()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(historyIds)) {
HashMap<String, Object> 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<String, Object> 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<Map<String, Object>> bean = new GridBean<>(pager.getPage(), pager.getRows(), total, list);

View File

@ -117,20 +117,25 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance
}
@Override
public GeneralResult<GridBean<CollectionTaskInstance>> list(Pager pager) {
public GeneralResult<GridBean<CollectionTaskInstance>> 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<SimpleBean> 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<CollectionTaskInstance> 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<GridBean<CollectionTaskInstance>> bakList(Pager pager) {
public GeneralResult<GridBean<CollectionTaskInstance>> 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<TableLog> tableLogs = tableLogRepository.query("ci_collection_task_instance_bak");
List<TableLog> tableLogs = tableLogRepository.query("ci_collection_task_instance_bak", positionKey);
List<String> 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<String> tableList = tableNames.parallelStream().filter(item -> {
List<CollectionTaskInstance> 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<Integer> 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<CollectionTaskInstance> 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<Param>(), 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<CollectionTaskInstance> detail(Long id) {
public GeneralResult<CollectionTaskInstance> 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<Object> successes = Lists.newArrayList();
List<Object> failures = Lists.newArrayList();
@ -302,9 +313,9 @@ public class CollectionTaskInstanceServiceImpl implements CollectionTaskInstance
}
@Override
public GeneralResult<CollectionTaskInstance> bakDetail(Long id, String name) {
public GeneralResult<CollectionTaskInstance> 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<Object> successes = Lists.newArrayList();
List<Object> failures = Lists.newArrayList();

View File

@ -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<GridBean<CollectionTask>> list(Pager pager) {
public GeneralResult<GridBean<CollectionTask>> 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<SimpleBean> beans = this.collectionTaskRepository.list(pager.getParams(), pager.getSorter());
List<SimpleBean> beans = this.collectionTaskRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<CollectionTask> list = this.collectionTaskRepository.list(pager.getPage(), pager.getRows(),
pager.getParams(), pager.getSorter());
List<CollectionTask> 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<CollectionTask> detail(Long id) {
public GeneralResult<CollectionTask> 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()) {

View File

@ -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<GridBean<CollectionComponent>> components(Pager pager) {
public GeneralResult<GridBean<CollectionComponent>> 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<SimpleBean> beans = this.collectionComponentRepository.list(pager.getParams(), pager.getSorter());
List<SimpleBean> beans = this.collectionComponentRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<CollectionComponent> list = this.collectionComponentRepository.list(pager.getPage(),
@ -79,24 +77,23 @@ public class CollectionTemplateServiceImpl implements CollectionTemplateService
}
@Override
public GeneralResult<GridBean<CollectionTemplate>> list(Pager pager) {
public GeneralResult<GridBean<CollectionTemplate>> 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<SimpleBean> beans = this.collectionTemplateRepository.list(pager.getParams(), pager.getSorter());
List<SimpleBean> beans = this.collectionTemplateRepository.list(pager.getParams(), pager.getSorter(), positionKey);
gridBean = new GridBean<>(1, 1, total, beans);
} else {
List<CollectionTemplate> list = this.collectionTemplateRepository.list(pager.getPage(), pager.getRows(),
pager.getParams(), pager.getSorter());
List<CollectionTemplate> 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<CollectionComponent> 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<CollectionTemplate> detail(Long id) {
public GeneralResult<CollectionTemplate> 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<CollectionComponent> components = collectionComponentRepository.queryByTemplateId(id);

View File

@ -29,8 +29,8 @@ public interface CmdbConfigService {
*/
Result batchUpdate(List<CmdbConfig> list, RequestContext context);
GeneralResult<Map<String, String>> listConfigs(String category, List<String> codes);
GeneralResult<Map<String, String>> listConfigs(String category, List<String> codes, String positionKey);
GeneralResult<JSONArray> listCategoryTree(String category);
GeneralResult<JSONArray> listCategoryTree(String category, String positionKey);
}

View File

@ -105,13 +105,13 @@ public class CmdbConfigServiceImpl implements CmdbConfigService {
}
@Override
public GeneralResult<Map<String, String>> listConfigs(String category, List<String> codes) {
public GeneralResult<Map<String, String>> listConfigs(String category, List<String> codes, String positionKey) {
try {
List<CmdbConfig> 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<String, CmdbConfig> configMap =
configs.stream().collect(Collectors.toMap(CmdbConfig::getCode, Function.identity()));
@ -128,9 +128,9 @@ public class CmdbConfigServiceImpl implements CmdbConfigService {
}
@Override
public GeneralResult<JSONArray> listCategoryTree(String category) {
public GeneralResult<JSONArray> listCategoryTree(String category, String positionKey) {
try {
List<CmdbConfig> configs = cmdbConfigRepository.listByCategory(category);
List<CmdbConfig> configs = cmdbConfigRepository.listByCategory(category, positionKey);
Map<String, List<CmdbConfig>> configMap =
configs.stream().collect(Collectors.groupingBy(CmdbConfig::getSubclass));
JSONArray jsonArray = new JSONArray();

View File

@ -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<Void> create(InstanceAuthority authority, Long userId);

View File

@ -14,7 +14,7 @@ import com.megatron.common.model.Pager;
public interface InstanceHistoryService {
GeneralResult list(Pager pager);
GeneralResult list(Pager pager, String positionKey);
GeneralResult<Void> create(InstanceHistory history, Long userId);

View File

@ -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);

View File

@ -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<Void> 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<Void> batchModify(InstanceBean instanceModel, Long userId);
GeneralResult<Instance> detail(Long id, String moduleCode);
GeneralResult<Instance> 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<InstanceTopo> topo(Long id, Long relationCategoryId, Long moduleId, Long userId);
GeneralResult<InstanceTopo> topo(Long id, Long relationCategoryId, Long moduleId, Long userId, String positionKey);
boolean checkAdminRole(Long userId);
void convertInstanceValue(List<Map<String, Object>> list, Long moduleId, Long userId, boolean hasAdminRole) throws Exception;
void convertInstanceValue(List<Map<String, Object>> list, Long moduleId, Long userId, boolean hasAdminRole, String positionKey) throws Exception;
}

View File

@ -46,13 +46,13 @@ public class InstanceAuthorityServiceImpl implements InstanceAuthorityService {
private RedisTemplate<String, String> 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<InstanceAuthority> list = this.instanceAuthorityRepository.list(pager);
int total = this.instanceAuthorityRepository.count(pager.getParams(), positionKey);
List<InstanceAuthority> list = this.instanceAuthorityRepository.list(pager, positionKey);
for (InstanceAuthority authority : list) {
String roleName = redisTemplate.opsForValue().get("Role_Name_" + authority.getRoleId());
if (StringUtils.isEmpty(authority.getAuths())) {

View File

@ -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<InstanceHistory> list = this.instanceHistoryRepository.list(pager);
int total = this.instanceHistoryRepository.count(pager.getParams(), positionKey);
List<InstanceHistory> list = this.instanceHistoryRepository.list(pager, positionKey);
for (InstanceHistory history : list) {
if (InstanceEnum.catalog.INSTANCE.name().equals(history.getCatalog())) {
history.setCatalog(InstanceEnum.catalog.INSTANCE.getValue());

View File

@ -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<InstanceRelationHistoryRecord> list = this.instanceRelationHistoryRecordRepository.list(pager);
int total = instanceRelationHistoryRecordRepository.count(pager.getParams(), positionKey);
List<InstanceRelationHistoryRecord> list = this.instanceRelationHistoryRecordRepository.list(pager, positionKey);
if (CollectionUtils.isNotEmpty(list)) {
list.forEach(template -> {
template

View File

@ -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<Map<String, Object>> 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<Map<String, Object>> 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<Instance> detail(Long id, String moduleCode) {
public GeneralResult<Instance> 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<InstanceValue> values = instanceValueRepository.listByInstanceId(id, valueTable);
Instance instance = instanceRepository.query(table, id, positionKey);
List<InstanceValue> 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<Map<String, Object>> instances =
instanceRepository.listAll(table, valueTable, module.getId(), null, userId, hasAdminRole);
instanceRepository.listAll(table, valueTable, module.getId(), null, userId, hasAdminRole, positionKey);
List<Property> 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<Map<String, Object>> list, Long moduleId, Long userId, boolean hasAdminRole)
public void convertInstanceValue(List<Map<String, Object>> list, Long moduleId, Long userId, boolean hasAdminRole, String positionKey)
throws Exception {
if (ListTool.isEmpty(list)) {
return;
}
List<Property> properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId);
List<Property> properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId, positionKey);
Map<String, Property> 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<InstanceAuthority> 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<Property> properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId);
List<PropertyItem> 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<InstanceTopo> topo(Long id, Long relationCategoryId, Long moduleId, Long userId) {
public GeneralResult<InstanceTopo> 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<ModuleRelation> 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<InstanceRelation> instanceRelations = new ArrayList<>();
List<InstanceRelation> sourceInstanceRelations =
instanceRelationRepository.querySources(instanceRelationTable, moduleId, id);
instanceRelationRepository.querySources(instanceRelationTable, moduleId, id, positionKey);
List<InstanceRelation> 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();

View File

@ -13,23 +13,23 @@ import java.util.List;
*/
public interface ModuleGroupService {
GeneralResult<List<ModuleGroup>> collections(String category, String moduleName);
GeneralResult<List<ModuleGroup>> collections(String category, String moduleName, String positionKey);
GeneralResult<List<ModuleGroup>> queryRoot();
GeneralResult<List<ModuleGroup>> queryRoot(String positionKey);
GeneralResult<List<ModuleGroup>> queryRootChildren();
GeneralResult<List<ModuleGroup>> queryRootChildren(String positionKey);
GeneralResult<Void> save(ModuleGroup group, Long target);
GeneralResult<ModuleGroup> detail(Long id);
GeneralResult<ModuleGroup> detail(Long id, String positionKey);
GeneralResult<Void> modify(ModuleGroup group, Long target);
GeneralResult<ModuleGroup> queryChildren(Long groupId, String menu, RequestContext context);
GeneralResult<ModuleGroup> queryChildren(Long groupId, String menu, RequestContext context, String positionKey);
GeneralResult<Void> remove(Long id, Long userId);
GeneralResult<List<ModuleGroup>> querylist();
GeneralResult<List<ModuleGroup>> querylist(String positionKey);
GeneralResult<List<ModuleGroup>> queryRootChildren(Long groupId, String menu, RequestContext context);
GeneralResult<List<ModuleGroup>> queryRootChildren(Long groupId, String menu, RequestContext context, String positionKey);
}

View File

@ -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<ModuleTopo> list(Long moduleId, Long relationCategoryId);
GeneralResult<ModuleTopo> list(Long moduleId, Long relationCategoryId, String positionKey);
/**
*
*
* @param relationCategoryId id
*/
GeneralResult<ModuleTopo> listByCategoryId(Long relationCategoryId);
GeneralResult<ModuleTopo> listByCategoryId(Long relationCategoryId, String positionKey);
/**
* @param relationCategoryId
@ -56,7 +56,7 @@ public interface ModuleRelationService {
* @param targetId
* @Description:
*/
GeneralResult<ModuleRelation> relevancy(Long relationCategoryId, Long sourceId, Long targetId);
GeneralResult<ModuleRelation> relevancy(Long relationCategoryId, Long sourceId, Long targetId, String positionKey);
/**
* id
@ -64,7 +64,7 @@ public interface ModuleRelationService {
* @param relationCategoryId
* @return
*/
GeneralResult<List<CiModule>> moduleList(Long relationCategoryId);
GeneralResult<List<CiModule>> 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);
}

View File

@ -18,11 +18,11 @@ import java.util.List;
*/
public interface ModuleService {
GeneralResult<GridBean<CiModule>> getModelList(Pager pager);
GeneralResult<GridBean<CiModule>> getModelList(Pager pager, String positionKey);
GeneralResult<List<CiModule>> list();
GeneralResult<List<CiModule>> list( String positionKey);
GeneralResult<CiModule> detail(Long id);
GeneralResult<CiModule> detail(Long id, String positionKey);
GeneralResult<Void> save(CiModule module, Long target);
@ -30,11 +30,11 @@ public interface ModuleService {
GeneralResult<Void> modify(CiModule module, Long target);
GeneralResult<PropertyModel> property(Long id);
GeneralResult<PropertyModel> property(Long id, String positionKey);
GeneralResult<GridBean<Property>> propertyList(Long moduleId, Pager pager);
GeneralResult<GridBean<Property>> propertyList(Long moduleId, Pager pager, String positionKey);
GeneralResult<Void> modifyProperty(PropertyModel model, Long id, RequestContext context);
GeneralResult statistics(RequestContext context);
GeneralResult statistics(RequestContext context, String positionKey);
}

View File

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

View File

@ -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<Property> detail(Long id);
GeneralResult<Property> detail(Long id, String positionKey);
void propertyHandle(final Property property, final List<PropertyItem> items) throws Exception;
void propertyHandle(final Property property, final List<PropertyItem> items, String positionKey) throws Exception;
}

View File

@ -19,5 +19,5 @@ public interface RegularExpressionService {
*
* @return
*/
GeneralResult<List<RegularExpression>> list(String type);
GeneralResult<List<RegularExpression>> list(String type, String positionKey);
}

View File

@ -59,6 +59,6 @@ public interface RelationCategoryService {
*/
GeneralResult<List<ModuleRelation>> moduleRelationList(Long id, Long moduleId);
GeneralResult listByModuleId(Long moduleId);
GeneralResult listByModuleId(Long moduleId, String positionKey);
}

View File

@ -58,10 +58,10 @@ public class ModuleGroupServiceImpl implements ModuleGroupService {
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Override
public GeneralResult<List<ModuleGroup>> collections(String category, String moduleName) {
public GeneralResult<List<ModuleGroup>> collections(String category, String moduleName, String positionKey) {
try {
// 获取模型分组所有数据
List<ModuleGroup> groups = moduleGroupRepository.all();
List<ModuleGroup> 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<CiModule> template = moduleRepository.existCollectionTemplate(moduleName);
List<CiModule> template = moduleRepository.existCollectionTemplate(moduleName, positionKey);
Map<Long, List<CiModule>> moduleMap =
template.stream().collect(Collectors.groupingBy(CiModule::getGroupId));
this.getTree(parents, groupMap, moduleMap);
} else if ("task".equalsIgnoreCase(category)) {
// 查询模型下存在采集任务的模型
List<CiModule> task = moduleRepository.existCollectionTask(moduleName);
List<CiModule> task = moduleRepository.existCollectionTask(moduleName, positionKey);
Map<Long, List<CiModule>> 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<List<ModuleGroup>> queryRoot() {
public GeneralResult<List<ModuleGroup>> queryRoot(String positionKey) {
try {
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot();
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot(positionKey);
if (CollectionUtils.isEmpty(rootGroups)) {
return new GeneralResult<>(true, rootGroups, "查询成功");
}
List<Long> rootGroupIds = rootGroups.stream().map(ModuleGroup::getId).collect(Collectors.toList());
// 获取模型分组所有数据
List<ModuleGroup> moduleGroups = moduleGroupRepository.all();
List<ModuleGroup> moduleGroups = moduleGroupRepository.all(positionKey);
// 获取根节点的子节点集合
List<ModuleGroup> children = moduleGroups.stream().filter(item -> rootGroupIds.contains(item.getParentId()))
.collect(Collectors.toList());
// 获取模型所有数据
List<CiModule> modules = moduleRepository.all();
List<CiModule> modules = moduleRepository.all(positionKey);
// 对模型根据groupId进行分组
Map<Long, List<CiModule>> 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<List<ModuleGroup>> queryRootChildren() {
public GeneralResult<List<ModuleGroup>> queryRootChildren(String positionKey) {
try {
// 获取模型分组所有数据
List<ModuleGroup> groups = moduleGroupRepository.all();
List<ModuleGroup> groups = moduleGroupRepository.all(positionKey);
List<ModuleGroup> 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<ModuleGroup> detail(Long id) {
public GeneralResult<ModuleGroup> 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<ModuleGroup> queryChildren(Long groupId, String menu, RequestContext context) {
public GeneralResult<ModuleGroup> queryChildren(Long groupId, String menu, RequestContext context, String positionKey) {
try {
// 获取模型分组所有数据
List<ModuleGroup> groups = moduleGroupRepository.all();
List<ModuleGroup> 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<Long, List<ModuleGroup>> groupMap =
groups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId));
// 获取模型所有数据
List<CiModule> modules = moduleRepository.all();
List<CiModule> 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<List<ModuleGroup>> querylist() {
public GeneralResult<List<ModuleGroup>> querylist(String positionKey) {
try {
// 获取根数据
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot();
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot(positionKey);
if (CollectionUtils.isEmpty(rootGroups)) {
return new GeneralResult<>(true, rootGroups, "查询成功");
}
// 获取模型分组所有数据
List<ModuleGroup> moduleGroups = moduleGroupRepository.all();
List<ModuleGroup> moduleGroups = moduleGroupRepository.all(positionKey);
// 对模型分组根据parentId进行分组
Map<Long, List<ModuleGroup>> groupMap =
moduleGroups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId));
List<CiModule> modules = moduleRepository.all();
List<CiModule> modules = moduleRepository.all(positionKey);
Map<Long, List<CiModule>> 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<List<ModuleGroup>> queryRootChildren(Long groupId , String menu, RequestContext context) {
public GeneralResult<List<ModuleGroup>> queryRootChildren(Long groupId , String menu, RequestContext context, String positionKey) {
try {
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot();
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRoot(positionKey);
if (CollectionUtils.isEmpty(rootGroups)) {
return new GeneralResult<>(true, rootGroups, "查询成功");
}
// 获取模型分组所有数据
List<ModuleGroup> groups = moduleGroupRepository.all();
List<ModuleGroup> groups = moduleGroupRepository.all(positionKey);
// 获取模型所有数据
List<CiModule> modules = moduleRepository.all();
List<CiModule> modules = moduleRepository.all(positionKey);
// 对模型根据groupId进行分组
Map<Long, List<CiModule>> moduleMap = modules.stream().filter(item -> null != item.getGroupId())
.collect(Collectors.groupingBy(CiModule::getGroupId));

View File

@ -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<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(rule.getId());
List<AutoRelationRuleItem> 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<ModuleTopo> list(Long moduleId, Long relationCategoryId) {
public GeneralResult<ModuleTopo> 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<ModuleRelation> relations = moduleRelationRepository.list(moduleId, relationCategoryId);
List<ModuleRelation> relations = moduleRelationRepository.list(moduleId, relationCategoryId, positionKey);
// 反向关系isReverse
List<ModuleRelation> reverseRelations = moduleRelationRepository.listReverse(moduleId, relationCategoryId);
List<ModuleRelation> reverseRelations = moduleRelationRepository.listReverse(moduleId, relationCategoryId, positionKey);
relations.addAll(reverseRelations);
// 所有模型ids
Set<Long> moduleSet = new HashSet<>();
@ -373,7 +362,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService {
if (moduleSet.size() > 0) {
List<Long> 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<ModuleTopo> listByCategoryId(Long relationCategoryId) {
public GeneralResult<ModuleTopo> 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<ModuleRelation> relations = moduleRelationRepository.listByCategoryId(relationCategoryId);
List<ModuleRelation> relations = moduleRelationRepository.listByCategoryId(relationCategoryId, positionKey);
// 所有模型ids
Set<Long> moduleSet = new HashSet<>();
List<ModuleLink> links = new ArrayList<>();
@ -416,7 +405,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService {
if (moduleSet.size() > 0) {
List<Long> 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<ModuleRelation> relevancy(Long relationCategoryId, Long sourceId, Long targetId) {
public GeneralResult<ModuleRelation> 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<AutoRelationRuleItem> items = autoRelationRuleItemRepository.queryByRuleId(rule.getId());
List<AutoRelationRuleItem> 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<List<CiModule>> moduleList(Long relationCategoryId) {
public GeneralResult<List<CiModule>> moduleList(Long relationCategoryId, String positionKey) {
try {
List<ModuleRelation> relations = moduleRelationRepository.queryModuleList(relationCategoryId);
List<ModuleRelation> relations = moduleRelationRepository.queryModuleList(relationCategoryId, positionKey);
if (CollectionUtils.isEmpty(relations)) {
return new GeneralResult<>(true, new ArrayList<CiModule>(), "查询成功");
}
@ -477,7 +466,7 @@ public class ModuleRelationServiceImpl implements ModuleRelationService {
List<Long> moduleIds = Stream.of(sourceIds, targetIds).flatMap(Collection::stream).filter(Objects::nonNull)
.distinct().collect(Collectors.toList());
// 获取模型集合
List<CiModule> modules = moduleRepository.queryModuleListByIds(moduleIds);
List<CiModule> 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<InstanceRelation> relations = null;
Map<Long, InstanceRelation> 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<Map<String, Object>> 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<String, Object> instance : list) {
// 判断被关联的模型实例是否已关联
InstanceRelation existRelation = relationMap.get(instance.get("id"));

View File

@ -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<GridBean<CiModule>> getModelList(Pager pager) {
public GeneralResult<GridBean<CiModule>> 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<ModuleGroup> groups = moduleGroupRepository.all();
List<ModuleGroup> groups = new ArrayList<>();
if (StringUtils.isEmpty(positionKey)) {
groups = moduleGroupRepository.all();
} else {
groups = moduleGroupRepository.all(positionKey);
}
Map<Long, List<ModuleGroup>> groupMap =
groups.stream().collect(Collectors.groupingBy(ModuleGroup::getParentId));
List<Long> groupIds = new ArrayList<>();
@ -159,11 +160,11 @@ public class ModuleServiceImpl implements ModuleService {
params.add(newParam);
}
}
int total = moduleRepository.count(pager.getParams());
List<CiModule> modules = this.moduleRepository.list(pager);
int total = moduleRepository.count(pager.getParams(), positionKey);
List<CiModule> modules = this.moduleRepository.list(pager, positionKey);
if (CollectionUtils.isNotEmpty(modules)) {
List<Long> groupIds = modules.stream().map(CiModule::getGroupId).collect(Collectors.toList());
List<ModuleGroup> groups = moduleGroupRepository.queryByIds(groupIds);
List<ModuleGroup> 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<CiModule>> list() {
public GeneralResult<List<CiModule>> list( String positionKey) {
try {
List<CiModule> modules = moduleRepository.all();
List<CiModule> modules = moduleRepository.all(positionKey);
List<CiModule> 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<CiModule> detail(Long id) {
public GeneralResult<CiModule> 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<PropertyModel> property(Long moduleId) {
public GeneralResult<PropertyModel> property(Long moduleId, String positionKey) {
try {
List<PropertyGroup> groups = propertyGroupRepository.listByModuleId(moduleId);
List<Property> properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId);
List<PropertyItem> items = propertyItemRepository.queryByModuleId(moduleId);
List<PropertyGroup> groups = propertyGroupRepository.listByModuleId(moduleId, positionKey);
List<Property> properties = propertyRepository.listNotHiddenByCmdbModuleId(moduleId, positionKey);
List<PropertyItem> 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<GridBean<Property>> propertyList(Long moduleId, Pager pager) {
public GeneralResult<GridBean<Property>> 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<Property> properties = propertyRepository.list(pager, moduleId);
int total = propertyRepository.count(pager.getParams(), moduleId, positionKey);
List<Property> 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<String> nameList = Arrays.asList("网络设备", "物理服务器", "安全设备");
//查询根节点
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRootInName(nameList);
List<ModuleGroup> rootGroups = moduleGroupRepository.queryRootInName(nameList, positionKey);
Map<String, Object> 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<String, Object> resultMap, Long userId) throws Exception {
private void getInstaceCount(ModuleGroup rootGroup, Map<String, Object> resultMap, Long userId, String positionKey) throws Exception {
//获取当前ModuleGroup下所有的modle
Pager pager = new Pager();
List<Param> modelParamList = new ArrayList<>();
@ -478,7 +479,7 @@ public class ModuleServiceImpl implements ModuleService {
pager.setRows(Integer.MAX_VALUE);
modelParamList.add(modelParam);
pager.setParams(modelParamList);
GeneralResult<GridBean<CiModule>> modelList = getModelList(pager);
GeneralResult<GridBean<CiModule>> modelList = getModelList(pager, positionKey);
if (modelList.isFailed()) {
log.info("modelList:{}", JSON.toJSONString(modelList));
throw new Exception("查询实例失败");

View File

@ -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<PropertyPool> list = this.propertyPoolRepository.list(pager);
int total = propertyPoolRepository.count(pager.getParams(), positionKey);
List<PropertyPool> list = this.propertyPoolRepository.list(pager, positionKey);
if (CollectionUtils.isNotEmpty(list)) {
for (PropertyPool pool : list) {
dealPoolItem(pool);

View File

@ -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<Property> detail(Long id) {
public GeneralResult<Property> 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<PropertyItem> items = propertyItemRepository.queryByPropertyId(id);
this.propertyHandle(property, items);
List<PropertyItem> 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<PropertyItem> items) throws Exception {
public void propertyHandle(Property property, List<PropertyItem> 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<PropertyPoolItem> poolItems = propertyPoolItemRepository.listByPropertyPoolId(pool.getId());
List<PropertyPoolItem> poolItems = propertyPoolItemRepository.listByPropertyPoolId(pool.getId(), positionKey);
List<PropertyItem> 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));
}
}

View File

@ -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<RegularExpression>> list(final String type) {
public GeneralResult<List<RegularExpression>> list(final String type, String positionKey) {
try {
List<RegularExpression> expressions = regularExpressionRepository.listAll();
// 模型属性的类别为数据加密的单独处理

View File

@ -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<RelationCategory> list = relationCategoryRepository.listByModuleId(moduleId);
List<RelationCategory> list = relationCategoryRepository.listByModuleId(moduleId, positionKey);
return new GeneralResult<>(true, list, "查询成功");
} catch (Exception e) {
log.error("CmdbRelationCategory list query by moduleId fail:", e);