| 
					
				 | 
			
			
				@@ -50,10 +50,16 @@ import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.function.Consumer; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import static com.ym.mec.biz.service.impl.TenantInfoSendMsgServiceImpl.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo> implements TenantInfoService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private static final Logger log = LoggerFactory.getLogger(TenantInfoServiceImpl.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public TenantInfoDao baseMapper() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return baseMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private SysUserFeignService sysUserFeignService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -88,6 +94,8 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private StudentService studentService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private SysMessageService sysMessageService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private TenantInfoSendMsgService tenantInfoSendMsgService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * 新增机构 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -335,12 +343,9 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date expiryDate = getExpiryDate(productInfo.getExpiryCount(), productInfo.getExpiryUnit(), now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         productInfo.setExpiryDate(expiryDate); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         tenantProductInfoService.updateById(productInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //发送邮件提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<Integer, String> receivers = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        receivers.put(tenantInfo.getUserId(), tenantInfo.getEmail()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                MessageTypeEnum.EMAIL_TENANT_ACTIVATION_SUCCESSFUL, receivers, null, 0, null, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "SYSTEM", tenantInfo.getName(), tenantInfo.getPhone(), "123456", "https://online.dayaedu.com"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //发送邮件及短信提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Object[] msg = {tenantInfo.getName(), tenantInfo.getPhone(), "123456", "https://online.dayaedu.com"}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        tenantInfoSendMsgService.sendToAll(OPEN, tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -499,14 +504,14 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     1,//临时写死 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     tenantEnum.getCode() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //操作续费信息,把续费周期存起来 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            opsRenewInfo(tenantId).set(val, 1, TimeUnit.HOURS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //续费成功 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             renewSuccess(val, productInfo, amount); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             orderState = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         createOrderRecord(tenantId, amount, orderNo, tenantEnum, orderState); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //写入续费信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        opsRenewInfo(tenantId).set(val, 1, TimeUnit.HOURS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         log.info("tenant pay >>>>> {} ", result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -525,6 +530,13 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @param amount      续费总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void renewSuccess(Integer val, TenantProductInfo productInfo, BigDecimal amount) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer tenantId = productInfo.getTenantId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        RBucket<Object> bucket = redissonClient.getBucket("tenant_renew_success:" + tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!bucket.trySet(tenantId, 1, TimeUnit.MINUTES)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //防止重复修改数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date expiryDate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (productInfo.getExpiryDate().compareTo(now) > 0) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -539,15 +551,12 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         productInfo.setExpiryCount(productInfo.getExpiryCount() + val); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         tenantProductInfoService.updateById(productInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        TenantInfo tenantInfo = this.getById(productInfo.getTenantId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //发送邮件提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        Map<Integer, String> receivers = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        receivers.put(tenantInfo.getUserId(), tenantInfo.getEmail()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.EMAIL, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                MessageTypeEnum.EMAIL_TENANT_RENEWAL_SUCCESSFUL, receivers, null, 0, null, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                "SYSTEM", tenantInfo.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TenantInfo tenantInfo = this.getById(tenantId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //发送邮件及短信提醒 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Object[] msg = {tenantInfo.getName()}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        tenantInfoSendMsgService.sendToAll(RENEW, tenantInfo.getUserId(), tenantInfo.getEmail(), tenantInfo.getPhone(), msg); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //释放锁 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        bucket.delete(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private TenantProductInfo getProductInfo(Integer tenantId) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -798,6 +807,41 @@ public class TenantInfoServiceImpl extends ServiceImpl<TenantInfoDao, TenantInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         baseMapper.updatePhone(newPhone, oldPhone); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     * 监测机构状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void checkTenantState() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date now = LocalDate.now().toDate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //查询还差30天和1天过期的机构,并发送邮件和短信 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Integer[] days = {30, 1}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Arrays.stream(days).forEach(d -> checkAndSend(now, d)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //查询过期并且没有停用的机构,将其停用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date maturity = DateUtils.addDays(now, -1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TenantInfo> maturityTenant = baseMapper.queryExpiryTenant(maturity); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        maturityTenant.forEach(t -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            t.setState(2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            t.setUpdatedBy(-1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            t.setUpdatedTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            this.updateById(t); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void checkAndSend(Date now, int i) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        Date one = DateUtils.addDays(now, i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<TenantInfo> oneTenant = baseMapper.queryExpiryTenant(one); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        send(oneTenant, DateUtils.formatDate(one, "yyyy年MM月dd日")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private void send(List<TenantInfo> infoList, String dateStr) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        infoList.forEach(t -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            Object[] objects = {t.getName(), dateStr}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            tenantInfoSendMsgService.sendToAll(EXPIRATION, t.getUserId(), t.getEmail(), t.getPhone(), objects); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public TenantInfo queryTenantInfoByOrgan(Integer organId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return baseMapper.queryTenantInfoByOrgan(organId); 
			 |