| | |
| | | import com.mzl.flower.constant.Constants; |
| | | import com.mzl.flower.dto.request.BindWechatDTO; |
| | | import com.mzl.flower.dto.request.CreateWechatUserDTO; |
| | | import com.mzl.flower.dto.request.UserLoginDTO; |
| | | import com.mzl.flower.dto.request.UserPhoneLoginDTO; |
| | | import com.mzl.flower.dto.request.customer.UpdateCustomerDTO; |
| | | import com.mzl.flower.dto.request.system.*; |
| | | import com.mzl.flower.dto.response.current.CurrentUserDTO; |
| | | import com.mzl.flower.dto.response.system.EmployeeDTO; |
| | | import com.mzl.flower.dto.response.system.MenuTreeDTO; |
| | | import com.mzl.flower.dto.response.system.UserDetailsDTO; |
| | | import com.mzl.flower.dto.response.system.UserListDTO; |
| | | import com.mzl.flower.dto.response.system.*; |
| | | import com.mzl.flower.entity.point.CustomerPoint; |
| | | import com.mzl.flower.entity.system.*; |
| | | import com.mzl.flower.enums.TrueOrFalseEnum; |
| | |
| | | , String imgUrl, String nickname,String userType){ |
| | | List<String> userTypes = new ArrayList<>(); |
| | | userTypes.add(userType); |
| | | User user = userMapper.getByOpenID(openId,userTypes); |
| | | if(user == null){ |
| | | List<User> userList = userMapper.getByOpenID(openId,userTypes); |
| | | if(CollectionUtils.isEmpty(userList)){ |
| | | throw new ValidationException("请注册账号后至\"个人中心-绑定微信\"后再使用微信登录"); |
| | | } |
| | | user.setNickName(nickname); |
| | | User user=userList.get(0); |
| | | // user.setNickName(nickname); |
| | | user.setNickName(user.getLoginName()); |
| | | user.setPicture(imgUrl); |
| | | user.update(user.getId()); |
| | | userMapper.updateById(user); |
| | |
| | | } |
| | | |
| | | public void bindWechat(String userId, String openId, String unionId, String sessionKey, BindWechatDTO dto) { |
| | | // 查看微信是否已经绑定过用户 |
| | | |
| | | User user = userMapper.selectById(userId); |
| | | if(ObjectUtils.isEmpty(user)){ |
| | | throw new ValidationException("当前用户不存在"); |
| | | } |
| | | |
| | | |
| | | List<User> userList=wechatMapper.selectUserByOpenId(openId,user.getType()); |
| | | if(!CollectionUtils.isEmpty(userList)){ |
| | | throw new ValidationException("该微信已绑定其他账号"); |
| | | } |
| | | |
| | | UserWechat wechat = wechatMapper.selectOne(new LambdaQueryWrapper<UserWechat>() |
| | | .eq(UserWechat::getUserId,userId)); |
| | | if(wechat == null){ |
| | |
| | | wechat.setRealName(dto.getRealName()); |
| | | wechatMapper.updateById(wechat); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | public User getExistUserByOpenId(String openId, String sessionKey, String unionId, String userType) { |
| | | List<String> userTypes = new ArrayList<>(); |
| | | userTypes.add(userType); |
| | | User user = userMapper.getByOpenID(openId,userTypes); |
| | | return user; |
| | | List<User> userList = userMapper.getByOpenID(openId,userTypes); |
| | | if(!CollectionUtils.isEmpty(userList)){ |
| | | return userList.get(0); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | public void registWxUser(CreateWechatUserDTO dto) { |
| | |
| | | updateCustomerDTO.setUserId(user.getId()); |
| | | if (StringUtils.isNotBlank(dto.getPurePhoneNumber())) { |
| | | updateCustomerDTO.setName("花满芫-" + dto.getPurePhoneNumber().substring(dto.getPurePhoneNumber().length() - 4)); |
| | | |
| | | } |
| | | customerService.addOrUpdateCustomer(updateCustomerDTO); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | public Page<UserListInfoDTO> searchUserInfos(SearchUserDTO dto, Page page) { |
| | | List<UserListInfoDTO> result = userMapper.searchUserInfo(page, dto); |
| | | |
| | | page.setRecords(result); |
| | | return page; |
| | | } |
| | | |
| | | |
| | | public User registPhoneUser(UserPhoneLoginDTO dto) { |
| | | String RETISTER_KEY = "%s_%s"; |
| | | RLock lock = redissonClient.getLock(String.format(RETISTER_KEY, dto.getUsername(), dto.getUserType())); |
| | | try { |
| | | // 获取锁,最多等待 10 秒,锁自动释放时间 30 秒 |
| | | if (lock.tryLock(10, 30, TimeUnit.SECONDS)) { |
| | | try { |
| | | // 其次查找当前loginName是prephonenume的,userType是customer的用户存在不存在 |
| | | if (StringUtils.isEmpty(dto.getUsername()) && StringUtils.isEmpty(dto.getUsername())) { |
| | | throw new ValidationException("电话号码为空!无法注册"); |
| | | } |
| | | // 1:查看用户存在不存在 |
| | | List<String> userTypes = new ArrayList<>(); |
| | | userTypes.add(dto.getUserType()); |
| | | User user = findByLoginName(dto.getUsername(), userTypes); |
| | | if (ObjectUtils.isEmpty(user)) { |
| | | // 是新用户,需要注册 |
| | | user = new User(); |
| | | user.setId(UUIDGenerator.getUUID()); |
| | | user.setLoginName(dto.getUsername()); |
| | | user.setTel(dto.getUsername()); |
| | | user.setNickName(dto.getUsername()); |
| | | user.setPassword(passwordEncoder.encode("12345678")); |
| | | user.setType(dto.getUserType()); |
| | | user.setStatus(Constants.STATUS_ACTIVE); |
| | | user.setIsSys(Constants.N); |
| | | user.create(); |
| | | userMapper.insert(user); |
| | | |
| | | // 注册商户信息 |
| | | UpdateCustomerDTO updateCustomerDTO = new UpdateCustomerDTO(); |
| | | updateCustomerDTO.setUserId(user.getId()); |
| | | if (StringUtils.isNotBlank(dto.getUsername())) { |
| | | updateCustomerDTO.setName("智信-" + dto.getUsername().substring(dto.getUsername().length() - 4)); |
| | | |
| | | } |
| | | customerService.addOrUpdateCustomer(updateCustomerDTO); |
| | | |
| | | return user; |
| | | } |
| | | } finally { |
| | | lock.unlock(); |
| | | } |
| | | } |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |