|
@@ -1,22 +1,16 @@
|
|
|
package com.caimei365.tools.task;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.caimei365.tools.mapper.LogisticsMapper;
|
|
|
-import com.caimei365.tools.model.ResponseJson;
|
|
|
-import com.caimei365.tools.model.po.LogisticsInfoPo;
|
|
|
+import com.caimei365.tools.mapper.BaseMapper;
|
|
|
import com.caimei365.tools.model.po.SuperVipPo;
|
|
|
import com.caimei365.tools.service.LogisticsService;
|
|
|
import com.caimei365.tools.utils.SmsUtil;
|
|
|
-import com.google.gson.Gson;
|
|
|
-import com.kuaidi100.sdk.response.QueryTrackResp;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Calendar;
|
|
@@ -34,82 +28,8 @@ import java.util.List;
|
|
|
@EnableScheduling
|
|
|
@RequiredArgsConstructor
|
|
|
public class LogisticsInfoTask {
|
|
|
-
|
|
|
- private final LogisticsService logisticsService;
|
|
|
@Resource
|
|
|
- private LogisticsMapper logisticsMapper;
|
|
|
- @Value("${spring.cloud.config.profile}")
|
|
|
- private String profile;
|
|
|
-
|
|
|
- /**
|
|
|
- * 每小时执行一次查询物流信息
|
|
|
- * <p>
|
|
|
- * cron表达式语法:秒 分 小时 日 月 周
|
|
|
- * 年可省略
|
|
|
- * * 表示所有值。
|
|
|
- * ? 表示不指定值。
|
|
|
- */
|
|
|
- @Scheduled(cron = "0 0 * * * ?")
|
|
|
- public void getLogistics() {
|
|
|
- log.info(">> 定时查询物流信息");
|
|
|
- // 正式环境才去查询物流信息
|
|
|
- if ("prod".equals(profile)) {
|
|
|
- // 近一年未签收物流列表
|
|
|
- List<LogisticsInfoPo> logisticsList = logisticsMapper.getAllUnsignedLogistics();
|
|
|
- if (!CollectionUtils.isEmpty(logisticsList)) {
|
|
|
- logisticsList.forEach(logistics -> {
|
|
|
- boolean updateFlag = false;
|
|
|
- Date current = new Date();
|
|
|
- String logMsg = null;
|
|
|
- if (logistics.getNu().length() >= 8) {
|
|
|
- ResponseJson<QueryTrackResp> result = logisticsService.getLogisticsByNumber(logistics.getNu(), logistics.getLogisticsCompanyCode(), "");
|
|
|
- if (result.getCode() == -2) {
|
|
|
- // 顺丰速运需要提供收/寄件人的电话号码查询
|
|
|
- String mobile = logisticsMapper.getLogisticsPhoneByOrderId(logistics.getOrderId());
|
|
|
- if (StringUtils.isNotEmpty(mobile)) {
|
|
|
- result = logisticsService.getLogisticsByNumber(logistics.getNu(), logistics.getLogisticsCompanyCode(), mobile);
|
|
|
- }
|
|
|
- }
|
|
|
- if (result.getCode() == 0) {
|
|
|
- // 查询成功
|
|
|
- QueryTrackResp queryTrackResp = result.getData();
|
|
|
- String state = queryTrackResp.getState();
|
|
|
- String companyCode = queryTrackResp.getCom();
|
|
|
- String info = new Gson().toJson(queryTrackResp.getData());
|
|
|
- if (StringUtils.isNotEmpty(state) && StringUtils.isNotEmpty(info)) {
|
|
|
- logistics.setState(state);
|
|
|
- logistics.setLogisticsCompanyCode(companyCode);
|
|
|
- logistics.setInfo(info);
|
|
|
- logistics.setUpdateDate(current);
|
|
|
- updateFlag = true;
|
|
|
- logMsg = "已成功更新!";
|
|
|
- }
|
|
|
- if ("400".equals(queryTrackResp.getReturnCode())) {
|
|
|
- logistics.setState("-1");
|
|
|
- String errInfo = "[{\"time\":\"" + current + "\",\"context\":\"" + queryTrackResp.getMessage() + "\",\"ftime\":\" + new Date() + \"}]";
|
|
|
- logistics.setInfo(errInfo);
|
|
|
- logistics.setUpdateDate(current);
|
|
|
- updateFlag = true;
|
|
|
- logMsg = queryTrackResp.getMessage();
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- logistics.setState("-1");
|
|
|
- String errInfo = "[{\"time\":\"" + current + "\",\"context\":\"运单号错误!\",\"ftime\":\"" + current + "\"}]";
|
|
|
- logistics.setInfo(errInfo);
|
|
|
- logistics.setUpdateDate(current);
|
|
|
- updateFlag = true;
|
|
|
- logMsg = "运单号错误!";
|
|
|
- }
|
|
|
- if (updateFlag) {
|
|
|
- // 更新数据库物流信息
|
|
|
- logisticsMapper.updateLogistics(logistics);
|
|
|
- log.info(">> 定时任务 >> 更新物流信息到DB:" + logMsg);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ private BaseMapper baseMapper;
|
|
|
|
|
|
/**
|
|
|
* 每天3点查一次超级会员是否到期,短信推送
|
|
@@ -127,11 +47,11 @@ public class LogisticsInfoTask {
|
|
|
Date endTime = getEndTime();
|
|
|
//今日到期
|
|
|
String message = "您的超级会员将于今日后到期,到期后将无法享受专属会员权益,快戳采美网站链接www.caimei365.com 或微信搜索“采美采购商城”小程序登录采美平台续费吧。关注公众号“采美365网”可获取更多优惠和精彩资讯。退订回T";
|
|
|
- List<SuperVipPo> vip = logisticsMapper.findVip(startTime, endTime);
|
|
|
+ List<SuperVipPo> vip = baseMapper.findVip(startTime, endTime);
|
|
|
if (vip != null && vip.size() > 0) {
|
|
|
vip.forEach(
|
|
|
v -> {
|
|
|
- String mobile = logisticsMapper.findMobile(v.getUserId());
|
|
|
+ String mobile = baseMapper.findMobile(v.getUserId());
|
|
|
String result = SmsUtil.sendSms(3, mobile, message);
|
|
|
JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
log.info("发送结果:" + result + ",短信内容:" + message);
|
|
@@ -152,11 +72,11 @@ public class LogisticsInfoTask {
|
|
|
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);
|
|
|
+ List<SuperVipPo> vips = baseMapper.findVip(startTime7, endTime7);
|
|
|
if (vips != null && vips.size() > 0) {
|
|
|
vips.forEach(
|
|
|
v -> {
|
|
|
- String mobile = logisticsMapper.findMobile(v.getUserId());
|
|
|
+ String mobile = baseMapper.findMobile(v.getUserId());
|
|
|
String result = SmsUtil.sendSms(3, mobile, mes);
|
|
|
JSONObject json = (JSONObject) JSONObject.parse(result);
|
|
|
log.info("发送结果:" + result + ",短信内容:" + mes);
|