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

- 商品导入测试

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