|
|
@@ -10,18 +10,24 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.dromara.common.core.constant.GlobalConstants;
|
|
|
import org.dromara.common.core.context.PlatformContext;
|
|
|
import org.dromara.common.core.enums.IsDefault;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.DateUtils;
|
|
|
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.RedisUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.customer.domain.*;
|
|
|
import org.dromara.customer.domain.bo.*;
|
|
|
import org.dromara.customer.domain.vo.*;
|
|
|
import org.dromara.customer.mapper.*;
|
|
|
import org.dromara.customer.service.ICustomerInfoService;
|
|
|
+import org.dromara.customer.utils.qcc.QccUtils;
|
|
|
+import org.dromara.customer.utils.qcc.domain.CompanyInfoResponse;
|
|
|
import org.dromara.system.api.*;
|
|
|
import org.dromara.system.api.domain.bo.RemoteUserBo;
|
|
|
import org.dromara.system.api.domain.vo.RemoteDeptVo;
|
|
|
@@ -834,4 +840,101 @@ public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, Cus
|
|
|
}
|
|
|
return baseMapper.deleteByIds(ids) > 0;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 客户注册
|
|
|
+ *
|
|
|
+ * @param bo
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean register(CustomerRegisterBo bo) {
|
|
|
+ //先校验验证码是否正确
|
|
|
+ String code = RedisUtils.getCacheObject(GlobalConstants.CAPTCHA_CODE_KEY + bo.getPurchasePhone());
|
|
|
+ code = "123456";
|
|
|
+ if (!code.equals(bo.getCode())) {
|
|
|
+ throw new ServiceException("验证码错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验密码与确认密码是否一致
|
|
|
+ if (!bo.getPassword().equals(bo.getConfirmPassword())) {
|
|
|
+ throw new ServiceException("密码与确认密码不一致");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询数据库是否存在企业,已存在则提示客户已存在
|
|
|
+ CustomerInfo customerInfo = baseMapper.selectOne(new LambdaQueryWrapper<CustomerInfo>()
|
|
|
+ .eq(CustomerInfo::getCustomerName, bo.getCustomerName())
|
|
|
+ );
|
|
|
+ if (customerInfo != null) {
|
|
|
+ throw new ServiceException("客户已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询企查查是否存在企业,如果企查查不存在则提示企业不存在
|
|
|
+ CompanyInfoResponse companyInfo = QccUtils.getCompanyInfo(bo.getCustomerName());
|
|
|
+ if (companyInfo == null || companyInfo.getResult() == null) {
|
|
|
+ throw new ServiceException("请检查企业名是否正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ //构建客户信息实体
|
|
|
+ CustomerInfo customerEntity = new CustomerInfo();
|
|
|
+ customerEntity.setCustomerName(bo.getCustomerName());
|
|
|
+ customerEntity.setBusinessCustomerName(companyInfo.getResult().getName());
|
|
|
+ customerEntity.setShortName(companyInfo.getResult().getName());
|
|
|
+ customerEntity.setStatus("0"); // 正常状态
|
|
|
+ customerEntity.setDelFlag("0"); // 未删除
|
|
|
+
|
|
|
+ // 设置其他工商信息
|
|
|
+ if (baseMapper.insert(customerEntity) <= 0) {
|
|
|
+ throw new ServiceException("客户信息新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long customerId = customerEntity.getId();
|
|
|
+
|
|
|
+ // 添加客户工商信息
|
|
|
+ CustomerBusinessInfo businessInfo = new CustomerBusinessInfo();
|
|
|
+ businessInfo.setCustomerId(customerId);
|
|
|
+ businessInfo.setBusinessCustomerName(companyInfo.getResult().getName());
|
|
|
+ businessInfo.setSocialCreditCode(companyInfo.getResult().getCreditCode());
|
|
|
+ businessInfo.setLegalPersonName(companyInfo.getResult().getOperName());
|
|
|
+ businessInfo.setRegisteredCapital(companyInfo.getResult().getRegistCapi());
|
|
|
+ businessInfo.setEstablishmentDate(DateUtils.parseDate((companyInfo.getResult().getStartDate())));
|
|
|
+ businessInfo.setRegistrationStatus(companyInfo.getResult().getStatus());
|
|
|
+ businessInfo.setBusinessAddress(companyInfo.getResult().getAddress());
|
|
|
+ businessInfo.setBussinessRange(companyInfo.getResult().getScope());
|
|
|
+ businessInfo.setStatus("0");
|
|
|
+ businessInfo.setDelFlag("0");
|
|
|
+
|
|
|
+ if (customerBusinessInfoMapper.insert(businessInfo) <= 0) {
|
|
|
+ throw new ServiceException("客户工商信息新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加客户联系人信息
|
|
|
+ CustomerContact contact = new CustomerContact();
|
|
|
+ contact.setCustomerId(customerId);
|
|
|
+ contact.setContactName(bo.getPurchaseName());
|
|
|
+ contact.setPhone(bo.getPurchasePhone());
|
|
|
+ contact.setCustomLoginName(bo.getPurchasePhone());
|
|
|
+ contact.setIsPrimary("0"); // 设为主联系人
|
|
|
+ contact.setStatus("0");
|
|
|
+ contact.setDelFlag("0");
|
|
|
+
|
|
|
+ if (customerContactMapper.insert(contact) <= 0) {
|
|
|
+ throw new ServiceException("客户联系人信息新增失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建系统用户
|
|
|
+ RemoteUserBo remoteUserBo = new RemoteUserBo();
|
|
|
+ remoteUserBo.setUserName(bo.getPurchasePhone());
|
|
|
+ remoteUserBo.setNickName(bo.getCustomerName());
|
|
|
+ remoteUserBo.setPhonenumber(bo.getPurchasePhone());
|
|
|
+ remoteUserBo.setPassword(BCrypt.hashpw(bo.getPassword()));
|
|
|
+ remoteUserBo.setUserSonType("3"); // 商城用户
|
|
|
+ remoteUserBo.setTenantId(LoginHelper.getTenantId());
|
|
|
+ remoteUserBo.setStatus("0"); // 正常状态
|
|
|
+
|
|
|
+ remoteUserService.addUser(remoteUserBo);
|
|
|
+
|
|
|
+ log.info("客户注册成功,客户ID:{},客户名称:{}", customerId, bo.getCustomerName());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|