Răsfoiți Sursa

门户页面优化2

o2sword 5 ani în urmă
părinte
comite
baa3c9285a

+ 38 - 0
o2server/x_portal_assemble_surface/src/main/java/com/x/portal/assemble/surface/jaxrs/page/PageAction.java

@@ -157,4 +157,42 @@ public class PageAction extends StandardJaxrsAction {
 		}
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
+
+	@JaxrsMethodDescribe(value = "列示属于指定Portal的Page,其中Portal可以用name,alias和id标识,Page为在此Portal下的页面.", action = V2GetWithPortal.class)
+	@GET
+	@Path("v2/{flag}/portal/{portalFlag}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void V2GetWithPortal(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+							  @JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
+							  @JaxrsParameterDescribe("门户标识") @PathParam("portalFlag") String portalFlag) {
+		ActionResult<V2GetWithPortal.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new V2GetWithPortal().execute(effectivePerson, flag, portalFlag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
+	@JaxrsMethodDescribe(value = "列示属于指定Portal的Page,其中Portal可以用name,alias和id标识,Page为在此Portal下的页面Mobile.", action = V2GetWithPortalMobile.class)
+	@GET
+	@Path("v2/{flag}/portal/{portalFlag}/mobile")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void V2GetWithPortalMobile(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+									@JaxrsParameterDescribe("标识") @PathParam("flag") String flag,
+									@JaxrsParameterDescribe("门户标识") @PathParam("portalFlag") String portalFlag) {
+		ActionResult<V2GetWithPortalMobile.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new V2GetWithPortalMobile().execute(effectivePerson, flag, portalFlag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
 }

+ 12 - 2
o2server/x_portal_assemble_surface/src/main/java/com/x/portal/assemble/surface/jaxrs/page/V2Get.java

@@ -15,12 +15,16 @@ import com.x.portal.core.entity.Page;
 import com.x.portal.core.entity.PageProperties;
 import com.x.portal.core.entity.Script;
 import com.x.portal.core.entity.Widget;
+import org.apache.commons.lang3.StringUtils;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
 
 class V2Get extends BaseAction {
 
@@ -51,8 +55,8 @@ class V2Get extends BaseAction {
 		}
 		Wo wo = new Wo();
 		final PageProperties properties = page.getProperties();
-		wo.setFastETag(page.getId() + page.getUpdateTime().getTime());
 		wo.setPage(new RelatedPage(page, page.getDataOrMobileData()));
+		final List<String> list = new CopyOnWriteArrayList<>();
 		CompletableFuture<Map<String, RelatedWidget>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedWidget> map = new TreeMap<>();
 			if (ListTools.isNotEmpty(properties.getRelatedWidgetList())) {
@@ -63,6 +67,7 @@ class V2Get extends BaseAction {
 						_f = bus.widget().pick(_id);
 						if (null != _f) {
 							map.put(_id, new RelatedWidget(_f, _f.getDataOrMobileData()));
+							list.add(_f.getId() + _f.getUpdateTime().getTime());
 						}
 					}
 				} catch (Exception e) {
@@ -84,6 +89,7 @@ class V2Get extends BaseAction {
 								if (null != _pp) {
 									map.put(entry.getKey(), new RelatedScript(_pp.getId(), _pp.getName(), _pp.getAlias(),
 											_pp.getText(), entry.getValue()));
+									list.add(_pp.getId() + _pp.getUpdateTime().getTime());
 								}
 								break;
 							case RelatedScript.TYPE_CMS:
@@ -91,6 +97,7 @@ class V2Get extends BaseAction {
 								if (null != _cms) {
 									map.put(entry.getKey(), new RelatedScript(_cms.getId(), _cms.getName(), _cms.getAlias(),
 											_cms.getText(), entry.getValue()));
+									list.add(_cms.getId() + _cms.getUpdateTime().getTime());
 								}
 								break;
 							case RelatedScript.TYPE_PORTAL:
@@ -98,6 +105,7 @@ class V2Get extends BaseAction {
 								if (null != _p) {
 									map.put(entry.getKey(), new RelatedScript(_p.getId(), _p.getName(), _p.getAlias(),
 											_p.getText(), entry.getValue()));
+									list.add(_p.getId() + _p.getUpdateTime().getTime());
 								}
 								break;
 							default:
@@ -110,9 +118,11 @@ class V2Get extends BaseAction {
 			}
 			return map;
 		});
+		list.add(page.getId() + page.getUpdateTime().getTime());
+		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
+		wo.setFastETag(StringUtils.join(sortList, "#"));
 		wo.setRelatedWidgetMap(_relatedWidget.get());
 		wo.setRelatedScriptMap(_relatedScript.get());
-		wo.setMaxAge(3600 * 24);
 		return wo;
 	}
 

+ 12 - 2
o2server/x_portal_assemble_surface/src/main/java/com/x/portal/assemble/surface/jaxrs/page/V2GetMobile.java

@@ -15,12 +15,16 @@ import com.x.portal.core.entity.Page;
 import com.x.portal.core.entity.PageProperties;
 import com.x.portal.core.entity.Script;
 import com.x.portal.core.entity.Widget;
+import org.apache.commons.lang3.StringUtils;
 
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Optional;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
 
 class V2GetMobile extends BaseAction {
 
@@ -51,8 +55,8 @@ class V2GetMobile extends BaseAction {
 		}
 		Wo wo = new Wo();
 		final PageProperties properties = page.getProperties();
-		wo.setFastETag(page.getId() + page.getUpdateTime().getTime());
 		wo.setPage(new RelatedPage(page, page.getMobileDataOrData()));
+		final List<String> list = new CopyOnWriteArrayList<>();
 		CompletableFuture<Map<String, RelatedWidget>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedWidget> map = new TreeMap<>();
 			if (ListTools.isNotEmpty(properties.getMobileRelatedWidgetList())) {
@@ -63,6 +67,7 @@ class V2GetMobile extends BaseAction {
 						_f = bus.widget().pick(_id);
 						if (null != _f) {
 							map.put(_id, new RelatedWidget(_f, _f.getMobileDataOrData()));
+							list.add(_f.getId() + _f.getUpdateTime().getTime());
 						}
 					}
 				} catch (Exception e) {
@@ -84,6 +89,7 @@ class V2GetMobile extends BaseAction {
 							if (null != _pp) {
 								map.put(entry.getKey(), new RelatedScript(_pp.getId(), _pp.getName(), _pp.getAlias(),
 										_pp.getText(), entry.getValue()));
+								list.add(_pp.getId() + _pp.getUpdateTime().getTime());
 							}
 							break;
 						case RelatedScript.TYPE_CMS:
@@ -91,6 +97,7 @@ class V2GetMobile extends BaseAction {
 							if (null != _cms) {
 								map.put(entry.getKey(), new RelatedScript(_cms.getId(), _cms.getName(), _cms.getAlias(),
 										_cms.getText(), entry.getValue()));
+								list.add(_cms.getId() + _cms.getUpdateTime().getTime());
 							}
 							break;
 						case RelatedScript.TYPE_PORTAL:
@@ -98,6 +105,7 @@ class V2GetMobile extends BaseAction {
 							if (null != _p) {
 								map.put(entry.getKey(), new RelatedScript(_p.getId(), _p.getName(), _p.getAlias(),
 										_p.getText(), entry.getValue()));
+								list.add(_p.getId() + _p.getUpdateTime().getTime());
 							}
 							break;
 						default:
@@ -110,9 +118,11 @@ class V2GetMobile extends BaseAction {
 			}
 			return map;
 		});
+		list.add(page.getId() + page.getUpdateTime().getTime());
+		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
+		wo.setFastETag(StringUtils.join(sortList, "#"));
 		wo.setRelatedWidgetMap(_relatedWidget.get());
 		wo.setRelatedScriptMap(_relatedScript.get());
-		wo.setMaxAge(3600 * 24);
 		return wo;
 	}
 

+ 149 - 0
o2server/x_portal_assemble_surface/src/main/java/com/x/portal/assemble/surface/jaxrs/page/V2GetWithPortal.java

@@ -0,0 +1,149 @@
+package com.x.portal.assemble.surface.jaxrs.page;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.project.cache.Cache.CacheKey;
+import com.x.base.core.project.cache.CacheManager;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.ListTools;
+import com.x.portal.assemble.surface.Business;
+import com.x.portal.core.entity.*;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
+
+class V2GetWithPortal extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(V2GetWithPortal.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
+		ActionResult<Wo> result = new ActionResult<>();
+		Wo wo = null;
+		CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
+		Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
+		if (optional.isPresent()) {
+			wo = (Wo) optional.get();
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				Portal portal = business.portal().pick(portalFlag);
+				if (null == portal) {
+					throw new ExceptionPortalNotExist(portalFlag);
+				}
+				if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
+					throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
+							portal.getId());
+				}
+			}
+		} else {
+			wo = this.get(flag, portalFlag, effectivePerson);
+			CacheManager.put(cacheCategory, cacheKey, wo);
+		}
+		result.setData(wo);
+		return result;
+	}
+
+	private Wo get(String flag, String portalFlag, EffectivePerson effectivePerson) throws Exception {
+		Page page = null;
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			Business business = new Business(emc);
+			Portal portal = business.portal().pick(portalFlag);
+			if (null == portal) {
+				throw new ExceptionPortalNotExist(portalFlag);
+			}
+			if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
+				throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
+						portal.getId());
+			}
+			page = business.page().pick(portal, flag);
+			if (null == page) {
+				throw new ExceptionPageNotExist(flag);
+			}
+		}
+		Wo wo = new Wo();
+		final PageProperties properties = page.getProperties();
+		wo.setPage(new RelatedPage(page, page.getDataOrMobileData()));
+		final List<String> list = new CopyOnWriteArrayList<>();
+		CompletableFuture<Map<String, RelatedWidget>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
+			Map<String, RelatedWidget> map = new TreeMap<>();
+			if (ListTools.isNotEmpty(properties.getRelatedWidgetList())) {
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					Business bus = new Business(emc);
+					Widget _f;
+					for (String _id : properties.getRelatedWidgetList()) {
+						_f = bus.widget().pick(_id);
+						if (null != _f) {
+							map.put(_id, new RelatedWidget(_f, _f.getDataOrMobileData()));
+							list.add(_f.getId() + _f.getUpdateTime().getTime());
+						}
+					}
+				} catch (Exception e) {
+					logger.error(e);
+				}
+			}
+			return map;
+		});
+		CompletableFuture<Map<String, RelatedScript>> _relatedScript = CompletableFuture.supplyAsync(() -> {
+			Map<String, RelatedScript> map = new TreeMap<>();
+			if ((null != properties.getRelatedScriptMap())
+					&& (properties.getRelatedScriptMap().size() > 0)) {
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					Business bus = new Business(emc);
+					for (Entry<String, String> entry : properties.getRelatedScriptMap().entrySet()) {
+						switch (entry.getValue()) {
+							case RelatedScript.TYPE_PROCESSPLATFORM:
+								com.x.processplatform.core.entity.element.Script _pp = bus.process().script().pick(entry.getKey());
+								if (null != _pp) {
+									map.put(entry.getKey(), new RelatedScript(_pp.getId(), _pp.getName(), _pp.getAlias(),
+											_pp.getText(), entry.getValue()));
+									list.add(_pp.getId() + _pp.getUpdateTime().getTime());
+								}
+								break;
+							case RelatedScript.TYPE_CMS:
+								com.x.cms.core.entity.element.Script _cms = bus.cms().script().pick(entry.getKey());
+								if (null != _cms) {
+									map.put(entry.getKey(), new RelatedScript(_cms.getId(), _cms.getName(), _cms.getAlias(),
+											_cms.getText(), entry.getValue()));
+									list.add(_cms.getId() + _cms.getUpdateTime().getTime());
+								}
+								break;
+							case RelatedScript.TYPE_PORTAL:
+								Script _p = bus.script().pick(entry.getKey());
+								if (null != _p) {
+									map.put(entry.getKey(), new RelatedScript(_p.getId(), _p.getName(), _p.getAlias(),
+											_p.getText(), entry.getValue()));
+									list.add(_p.getId() + _p.getUpdateTime().getTime());
+								}
+								break;
+							default:
+								break;
+						}
+					}
+				} catch (Exception e) {
+					logger.error(e);
+				}
+			}
+			return map;
+		});
+		list.add(page.getId() + page.getUpdateTime().getTime());
+		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
+		wo.setFastETag(StringUtils.join(sortList, "#"));
+		wo.setRelatedWidgetMap(_relatedWidget.get());
+		wo.setRelatedScriptMap(_relatedScript.get());
+		return wo;
+	}
+
+	public static class Wo extends AbstractWo {
+
+	}
+
+}

