瀏覽代碼

cms表单查询优化4

o2sword 5 年之前
父節點
當前提交
66c9a762bb

+ 6 - 8
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/FormAction.java

@@ -251,17 +251,16 @@ public class FormAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "查询表单,如果有表单那么返回表单id,如果表单不存在那么返回分类的默认Form.", action = V2LookupDoc.class)
 	@GET
-	@Path("v2/lookup/document/{docId}/mode/{openMode}")
+	@Path("v2/lookup/document/{docId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void V2LookupDoc(@Suspended final AsyncResponse asyncResponse,
 											@Context HttpServletRequest request,
-											@JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId,
-											@JaxrsParameterDescribe("文档打开模式:read(只读模式)|edit(编辑模式)") @PathParam("openMode") String openMode) {
+											@JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId) {
 		ActionResult<V2LookupDoc.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new V2LookupDoc().execute(effectivePerson, docId, openMode);
+			result = new V2LookupDoc().execute(effectivePerson, docId);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);
@@ -271,17 +270,16 @@ public class FormAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "查询表单,如果有表单那么返回表单id,如果表单不存在返回分类的默认FormMobile.", action = V2LookupDocMobile.class)
 	@GET
-	@Path("v2/lookup/document/{docId}/mode/{openMode}/mobile")
+	@Path("v2/lookup/document/{docId}/mobile")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void V2LookupDocMobile(@Suspended final AsyncResponse asyncResponse,
 												  @Context HttpServletRequest request,
-												  @JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId,
-												  @JaxrsParameterDescribe("文档打开模式:read(只读模式)|edit(编辑模式)") @PathParam("openMode") String openMode) {
+												  @JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId) {
 		ActionResult<V2LookupDocMobile.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new V2LookupDocMobile().execute(effectivePerson, docId, openMode);
+			result = new V2LookupDocMobile().execute(effectivePerson, docId);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);

+ 6 - 8
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/FormAnonymousAction.java

@@ -50,17 +50,16 @@ public class FormAnonymousAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "查询表单,如果有表单那么返回表单id,如果表单不存在那么返回分类的默认Form.", action = V2LookupDoc.class)
 	@GET
