提交 e693395d authored 作者: zgy's avatar zgy

更新定时任务时间

上级 ea9817b1
...@@ -31,7 +31,7 @@ public class ExpressStatusTask { ...@@ -31,7 +31,7 @@ public class ExpressStatusTask {
@Autowired @Autowired
private TbCfOrderService tbCfOrderService; private TbCfOrderService tbCfOrderService;
@Scheduled(cron = "0 15 0/2 * * ? ") @Scheduled(cron = "0 0/10 * * * ? ")
public void expressStatusTaskForStorageC() { public void expressStatusTaskForStorageC() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startime = sdf.format(getStartTime()); String startime = sdf.format(getStartTime());
...@@ -63,7 +63,7 @@ public class ExpressStatusTask { ...@@ -63,7 +63,7 @@ public class ExpressStatusTask {
System.out.println("入珠海仓库查询时间:"+s1); System.out.println("入珠海仓库查询时间:"+s1);
System.out.println("消耗时间:"+(endTime-startTime)+"ms"); System.out.println("消耗时间:"+(endTime-startTime)+"ms");
} }
@Scheduled(cron = "0 35 0/2 * * ? ") @Scheduled(cron = "0 0/10 * * * ? ")
public void expressStatusTaskForStorageA() { public void expressStatusTaskForStorageA() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startime = sdf.format(getStartTime()); String startime = sdf.format(getStartTime());
...@@ -95,7 +95,7 @@ public class ExpressStatusTask { ...@@ -95,7 +95,7 @@ public class ExpressStatusTask {
System.out.println("入非洲仓库查询时间:"+s1); System.out.println("入非洲仓库查询时间:"+s1);
System.out.println("消耗时间:"+(endTime-startTime)+"ms"); System.out.println("消耗时间:"+(endTime-startTime)+"ms");
} }
@Scheduled(cron = "0 55 0/2 * * ? ") @Scheduled(cron = "0 0/10 * * * ? ")
public void expressStatusTaskForDelivery() { public void expressStatusTaskForDelivery() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startime = sdf.format(getStartTime()); String startime = sdf.format(getStartTime());
......
package com.platform.task; package com.platform.task;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.mashape.unirest.http.Unirest;
import com.platform.dao.TbCfStationItemDao;
import com.platform.entity.TbCfStationItemEntity; import com.platform.entity.TbCfStationItemEntity;
import com.platform.service.TbCfStationItemService;
import com.platform.utils.IdUtil;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import org.apache.http.*; import org.apache.http.*;
...@@ -16,14 +20,14 @@ import org.apache.http.message.BasicHeader; ...@@ -16,14 +20,14 @@ import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Auther: wudepeng * @Auther: wudepeng
...@@ -33,42 +37,60 @@ import java.util.Map; ...@@ -33,42 +37,60 @@ import java.util.Map;
@Component("itemTask") @Component("itemTask")
public class ItemTask { public class ItemTask {
@Autowired
private TbCfStationItemDao tbCfStationItemDao;
/** /**
* 定时查询 * 定时查询
* *
* @throws IOException * @throws IOException
*/ */
//@Scheduled(cron = "0 0 21 * * ? ") // @Scheduled(cron = "0 0 21 * * ? ")
@Test // @Scheduled(cron = "0 0 0/1 * * ? ")
public void queryItemFromShopify() throws IOException { public void queryItemFromShopify() throws IOException {
Map<String, Object> params = new HashMap<>(); Map<String, Object> params = new HashMap<>();
List type = getProductType(); List type = getProductType();
for (int i = 0; i < type.size(); i++) { for (int i = 0; i < type.size(); i++) {
params.put("product_type", type.get(i)); params.put("product_type", type.get(i));
params.put("limit", "4"); params.put("limit", "250");
String data = createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8"); String data = createConnection(ShopifyConstant.productTypeUrl(), params, "UTF-8");
System.out.println(data); System.out.println(data);
JSONObject jsonObject = JSONObject.fromObject(data); JSONObject jsonObject = JSONObject.fromObject(data);
JSONArray products = jsonObject.getJSONArray("products"); JSONArray products = jsonObject.getJSONArray("products");
for (int j = 0; j < products.size(); j++) { for (int j = 0; j < products.size(); j++) {
TbCfStationItemEntity item = new TbCfStationItemEntity();
JSONObject object = products.getJSONObject(j); JSONObject object = products.getJSONObject(j);
String id = object.getString("id"); String id = object.getString("id");
String title = object.getString("title"); String title = object.getString("title");
String product_type = object.getString("product_type"); String product_type = object.getString("product_type");
JSONArray variants = object.getJSONArray("variants"); JSONArray variants = object.getJSONArray("variants");
String image = object.getJSONObject("image").getString("src"); String image = object.getJSONObject("image").getString("src");
for (int m=0;m<variants.size();m++){ List<Double> priceList = new ArrayList<>();
for (int m = 0; m < variants.size(); m++) {
JSONObject obj = variants.getJSONObject(m); JSONObject obj = variants.getJSONObject(m);
String price = obj.getString("price"); String productPrice = obj.getString("price");
// System.out.println(id); priceList.add(Double.valueOf(productPrice));
// System.out.println(title);
// System.out.println(product_type);
// System.out.println(image);
// System.out.println(price);
// System.out.println("============================");
} }
Collections.sort(priceList);
System.out.println(id);
System.out.println(title);
System.out.println(product_type);
System.out.println(image);
System.out.println(priceList);
System.out.println("===================");
System.out.println(new BigDecimal(priceList.get(0)).setScale(2, BigDecimal.ROUND_DOWN));
TbCfStationItemEntity product = new TbCfStationItemEntity();
product.setItemId(IdUtil.createIdbyUUID());
product.setItemCode(id);
product.setItemName(title);
product.setItemBrief(title);
product.setItemPrice(new BigDecimal(priceList.get(0)).setScale(2, BigDecimal.ROUND_DOWN));
product.setItemImg(image);
product.setItemNum(0L);
product.setPlatformCode("afri-eshop");
product.setPlatformName("afri-eshop");
product.setEnableFlag(1);
product.setCreateTime(new Date());
tbCfStationItemDao.save(product);
} }
} }
...@@ -155,4 +177,40 @@ public class ItemTask { ...@@ -155,4 +177,40 @@ public class ItemTask {
} }
return list; return list;
} }
/**
* 获取shopify接口 headers里的参数【Link】
*
* @param url
* @return
* @throws Exception
*/
public static List<String> getHeaders(String url) throws Exception {
List<String> list = new ArrayList();
com.mashape.unirest.http.HttpResponse<String> response = Unirest.get(url)
.headers(new HashMap<>())
.asString();
List<String> link = response.getHeaders().get("Link");
String linkString = link.toString();
boolean next = linkString.contains("next");
boolean previous = linkString.contains("previous");
String str = link.get(0);
String[] split = str.split(",");
for (int i = 0; i < split.length; i++) {
String s = split[i];
String sub = s.substring(s.indexOf("page_info="), s.lastIndexOf(">;"));
String substring = sub.substring(10);
list.add(substring);
}
if (next) {
list.add("first");
if (previous) {
list.add("middle");
}
} else {
list.add("last");
}
return list;
}
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
# xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.ClusterPolicy # xx.xxxx.xxxx.Xxxxx your own cache broadcast policy classname that implement net.oschina.j2cache.ClusterPolicy
######################################### #########################################
j2cache.broadcast=redis j2cache.broadcast=redis
#组播的通道名称 #�鲥��ͨ������
jgroups.channel.name=j2cache jgroups.channel.name=j2cache
jgroups.configXml=/network.xml jgroups.configXml=/network.xml
######################################### #########################################
...@@ -57,8 +57,8 @@ caffeine.properties=/caffeine.properties ...@@ -57,8 +57,8 @@ caffeine.properties=/caffeine.properties
# #
# single -> single redis server # single -> single redis server
# sentinel -> master-slaves servers # sentinel -> master-slaves servers
# cluster -> cluster servers (数据库配置无效,使用 database = 0) # cluster -> cluster servers (���ݿ�������Ч��ʹ�� database = 0��
# sharded -> sharded servers (密码、数据库必须在 hosts 中指定,且连接池配置无效 ; redis://user:password@127.0.0.1:6379/0) # sharded -> sharded servers (���롢���ݿ������ hosts ��ָ���������ӳ�������Ч ; redis://user:password@127.0.0.1:6379/0��
# #
######################################### #########################################
redis.mode=single redis.mode=single
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论