Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
C
chinafrica
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
chinafrica
Commits
b535bbfe
提交
b535bbfe
authored
3月 18, 2020
作者:
梁业锦
💬
提交者:
何春颖
3月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 提交
上级
fe1fcf0e
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
15 行删除
+31
-15
ImpartCode.java
platform-admin/src/main/test/java/test/ImpartCode.java
+26
-10
log4j.properties
platform-admin/src/main/test/resource/log4j.properties
+5
-5
没有找到文件。
platform-admin/src/main/test/java/test/ImpartCode.java
浏览文件 @
b535bbfe
...
@@ -79,8 +79,7 @@ public class ImpartCode {
...
@@ -79,8 +79,7 @@ public class ImpartCode {
*/
*/
@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
;
...
@@ -101,7 +100,11 @@ public class ImpartCode {
...
@@ -101,7 +100,11 @@ public class ImpartCode {
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
header
(
"link"
);
.
execute
().
header
(
"link"
);
// 获取第一次循环后的请求
// 获取第一次循环后的请求
try
{
headerLink
=
headerLink
.
split
(
";"
)[
0
].
replaceAll
(
"<"
,
""
).
replaceAll
(
">"
,
""
);
headerLink
=
headerLink
.
split
(
";"
)[
0
].
replaceAll
(
"<"
,
""
).
replaceAll
(
">"
,
""
);
}
catch
(
Exception
e
)
{
continue
;
}
// 无限导入
// 无限导入
while
(
true
)
{
while
(
true
)
{
// 导入商品
// 导入商品
...
@@ -141,6 +144,8 @@ public class ImpartCode {
...
@@ -141,6 +144,8 @@ public class ImpartCode {
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
// 取每个数组中的 products 数组节点
// 取每个数组中的 products 数组节点
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
// 记录线程数
int
threadCount
=
0
;
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
...
@@ -157,10 +162,13 @@ public class ImpartCode {
...
@@ -157,10 +162,13 @@ public class ImpartCode {
String
id
=
productsObj
.
getString
(
"id"
);
String
id
=
productsObj
.
getString
(
"id"
);
// 查询该商品的 id 是否已保存
// 查询该商品的 id 是否已保存
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
System
.
err
.
println
(
"已存在的商品,跳过导入的商品id为:"
+
id
);
// 跳过循环
// 跳过循环
continue
;
continue
;
}
}
threadCount
++;
// 线程任务
// 线程任务
int
finalThreadCount
=
threadCount
;
Runnable
runnable
=
()
->
{
Runnable
runnable
=
()
->
{
try
{
try
{
// 用于记录 option 的属性名
// 用于记录 option 的属性名
...
@@ -223,7 +231,11 @@ public class ImpartCode {
...
@@ -223,7 +231,11 @@ public class ImpartCode {
tbCfOptionDao
.
save
(
optionEntity
);
tbCfOptionDao
.
save
(
optionEntity
);
}
}
categoryEntity
.
setCategoryDesc
(
categoryBuilder
.
toString
());
categoryEntity
.
setCategoryDesc
(
categoryBuilder
.
toString
());
try
{
tbCfCategoryDao
.
save
(
categoryEntity
);
tbCfCategoryDao
.
save
(
categoryEntity
);
}
catch
(
Exception
e
)
{
tbCfCategoryDao
.
update
(
categoryEntity
);
}
}
}
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
...
@@ -356,7 +368,9 @@ public class ImpartCode {
...
@@ -356,7 +368,9 @@ public class ImpartCode {
// 上传图片
// 上传图片
src
=
imageObj
.
getString
(
"src"
);
src
=
imageObj
.
getString
(
"src"
);
inputStream
=
getImageStream
(
src
);
inputStream
=
getImageStream
(
src
);
if
(
inputStream
!=
null
)
{
bytes
=
toByteArray
(
inputStream
);
bytes
=
toByteArray
(
inputStream
);
}
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_sku_"
+
j
+
".jpg"
,
"zion"
);
url
=
OssUtil
.
upload
(
bytes
,
id
+
"_sku_"
+
j
+
".jpg"
,
"zion"
);
// 拼接富文本的 HTML
// 拼接富文本的 HTML
...
@@ -364,6 +378,7 @@ public class ImpartCode {
...
@@ -364,6 +378,7 @@ public class ImpartCode {
.
append
(
url
).
append
(
"\" title=\""
)
.
append
(
url
).
append
(
"\" title=\""
)
.
append
(
IdUtil
.
randomUUID
()).
append
(
"_350x350"
)
.
append
(
IdUtil
.
randomUUID
()).
append
(
"_350x350"
)
.
append
(
IdUtil
.
simpleUUID
()).
append
(
".jpg\"/></p>"
);
.
append
(
IdUtil
.
simpleUUID
()).
append
(
".jpg\"/></p>"
);
System
.
err
.
println
(
"富文本图片内容:"
+
imageBuilder
.
toString
());
}
}
// 商品详情
// 商品详情
TbCfItemDescEntity
itemDescEntity
=
tbCfItemDescDao
.
queryObject
(
itemId
);
TbCfItemDescEntity
itemDescEntity
=
tbCfItemDescDao
.
queryObject
(
itemId
);
...
@@ -374,6 +389,7 @@ public class ImpartCode {
...
@@ -374,6 +389,7 @@ public class ImpartCode {
itemDescEntity
.
setCreateTime
(
date
);
itemDescEntity
.
setCreateTime
(
date
);
tbCfItemDescDao
.
save
(
itemDescEntity
);
tbCfItemDescDao
.
save
(
itemDescEntity
);
}
}
System
.
err
.
println
(
"线程号:"
+
finalThreadCount
+
",已执行完成!"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
// 记录失败的产品记录
// 记录失败的产品记录
...
@@ -388,8 +404,8 @@ public class ImpartCode {
...
@@ -388,8 +404,8 @@ public class ImpartCode {
};
};
// 提交任务执行
// 提交任务执行
executorService
.
submit
(
runnable
);
executorService
.
submit
(
runnable
);
System
.
err
.
println
(
"线程号:"
+
finalThreadCount
+
",开始提交任务!"
);
}
}
}
}
/**
/**
...
@@ -402,8 +418,8 @@ public class ImpartCode {
...
@@ -402,8 +418,8 @@ public class ImpartCode {
public
static
InputStream
getImageStream
(
String
url
)
{
public
static
InputStream
getImageStream
(
String
url
)
{
try
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setReadTimeout
(
5
000
);
connection
.
setReadTimeout
(
10
000
);
connection
.
setConnectTimeout
(
5
000
);
connection
.
setConnectTimeout
(
10
000
);
connection
.
setRequestMethod
(
"GET"
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
return
connection
.
getInputStream
();
return
connection
.
getInputStream
();
...
...
platform-admin/src/main/test/resource/log4j.properties
浏览文件 @
b535bbfe
...
@@ -59,8 +59,8 @@ log4j.appender.slowsql.layout=org.apache.log4j.PatternLayout
...
@@ -59,8 +59,8 @@ log4j.appender.slowsql.layout=org.apache.log4j.PatternLayout
log4j.appender.slowsql.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
log4j.appender.slowsql.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#控制台输出所有SQL
#控制台输出所有SQL
#便于调试 生产环境注释
#便于调试 生产环境注释
log4j.logger.com.platform.dao
=
DEBUG,sql
#
log4j.logger.com.platform.dao=DEBUG,sql
log4j.appender.sql
=
org.apache.log4j.ConsoleAppender
#
log4j.appender.sql=org.apache.log4j.ConsoleAppender
log4j.appender.sql.Target
=
System.out
#
log4j.appender.sql.Target=System.out
log4j.appender.sql.layout
=
org.apache.log4j.PatternLayout
#
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern
=
%m %n
#
log4j.appender.sql.layout.ConversionPattern=%m %n
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论