-	@Path("v2/lookup/document/{docId}/mode/{openMode}")
+	@Path("v2/lookup/document/{docId}")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void V2LookupDoc(@Suspended final AsyncResponse asyncResponse,
 											@Context HttpServletRequest request,
-											@JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId,
-											@JaxrsParameterDescribe("文档打开模式:read(只读模式)|edit(编辑模式)") @PathParam("openMode") String openMode) {
+											@JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId) {
 		ActionResult<V2LookupDoc.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new V2LookupDoc().execute(effectivePerson, docId, openMode);
+			result = new V2LookupDoc().execute(effectivePerson, docId);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);
@@ -70,17 +69,16 @@ public class FormAnonymousAction extends StandardJaxrsAction {
 
 	@JaxrsMethodDescribe(value = "查询表单,如果有表单那么返回表单id,如果表单不存在返回分类的默认FormMobile.", action = V2LookupDocMobile.class)
 	@GET
-	@Path("v2/lookup/document/{docId}/mode/{openMode}/mobile")
+	@Path("v2/lookup/document/{docId}/mobile")
 	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
 	@Consumes(MediaType.APPLICATION_JSON)
 	public void V2LookupDocMobile(@Suspended final AsyncResponse asyncResponse,
 												  @Context HttpServletRequest request,
-												  @JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId,
-												  @JaxrsParameterDescribe("文档打开模式:read(只读模式)|edit(编辑模式)") @PathParam("openMode") String openMode) {
+												  @JaxrsParameterDescribe("文档ID") @PathParam("docId") String docId) {
 		ActionResult<V2LookupDocMobile.Wo> result = new ActionResult<>();
 		EffectivePerson effectivePerson = this.effectivePerson(request);
 		try {
-			result = new V2LookupDocMobile().execute(effectivePerson, docId, openMode);
+			result = new V2LookupDocMobile().execute(effectivePerson, docId);
 		} catch (Exception e) {
 			logger.error(e, effectivePerson, request, null);
 			result.error(e);

+ 67 - 65
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/V2Get.java

@@ -14,16 +14,13 @@ import com.x.cms.assemble.control.Business;
 import com.x.cms.core.entity.element.Form;
 import com.x.cms.core.entity.element.FormProperties;
 import com.x.cms.core.entity.element.Script;
-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;
+import java.util.concurrent.TimeUnit;
 
 class V2Get extends BaseAction {
 
@@ -36,37 +33,41 @@ class V2Get extends BaseAction {
 		if (optional.isPresent()) {
 			result.setData((Wo) optional.get());
 		} else {
-			Wo wo = this.get(id);
+			Form form = null;
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				form = business.getFormFactory().pick(id);
+			}
+			if (null == form) {
+				throw new ExceptionEntityNotExist(id, Form.class);
+			}
+			Wo wo = new Wo();
+			final FormProperties properties = form.getProperties();
+			wo.setFastETag(form.getId() + form.getUpdateTime().getTime());
+			wo.setForm(new RelatedForm(form, form.getDataOrMobileData()));
+			CompletableFuture<Map<String, RelatedForm>> getRelatedFormFuture = this.getRelatedFormFuture(properties);
+			CompletableFuture<Map<String, RelatedScript>> getRelatedScriptFuture = this
+					.getRelatedScriptFuture(properties);
+			wo.setRelatedFormMap(getRelatedFormFuture.get(10, TimeUnit.SECONDS));
+			wo.setRelatedScriptMap(getRelatedScriptFuture.get(10, TimeUnit.SECONDS));
+			wo.setMaxAge(3600 * 24);
 			CacheManager.put(cacheCategory, cacheKey, wo);
 			result.setData(wo);
 		}
 		return result;
 	}
 
-	private Wo get(String id) throws Exception {
-		Form form;
-		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			Business business = new Business(emc);
-			form = business.getFormFactory().pick(id);
-		}
-		if (null == form) {
-			throw new ExceptionEntityNotExist(id, Form.class);
-		}
-		Wo wo = new Wo();
-		final FormProperties properties = form.getProperties();
-		wo.setForm(new RelatedForm(form, form.getDataOrMobileData()));
-		final List<String> list = new CopyOnWriteArrayList<>();
-		CompletableFuture<Map<String, RelatedForm>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
+	private CompletableFuture<Map<String, RelatedForm>> getRelatedFormFuture(FormProperties properties) {
+		return CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedForm> map = new TreeMap<>();
 			if (ListTools.isNotEmpty(properties.getRelatedFormList())) {
 				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 					Business bus = new Business(emc);
-					Form _f;
-					for (String _id : properties.getRelatedFormList()) {
-						_f = bus.getFormFactory().pick(_id);
-						if (null != _f) {
-							map.put(_id, new RelatedForm(_f, _f.getDataOrMobileData()));
-							list.add(_f.getId() + _f.getUpdateTime().getTime());
+					Form f;
+					for (String id : properties.getRelatedFormList()) {
+						f = bus.getFormFactory().pick(id);
+						if (null != f) {
+							map.put(id, new RelatedForm(f, f.getDataOrMobileData()));
 						}
 					}
 				} catch (Exception e) {
@@ -75,58 +76,59 @@ class V2Get extends BaseAction {
 			}
 			return map;
 		});
-		CompletableFuture<Map<String, RelatedScript>> _relatedScript = CompletableFuture.supplyAsync(() -> {
+	}
+
+	private CompletableFuture<Map<String, RelatedScript>> getRelatedScriptFuture(FormProperties properties) {
+		return CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedScript> map = new TreeMap<>();
-			if ((null != properties.getRelatedScriptMap())
-					&& (properties.getRelatedScriptMap().size() > 0)) {
+			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_PROCESS_PLATFORM:
-								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:
-								Script _cms = bus.getScriptFactory().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:
-								com.x.portal.core.entity.Script _p = bus.portal().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;
-						}
-					}
+					Business business = new Business(emc);
+					map = convertScript(business, properties);
 				} catch (Exception e) {
 					logger.error(e);
 				}
 			}
 			return map;
 		});
-		list.add(form.getId() + form.getUpdateTime().getTime());
-		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
-		wo.setFastETag(StringUtils.join(sortList, "#"));
-		wo.setRelatedFormMap(_relatedWidget.get());
-		wo.setRelatedScriptMap(_relatedScript.get());
-		return wo;
+	}
+
+	private Map<String, RelatedScript> convertScript(Business bus, FormProperties properties) throws Exception {
+		Map<String, RelatedScript> map = new TreeMap<>();
+		for (Entry<String, String> entry : properties.getRelatedScriptMap().entrySet()) {
+			switch (entry.getValue()) {
+				case RelatedScript.TYPE_PROCESS_PLATFORM:
+					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()));
+					}
+					break;
+				case RelatedScript.TYPE_CMS:
+					Script cms = bus.getScriptFactory().pick(entry.getKey());
+					if (null != cms) {
+						map.put(entry.getKey(), new RelatedScript(cms.getId(), cms.getName(), cms.getAlias(), cms.getText(),
+								entry.getValue()));
+					}
+					break;
+				case RelatedScript.TYPE_PORTAL:
+					com.x.portal.core.entity.Script p = bus.portal().script().pick(entry.getKey());
+					if (null != p) {
+						map.put(entry.getKey(),
+								new RelatedScript(p.getId(), p.getName(), p.getAlias(), p.getText(), entry.getValue()));
+					}
+					break;
+				default:
+					break;
+			}
+		}
+		return map;
 	}
 
 	public static class Wo extends AbstractWo {
 
+		private static final long serialVersionUID = 3540820372721279101L;
+
 	}
 
 }

