| 
					
				 | 
			
			
				@@ -85,7 +85,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void addTenantInfo(TenantInfoDto dto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //校验手机号是否唯一 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        checkPhone(dto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RBucket<Object> bucket = checkPhone(dto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //校验营业执照信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         checkTsign(dto.getTsignCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -106,6 +106,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 tenantProductInfoService::addTenantProduct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //添加机构配置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::addConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //释放 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -114,25 +116,25 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void updateTenantInfo(TenantInfoDto dto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //机构id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Integer tenantId = Optional.ofNullable(dto) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .map(TenantInfoDto::getId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .orElseThrow(() -> new BizException("机构信息不能为空!")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //查询机构信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TenantInfo tenantInfo = this.getById(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (Objects.isNull(tenantInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            throw new BizException("未找到该机构信息!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TenantInfo tenantInfo = Optional.ofNullable(dto) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .map(TenantInfoDto::getId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .map(this::getById) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .orElseThrow(() -> new BizException("未找到该机构信息,机构信息不能为空!")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //机构状态 1已缴费,并且 机构注册的手机号与本次修改后的手机号不同,就证明本次修改了手机号 则需要修改机构的账号信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (1 == tenantInfo.getPayState() && !Objects.equals(tenantInfo.getPhone(), dto.getPhone())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //校验修改后的手机号是否是唯一 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            checkPhone(dto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            //修改机构用户手机号(登录账号)信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            SysUser tenantUser = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            tenantUser.setPhone(dto.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            sysUserFeignService.updateSysUser(tenantUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            RBucket<Object> bucket = checkPhone(dto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.nonNull(tenantInfo.getUserId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                SysUser tenantUser = sysUserFeignService.queryUserById(tenantInfo.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                tenantUser.setPhone(dto.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sysUserFeignService.updateSysUser(tenantUser); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //机构状态 0未缴费 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -140,8 +142,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //校验营业执照信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             checkTsign(dto.getTsignCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //修改产品 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            setIdByApply(tenantId, dto.getProductInfo(), dto.getProductInfo()::setTenantId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    tenantProductInfoService::updateTenantProduct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.nonNull(dto.getProductInfo())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                setIdByApply(tenantInfo.getId(), dto.getProductInfo(), dto.getProductInfo()::setTenantId, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        tenantProductInfoService::updateTenantProduct); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -151,7 +155,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.updateById(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //修改机构配置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        setIdByApply(tenantId, dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::updateConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.nonNull(dto.getConfig())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            setIdByApply(tenantInfo.getId(), dto.getConfig(), dto.getConfig()::setTenantId, tenantConfigService::updateConfig); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -195,33 +201,33 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 第一个启用默认激活账号等信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param id    机构id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-     * @param state 机构状态 0草稿 1启动 2停用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @param state 机构状态1启动 2停用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void opsTenantState(Integer id, Integer state) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (Objects.nonNull(state)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if (state == 1 || state == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                TenantInfo tenantInfo = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (Objects.isNull(tenantInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    throw new BizException("该机构数据异常! ID : [" + id + "]"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (Objects.nonNull(state) && state == 1 || state == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            TenantInfo tenantInfo = baseMapper.selectById(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (Objects.isNull(tenantInfo)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                throw new BizException("该机构数据异常! ID : [" + id + "]"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Integer userId = getUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tenantInfo.setUpdatedBy(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tenantInfo.setUpdatedTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tenantInfo.setState(state); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //状态= 开通 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (state == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (tenantInfo.getPayState() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    throw new BizException("机构未缴费无法开通!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                Integer userId = getUserId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                tenantInfo.setUpdatedBy(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                tenantInfo.setUpdatedTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                tenantInfo.setState(state); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                //状态= 开通并且已支付完成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (state == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (tenantInfo.getPayState() == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        //判断是否初次启用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        firstOpen(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        throw new BizException("机构未缴费无法开通!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                //已支付完成 并且 没有创建用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (tenantInfo.getPayState() == 1 && Objects.nonNull(tenantInfo.getUserId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //初次开通 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    checkFirstOpen(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                baseMapper.updateById(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            baseMapper.updateById(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw new BizException("传入机构状态参数异常!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -231,7 +237,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param tenantInfo 机构信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void firstOpen(TenantInfo tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void checkFirstOpen(TenantInfo tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer tenantId = tenantInfo.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.nonNull(user)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -267,8 +273,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 创建账号、用户信息、用户和角色关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         createUser(tenantInfo, orgId, Lists.newArrayList(roleId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //建立角色和菜单关系数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-         Lists.partition(collectMenuId, 200) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                         .forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Lists.partition(collectMenuId, 50) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //创建资产信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         TenantAssetsInfo assetsInfo = new TenantAssetsInfo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         assetsInfo.setTenantId(tenantId); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -276,6 +282,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         assetsInfo.setFrozenAmount(BigDecimal.ZERO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         assetsInfo.setCreatedTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         assetsInfoService.save(assetsInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //拆分菜单获取菜单ID 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -310,6 +318,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setEntryDate(LocalDate.now().toDate()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setRoles(roles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setRoleIds(roles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        e.setUserType(SysUserType.SYSTEM.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setOrganIdList(String.valueOf(orgId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             log.info("createUser >>>> {}", e); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -461,9 +470,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 校验手机号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void checkPhone(TenantInfoDto dto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private RBucket<Object> checkPhone(TenantInfoDto dto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //防止重复点击 加锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        String key = "Tenant_First_Add:" + dto.getPhone(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String key = "Tenant_Check_Phone:" + dto.getPhone(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         RBucket<Object> bucket = redissonClient.getBucket(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //原子操作 抢锁成功为true 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!bucket.trySet(dto.getPhone(), 1L, TimeUnit.MINUTES)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -475,9 +484,11 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .orElse(null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.nonNull(sysUser)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (sysUser.getUserType().contains(SysUserType.SYSTEM.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 throw new BizException("该手机号已被注册!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return bucket; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -489,8 +500,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param action    需要执行的操作 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private <T> void setIdByApply(Integer tenantId, T clazz, Consumer<Integer> setOption, Consumer<T> action) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Optional.ofNullable(tenantId) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .ifPresent(setOption); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        setOption.accept(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         action.accept(clazz); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |