Parcourir la source

fix 账号有效期小于5天的人,不发账号替换/改密码短信提醒

zoujiajian il y a 3 ans
Parent
commit
d8bdd429c4

+ 4 - 0
netflix-service/src/main/java/com/cyksj/common/EnvCommonService.java

@@ -33,4 +33,8 @@ public class EnvCommonService {
 	public String getDomain() {
 		return this.getHost().substring(0, this.getHost().indexOf("8081"));
 	}
+
+	public Boolean isPrdEnv() {
+		return EnvCommonService.active_prd.equals(getEnv());
+	}
 }

+ 23 - 5
netflix-service/src/main/java/com/cyksj/service/mange/group/CmsGroupServiceImpl.java

@@ -1,10 +1,12 @@
 package com.cyksj.service.mange.group;
 
 import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.cyksj.common.EnvCommonService;
 import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
@@ -54,6 +56,8 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
 
     private final SmsService smsService;
 
+    private final EnvCommonService envCommonService;
+
     private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
 
 
@@ -125,6 +129,7 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
         if (StrUtil.isNotBlank(verifyCodes)) {
             verifyCodeArray = verifyCodes.split(",");
         }
+        Boolean isPrdEnv = envCommonService.isPrdEnv();
         for (int i = 0; i < groupsRelations.size(); i++) {
             GroupsRelation relation = groupsRelations.get(i);
             if (relation.getExpiryTime() == null) {
@@ -144,8 +149,10 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
                     orderDonMapper.updateById(orderDon);
                 });
             }
-            //发送短信
-            smsService.sendSmsToRelationUser(relation.getUserId(), msg);
+            if (relation.getUserId() != 0 && isPrdEnv) {
+                //发送短信
+                smsService.sendSmsToRelationUser(relation.getUserId(), msg);
+            }
             if (verifyCodeArray != null && verifyCodeArray.length > 0 && i < verifyCodeArray.length) {
                 relation.setVerifyCode(verifyCodeArray[i]);
                 relationMapper.updateById(relation);
@@ -226,11 +233,22 @@ public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> i
 
     private void sendChangeAccountMsg(Long groupsId, Long goodsId) {
         GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
+        String title = goodsDon != null ? goodsDon.getTitle() : "车票";
+        DateTime now = DateTime.now();
+        Boolean isPrd = envCommonService.isPrdEnv();
         List<GroupsRelation> groupsRelations = beanSearcher.searchAll(GroupsRelation.class, MapUtils.builder().field(GroupsRelation::getGroupsId, groupsId).build());
         groupsRelations.forEach(relation -> {
-            String title = goodsDon != null ? goodsDon.getTitle() : "车票";
-            String msg = String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
-            smsService.sendSmsToRelationUser(relation.getUserId(), msg);
+            if (relation.getExpiryTime() == null) {
+                return;
+            }
+            //账号有效期小于5天的人,不发账号替换/改密码短信提醒
+            if (now.after(DateUtil.offsetDay(relation.getExpiryTime(), -5))) {
+                return;
+            }
+            if (relation.getUserId() != 0 && isPrd) {
+                String msg = String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
+                smsService.sendSmsToRelationUser(relation.getUserId(), msg);
+            }
         });
     }
 }

+ 19 - 1
netflix-service/src/main/java/com/cyksj/service/template/impl/TemplateCommonServiceImpl.java

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.cyksj.common.EnvCommonService;
+import com.cyksj.common.constant.Constant;
 import com.cyksj.common.constant.TemplateEnum;
 import com.cyksj.common.util.Jsons;
 import com.cyksj.common.util.StringUtil;
@@ -20,6 +21,7 @@ import com.cyksj.model.entity.*;
 import com.cyksj.model.manage.request.ReqSetLogisticsPost;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.views.WxAppTemplateView;
+import com.cyksj.service.sms.SmsService;
 import com.cyksj.service.template.TemplateCommonService;
 import com.cyksj.service.wechat.WeChatService;
 import com.ejlchina.searcher.BeanSearcher;
@@ -61,6 +63,8 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 
 	private final GoodsDonSkuMapper goodsDonSkuMapper;
 
