提交 df6cab28 authored 作者: 梁业锦's avatar 梁业锦 💬

- 商品导入测试

上级 43275007
......@@ -80,7 +80,6 @@ public class TestApi {
Console.log("链接:" + link);
}
/**
* 测试分类的商品数量
*/
......@@ -110,15 +109,6 @@ public class TestApi {
System.err.println(headerLink);
}
/**
* 导入商品
*/
@Test
public void test() {
}
/**
* 连接测试
*/
......@@ -142,18 +132,35 @@ public class TestApi {
}
/**
* 第一遍循环导入
* 导入商品
*/
private String once(String link) {
// 记录页数的
int pageSize = 0;
int productCount = 0;
@Test
public void test() {
String link = "";
// 这个请求需要密钥,可以先拿着账号密码去浏览器请求一遍,F12 获取 token 复制粘贴即可
String result = HttpRequest.get(link)
.header("Authorization", "Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA=")
.execute().body();
JSONObject jsonObject = JSONObject.fromObject(result);
// 第一次导入
once(result);
// 解析请求头,获取到下一页的 url
String headerLink = HttpRequest.get(link)
.header("Authorization", "Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA=")
.execute().header("link");
headerLink = headerLink.split(";")[0].replaceAll("<", "").replaceAll(">", "");
// 无限导入
unlimited(headerLink);
}
/**
* 第一遍循环导入
*/
private void once(String data) {
// 记录页数的
int productCount = 0;
// json 化返回数据
JSONObject jsonObject = JSONObject.fromObject(data);
// 取每个数组中的 products 数组节点
JSONArray productsArr = jsonObject.getJSONArray("products");
......@@ -172,8 +179,8 @@ public class TestApi {
try {
// 查询该商品的 id 是否已保存
if (tbCfStationItemDao.queryByCode(id) != null) {
// 记录失败的产品记录
throw new ProductExitException();
// 继续循环
continue;
}
// 用于记录 option 的属性名
int optionNum = 0;
......@@ -386,7 +393,7 @@ public class TestApi {
tbProductMissEntity.setId(IdUtil.simpleUUID());
tbProductMissEntity.setProductId(id);
tbProductMissEntity.setMissType(1);
tbProductMissEntity.setPageSize(pageSize);
tbProductMissEntity.setPageSize(1);
tbProductMissEntity.setCreateTime(new Date());
tbProductMissDao.save(tbProductMissEntity);
} catch (Exception e) {
......@@ -396,17 +403,11 @@ public class TestApi {
tbProductMissEntity.setId(IdUtil.simpleUUID());
tbProductMissEntity.setProductId(id);
tbProductMissEntity.setMissType(2);
tbProductMissEntity.setPageSize(pageSize);
tbProductMissEntity.setPageSize(1);
tbProductMissEntity.setCreateTime(new Date());
tbProductMissDao.save(tbProductMissEntity);
}
}
String headerLink = HttpRequest.get(link)
.header("Authorization", "Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA=")
.execute().header("link");
headerLink = headerLink.split(";")[0].replaceAll("<", "").replaceAll(">", "");
return headerLink;
}
/**
......@@ -415,7 +416,7 @@ public class TestApi {
private void unlimited(String link) {
// 记录页数的
int pageSize = 0;
int productCount = 0;
int productCount = 1;
// 循环翻页
while (true) {
Console.error("当前的页数为:" + pageSize);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论