+ 67 - 65
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/V2GetMobile.java

@@ -14,16 +14,13 @@ import com.x.cms.assemble.control.Business;
 import com.x.cms.core.entity.element.Form;
 import com.x.cms.core.entity.element.FormProperties;
 import com.x.cms.core.entity.element.Script;
-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;
+import java.util.concurrent.TimeUnit;
 
 class V2GetMobile extends BaseAction {
 
@@ -36,37 +33,41 @@ class V2GetMobile extends BaseAction {
 		if (optional.isPresent()) {
 			result.setData((Wo) optional.get());
 		} else {
-			Wo wo = this.get(id);
+			Form form = null;
+			try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+				Business business = new Business(emc);
+				form = business.getFormFactory().pick(id);
+			}
+			if (null == form) {
+				throw new ExceptionEntityNotExist(id, Form.class);
+			}
+			Wo wo = new Wo();
+			final FormProperties properties = form.getProperties();
+			wo.setFastETag(form.getId() + form.getUpdateTime().getTime());
+			wo.setForm(new RelatedForm(form, form.getMobileDataOrData()));
+			CompletableFuture<Map<String, RelatedForm>> getRelatedFormFuture = this.getRelatedFormFuture(properties);
+			CompletableFuture<Map<String, RelatedScript>> getRelatedScriptFuture = this
+					.getRelatedScriptFuture(properties);
+			wo.setRelatedFormMap(getRelatedFormFuture.get(10, TimeUnit.SECONDS));
+			wo.setRelatedScriptMap(getRelatedScriptFuture.get(10, TimeUnit.SECONDS));
+			wo.setMaxAge(3600 * 24);
 			CacheManager.put(cacheCategory, cacheKey, wo);
 			result.setData(wo);
 		}
 		return result;
 	}
 
