Просмотр исходного кода

全局设计搜索之script脚本搜索2

o2sword 5 лет назад
Родитель
Сommit
eb422b81c2

+ 25 - 2
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/script/ActionManagerList.java

@@ -1,5 +1,6 @@
 package com.x.cms.assemble.control.jaxrs.script;
 
+import com.google.gson.JsonElement;
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
@@ -7,21 +8,30 @@ import com.x.base.core.project.annotation.FieldDescribe;
 import com.x.base.core.project.bean.WrapCopier;
 import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.gson.GsonPropertyObject;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.tools.ListTools;
 import com.x.cms.core.entity.AppInfo;
 import com.x.cms.core.entity.element.Script;
 
+import java.util.ArrayList;
 import java.util.List;
 
 class ActionManagerList extends BaseAction {
-	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
 		if(!effectivePerson.isManager()){
 			throw new ExceptionAccessDenied(effectivePerson);
 		}
+		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<List<Wo>> result = new ActionResult<>();
-			List<Wo> wos = emc.fetchAll(Script.class,  Wo.copier);
+			List<Wo> wos;
+			if(ListTools.isEmpty(wi.getAppIdList())){
+				wos = emc.fetchAll(Script.class,  Wo.copier);
+			}else{
+				wos = emc.fetchIn(Script.class, Wo.copier, Script.appId_FIELDNAME, wi.getAppIdList());
+			}
 			wos.stream().forEach(wo -> {
 				try {
 					AppInfo appInfo = emc.find( wo.getAppId(), AppInfo.class );
@@ -37,6 +47,19 @@ class ActionManagerList extends BaseAction {
 		}
 	}
 
+	public static class Wi extends GsonPropertyObject{
+		@FieldDescribe("应用ID列表.")
+		private List<String> appIdList = new ArrayList<>();
+
+		public List<String> getAppIdList() {
+			return appIdList;
+		}
+
+		public void setAppIdList(List<String> appIdList) {
+			this.appIdList = appIdList;
+		}
+	}
+
 	public static class Wo extends Script {
 
 		private static final long serialVersionUID = -8095369685452823624L;

+ 4 - 3
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/script/ScriptAction.java

@@ -260,15 +260,16 @@ public class ScriptAction extends StandardJaxrsAction {
 	}
 
 	@JaxrsMethodDescribe(value = "列示Script对象(管理员权限).", action = ActionManagerList.class)
-	@GET
+	@POST
 	@Path("list/manager")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
-	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+							JsonElement jsonElement) {
 		ActionResult<List<ActionManagerList.Wo>> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionManagerList().execute(effectivePerson);
+			result = new ActionManagerList().execute(effectivePerson, jsonElement);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);

+ 25 - 2
o2server/x_portal_assemble_designer/src/main/java/com/x/portal/assemble/designer/jaxrs/script/ActionManagerList.java

@@ -1,5 +1,6 @@
 package com.x.portal.assemble.designer.jaxrs.script;
 
+import com.google.gson.JsonElement;
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
@@ -7,21 +8,30 @@ import com.x.base.core.project.annotation.FieldDescribe;
 import com.x.base.core.project.bean.WrapCopier;
 import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.gson.GsonPropertyObject;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.tools.ListTools;
 import com.x.portal.core.entity.Portal;
 import com.x.portal.core.entity.Script;
 
+import java.util.ArrayList;
 import java.util.List;
 
 class ActionManagerList extends BaseAction {
-	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
 		if(!effectivePerson.isManager()){
 			throw new ExceptionAccessDenied(effectivePerson);
 		}
+		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<List<Wo>> result = new ActionResult<>();
-			List<Wo> wos = emc.fetchAll(Script.class,  Wo.copier);
+			List<Wo> wos;
+			if(ListTools.isEmpty(wi.getAppIdList())){
+				wos = emc.fetchAll(Script.class,  Wo.copier);
+			}else{
+				wos = emc.fetchIn(Script.class, Wo.copier, Script.portal_FIELDNAME, wi.getAppIdList());
+			}
 			wos.stream().forEach(wo -> {
 				try {
 					Portal portal = emc.find(wo.getPortal(), Portal.class);
@@ -38,6 +48,19 @@ class ActionManagerList extends BaseAction {
 		}
 	}
 
+	public static class Wi extends GsonPropertyObject {
+		@FieldDescribe("应用ID列表.")
+		private List<String> appIdList = new ArrayList<>();
+
+		public List<String> getAppIdList() {
+			return appIdList;
+		}
+
+		public void setAppIdList(List<String> appIdList) {
+			this.appIdList = appIdList;
+		}
+	}
+
 	public static class Wo extends Script {
 
 		private static final long serialVersionUID = -8095369685452823624L;

+ 4 - 3
o2server/x_portal_assemble_designer/src/main/java/com/x/portal/assemble/designer/jaxrs/script/ScriptAction.java

@@ -143,15 +143,16 @@ public class ScriptAction extends StandardJaxrsAction {
 	}
 
 	@JaxrsMethodDescribe(value = "列示Script对象(管理员权限).", action = ActionManagerList.class)
-	@GET
+	@POST
 	@Path("list/manager")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
-	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+							JsonElement jsonElement) {
 		ActionResult<List<ActionManagerList.Wo>> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionManagerList().execute(effectivePerson);
+			result = new ActionManagerList().execute(effectivePerson, jsonElement);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);

+ 24 - 2
o2server/x_processplatform_assemble_designer/src/main/java/com/x/processplatform/assemble/designer/jaxrs/script/ActionManagerList.java

@@ -1,5 +1,6 @@
 package com.x.processplatform.assemble.designer.jaxrs.script;
 
+import com.google.gson.JsonElement;
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
@@ -7,22 +8,30 @@ import com.x.base.core.project.annotation.FieldDescribe;
 import com.x.base.core.project.bean.WrapCopier;
 import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.exception.ExceptionAccessDenied;
+import com.x.base.core.project.gson.GsonPropertyObject;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.tools.ListTools;
 import com.x.processplatform.core.entity.element.Application;
 import com.x.processplatform.core.entity.element.Script;
 
+import java.util.ArrayList;
 import java.util.List;
 
 class ActionManagerList extends BaseAction {
-	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
 		if(!effectivePerson.isManager()){
 			throw new ExceptionAccessDenied(effectivePerson);
 		}
+		Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			ActionResult<List<Wo>> result = new ActionResult<>();
-			List<Wo> wos = emc.fetchAll(Script.class,  Wo.copier);
+			List<Wo> wos;
+			if(ListTools.isEmpty(wi.getAppIdList())){
+				wos = emc.fetchAll(Script.class,  Wo.copier);
+			}else{
+				wos = emc.fetchIn(Script.class, Wo.copier, Script.application_FIELDNAME, wi.getAppIdList());
+			}
 			wos.stream().forEach(wo -> {
 				try {
 					Application app = emc.find(wo.getApplication(), Application.class);
@@ -39,6 +48,19 @@ class ActionManagerList extends BaseAction {
 		}
 	}
 
+	public static class Wi extends GsonPropertyObject {
+		@FieldDescribe("应用ID列表.")
+		private List<String> appIdList = new ArrayList<>();
+
+		public List<String> getAppIdList() {
+			return appIdList;
+		}
+
+		public void setAppIdList(List<String> appIdList) {
+			this.appIdList = appIdList;
+		}
+	}
+
 	public static class Wo extends Script {
 
 		private static final long serialVersionUID = -8095369685452823624L;

+ 4 - 3
o2server/x_processplatform_assemble_designer/src/main/java/com/x/processplatform/assemble/designer/jaxrs/script/ScriptAction.java

@@ -201,15 +201,16 @@ public class ScriptAction extends StandardJaxrsAction {
 	}
 
 	@JaxrsMethodDescribe(value = "列示Script对象(管理员权限).", action = ActionManagerList.class)
-	@GET
+	@POST
 	@Path("list/manager")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
-	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
+	public void managerList(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+							JsonElement jsonElement) {
 		ActionResult<List<ActionManagerList.Wo>> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new ActionManagerList().execute(effectivePerson);
+			result = new ActionManagerList().execute(effectivePerson, jsonElement);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);

+ 54 - 60
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/design/ActionSearch.java

@@ -3,6 +3,7 @@ package com.x.query.service.processing.jaxrs.design;
 import com.google.gson.JsonElement;
 import com.x.base.core.project.Applications;
 import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.annotation.FieldTypeDescribe;
 import com.x.base.core.project.gson.GsonPropertyObject;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
@@ -16,8 +17,7 @@ import com.x.base.core.project.x_processplatform_assemble_designer;
 import com.x.query.service.processing.ThisApplication;
 import org.apache.commons.lang3.StringUtils;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 import java.util.concurrent.CompletableFuture;
 
 class ActionSearch extends BaseAction {
@@ -49,69 +49,62 @@ class ActionSearch extends BaseAction {
 	}
 
 	private List<ScriptWo> searchScript(final Wi wi) throws Exception{
-		List<ScriptWo> scriptWoList = new ArrayList<>();
-		CompletableFuture<List<ScriptWo>> cmsCf = CompletableFuture.supplyAsync(() -> {
-			List<ScriptWo> swList = new ArrayList<>();
-			try {
-				List<WrapScript> scriptList = ThisApplication.context().applications().getQuery(x_cms_assemble_control.class,
-						Applications.joinQueryUri("script", "list", "manager"), null).getDataAsList(WrapScript.class);
-				logger.print("CMS的脚本个数:{}",scriptList.size());
-				getScriptSearchRes(wi,"cms",  swList, scriptList);
-			} catch (Exception e) {
-				logger.error(e);
-			}
-			if (swList.size()>2){
-				try {
-					SortTools.desc(swList, "appId");
-				} catch (Exception e) {
+		final Map<String, List<String>> moduleMap = new HashMap<>();
+		if(!ListTools.isEmpty(wi.getModuleList())){
+			for (Module module: wi.getModuleList()){
+				if(module.getModuleType().equalsIgnoreCase(ModuleType.cms.toString())){
+					moduleMap.put(ModuleType.cms.toString(), module.getFlagList());
 				}
-			}
-			return swList;
-		});
-
-		CompletableFuture<List<ScriptWo>> portalCf = CompletableFuture.supplyAsync(() -> {
-			List<ScriptWo> swList = new ArrayList<>();
-			try {
-				List<WrapScript> scriptList = ThisApplication.context().applications().getQuery(x_portal_assemble_designer.class,
-						Applications.joinQueryUri("script", "list", "manager"), null).getDataAsList(WrapScript.class);
-				logger.print("门户的脚本个数:{}",scriptList.size());
-				getScriptSearchRes(wi,"portal",  swList, scriptList);
-			} catch (Exception e) {
-				logger.error(e);
-			}
-			if (swList.size()>2){
-				try {
-					SortTools.desc(swList, "appId");
-				} catch (Exception e) {
+				if(module.getModuleType().equalsIgnoreCase(ModuleType.portal.toString())){
+					moduleMap.put(ModuleType.portal.toString(), module.getFlagList());
+				}
+				if(module.getModuleType().equalsIgnoreCase(ModuleType.processPlatform.toString())){
+					moduleMap.put(ModuleType.processPlatform.toString(), module.getFlagList());
 				}
 			}
-			return swList;
-		});
+		}else{
+			List<String> list = new ArrayList<>();
+			moduleMap.put(ModuleType.cms.toString(), list);
+			moduleMap.put(ModuleType.portal.toString(), list);
+			moduleMap.put(ModuleType.processPlatform.toString(), list);
+		}
+
+		CompletableFuture<List<ScriptWo>> processPlatformCf = scriptSearchAsync(wi, moduleMap, ModuleType.processPlatform.toString(), x_processplatform_assemble_designer.class);
+		CompletableFuture<List<ScriptWo>> portalCf = scriptSearchAsync(wi, moduleMap, ModuleType.portal.toString(), x_portal_assemble_designer.class);
+		CompletableFuture<List<ScriptWo>> cmsCf = scriptSearchAsync(wi, moduleMap, ModuleType.cms.toString(), x_cms_assemble_control.class);
 
-		CompletableFuture<List<ScriptWo>> processPlatformCf = CompletableFuture.supplyAsync(() -> {
+		List<ScriptWo> scriptWoList = new ArrayList<>();
+		scriptWoList.addAll(processPlatformCf.get());
+		scriptWoList.addAll(portalCf.get());
+		scriptWoList.addAll(cmsCf.get());
+
+		return scriptWoList;
+	}
+
+	private CompletableFuture<List<ScriptWo>> scriptSearchAsync(final Wi wi, final Map<String, List<String>> moduleMap, final String moduleType, final Class<?> applicationClass){
+		CompletableFuture<List<ScriptWo>> cf = CompletableFuture.supplyAsync(() -> {
 			List<ScriptWo> swList = new ArrayList<>();
-			try {
-				List<WrapScript> scriptList = ThisApplication.context().applications().getQuery(x_processplatform_assemble_designer.class,
-						Applications.joinQueryUri("script", "list", "manager"), null).getDataAsList(WrapScript.class);
-				logger.print("流程平台的脚本个数:{}",scriptList.size());
-				getScriptSearchRes(wi,"processPlatform", swList, scriptList);
-			} catch (Exception e) {
-				logger.error(e);
-			}
-			if (swList.size()>2){
+			if(moduleMap.containsKey(moduleType)) {
 				try {
-					SortTools.desc(swList, "appId");
+					Map<String, List<String>> map = new HashMap<>();
+					map.put("appIdList", moduleMap.get(moduleType));
+					List<WrapScript> scriptList = ThisApplication.context().applications().postQuery(applicationClass,
+							Applications.joinQueryUri("script", "list", "manager"), map).getDataAsList(WrapScript.class);
+					logger.print("设计搜索关联{}的脚本个数:{}", moduleType, scriptList.size());
+					getScriptSearchRes(wi, moduleType, swList, scriptList);
 				} catch (Exception e) {
+					logger.error(e);
+				}
+				if (swList.size() > 2) {
+					try {
+						SortTools.desc(swList, "appId");
+					} catch (Exception e) {
+					}
 				}
 			}
 			return swList;
 		});
-
-		scriptWoList.addAll(processPlatformCf.get());
-		scriptWoList.addAll(portalCf.get());
-		scriptWoList.addAll(cmsCf.get());
-
-		return scriptWoList;
+		return cf;
 	}
 
 	private void getScriptSearchRes(final Wi wi, String moduleType, List<ScriptWo> swList, List<WrapScript> scriptList){
@@ -149,6 +142,7 @@ class ActionSearch extends BaseAction {
 		@FieldDescribe("是否正则表达式匹配.")
 		private Boolean matchRegExp;
 		@FieldDescribe("限制查询的模块列表.")
+		@FieldTypeDescribe(fieldType = "class", fieldTypeName = "Module", fieldValue = "{\"moduleType\": \"cms\", \"flagList\": []}")
 		private List<Module> moduleList;
 
 		public String getKeyword() {
@@ -201,17 +195,17 @@ class ActionSearch extends BaseAction {
 	}
 
 	public static class Module extends GsonPropertyObject {
-		@FieldDescribe("模块的应用关键字.")
-		private String flag;
+		@FieldDescribe("模块的应用id列表.")
+		private List<String> flagList;
 		@FieldDescribe("模块类型:processPlatform|cms|portal|query|service")
 		private String moduleType;
 
-		public String getFlag() {
-			return flag;
+		public List<String> getFlagList() {
+			return flagList == null ? new ArrayList<>() : flagList;
 		}
 
-		public void setFlag(String flag) {
-			this.flag = flag;
+		public void setFlagList(List<String> flagList) {
+			this.flagList = flagList;
 		}
 
 		public String getModuleType() {

+ 12 - 0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/design/ModuleType.java

@@ -0,0 +1,12 @@
+package com.x.query.service.processing.jaxrs.design;
+
+import com.x.base.core.entity.JpaObject;
+
+/**
+ *
+ */
+public enum ModuleType {
+
+	processPlatform, portal, cms;
+	public static final int length = JpaObject.length_64B;
+}