提交 4063663b 编写于 作者: O o2null

Merge branch '优化人员、组织和身份查询,支持根据名称查询' into 'develop'

优化人员、组织和身份查询,支持根据名称查询

See merge request o2oa/o2oa!1277
package com.x.organization.assemble.express.factory;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
......@@ -105,6 +102,44 @@ public class PersonFactory extends AbstractFactory {
return list;
}
public List<Person> pick(List<String> flags, Boolean useNameFind) throws Exception {
List<Person> list = new ArrayList<>();
for (String str : ListTools.trim(flags, true, false)) {
CacheKey cacheKey = new CacheKey(Person.class.getName(), str);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
list.add((Person) optional.get());
} else {
Person o = this.pickObject(str);
if (null != o) {
CacheManager.put(cacheCategory, cacheKey, o);
list.add(o);
}
}
}
if(list.isEmpty() && BooleanUtils.isTrue(useNameFind)){
list = this.listWithName(flags);
}
return list;
}
public List<Person> listWithName(List<String> names) throws Exception {
if(ListTools.isEmpty(names)){
return Collections.EMPTY_LIST;
}
EntityManager em = this.entityManagerContainer().get(Person.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Person> cq = cb.createQuery(Person.class);
Root<Person> root = cq.from(Person.class);
Predicate p;
if(names.size() > 1){
p = root.get(Person_.name).in(names);
}else{
p = cb.equal(root.get(Person_.name), names.get(0));
}
return em.createQuery(cq.select(root).where(p)).getResultList().stream().distinct().collect(Collectors.toList());
}
public <T extends Person> List<T> sort(List<T> list) {
list = list.stream().sorted(
Comparator.comparing(Person::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(
......
package com.x.organization.assemble.express.factory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
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 org.apache.commons.lang3.StringUtils;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.cache.Cache.CacheCategory;
import com.x.base.core.project.cache.Cache.CacheKey;
......@@ -28,6 +11,17 @@ import com.x.organization.assemble.express.Business;
import com.x.organization.core.entity.PersistenceProperties;
import com.x.organization.core.entity.Unit;
import com.x.organization.core.entity.Unit_;
import org.apache.commons.lang3.BooleanUtils;
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.*;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
public class UnitFactory extends AbstractFactory {
......@@ -121,6 +115,44 @@ public class UnitFactory extends AbstractFactory {
return list;
}
public List<Unit> pick(List<String> flags, Boolean useNameFind) throws Exception {
List<Unit> list = new ArrayList<>();
for (String str : flags) {
CacheKey cacheKey = new CacheKey(Unit.class.getName(), str);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
list.add((Unit) optional.get());
} else {
Unit o = this.pickObject(str);
if (null != o) {
CacheManager.put(cacheCategory, cacheKey, o);
list.add(o);
}
}
}
if(list.isEmpty() && BooleanUtils.isTrue(useNameFind)){
list = this.listWithName(flags);
}
return list;
}
public List<Unit> listWithName(List<String> names) throws Exception {
if(ListTools.isEmpty(names)){
return Collections.EMPTY_LIST;
}
EntityManager em = this.entityManagerContainer().get(Unit.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
Root<Unit> root = cq.from(Unit.class);
Predicate p;
if(names.size() > 1){
p = root.get(Unit_.name).in(names);
}else{
p = cb.equal(root.get(Unit_.name), names.get(0));
}
return em.createQuery(cq.select(root).where(p)).getResultList().stream().distinct().collect(Collectors.toList());
}
public <T extends Unit> List<T> sort(List<T> list) throws Exception {
if (Config.person().getPersonUnitOrderByAsc()) {
list = list.stream().sorted(Comparator.comparing(Unit::getLevel, Comparator.nullsLast(Integer::compareTo))
......
......@@ -34,7 +34,7 @@ class ActionListWithPerson extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((Wo) optional.get());
......@@ -52,6 +52,9 @@ class ActionListWithPerson extends BaseAction {
@FieldDescribe("个人")
private List<String> personList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getPersonList() {
return personList;
}
......@@ -60,6 +63,13 @@ class ActionListWithPerson extends BaseAction {
this.personList = personList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends WoIdentityAbstract {
......@@ -67,7 +77,7 @@ class ActionListWithPerson extends BaseAction {
}
private Wo list(Business business, Wi wi) throws Exception {
List<Person> os = business.person().pick(wi.getPersonList());
List<Person> os = business.person().pick(wi.getPersonList(), wi.getUseNameFind());
List<String> personIds = ListTools.extractProperty(os, JpaObject.id_FIELDNAME, String.class, true, true);
EntityManager em = business.entityManagerContainer().get(Identity.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
......@@ -82,4 +92,4 @@ class ActionListWithPerson extends BaseAction {
return wo;
}
}
\ No newline at end of file
}
......@@ -35,7 +35,7 @@ class ActionListWithPersonObject extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<List<Wo>> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>) optional.get());
......@@ -52,6 +52,9 @@ class ActionListWithPersonObject extends BaseAction {
@FieldDescribe("个人")
private List<String> personList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getPersonList() {
return personList;
}
......@@ -59,6 +62,14 @@ class ActionListWithPersonObject extends BaseAction {
public void setPersonList(List<String> personList) {
this.personList = personList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends com.x.base.core.project.organization.Identity {
......@@ -67,7 +78,7 @@ class ActionListWithPersonObject extends BaseAction {
private List<Wo> list(Business business, Wi wi) throws Exception {
List<Wo> wos = new ArrayList<>();
List<String> personMajorIds = new ArrayList<>();
List<Person> os = business.person().pick(wi.getPersonList());
List<Person> os = business.person().pick(wi.getPersonList(), wi.getUseNameFind());
List<String> personIds = ListTools.extractProperty(os, JpaObject.id_FIELDNAME, String.class, true, true);
List<Identity> personMajors = business.identity().listMajorOfPerson(business, personIds);
if (ListTools.isNotEmpty(personMajors)) {
......@@ -92,4 +103,4 @@ class ActionListWithPersonObject extends BaseAction {
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.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.jaxrs.WrapString;
import com.x.organization.assemble.express.Business;
import com.x.organization.core.entity.Person;
import org.apache.commons.lang3.StringUtils;
import java.util.Optional;
class ActionGetMobile 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);
CacheKey cacheKey = new CacheKey(this.getClass(), flag);
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((Wo) optional.get());
} else {
Wo wo = new Wo();
Person person = business.person().pick(flag);
if(person != null) {
wo.setValue(person.getMobile());
}
CacheManager.put(cacheCategory, cacheKey, wo);
result.setData(wo);
}
return result;
}
}
public static class Wo extends WrapString {
}
}
......@@ -24,7 +24,7 @@ class ActionList extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((Wo) optional.get());
......@@ -42,6 +42,9 @@ class ActionList extends BaseAction {
@FieldDescribe("个人")
private List<String> personList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getPersonList() {
return personList;
}
......@@ -50,6 +53,13 @@ class ActionList extends BaseAction {
this.personList = personList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends WoPersonListAbstract {
......@@ -57,11 +67,11 @@ class ActionList extends BaseAction {
}
private Wo list(Business business, Wi wi) throws Exception {
List<Person> os = business.person().pick(wi.getPersonList());
List<Person> os = business.person().pick(wi.getPersonList(), wi.getUseNameFind());
List<String> list = ListTools.extractProperty(os, "distinguishedName", String.class, true, true);
Wo wo = new Wo();
wo.getPersonList().addAll(list);
return wo;
}
}
\ No newline at end of file
}
......@@ -15,16 +15,16 @@ import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.organization.assemble.express.Business;
import com.x.organization.core.entity.Person;
import org.apache.commons.lang3.BooleanUtils;
class ActionListObject extends BaseAction {
@SuppressWarnings("unchecked")
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<List<Wo>> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getPersonList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>) optional.get());
......@@ -42,6 +42,9 @@ class ActionListObject extends BaseAction {
@FieldDescribe("个人")
private List<String> personList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getPersonList() {
return personList;
}
......@@ -50,6 +53,14 @@ class ActionListObject extends BaseAction {
this.personList = personList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends com.x.base.core.project.organization.Person {
......@@ -66,7 +77,15 @@ class ActionListObject extends BaseAction {
wos.add(wo);
}
}
if(wos.isEmpty() && BooleanUtils.isTrue(wi.getUseNameFind())){
List<Person> os = business.person().listWithName(wi.getPersonList());
for(Person o : os){
Wo wo = this.convert(business, o, Wo.class);
wo.setMatchKey(o.getName());
wos.add(wo);
}
}
return wos;
}
}
\ No newline at end of file
}
......@@ -71,6 +71,24 @@ public class PersonAction extends StandardJaxrsAction {
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@JaxrsMethodDescribe(value = "获取个人手机号码.", action = ActionGetMobile.class)
@GET
@Path("mobile/{flag}")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void getMobile(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("人员标识") @PathParam("flag") String flag) {
ActionResult<ActionGetMobile.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionGetMobile().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")
......
......@@ -24,7 +24,7 @@ class ActionList extends BaseAction {
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<Wo> result = new ActionResult<>();
Business business = new Business(emc);
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getUnitList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getUnitList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((Wo) optional.get());
......@@ -42,6 +42,9 @@ class ActionList extends BaseAction {
@FieldDescribe("组织")
private List<String> unitList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getUnitList() {
return unitList;
}
......@@ -50,6 +53,13 @@ class ActionList extends BaseAction {
this.unitList = unitList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends WoUnitListAbstract {
......@@ -57,11 +67,11 @@ class ActionList extends BaseAction {
}
private Wo list(Business business, Wi wi) throws Exception {
List<Unit> os = business.unit().pick(wi.getUnitList());
List<Unit> os = business.unit().pick(wi.getUnitList(), wi.getUseNameFind());
List<String> list = ListTools.extractProperty(os, "distinguishedName", String.class, true, true);
Wo wo = new Wo();
wo.getUnitList().addAll(list);
return wo;
}
}
\ No newline at end of file
}
......@@ -10,6 +10,7 @@ import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonElement;
......@@ -40,7 +41,7 @@ class ActionListObject extends BaseAction {
logger.debug(effectivePerson.getDistinguishedName());
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
ActionResult<List<Wo>> result = new ActionResult<>();
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getUnitList());
CacheKey cacheKey = new CacheKey(this.getClass(), wi.getUnitList(), wi.getUseNameFind());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>) optional.get());
......@@ -58,6 +59,9 @@ class ActionListObject extends BaseAction {
@FieldDescribe("组织")
private List<String> unitList = new ArrayList<>();
@FieldDescribe("是否需要根据名称查找,默认false")
private Boolean useNameFind = false;
public List<String> getUnitList() {
return unitList;
}
......@@ -66,6 +70,14 @@ class ActionListObject extends BaseAction {
this.unitList = unitList;
}
public Boolean getUseNameFind() {
return useNameFind;
}
public void setUseNameFind(Boolean useNameFind) {
this.useNameFind = useNameFind;
}
}
public static class Wo extends Unit {
......@@ -115,8 +127,14 @@ class ActionListObject extends BaseAction {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
for (String str : wi.getUnitList()) {
Unit o = business.unit().pick(str);
if (o != null) {
List<Unit> os = new ArrayList<>();
Unit unit = business.unit().pick(str);
if(unit != null){
os.add(unit);
}else if(BooleanUtils.isTrue(wi.getUseNameFind())){
os.addAll(business.unit().listWithName(List.of(str)));
}
for(Unit o : os){
Wo wo = Wo.copier.copy(o);
wo.setMatchKey(str);
if (StringUtils.isNotEmpty(wo.getSuperior())) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册