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

增加校验身份是否是指定组织的成员接口;
增加校验用户是否在指定组织中注册身份接口;

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

+ 104 - 0
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/unit/ActionHasIdentity.java

@@ -0,0 +1,104 @@
+package com.x.organization.assemble.express.jaxrs.unit;
+
+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.project.annotation.FieldDescribe;
+import com.x.base.core.project.cache.Cache.CacheKey;
+import com.x.base.core.project.cache.CacheManager;
+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.jaxrs.WrapBoolean;
+import com.x.organization.assemble.express.Business;
+import com.x.organization.core.entity.Identity;
+import com.x.organization.core.entity.Unit;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Optional;
+
+class ActionHasIdentity extends BaseAction {
+
+	/*** 校验身份是否是指定组织的成员 */
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<Wo> result = new ActionResult<>();
+			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+			Business business = new Business(emc);
+			CacheKey cacheKey = new CacheKey(this.getClass(), wi.getIdentity(), wi.getUnit(), wi.getRecursive());
+			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
+			if (optional.isPresent()) {
+				result.setData((Wo) optional.get());
+			} else {
+				Wo wo = new Wo();
+				wo.setValue(this.hasIdentity(business, wi));
+				CacheManager.put(cacheCategory, cacheKey, wo);
+				result.setData(wo);
+			}
+			return result;
+		}
+	}
+
+	public static class Wi extends GsonPropertyObject {
+
+		@FieldDescribe("*身份")
+		private String identity;
+
+		@FieldDescribe("*组织")
+		private String unit;
+
+		@FieldDescribe("*是否递归查找组织(true|false)")
+		private Boolean recursive = true;
+
+		public String getIdentity() {
+			return identity;
+		}
+
+		public void setIdentity(String identity) {
+			this.identity = identity;
+		}
+
+		public String getUnit() {
+			return unit;
+		}
+
+		public void setUnit(String unit) {
+			this.unit = unit;
+		}
+
+		public Boolean getRecursive() {
+			return recursive;
+		}
+
+		public void setRecursive(Boolean recursive) {
+			this.recursive = recursive;
+		}
+	}
+
+	public static class Wo extends WrapBoolean {
+	}
+
+	private boolean hasIdentity(Business business, Wi wi) throws Exception {
+		boolean result = false;
+
+		if(StringUtils.isNotBlank(wi.getIdentity()) && StringUtils.isNotBlank(wi.getUnit())) {
+			Identity identity = business.identity().pick(wi.getIdentity());
+			Unit unit = business.unit().pick(wi.getUnit());
+			if (identity != null && unit != null) {
+				if (unit.getId().equals(identity.getUnit())) {
+					result = true;
+				} else if (BooleanUtils.isTrue(wi.getRecursive())) {
+					List<String> units = business.unit().listSupNested(identity.getUnit());
+					if (units.contains(unit.getId())) {
+						result = true;
+					}
+				}
+			}
+		}
+
+		return result;
+	}
+
+}

+ 113 - 0
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/unit/ActionHasPerson.java

@@ -0,0 +1,113 @@
+package com.x.organization.assemble.express.jaxrs.unit;
+
+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.project.annotation.FieldDescribe;
+import com.x.base.core.project.cache.Cache.CacheKey;
+import com.x.base.core.project.cache.CacheManager;
+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.jaxrs.WrapBoolean;
+import com.x.base.core.project.tools.ListTools;
+import com.x.organization.assemble.express.Business;
+import com.x.organization.core.entity.Identity;
+import com.x.organization.core.entity.Person;
+import com.x.organization.core.entity.Unit;
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Optional;
+
+class ActionHasPerson extends BaseAction {
+
+	/*** 校验用户是否在指定组织中注册身份 */
+	ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			ActionResult<Wo> result = new ActionResult<>();
+			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
+			Business business = new Business(emc);
+			CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPerson(), wi.getUnit(), wi.getRecursive());
+			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
+			if (optional.isPresent()) {
+				result.setData((Wo) optional.get());
+			} else {
+				Wo wo = new Wo();
+				wo.setValue(this.hasIdentity(business, wi));
+				CacheManager.put(cacheCategory, cacheKey, wo);
+				result.setData(wo);
+			}
+			return result;
+		}
+	}
+
+	public static class Wi extends GsonPropertyObject {
+
+		@FieldDescribe("*用户")
+		private String person;
+
+		@FieldDescribe("*组织")
+		private String unit;
+
+		@FieldDescribe("*是否递归查找组织(true|false)")
+		private Boolean recursive = true;
+
+		public String getPerson() {
+			return person;
+		}
+
+		public void setPerson(String person) {
+			this.person = person;
+		}
+
+		public String getUnit() {
+			return unit;
+		}
+
+		public void setUnit(String unit) {
+			this.unit = unit;
+		}
+
+		public Boolean getRecursive() {
+			return recursive;
+		}
+
+		public void setRecursive(Boolean recursive) {
+			this.recursive = recursive;
+		}
+	}
+
+	public static class Wo extends WrapBoolean {
+	}
+
+	private boolean hasIdentity(Business business, Wi wi) throws Exception {
+		boolean result = false;
+
+		if(StringUtils.isNotBlank(wi.getPerson()) && StringUtils.isNotBlank(wi.getUnit())) {
+			Person person = business.person().pick(wi.getPerson());
+			if(person!=null) {
+				List<Identity> identityList = business.identity().listByPerson(person.getId());
+				Unit unit = business.unit().pick(wi.getUnit());
+				if (identityList != null && !identityList.isEmpty() && unit != null) {
+					List<String> units = ListTools.extractProperty(identityList, Identity.unit_FIELDNAME, String.class, true, true);
+					if (units.contains(unit.getId())) {
+						result = true;
+					} else if (BooleanUtils.isTrue(wi.getRecursive())) {
+						for (String unitId : units){
+							List<String> units2 = business.unit().listSupNested(unitId);
+							if (units2.contains(unit.getId())) {
+								result = true;
+								break;
+							}
+						}
+					}
+				}
+			}
+		}
+
+		return result;
+	}
+
+}

+ 36 - 0
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/unit/UnitAction.java

@@ -585,4 +585,40 @@ public class UnitAction extends StandardJaxrsAction {
 		}
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
+
+	@JaxrsMethodDescribe(value = "校验身份是否是指定组织的成员.", action = ActionHasIdentity.class)
+	@POST
+	@Path("check/unit/has/identity")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void checkHasIdentity(@Suspended final AsyncResponse asyncResponse,
+								 @Context HttpServletRequest request, JsonElement jsonElement) {
+		ActionResult<ActionHasIdentity.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionHasIdentity().execute(effectivePerson, jsonElement);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
+
+	@JaxrsMethodDescribe(value = "校验用户是否在指定组织中注册身份.", action = ActionHasPerson.class)
+	@POST
+	@Path("check/unit/has/person")
+	@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void checkHasPerson(@Suspended final AsyncResponse asyncResponse,
+								 @Context HttpServletRequest request, JsonElement jsonElement) {
+		ActionResult<ActionHasPerson.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionHasPerson().execute(effectivePerson, jsonElement);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
 }