+	private final SmsService smsService;
+
 	public void newOderSendMsgByType(OrderDon order, GoodsDon goodsDon, User user, String toPeople, Boolean isCustomer) throws Exception {
 		if (!EnvCommonService.active.equals(envCommonService.getEnv())) {
 			String openId = toPeople;
@@ -210,9 +214,23 @@ public class TemplateCommonServiceImpl implements TemplateCommonService {
 					.field(GroupsRelationView::getAccountId, account.getId()).op(Operator.Equal)
 					.field(GroupsRelationView::getStatus, "validity").op(Operator.Equal)
 					.build());
+			Boolean isPrdEnv = envCommonService.isPrdEnv();
+			GoodsDon goodsDon = goodsDonMapper.selectById(account.getGoodsId());
+			String title = goodsDon != null ? goodsDon.getTitle() : "车票";
+			DateTime now = DateTime.now();
 			log.info("开始发送账号修改密码模板消息,大小:{}", relations.size());
 			for (GroupsRelationView relation : relations) {
-				sendUpdateAccountMsg(relation);
+				if (relation.getExpiryTime() == null) {
+					return;
+				}
+				//账号有效期小于5天的人,不发账号替换/改密码短信提醒
+				if (now.after(DateUtil.offsetDay(relation.getExpiryTime(), -5))) {
+					return;
+				}
+				if (relation.getUserId() != 0 && isPrdEnv) {
+					String msg = String.format(Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
+					smsService.sendSmsToRelationUser(relation.getUserId(), msg);
+				}
 			}
 		}
 	}

+ 19 - 19
netflix-service/src/main/java/com/cyksj/task/Scheduler.java

@@ -114,14 +114,15 @@ public class Scheduler {
         expiryList.forEach(relation -> groupRelationClearService.clearTicket(relation, UserTicketClearedRecord.Source.self));
     }
 
-    @Scheduled(cron = "0 0 9 * * ?")
-    public void expiryWxMsg() throws Exception {
-        DateTime now = new DateTime();
-        DateTime zero = DateUtil.offset(now, DateField.HOUR, -9);
-        DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 3);
-	    List<GroupsRelationView> groupsRelations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getExpiryTime, time).op(Operator.LessEqual).build());
-        //String url = String.format("%sauth/weChat?url=%syinhe/web/ticket", envCommonService.getHost(), envCommonService.getDomain());
-        for (GroupsRelationView relation : groupsRelations) {
+	@Scheduled(cron = "0 0 9 * * ?")
+	public void expiryWxMsg() throws Exception {
+		if (envCommonService.isPrdEnv()) {
+			DateTime now = new DateTime();
+			DateTime zero = DateUtil.offset(now, DateField.HOUR, -9);
+			DateTime time = DateUtil.offset(zero, DateField.DAY_OF_MONTH, 3);
+			List<GroupsRelationView> groupsRelations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getExpiryTime, time).op(Operator.LessEqual).build());
+			//String url = String.format("%sauth/weChat?url=%syinhe/web/ticket", envCommonService.getHost(), envCommonService.getDomain());
+			for (GroupsRelationView relation : groupsRelations) {
 //            User user = userMapper.selectById(relation.getUserId());
 //            if (user != null && StrUtil.isNotBlank(user.getOpenId())) {
 //                String openId = user.getOpenId();
@@ -173,17 +174,16 @@ public class Scheduler {
 //                    }
 //                }
 //            }
-	        //短信通知过期账号 用户
-	        try {
-		        String day = DateUtil.formatBetween(zero, relation.getExpiryTime(), BetweenFormater.Level.DAY);
-		        smsService.sendSmsToRelationUser(relation.getUserId(), String.format(Constant.ACCOUNT_EXPIRY_MSG_TEMPLATE, relation.getTitle(), day));
-	        } catch (Exception e) {
-		        log.error("过期账号用户:{}发送短信错误:{}", relation.getUserId(), StringUtil.getErrorText(e));
-	        }
-        }
-
-
-    }
+				//短信通知过期账号 用户
+				try {
+					String day = DateUtil.formatBetween(zero, relation.getExpiryTime(), BetweenFormater.Level.DAY);
+					smsService.sendSmsToRelationUser(relation.getUserId(), String.format(Constant.ACCOUNT_EXPIRY_MSG_TEMPLATE, relation.getTitle(), day));
+				} catch (Exception e) {
+					log.error("过期账号用户:{}发送短信错误:{}", relation.getUserId(), StringUtil.getErrorText(e));
+				}
+			}
+		}
+	}
 
     /**
      * 定时关闭订单