@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveSubAccountTenantBinding(SaveSubAccountTenantBindingParam param) {
		if (param == null || param.getUserId() == null || param.getMasterUserId() == null) {
			throw new UserSideException("用户ID不能为空");
		}
		Long userId = param.getUserId();
		Long masterUserId = param.getMasterUserId();
		List<Long> tenantIds = param.getTenantIds();
		Boolean allTenantVisible = param.getAllTenantVisible();
		if (userId.equals(masterUserId)) {
			throw new UserSideException("主账号和子账号不能为同一个账号");
		}
		// 若非全选租户，且租户列表仍为null，什么都不改变
		if (tenantIds == null && Boolean.FALSE.equals(allTenantVisible)) {
			log.info("未指定 tenantIds，保持子账号绑定关系不变。userId={}, masterUserId={}", userId, masterUserId);
			return;
		}
		// 可加入对userId和masterUserId的userInfo的AccountType是否为子/主账号和UserAccount之间是否存在后缀关联CHECK
		CustomerSideUserBasicInfoDTO userInfo = userService.getCustomerSideUserBasicInfo(userId);

		List<PlatAccountBindTenant> existingBindings = platAccountBindTenantRepository.getListByUserId(userId);
		Map<Long, PlatAccountBindTenant> existingBindingMap = existingBindings.stream()
				.collect(Collectors.toMap(PlatAccountBindTenant::getTenantId, item -> item));
		// 子账号只能绑定主账号已绑定的租户
		List<PlatAccountBindTenant> masterBindings = platAccountBindTenantRepository.getListByUserId(masterUserId);
		Map<Long, PlatAccountBindTenant> masterBindingMap = masterBindings.stream()
				.collect(Collectors.toMap(PlatAccountBindTenant::getTenantId, item -> item));
		if (masterBindingMap.isEmpty()) {
			log.warn("主账号无绑定租户，无法进行子账号绑定，masterUserId={}", masterUserId);
			throw new UserSideException("主账号未绑定任何租户，无法进行子账号绑定");
		}

		List<PlatAccountBindTenant> addList = new ArrayList<>();

		// 如果是全选，则使用主账号的所有租户ID
		if (Boolean.TRUE.equals(allTenantVisible)) {
			log.info("全选租户，将绑定主账号的所有租户关系。userId={}, masterUserId={}", userId, masterUserId);
			tenantIds = new ArrayList<>(masterBindingMap.keySet());
		}
		if (CollectionUtils.isNotEmpty(tenantIds)) {
			for (Long tenantId : tenantIds) {
				if (!masterBindingMap.containsKey(tenantId)) {
					log.warn("主账号未绑定租户: {}, 跳过此租户", tenantId);
					continue;
				}
				// 子账号已有此租户的绑定关系，无视
				if (existingBindingMap.containsKey(tenantId)) {
					existingBindingMap.remove(tenantId);
				} else {
					// 子账号没有此租户的绑定关系，则新增
					PlatAccountBindTenant masterBinding = masterBindingMap.get(tenantId);

					PlatAccountBindTenant newBinding = new PlatAccountBindTenant();
					newBinding.setUserId(userId);
					newBinding.setUserAccount(userInfo.getUserAccount());
					newBinding.setTenantId(masterBinding.getTenantId());
					newBinding.setTenantName(masterBinding.getTenantName());
					newBinding.setTenantCode(masterBinding.getTenantCode());
					newBinding.setCustomerId(masterBinding.getCustomerId());
					newBinding.setCustomerName(masterBinding.getCustomerName());
					newBinding.setCustomerCode(masterBinding.getCustomerCode());

					addList.add(newBinding);
				}
			}
		}
		// 批量保存新增
		if (CollectionUtils.isNotEmpty(addList)) {
			platAccountBindTenantRepository.saveList(addList);
		}
		// 剩下的不是已有也不是新增，则删除
		if (!existingBindingMap.isEmpty()) {
			List<Long> deleteIds = existingBindingMap.values().stream()
					.map(PlatAccountBindTenant::getId)
					.collect(Collectors.toList());
			platAccountBindTenantRepository.removeListByIds(deleteIds);
		}
	}

你能帮我检查一下我的代码的逻辑吗