Commit f7d14172 authored by zhouqian's avatar zhouqian
parents 5d5a81e1 9d82b485
...@@ -234,6 +234,7 @@ public class InnerController { ...@@ -234,6 +234,7 @@ public class InnerController {
for (Contact c : contacts) { for (Contact c : contacts) {
c.setId(null); c.setId(null);
c.setUserId(userId); c.setUserId(userId);
c.setRelation(c.getRelation() == null ? Relation.OTHER : c.getRelation());
c.setCreatedAt(now); c.setCreatedAt(now);
c.setUpdateAt(now); c.setUpdateAt(now);
} }
......
...@@ -10,6 +10,7 @@ import org.springframework.data.jpa.domain.Specification; ...@@ -10,6 +10,7 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.criteria.*; import javax.persistence.criteria.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -47,22 +48,21 @@ public class UserDetailServiceImpl implements IUserDetailService { ...@@ -47,22 +48,21 @@ public class UserDetailServiceImpl implements IUserDetailService {
} }
private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) { private Specification<UserDetail> getSpecification(String name, String phoneNo, String idNo) {
List<Predicate> list = new ArrayList<>();
Specification<UserDetail> specification = new Specification<UserDetail>() { Specification<UserDetail> specification = new Specification<UserDetail>() {
@Override @Override
public Predicate toPredicate(Root<UserDetail> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) { public Predicate toPredicate(Root<UserDetail> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
if (!StringUtils.isEmpty(name)) { if (!StringUtils.isEmpty(name)) {
Path<String> namePath = root.get("name"); list.add(criteriaBuilder.equal(root.get("name").as(String.class), name));
criteriaQuery.where(criteriaBuilder.equal(namePath, name));
} }
if (!StringUtils.isEmpty(phoneNo)) { if (!StringUtils.isEmpty(phoneNo)) {
Path<String> phonePath = root.get("phoneNo"); list.add(criteriaBuilder.equal(root.get("phoneNo").as(String.class), phoneNo));
criteriaQuery.where(criteriaBuilder.equal(phonePath, phoneNo));
} }
if (!StringUtils.isEmpty(idNo)) { if (!StringUtils.isEmpty(idNo)) {
Path<String> idNoPath = root.get("idNo"); list.add(criteriaBuilder.equal(root.get("idNo").as(String.class), idNo));
criteriaQuery.where(criteriaBuilder.equal(idNoPath, idNo));
} }
return null; Predicate[] p = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(p));
} }
}; };
return specification; return specification;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment