| | |
| | | package com.yeshi.fanli.job;
|
| | |
|
| | | import java.util.Calendar;
|
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
| | | */
|
| | | private void updateRelationOrder(long startTime) {
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoRelationOrder(startTimeStr, Constant.TAOBAO_AUTH_APPKEY,
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoRelationOrder(startTimeStr, 1, Constant.TAOBAO_AUTH_APPKEY,
|
| | | Constant.TAOBAO_AUTH_APPSECRET);
|
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新渠道订单
|
| | | * |
| | | * @param fromPage
|
| | | * 开始页码
|
| | | * @param toPage
|
| | | * 结束页码(每页100条数据)
|
| | | */
|
| | | private void updateRelationOrder(int fromPage, int toPage) {
|
| | | // 最近90天的订单
|
| | | String startTimeStr = TimeUtil.getGernalTime(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 90L,
|
| | | "yyyy-MM-dd HH:mm:ss");
|
| | | for (int p = fromPage; p < toPage; p++) {
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoRelationOrder(startTimeStr, p,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | */
|
| | | private void updateSpecialOrder(long startTime) {
|
| | | String startTimeStr = TimeUtil.getGernalTime(startTime, "yyyy-MM-dd HH:mm:ss");
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoSpecialOrder(startTimeStr, Constant.TAOBAO_AUTH_APPKEY,
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoSpecialOrder(startTimeStr, 1, Constant.TAOBAO_AUTH_APPKEY,
|
| | | Constant.TAOBAO_AUTH_APPSECRET);
|
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新会员订单()
|
| | | * |
| | | * @param fromPage-开始页码
|
| | | * @param toPage-结束页码(每页20条数据)
|
| | | */
|
| | | private void updateSpecialOrder(int fromPage, int toPage) {
|
| | | String startTimeStr = TimeUtil.getGernalTime(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 90L,
|
| | | "yyyy-MM-dd HH:mm:ss");
|
| | | for (int p = fromPage; p < toPage; p++) {
|
| | | List<TaoBaoOrder> orderList = TaoKeApiUtil.getTaoBaoSpecialOrder(startTimeStr, p,
|
| | | Constant.TAOBAO_AUTH_APPKEY, Constant.TAOBAO_AUTH_APPSECRET);
|
| | | addRelationAndSpecialOrder(orderList);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public void doJob1() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long currentTime = System.currentTimeMillis();
|
| | | // 爬取21分钟之前到现在的
|
| | | updateRelationOrder(currentTime - 1000 * 60 * 20L);
|
| | | updateSpecialOrder(currentTime - 1000 * 60 * 20L);
|
| | | // 爬取最近3页数据
|
| | | updateRelationOrder(1, 3);
|
| | | updateSpecialOrder(1, 3);
|
| | | }
|
| | |
|
| | | // 每16分钟更新一次一天的(每天可更新近90天的数据)
|
| | | @Scheduled(cron = "0 0/16 * * * ? ")
|
| | | // 每5分钟更新(3-10页数据)
|
| | | @Scheduled(cron = "0 0/5 * * * ? ")
|
| | | public void doJob2() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long currentTime = System.currentTimeMillis();
|
| | | long dayStartTime = TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(currentTime, "yyyy-MM-dd"), "yyyy-MM-dd");
|
| | | int pos = (int) ((currentTime - dayStartTime) / 1000 * 60 * 16L);
|
| | |
|
| | | long time = dayStartTime - (pos + 1) * 1000 * 60 * 60 * 24L;
|
| | |
|
| | | // 只能更新最近90天的
|
| | | if (currentTime - time > 1000 * 60 * 60 * 24L * 90)
|
| | | return;
|
| | | updateRelationOrderByDay(TimeUtil.getGernalTime(time, "yyyy-MM-dd"));
|
| | | updateSpecialOrderByDay(TimeUtil.getGernalTime(time, "yyyy-MM-dd"));
|
| | | updateRelationOrder(3, 11);
|
| | | updateSpecialOrder(3, 11);
|
| | | }
|
| | |
|
| | | // 每个小时更新最近1天的数据
|
| | | // 每个小时更新10-1000页数据
|
| | | @Scheduled(cron = "0 0 0/1 * * ? ")
|
| | | public void doJob3() {
|
| | | if (!Constant.IS_TASK)
|
| | | return;
|
| | | long startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 24L;
|
| | | for (int i = 0; i < 71; i++) {
|
| | | updateRelationOrder(startTime + 1000 * 60 * 20L * i);
|
| | | updateSpecialOrder(startTime + 1000 * 60 * 20L * i);
|
| | | }
|
| | | Calendar calendar = Calendar.getInstance();
|
| | | int h = calendar.get(Calendar.HOUR_OF_DAY);
|
| | | // 每个小时更新100页数据
|
| | | int fromPage = h * 100;
|
| | | if (fromPage <= 0)
|
| | | fromPage = 11;
|
| | | int toPage = h * 100 + 100;
|
| | | updateRelationOrder(fromPage, toPage);
|
| | | updateSpecialOrder(fromPage, toPage);
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | /**
|
| | | * 获取会员订单
|
| | | *
|
| | | * @param startTime
|
| | | * @param startTime-开始时间
|
| | | * @param page-页码
|
| | | * @param appKey
|
| | | * @param appSecret
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoOrder> getTaoBaoSpecialOrder(String startTime, String appKey, String appSecret) {
|
| | | public static List<TaoBaoOrder> getTaoBaoSpecialOrder(String startTime, int page, String appKey, String appSecret) {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("method", "taobao.tbk.order.get");
|
| | | map.put("fields",
|
| | | "tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk_status,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,relation_id,tb_trade_parent_id,tb_trade_id,num_iid,item_title,item_num,price,pay_price,seller_nick,seller_shop_title,commission,commission_rate,unid,create_time,earning_time,tk3rd_pub_id,tk3rd_site_id,tk3rd_adzone_id,special_id,click_time,relation_id,special_id");
|
| | | map.put("start_time", startTime);
|
| | | map.put("span", "1200");
|
| | | map.put("tk_status", "1");
|
| | | map.put("order_query_type", "create_time");
|
| | | map.put("order_scene", "3");
|
| | | map.put("page_no", 1 + "");
|
| | | map.put("page_no", page + "");
|
| | | map.put("page_size", 100 + "");
|
| | |
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|
| | |
| | | app.setAppSecret(appSecret);
|
| | | try {
|
| | | JSONObject json = TaoKeBaseUtil.baseRequest(map, app);
|
| | | System.out.println(json.toString());
|
| | | return parseTaoBaoOrder(json.toString());
|
| | | } catch (TaoKeApiException e) {
|
| | | e.printStackTrace();
|
| | |
| | | * @param appSecret
|
| | | * @return
|
| | | */
|
| | | public static List<TaoBaoOrder> getTaoBaoRelationOrder(String startTime, String appKey, String appSecret) {
|
| | | public static List<TaoBaoOrder> getTaoBaoRelationOrder(String startTime,int page, String appKey, String appSecret) {
|
| | | Map<String, String> map = new HashMap<>();
|
| | | map.put("method", "taobao.tbk.order.get");
|
| | | map.put("fields",
|
| | |
| | | map.put("tk_status", "1");
|
| | | map.put("order_query_type", "create_time");
|
| | | map.put("order_scene", "2");
|
| | | map.put("page_no", 1 + "");
|
| | | map.put("page_no", page + "");
|
| | | map.put("page_size", 100 + "");
|
| | |
|
| | | TaoKeAppInfo app = new TaoKeAppInfo();
|