|
@@ -1,9 +1,12 @@
|
|
package com.caimei365.tools.task;
|
|
package com.caimei365.tools.task;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei365.tools.mapper.LogisticsMapper;
|
|
import com.caimei365.tools.mapper.LogisticsMapper;
|
|
import com.caimei365.tools.model.ResponseJson;
|
|
import com.caimei365.tools.model.ResponseJson;
|
|
import com.caimei365.tools.model.po.LogisticsInfoPo;
|
|
import com.caimei365.tools.model.po.LogisticsInfoPo;
|
|
|
|
+import com.caimei365.tools.model.po.SuperVipPo;
|
|
import com.caimei365.tools.service.LogisticsService;
|
|
import com.caimei365.tools.service.LogisticsService;
|
|
|
|
+import com.caimei365.tools.utils.SmsUtil;
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
import com.kuaidi100.sdk.response.QueryTrackResp;
|
|
import com.kuaidi100.sdk.response.QueryTrackResp;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
@@ -16,6 +19,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.Calendar;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
@@ -39,7 +43,7 @@ public class LogisticsInfoTask {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 每小时执行一次查询物流信息
|
|
* 每小时执行一次查询物流信息
|
|
- *
|
|
|
|
|
|
+ * <p>
|
|
* cron表达式语法:秒 分 小时 日 月 周
|
|
* cron表达式语法:秒 分 小时 日 月 周
|
|
* 年可省略
|
|
* 年可省略
|
|
* * 表示所有值。
|
|
* * 表示所有值。
|
|
@@ -82,7 +86,7 @@ public class LogisticsInfoTask {
|
|
}
|
|
}
|
|
if ("400".equals(queryTrackResp.getReturnCode())) {
|
|
if ("400".equals(queryTrackResp.getReturnCode())) {
|
|
logistics.setState("-1");
|
|
logistics.setState("-1");
|
|
- String errInfo = "[{\"time\":\"" + current + "\",\"context\":\""+queryTrackResp.getMessage()+"\",\"ftime\":\" + new Date() + \"}]";
|
|
|
|
|
|
+ String errInfo = "[{\"time\":\"" + current + "\",\"context\":\"" + queryTrackResp.getMessage() + "\",\"ftime\":\" + new Date() + \"}]";
|
|
logistics.setInfo(errInfo);
|
|
logistics.setInfo(errInfo);
|
|
logistics.setUpdateDate(current);
|
|
logistics.setUpdateDate(current);
|
|
updateFlag = true;
|
|
updateFlag = true;
|
|
@@ -106,4 +110,79 @@ public class LogisticsInfoTask {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 每天3点查一次超级会员是否到期,短信推送
|
|
|
|
+ * <p>
|
|
|
|
+ * cron表达式语法:秒 分 小时 日 月 周
|
|
|
|
+ * 年可省略
|
|
|
|
+ * * 表示所有值。
|
|
|
|
+ * ? 表示不指定值。
|
|
|
|
+ */
|
|
|
|
+ @Scheduled(cron = "0 0 15 * * ?")
|
|
|
|
+ public void checkVip() {
|
|
|
|
+ try {
|
|
|
|
+ log.info("开始检测超级会员到期时间");
|
|
|
|
+ Date startTime = getNowTime();
|
|
|
|
+ Date endTime = getEndTime();
|
|
|
|
+ //今日到期
|
|
|
|
+ String message = "您的超级会员将于今日后到期,到期后将无法享受专属会员权益,快戳采美网站链接www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台续费吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
|
|
|
|
+ List<SuperVipPo> vip = logisticsMapper.findVip(startTime, endTime);
|
|
|
|
+ if (vip != null && vip.size() > 0) {
|
|
|
|
+ vip.forEach(
|
|
|
|
+ v -> {
|
|
|
|
+ String mobile = logisticsMapper.findMobile(v.getUserId());
|
|
|
|
+ String result = SmsUtil.sendSms(3, mobile, message);
|
|
|
|
+ JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
|
+ log.info("发送结果:" + result + ",短信内容:" + message);
|
|
|
|
+ if (null != json && json.getInteger("code") == 0) {
|
|
|
|
+ log.info(mobile + "发送成功");
|
|
|
|
+ } else {
|
|
|
|
+ log.error(mobile + "发送失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ //7天后到期
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ cal.setTime(startTime);
|
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, 7);
|
|
|
|
+ Date endTime7 = cal.getTime();
|
|
|
|
+ cal.setTime(startTime);
|
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, 7);
|
|
|
|
+ Date startTime7 = cal.getTime();
|
|
|
|
+ String mes = "您的超级会员将于7日后到期,到期后将无法享受专属会员权益,快戳采美网站链接www.caimei365.com或微信搜索“采美采购商城”小程序登录采美平台续费吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
|
|
|
|
+ List<SuperVipPo> vips = logisticsMapper.findVip(startTime7, endTime7);
|
|
|
|
+ if (vips != null && vips.size() > 0) {
|
|
|
|
+ vips.forEach(
|
|
|
|
+ v -> {
|
|
|
|
+ String mobile = logisticsMapper.findMobile(v.getUserId());
|
|
|
|
+ String result = SmsUtil.sendSms(3, mobile, mes);
|
|
|
|
+ JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
|
+ log.info("发送结果:" + result + ",短信内容:" + mes);
|
|
|
|
+ if (null != json && json.getInteger("code") == 0) {
|
|
|
|
+ log.info(mobile + "发送成功");
|
|
|
|
+ } else {
|
|
|
|
+ log.error(mobile + "发送失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("自动检测会员到期时间失败", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Date getNowTime() {
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
|
|
|
+ return cal.getTime();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Date getEndTime() {
|
|
|
|
+ Calendar cal = Calendar.getInstance();
|
|
|
|
+ cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
|
|
|
|
+ cal.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
|
+ return cal.getTime();
|
|
|
|
+ }
|
|
}
|
|
}
|