Sfoglia il codice sorgente

refactor(customer): 重构部门ID查询方法并添加验证码验证功能

- 将远程部门服务中的selectDeptChildrenIds方法替换为selectDeptIdsByDeptId方法
- 在CustomerInfoService接口中添加verifyCode方法定义
- 实现验证码验证逻辑,包括Redis缓存验证和过期处理
- 在CustomerRegisterController中添加验证码验证API端点
- 在系统部门服务中实现selectDeptIdsByDeptId方法,支持查询部门及其子部门ID列表
hurx 2 settimane fa
parent
commit
d39e71c697

+ 7 - 0
ruoyi-api/ruoyi-api-system/src/main/java/org/dromara/system/api/RemoteDeptService.java

@@ -79,4 +79,11 @@ public interface RemoteDeptService {
 
     Map<Long, String> selectDeptNameByIds(Set<Long> ids);
 
+    /**
+     * 根据部门ID查询所有子部门(正常状态)
+     *
+     * @param deptId 部门ID
+     */
+    List<Long> selectDeptIdsByDeptId(Long deptId);
+
 }

+ 9 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/controller/pc/CustomerRegisterController.java

@@ -46,6 +46,15 @@ public class CustomerRegisterController {
         return R.ok(customerInfoVoList);
     }
 
+    /**
+     * 验证验证码
+     */
+    @PutMapping("/validateCode")
+    public R<Void> verifyCode(@RequestBody CustomerRegisterBo bo) {
+        customerInfoService.verifyCode(bo);
+        return R.ok();
+    }
+
     /**
      * 验证密码与验证码
      */

+ 3 - 0
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/ICustomerInfoService.java

@@ -158,6 +158,9 @@ public interface ICustomerInfoService extends IService<CustomerInfo> {
     /*验证密码与验证码*/
     Boolean verifyCodeAndPassword(CustomerRegisterBo bo);
 
+    /*验证验证码*/
+    Boolean verifyCode(CustomerRegisterBo bo);
+
     /**
      * 客户注册
      */

+ 1 - 1
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerContactServiceImpl.java

@@ -198,7 +198,7 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
         }
         if (bo.getDeptId() != null) {
             // 1. 获取当前部门及所有子部门的 ID 列表
-            List<Long> deptIds = remoteDeptService.selectDeptChildrenIds(bo.getDeptId());
+            List<Long> deptIds = remoteDeptService.selectDeptIdsByDeptId(bo.getDeptId());
 
             // 2. 使用 in 查询
             if (deptIds != null && !deptIds.isEmpty()) {

+ 19 - 6
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/service/impl/CustomerInfoServiceImpl.java

@@ -35,9 +35,7 @@ import org.dromara.system.api.*;
 import org.dromara.system.api.domain.bo.RemoteUserBo;
 import org.dromara.system.api.domain.dto.AddressAreaDTO;
 import org.dromara.system.api.domain.vo.RemoteDeptVo;
-import org.dromara.system.api.domain.vo.RemoteComStaffVo;
 import org.dromara.system.api.domain.vo.RemoteDictDataVo;
-import org.dromara.system.api.domain.dto.AddressAreaDTO;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -191,10 +189,10 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         if (businessInfo != null) {
             vo.setCustomerBusinessInfoVo(MapstructUtils.convert(businessInfo, CustomerBusinessInfoVo.class));
             // 补充主表缺失字段
-            if (StringUtils.isBlank(vo.getSocialCreditCode())){
+            if (StringUtils.isBlank(vo.getSocialCreditCode())) {
                 vo.setSocialCreditCode(businessInfo.getSocialCreditCode());
             }
-            if (StringUtils.isBlank(vo.getBusinessCustomerName())){
+            if (StringUtils.isBlank(vo.getBusinessCustomerName())) {
                 vo.setBusinessCustomerName(businessInfo.getBusinessCustomerName());
             }
 
@@ -847,7 +845,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
 
             /*新增客户时给每个客户创建自己的组织架构*/
             RemoteDeptVo remoteDeptVo = new RemoteDeptVo();
-            remoteDeptVo.setParentId(100L);
+            remoteDeptVo.setParentId(0L);
             remoteDeptVo.setDeptName(bo.getBusinessCustomerName());
             remoteDeptVo.setPlatformCode(platform);
             RemoteDeptVo deptVo = remoteDeptService.insertDept(remoteDeptVo);
@@ -1194,6 +1192,21 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
         return true;
     }
 
+    @Override
+    public Boolean verifyCode(CustomerRegisterBo bo) {
+        //先校验验证码是否正确
+        String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + bo.getPurchasePhone());
+        if (code == null) {
+            throw new ServiceException("验证码已过期");
+        }
+
+        if (!code.equals(bo.getCode())) {
+            throw new ServiceException("验证码错误");
+        }
+
+        return true;
+    }
+
     /**
      * 客户注册
      *
@@ -1295,7 +1308,7 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
 
         /*新增客户时给每个客户创建自己的组织架构*/
         RemoteDeptVo remoteDeptVo = new RemoteDeptVo();
-        remoteDeptVo.setParentId(100L);
+        remoteDeptVo.setParentId(0L);
         remoteDeptVo.setDeptName(companyInfo.getResult().getName());
         RemoteDeptVo deptVo = remoteDeptService.insertDept(remoteDeptVo);
 

+ 5 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteDeptServiceImpl.java

@@ -118,4 +118,9 @@ public class RemoteDeptServiceImpl implements RemoteDeptService {
     public Map<Long, String> selectDeptNameByIds(Set<Long> ids) {
         return sysDeptService.selectDeptNameByIds(ids);
     }
+
+    @Override
+    public List<Long> selectDeptIdsByDeptId(Long deptId) {
+        return sysDeptService.selectDeptIdsByDeptId(deptId);
+    }
 }

+ 7 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysDeptService.java

@@ -168,4 +168,11 @@ public interface ISysDeptService extends IService<SysDept> {
     List<SysDeptVo> selectCustomerDeptList(Long customerId);
 
     Map<Long, String> selectDeptNameByIds(Set<Long> ids);
+
+    /**
+     * 根据部门ID查询所有子部门(正常状态)
+     *
+     * @param deptId 部门ID
+     */
+    List<Long> selectDeptIdsByDeptId(Long deptId);
 }

+ 25 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java

@@ -594,4 +594,29 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
             collectAllDescendantIds(child.getDeptId(), result);
         }
     }
+
+    public List<Long> selectDeptIdsByDeptId(Long deptId) {
+        List<Long> resultIds = new ArrayList<>();
+        if (Objects.isNull(deptId)) {
+            return resultIds;
+        }
+
+        // 添加自身
+        resultIds.add(deptId);
+
+        // 构建查询条件
+        LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
+        // 使用 apply 注入 FIND_IN_SET,注意 {0} 是占位符
+        queryWrapper.apply("FIND_IN_SET({0}, ancestors)", deptId)
+            .eq(SysDept::getDelFlag, "0") //
+            .select(SysDept::getDeptId);  // 只查询 ID 字段以提高性能
+
+        List<SysDept> depts = baseMapper.selectList(queryWrapper);
+        List<Long> childIds = depts.stream()
+            .map(SysDept::getDeptId)
+            .collect(Collectors.toList());
+
+        resultIds.addAll(childIds);
+        return resultIds;
+    }
 }