|
|
@@ -137,7 +137,8 @@ public class UserService {
|
|
|
if (userInfo != null) {
|
|
|
// 插入上级
|
|
|
if (ObjectUtil.isNotNull(parent)) {
|
|
|
- if (this.getParent(parent, userInfo)) {
|
|
|
+// if (this.getParent(parent, userInfo)) {
|
|
|
+ if (ObjectUtil.isNull(userInfo.getParent())) {
|
|
|
userInfo.setParent(parent);
|
|
|
}
|
|
|
// 邀请成为创客
|
|
|
@@ -263,7 +264,7 @@ public class UserService {
|
|
|
User user = userRepo.findById(SecurityUtils.getAuthenticatedUser().getId())
|
|
|
.orElseThrow(new BusinessException("用户不存在"));
|
|
|
user.setPhone(phoneNoInfo.getPhoneNumber());
|
|
|
- if (StrUtil.isNotBlank(phoneNoInfo.getPhoneNumber())){
|
|
|
+ if (StrUtil.isNotBlank(phoneNoInfo.getPhoneNumber())) {
|
|
|
user.setUsername(phoneNoInfo.getPhoneNumber());
|
|
|
}
|
|
|
user = userRepo.save(user);
|
|
|
@@ -307,6 +308,7 @@ public class UserService {
|
|
|
Set<User> users = new HashSet<>();
|
|
|
// 如果是企业创始人,查出下级所有推广
|
|
|
if (user.getTeamFounder()) {
|
|
|
+// if (user.getAuthorities().contains(Authority.get(AuthorityName.ROLE_CREATOR))) {
|
|
|
List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(user.getCompanyId());
|
|
|
List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
|
users.addAll(userRepo.findAllByParentInAndDelFalse(collect));
|
|
|
@@ -321,6 +323,7 @@ public class UserService {
|
|
|
*/
|
|
|
public Page<PromotionDTO> myPromotion(PageQuery pageQuery, Long userId) {
|
|
|
User parent = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+// if (parent.getAuthorities().contains(Authority.get(AuthorityName.ROLE_CREATOR))) {
|
|
|
if (parent.getTeamFounder()) {
|
|
|
List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(parent.getCompanyId());
|
|
|
Map<Long, User> userMap = employees.stream().collect(Collectors.toMap(User::getId, user -> user));
|
|
|
@@ -425,6 +428,7 @@ public class UserService {
|
|
|
|
|
|
/*
|
|
|
捞所有下级id
|
|
|
+ 互为上级死循环
|
|
|
*/
|
|
|
public List<Long> childrenId(Long userId) {
|
|
|
List<Long> users = userRepo.findIdByParentAndDelFalse(userId);
|
|
|
@@ -439,10 +443,10 @@ public class UserService {
|
|
|
/*
|
|
|
下级
|
|
|
*/
|
|
|
- public Page<User> children(PageQuery pageQuery) {
|
|
|
+ public Page<UserDTO> children(PageQuery pageQuery) {
|
|
|
Map<String, Object> query = pageQuery.getQuery();
|
|
|
|
|
|
- Object userId = query.get("userId");
|
|
|
+ Object userId = query.get("parent");
|
|
|
Long parent = 0L;
|
|
|
if (userId instanceof String) {
|
|
|
String of = String.valueOf(userId);
|
|
|
@@ -452,21 +456,29 @@ public class UserService {
|
|
|
Integer of = (Integer) userId;
|
|
|
parent = Long.valueOf(of);
|
|
|
}
|
|
|
+ if (userId instanceof Long) {
|
|
|
+ parent = (Long) userId;
|
|
|
+ }
|
|
|
|
|
|
- List<Long> users = userRepo.findIdByParentAndDelFalse(parent);
|
|
|
-
|
|
|
- List<Long> children = new ArrayList<>(users);
|
|
|
- while (CollUtil.isNotEmpty(users)) {
|
|
|
- users = userRepo.findIdByParentInAndDelFalse(users);
|
|
|
+// List<Long> users = userRepo.findIdByParentAndDelFalse(parent);
|
|
|
+ List<User> users;
|
|
|
+ List<Long> ids = Collections.singletonList(parent);
|
|
|
+// List<Long> children = new ArrayList<>(users);
|
|
|
+ List<User> children = new ArrayList<>();
|
|
|
+ while (CollUtil.isNotEmpty(ids)) {
|
|
|
+ users = userRepo.findAllByParentInAndDelFalse(ids);
|
|
|
+ ids = users.stream().map(User::getId).collect(Collectors.toList());
|
|
|
children.addAll(users);
|
|
|
}
|
|
|
|
|
|
+ Map<Long, String> parentMap = children.stream().collect(Collectors.toMap(User::getId, User::getNickname));
|
|
|
+
|
|
|
query.remove("parent");
|
|
|
return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
- and.add(root.in(children));
|
|
|
+ and.add(root.get("parent").in(parentMap.keySet()));
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery)).map(user -> new UserDTO(user, parentMap.get(user.getParent())));
|
|
|
}
|
|
|
|
|
|
public String shareImg(Long userId) throws IOException, WxErrorException {
|