|
@@ -1,11 +1,18 @@
|
|
|
package com.caimei365.tools.task;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.tools.mapper.BaseMapper;
|
|
|
import com.caimei365.tools.mapper.HeheMapper;
|
|
|
import com.caimei365.tools.model.bo.CouponBo;
|
|
|
import com.caimei365.tools.model.bo.HeheCollageBo;
|
|
|
import com.caimei365.tools.model.bo.HeheCouponBo;
|
|
|
import com.caimei365.tools.model.bo.HeheUserBo;
|
|
|
+import com.caimei365.tools.model.dto.message.InsideMessage;
|
|
|
+import com.caimei365.tools.model.dto.message.MessageModel;
|
|
|
+import com.caimei365.tools.model.dto.message.MqInfo;
|
|
|
+import com.caimei365.tools.model.dto.message.enums.MessageType;
|
|
|
+import com.caimei365.tools.model.po.OrderVo;
|
|
|
+import com.caimei365.tools.service.MessageSender;
|
|
|
import com.caimei365.tools.utils.CodeUtil;
|
|
|
import com.caimei365.tools.utils.DateUtils;
|
|
|
import com.caimei365.tools.utils.SmsUtil;
|
|
@@ -14,13 +21,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
@@ -39,18 +45,19 @@ public class HeheTask {
|
|
|
private BaseMapper baseMapper;
|
|
|
@Resource
|
|
|
private HeheMapper heheMapper;
|
|
|
+ @Resource
|
|
|
+ private MessageSender messageSender;
|
|
|
@Value("${spring.cloud.config.profile}")
|
|
|
private String profile;
|
|
|
-
|
|
|
/**
|
|
|
* 每隔半小时检查这半小时内生效的优惠券,并给对应用户发送短信
|
|
|
*/
|
|
|
@Scheduled(cron = "0 0/30 * * * ?")
|
|
|
public void couponOpen() {
|
|
|
- log.info("呵呵商城定时发送短信");
|
|
|
+ log.info("颜选美学商城定时发送短信");
|
|
|
// 查询半小时内生效的活动券及专享券
|
|
|
List<HeheCouponBo> couponList = heheMapper.getNewHeheCoupons();
|
|
|
- // 查询呵呵商城所有用户的手机号
|
|
|
+ // 查询颜选美学商城所有用户的手机号
|
|
|
List<String> mobileList = heheMapper.getHeheUserMobiles();
|
|
|
AtomicInteger a = new AtomicInteger();
|
|
|
AtomicInteger b = new AtomicInteger();
|
|
@@ -63,41 +70,62 @@ public class HeheTask {
|
|
|
couponList.forEach(coupon->{
|
|
|
Double couponAmount = coupon.getCouponAmount();
|
|
|
AtomicReference<String> content = new AtomicReference<>("");
|
|
|
+ List<String> userIdByUserYear = heheMapper.findUserIdByUserYear(3);
|
|
|
+ String insideContent;
|
|
|
+ int type;
|
|
|
if (1 == coupon.getCouponType()) {
|
|
|
// 活动券,给所有注册用户发送短信
|
|
|
+ type=0;
|
|
|
+ insideContent=couponAmount+"元优惠券已派送到您的领券中心,快去领取下单吧。";
|
|
|
mobileList.forEach(mobile -> {
|
|
|
if (StringUtils.isBlank(mobile) || mobile.length() != 11) {
|
|
|
- log.info("【呵呵短信】,手机号异常,mobile>>>>>" + mobile);
|
|
|
+ log.info("【颜选美学短信】,手机号异常,mobile>>>>>" + mobile);
|
|
|
} else {
|
|
|
// 正式环境或指定手机号
|
|
|
if ("prod".equals(profile) || list.contains(mobile)) {
|
|
|
content.set(couponAmount + "元优惠券已派送到您的领券中心,请赶紧登录颜选美学小程序领取下单吧。退订回T");
|
|
|
String result = SmsUtil.sendSms(3, mobile, content.get());
|
|
|
- log.info("【呵呵短信】,result>>>>>>" + result);
|
|
|
+ log.info("【颜选美学短信】,result>>>>>>" + result);
|
|
|
a.getAndIncrement();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
// 专享券
|
|
|
+ type=2;
|
|
|
+ insideContent=couponAmount+"为了感谢您长久以来的支持,现已派送" + couponAmount + "元优惠券到您的领券中心,快去领取下单吧。";
|
|
|
String userIds = coupon.getUserIds();
|
|
|
String[] userIdArr = userIds.split(",");
|
|
|
for (int i = 0; i < userIdArr.length; i++) {
|
|
|
// 查询用户手机号
|
|
|
String mobile = heheMapper.findHeheMobile(userIdArr[i]);
|
|
|
if (StringUtils.isBlank(mobile) || mobile.length() != 11) {
|
|
|
- log.info("【呵呵短信】,手机号异常,mobile>>>>>" + mobile);
|
|
|
+ log.info("【颜选美学短信】,手机号异常,mobile>>>>>" + mobile);
|
|
|
} else {
|
|
|
// 正式环境或指定手机号
|
|
|
if ("prod".equals(profile) || list.contains(mobile)) {
|
|
|
content.set("为了感谢您长久以来的支持,现已派送" + couponAmount + "元优惠券到您的领券中心,请赶紧登录颜选美学小程序领取下单吧。退订回T");
|
|
|
String result = SmsUtil.sendSms(3, mobile, content.get());
|
|
|
- log.info("【呵呵短信】,result>>>>>>" + result);
|
|
|
+ log.info("【颜选美学短信】,result>>>>>>" + result);
|
|
|
b.getAndIncrement();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ for (String userId : userIdByUserYear) {
|
|
|
+ //站内信 【活动卷/专享卷】
|
|
|
+ MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
|
|
|
+ insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
|
|
|
+ .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
|
|
|
+ .info(new InsideMessage()
|
|
|
+ .userType(4)
|
|
|
+ .messageType(4)
|
|
|
+ .couponType(type)
|
|
|
+ .content(insideContent)
|
|
|
+ .thisId(Integer.valueOf(userId))
|
|
|
+ );
|
|
|
+ messageSender.messageSend(insideMessageMessageModel);
|
|
|
+ }
|
|
|
});
|
|
|
baseMapper.updateSmsSendCount(15, a.get());
|
|
|
baseMapper.updateSmsSendCount(16, b.get());
|
|
@@ -165,6 +193,18 @@ public class HeheTask {
|
|
|
//7天后优惠券即将过期推送
|
|
|
content.set("您有优惠券即将过期,请赶紧登录颜选美学小程序领取下单吧。退订回T");
|
|
|
String result = SmsUtil.sendSms(3, mobile, content.get());
|
|
|
+ //站内信 【7天后优惠券即将过期推送】
|
|
|
+ MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
|
|
|
+ insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
|
|
|
+ .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
|
|
|
+ .info(new InsideMessage()
|
|
|
+ .userType(4)
|
|
|
+ .messageType(4)
|
|
|
+ .couponMessageType(2)
|
|
|
+ .content("您有"+coupon.getCouponAmount()+"元优惠券将于7日后过期,快去使用吧。")
|
|
|
+ .thisId(userId)
|
|
|
+ );
|
|
|
+ messageSender.messageSend(insideMessageMessageModel);
|
|
|
a++;
|
|
|
continue A;
|
|
|
}
|
|
@@ -172,6 +212,18 @@ public class HeheTask {
|
|
|
//当天优惠券即将过期推送
|
|
|
content.set("您有优惠券今日将过期,请赶紧登录颜选美学小程序领取下单吧。退订回T");
|
|
|
String result = SmsUtil.sendSms(3, mobile, content.get());
|
|
|
+ //站内信 【当天优惠券即将过期推送】
|
|
|
+ MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
|
|
|
+ insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
|
|
|
+ .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
|
|
|
+ .info(new InsideMessage()
|
|
|
+ .userType(4)
|
|
|
+ .messageType(4)
|
|
|
+ .couponMessageType(2)
|
|
|
+ .content("您有"+coupon.getCouponAmount()+"元优惠券今日将过期,快去使用吧。")
|
|
|
+ .thisId(userId)
|
|
|
+ );
|
|
|
+ messageSender.messageSend(insideMessageMessageModel);
|
|
|
b++;
|
|
|
continue A;
|
|
|
}
|
|
@@ -184,6 +236,18 @@ public class HeheTask {
|
|
|
//离失效日只剩7天还没领取
|
|
|
content.set("您有优惠券尚未领取,优惠券即将失效,请赶紧登录颜选美学小程序领取下单吧。退订回T");
|
|
|
String result = SmsUtil.sendSms(3, mobile, content.get());
|
|
|
+ //站内信 【离失效日只剩7天还没领取】
|
|
|
+ MessageModel<InsideMessage> insideMessageMessageModel = new MessageModel<>();
|
|
|
+ insideMessageMessageModel.code(MessageType.WEB_INSIDE_MESSAGE)
|
|
|
+ .mqInfo(new MqInfo().topic("MessageLine").delay(3).async(1))
|
|
|
+ .info(new InsideMessage()
|
|
|
+ .userType(4)
|
|
|
+ .messageType(4)
|
|
|
+ .couponMessageType(1)
|
|
|
+ .content("您有"+coupon.getCouponAmount()+"元优惠券尚未领取,优惠券即将失效,快去领取下单吧。")
|
|
|
+ .thisId(userId)
|
|
|
+ );
|
|
|
+ messageSender.messageSend(insideMessageMessageModel);
|
|
|
c++;
|
|
|
continue A;
|
|
|
}
|
|
@@ -195,6 +259,33 @@ public class HeheTask {
|
|
|
baseMapper.updateSmsSendCount(22, c);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 用户下单后,5分钟内没有线上支付 推送短信,定时查询一次
|
|
|
+ */
|
|
|
+ @Scheduled(cron = "0 */5 * * * ?")
|
|
|
+ public void waitPay() {
|
|
|
+ log.info("******************** 用户下单后,5分钟内没有线上支付 推送短信 start *******************");
|
|
|
+ List<OrderVo> orderList = heheMapper.getOrderMinuteList(5);
|
|
|
+ orderList.forEach((order) -> {
|
|
|
+ String name = order.getProductName();
|
|
|
+ if (name.length() > 10) {
|
|
|
+ name = name.substring(0, 10);
|
|
|
+ }
|
|
|
+ String content = "【颜选美学】您已成功下单“" + name + "...”等" + order.getProductCount() + "件商品,订单编号:" + order.getOrderNo() + ",订单等待支付,支付完成后采美将尽快安排发货。您可使用微信小程序“颜选美学”查看并支付订单。";
|
|
|
+ //发送短信 【用户下单后,5分钟内没有线上支付,推送短信】
|
|
|
+ String result = SmsUtil.sendSms(3, order.getMobile().substring(1), content);
|
|
|
+ JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
+ log.info("发送结果:" + result + ",短信内容:" + content);
|
|
|
+ if (null != json && json.getInteger("code") == 0) {
|
|
|
+ log.info(order.getMobile() + "发送成功");
|
|
|
+ } else {
|
|
|
+ log.error(order.getMobile() + "发送失败");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ log.info("******************** 用户下单后,5分钟内没有线上支付 推送短信 end *******************");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 生成短链接
|
|
|
*
|