Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
C
chinafrica
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
chinafrica
Commits
9e3badc9
提交
9e3badc9
authored
3月 18, 2020
作者:
梁业锦
💬
提交者:
Messenger902
3月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 多线程形式改善代码
上级
9481b5d9
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
290 行增加
和
224 行删除
+290
-224
TbCfStationItemDao.xml
...rc/main/resources/com/platform/dao/TbCfStationItemDao.xml
+1
-1
ImpartCode.java
platform-admin/src/main/test/java/test/ImpartCode.java
+245
-219
ImportTask.java
platform-admin/src/main/test/java/test/ImportTask.java
+16
-0
TestApi.java
platform-admin/src/main/test/java/test/TestApi.java
+20
-4
Test.sql
platform-admin/src/main/test/sql/Test.sql
+8
-0
没有找到文件。
platform-admin/src/main/resources/com/platform/dao/TbCfStationItemDao.xml
浏览文件 @
9e3badc9
...
@@ -229,7 +229,7 @@
...
@@ -229,7 +229,7 @@
#{itemUrl},
#{itemUrl},
#{itemImg},
#{itemImg},
#{itemTags},
#{itemTags},
#{itemLabel}
,
#{itemLabel}
,
#{itemNum},
#{itemNum},
#{itemCount},
#{itemCount},
#{itemSku},
#{itemSku},
...
...
platform-admin/src/main/test/java/test/ImpartCode.java
浏览文件 @
9e3badc9
...
@@ -23,6 +23,10 @@ import java.net.URL;
...
@@ -23,6 +23,10 @@ import java.net.URL;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ThreadPoolExecutor
;
/**
/**
* 商品导入功能
* 商品导入功能
...
@@ -63,26 +67,33 @@ public class ImpartCode {
...
@@ -63,26 +67,33 @@ public class ImpartCode {
* 接口路径
* 接口路径
*/
*/
private
final
String
API_URL
=
"https://mollykitty.myshopify.com/admin/api/"
+
VERSION
+
"/products.json"
;
private
final
String
API_URL
=
"https://mollykitty.myshopify.com/admin/api/"
+
VERSION
+
"/products.json"
;
/**
* 任务用线程池
*/
ExecutorService
executorService
=
Executors
.
newCachedThreadPool
();
/**
/**
* 根据分类进行导入
* 根据分类进行导入
*/
*/
@Test
@Test
public
void
goImport
()
{
public
void
goImport
()
{
List
<
String
>
list
=
Arrays
.
asList
(
"Men"
,
"Women"
,
"Children"
,
"Afri Home"
,
"Cosmetics"
,
"Hair"
,
"Sportswear"
,
"Electronics"
);
List
<
String
>
list
=
Arrays
.
asList
(
"Men"
,
"Women"
,
"Children"
,
"Afri Home"
,
"Cosmetics"
,
"Hair"
,
"Sportswear"
,
"Electronics"
);
// 创建线程池
for
(
String
product_type
:
list
)
{
for
(
String
product_type
:
list
)
{
// 记录商品数量
// 记录商品数量
int
productCount
=
0
;
int
productCount
=
0
;
// 记录页数
// 记录页数
int
pageSize
=
1
;
int
pageSize
=
1
;
// 测试数量
// 测试数量
String
link
=
"https://mollykitty.myshopify.com/admin/api/"
+
VERSION
+
"/products/count.json"
+
"?
&
product_type="
+
product_type
;
String
link
=
"https://mollykitty.myshopify.com/admin/api/"
+
VERSION
+
"/products/count.json"
+
"?product_type="
+
product_type
;
String
data
=
HttpRequest
.
get
(
link
)
String
data
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
.
execute
().
body
();
System
.
err
.
println
(
product_type
+
":"
+
data
);
System
.
err
.
println
(
product_type
+
":"
+
data
);
// 导入请求
// 导入请求
link
=
API_URL
+
"?&product_type="
+
product_type
;
link
=
"https://mollykitty.myshopify.com/admin/api/"
+
VERSION
+
"/products.json"
+
"?product_type="
+
product_type
+
"&limit=250"
;
// 开始第一次导入商品
// 开始第一次导入商品
importMethod
(
link
,
pageSize
,
productCount
);
importMethod
(
link
,
pageSize
,
productCount
);
// 获取第一次循环的请求头
// 获取第一次循环的请求头
...
@@ -109,7 +120,6 @@ public class ImpartCode {
...
@@ -109,7 +120,6 @@ public class ImpartCode {
// 死循环的终点为获取下一页链接抛出数组越界异常
// 死循环的终点为获取下一页链接抛出数组越界异常
break
;
break
;
}
}
}
}
}
}
...
@@ -118,11 +128,15 @@ public class ImpartCode {
...
@@ -118,11 +128,15 @@ public class ImpartCode {
/**
/**
* 商品导入处理
* 商品导入处理
*
*
* @param
data 接口返回数据
* @param
link 请求链接
* @param pageSize 正在导入的页数
* @param pageSize 正在导入的页数
* @param productCount 正在导入的商品数量
* @param productCount 正在导入的商品数量
*/
*/
private
void
importMethod
(
String
data
,
int
pageSize
,
int
productCount
)
{
private
void
importMethod
(
String
link
,
int
pageSize
,
int
productCount
)
{
// 请求
String
data
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
// 格式化
// 格式化
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
// 取每个数组中的 products 数组节点
// 取每个数组中的 products 数组节点
...
@@ -141,227 +155,239 @@ public class ImpartCode {
...
@@ -141,227 +155,239 @@ public class ImpartCode {
Date
date
=
new
Date
();
Date
date
=
new
Date
();
// 商品的平台 id
// 商品的平台 id
String
id
=
productsObj
.
getString
(
"id"
);
String
id
=
productsObj
.
getString
(
"id"
);
try
{
// 查询该商品的 id 是否已保存
// 查询该商品的 id 是否已保存
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
// 跳过循环
// 继续循环
continue
;
continue
;
}
}
// 线程任务
// 用于记录 option 的属性名
Runnable
runnable
=
()
->
{
int
optionNum
=
0
;
try
{
// 下方商品主体信息需要的商品属性,以"/"隔开
// 用于记录 option 的属性名
StringBuilder
optionBuilder
=
new
StringBuilder
();
int
optionNum
=
0
;
// 下方商品主体信息需要的商品属性,以"/"隔开
// 商品的属性
StringBuilder
optionBuilder
=
new
StringBuilder
();
JSONArray
optionsArr
=
productsObj
.
getJSONArray
(
"options"
);
for
(
int
j
=
0
;
j
<
optionsArr
.
size
();
j
++)
{
// 商品的属性
JSONObject
optionObj
=
optionsArr
.
getJSONObject
(
j
);
JSONArray
optionsArr
=
productsObj
.
getJSONArray
(
"options"
);
for
(
int
j
=
0
;
j
<
optionsArr
.
size
();
j
++)
{
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
JSONObject
optionObj
=
optionsArr
.
getJSONObject
(
j
);
String
optionId
=
optionObj
.
getString
(
"id"
);
categoryEntity
.
setCategoryId
(
optionId
);
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
categoryEntity
.
setCreateTime
(
date
);
String
optionId
=
optionObj
.
getString
(
"id"
);
categoryEntity
.
setUpdateTime
(
date
);
categoryEntity
.
setCategoryId
(
optionId
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setCreateTime
(
date
);
categoryEntity
.
setItemId
(
itemId
);
categoryEntity
.
setUpdateTime
(
date
);
String
optionName
=
optionObj
.
getString
(
"name"
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setCategoryName
(
optionName
);
categoryEntity
.
setItemId
(
itemId
);
optionBuilder
.
append
(
optionName
);
String
optionName
=
optionObj
.
getString
(
"name"
);
if
(
j
!=
optionsArr
.
size
()
-
1
)
{
categoryEntity
.
setCategoryName
(
optionName
);
optionBuilder
.
append
(
"/"
);
optionBuilder
.
append
(
optionName
);
if
(
j
!=
optionsArr
.
size
()
-
1
)
{
optionBuilder
.
append
(
"/"
);
}
optionNum
++;
categoryEntity
.
setOrderNum
(
optionNum
);
categoryEntity
.
setOption
(
"option"
+
optionNum
);
// 保存属性名
String
categoryId
=
IdUtil
.
simpleUUID
();
if
(
tbCategoryTemplateDao
.
queryByDesc
(
optionName
)
==
null
)
{
TbCategoryTemplateEntity
tbCategoryTemplateEntity
=
new
TbCategoryTemplateEntity
();
tbCategoryTemplateEntity
.
setId
(
categoryId
);
tbCategoryTemplateEntity
.
setCategoryDesc
(
optionName
);
tbCategoryTemplateEntity
.
setDelFlag
(
1
);
tbCategoryTemplateEntity
.
setCategoryName
(
optionName
);
tbCategoryTemplateEntity
.
setUpdateTime
(
date
);
tbCategoryTemplateEntity
.
setUpdateTime
(
date
);
tbCategoryTemplateDao
.
save
(
tbCategoryTemplateEntity
);
}
StringBuilder
categoryBuilder
=
new
StringBuilder
();
JSONArray
valuesArr
=
optionObj
.
getJSONArray
(
"values"
);
for
(
int
k
=
0
;
k
<
valuesArr
.
size
();
k
++)
{
// 商品属性
TbCfOptionEntity
optionEntity
=
new
TbCfOptionEntity
();
optionEntity
.
setOptionId
(
IdUtil
.
simpleUUID
());
optionEntity
.
setCid
(
optionId
);
optionEntity
.
setItemId
(
itemId
);
String
optionSpecies
=
valuesArr
.
getString
(
k
);
optionEntity
.
setOptiionSpecies
(
optionSpecies
);
categoryBuilder
.
append
(
optionSpecies
);
if
(
k
!=
valuesArr
.
size
()
-
1
)
{
categoryBuilder
.
append
(
","
);
}
optionEntity
.
setCreateTime
(
date
);
optionEntity
.
setUpdateTime
(
date
);
optionEntity
.
setDelFlag
(
1
);
optionEntity
.
setOptionName
(
optionName
);
tbCfOptionDao
.
save
(
optionEntity
);
}
categoryEntity
.
setCategoryDesc
(
categoryBuilder
.
toString
());
tbCfCategoryDao
.
save
(
categoryEntity
);
}
}
optionNum
++;
categoryEntity
.
setOrderNum
(
optionNum
);
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
categoryEntity
.
setOption
(
"option"
+
optionNum
);
// 保存属性名
// 保存商品的变体数据
String
categoryId
=
IdUtil
.
simpleUUID
();
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
if
(
tbCategoryTemplateDao
.
queryByDesc
(
optionName
)
==
null
)
{
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
TbCategoryTemplateEntity
tbCategoryTemplateEntity
=
new
TbCategoryTemplateEntity
();
JSONObject
variantsObj
=
variantsArr
.
getJSONObject
(
j
);
tbCategoryTemplateEntity
.
setId
(
categoryId
);
tbCategoryTemplateEntity
.
setCategoryDesc
(
optionName
);
Integer
quantity
=
variantsObj
.
getInt
(
"inventory_quantity"
);
// 库存信息
tbCategoryTemplateEntity
.
setDelFlag
(
1
);
BigDecimal
price
=
new
BigDecimal
(
variantsObj
.
getString
(
"price"
));
// 价格
tbCategoryTemplateEntity
.
setCategoryName
(
optionName
);
tbCategoryTemplateEntity
.
setUpdateTime
(
date
);
TbCfItemSkusEntity
skusEntity
=
new
TbCfItemSkusEntity
();
tbCategoryTemplateEntity
.
setUpdateTime
(
date
);
skusEntity
.
setId
(
variantsObj
.
getString
(
"id"
));
tbCategoryTemplateDao
.
save
(
tbCategoryTemplateEntity
);
skusEntity
.
setItemId
(
itemId
);
skusEntity
.
setDelFlag
(
1
);
skusEntity
.
setCreateTime
(
date
);
skusEntity
.
setUpdateTime
(
date
);
skusEntity
.
setSkuDesc
(
variantsObj
.
getString
(
"title"
));
System
.
out
.
println
(
optionBuilder
.
toString
());
skusEntity
.
setSkuName
(
optionBuilder
.
toString
());
skusEntity
.
setSkuPrice
(
price
);
skusEntity
.
setSkuCount
(
quantity
);
skusEntity
.
setOrderNum
(
variantsObj
.
getInt
(
"position"
));
tbCfItemSkusDao
.
save
(
skusEntity
);
tbCfStationItem
.
setItemCount
(
quantity
.
longValue
());
// 商品的原价
String
compare_at_price
=
variantsObj
.
getString
(
"compare_at_price"
);
if
(!
"null"
.
equals
(
compare_at_price
))
{
tbCfStationItem
.
setItemPrice
(
new
BigDecimal
(
compare_at_price
));
}
else
{
tbCfStationItem
.
setItemPrice
(
null
);
}
// 商品的折扣价
tbCfStationItem
.
setDiscountPrice
(
price
);
}
}
StringBuilder
categoryBuilder
=
new
StringBuilder
();
String
title
=
productsObj
.
getString
(
"title"
);
// 商品的名称
JSONArray
valuesArr
=
optionObj
.
getJSONArray
(
"values"
);
String
product_type
=
productsObj
.
getString
(
"product_type"
);
// 商品的分类
for
(
int
k
=
0
;
k
<
valuesArr
.
size
();
k
++)
{
// 商品属性
// 保存一级分类名
TbCfOptionEntity
optionEntity
=
new
TbCfOptionEntity
();
String
goods_type_id
=
IdUtil
.
simpleUUID
();
// 商品分类id
optionEntity
.
setOptionId
(
IdUtil
.
simpleUUID
());
if
(
tbCfGoodstypeDao
.
queryByTitle
(
product_type
)
==
null
)
{
// 如果分类名已存在则不保存
optionEntity
.
setCid
(
optionId
);
TbCfGoodstypeEntity
tbCfGoodstypeEntity
=
new
TbCfGoodstypeEntity
();
optionEntity
.
setItemId
(
itemId
);
tbCfGoodstypeEntity
.
setGoodstypeId
(
goods_type_id
);
String
optionSpecies
=
valuesArr
.
getString
(
k
);
tbCfGoodstypeEntity
.
setGoodstypeTitle
(
product_type
);
optionEntity
.
setOptiionSpecies
(
optionSpecies
);
tbCfGoodstypeEntity
.
setGoodstypeSort
(
tbCfGoodstypeDao
.
queryTotal
()
+
1
);
categoryBuilder
.
append
(
optionSpecies
);
product_type
=
product_type
.
replaceAll
(
" "
,
"-"
);
if
(
k
!=
valuesArr
.
size
()
-
1
)
{
tbCfGoodstypeEntity
.
setGoodstypeUrl
(
"https://www.afrieshop.com/collections/"
+
product_type
);
categoryBuilder
.
append
(
","
);
tbCfGoodstypeDao
.
save
(
tbCfGoodstypeEntity
);
}
else
{
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity
tbCfGoodstypeEntity
=
tbCfGoodstypeDao
.
queryByTitle
(
product_type
);
goods_type_id
=
tbCfGoodstypeEntity
.
getGoodstypeId
();
}
// 二级分类名
String
tags
=
""
;
// 三级分类名
String
three
=
""
;
String
[]
s
=
productsObj
.
getString
(
"tags"
).
split
(
","
);
Console
.
error
(
Arrays
.
toString
(
s
));
for
(
String
str
:
s
)
{
if
(
str
.
indexOf
(
"#"
)
==
0
)
{
tags
=
str
.
replaceAll
(
"#"
,
""
);
}
else
{
three
=
str
;
}
}
optionEntity
.
setCreateTime
(
date
);
optionEntity
.
setUpdateTime
(
date
);
optionEntity
.
setDelFlag
(
1
);
optionEntity
.
setOptionName
(
optionName
);
tbCfOptionDao
.
save
(
optionEntity
);
}
}
categoryEntity
.
setCategoryDesc
(
categoryBuilder
.
toString
());
tbCfCategoryDao
.
save
(
categoryEntity
);
// 保存二级分类名
}
String
goodsTwoId
=
IdUtil
.
simpleUUID
();
// 商品二级分类id
if
(
tbCfGoodstwotypeDao
.
queryTitle
(
tags
)
==
null
)
{
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
new
TbCfGoodstwotypeEntity
();
tbCfGoodstwotypeEntity
.
setGoodstwotypeId
(
goodsTwoId
);
// 保存商品的变体数据
tbCfGoodstwotypeEntity
.
setGoodstwotypeTitle
(
tags
);
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
tbCfGoodstwotypeEntity
.
setGoodstypeId
(
goods_type_id
);
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
tbCfGoodstwotypeDao
.
save
(
tbCfGoodstwotypeEntity
);
JSONObject
variantsObj
=
variantsArr
.
getJSONObject
(
j
);
Integer
quantity
=
variantsObj
.
getInt
(
"inventory_quantity"
);
// 库存信息
BigDecimal
price
=
new
BigDecimal
(
variantsObj
.
getString
(
"price"
));
// 价格
TbCfItemSkusEntity
skusEntity
=
new
TbCfItemSkusEntity
();
skusEntity
.
setId
(
variantsObj
.
getString
(
"id"
));
skusEntity
.
setItemId
(
itemId
);
skusEntity
.
setDelFlag
(
1
);
skusEntity
.
setCreateTime
(
date
);
skusEntity
.
setUpdateTime
(
date
);
skusEntity
.
setSkuDesc
(
variantsObj
.
getString
(
"title"
));
skusEntity
.
setSkuName
(
optionBuilder
.
toString
());
skusEntity
.
setSkuPrice
(
price
);
skusEntity
.
setSkuCount
(
quantity
);
skusEntity
.
setOrderNum
(
variantsObj
.
getInt
(
"position"
));
tbCfItemSkusDao
.
save
(
skusEntity
);
tbCfStationItem
.
setItemCount
(
quantity
.
longValue
());
tbCfStationItem
.
setItemPrice
(
null
);
// 商品的折扣价
tbCfStationItem
.
setDiscountPrice
(
price
);
}
String
title
=
productsObj
.
getString
(
"title"
);
// 商品的名称
String
product_type
=
productsObj
.
getString
(
"product_type"
);
// 商品的分类
// 保存一级分类名
String
goods_type_id
=
IdUtil
.
simpleUUID
();
// 商品分类id
if
(
tbCfGoodstypeDao
.
queryByTitle
(
product_type
)
==
null
)
{
// 如果分类名已存在则不保存
TbCfGoodstypeEntity
tbCfGoodstypeEntity
=
new
TbCfGoodstypeEntity
();
tbCfGoodstypeEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfGoodstypeEntity
.
setGoodstypeTitle
(
product_type
);
tbCfGoodstypeEntity
.
setGoodstypeSort
(
tbCfGoodstypeDao
.
queryTotal
()
+
1
);
product_type
=
product_type
.
replaceAll
(
" "
,
"-"
);
tbCfGoodstypeEntity
.
setGoodstypeUrl
(
"https://www.afrieshop.com/collections/"
+
product_type
);
tbCfGoodstypeDao
.
save
(
tbCfGoodstypeEntity
);
}
else
{
// 如果已存在一级分类名,则使用已存在的 id
TbCfGoodstypeEntity
tbCfGoodstypeEntity
=
tbCfGoodstypeDao
.
queryByTitle
(
product_type
);
goods_type_id
=
tbCfGoodstypeEntity
.
getGoodstypeId
();
}
// 二级分类名
String
tags
=
""
;
// 三级分类名
String
three
=
""
;
String
[]
s
=
productsObj
.
getString
(
"tags"
).
split
(
","
);
Console
.
error
(
Arrays
.
toString
(
s
));
for
(
String
str
:
s
)
{
if
(
str
.
indexOf
(
"#"
)
==
0
)
{
tags
=
str
.
replaceAll
(
"#"
,
""
);
}
else
{
}
else
{
three
=
str
;
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
tbCfGoodstwotypeDao
.
queryTitle
(
tags
);
goodsTwoId
=
tbCfGoodstwotypeEntity
.
getGoodstwotypeId
();
}
}
}
// 保存三级分类名(品名)
// 保存二级分类名
String
goodsThreeId
=
IdUtil
.
simpleUUID
();
// 商品三级分类id
String
goodsTwoId
=
IdUtil
.
simpleUUID
();
// 商品二级分类id
if
(
tbCfDescripitonDao
.
queryByDescriptionName
(
three
)
==
null
)
{
if
(
tbCfGoodstwotypeDao
.
queryTitle
(
tags
)
==
null
)
{
TbCfDescripitonEntity
tbCfDescripitonEntity
=
new
TbCfDescripitonEntity
();
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
new
TbCfGoodstwotypeEntity
();
tbCfDescripitonEntity
.
setDescripitionId
(
goodsThreeId
);
tbCfGoodstwotypeEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfDescripitonEntity
.
setDescripitionName
(
three
);
tbCfGoodstwotypeEntity
.
setGoodstwotypeTitle
(
tags
);
tbCfDescripitonEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfGoodstwotypeEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfDescripitonEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfGoodstwotypeDao
.
save
(
tbCfGoodstwotypeEntity
);
tbCfDescripitonDao
.
save
(
tbCfDescripitonEntity
);
}
else
{
}
else
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
tbCfGoodstwotypeDao
.
queryTitle
(
tags
);
TbCfDescripitonEntity
tbCfDescripitonEntity
=
tbCfDescripitonDao
.
queryByDescriptionName
(
three
);
goodsTwoId
=
tbCfGoodstwotypeEntity
.
getGoodstwotypeId
();
goodsThreeId
=
tbCfDescripitonEntity
.
getDescripitionId
();
}
}
// 保存三级分类名(品名)
// 保存商品的主体信息
String
goodsThreeId
=
IdUtil
.
simpleUUID
();
// 商品三级分类id
tbCfStationItem
.
setItemId
(
itemId
);
if
(
tbCfDescripitonDao
.
queryByDescriptionName
(
three
)
==
null
)
{
tbCfStationItem
.
setCreateTime
(
date
);
TbCfDescripitonEntity
tbCfDescripitonEntity
=
new
TbCfDescripitonEntity
();
tbCfStationItem
.
setItemNum
(
0L
);
tbCfDescripitonEntity
.
setDescripitionId
(
goodsThreeId
);
tbCfStationItem
.
setItemUrl
(
"https://www.afrieshop.com/products/"
+
productsObj
.
getString
(
"handle"
));
tbCfDescripitonEntity
.
setDescripitionName
(
three
);
tbCfStationItem
.
setSupplier
(
productsObj
.
getString
(
"vendor"
));
tbCfDescripitonEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfStationItem
.
setItemBrief
(
title
);
tbCfDescripitonEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfStationItem
.
setItemName
(
title
);
tbCfDescripitonDao
.
save
(
tbCfDescripitonEntity
);
tbCfStationItem
.
setItemCode
(
id
);
}
else
{
tbCfStationItem
.
setItemCategory
(
goods_type_id
);
TbCfDescripitonEntity
tbCfDescripitonEntity
=
tbCfDescripitonDao
.
queryByDescriptionName
(
three
);
tbCfStationItem
.
setItemCategorytwo
(
goodsTwoId
);
goodsThreeId
=
tbCfDescripitonEntity
.
getDescripitionId
();
tbCfStationItem
.
setItemDescritionId
(
goodsThreeId
);
}
tbCfStationItem
.
setItemTags
(
product_type
+
","
+
tags
+
","
+
three
);
tbCfStationItem
.
setItemTop
(
"N"
);
// 保存商品的主体信息
tbCfStationItem
.
setItemId
(
itemId
);
tbCfStationItem
.
setCreateTime
(
date
);
tbCfStationItem
.
setItemNum
(
0L
);
tbCfStationItem
.
setItemUrl
(
"https://www.afrieshop.com/products/"
+
productsObj
.
getString
(
"handle"
));
tbCfStationItem
.
setSupplier
(
productsObj
.
getString
(
"vendor"
));
tbCfStationItem
.
setItemBrief
(
title
);
tbCfStationItem
.
setItemName
(
title
);
tbCfStationItem
.
setItemCode
(
id
);
tbCfStationItem
.
setItemCategory
(
goods_type_id
);
tbCfStationItem
.
setItemCategorytwo
(
goodsTwoId
);
tbCfStationItem
.
setItemDescritionId
(
goodsThreeId
);
tbCfStationItem
.
setItemTags
(
product_type
+
","
+
tags
+
","
+
three
);
tbCfStationItem
.
setItemTop
(
"N"
);
// 上传图片
String
src
=
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
);
InputStream
inputStream
=
getImageStream
(
src
);
byte
[]
bytes
=
toByteArray
(
inputStream
);
String
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_station.jpg"
,
"zion"
);
tbCfStationItem
.
setItemImg
(
url
);
tbCfStationItem
.
setEnableFlag
(
2
);
tbCfStationItemDao
.
save
(
tbCfStationItem
);
// 商品的富文本描述
StringBuilder
imageBuilder
=
new
StringBuilder
();
JSONArray
imagesArr
=
productsObj
.
getJSONArray
(
"images"
);
for
(
int
j
=
0
;
j
<
imagesArr
.
size
();
j
++)
{
JSONObject
imageObj
=
imagesArr
.
getJSONObject
(
j
);
// 上传图片
// 上传图片
src
=
imageObj
.
getString
(
"src"
);
String
src
=
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
);
inputStream
=
getImageStream
(
src
);
InputStream
inputStream
=
getImageStream
(
src
);
bytes
=
toByteArray
(
inputStream
);
byte
[]
bytes
=
toByteArray
(
inputStream
);
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_sku_"
+
j
+
".jpg"
,
"zion"
);
String
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_station.jpg"
,
"zion"
);
System
.
err
.
println
(
"主图的链接为: "
+
url
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
tbCfStationItem
.
setItemImg
(
url
);
.
append
(
url
).
append
(
"\" title=\""
)
tbCfStationItem
.
setEnableFlag
(
2
);
.
append
(
IdUtil
.
randomUUID
()).
append
(
"_350x350"
)
tbCfStationItemDao
.
save
(
tbCfStationItem
);
.
append
(
IdUtil
.
simpleUUID
()).
append
(
".jpg\"/></p>"
);
}
// 商品的富文本描述
// 商品详情
StringBuilder
imageBuilder
=
new
StringBuilder
();
TbCfItemDescEntity
itemDescEntity
=
tbCfItemDescDao
.
queryObject
(
itemId
);
JSONArray
imagesArr
=
productsObj
.
getJSONArray
(
"images"
);
if
(
itemDescEntity
==
null
)
{
for
(
int
j
=
0
;
j
<
imagesArr
.
size
();
j
++)
{
itemDescEntity
=
new
TbCfItemDescEntity
();
JSONObject
imageObj
=
imagesArr
.
getJSONObject
(
j
);
itemDescEntity
.
setItemId
(
itemId
);
// 上传图片
itemDescEntity
.
setItemDesc
(
imageBuilder
.
toString
());
src
=
imageObj
.
getString
(
"src"
);
itemDescEntity
.
setCreateTime
(
date
);
inputStream
=
getImageStream
(
src
);
tbCfItemDescDao
.
save
(
itemDescEntity
);
bytes
=
toByteArray
(
inputStream
);
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_sku_"
+
j
+
".jpg"
,
"zion"
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
.
append
(
url
).
append
(
"\" title=\""
)
.
append
(
IdUtil
.
randomUUID
()).
append
(
"_350x350"
)
.
append
(
IdUtil
.
simpleUUID
()).
append
(
".jpg\"/></p>"
);
}
// 商品详情
TbCfItemDescEntity
itemDescEntity
=
tbCfItemDescDao
.
queryObject
(
itemId
);
if
(
itemDescEntity
==
null
)
{
itemDescEntity
=
new
TbCfItemDescEntity
();
itemDescEntity
.
setItemId
(
itemId
);
itemDescEntity
.
setItemDesc
(
imageBuilder
.
toString
());
itemDescEntity
.
setCreateTime
(
date
);
tbCfItemDescDao
.
save
(
itemDescEntity
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
// 记录失败的产品记录
TbProductMissEntity
tbProductMissEntity
=
new
TbProductMissEntity
();
tbProductMissEntity
.
setId
(
IdUtil
.
simpleUUID
());
tbProductMissEntity
.
setProductId
(
id
);
tbProductMissEntity
.
setMissType
(
2
);
tbProductMissEntity
.
setPageSize
(
pageSize
);
tbProductMissEntity
.
setCreateTime
(
new
Date
());
tbProductMissDao
.
save
(
tbProductMissEntity
);
}
}
}
catch
(
Exception
e
)
{
};
e
.
printStackTrace
();
// 提交任务执行
// 记录失败的产品记录
executorService
.
submit
(
runnable
);
TbProductMissEntity
tbProductMissEntity
=
new
TbProductMissEntity
();
tbProductMissEntity
.
setId
(
IdUtil
.
simpleUUID
());
tbProductMissEntity
.
setProductId
(
id
);
tbProductMissEntity
.
setMissType
(
2
);
tbProductMissEntity
.
setPageSize
(
pageSize
);
tbProductMissEntity
.
setCreateTime
(
new
Date
());
tbProductMissDao
.
save
(
tbProductMissEntity
);
}
}
}
}
}
...
...
platform-admin/src/main/test/java/test/ImportTask.java
0 → 100644
浏览文件 @
9e3badc9
package
test
;
/**
* 商品导入的任务块
*
* @author 爱酱油不爱醋
* @version 1.0
*/
public
class
ImportTask
implements
Runnable
{
@Override
public
void
run
()
{
}
}
platform-admin/src/main/test/java/test/TestApi.java
浏览文件 @
9e3badc9
...
@@ -3,6 +3,7 @@ package test;
...
@@ -3,6 +3,7 @@ package test;
import
cn.hutool.core.lang.Console
;
import
cn.hutool.core.lang.Console
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HttpRequest
;
import
cn.hutool.http.HttpRequest
;
import
com.google.gson.annotations.JsonAdapter
;
import
com.platform.controller.api.ProductExitException
;
import
com.platform.controller.api.ProductExitException
;
import
com.platform.dao.*
;
import
com.platform.dao.*
;
import
com.platform.entity.*
;
import
com.platform.entity.*
;
...
@@ -114,21 +115,36 @@ public class TestApi {
...
@@ -114,21 +115,36 @@ public class TestApi {
*/
*/
@Test
@Test
public
void
linkTest
()
{
public
void
linkTest
()
{
String
link
=
"https://mollykitty.myshopify.com/admin/api/2020-01/products.json?vendor=%E6%B3%B0%E9%82%A6%E6%9C%8D%E9%A5%B0&limit=1&vendor=戴菊"
;
String
link
=
"https://mollykitty.myshopify.com/admin/api/2020-01/products.json?vendor=%E6%B3%B0%E9%82%A6%E6%9C%8D%E9%A5%B0&limit=1
00
&vendor=戴菊"
;
link
=
HttpRequest
.
get
(
link
)
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
.
execute
().
body
();
JSONObject
json
=
JSONObject
.
fromObject
(
link
);
JSONObject
json
=
JSONObject
.
fromObject
(
link
);
JSONObject
product
=
json
.
getJSONArray
(
"products"
).
getJSONObject
(
0
);
JSONArray
productArr
=
json
.
getJSONArray
(
"products"
);
String
tags
=
product
.
getString
(
"tags"
);
for
(
int
j
=
0
;
j
<
productArr
.
size
();
j
++)
{
JSONObject
product
=
productArr
.
getJSONObject
(
j
);
JSONArray
variantsArr
=
product
.
getJSONArray
(
"variants"
);
for
(
int
i
=
0
;
i
<
variantsArr
.
size
();
i
++)
{
JSONObject
variantsObj
=
variantsArr
.
getJSONObject
(
i
);
String
compare_at_price
=
variantsObj
.
getString
(
"compare_at_price"
);
if
(!
"null"
.
equals
(
compare_at_price
))
{
System
.
out
.
println
(
compare_at_price
);
}
}
}
/*String tags = product.getString("tags");
String[] s = tags.split(",");
String[] s = tags.split(",");
Console.error(Arrays.toString(s));
Console.error(Arrays.toString(s));
for (String i : s) {
for (String i : s) {
if (i.indexOf("#") == 0) {
if (i.indexOf("#") == 0) {
System.out.println(i);
System.out.println(i);
}
}
}
}
*/
}
}
/**
/**
...
...
platform-admin/src/main/test/sql/Test.sql
0 → 100644
浏览文件 @
9e3badc9
truncate
from
tb_category_template
;
DELETE
from
tb_cf_category
;
DELETE
from
tb_cf_goodstwotype
;
DELETE
from
tb_cf_goodstype
;
DELETE
from
tb_cf_item_desc
;
DELETE
from
tb_cf_item_skus
;
DELETE
from
tb_cf_option
;
DELETE
from
tb_cf_station_item
;
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论