| | |
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.scheduling.annotation.Scheduled;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.xxl.job.core.biz.model.ReturnT;
|
| | | import com.xxl.job.core.handler.annotation.XxlJob;
|
| | | import com.yeshi.fanli.dto.jd.JDOrderResult;
|
| | | import com.yeshi.fanli.entity.jd.JDOrder;
|
| | | import com.yeshi.fanli.exception.jd.JDOrderException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.order.jd.JDOrderService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.RedisKeyEnum;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.cmq.JDOrderCMQManager;
|
| | | import com.yeshi.fanli.util.cmq.order.JDOrderCMQManager;
|
| | | import com.yeshi.fanli.util.jd.JDApiUtil;
|
| | |
|
| | | //从淘宝爬去订单更新
|
| | |
| | | */
|
| | | public void saveJDOrders(List<JDOrder> jdOrderList) {
|
| | | for (JDOrder order : jdOrderList) {
|
| | | LogHelper.orderInfo("京东订单:" + order.getOrderId());
|
| | | if (order.getValidCode() == 15)// 过滤掉代付款状态
|
| | | LogHelper.orderInfo("京东订单:" + order.getOrderId() + "-" + order.getValidCode());
|
| | | if (order.getValidCode() == 15)// 过滤掉待付款
|
| | | continue;
|
| | |
|
| | | // 防止多个商品拆单问题,爬取
|
| | | if (order.getOrderItemList().size() > 1
|
| | | && order.getOrderTime() > System.currentTimeMillis() - 1000 * 60 * 3L) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | try {
|
| | | jdOrderService.addJDOrder(order);
|
| | | /**
|
| | | * 做频率限制
|
| | | */
|
| | | String key = "jd-order-" + order.getOrderId();
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.JDOrder, order.getOrderId() + "");
|
| | | String result = redisManager.getCommonString(key);
|
| | |
|
| | | JDOrderCMQManager.getInstance().addJDOrder(order.getOrderId() + "");
|
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 2小时内不再更新
|
| | | // 判断
|
| | | if (StringUtil.isNullOrEmpty(result)) {
|
| | | JDOrderCMQManager.getInstance().addJDOrder(order.getOrderId() + "");
|
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 2小时内不再更新
|
| | | }
|
| | | } catch (JDOrderException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | /**
|
| | | * 快速订单更新(爬取本小时内的单,每分钟一次)
|
| | | */
|
| | | @Scheduled(cron = "0 0/1 * * * ? ")
|
| | | public void updateSoonOrder() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | LogHelper.job("开始爬取京东订单"); |
| | | long now = System.currentTimeMillis();
|
| | | @XxlJob("updateJDOrderHandler")
|
| | | public ReturnT<String> updateJDSoonOrder(String param) throws Exception {
|
| | | if ("1".equalsIgnoreCase(param)) {//更新本小时内的单
|
| | | LogHelper.job("开始爬取京东订单");
|
| | | long now = System.currentTimeMillis();
|
| | |
|
| | | JDOrderResult result = JDApiUtil.getOrderList(1, 200, new Date(now), JDApiUtil.ORDER_TYPE_CREATETIME);
|
| | | if (result != null && result.getOrderList() != null)
|
| | | saveJDOrders(result.getOrderList());
|
| | | // 查询上个小时的
|
| | | result = JDApiUtil.getOrderList(1, 200, new Date(now - 1000 * 60 * 60L), JDApiUtil.ORDER_TYPE_CREATETIME);
|
| | | if (result != null && result.getOrderList() != null)
|
| | | saveJDOrders(result.getOrderList());
|
| | | JDOrderResult result = JDApiUtil.getOrderList(1, 200, new Date(now), JDApiUtil.ORDER_TYPE_CREATETIME);
|
| | | if (result != null && result.getOrderList() != null)
|
| | | saveJDOrders(result.getOrderList());
|
| | | // 查询上个小时的
|
| | | result = JDApiUtil.getOrderList(1, 200, new Date(now - 1000 * 60 * 60L), JDApiUtil.ORDER_TYPE_CREATETIME);
|
| | | if (result != null && result.getOrderList() != null)
|
| | | saveJDOrders(result.getOrderList());
|
| | | } else if ("1hour".equalsIgnoreCase(param)) {// 更新1小时内的订单
|
| | | updateUpdateOrder();
|
| | | } else if ("3day".equalsIgnoreCase(param)) {// 更新最近3天更新的数据
|
| | | updateLatest3DayOrder();
|
| | | }
|
| | |
|
| | | return ReturnT.SUCCESS;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 爬取最近一小时内的状态更新了的单(10分钟一次)
|
| | | */
|
| | | @Scheduled(cron = "0 0/10 * * * ? ")
|
| | |
|
| | | public void updateUpdateOrder() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | List<JDOrder> jdOrderList = new ArrayList<>();
|
| | | int pageSize = 200;
|
| | | int page = 1;
|
| | |
| | | /**
|
| | | * 更新最近3天的订单(每天早上凌晨0点过10分,早上8点过10分)
|
| | | */
|
| | | @Scheduled(cron = "0 10 0,8 * * ? ")
|
| | | public void updateLatest3DayOrder() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | Date now = new Date();
|
| | | for (int i = 1; i < 4; i++) {
|
| | | updateDayOrder(new Date(now.getTime() - 1000 * 60 * 60 * 24L * i));
|