| | |
| | | package com.yeshi.fanli.job.order.vipshop; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.dao.mybatis.vipshop.VipShopOrderMapper; |
| | | import com.yeshi.fanli.dto.mq.order.body.CommonOrderMQMsg; |
| | | import com.yeshi.fanli.entity.order.CommonOrder; |
| | | import com.yeshi.fanli.service.inter.order.CommonOrderService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.mq.cmq.order.OrdersCMQManager; |
| | | import com.yeshi.fanli.util.mq.rabbit.RabbitmqManager; |
| | | import com.yeshi.fanli.util.vipshop.DingDanXiaApiUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import com.xxl.job.core.biz.model.ReturnT; |
| | |
| | | import com.yeshi.fanli.service.inter.order.vipshop.VipShopOrderService; |
| | | import com.yeshi.fanli.util.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.mq.cmq.order.VipShopOrderCMQManager; |
| | | import com.yeshi.fanli.util.vipshop.VipShopApiUtil; |
| | | |
| | | //从淘宝爬去订单更新 |
| | | @Component |
| | | public class UpdateVipShopOrderJob { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger("debugLog"); |
| | | |
| | | @Resource |
| | | private VipShopOrderService vipShopOrderService; |
| | |
| | | private RedisManager redisManager; |
| | | @Resource |
| | | private VipShopOrderMapper vipShopOrderMapper; |
| | | |
| | | @Resource |
| | | private OrdersCMQManager ordersCMQManager; |
| | | |
| | | /** |
| | | * 保存订单 |
| | |
| | | String result = redisManager.getCommonString(key); |
| | | // 判断 |
| | | // if (StringUtil.isNullOrEmpty(result)) { |
| | | VipShopOrderCMQManager.getInstance().addVipShopOrder(order.getOrderSn() + ""); |
| | | ordersCMQManager.addOrder(new CommonOrderMQMsg(order.getOrderSn() + "", Constant.SOURCE_TYPE_VIP)); |
| | | redisManager.cacheCommonString(key, "1", 60 * 60 * 2);// 2小时内不再更新 |
| | | LogHelper.test("唯品会订单消息发送成功"); |
| | | // }else{ |
| | |
| | | @XxlJob("updateVipShopOrderHandler") |
| | | public ReturnT<String> updateVipShopSoonOrder(String param) throws Exception { |
| | | LogHelper.test("updateVipShopOrderHandler:" + param); |
| | | long endTime = System.currentTimeMillis(); |
| | | if ("1hour".equalsIgnoreCase(param)) {// 更新1小时内的订单 |
| | | updateByOrderTime(endTime - 1000 * 60 * 60 * 1L, endTime); |
| | | updateByUpdateTime(endTime - 1000 * 60 * 60 * 1L, endTime); |
| | | } else if ("1day".equalsIgnoreCase(param)) {// 更新最近1天更新的数据 |
| | | updateByOrderTime(endTime - 1000 * 60 * 60 * 24L, endTime); |
| | | updateByUpdateTime(endTime - 1000 * 60 * 60 * 24L, endTime); |
| | | logger.info("唯品会订单更新开始:updateVipShopSoonOrder 参数:"+param); |
| | | try { |
| | | long endTime = System.currentTimeMillis(); |
| | | if ("1hour".equalsIgnoreCase(param)) {// 更新1小时内的订单 |
| | | updateByOrderTime(endTime - 1000 * 60 * 60 * 1L, endTime); |
| | | updateByUpdateTime(endTime - 1000 * 60 * 60 * 1L, endTime); |
| | | } else if ("1day".equalsIgnoreCase(param)) {// 更新最近1天更新的数据 |
| | | Long startT = endTime - 1000 * 60 * 60 * 24L; |
| | | for (long start = startT; start < startT + 1000 * 60 * 60 * 24L; start += 1000 * 60 * 60) { |
| | | updateByOrderTime(start, start + 1000 * 60 * 60); |
| | | updateByUpdateTime(start, start + 1000 * 60 * 60); |
| | | } |
| | | } else if ("1month".equalsIgnoreCase(param)) {// 更新最近1个月的数据 |
| | | for (int i = 0; i < 30; i++) { |
| | | Long startT = endTime - 1000 * 60 * 60 * 24L * (i + 1); |
| | | for (long start = startT; start < startT + 1000 * 60 * 60 * 24L; start += 1000 * 60 * 60) { |
| | | updateByOrderTime(start, start + 1000 * 60 * 60); |
| | | updateByUpdateTime(start, start + 1000 * 60 * 60); |
| | | } |
| | | } |
| | | } |
| | | /* |
| | | * else if ("3day".equalsIgnoreCase(param)) {// 更新最近3天更新的数据 |
| | | * updateByOrderTime(endTime - 1000 * 60 * 60 * 24 * 3L, endTime); |
| | | * updateByUpdateTime(endTime - 1000 * 60 * 60 * 24 * 3L, endTime); } |
| | | */ |
| | | }catch(Exception e){ |
| | | logger.error("唯品会订单更新异常:",e); |
| | | }finally { |
| | | logger.info("唯品会订单更新结束:updateVipShopSoonOrder 参数:"+ param); |
| | | } |
| | | /* |
| | | * else if ("3day".equalsIgnoreCase(param)) {// 更新最近3天更新的数据 |
| | | * updateByOrderTime(endTime - 1000 * 60 * 60 * 24 * 3L, endTime); |
| | | * updateByUpdateTime(endTime - 1000 * 60 * 60 * 24 * 3L, endTime); } |
| | | */ |
| | | |
| | | return ReturnT.SUCCESS; |
| | | } |
| | | |
| | |
| | | //根据订单号更新 |
| | | @XxlJob("order-vip-updateByOrderSn") |
| | | public ReturnT<String> updateByOrderSn(String param) throws Exception { |
| | | List<VipShopOrder> orders = vipShopOrderService.listByOrderSn(param); |
| | | if (orders == null || orders.size() == 0) |
| | | throw new Exception("订单不存在"); |
| | | |
| | | VipShopOrder vipShopOrder = DingDanXiaApiUtil.getOrderDetail(param); |
| | | if (vipShopOrder != null) { |
| | | List<VipShopOrder> vipShopOrderList = new ArrayList<>(); |
| | | vipShopOrderList.add(vipShopOrder); |
| | | saveVipShopOrders(vipShopOrderList); |
| | | logger.info(String.format("唯品会订单更新:%s", param)); |
| | | try { |
| | | String[] ps = param.split(","); |
| | | for (String p : ps) { |
| | | List<VipShopOrder> orders = vipShopOrderService.listByOrderSn(p); |
| | | if (orders == null || orders.size() == 0) { |
| | | // 请求订单详情 |
| | | saveVipShopOrders(Arrays.asList(new VipShopOrder[]{DingDanXiaApiUtil.getOrderDetail(p)})); |
| | | } else { |
| | | Thread.sleep(1000); |
| | | VipShopOrder vipShopOrder = DingDanXiaApiUtil.getOrderDetail(p); |
| | | if (vipShopOrder != null) { |
| | | List<VipShopOrder> vipShopOrderList = new ArrayList<>(); |
| | | vipShopOrderList.add(vipShopOrder); |
| | | saveVipShopOrders(vipShopOrderList); |
| | | } |
| | | } |
| | | } |
| | | logger.info("唯品会订单更新成功"); |
| | | }catch(Exception e){ |
| | | logger.info(String.format("唯品会订单更新失败:%s", e.getMessage())); |
| | | } |
| | | return ReturnT.SUCCESS; |
| | | } |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Resource |
| | | private CommonOrderService commonOrderService; |
| | | |
| | | @XxlJob("order-vip-updateByLongTimeNoUpdate") |
| | | public ReturnT<String> updateByLongTimeNoUpdate(String param) throws Exception { |
| | | Date maxCreateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24L * 30); |
| | | Date minCreateTime = new Date(maxCreateTime.getTime() - 1000 * 60 * 60 * 24L * 60L); |
| | | VipShopOrderMapper.DaoQuery daoQuery = new VipShopOrderMapper.DaoQuery(); |
| | | daoQuery.orderSubStatusName = "已付款"; |
| | | daoQuery.minCreateTime = minCreateTime; |
| | | daoQuery.maxCreateTime = maxCreateTime; |
| | | long count = vipShopOrderMapper.count(daoQuery); |
| | | if (count > 0) { |
| | | daoQuery.start = 0; |
| | | daoQuery.count = (int) count; |
| | | List<VipShopOrder> orderList = vipShopOrderMapper.list(daoQuery); |
| | | for (VipShopOrder order : orderList) { |
| | | try { |
| | | updateByOrderSn(order.getOrderSn()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | List<CommonOrder> commonOrders = commonOrderService.listPayStateOrder(Constant.SOURCE_TYPE_VIP, new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24L * 60), new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24L * 10), 1, 200); |
| | | if (commonOrders == null || commonOrders.size() == 0) { |
| | | throw new Exception("没有需要更新的订单"); |
| | | } |
| | | Set<String> orderIds = new HashSet<>(); |
| | | for (CommonOrder commonOrder : commonOrders) { |
| | | orderIds.add(commonOrder.getOrderNo()); |
| | | } |
| | | for (String orderId : orderIds) { |
| | | updateByOrderSn(orderId); |
| | | } |
| | | |
| | | return ReturnT.SUCCESS; |
| | | } |
| | | |
| | |
| | | public void updateByOrderTime(long startTime, long endTime) { |
| | | List<VipShopOrder> vipShopOrderList = new ArrayList<>(); |
| | | int page = 1; |
| | | VipShopQueryOrderResultDTO result = VipShopApiUtil |
| | | VipShopQueryOrderResultDTO result = DingDanXiaApiUtil |
| | | .getOrderList(VipShopOrderQueryModel.createOrderTime(startTime, endTime, null, page)); |
| | | |
| | | while (result != null && result.getOrderList().size() > 0) { |
| | | page++; |
| | | vipShopOrderList.addAll(result.getOrderList()); |
| | | result = VipShopApiUtil |
| | | result = DingDanXiaApiUtil |
| | | .getOrderList(VipShopOrderQueryModel.createOrderTime(startTime, endTime, null, page)); |
| | | } |
| | | |
| | |
| | | public void updateByUpdateTime(long startTime, long endTime) { |
| | | List<VipShopOrder> vipShopOrderList = new ArrayList<>(); |
| | | int page = 1; |
| | | VipShopQueryOrderResultDTO result = VipShopApiUtil |
| | | VipShopQueryOrderResultDTO result = DingDanXiaApiUtil |
| | | .getOrderList(VipShopOrderQueryModel.createUpdateTime(startTime, endTime, null, page)); |
| | | |
| | | while (result != null && result.getOrderList().size() > 0) { |
| | | page++; |
| | | vipShopOrderList.addAll(result.getOrderList()); |
| | | result = VipShopApiUtil |
| | | result = DingDanXiaApiUtil |
| | | .getOrderList(VipShopOrderQueryModel.createUpdateTime(startTime, endTime, null, page)); |
| | | } |
| | | saveVipShopOrders(vipShopOrderList); |