|
|
@@ -4,10 +4,12 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.jiashanxia.config.Constants;
|
|
|
import com.izouma.jiashanxia.domain.User;
|
|
|
import com.izouma.jiashanxia.dto.PageQuery;
|
|
|
+import com.izouma.jiashanxia.dto.PromotionDTO;
|
|
|
import com.izouma.jiashanxia.dto.UserRegister;
|
|
|
import com.izouma.jiashanxia.enums.AuthorityName;
|
|
|
import com.izouma.jiashanxia.enums.TransactionType;
|
|
|
@@ -255,20 +257,56 @@ public class UserService {
|
|
|
我的推广
|
|
|
移除员工:推广列表下员工的推广就会没有
|
|
|
*/
|
|
|
- public Page<User> myPromotion(PageQuery pageQuery, Long userId) {
|
|
|
- User user = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ public Page<PromotionDTO> myPromotion(PageQuery pageQuery, Long userId) {
|
|
|
+// User parent = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+// return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+// List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
+// if (parent.getTeamFounder()) {
|
|
|
+// List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(parent.getCompanyId());
|
|
|
+// List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
|
+// and.add(root.get("parent").in(collect));
|
|
|
+// } else {
|
|
|
+// and.add(criteriaBuilder.equal(root.get("parent"), userId));
|
|
|
+// }
|
|
|
+// return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+// }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+
|
|
|
+ User parent = userRepo.findById(userId).orElseThrow(new BusinessException("无用户"));
|
|
|
+ if (parent.getTeamFounder()) {
|
|
|
+ List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(parent.getCompanyId());
|
|
|
+ Map<Long, User> userMap = employees.stream().collect(Collectors.toMap(User::getId, user -> user));
|
|
|
+ return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
+ List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
+ and.add(root.get("parent").in(userMap.keySet()));
|
|
|
+ return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery)).map(user -> {
|
|
|
+ // 找出上级昵称
|
|
|
+ User user1 = userMap.get(user.getParent());
|
|
|
+ PromotionDTO dto = new PromotionDTO();
|
|
|
+ BeanUtil.copyProperties(user, dto);
|
|
|
+ if (ObjectUtil.isNotEmpty(user1)) {
|
|
|
+ dto.setParentNickname(user1.getNickname());
|
|
|
+ }
|
|
|
+ return dto;
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
return userRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> {
|
|
|
List<Predicate> and = JpaUtils.toPredicates(pageQuery, User.class, root, criteriaQuery, criteriaBuilder);
|
|
|
- if (user.getTeamFounder()) {
|
|
|
- List<User> employees = userRepo.findAllByCompanyIdAndDelFalse(user.getCompanyId());
|
|
|
- List<Long> collect = employees.stream().map(User::getId).collect(Collectors.toList());
|
|
|
- and.add(root.get("parent").in(collect));
|
|
|
- } else {
|
|
|
- and.add(criteriaBuilder.equal(root.get("parent"), userId));
|
|
|
- }
|
|
|
+ and.add(criteriaBuilder.equal(root.get("parent"), userId));
|
|
|
return criteriaBuilder.and(and.toArray(new Predicate[0]));
|
|
|
- }), JpaUtils.toPageRequest(pageQuery));
|
|
|
+ }), JpaUtils.toPageRequest(pageQuery)).map(user ->
|
|
|
+ // 插入上级昵称
|
|
|
+ PromotionDTO.builder()
|
|
|
+ .id(user.getId())
|
|
|
+ .avatar(user.getAvatar())
|
|
|
+ .nickname(user.getNickname())
|
|
|
+ .username(user.getUsername())
|
|
|
+ .phone(user.getPhone())
|
|
|
+ .parent(userId)
|
|
|
+ .parentNickname(parent.getNickname())
|
|
|
+ .build()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
/*
|