gongzuming
2024-10-27 c25b0632e4a360f7499f1c79ff1d70a67919e008
src/main/java/com/mzl/flower/service/register/RegisterService.java
@@ -1,7 +1,6 @@
package com.mzl.flower.service.register;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.constant.Constants;
import com.mzl.flower.dto.request.register.RegisterCustomerDTO;
@@ -13,6 +12,7 @@
import com.mzl.flower.mapper.system.UserWechatMapper;
import com.mzl.flower.service.customer.CustomerService;
import com.mzl.flower.service.partner.PartnerService;
import com.mzl.flower.service.payment.RedisLockService;
import com.mzl.flower.utils.UUIDGenerator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.crypto.password.PasswordEncoder;
@@ -36,15 +36,19 @@
    private final UserWechatMapper wechatMapper;
    private final RedisLockService lockService;
    public RegisterService(UserMapper userMapper,
                           PasswordEncoder passwordEncoder,
                           PartnerService partnerService,
                           CustomerService customerService, UserWechatMapper wechatMapper) {
                           CustomerService customerService, UserWechatMapper wechatMapper,
                           RedisLockService lockService) {
        this.userMapper = userMapper;
        this.passwordEncoder = passwordEncoder;
        this.partnerService = partnerService;
        this.customerService = customerService;
        this.wechatMapper = wechatMapper;
        this.lockService = lockService;
    }
    public void registerUser(RegisterDTO dto, String userType) {
@@ -65,6 +69,12 @@
    }
    public void registerCustomerUser(RegisterCustomerDTO dto, String userType, String openId, String sessionKey, String unionId) {
        String key = dto.getTel() + "_" + userType;
        boolean lock = lockService.getObjectLock(RedisLockService.LOCK_KEY_CART_, key);
        if(!lock){
            return;
        }
        try {
        if(checkUserExist(dto.getTel(),userType)){
            throw new ValidationException("该手机号码已经注册");
        }
@@ -98,6 +108,10 @@
        }
        dto.getDto().setUserId(user.getId());
        customerService.addOrUpdateCustomer(dto.getDto());
        }finally {
            lockService.releaseObjectLock(RedisLockService.LOCK_KEY_CART_, key);
        }
    }