Kaynağa Gözat

feat(customer):
- 添加RemoteUserService远程调用依赖以支持用户创建
- 实现客户联系人新增时自动创建对应系统用户逻辑
- 将客户联系人与系统用户通过userId关联
- 修复远程服务查询客户ID时的字段映射错误
- 在系统用户控制器中添加手机号查询接口用于注册校验
- 更新数据权限拦截器配置以包含sys_user表
- 修复远程用户服务中的字符串拼接格式问题

hurx 1 ay önce
ebeveyn
işleme
7f147a1675

+ 2 - 1
ruoyi-common/ruoyi-common-mybatis/src/main/java/org/dromara/common/mybatis/interceptor/PlatformDataScopeInterceptor.java

@@ -101,7 +101,8 @@ public class PlatformDataScopeInterceptor implements Interceptor {
         "order_return_item",
         "customer_business_info",
         "mall_page_link",
-        "mall_page_category"
+        "mall_page_category",
+        "sys_user"
 
 
         // 注意:前缀匹配需特殊处理(如 qrtz_),见 isIgnoreTable 方法

+ 2 - 2
ruoyi-modules/ruoyi-customer/src/main/java/org/dromara/customer/dubbo/RemoteCustomerServiceImpl.java

@@ -72,7 +72,7 @@ public class RemoteCustomerServiceImpl implements RemoteCustomerService {
     @Override
     public Long selectCustomerIdByUserId(Long userId) {
         CustomerContact one = customerContactService.getOne(Wrappers.lambdaQuery(CustomerContact.class)
-            .eq(CustomerContact::getId, userId)
+            .eq(CustomerContact::getUserId, userId)
             .last("limit 1")
         );
         if (one != null) {
@@ -82,7 +82,7 @@ public class RemoteCustomerServiceImpl implements RemoteCustomerService {
     }
 
     @Override
-    public CustomerInfoDTO addReceiver(String name , String email) {
+    public CustomerInfoDTO addReceiver(String name, String email) {
         CustomerInfo customerInfo = new CustomerInfo();
         customerInfo.setCustomerName(name);
         customerInfo.setEmail(email);

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

@@ -1,5 +1,6 @@
 package org.dromara.customer.service.impl;
 
+import cn.hutool.crypto.digest.BCrypt;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -10,11 +11,13 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.common.core.enums.IsDefault;
 import org.dromara.common.core.enums.SysPlatformYesNo;
+import org.dromara.common.core.exception.ServiceException;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.common.redis.utils.SequenceUtils;
+import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.customer.domain.CustomerContact;
 import org.dromara.customer.domain.CustomerShippingAddress;
 import org.dromara.customer.domain.bo.CustomerContactBo;
@@ -26,6 +29,8 @@ import org.dromara.customer.mapper.CustomerContactMapper;
 import org.dromara.customer.mapper.CustomerInfoMapper;
 import org.dromara.customer.service.ICustomerContactService;
 import org.dromara.system.api.RemoteDeptService;
+import org.dromara.system.api.RemoteUserService;
+import org.dromara.system.api.domain.bo.RemoteUserBo;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -49,6 +54,9 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
     @DubboReference
     private RemoteDeptService remoteDeptService;
 
+    @DubboReference
+    private RemoteUserService remoteUserService;
+
     private final CustomerContactMapper baseMapper;
 
     private final CustomerInfoMapper customerInfoMapper;
@@ -150,12 +158,31 @@ public class CustomerContactServiceImpl extends ServiceImpl<CustomerContactMappe
             }
         }
 
+        // 1. 准备创建系统用户的数据
+        RemoteUserBo remoteUserBo = new RemoteUserBo();
+        remoteUserBo.setNickName(bo.getContactName());
+        remoteUserBo.setDeptId(bo.getDeptId());
+        remoteUserBo.setUserName(bo.getPhone());// 用手机号做账号
+        String defaultPassword = "123456";
+        remoteUserBo.setPassword(BCrypt.hashpw(defaultPassword));
+        remoteUserBo.setUserSonType("3");
+        remoteUserBo.setTenantId(LoginHelper.getTenantId());
+
+        // 2. 调用远程服务创建用户
+        Long userId = remoteUserService.addUser(remoteUserBo);
+
+        if (userId == null) {
+            throw new ServiceException("创建系统用户失败:" + userId);
+        }
+
+
         // 2. 生成联系人编号
         String seqId = SequenceUtils.nextPaddedIdStr(CONTACT_NO_KEY, Duration.ofDays(3650), 3);
         String contactNo = customerNo + seqId;
 
         CustomerContact add = MapstructUtils.convert(bo, CustomerContact.class);
         add.setContactNo(contactNo);
+        add.setUserId(userId);
         validEntityBeforeSave(add);
         boolean flag = baseMapper.insert(add) > 0;
         if (flag) {

+ 21 - 4
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/pc/PcSysUserController.java

@@ -5,17 +5,16 @@ import lombok.RequiredArgsConstructor;
 import org.dromara.common.core.constant.GlobalConstants;
 import org.dromara.common.core.domain.R;
 import org.dromara.common.core.exception.ServiceException;
+import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.common.satoken.utils.LoginHelper;
 import org.dromara.common.web.core.BaseController;
 import org.dromara.system.domain.bo.ChangeUserPwdBo;
 import org.dromara.system.domain.bo.SysUserBo;
+import org.dromara.system.domain.vo.SysUserVo;
 import org.dromara.system.service.ISysUserService;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 @Validated
 @RequiredArgsConstructor
@@ -26,6 +25,24 @@ public class PcSysUserController extends BaseController {
     private final ISysUserService sysUserService;
 
 
+    /**
+     * 根据手机号查询用户(用于注册前校验)
+     */
+    @GetMapping("/selectByPhone/{phonenumber}")
+    public R<SysUserVo> selectUserByPhonenumber(@PathVariable String phonenumber) {
+        if (StringUtils.isEmpty(phonenumber)) {
+            return R.fail("手机号不能为空");
+        }
+
+        SysUserVo user = sysUserService.selectUserByPhonenumber(phonenumber);
+        if (user != null) {
+            // 可选:返回用户信息,前端可提示“该手机号已注册”
+            return R.fail("该手机号已注册");
+        } else {
+            return R.ok(null);
+        }
+    }
+
     /**
      * 重置密码
      */

+ 3 - 2
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java

@@ -69,6 +69,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
      */
     @Override
     public LoginUser getUserInfo(String username, String tenantId) throws UserException {
+        SysUserVo sysUser1 = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
         return TenantHelper.dynamic(tenantId, () -> {
             SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
             if (ObjectUtil.isNull(sysUser)) {
@@ -487,7 +488,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
         boolean exist = userMapper.exists(new LambdaQueryWrapper<SysUser>()
             .eq(SysUser::getUserName, sysUserBo.getUserName()));
         if (exist) {
-            throw new ServiceException("账号已经存在:"+ username);
+            throw new ServiceException("账号已经存在:" + username);
         }
         userService.insertUser(sysUserBo);
         return sysUserBo.getUserId();
@@ -509,7 +510,7 @@ public class RemoteUserServiceImpl implements RemoteUserService {
 
         );
         if (exist) {
-            throw new RuntimeException("账号已经存在:"+ username);
+            throw new RuntimeException("账号已经存在:" + username);
         }
         userService.updateUser(sysUserBo);
         return sysUserBo.getUserId();