| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | import org.springframework.scheduling.annotation.Scheduled;
|
| | | import org.springframework.stereotype.Component;
|
| | |
|
| | | import com.yeshi.fanli.entity.bus.user.Order;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
| | | import com.yeshi.fanli.exception.TaoBaoOrderException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.common.DataMonitorService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
|
| | | import com.yeshi.fanli.service.inter.hongbao.ThreeSaleGiftService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderItemServcie;
|
| | | import com.yeshi.fanli.service.inter.order.LostOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderProcessService;
|
| | | import com.yeshi.fanli.service.inter.order.PidOrderService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoOrderService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoWeiQuanOrderService;
|
| | |
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBao110Util;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeOrderApiUtil;
|
| | |
|
| | | //从淘宝爬去订单更新
|
| | | @Component
|
| | |
| | | public UpdateOrderJob() {
|
| | | System.out.println("初始化:UpdateOrderJob");
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private OrderItemServcie orderItemServcie;
|
| | |
|
| | | @Resource
|
| | | private ThreeSaleGiftService threeSaleGiftService;
|
| | |
|
| | | @Resource
|
| | | private HongBaoService hongBaoService;
|
| | |
|
| | | @Resource
|
| | | private PidOrderService pidOrderService;
|
| | |
|
| | | @Resource
|
| | | private OrderProcessService orderProcessService;
|
| | |
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | private void updateOrder(long startTime, long endTime) {
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | @Resource
|
| | | private LostOrderService lostOrderService;
|
| | |
|
| | | @Resource
|
| | | private OrderService orderService;
|
| | |
|
| | | /**
|
| | | * 新版获取普通订单
|
| | | * |
| | | * @param startTime
|
| | | * @param span
|
| | | * @return
|
| | | */
|
| | | private static List<TaoBaoOrder> getCommonOrder(long startTime, int span) {
|
| | | int page = 1;
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeOrderApiUtil.getTaoBaoAllOrder(startTimeStr, span, page,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | while (orderList.size() == 100 * page) {
|
| | | page++;
|
| | | List<TaoBaoOrder> tempOrderList = TaoKeOrderApiUtil.getTaoBaoAllOrder(startTimeStr, span, page,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | if (tempOrderList != null && tempOrderList.size() > 0)
|
| | | orderList.addAll(tempOrderList);
|
| | | }
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取第三方普通订单
|
| | | * |
| | | * @param startTime
|
| | | * @param span
|
| | | * @return
|
| | | */
|
| | | private static List<TaoBaoOrder> getThirdCommonOrder(long startTime, int span) {
|
| | | int page = 1;
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeOrderApiUtil.getTaoBaoThirdAllOrder(startTimeStr, span, page,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | while (orderList.size() == 100 * page) {
|
| | | page++;
|
| | | List<TaoBaoOrder> tempOrderList = TaoKeOrderApiUtil.getTaoBaoThirdAllOrder(startTimeStr, span, page,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | if (tempOrderList != null && tempOrderList.size() > 0)
|
| | | orderList.addAll(tempOrderList);
|
| | | }
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取某个区间段的订单
|
| | | * |
| | | * @param startTime
|
| | | * @param endTime
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoOrder> getCommonOrder(long startTime, long endTime) {
|
| | | List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | try {
|
| | | orderList = TaoBaoOrderUtil.getOrderList(startTime, endTime, configList.get(0));
|
| | | } catch (TaoBaoOrderException e2) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e2);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | long span = (endTime - startTime) % 1000 == 0 ? (endTime - startTime) / 1000 : (endTime - startTime) / 1000 + 1;
|
| | | int count = (int) (span / 1200);
|
| | | if (span % 1200 != 0)
|
| | | count++;
|
| | | for (int i = 0; i < count; i++) {
|
| | | long startT = startTime + i * 1200 * 1000L;
|
| | | int s = 1200;
|
| | | if (endTime < startT + 1200 * 1000L) {
|
| | | s = (int) ((endTime - startT) / 1000) + 1;
|
| | | if (s < 60)
|
| | | s = 60;
|
| | | }
|
| | | List<TaoBaoOrder> tempOrderList = getCommonOrder(startT, s);
|
| | | if (tempOrderList != null && tempOrderList.size() > 0)
|
| | | orderList.addAll(tempOrderList);
|
| | | }
|
| | | List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
|
| | | try {
|
| | | thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(startTime, endTime, configList.get(0));
|
| | | } catch (TaoBaoOrderException e2) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e2);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 爬取三方订单
|
| | | * |
| | | * @param startTime
|
| | | * @param endTime
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoOrder> getThirdCommonOrder(long startTime, long endTime) {
|
| | | List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | long span = (endTime - startTime) % 1000 == 0 ? (endTime - startTime) / 1000 : (endTime - startTime) / 1000 + 1;
|
| | | int count = (int) (span / 1200);
|
| | | if (span % 1200 != 0)
|
| | | count++;
|
| | | for (int i = 0; i < count; i++) {
|
| | | long startT = startTime + i * 1200 * 1000L;
|
| | | int s = 1200;
|
| | | if (endTime < startT + 1200 * 1000L) {
|
| | | s = (int) ((endTime - startT) / 1000) + 1;
|
| | | if (s < 60)
|
| | | s = 60;
|
| | | }
|
| | | List<TaoBaoOrder> tempOrderList = getThirdCommonOrder(startT, s);
|
| | | if (tempOrderList != null && tempOrderList.size() > 0)
|
| | | orderList.addAll(tempOrderList);
|
| | | }
|
| | | if (thirdOrderList != null && thirdOrderList.size() > 0)
|
| | | orderList.addAll(thirdOrderList);
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 按天获取普通订单(新版)
|
| | | * |
| | | * @param date
|
| | | * @return
|
| | | */
|
| | | public List<TaoBaoOrder> getCommonOrderByDay(Date date) {
|
| | | List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | // 将一天分成12段
|
| | | for (int i = 0; i < 72; i++) {
|
| | | List<TaoBaoOrder> tempOrderList = getCommonOrder(date.getTime() + 1000 * 60 * 20L * i, 1200);
|
| | | if (tempOrderList != null && tempOrderList.size() > 0)
|
| | | orderList.addAll(tempOrderList);
|
| | | }
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | public void updateOrder(long startTime, long endTime) {
|
| | | // 老版本处理方式
|
| | | // List<TaoBaoUnionConfig> configList =
|
| | | // taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | // List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | | // try {
|
| | | // orderList = TaoBaoOrderUtil.getOrderList(startTime, endTime,
|
| | | // configList.get(0));
|
| | | // } catch (TaoBaoOrderException e2) {
|
| | | // try {
|
| | | // LogHelper.errorDetailInfo(e2);
|
| | | // } catch (Exception e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // }
|
| | | // List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
|
| | | // try {
|
| | | // thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(startTime,
|
| | | // endTime, configList.get(0));
|
| | | // } catch (TaoBaoOrderException e2) {
|
| | | // try {
|
| | | // LogHelper.errorDetailInfo(e2);
|
| | | // } catch (Exception e) {
|
| | | // e.printStackTrace();
|
| | | // }
|
| | | // }
|
| | | // if (thirdOrderList != null && thirdOrderList.size() > 0)
|
| | | // orderList.addAll(thirdOrderList);
|
| | | // 新版本处理方式
|
| | | List<TaoBaoOrder> orderList = getCommonOrder(startTime, endTime);
|
| | | List<TaoBaoOrder> tempOrderList2 = getThirdCommonOrder(startTime, endTime);
|
| | | if (tempOrderList2 != null && tempOrderList2.size() > 0)
|
| | | orderList.addAll(tempOrderList2);
|
| | |
|
| | | LogHelper.orderInfo("正在执行订单爬取结束,共有订单:" + orderList.size());
|
| | | addOrder(orderList);
|
| | |
| | | } catch (InterruptedException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | public static List<TaoBaoOrder> mixTaoBaoOrder(List<TaoBaoOrder> commonOrderList, List<TaoBaoOrder> sorderList) {
|
| | | Map<String, List<TaoBaoOrder>> commonMap = TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(commonOrderList);
|
| | | Map<String, List<TaoBaoOrder>> sMap = TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(sorderList);
|
| | | // 获取订单交集
|
| | | Iterator<String> its = commonMap.keySet().iterator();
|
| | | List<String> commonOrderIdList = new ArrayList<>();
|
| | | List<String> sOrderIdList = new ArrayList<>();
|
| | | while (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | | commonOrderIdList.add(orderId);
|
| | | }
|
| | | its = sMap.keySet().iterator();
|
| | | while (its.hasNext()) {
|
| | | String orderId = its.next();
|
| | | sOrderIdList.add(orderId);
|
| | | }
|
| | |
|
| | | // 求交集
|
| | | commonOrderIdList.retainAll(sOrderIdList);
|
| | |
|
| | | List<TaoBaoOrder> orderList = new ArrayList<>();
|
| | |
|
| | | for (String orderId : commonOrderIdList) {
|
| | | List<TaoBaoOrder> list = commonMap.get(orderId);
|
| | | String specialId = sMap.get(orderId).get(0).getSpecialId();
|
| | | String relationId = sMap.get(orderId).get(0).getRelationId();
|
| | | for (TaoBaoOrder to : list) {
|
| | | to.setSpecialId(specialId);
|
| | | to.setRelationId(relationId);
|
| | | orderList.add(to);
|
| | | }
|
| | | }
|
| | |
|
| | | return orderList;
|
| | | }
|
| | |
|
| | | private void addOrder(List<TaoBaoOrder> orderList) {
|
| | |
|
| | | if (orderList != null)
|
| | | for (int i = 0; i < orderList.size(); i++) {
|
| | | // 移除会员运营ID与渠道专属订单
|
| | | if (orderList.get(i).getAdPositionName().contains("会员运营")
|
| | | || orderList.get(i).getAdPositionName().contains("渠道专属")) {
|
| | | if (orderList.get(i).getAdPositionName().contains("会员运营")) {// 处理订单申诉
|
| | | Order order = orderService.findOrderByOrderIdAndType(orderList.get(i).getOrderId(),
|
| | | Order.ORDER_TYPE_TAOBAO);
|
| | | if (order != null && order.getBeizhu().contains("补单")) {// 不排除补单的情况
|
| | |
|
| | | } else {
|
| | | orderList.remove(i);
|
| | | i--;
|
| | | break;
|
| | | }
|
| | | } else {
|
| | | orderList.remove(i);
|
| | | i--;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | try {
|
| | | taoBaoOrderService.addTaoBaoOrderList(orderList);
|
| | | } catch (Exception e) {
|
| | |
| | | public void doJob1() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long currentTime = System.currentTimeMillis();
|
| | | long currentTime = System.currentTimeMillis() - 1000 * 60;
|
| | | String h = TimeUtil.getGernalTime(currentTime, "HH");
|
| | | String m = TimeUtil.getGernalTime(currentTime, "mm");
|
| | | int mm = Integer.parseInt(h) * 60 + Integer.parseInt(m);
|
| | |
| | | }
|
| | |
|
| | | // 淘宝推广订单 每隔3分13秒执行一次
|
| | | @Scheduled(cron = "13 0/3 0 24,25 * ? ")
|
| | | @Scheduled(cron = "13 0/3 * * * ? ")
|
| | | public void doJob6() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | | LogHelper.orderInfo("正在执行订单爬取...");
|
| | | // 爬取1分钟以前的
|
| | | long endTime = System.currentTimeMillis() - 1000 * 60 * 1L;
|
| | | List<TaoBaoOrder> orderList = new ArrayList<TaoBaoOrder>();
|
| | | try {
|
| | | orderList = TaoBaoOrderUtil.getOrderList(endTime - 1000 * 60 * 60 * 24 * 2L, endTime, configList.get(0));
|
| | | TaoBao110Util.rightTaoBaoOrderWarning();
|
| | | } catch (TaoBaoOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | TaoBao110Util.reportTaoBaoOrderWarning(e.getCode(), e.getMessage());
|
| | | } catch (Exception e2) {
|
| | | e2.printStackTrace();
|
| | | }
|
| | | }
|
| | | List<TaoBaoOrder> thirdOrderList = new ArrayList<>();
|
| | | try {
|
| | | thirdOrderList = TaoBaoOrderUtil.getThirdServiceOrderList(endTime - 1000 * 60 * 60 * 24 * 2L, endTime,
|
| | | configList.get(0));
|
| | | } catch (TaoBaoOrderException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | } catch (Exception e2) {
|
| | | e2.printStackTrace();
|
| | | }
|
| | | }
|
| | | if (thirdOrderList != null && thirdOrderList.size() > 0)
|
| | | orderList.addAll(thirdOrderList);
|
| | | if (orderList != null && orderList.size() > 0)
|
| | | dataMonitorService.parseTaoBaoOrderSuccess();
|
| | | LogHelper.orderInfo("正在执行订单爬取结束,共有订单:" + orderList.size());
|
| | | addOrder(orderList);
|
| | | long endTime = System.currentTimeMillis() - 1000 * 60;
|
| | | ;
|
| | | updateOrder(endTime - 1000 * 60 * 20L, endTime);
|
| | | }
|
| | |
|
| | | // 返利
|
| | |
| | | public void doJob2() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | doJob4();
|
| | | doTaoBaoWeiQuan();
|
| | |
|
| | | orderProcessService.fanli();
|
| | | }
|
| | |
| | | // 维权订单处理-处理最近60天的
|
| | | // 30分钟一次
|
| | | @Scheduled(cron = "0 0/30 * * * ? ")
|
| | | public void doJob4() {
|
| | | public void doTaoBaoWeiQuan() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
| | | orderProcessService.weiQuanOrder(orderList);
|
| | | }
|
| | |
|
| | | // 处理分享商品所产生的订单
|
| | | @Scheduled(cron = "0 0/2 * * * ? ")
|
| | | public void doJob7() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | pidOrderService.doPidOrder();
|
| | | // 处理分享商品所产生的订单(后续版本废除)
|
| | | // @Scheduled(cron = "0 0/2 * * * ? ")
|
| | | // public void doPidOrder() {
|
| | | // if (!Constant.IS_TASK)
|
| | | // return;
|
| | | // pidOrderService.doPidOrder();
|
| | | // }
|
| | |
|
| | | // 每6个小时执行一次
|
| | | @Scheduled(cron = "0 0 0/6 * * ? ")
|
| | | public void doLostOrder() {
|
| | | lostOrderService.processFail();
|
| | | }
|
| | |
|
| | | }
|