-	private Wo get(String id) throws Exception {
-		Form form;
-		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-			Business business = new Business(emc);
-			form = business.getFormFactory().pick(id);
-		}
-		if (null == form) {
-			throw new ExceptionEntityNotExist(id, Form.class);
-		}
-		Wo wo = new Wo();
-		final FormProperties properties = form.getProperties();
-		wo.setForm(new RelatedForm(form, form.getMobileDataOrData()));
-		final List<String> list = new CopyOnWriteArrayList<>();
-		CompletableFuture<Map<String, RelatedForm>> _relatedWidget = CompletableFuture.supplyAsync(() -> {
+	private CompletableFuture<Map<String, RelatedForm>> getRelatedFormFuture(FormProperties properties) {
+		return CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedForm> map = new TreeMap<>();
 			if (ListTools.isNotEmpty(properties.getMobileRelatedFormList())) {
 				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 					Business bus = new Business(emc);
-					Form _f;
-					for (String _id : properties.getMobileRelatedFormList()) {
-						_f = bus.getFormFactory().pick(_id);
-						if (null != _f) {
-							map.put(_id, new RelatedForm(_f, _f.getMobileDataOrData()));
-							list.add(_f.getId() + _f.getUpdateTime().getTime());
+					Form f;
+					for (String id : properties.getMobileRelatedFormList()) {
+						f = bus.getFormFactory().pick(id);
+						if (null != f) {
+							map.put(id, new RelatedForm(f, f.getMobileDataOrData()));
 						}
 					}
 				} catch (Exception e) {
@@ -75,58 +76,59 @@ class V2GetMobile extends BaseAction {
 			}
 			return map;
 		});
-		CompletableFuture<Map<String, RelatedScript>> _relatedScript = CompletableFuture.supplyAsync(() -> {
+	}
+
+	private CompletableFuture<Map<String, RelatedScript>> getRelatedScriptFuture(FormProperties properties) {
+		return CompletableFuture.supplyAsync(() -> {
 			Map<String, RelatedScript> map = new TreeMap<>();
-			if ((null != properties.getMobileRelatedScriptMap())
-					&& (properties.getMobileRelatedScriptMap().size() > 0)) {
+			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_PROCESS_PLATFORM:
-								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:
-								Script _cms = bus.getScriptFactory().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:
-								com.x.portal.core.entity.Script _p = bus.portal().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;
-						}
-					}
+					Business business = new Business(emc);
+					map = convertScript(business, properties);
 				} catch (Exception e) {
 					logger.error(e);
 				}
 			}
 			return map;
 		});
-		list.add(form.getId() + form.getUpdateTime().getTime());
-		List<String> sortList = list.stream().sorted().collect(Collectors.toList());
-		wo.setFastETag(StringUtils.join(sortList, "#"));
-		wo.setRelatedFormMap(_relatedWidget.get());
-		wo.setRelatedScriptMap(_relatedScript.get());
-		return wo;
+	}
+
+	private Map<String, RelatedScript> convertScript(Business bus, FormProperties properties) throws Exception {
+		Map<String, RelatedScript> map = new TreeMap<>();
+		for (Entry<String, String> entry : properties.getMobileRelatedScriptMap().entrySet()) {
+			switch (entry.getValue()) {
+				case RelatedScript.TYPE_PROCESS_PLATFORM:
+					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()));
+					}
+					break;
+				case RelatedScript.TYPE_CMS:
+					Script cms = bus.getScriptFactory().pick(entry.getKey());
+					if (null != cms) {
+						map.put(entry.getKey(), new RelatedScript(cms.getId(), cms.getName(), cms.getAlias(), cms.getText(),
+								entry.getValue()));
+					}
+					break;
+				case RelatedScript.TYPE_PORTAL:
+					com.x.portal.core.entity.Script p = bus.portal().script().pick(entry.getKey());
+					if (null != p) {
+						map.put(entry.getKey(),
+								new RelatedScript(p.getId(), p.getName(), p.getAlias(), p.getText(), entry.getValue()));
+					}
+					break;
+				default:
+					break;
+			}
+		}
+		return map;
 	}
 
 	public static class Wo extends AbstractWo {
 
+		private static final long serialVersionUID = 3540820372721279101L;
+
 	}
 
 }

+ 64 - 24
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/V2LookupDoc.java

@@ -30,29 +30,48 @@ class V2LookupDoc extends BaseAction {
 	private static Logger logger = LoggerFactory.getLogger(V2LookupDoc.class);
 
 	private Form form = null;
+	private Form readForm = null;
 	private Wo wo = new Wo();
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String docId, String openMode) throws Exception {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String docId) throws Exception {
 
 		ActionResult<Wo> result = new ActionResult<>();
 
-		this.getDocForm(docId, openMode);
-
+		this.getDocForm(docId);
+		String formId = "";
+		String readFormId = "";
 		if (null != this.form) {
-			CacheKey cacheKey = new CacheKey(this.getClass(), this.form.getId());
+			formId = form.getId();
+			this.wo.setFormId(formId);
+		}
+		if (null != this.readForm) {
+			readFormId = readForm.getId();
+			this.wo.setReadFormId(readFormId);
+		}
+		if(StringUtils.isNotEmpty(formId) || StringUtils.isNotEmpty(readFormId)){
+			CacheKey cacheKey = new CacheKey(this.getClass(), formId, readFormId);
 			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
 			if (optional.isPresent()) {
 				this.wo = (Wo) optional.get();
 			} else {
 				List<String> list = new ArrayList<>();
-				CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.form.getProperties());
-				CompletableFuture<List<String>> relatedScriptFuture = this
-						.relatedScriptFuture(this.form.getProperties());
-				list.add(this.form.getId() + this.form.getUpdateTime().getTime());
-				list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
-				list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				if (null != this.form) {
+					CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.form.getProperties());
+					CompletableFuture<List<String>> relatedScriptFuture = this
+							.relatedScriptFuture(this.form.getProperties());
+					list.add(this.form.getId() + this.form.getUpdateTime().getTime());
+					list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
+					list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				}
+				if (null != this.readForm && !formId.equals(readFormId)) {
+					CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.readForm.getProperties());
+					CompletableFuture<List<String>> relatedScriptFuture = this
+							.relatedScriptFuture(this.readForm.getProperties());
+					list.add(this.readForm.getId() + this.readForm.getUpdateTime().getTime());
+					list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
+					list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				}
 				list = list.stream().sorted().collect(Collectors.toList());
