Преглед изворни кода

Merge branch 'feature/数据中心自建表增加分页接口' into 'wrdp'

[数据中心]自建表增加分页接口

See merge request o2oa/o2oa!2128
o2null пре 5 година
родитељ
комит
cd49ed0f87

+ 73 - 0
o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/table/ActionGet.java

@@ -0,0 +1,73 @@
+package com.x.query.assemble.surface.jaxrs.table;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.JpaObject;
+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.exception.ExceptionEntityNotExist;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.query.assemble.surface.Business;
+import com.x.query.core.entity.Query;
+import com.x.query.core.entity.schema.Table;
+
+class ActionGet extends BaseAction {
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<Wo> result = new ActionResult<>();
+			Business business = new Business(emc);
+			Table table = emc.flag(flag, Table.class);
+			if (null == table) {
+				throw new ExceptionEntityNotExist(flag, Table.class);
+			}
+			Query query = business.entityManagerContainer().flag(table.getQuery(), Query.class);
+			if (null == query) {
+				throw new ExceptionEntityNotExist(table.getQuery(), Query.class);
+			}
+			if (!business.readable(effectivePerson, query)) {
+				throw new ExceptionAccessDenied(effectivePerson, query);
+			}
+			if (!business.readable(effectivePerson, table)) {
+				throw new ExceptionAccessDenied(effectivePerson, table);
+			}
+			Wo wo = Wo.copier.copy(table);
+			wo.setQueryName(query.getName());
+			wo.setQueryAlias(query.getAlias());
+			result.setData(wo);
+			return result;
+		}
+	}
+
+	public static class Wo extends Table {
+
+		private static final long serialVersionUID = -5755898083219447939L;
+
+		static WrapCopier<Table, Wo> copier = WrapCopierFactory.wo(Table.class, Wo.class, null,
+				JpaObject.FieldsInvisible);
+
+		@FieldDescribe("查询应用名称.")
+		private String queryName;
+
+		@FieldDescribe("查询应用别名.")
+		private String queryAlias;
+
+		public String getQueryName() {
+			return queryName;
+		}
+
+		public void setQueryName(String queryName) {
+			this.queryName = queryName;
+		}
+
+		public String getQueryAlias() {
+			return queryAlias;
+		}
+
+		public void setQueryAlias(String queryAlias) {
+			this.queryAlias = queryAlias;
+		}
+	}
+}

+ 79 - 0
o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/table/ActionListPaging.java

@@ -0,0 +1,79 @@
+package com.x.query.assemble.surface.jaxrs.table;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.JpaObject;
+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.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.Predicate;
+import java.util.List;
+
+import com.x.query.assemble.surface.Business;
+import com.x.query.core.entity.Query;
+import com.x.query.core.entity.schema.Table;
+
+class ActionListPaging extends BaseAction {
+	ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, Integer page, Integer size) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<List<Wo>> result = new ActionResult<>();
+			Business business = new Business(emc);
+			if (!business.editable(effectivePerson, new Table())) {
+				throw new ExceptionAccessDenied(effectivePerson.getDistinguishedName());
+			}
+			EntityManager em = emc.get(Table.class);
+			CriteriaBuilder cb = em.getCriteriaBuilder();
+			Predicate p = cb.conjunction();
+			List<Wo> wos = emc.fetchDescPaging(Table.class, Wo.copier, p, page, size, Table.sequence_FIELDNAME);
+			wos.stream().forEach(wo -> {
+				try {
+					Query query = emc.find(wo.getQuery(), Query.class);
+					if(query != null){
+						wo.setQueryName(query.getName());
+						wo.setQueryAlias(query.getAlias());
+					}
+				} catch (Exception e) {
+				}
+			});
+			result.setData(wos);
+			result.setCount(emc.count(Table.class, p));
+			return result;
+		}
+	}
+
+	public static class Wo extends Table {
+
+		private static final long serialVersionUID = -2529024915990955519L;
+
+		static WrapCopier<Table, Wo> copier = WrapCopierFactory.wo(Table.class, Wo.class,
+				JpaObject.singularAttributeField(Table.class, true, true), null);
+
+		@FieldDescribe("查询应用名称.")
+		private String queryName;
+
+		@FieldDescribe("查询应用别名.")
+		private String queryAlias;
+
+		public String getQueryName() {
+			return queryName;
+		}
+
+		public void setQueryName(String queryName) {
+			this.queryName = queryName;
+		}
+
+		public String getQueryAlias() {
+			return queryAlias;
+		}
+
+		public void setQueryAlias(String queryAlias) {
+			this.queryAlias = queryAlias;
+		}
+	}
+}

+ 37 - 0
o2server/x_query_assemble_surface/src/main/java/com/x/query/assemble/surface/jaxrs/table/TableAction.java

@@ -244,4 +244,41 @@ public class TableAction extends StandardJaxrsAction {
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
 
+	@JaxrsMethodDescribe(value = "根据标识获取表.", action = ActionGet.class)
+	@GET
+	@Path("{flag}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void get(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+					@JaxrsParameterDescribe("标识") @PathParam("flag") String flag) {
+		ActionResult<ActionGet.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionGet().execute(effectivePerson, flag);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
+	@JaxrsMethodDescribe(value = "分页列示Table对象.", action = ActionListPaging.class)
+	@POST
+	@Path("list/paging/{page}/size/{size}")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void listPaging(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
+						   @JaxrsParameterDescribe("分页") @PathParam("page") Integer page,
+						   @JaxrsParameterDescribe("每页数量") @PathParam("size") Integer size) {
+		ActionResult<List<ActionListPaging.Wo>> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionListPaging().execute(effectivePerson, page, size);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
 }