提交 0844c47b 编写于 作者: O o2null

Merge branch 'feature/增加查询指定用户及关联的组织、角色、群组等信息' into 'wrdp'

[人员组织]增加查询指定用户及关联的组织、角色、群组等信息的接口

See merge request o2oa/o2oa!2376
package com.x.organization.assemble.express;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.persistence.EntityManager;
......@@ -10,6 +11,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.tools.ListTools;
import com.x.organization.assemble.express.factory.GroupFactory;
import com.x.organization.assemble.express.factory.IdentityFactory;
......@@ -27,6 +29,7 @@ import com.x.organization.core.entity.Person;
import com.x.organization.core.entity.Role;
import com.x.organization.core.entity.Role_;
import com.x.organization.core.entity.Unit;
import org.apache.commons.collections4.CollectionUtils;
public class Business {
......@@ -366,4 +369,28 @@ public class Business {
return this.person().listPersonDistinguishedNameSorted(expendUnitToPersonId(unitList));
}
public boolean hasAnyRole(EffectivePerson effectivePerson, String... roleFlags) throws Exception {
/** 如果不加这个xadmin会报错 */
if (effectivePerson.isManager()) {
return true;
}
Person person = this.person().pick(effectivePerson.getDistinguishedName());
if (null != person) {
List<String> groupIds = this.group().listSupNestedWithPerson(person.getId());
if (null != person) {
List<Role> roles = this.role().pick(Arrays.asList(roleFlags));
for (Role o : roles) {
if (o.getPersonList().contains(person.getId())) {
return true;
}
if (CollectionUtils.containsAny(o.getGroupList(), groupIds)) {
return true;
}
}
}
}
return false;
}
}
......@@ -68,11 +68,13 @@ class ActionListWithGroup extends BaseAction {
}
List<String> personIds = new ArrayList<>();
List<String> unitIds = new ArrayList<>();
List<String> identityIds = new ArrayList<>();
for (Group o : list) {
personIds.addAll(o.getPersonList());
if (ListTools.isNotEmpty(o.getUnitList())) {
unitIds.addAll(o.getUnitList());
}
identityIds.addAll(o.getIdentityList());
}
/* 先解析组织 */
List<Identity> identities = new ArrayList<>();
......@@ -91,6 +93,10 @@ class ActionListWithGroup extends BaseAction {
identities.add(o);
}
}
/* 最后把身份解析处理 */
identities.addAll(business.identity().pick(identityIds));
identities = ListTools.trim(identities, true, true);
Wo wo = new Wo();
wo.getIdentityList().addAll(ListTools.extractProperty(business.identity().sort(identities),
......@@ -98,4 +104,4 @@ class ActionListWithGroup extends BaseAction {
return wo;
}
}
\ No newline at end of file
}
......@@ -69,11 +69,13 @@ class ActionListWithGroupObject extends BaseAction {
}
List<String> personIds = new ArrayList<>();
List<String> unitIds = new ArrayList<>();
List<String> identityIds = new ArrayList<>();
for (Group o : list) {
personIds.addAll(o.getPersonList());
if (ListTools.isNotEmpty(o.getUnitList())) {
unitIds.addAll(o.getUnitList());
}
identityIds.addAll(o.getIdentityList());
}
/* 先解析组织 */
List<Identity> identities = new ArrayList<>();
......@@ -92,10 +94,14 @@ class ActionListWithGroupObject extends BaseAction {
identities.add(o);
}
}
/* 最后把身份解析处理 */
identities.addAll(business.identity().pick(identityIds));
identities = ListTools.trim(identities, true, true);
for (Identity o : identities) {
wos.add(this.convert(business, o, Wo.class));
}
return wos;
}
}
\ No newline at end of file
}
package com.x.organization.assemble.express.jaxrs.person;
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.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.config.Config;
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.organization.assemble.express.Business;
import com.x.organization.core.entity.*;
import org.apache.commons.collections4.set.ListOrderedSet;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;
import java.util.Optional;
class ActionGet extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
ActionResult<Wo> result = new ActionResult<>();
CacheKey cacheKey = new CacheKey(this.getClass(), flag);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((Wo) optional.get());
} else {
if (Config.token().isInitialManager(flag)) {
/** 如果是xadmin单独处理 */
Wo wo = new Wo();
Config.token().initialManagerInstance().copyTo(wo, "password");
result.setData(wo);
} else {
Person person = business.person().pick(flag);
if (null == person) {
throw new ExceptionPersonNotExist(flag);
}
Wo wo = Wo.copier.copy(person);
this.referencePersonAttribute(business, wo);
this.referenceIdentity(business, wo);
this.referenceRole(business, wo);
this.referenceGroup(business, wo);
CacheManager.put(cacheCategory, cacheKey, wo);
result.setData(wo);
}
}
this.hide(effectivePerson, business, result.getData());
return result;
}
}
private void referencePersonAttribute(Business business, Wo wo) throws Exception {
EntityManager em = business.entityManagerContainer().get(PersonAttribute.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PersonAttribute> cq = cb.createQuery(PersonAttribute.class);
Root<PersonAttribute> root = cq.from(PersonAttribute.class);
Predicate p = cb.equal(root.get(PersonAttribute_.person), wo.getId());
List<PersonAttribute> os = em.createQuery(cq.select(root).where(p)).getResultList();
List<WoPersonAttribute> wos = WoPersonAttribute.copier.copy(os);
wos = business.personAttribute().sort(wos);
wo.setWoPersonAttributeList(wos);
}
private void referenceIdentity(Business business, Wo wo) throws Exception {
EntityManager em = business.entityManagerContainer().get(Identity.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
Root<Identity> root = cq.from(Identity.class);
Predicate p = cb.equal(root.get(Identity_.person), wo.getId());
List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
List<WoIdentity> wos = WoIdentity.copier.copy(os);
wos = business.identity().sort(wos);
wo.setWoIdentityList(wos);
for (WoIdentity o : wo.getWoIdentityList()) {
this.referenceUnit(business, o);
this.referenceUnitDuty(business, o);
}
}
private void referenceRole(Business business, Wo wo) throws Exception {
EntityManager em = business.entityManagerContainer().get(Role.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Role> cq = cb.createQuery(Role.class);
Root<Role> root = cq.from(Role.class);
Predicate p = cb.isMember(wo.getId(), root.get(Role_.personList));
List<Role> os = em.createQuery(cq.select(root).where(p)).getResultList();
List<WoRole> wos = WoRole.copier.copy(os);
wos = business.role().sort(wos);
wo.setWoRoleList(wos);
}
private void referenceGroup(Business business, Wo wo) throws Exception {
EntityManager em = business.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Group> cq = cb.createQuery(Group.class);
Root<Group> root = cq.from(Group.class);
Predicate p = cb.isMember(wo.getId(), root.get(Group_.personList));
if(ListTools.isNotEmpty(wo.getWoIdentityList())){
List<String> identities = ListTools.extractField(wo.getWoIdentityList(), JpaObject.id_FIELDNAME, String.class, true, true);
p = cb.or(p, root.get(Group_.identityList).in(identities));
}
List<Group> os = em.createQuery(cq.select(root).where(p)).getResultList();
ListOrderedSet<Group> set = new ListOrderedSet<>();
os.stream().forEach(o -> {
set.add(o);
try {
set.addAll(business.group().listSupNestedObject(o));
} catch (Exception e) {
e.printStackTrace();
}
});
List<WoGroup> wos = WoGroup.copier.copy(set.asList());
wos = business.group().sort(wos);
wo.setWoGroupList(wos);
}
private void referenceUnit(Business business, WoIdentity woIdentity) throws Exception {
if (StringUtils.isNotEmpty(woIdentity.getUnit())) {
Unit unit = business.unit().pick(woIdentity.getUnit());
if (null != unit) {
WoUnit wo = WoUnit.copier.copy(unit);
woIdentity.setWoUnit(wo);
}
}
}
private void referenceUnitDuty(Business business, WoIdentity woIdentity) throws Exception {
EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
Root<UnitDuty> root = cq.from(UnitDuty.class);
Predicate p = cb.isMember(woIdentity.getId(), root.get(UnitDuty_.identityList));
List<UnitDuty> os = em.createQuery(cq.select(root).where(p)).getResultList();
List<WoUnitDuty> wos = WoUnitDuty.copier.copy(os);
wos = business.unitDuty().sort(wos);
for (WoUnitDuty woUnitDuty : wos) {
this.referenceUnit(business, woUnitDuty);
}
woIdentity.setWoUnitDutyList(wos);
}
private void referenceUnit(Business business, WoUnitDuty woUnitDuty) throws Exception {
if (StringUtils.isNotEmpty(woUnitDuty.getUnit())) {
Unit unit = business.unit().pick(woUnitDuty.getUnit());
if (null != unit) {
WoUnit wo = WoUnit.copier.copy(unit);
woUnitDuty.setWoUnit(wo);
}
}
}
public static class Wo extends Person {
private static final long serialVersionUID = -8456354949288335211L;
static WrapCopier<Person, Wo> copier = WrapCopierFactory.wo(Person.class, Wo.class, null,
person_fieldsInvisible);
@FieldDescribe("身份对象")
private List<WoIdentity> woIdentityList;
@FieldDescribe("角色对象")
private List<WoRole> woRoleList;
@FieldDescribe("群组对象")
private List<WoGroup> woGroupList;
@FieldDescribe("个人属性对象")
private List<WoPersonAttribute> woPersonAttributeList;
public List<WoIdentity> getWoIdentityList() {
return woIdentityList;
}
public void setWoIdentityList(List<WoIdentity> woIdentityList) {
this.woIdentityList = woIdentityList;
}
public List<WoRole> getWoRoleList() {
return woRoleList;
}
public void setWoRoleList(List<WoRole> woRoleList) {
this.woRoleList = woRoleList;
}
public List<WoGroup> getWoGroupList() {
return woGroupList;
}
public void setWoGroupList(List<WoGroup> woGroupList) {
this.woGroupList = woGroupList;
}
public List<WoPersonAttribute> getWoPersonAttributeList() {
return woPersonAttributeList;
}
public void setWoPersonAttributeList(List<WoPersonAttribute> woPersonAttributeList) {
this.woPersonAttributeList = woPersonAttributeList;
}
}
public static class WoIdentity extends Identity {
private static final long serialVersionUID = 6193615461099768815L;
static WrapCopier<Identity, WoIdentity> copier = WrapCopierFactory.wo(Identity.class, WoIdentity.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
@FieldDescribe("组织对象")
private WoUnit woUnit;
@FieldDescribe("组织职务对象")
private List<WoUnitDuty> woUnitDutyList;
public WoUnit getWoUnit() {
return woUnit;
}
public void setWoUnit(WoUnit woUnit) {
this.woUnit = woUnit;
}
public List<WoUnitDuty> getWoUnitDutyList() {
return woUnitDutyList;
}
public void setWoUnitDutyList(List<WoUnitDuty> woUnitDutyList) {
this.woUnitDutyList = woUnitDutyList;
}
}
public static class WoGroup extends Group {
private static final long serialVersionUID = 4503618773692247688L;
static WrapCopier<Group, WoGroup> copier = WrapCopierFactory.wo(Group.class, WoGroup.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
public static class WoRole extends Role {
private static final long serialVersionUID = -3903028273062897622L;
static WrapCopier<Role, WoRole> copier = WrapCopierFactory.wo(Role.class, WoRole.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
}
public static class WoUnit extends Unit {
private static final long serialVersionUID = 6172047743675016186L;
private Long subDirectUnitCount;
private Long subDirectIdentityCount;
static WrapCopier<Unit, WoUnit> copier = WrapCopierFactory.wo(Unit.class, WoUnit.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
public Long getSubDirectUnitCount() {
return subDirectUnitCount;
}
public void setSubDirectUnitCount(Long subDirectUnitCount) {
this.subDirectUnitCount = subDirectUnitCount;
}
public Long getSubDirectIdentityCount() {
return subDirectIdentityCount;
}
public void setSubDirectIdentityCount(Long subDirectIdentityCount) {
this.subDirectIdentityCount = subDirectIdentityCount;
}
}
public static class WoUnitDuty extends UnitDuty {
private static final long serialVersionUID = 3145496265299807549L;
@FieldDescribe("组织对象")
private WoUnit woUnit;
static WrapCopier<UnitDuty, WoUnitDuty> copier = WrapCopierFactory.wo(UnitDuty.class, WoUnitDuty.class, null,
ListTools.toList(JpaObject.FieldsInvisible));
public WoUnit getWoUnit() {
return woUnit;
}
public void setWoUnit(WoUnit woUnit) {
this.woUnit = woUnit;
}
}
public static class WoPersonAttribute extends PersonAttribute {
private static final long serialVersionUID = -3155093360276871418L;
static WrapCopier<PersonAttribute, WoPersonAttribute> copier = WrapCopierFactory.wo(PersonAttribute.class,
WoPersonAttribute.class, null, ListTools.toList(JpaObject.FieldsInvisible));
}
}
......@@ -31,7 +31,7 @@ class ActionListFilterPaging extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Predicate p = this.toFilterPredicate(business, wi);
List<Wo> wos = emc.fetchAscPaging(Person.class, Wo.copier, p, page, size, Person.pinyin_FIELDNAME);
this.hide(effectivePerson, business, wos);
result.setData(wos);
result.setCount(emc.count(Person.class, p));
return result;
......
......@@ -3,6 +3,11 @@ package com.x.organization.assemble.express.jaxrs.person;
import java.util.ArrayList;
import java.util.List;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.organization.OrganizationDefinition;
import com.x.base.core.project.tools.ListTools;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.project.annotation.FieldDescribe;
......@@ -74,4 +79,35 @@ class BaseAction extends StandardJaxrsAction {
}
}
\ No newline at end of file
protected static List<String> person_fieldsInvisible = ListTools.toList(JpaObject.FieldsInvisible,
Person.password_FIELDNAME, Person.icon_FIELDNAME);
protected <T extends Person> void hide(EffectivePerson effectivePerson, Business business, List<T> list)
throws Exception {
if (!effectivePerson.isManager() && (!effectivePerson.isCipher())) {
if (!business.hasAnyRole(effectivePerson, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.Manager)) {
for (Person o : list) {
if (BooleanUtils.isTrue(o.getHiddenMobile()) && (!StringUtils
.equals(effectivePerson.getDistinguishedName(), o.getDistinguishedName()))) {
o.setMobile(Person.HIDDENMOBILESYMBOL);
}
}
}
}
}
protected <T extends Person> void hide(EffectivePerson effectivePerson, Business business, T t)
throws Exception {
if (!effectivePerson.isManager() && (!effectivePerson.isCipher())) {
if (!business.hasAnyRole(effectivePerson, OrganizationDefinition.OrganizationManager,
OrganizationDefinition.Manager)) {
if (BooleanUtils.isTrue(t.getHiddenMobile())
&& (!StringUtils.equals(effectivePerson.getDistinguishedName(), t.getDistinguishedName()))) {
t.setMobile(Person.HIDDENMOBILESYMBOL);
}
}
}
}
}
package com.x.organization.assemble.express.jaxrs.person;
import com.x.base.core.project.exception.PromptException;
class ExceptionPersonNotExist extends PromptException {
private static final long serialVersionUID = -3439770681867963457L;
ExceptionPersonNotExist(String name) {
super("用户: {} 不存在.", name);
}
}
......@@ -27,6 +27,24 @@ public class PersonAction extends StandardJaxrsAction {
private static Logger logger = LoggerFactory.getLogger(PersonAction.class);
@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 = "判断个人是否拥有指定角色中的一个或者多个", action = ActionHasRole.class)
@POST
@Path("has/role")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册