| | |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.mq.cmq.order.OrdersCMQManager; |
| | | 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; |
| | |
| | | //从淘宝爬去订单更新 |
| | | @Component |
| | | public class UpdateVipShopOrderJob { |
| | | |
| | | private Logger logger = LoggerFactory.getLogger("debugLog"); |
| | | |
| | | @Resource |
| | | private VipShopOrderService vipShopOrderService; |
| | |
| | | @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天更新的数据 |
| | | 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 ); |
| | | 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 ("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 { |
| | | 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(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; |
| | | } |