+ 149 - 0
o2server/x_portal_assemble_surface/src/main/java/com/x/portal/assemble/surface/jaxrs/page/V2GetWithPortalMobile.java

@@ -0,0 +1,149 @@
+package com.x.portal.assemble.surface.jaxrs.page;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.project.cache.Cache.CacheKey;
+import com.x.base.core.project.cache.CacheManager;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.tools.ListTools;
+import com.x.portal.assemble.surface.Business;
+import com.x.portal.core.entity.*;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.TreeMap;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.stream.Collectors;
+
+class V2GetWithPortalMobile extends BaseAction {
+
+	private static Logger logger = LoggerFactory.getLogger(V2GetWithPortalMobile.class);
+
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag, String portalFlag) throws Exception {
+		ActionResult<Wo> result = new ActionResult<>();
+		Wo wo = null;
+		CacheKey cacheKey = new CacheKey(this.getClass(), flag, portalFlag);
+		Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
+		if (optional.isPresent()) {
+			wo = (Wo) optional.get();
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				Portal portal = business.portal().pick(portalFlag);
+				if (null == portal) {
+					throw new ExceptionPortalNotExist(portalFlag);
+				}
+				if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
+					throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
+							portal.getId());
+				}
+			}
+		} else {
+			wo = this.get(flag, portalFlag, effectivePerson);
+			CacheManager.put(cacheCategory, cacheKey, wo);
+		}
+		result.setData(wo);
+		return result;
+	}
+
+	private Wo get(String flag, String portalFlag, EffectivePerson effectivePerson) throws Exception {
+		Page page;
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			Business business = new Business(emc);
+			Portal portal = business.portal().pick(portalFlag);
+			if (null == portal) {
+				throw new ExceptionPortalNotExist(portalFlag);
+			}
+			if (isNotLoginPage(flag) && (!business.portal().visible(effectivePerson, portal))) {
+				throw new ExceptionPortalAccessDenied(effectivePerson.getDistinguishedName(), portal.getName(),
+						portal.getId());
+			}
+			page = business.page().pick(portal, flag);
+			if (null == page) {
+				throw new ExceptionPageNotExist(flag);
+			}
+		}
+		Wo wo = new Wo();
+		final PageProperties properties = page.getProperties();
+		wo.setPage(new RelatedPage(page, page.getMobileDataOrData()));
+		final List<String> list = new CopyOnWriteArrayList<>();
+		CompletableFuture<Map<String, RelatedWidget>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
+			Map<String, RelatedWidget> map = new TreeMap<>();
+			if (ListTools.isNotEmpty(properties.getMobileRelatedWidgetList())) {
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					Business bus = new Business(emc);
+					Widget _f;
+					for (String _id : properties.getMobileRelatedWidgetList()) {
+						_f = bus.widget().pick(_id);
+						if (null != _f) {
+							map.put(_id, new RelatedWidget(_f, _f.getMobileDataOrData()));
+							list.add(_f.getId() + _f.getUpdateTime().getTime());
+						}
+					}
+				} catch (Exception e) {
+					logger.error(e);
+				}
+			}
+			return map;
+		});
+		CompletableFuture<Map<String, RelatedScript>> _relatedScript = CompletableFuture.supplyAsync(() -> {
+			Map<String, RelatedScript> map = new TreeMap<>();
+			if ((null != properties.getMobileRelatedScriptMap())
+					&& (properties.getMobileRelatedScriptMap().size() > 0)) {
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					Business bus = new Business(emc);
+					for (Entry<String, String> entry : properties.getMobileRelatedScriptMap().entrySet()) {
+						switch (entry.getValue()) {
+						case RelatedScript.TYPE_PROCESSPLATFORM:
+							com.x.processplatform.core.entity.element.Script _pp = bus.process().script().pick(entry.getKey());
+							if (null != _pp) {
+								map.put(entry.getKey(), new RelatedScript(_pp.getId(), _pp.getName(), _pp.getAlias(),
+										_pp.getText(), entry.getValue()));
+								list.add(_pp.getId() + _pp.getUpdateTime().getTime());
+							}
+							break;
+						case RelatedScript.TYPE_CMS:
+							com.x.cms.core.entity.element.Script _cms = bus.cms().script().pick(entry.getKey());
+							if (null != _cms) {
+								map.put(entry.getKey(), new RelatedScript(_cms.getId(), _cms.getName(), _cms.getAlias(),
+										_cms.getText(), entry.getValue()));
+								list.add(_cms.getId() + _cms.getUpdateTime().getTime());
+							}
+							break;
+						case RelatedScript.TYPE_PORTAL:
+							Script _p = bus.script().pick(entry.getKey());
+							if (null != _p) {
+								map.put(entry.getKey(), new RelatedScript(_p.getId(), _p.getName(), _p.getAlias(),
+										_p.getText(), entry.getValue()));
+								list.add(_p.getId() + _p.getUpdateTime().getTime());
+							}
+							break;
+						default:
+							break;
+						}
+					}
+				} catch (Exception e) {
+					logger.error(e);
+				}
+			}
+			return map;
+		});
+		list.add(page.getId() + page.getUpdateTime().getTime());
+		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
+		wo.setFastETag(StringUtils.join(sortList, "#"));
+		wo.setRelatedWidgetMap(_relatedWidget.get());
+		wo.setRelatedScriptMap(_relatedScript.get());
+		return wo;
+	}
+
+	public static class Wo extends AbstractWo {
+
+	}
+
+}