|
|
@@ -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) {
|