-				this.wo.setId(this.form.getId());
 				CRC32 crc = new CRC32();
 				crc.update(StringUtils.join(list, "#").getBytes());
 				this.wo.setCacheTag(crc.getValue() + "");
@@ -63,27 +82,38 @@ class V2LookupDoc extends BaseAction {
 		return result;
 	}
 
-	private void getDocForm(String docId, String openMode) throws Exception {
+	private void getDocForm(String docId) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			Business business = new Business(emc);
 			Document document = emc.fetch(docId, Document.class, ListTools.toList(JpaObject.id_FIELDNAME, Document.form_FIELDNAME,
 					Document.readFormId_FIELDNAME, Document.categoryId_FIELDNAME));
 			if (null != document) {
 				String formId = document.getForm();
-				if(FORM_OPEN_MODE_READ.equals(openMode)){
-					formId = document.getReadFormId();
+				String readFormId = document.getReadFormId();
+				if(StringUtils.isNotBlank(formId)) {
+					this.form = business.getFormFactory().pick(formId);
 				}
-				this.form = business.getFormFactory().pick(formId);
 				if (null == this.form) {
 					CategoryInfo categoryInfo = business.getCategoryInfoFactory().pick(document.getCategoryId());
 					if (null != categoryInfo) {
 						formId = categoryInfo.getFormId();
-						if(FORM_OPEN_MODE_READ.equals(openMode)){
-							formId = categoryInfo.getReadFormId();
-						}
 						this.form = business.getFormFactory().pick(formId);
 					}
 				}
+				if(StringUtils.isNotBlank(readFormId)) {
+					if(readFormId.equals(formId)){
+						this.readForm = this.form;
+					}else {
+						this.readForm = business.getFormFactory().pick(formId);
+					}
+				}
+				if (null == this.readForm) {
+					CategoryInfo categoryInfo = business.getCategoryInfoFactory().pick(document.getCategoryId());
+					if (null != categoryInfo) {
+						readFormId = categoryInfo.getReadFormId();
+						this.readForm = business.getFormFactory().pick(readFormId);
+					}
+				}
 			}
 		}
 	}
