| 
					
				 | 
			
			
				@@ -9,7 +9,6 @@ import com.ym.mec.auth.api.entity.SysRole; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.entity.SysUser; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.auth.api.enums.SysUserType; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dao.OrganizationDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.ym.mec.biz.dal.dao.SysConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dao.TenantInfoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.TenantConfigDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.ym.mec.biz.dal.dto.TenantInfoDto; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -38,6 +37,7 @@ import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.dao.DuplicateKeyException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -81,8 +81,6 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IdGeneratorService idGenerator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private SysConfigDao sysConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TenantOrderRecordService tenantOrderRecordService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TenantAssetsInfoService assetsInfoService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -94,6 +92,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TenantInfoSendMsgService tenantInfoSendMsgService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private SysConfigService sysConfigService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ContractService contractService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 新增机构 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -267,6 +267,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             tenantInfo.setUpdatedBy(userId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             tenantInfo.setUpdatedTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             tenantInfo.setState(state); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            String pw = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //状态= 开通 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (state == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (tenantInfo.getPayState() == 0) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -274,11 +275,16 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //已支付完成 并且 没有创建用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 if (tenantInfo.getPayState() == 1 && Objects.isNull(tenantInfo.getUserId())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //初次开通 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    checkFirstOpen(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    //初次开通 返回密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    pw = checkFirstOpen(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.updateById(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //在执行了修改机构信息之后,并且有返回密码(第一次开通机构会生成登录密码并返回)就发送邮件及短信提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (StringUtils.isNotBlank(pw)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), pw, "https://online.dayaedu.com"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                tenantInfoSendMsgService.platformSendToAll(tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         throw new BizException("传入机构状态参数异常!"); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -288,13 +294,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 第一次开通服务 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param tenantInfo 机构信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * @return 初次开通机构返回机构密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void checkFirstOpen(TenantInfo tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private String checkFirstOpen(TenantInfo tenantInfo) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer tenantId = tenantInfo.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         SysUser user = sysUserFeignService.queryUserByMobile(tenantInfo.getPhone()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (Objects.nonNull(user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             if (user.getUserType().contains(SysUserType.SYSTEM.getCode())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -322,11 +329,15 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer orgId = createOrg(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //建立角色 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Integer roleId = createRole(tenantInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //密码规则 gym + 随机6位数字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        String pw = new BCryptPasswordEncoder().encode("gym" + (int) ((Math.random() * 9 + 1) * 100000)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 创建账号、用户信息、用户和角色关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        createUser(tenantInfo, orgId, Lists.newArrayList(roleId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        createUser(tenantInfo, orgId, Lists.newArrayList(roleId), pw); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //建立角色和菜单关系数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Lists.partition(collectMenuId, 50) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 .forEach(idList -> employeeService.batchInsertRoleMenu(roleId, idList, tenantId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //添加签章信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        contractService.addTsign(tenantInfo.getTsignCode(), tenantInfo.getTsignName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -341,11 +352,10 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         productInfo.setExpiryDate(expiryDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         tenantProductInfoService.updateById(productInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //发送邮件及短信提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), "123456", "https://online.dayaedu.com"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return pw; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //计算过期时间 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -383,8 +393,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return sysRole.getId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    //创建账号、用户信息、用户和角色关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    private void createUser(TenantInfo tenantInfo, Integer orgId, List<Integer> roles) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //创建账号、用户信息、用户和角色关系 返回密码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void createUser(TenantInfo tenantInfo, Integer orgId, List<Integer> roles, String pw) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Employee e = new Employee(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setTenantId(tenantInfo.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setPhone(tenantInfo.getPhone()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -395,6 +405,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setRoleIds(roles); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setUserType(SysUserType.SYSTEM.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         e.setOrganIdList(String.valueOf(orgId)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        e.setPassword(pw); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             log.info("createUser >>>> {}", e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             employeeService.add(e); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -563,7 +574,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         TenantInfo tenantInfo = this.getById(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //发送邮件及短信提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Object[] msg = {tenantInfo.getName()}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        tenantInfoSendMsgService.platformSendToAll(tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -831,7 +842,7 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private void send(List<TenantInfo> infoList, String dateStr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         infoList.forEach(t -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Object[] objects = {t.getName(), dateStr}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            tenantInfoSendMsgService.platformSendToAll(t.getEmail(), t.getPhone(), objects); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tenantInfoSendMsgService.platformSendToAll(t.getUserId(), t.getEmail(), t.getPhone(), objects); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |