Procházet zdrojové kódy

Merge branch 'dev/2024/0417/update-admin' of Harper/feifan-backend-zx-admin into master

添加用户关系的树状及名称查询和电话查询
Yangzw před 11 měsíci
rodič
revize
e4e76a5e06

+ 3 - 0
feifan-module-distri/feifan-module-distri-api/src/main/java/cn/newfeifan/mall/module/distri/enums/ErrorCodeConstants.java

@@ -20,5 +20,8 @@ public interface ErrorCodeConstants {
     ErrorCode PT_PROFIT_LOG_NOT_EXISTS = new ErrorCode(1_002_030_013, "平台利润日志表不存在");
     ErrorCode PERCENT_LARGE_ONE_HUNDRED = new ErrorCode(1_002_030_014, "百分比总和超过100");
     ErrorCode HAS_PARENT = new ErrorCode(1_002_030_015, "该直推人已经有推荐人, 故不能增加");
+    ErrorCode DUSER_NAME_NOT_EXISTS = new ErrorCode(1_002_030_017, "该直推人名称不存在");
+    ErrorCode DUSER_NAME_IS_NOT_ONLY_ONE = new ErrorCode(1_002_030_018, "该直推人名称有重复的,请选择电话查询");
+    ErrorCode DUSER_MOBILE_NOT_EXISTS = new ErrorCode(1_002_030_019, "该直推人电话不存在");
 
 }

+ 0 - 4
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/controller/admin/sharepath/vo/SharePathTreeReqVO.java

@@ -16,10 +16,6 @@ public class SharePathTreeReqVO {
     @Schema(description = "电话")
     private String mobile;
 
-    @Schema(description = "最小层级")
-    @NotNull(message = "最小层级不能为空")
-    private Integer minDepth;
-
     @Schema(description = "最大层级")
     @NotNull(message = "最大层级不能为空")
     private Integer maxDepth;

+ 7 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/dal/mysql/sharepath/SharePathMapper.java

@@ -73,6 +73,13 @@ public interface SharePathMapper extends BaseMapperX<SharePathDO> {
 
 
     List<TreeNode> selectDescendants(@Param("ancestor") Long userId,  @Param("maxDepth") Integer maxDepth);
+
+    default Long selectAncestorByDescendant(Long userId){
+        return selectOne(new LambdaQueryWrapperX<SharePathDO>()
+                .eq(SharePathDO::getDescendant, userId)
+                .eq(SharePathDO::getDepth, 1)
+        ).getAncestor();
+    }
 }
 
 

+ 4 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/duser/DuserService.java

@@ -82,4 +82,8 @@ public interface DuserService {
     DuserInfoVO getDuserInfo(Long userId);
 
     DuserDO getDuserByUser(Long userId);
+
+    List<DuserDO> getDuserByName(String name);
+
+    DuserDO getDuserByMobile(String mobile);
 }

+ 14 - 0
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/duser/DuserServiceImpl.java

@@ -101,6 +101,20 @@ public class DuserServiceImpl implements DuserService {
         return duserMapper.selectOne(new LambdaQueryWrapperX<DuserDO>().eq(DuserDO::getUserId,id));
     }
 
+    @Override
+    public List<DuserDO> getDuserByName(String name) {
+        return duserMapper.selectList(new LambdaQueryWrapperX<DuserDO>()
+                .eq(DuserDO::getName,name)
+        );
+    }
+
+    @Override
+    public DuserDO getDuserByMobile(String mobile) {
+        return duserMapper.selectOne(new LambdaQueryWrapperX<DuserDO>()
+                .eq(DuserDO::getMobile,mobile)
+        );
+    }
+
     @Override
     public PageResult<DuserDO> getDuserPage(DuserPageReqVO pageReqVO) {
         return duserMapper.selectPage(pageReqVO);

+ 29 - 6
feifan-module-distri/feifan-module-distri-biz/src/main/java/cn/newfeifan/mall/module/distri/service/sharepath/SharePathServiceImpl.java

@@ -7,6 +7,7 @@ import cn.newfeifan.mall.module.distri.service.duser.DuserService;
 import cn.newfeifan.mall.module.distri.service.ordercalc.OrderCalcService;
 import cn.newfeifan.mall.module.member.dal.dataobject.user.MemberUserDO;
 import cn.newfeifan.mall.module.member.service.user.MemberUserService;
+import com.aliyuncs.utils.StringUtils;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
@@ -189,8 +190,31 @@ public class SharePathServiceImpl implements SharePathService {
 
     @Override
     public TreeNode getTreeByNameOrMobile(SharePathTreeReqVO sharePathTreeReqVO) {
-//        duserService.getDuserByName(sharePathTreeReqVO.getName());
-        return null;
+        //拿到当前用户ID
+        Long userId = getUserIdByNameOrMobile(sharePathTreeReqVO.getName(), sharePathTreeReqVO.getMobile());
+
+        //拿到推荐人ID
+        Long ancestor = sharePathMapper.selectAncestorByDescendant(userId);
+        return getTree(ancestor, sharePathTreeReqVO.getMaxDepth());
+    }
+
+    private Long getUserIdByNameOrMobile(String name, String mobile) {
+        if(!StringUtils.isEmpty(name)){
+            List<DuserDO> duserDOS = duserService.getDuserByName(name);
+            if (duserDOS.isEmpty()) {
+                throw exception(DUSER_NAME_NOT_EXISTS);
+            } else if (duserDOS.size() > 1) {
+                throw exception(DUSER_NAME_IS_NOT_ONLY_ONE);
+            }
+
+            return duserDOS.get(0).getUserId();
+        }else{
+            DuserDO duserDO = duserService.getDuserByMobile(mobile);
+            if (duserDO == null) {
+                throw exception(DUSER_MOBILE_NOT_EXISTS);
+            }
+            return duserDO.getUserId();
+        }
     }
 
 
@@ -325,13 +349,14 @@ public class SharePathServiceImpl implements SharePathService {
         return Stream.concat(orderUserId.stream(), userId.stream()).distinct().collect(Collectors.toList());
 
     }
+
     @Override
     public PageResult<SharePathRespVO> getDescendants(SharePathPageReqVO pageReqVO) {
         LambdaQueryWrapperX<SharePathDO> wrapper = new LambdaQueryWrapperX<SharePathDO>()
                 .eq(SharePathDO::getAncestor, pageReqVO.getAncestor());
-        if(pageReqVO.getDepth() != null){
+        if (pageReqVO.getDepth() != null) {
             wrapper.eq(SharePathDO::getDepth, 1);
-        }else {
+        } else {
             wrapper.ne(SharePathDO::getDepth, 1);
         }
 
@@ -345,6 +370,4 @@ public class SharePathServiceImpl implements SharePathService {
     }
 
 
-
-
 }