@@ -125,18 +155,28 @@ class V2LookupDoc extends BaseAction {
 
 	public static class Wo extends AbstractWo {
 
-		private static final long serialVersionUID = 4800180927316707892L;
+		private static final long serialVersionUID = -4090679604631097945L;
+
+		private String formId;
 
-		private String id;
+		private String readFormId;
 
 		private String cacheTag;
 
-		public String getId() {
-			return id;
+		public String getFormId() {
+			return formId;
+		}
+
+		public void setFormId(String formId) {
+			this.formId = formId;
+		}
+
+		public String getReadFormId() {
+			return readFormId;
 		}
 
-		public void setId(String id) {
-			this.id = id;
+		public void setReadFormId(String readFormId) {
+			this.readFormId = readFormId;
 		}
 
 		public String getCacheTag() {

+ 63 - 22
o2server/x_cms_assemble_control/src/main/java/com/x/cms/assemble/control/jaxrs/form/V2LookupDocMobile.java

@@ -30,29 +30,49 @@ class V2LookupDocMobile extends BaseAction {
 	private static Logger logger = LoggerFactory.getLogger(V2LookupDocMobile.class);
 
 	private Form form = null;
+	private Form readForm = null;
 	private Wo wo = new Wo();
 
-	ActionResult<Wo> execute(EffectivePerson effectivePerson, String docId, String openMode) throws Exception {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String docId) throws Exception {
 
 		ActionResult<Wo> result = new ActionResult<>();
 
-		this.getDocForm(docId, openMode);
+		this.getDocForm(docId);
 
+		String formId = "";
+		String readFormId = "";
 		if (null != this.form) {
-			CacheKey cacheKey = new CacheKey(this.getClass(), this.form.getId());
+			formId = form.getId();
+			this.wo.setFormId(formId);
+		}
+		if (null != this.readForm) {
+			readFormId = readForm.getId();
+			this.wo.setReadFormId(readFormId);
+		}
+		if(StringUtils.isNotEmpty(formId) || StringUtils.isNotEmpty(readFormId)){
+			CacheKey cacheKey = new CacheKey(this.getClass(), formId, readFormId);
 			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
 			if (optional.isPresent()) {
 				this.wo = (Wo) optional.get();
 			} else {
 				List<String> list = new ArrayList<>();
-				CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.form.getProperties());
-				CompletableFuture<List<String>> relatedScriptFuture = this
-						.relatedScriptFuture(this.form.getProperties());
-				list.add(this.form.getId() + this.form.getUpdateTime().getTime());
-				list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
-				list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				if (null != this.form) {
+					CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.form.getProperties());
+					CompletableFuture<List<String>> relatedScriptFuture = this
+							.relatedScriptFuture(this.form.getProperties());
+					list.add(this.form.getId() + this.form.getUpdateTime().getTime());
+					list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
+					list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				}
+				if (null != this.readForm && !formId.equals(readFormId)) {
+					CompletableFuture<List<String>> relatedFormFuture = this.relatedFormFuture(this.readForm.getProperties());
+					CompletableFuture<List<String>> relatedScriptFuture = this
+							.relatedScriptFuture(this.readForm.getProperties());
+					list.add(this.readForm.getId() + this.readForm.getUpdateTime().getTime());
+					list.addAll(relatedFormFuture.get(10, TimeUnit.SECONDS));
+					list.addAll(relatedScriptFuture.get(10, TimeUnit.SECONDS));
+				}
 				list = list.stream().sorted().collect(Collectors.toList());
-				this.wo.setId(this.form.getId());
 				CRC32 crc = new CRC32();
 				crc.update(StringUtils.join(list, "#").getBytes());
 				this.wo.setCacheTag(crc.getValue() + "");
@@ -63,27 +83,38 @@ class V2LookupDocMobile extends BaseAction {
 		return result;
 	}
 
-	private void getDocForm(String docId, String openMode) throws Exception {
+	private void getDocForm(String docId) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			Business business = new Business(emc);
 			Document document = emc.fetch(docId, Document.class, ListTools.toList(JpaObject.id_FIELDNAME, Document.form_FIELDNAME,
 					Document.readFormId_FIELDNAME, Document.categoryId_FIELDNAME));
 			if (null != document) {
 				String formId = document.getForm();
-				if(FORM_OPEN_MODE_READ.equals(openMode)){
-					formId = document.getReadFormId();
+				String readFormId = document.getReadFormId();
+				if(StringUtils.isNotBlank(formId)) {
+					this.form = business.getFormFactory().pick(formId);
 				}
-				this.form = business.getFormFactory().pick(formId);
 				if (null == this.form) {
 					CategoryInfo categoryInfo = business.getCategoryInfoFactory().pick(document.getCategoryId());
 					if (null != categoryInfo) {
 						formId = categoryInfo.getFormId();
-						if(FORM_OPEN_MODE_READ.equals(openMode)){
-							formId = categoryInfo.getReadFormId();
-						}
 						this.form = business.getFormFactory().pick(formId);
 					}
 				}
+				if(StringUtils.isNotBlank(readFormId)) {
+					if(readFormId.equals(formId)){
+						this.readForm = this.form;
+					}else {
+						this.readForm = business.getFormFactory().pick(formId);
+					}
+				}
+				if (null == this.readForm) {
+					CategoryInfo categoryInfo = business.getCategoryInfoFactory().pick(document.getCategoryId());
+					if (null != categoryInfo) {
+						readFormId = categoryInfo.getReadFormId();
+						this.readForm = business.getFormFactory().pick(readFormId);
+					}
+				}
 			}
 		}
 	}
@@ -128,16 +159,26 @@ class V2LookupDocMobile extends BaseAction {
 
 		private static final long serialVersionUID = -955543425744298907L;
 
-		private String id;
+		private String formId;
+
+		private String readFormId;
 
 		private String cacheTag;
 
-		public String getId() {
-			return id;
+		public String getFormId() {
+			return formId;
+		}
+
+		public void setFormId(String formId) {
+			this.formId = formId;
+		}
+
+		public String getReadFormId() {
+			return readFormId;
 		}
 
-		public void setId(String id) {
-			this.id = id;
+		public void setReadFormId(String readFormId) {
+			this.readFormId = readFormId;
 		}
 
 		public String getCacheTag() {