Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
C
chinafrica
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
chinafrica
Commits
e94a2d49
提交
e94a2d49
authored
3月 10, 2020
作者:
梁业锦
💬
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 商品导入相关逻辑
上级
22005583
隐藏空白字符变更
内嵌
并排
正在显示
28 个修改的文件
包含
1930 行增加
和
12 行删除
+1930
-12
ProductExitException.java
...ava/com/platform/controller/api/ProductExitException.java
+24
-0
ShopifyController.java
...n/java/com/platform/controller/api/ShopifyController.java
+531
-0
TbCategoryTemplateDao.java
...src/main/java/com/platform/dao/TbCategoryTemplateDao.java
+2
-0
TbCfCategoryDao.java
...admin/src/main/java/com/platform/dao/TbCfCategoryDao.java
+1
-0
TbCfDescripitonDao.java
...in/src/main/java/com/platform/dao/TbCfDescripitonDao.java
+3
-0
TbCfGoodstwotypeDao.java
...n/src/main/java/com/platform/dao/TbCfGoodstwotypeDao.java
+5
-2
TbCfGoodstypeDao.java
...dmin/src/main/java/com/platform/dao/TbCfGoodstypeDao.java
+8
-0
TbCfItemDescDao.java
...admin/src/main/java/com/platform/dao/TbCfItemDescDao.java
+1
-0
TbCfStationItemDao.java
...in/src/main/java/com/platform/dao/TbCfStationItemDao.java
+3
-1
TbProductMissDao.java
...dmin/src/main/java/com/platform/dao/TbProductMissDao.java
+14
-0
ItemDescSkus.java
...admin/src/main/java/com/platform/entity/ItemDescSkus.java
+13
-0
TbCfItemSkusEntity.java
...src/main/java/com/platform/entity/TbCfItemSkusEntity.java
+0
-1
TbProductMissEntity.java
...rc/main/java/com/platform/entity/TbProductMissEntity.java
+102
-0
TbProductMissService.java
.../main/java/com/platform/service/TbProductMissService.java
+71
-0
TbProductMissServiceImpl.java
...a/com/platform/service/impl/TbProductMissServiceImpl.java
+59
-0
ShopifyConstant.java
...dmin/src/main/java/com/platform/task/ShopifyConstant.java
+78
-6
TbCategoryTemplateDao.xml
...main/resources/com/platform/dao/TbCategoryTemplateDao.xml
+13
-0
TbCfCategoryDao.xml
...n/src/main/resources/com/platform/dao/TbCfCategoryDao.xml
+5
-0
TbCfDescripitonDao.xml
...rc/main/resources/com/platform/dao/TbCfDescripitonDao.xml
+8
-1
TbCfGoodstwotypeDao.xml
...c/main/resources/com/platform/dao/TbCfGoodstwotypeDao.xml
+9
-0
TbCfGoodstypeDao.xml
.../src/main/resources/com/platform/dao/TbCfGoodstypeDao.xml
+10
-0
TbCfStationItemDao.xml
...rc/main/resources/com/platform/dao/TbCfStationItemDao.xml
+15
-1
TbProductMissDao.xml
.../src/main/resources/com/platform/dao/TbProductMissDao.xml
+95
-0
TestApi.java
platform-admin/src/main/test/java/test/TestApi.java
+642
-0
applicationContext-test.xml
...-admin/src/main/test/resource/applicationContext-test.xml
+129
-0
log4j.properties
platform-admin/src/main/test/resource/log4j.properties
+66
-0
platform.properties
platform-admin/src/main/test/resource/platform.properties
+18
-0
pom.xml
pom.xml
+5
-0
没有找到文件。
platform-admin/src/main/java/com/platform/controller/api/ProductExitException.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
controller
.
api
;
public
class
ProductExitException
extends
Exception
{
public
ProductExitException
()
{
super
();
}
public
ProductExitException
(
String
message
)
{
super
(
message
);
}
public
ProductExitException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
ProductExitException
(
Throwable
cause
)
{
super
(
cause
);
}
protected
ProductExitException
(
String
message
,
Throwable
cause
,
boolean
enableSuppression
,
boolean
writableStackTrace
)
{
super
(
message
,
cause
,
enableSuppression
,
writableStackTrace
);
}
}
platform-admin/src/main/java/com/platform/controller/api/ShopifyController.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
controller
.
api
;
import
cn.hutool.core.lang.Console
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HttpRequest
;
import
com.platform.dao.*
;
import
com.platform.entity.*
;
import
com.platform.task.ShopifyConstant
;
import
com.platform.utils.R
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
java.io.*
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
/**
* 保存 Shopify 的商品数据
*
* @author 爱酱油不爱醋
* @version 1.0
*/
@Controller
@RequestMapping
(
value
=
"/api/shopify"
,
produces
=
"application/json;charset=UTF-8"
)
public
class
ShopifyController
{
@Autowired
private
TbCfStationItemDao
tbCfStationItemDao
;
@Autowired
private
TbCfItemDescDao
tbCfItemDescDao
;
@Autowired
private
TbCfItemSkusDao
tbCfItemSkusDao
;
@Autowired
private
TbCfCategoryDao
tbCfCategoryDao
;
@Autowired
private
TbCfOptionDao
tbCfOptionDao
;
@Autowired
private
TbCfGoodstypeDao
tbCfGoodstypeDao
;
@Autowired
private
TbProductMissDao
tbProductMissDao
;
@Autowired
private
TbCategoryTemplateDao
tbCategoryTemplateDao
;
@Autowired
private
TbCfGoodstwotypeDao
tbCfGoodstwotypeDao
;
public
static
void
main
(
String
[]
args
)
{
String
link
=
"https://mollykitty.myshopify.com/admin/api/2019-10/products.json?limit=250&page_info=eyJwcm9kdWN0X3R5cGUiOiJXb21lbiIsImxhc3RfaWQiOjQ0OTc2Nzg5NTg2ODksImxhc3RfdmFsdWUiOiJDYXN1YWwgU2xpbSBTd2VhdGVycyIsImRpcmVjdGlvbiI6Im5leHQifQ"
;
Console
.
error
(
link
);
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
header
(
"link"
)
.
split
(
","
)[
1
];
Console
.
error
(
link
);
link
=
link
.
substring
(
2
,
link
.
indexOf
(
">"
));
Console
.
log
(
"链接:"
+
link
);
}
/**
* 保存平台接口的数据
*
* @return 保存商品数据
*/
@PostMapping
(
"/save"
)
public
R
save
()
{
// 记录页数的
int
pageSize
=
0
;
int
productCount
=
0
;
// 初始页
String
link
=
"https://mollykitty.myshopify.com/admin/api/2019-10/products.json?limit=250&page_info=eyJsYXN0X2lkIjo0Mzg1NDgxMTMwMDgxLCJsYXN0X3ZhbHVlIjoiQmFieSBmb29kIHN1cHBsZW1lbnQgZ3JpbmRlciIsImRpcmVjdGlvbiI6Im5leHQifQ"
;
// 循环翻页
while
(
true
)
{
Console
.
error
(
"当前的页数为:"
+
pageSize
);
// 这个请求需要密钥,可以先拿着账号密码去浏览器请求一遍,F12 获取 token 复制粘贴即可
String
result
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
result
);
// 取每个数组中的 products 数组节点
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
JSONObject
productsObj
=
productsArr
.
getJSONObject
(
i
);
Console
.
log
(
"当前正在导入的商品个数为:"
+
productCount
);
productCount
++;
// 商品主体信息的商品 id
String
itemId
=
IdUtil
.
simpleUUID
();
// 复用的日期
Date
date
=
new
Date
();
// 商品的平台 id
String
id
=
productsObj
.
getString
(
"id"
);
try
{
// 查询该商品的 id 是否已保存
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
// 记录失败的产品记录
throw
new
ProductExitException
();
}
// 用于记录 option 的属性名
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
);
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
String
optionId
=
optionObj
.
getString
(
"id"
);
categoryEntity
.
setCategoryId
(
optionId
);
categoryEntity
.
setCreateTime
(
date
);
categoryEntity
.
setUpdateTime
(
date
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setItemId
(
itemId
);
String
optionName
=
optionObj
.
getString
(
"name"
);
categoryEntity
.
setCategoryName
(
optionName
);
optionBuilder
.
append
(
optionName
);
if
(
j
!=
optionsArr
.
size
()
-
1
)
{
optionBuilder
.
append
(
"/"
);
}
optionNum
++;
categoryEntity
.
setOrderNum
(
optionNum
);
categoryEntity
.
setOption
(
"option"
+
optionNum
);
// 保存属性名
if
(
tbCategoryTemplateDao
.
queryByDesc
(
optionName
)
==
null
)
{
TbCategoryTemplateEntity
tbCategoryTemplateEntity
=
new
TbCategoryTemplateEntity
();
tbCategoryTemplateEntity
.
setId
(
IdUtil
.
simpleUUID
());
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
);
}
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
// 保存商品的变体数据
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
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
tags
=
productsObj
.
getString
(
"tags"
);
// 商品的标签名(视为二级分类名)
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
goodsTwoId
=
IdUtil
.
simpleUUID
();
// 商品二级分类id
// 保存二级分类名
if
(
tbCfGoodstwotypeDao
.
queryTitle
(
tags
)
==
null
)
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
new
TbCfGoodstwotypeEntity
();
tbCfGoodstwotypeEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfGoodstwotypeEntity
.
setGoodstwotypeTitle
(
tags
);
tbCfGoodstwotypeEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfGoodstwotypeDao
.
save
(
tbCfGoodstwotypeEntity
);
}
else
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
tbCfGoodstwotypeDao
.
queryTitle
(
tags
);
goodsTwoId
=
tbCfGoodstwotypeEntity
.
getGoodstwotypeId
();
}
// 保存商品的主体信息
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
.
setItemTags
(
tags
);
tbCfStationItem
.
setItemDescritionId
(
null
);
tbCfStationItem
.
setItemTop
(
"N"
);
tbCfStationItem
.
setItemImg
(
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
));
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
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
.
append
(
imageObj
.
getString
(
"src"
)).
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
(
ProductExitException
e
)
{
Console
.
error
(
"该商品已存在"
);
// 记录已存在的商品
TbProductMissEntity
tbProductMissEntity
=
new
TbProductMissEntity
();
tbProductMissEntity
.
setId
(
IdUtil
.
simpleUUID
());
tbProductMissEntity
.
setProductId
(
id
);
tbProductMissEntity
.
setMissType
(
1
);
tbProductMissEntity
.
setPageSize
(
pageSize
);
tbProductMissEntity
.
setCreateTime
(
new
Date
());
tbProductMissDao
.
save
(
tbProductMissEntity
);
}
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
);
}
}
// 循环翻页
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
header
(
"link"
)
.
split
(
","
)[
1
];
Console
.
error
(
link
);
link
=
link
.
substring
(
2
,
link
.
indexOf
(
">"
));
// 记录页数
pageSize
++;
}
}
/**
* 补录失败的商品
*
* @return 补录失败的商品
*/
@GetMapping
(
"/update"
)
public
R
update
()
{
List
<
TbProductMissEntity
>
TbProductList
=
tbProductMissDao
.
queryList
(
new
HashMap
<>());
for
(
TbProductMissEntity
tbProductMissEntity
:
TbProductList
)
{
String
product_id
=
tbProductMissEntity
.
getProductId
();
List
<
TbCfStationItemEntity
>
list
=
tbCfStationItemDao
.
queryByCodeList
(
product_id
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
for
(
TbCfStationItemEntity
tbCfStationItemEntity
:
list
)
{
String
item_id
=
tbCfStationItemEntity
.
getItemId
();
// 删除主体数据
tbCfStationItemDao
.
delete
(
item_id
);
// 删除商品描述数据
tbCfItemDescDao
.
delete
(
item_id
);
// 删除商品的属性
tbCfCategoryDao
.
deleteByItemId
(
item_id
);
// 删除商品的变体数据
tbCfItemSkusDao
.
deleteByItemId
(
item_id
);
}
}
// 删除记录表的数据
tbProductMissDao
.
deleteByCode
(
product_id
);
// 这个请求需要密钥,可以先拿着账号密码去浏览器请求一遍,F12 获取 token 复制粘贴即可
String
result
=
HttpRequest
.
get
(
ShopifyConstant
.
productId
(
product_id
))
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
productsObj
=
JSONObject
.
fromObject
(
result
).
getJSONObject
(
"product"
);
// 商品主体信息的商品 id
String
itemId
=
IdUtil
.
simpleUUID
();
// 复用的日期
Date
date
=
new
Date
();
// 商品的平台 id
String
id
=
productsObj
.
getString
(
"id"
);
try
{
// 用于记录 option 的属性名
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
);
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
String
optionId
=
IdUtil
.
simpleUUID
();
categoryEntity
.
setCategoryId
(
optionId
);
categoryEntity
.
setCreateTime
(
date
);
categoryEntity
.
setUpdateTime
(
date
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setItemId
(
itemId
);
String
optionName
=
optionObj
.
getString
(
"name"
);
categoryEntity
.
setCategoryName
(
optionName
);
optionBuilder
.
append
(
optionName
);
if
(
j
!=
optionsArr
.
size
())
{
optionBuilder
.
append
(
"/"
);
}
optionNum
++;
categoryEntity
.
setOrderNum
(
optionNum
);
categoryEntity
.
setOption
(
"option"
+
optionNum
);
tbCfCategoryDao
.
save
(
categoryEntity
);
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
);
optionEntity
.
setOptiionSpecies
(
valuesArr
.
getString
(
k
));
optionEntity
.
setCreateTime
(
date
);
optionEntity
.
setUpdateTime
(
date
);
optionEntity
.
setDelFlag
(
1
);
optionEntity
.
setOptionName
(
optionName
);
tbCfOptionDao
.
save
(
optionEntity
);
}
}
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
// 保存商品的变体数据
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
JSONObject
variantsObj
=
variantsArr
.
getJSONObject
(
j
);
Integer
quantity
=
variantsObj
.
getInt
(
"inventory_quantity"
);
// 库存信息
BigDecimal
price
=
new
BigDecimal
(
variantsObj
.
getString
(
"price"
));
// 价格
TbCfItemSkusEntity
skusEntity
=
new
TbCfItemSkusEntity
();
skusEntity
.
setId
(
IdUtil
.
simpleUUID
());
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
tags
=
productsObj
.
getString
(
"tags"
);
// 商品的标签名(视为二级分类名)
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
);
}
// 保存商品的主体信息
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
(
tags
);
tbCfStationItem
.
setItemTags
(
tags
);
tbCfStationItem
.
setItemDescritionId
(
null
);
tbCfStationItem
.
setItemTop
(
"N"
);
tbCfStationItem
.
setItemImg
(
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
));
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
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
.
append
(
imageObj
.
getString
(
"src"
)).
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
=
new
TbProductMissEntity
();
tbProductMissEntity
.
setId
(
IdUtil
.
simpleUUID
());
tbProductMissEntity
.
setProductId
(
id
);
tbProductMissEntity
.
setMissType
(
2
);
tbProductMissEntity
.
setPageSize
(
0
);
tbProductMissEntity
.
setCreateTime
(
new
Date
());
tbProductMissDao
.
save
(
tbProductMissEntity
);
}
}
return
R
.
ok
();
}
/**
* 通过URL获取网络图片
* 获取网络图片流
*
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
* @return 输入流
*/
public
static
InputStream
getImageStream
(
String
url
)
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setReadTimeout
(
5000
);
connection
.
setConnectTimeout
(
5000
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
return
connection
.
getInputStream
();
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"获取网络图片出现异常,图片路径为:"
+
url
);
e
.
printStackTrace
();
}
return
null
;
}
/**
* 将 InputStream 流转换为 byte[]
*
* @param input InputStream
* @return byte[]
* @throws IOException IO流异常
*/
public
static
byte
[]
toByteArray
(
InputStream
input
)
throws
IOException
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
int
n
=
0
;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
}
platform-admin/src/main/java/com/platform/dao/TbCategoryTemplateDao.java
浏览文件 @
e94a2d49
...
...
@@ -10,4 +10,6 @@ import com.platform.entity.TbCategoryTemplateEntity;
*/
public
interface
TbCategoryTemplateDao
extends
BaseDao
<
TbCategoryTemplateEntity
>
{
TbCategoryTemplateEntity
queryByDesc
(
String
category_desc
);
}
platform-admin/src/main/java/com/platform/dao/TbCfCategoryDao.java
浏览文件 @
e94a2d49
...
...
@@ -20,5 +20,6 @@ public interface TbCfCategoryDao extends BaseDao<TbCfCategoryEntity> {
int
changStatusBatch
(
String
[]
itemId
);
TbCfCategoryEntity
queryByOrderNum
(
@Param
(
"orderNum"
)
Integer
orderNum
,
@Param
(
"itemId"
)
String
itemId
);
int
deleteByItemId
(
String
itemId
);
}
platform-admin/src/main/java/com/platform/dao/TbCfDescripitonDao.java
浏览文件 @
e94a2d49
...
...
@@ -11,5 +11,8 @@ import java.util.List;
* @date 2019-10-16 11:51:35
*/
public
interface
TbCfDescripitonDao
extends
BaseDao
<
TbCfDescripitonEntity
>
{
List
<
TbCfDescripitonEntity
>
queryByItemTypeTwo
(
String
id
);
TbCfDescripitonEntity
queryByDescriptionName
(
String
descripition_name
);
}
platform-admin/src/main/java/com/platform/dao/TbCfGoodstwotypeDao.java
浏览文件 @
e94a2d49
...
...
@@ -12,7 +12,10 @@ import java.util.List;
* @date 2019-10-15 15:06:31
*/
public
interface
TbCfGoodstwotypeDao
extends
BaseDao
<
TbCfGoodstwotypeEntity
>
{
GoodsTypeToGoodsTwo
queryGoodsTypeId
(
String
goodstype_id
);
List
<
TbCfGoodstwotypeEntity
>
queryByTypeId
(
String
typeId
);
GoodsTypeToGoodsTwo
queryGoodsTypeId
(
String
goodstype_id
);
List
<
TbCfGoodstwotypeEntity
>
queryByTypeId
(
String
typeId
);
TbCfGoodstwotypeEntity
queryTitle
(
String
title
);
}
platform-admin/src/main/java/com/platform/dao/TbCfGoodstypeDao.java
浏览文件 @
e94a2d49
...
...
@@ -10,4 +10,12 @@ import com.platform.entity.TbCfGoodstypeEntity;
*/
public
interface
TbCfGoodstypeDao
extends
BaseDao
<
TbCfGoodstypeEntity
>
{
/**
* 根据名称查询对象
*
* @param title 分类名称
* @return TbCfGoodstypeEntity
*/
TbCfGoodstypeEntity
queryByTitle
(
String
title
);
}
platform-admin/src/main/java/com/platform/dao/TbCfItemDescDao.java
浏览文件 @
e94a2d49
...
...
@@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Param;
* @date 2019-12-23 14:28:47
*/
public
interface
TbCfItemDescDao
extends
BaseDao
<
TbCfItemDescEntity
>
{
int
changStatus
(
String
itemId
);
int
changStatusBatch
(
String
[]
itemId
);
...
...
platform-admin/src/main/java/com/platform/dao/TbCfStationItemDao.java
浏览文件 @
e94a2d49
...
...
@@ -6,7 +6,6 @@ import com.platform.entity.TbCfStationItemEntityExtends;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
/**
* 站点商品Dao
...
...
@@ -15,11 +14,14 @@ import java.util.Map;
* @date 2019-09-20 11:03:38
*/
public
interface
TbCfStationItemDao
extends
BaseDao
<
TbCfStationItemEntity
>
{
int
changeItemStatus
(
@Param
(
"status"
)
Integer
status
,
@Param
(
"itemIds"
)
String
[]
itemIds
);
List
<
ItemDescSkus
>
queryItemInfoById
(
String
itemId
);
List
<
TbCfStationItemEntityExtends
>
queryByItems
();
TbCfStationItemEntity
queryByCode
(
String
code
);
List
<
TbCfStationItemEntity
>
queryByCodeList
(
String
code
);
}
platform-admin/src/main/java/com/platform/dao/TbProductMissDao.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
dao
;
import
com.platform.entity.TbProductMissEntity
;
/**
* 产品导入失败记录表Dao
*
* @author lipengjun
* @date 2020-02-01 20:14:20
*/
public
interface
TbProductMissDao
extends
BaseDao
<
TbProductMissEntity
>
{
int
deleteByCode
(
String
productId
);
}
platform-admin/src/main/java/com/platform/entity/ItemDescSkus.java
浏览文件 @
e94a2d49
...
...
@@ -8,10 +8,23 @@ import java.util.List;
* @Description:
*/
public
class
ItemDescSkus
extends
TbCfStationItemEntity
{
/**
* 商品详情
*/
private
String
itemDesc
;
/**
* 是否立即上架
*/
private
boolean
putaway
;
/**
* 商品主体信息
*/
private
List
<
TbCfItemSkusEntity
>
prevItem
;
/**
* 商品规格信息
*/
private
List
<
TbCfCategoryEntity
>
tree
;
public
String
getItemDesc
()
{
return
itemDesc
;
}
...
...
platform-admin/src/main/java/com/platform/entity/TbCfItemSkusEntity.java
浏览文件 @
e94a2d49
...
...
@@ -42,7 +42,6 @@ public class TbCfItemSkusEntity implements Serializable {
* 属性IDS
*/
private
String
optionIds
;
/**
* 排序号
*/
...
...
platform-admin/src/main/java/com/platform/entity/TbProductMissEntity.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* 产品导入失败记录表实体
* 表名 tb_product_miss
*
* @author lipengjun
* @date 2020-02-01 20:14:20
*/
public
class
TbProductMissEntity
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
/**
* id
*/
private
String
id
;
/**
* 产品的id
*/
private
String
productId
;
/**
* 失败类型【1:已存在】【2:出现了异常】
*/
private
Integer
missType
;
/**
* 页数(每250个)
*/
private
Integer
pageSize
;
/**
* 创建时间
*/
private
Date
createTime
;
/**
* 设置:
*/
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
/**
* 获取:
*/
public
String
getId
()
{
return
id
;
}
/**
* 设置:产品的id
*/
public
void
setProductId
(
String
productId
)
{
this
.
productId
=
productId
;
}
/**
* 获取:产品的id
*/
public
String
getProductId
()
{
return
productId
;
}
/**
* 设置:失败类型【1:已存在】【2:出现了异常】
*/
public
void
setMissType
(
Integer
missType
)
{
this
.
missType
=
missType
;
}
/**
* 获取:失败类型【1:已存在】【2:出现了异常】
*/
public
Integer
getMissType
()
{
return
missType
;
}
/**
* 设置:页数(每250个)
*/
public
void
setPageSize
(
Integer
pageSize
)
{
this
.
pageSize
=
pageSize
;
}
/**
* 获取:页数(每250个)
*/
public
Integer
getPageSize
()
{
return
pageSize
;
}
/**
* 设置:创建时间
*/
public
void
setCreateTime
(
Date
createTime
)
{
this
.
createTime
=
createTime
;
}
/**
* 获取:创建时间
*/
public
Date
getCreateTime
()
{
return
createTime
;
}
}
platform-admin/src/main/java/com/platform/service/TbProductMissService.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
service
;
import
com.platform.entity.TbProductMissEntity
;
import
java.util.List
;
import
java.util.Map
;
/**
* 产品导入失败记录表Service接口
*
* @author lipengjun
* @date 2020-02-01 20:14:20
*/
public
interface
TbProductMissService
{
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
TbProductMissEntity
queryObject
(
String
id
);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List
<
TbProductMissEntity
>
queryList
(
Map
<
String
,
Object
>
map
);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int
queryTotal
(
Map
<
String
,
Object
>
map
);
/**
* 保存实体
*
* @param tbProductMiss 实体
* @return 保存条数
*/
int
save
(
TbProductMissEntity
tbProductMiss
);
/**
* 根据主键更新实体
*
* @param tbProductMiss 实体
* @return 更新条数
*/
int
update
(
TbProductMissEntity
tbProductMiss
);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int
delete
(
String
id
);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int
deleteBatch
(
String
[]
ids
);
}
platform-admin/src/main/java/com/platform/service/impl/TbProductMissServiceImpl.java
0 → 100644
浏览文件 @
e94a2d49
package
com
.
platform
.
service
.
impl
;
import
com.platform.dao.TbProductMissDao
;
import
com.platform.entity.TbProductMissEntity
;
import
com.platform.service.TbProductMissService
;
import
com.platform.utils.IdUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
/**
* 产品导入失败记录表Service实现类
*
* @author lipengjun
* @date 2020-02-01 20:14:20
*/
@Service
(
"tbProductMissService"
)
public
class
TbProductMissServiceImpl
implements
TbProductMissService
{
@Autowired
private
TbProductMissDao
tbProductMissDao
;
@Override
public
TbProductMissEntity
queryObject
(
String
id
)
{
return
tbProductMissDao
.
queryObject
(
id
);
}
@Override
public
List
<
TbProductMissEntity
>
queryList
(
Map
<
String
,
Object
>
map
)
{
return
tbProductMissDao
.
queryList
(
map
);
}
@Override
public
int
queryTotal
(
Map
<
String
,
Object
>
map
)
{
return
tbProductMissDao
.
queryTotal
(
map
);
}
@Override
public
int
save
(
TbProductMissEntity
tbProductMiss
)
{
tbProductMiss
.
setId
(
IdUtil
.
createIdbyUUID
());
return
tbProductMissDao
.
save
(
tbProductMiss
);
}
@Override
public
int
update
(
TbProductMissEntity
tbProductMiss
)
{
return
tbProductMissDao
.
update
(
tbProductMiss
);
}
@Override
public
int
delete
(
String
id
)
{
return
tbProductMissDao
.
delete
(
id
);
}
@Override
public
int
deleteBatch
(
String
[]
ids
)
{
return
tbProductMissDao
.
deleteBatch
(
ids
);
}
}
platform-admin/src/main/java/com/platform/task/ShopifyConstant.java
浏览文件 @
e94a2d49
package
com
.
platform
.
task
;
import
cn.hutool.http.HttpRequest
;
import
com.platform.entity.ItemDescSkus
;
import
com.platform.utils.IdUtil
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
java.util.*
;
/**
* @Auther: wudepeng
* @Date: 2019/11/15
* @Description: Shopify url
* 获取 Shopify 商品信息及其保存商品信息
*
* @author wudepeng
* @author 爱酱油不爱醋
* @date 2019/11/15
* @date 2020/1/22
*/
public
class
ShopifyConstant
{
...
...
@@ -17,12 +27,74 @@ public class ShopifyConstant {
//password
public
static
String
SHOPIFY_PASSWORD
=
"1c97a1222c5b40e0597c816c6dfecac0"
;
//api
public
static
String
SHOPIFY_PRODUCTS_API
=
"/admin/api/2019-10/products.json"
;
//https://7f0e048ac4016b9357bb1eb2217e4201:1c97a1222c5b40e0597c816c6dfecac0@mollykitty.myshopify.com/admin/api/2019-10/products.json?fields=product_type;
public
static
String
SHOPIFY_PRODUCTS_API
=
"/admin/api/2020-01/products.json"
;
public
static
String
countUrl
()
{
return
"https://"
+
SHOPIFY_API_KEY
+
":"
+
SHOPIFY_PASSWORD
+
"@"
+
SHOPIFY_HOSTNAME
+
"/admin/api/2020-01/count.json"
;
}
public
static
String
productId
(
String
productId
)
{
return
"https://"
+
SHOPIFY_API_KEY
+
":"
+
SHOPIFY_PASSWORD
+
"@"
+
SHOPIFY_HOSTNAME
+
"/admin/api/2020-01/products/"
+
productId
+
".json"
;
}
public
static
String
productTypeUrl
()
{
return
"https://"
+
SHOPIFY_API_KEY
+
":"
+
SHOPIFY_PASSWORD
+
"@"
+
SHOPIFY_HOSTNAME
+
SHOPIFY_PRODUCTS_API
;
return
"https://"
+
SHOPIFY_API_KEY
+
":"
+
SHOPIFY_PASSWORD
+
"@"
+
SHOPIFY_HOSTNAME
+
SHOPIFY_PRODUCTS_API
+
"?limit=250"
;
}
public
static
void
main
(
String
[]
args
)
{
String
result
=
HttpRequest
.
get
(
productTypeUrl
())
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
result
);
ItemDescSkus
itemDescSkus
=
new
ItemDescSkus
();
// 取每个数组中的 products 数组节点
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
JSONObject
productsObj
=
productsArr
.
getJSONObject
(
i
);
// 商品的基本属性
String
id
=
productsObj
.
getString
(
"id"
);
String
title
=
productsObj
.
getString
(
"title"
);
String
product_type
=
productsObj
.
getString
(
"product_type"
);
String
handle
=
productsObj
.
getString
(
"handle"
);
String
tags
=
productsObj
.
getString
(
"tags"
);
String
image
=
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
);
String
vendor
=
productsObj
.
getString
(
"vendor"
);
// 商品的规格属性
Map
<
String
,
HashMap
<
String
,
Set
<
String
>>>
optionMap
=
new
HashMap
<>(
3
);
Map
<
String
,
Set
<
String
>>
skuMap
=
new
HashMap
<>(
5
);
JSONArray
optionsArr
=
new
JSONArray
();
for
(
int
j
=
0
;
j
<
optionsArr
.
size
();
j
++)
{
JSONObject
optionsObj
=
optionsArr
.
getJSONObject
(
j
);
String
optionsName
=
optionsObj
.
getString
(
"name"
);
// 商品的属性名
Set
<
String
>
optionsSet
=
new
HashSet
<>();
// 商品的属性集合
JSONArray
optionsValuesArr
=
new
JSONArray
();
for
(
int
k
=
0
;
k
<
optionsValuesArr
.
size
();
k
++)
{
optionsSet
.
add
(
optionsValuesArr
.
getString
(
k
));
}
skuMap
.
put
(
optionsName
,
optionsSet
);
// 保存数据
}
// TODO 商品的价格属性
// 商品的图片集合
List
<
String
>
imagesList
=
new
ArrayList
<>(
5
);
JSONArray
imageArr
=
productsObj
.
getJSONArray
(
"images"
);
for
(
int
j
=
0
;
j
<
imageArr
.
size
();
j
++)
{
imagesList
.
add
(
imageArr
.
getJSONObject
(
j
).
getString
(
"src"
));
// 图片组的图片路径
}
// 商品的基本属性
itemDescSkus
.
setItemId
(
IdUtil
.
createIdbyUUID
());
itemDescSkus
.
setItemCode
(
id
);
itemDescSkus
.
setItemName
(
title
);
itemDescSkus
.
setItemBrief
(
title
);
itemDescSkus
.
setItemCategory
(
product_type
);
itemDescSkus
.
setItemUrl
(
"https://www.afrieshop.com/products/"
+
handle
);
itemDescSkus
.
setItemTags
(
tags
);
itemDescSkus
.
setItemUrl
(
image
);
itemDescSkus
.
setSupplier
(
vendor
);
}
}
}
platform-admin/src/main/resources/com/platform/dao/TbCategoryTemplateDao.xml
浏览文件 @
e94a2d49
...
...
@@ -24,6 +24,19 @@
where id = #{id}
</select>
<select
id=
"queryByDesc"
resultType=
"com.platform.entity.TbCategoryTemplateEntity"
>
select
`id`,
`category_name`,
`category_desc`,
`del_flag`,
`create_time`,
`update_time`
from tb_category_template
where category_desc = #{category_desc}
</select>
<select
id=
"queryList"
resultType=
"com.platform.entity.TbCategoryTemplateEntity"
>
select
`id`,
...
...
platform-admin/src/main/resources/com/platform/dao/TbCfCategoryDao.xml
浏览文件 @
e94a2d49
...
...
@@ -106,18 +106,22 @@
</set>
where category_id = #{categoryId}
</update>
<update
id=
"changStatus"
parameterType=
"com.platform.entity.TbCfCategoryEntity"
>
update tb_cf_category set del_flag=0 where item_id=#{itemId}
</update>
<update
id=
"changStatusBatch"
parameterType=
"com.platform.entity.TbCfCategoryEntity"
>
update tb_cf_category set del_flag=0 where item_id in
<foreach
item=
"itemId"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{itemId}
</foreach>
</update>
<select
id=
"queryByItemId"
resultType=
"com.platform.entity.TbCfCategoryEntity"
>
select * from tb_cf_category where item_id=#{itemId} order by order_num asc
</select>
<delete
id=
"delete"
>
delete from tb_cf_category where category_id = #{value}
</delete>
...
...
@@ -128,6 +132,7 @@
#{categoryId}
</foreach>
</delete>
<delete
id=
"deleteByItemId"
>
delete from tb_cf_category where item_id =#{itemId}
</delete>
...
...
platform-admin/src/main/resources/com/platform/dao/TbCfDescripitonDao.xml
浏览文件 @
e94a2d49
...
...
@@ -27,6 +27,13 @@
from tb_cf_descripiton
where descripition_id = #{id}
</select>
<select
id=
"queryByDescriptionName"
resultType=
"com.platform.entity.TbCfDescripitonEntity"
>
select *
from tb_cf_descripiton
where descripition_name = #{descripition_name}
</select>
<select
id=
"queryByItemTypeTwo"
resultType=
"com.platform.entity.TbCfDescripitonEntity"
>
select
`descripition_id`,
...
...
@@ -124,4 +131,4 @@
#{descripitionId}
</foreach>
</delete>
</mapper>
\ No newline at end of file
</mapper>
platform-admin/src/main/resources/com/platform/dao/TbCfGoodstwotypeDao.xml
浏览文件 @
e94a2d49
...
...
@@ -29,6 +29,14 @@
INNER JOIN tb_cf_goodstype ds ON ds.goodstype_id = tw.goodstype_id
where tw.goodstwotype_id = #{id}
</select>
<select
id=
"queryTitle"
resultType=
"com.platform.entity.TbCfGoodstwotypeEntity"
>
SELECT
*
FROM tb_cf_goodstwotype
where goodstwotype_title = #{title}
</select>
<select
id=
"queryByTypeId"
resultType=
"com.platform.entity.TbCfGoodstwotypeEntity"
>
select
`goodstwotype_id`,
...
...
@@ -38,6 +46,7 @@
from tb_cf_goodstwotype
WHERE goodstype_id= #{id}
</select>
<select
id=
"queryObject"
resultType=
"com.platform.entity.TbCfGoodstwotypeEntity"
>
select
`goodstwotype_id`,
...
...
platform-admin/src/main/resources/com/platform/dao/TbCfGoodstypeDao.xml
浏览文件 @
e94a2d49
...
...
@@ -20,6 +20,16 @@
where goodstype_id = #{id}
</select>
<select
id=
"queryByTitle"
resultType=
"com.platform.entity.TbCfGoodstypeEntity"
>
select
`goodstype_id`,
`goodstype_title`,
`goodstype_sort`,
`goodstype_url`
from tb_cf_goodstype
where goodstype_title = #{title}
</select>
<select
id=
"queryList"
resultType=
"com.platform.entity.TbCfGoodstypeEntity"
>
select
`goodstype_id`,
...
...
platform-admin/src/main/resources/com/platform/dao/TbCfStationItemDao.xml
浏览文件 @
e94a2d49
...
...
@@ -82,6 +82,19 @@
where
i.enable_flag!=0
</select>
<select
id=
"queryByCode"
resultType=
"com.platform.entity.TbCfStationItemEntity"
>
SELECT *
FROM tb_cf_station_item
WHERE item_code = #{code}
</select>
<select
id=
"queryByCodeList"
resultType=
"com.platform.entity.TbCfStationItemEntity"
>
SELECT *
FROM tb_cf_station_item
WHERE item_code = #{code}
</select>
<select
id=
"queryList"
resultType=
"com.platform.entity.TbCfStationItemEntityExtends"
>
SELECT
i.item_id,
...
...
@@ -139,6 +152,7 @@
</if>
</select>
<select
id=
"queryItemInfoById"
resultType=
"com.platform.entity.ItemDescSkus"
>
SELECT
i.*,
...
...
@@ -151,6 +165,7 @@
WHERE
i.item_id = #{itemId}
</select>
<select
id=
"queryTotal"
resultType=
"int"
>
select count(*) from tb_cf_station_item
WHERE 1=1 and enable_flag!=0
...
...
@@ -240,7 +255,6 @@
</update>
<delete
id=
"delete"
>
delete from tb_cf_station_item where item_id = #{value}
</delete>
...
...
platform-admin/src/main/resources/com/platform/dao/TbProductMissDao.xml
0 → 100644
浏览文件 @
e94a2d49
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.platform.dao.TbProductMissDao"
>
<resultMap
type=
"com.platform.entity.TbProductMissEntity"
id=
"tbProductMissMap"
>
<result
property=
"id"
column=
"id"
/>
<result
property=
"productId"
column=
"product_id"
/>
<result
property=
"missType"
column=
"miss_type"
/>
<result
property=
"pageSize"
column=
"page_size"
/>
<result
property=
"createTime"
column=
"create_time"
/>
</resultMap>
<select
id=
"queryObject"
resultType=
"com.platform.entity.TbProductMissEntity"
>
select
`id`,
`product_id`,
`miss_type`,
`page_size`,
`create_time`
from tb_product_miss
where id = #{id}
</select>
<select
id=
"queryList"
resultType=
"com.platform.entity.TbProductMissEntity"
>
select
`id`,
`product_id`,
`miss_type`,
`page_size`,
`create_time`
from tb_product_miss
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when
test=
"sidx != null and sidx.trim() != ''"
>
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if
test=
"offset != null and limit != null"
>
limit #{offset}, #{limit}
</if>
</select>
<select
id=
"queryTotal"
resultType=
"int"
>
select count(*) from tb_product_miss
WHERE 1=1
<if
test=
"name != null and name.trim() != ''"
>
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert
id=
"save"
parameterType=
"com.platform.entity.TbProductMissEntity"
>
insert into tb_product_miss(
`id`,
`product_id`,
`miss_type`,
`page_size`,
`create_time`)
values(
#{id},
#{productId},
#{missType},
#{pageSize},
#{createTime})
</insert>
<update
id=
"update"
parameterType=
"com.platform.entity.TbProductMissEntity"
>
update tb_product_miss
<set>
<if
test=
"productId != null"
>
`product_id` = #{productId},
</if>
<if
test=
"missType != null"
>
`miss_type` = #{missType},
</if>
<if
test=
"pageSize != null"
>
`page_size` = #{pageSize},
</if>
<if
test=
"createTime != null"
>
`create_time` = #{createTime}
</if>
</set>
where id = #{id}
</update>
<delete
id=
"deleteByCode"
>
delete from tb_product_miss where product_id = #{productId};
</delete>
<delete
id=
"deleteBatch"
>
delete from tb_product_miss where id in
<foreach
item=
"id"
collection=
"array"
open=
"("
separator=
","
close=
")"
>
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
platform-admin/src/main/test/java/test/TestApi.java
0 → 100644
浏览文件 @
e94a2d49
package
test
;
import
cn.hutool.core.lang.Console
;
import
cn.hutool.core.util.IdUtil
;
import
cn.hutool.http.HttpRequest
;
import
com.platform.controller.api.ProductExitException
;
import
com.platform.dao.*
;
import
com.platform.entity.*
;
import
com.platform.utils.OssUtil
;
import
com.platform.utils.R
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Arrays
;
import
java.util.Date
;
/**
* @author 爱酱油不爱醋
* @version 1.0
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@ContextConfiguration
(
locations
=
{
"classpath*:/applicationContext-test.xml"
})
public
class
TestApi
{
@Autowired
private
TbCfStationItemDao
tbCfStationItemDao
;
@Autowired
private
TbCfItemDescDao
tbCfItemDescDao
;
@Autowired
private
TbCfItemSkusDao
tbCfItemSkusDao
;
@Autowired
private
TbCfCategoryDao
tbCfCategoryDao
;
@Autowired
private
TbCfOptionDao
tbCfOptionDao
;
@Autowired
private
TbCfGoodstypeDao
tbCfGoodstypeDao
;
@Autowired
private
TbProductMissDao
tbProductMissDao
;
@Autowired
private
TbCategoryTemplateDao
tbCategoryTemplateDao
;
@Autowired
private
TbCfGoodstwotypeDao
tbCfGoodstwotypeDao
;
@Autowired
private
TbCfDescripitonDao
tbCfDescripitonDao
;
@Test
public
void
host
()
{
String
link
=
"https://mollykitty.myshopify.com/admin/api/2019-10/products.json?limit=250&page_info=eyJwcm9kdWN0X3R5cGUiOiJXb21lbiIsImxhc3RfaWQiOjQ0OTc2Nzg5NTg2ODksImxhc3RfdmFsdWUiOiJDYXN1YWwgU2xpbSBTd2VhdGVycyIsImRpcmVjdGlvbiI6Im5leHQifQ"
;
Console
.
error
(
link
);
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
header
(
"link"
)
.
split
(
","
)[
1
];
Console
.
error
(
link
);
link
=
link
.
substring
(
2
,
link
.
indexOf
(
">"
));
Console
.
log
(
"链接:"
+
link
);
}
@Test
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=戴菊"
;
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
json
=
JSONObject
.
fromObject
(
link
);
JSONObject
product
=
json
.
getJSONArray
(
"products"
).
getJSONObject
(
0
);
String
tags
=
product
.
getString
(
"tags"
);
String
[]
s
=
tags
.
split
(
","
);
Console
.
error
(
Arrays
.
toString
(
s
));
for
(
String
i
:
s
)
{
if
(
i
.
indexOf
(
"#"
)
==
0
)
{
System
.
out
.
println
(
i
);
}
}
}
@Test
public
void
save
()
{
// 记录页数的
int
pageSize
=
0
;
int
productCount
=
0
;
// 初始页
String
link
=
"https://mollykitty.myshopify.com/admin/api/2020-01/products.json?limit=250&page_info=eyJsYXN0X2lkIjo0NDQzNjE1MDAyNzIxLCJsYXN0X3ZhbHVlIjoiQW5kcm9pZCBwaG9uZSBkYXRhIGNhYmxlIiwiZGlyZWN0aW9uIjoibmV4dCJ9"
;
// 循环翻页
while
(
true
)
{
Console
.
error
(
"当前的页数为:"
+
pageSize
);
// 这个请求需要密钥,可以先拿着账号密码去浏览器请求一遍,F12 获取 token 复制粘贴即可
String
result
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
result
);
// 取每个数组中的 products 数组节点
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
JSONObject
productsObj
=
productsArr
.
getJSONObject
(
i
);
Console
.
log
(
"当前正在导入的商品个数为:"
+
productCount
);
productCount
++;
// 商品主体信息的商品 id
String
itemId
=
IdUtil
.
simpleUUID
();
// 复用的日期
Date
date
=
new
Date
();
// 商品的平台 id
String
id
=
productsObj
.
getString
(
"id"
);
try
{
// 查询该商品的 id 是否已保存
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
// 继续循环
continue
;
}
// 用于记录 option 的属性名
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
);
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
String
optionId
=
optionObj
.
getString
(
"id"
);
categoryEntity
.
setCategoryId
(
optionId
);
categoryEntity
.
setCreateTime
(
date
);
categoryEntity
.
setUpdateTime
(
date
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setItemId
(
itemId
);
String
optionName
=
optionObj
.
getString
(
"name"
);
categoryEntity
.
setCategoryName
(
optionName
);
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
);
}
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
// 保存商品的变体数据
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
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
{
three
=
str
;
}
}
// 保存二级分类名
String
goodsTwoId
=
IdUtil
.
simpleUUID
();
// 商品二级分类id
if
(
tbCfGoodstwotypeDao
.
queryTitle
(
tags
)
==
null
)
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
new
TbCfGoodstwotypeEntity
();
tbCfGoodstwotypeEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfGoodstwotypeEntity
.
setGoodstwotypeTitle
(
tags
);
tbCfGoodstwotypeEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfGoodstwotypeDao
.
save
(
tbCfGoodstwotypeEntity
);
}
else
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
tbCfGoodstwotypeDao
.
queryTitle
(
tags
);
goodsTwoId
=
tbCfGoodstwotypeEntity
.
getGoodstwotypeId
();
}
// 保存三级分类名(品名)
String
goodsThreeId
=
IdUtil
.
simpleUUID
();
// 商品三级分类id
if
(
tbCfDescripitonDao
.
queryByDescriptionName
(
three
)
==
null
)
{
TbCfDescripitonEntity
tbCfDescripitonEntity
=
new
TbCfDescripitonEntity
();
tbCfDescripitonEntity
.
setDescripitionId
(
goodsThreeId
);
tbCfDescripitonEntity
.
setDescripitionName
(
three
);
tbCfDescripitonEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfDescripitonEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfDescripitonDao
.
save
(
tbCfDescripitonEntity
);
}
else
{
TbCfDescripitonEntity
tbCfDescripitonEntity
=
tbCfDescripitonDao
.
queryByDescriptionName
(
three
);
goodsThreeId
=
tbCfDescripitonEntity
.
getDescripitionId
();
}
// 保存商品的主体信息
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"
);
tbCfStationItem
.
setItemImg
(
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
));
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
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
.
append
(
imageObj
.
getString
(
"src"
)).
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
);
}
}
// 循环翻页
link
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
header
(
"link"
)
.
split
(
","
)[
1
];
Console
.
error
(
link
);
link
=
link
.
substring
(
2
,
link
.
indexOf
(
">"
));
// 记录页数
pageSize
++;
}
}
@Test
public
void
onLoop
()
{
// 记录页数的
int
pageSize
=
0
;
int
productCount
=
0
;
// 初始页
String
link
=
"https://mollykitty.myshopify.com/admin/api/2019-10/products.json?limit=150&vendor=戴菊"
;
// 这个请求需要密钥,可以先拿着账号密码去浏览器请求一遍,F12 获取 token 复制粘贴即可
String
result
=
HttpRequest
.
get
(
link
)
.
header
(
"Authorization"
,
"Basic N2YwZTA0OGFjNDAxNmI5MzU3YmIxZWIyMjE3ZTQyMDE6MWM5N2ExMjIyYzViNDBlMDU5N2M4MTZjNmRmZWNhYzA="
)
.
execute
().
body
();
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
result
);
// 取每个数组中的 products 数组节点
JSONArray
productsArr
=
jsonObject
.
getJSONArray
(
"products"
);
for
(
int
i
=
0
;
i
<
productsArr
.
size
();
i
++)
{
JSONObject
productsObj
=
productsArr
.
getJSONObject
(
i
);
Console
.
log
(
"当前正在导入的商品个数为:"
+
productCount
);
productCount
++;
// 商品主体信息的商品 id
String
itemId
=
IdUtil
.
simpleUUID
();
// 复用的日期
Date
date
=
new
Date
();
// 商品的平台 id
String
id
=
productsObj
.
getString
(
"id"
);
try
{
// 查询该商品的 id 是否已保存
if
(
tbCfStationItemDao
.
queryByCode
(
id
)
!=
null
)
{
// 记录失败的产品记录
throw
new
ProductExitException
();
}
// 用于记录 option 的属性名
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
);
TbCfCategoryEntity
categoryEntity
=
new
TbCfCategoryEntity
();
String
optionId
=
optionObj
.
getString
(
"id"
);
categoryEntity
.
setCategoryId
(
optionId
);
categoryEntity
.
setCreateTime
(
date
);
categoryEntity
.
setUpdateTime
(
date
);
categoryEntity
.
setDelFlag
(
1
);
categoryEntity
.
setItemId
(
itemId
);
String
optionName
=
optionObj
.
getString
(
"name"
);
categoryEntity
.
setCategoryName
(
optionName
);
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
);
}
TbCfStationItemEntity
tbCfStationItem
=
new
TbCfStationItemEntity
();
// 商品主体信息实体类
// 保存商品的变体数据
JSONArray
variantsArr
=
productsObj
.
getJSONArray
(
"variants"
);
for
(
int
j
=
0
;
j
<
variantsArr
.
size
();
j
++)
{
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
{
three
=
str
;
}
}
// 保存二级分类名
String
goodsTwoId
=
IdUtil
.
simpleUUID
();
// 商品二级分类id
if
(
tbCfGoodstwotypeDao
.
queryTitle
(
tags
)
==
null
)
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
new
TbCfGoodstwotypeEntity
();
tbCfGoodstwotypeEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfGoodstwotypeEntity
.
setGoodstwotypeTitle
(
tags
);
tbCfGoodstwotypeEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfGoodstwotypeDao
.
save
(
tbCfGoodstwotypeEntity
);
}
else
{
TbCfGoodstwotypeEntity
tbCfGoodstwotypeEntity
=
tbCfGoodstwotypeDao
.
queryTitle
(
tags
);
goodsTwoId
=
tbCfGoodstwotypeEntity
.
getGoodstwotypeId
();
}
// 保存三级分类名(品名)
String
goodsThreeId
=
IdUtil
.
simpleUUID
();
// 商品三级分类id
if
(
tbCfDescripitonDao
.
queryByDescriptionName
(
three
)
==
null
)
{
TbCfDescripitonEntity
tbCfDescripitonEntity
=
new
TbCfDescripitonEntity
();
tbCfDescripitonEntity
.
setDescripitionId
(
goodsThreeId
);
tbCfDescripitonEntity
.
setDescripitionName
(
three
);
tbCfDescripitonEntity
.
setGoodstypeId
(
goods_type_id
);
tbCfDescripitonEntity
.
setGoodstwotypeId
(
goodsTwoId
);
tbCfDescripitonDao
.
save
(
tbCfDescripitonEntity
);
}
else
{
TbCfDescripitonEntity
tbCfDescripitonEntity
=
tbCfDescripitonDao
.
queryByDescriptionName
(
three
);
goodsThreeId
=
tbCfDescripitonEntity
.
getDescripitionId
();
}
// 保存商品的主体信息
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"
);
tbCfStationItem
.
setItemImg
(
productsObj
.
getJSONObject
(
"image"
).
getString
(
"src"
));
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
);
// 拼接富文本的 HTML
imageBuilder
.
append
(
"<p><img src=\""
)
.
append
(
imageObj
.
getString
(
"src"
)).
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
(
ProductExitException
e
)
{
Console
.
error
(
"该商品已存在"
);
// 记录已存在的商品
TbProductMissEntity
tbProductMissEntity
=
new
TbProductMissEntity
();
tbProductMissEntity
.
setId
(
IdUtil
.
simpleUUID
());
tbProductMissEntity
.
setProductId
(
id
);
tbProductMissEntity
.
setMissType
(
1
);
tbProductMissEntity
.
setPageSize
(
pageSize
);
tbProductMissEntity
.
setCreateTime
(
new
Date
());
tbProductMissDao
.
save
(
tbProductMissEntity
);
}
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
);
}
}
}
/**
* 通过URL获取网络图片
* 获取网络图片流
*
* @param url 传入的 URL 必须是以 http:// 开头的,因为我们使用了 HttpURLConnection
* @return 输入流
*/
public
static
InputStream
getImageStream
(
String
url
)
{
try
{
HttpURLConnection
connection
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
connection
.
setReadTimeout
(
5000
);
connection
.
setConnectTimeout
(
5000
);
connection
.
setRequestMethod
(
"GET"
);
if
(
connection
.
getResponseCode
()
==
HttpURLConnection
.
HTTP_OK
)
{
return
connection
.
getInputStream
();
}
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"获取网络图片出现异常,图片路径为:"
+
url
);
e
.
printStackTrace
();
}
return
null
;
}
/**
* 将 InputStream 流转换为 byte[]
*
* @param input InputStream
* @return byte[]
* @throws IOException IO流异常
*/
public
static
byte
[]
toByteArray
(
InputStream
input
)
throws
IOException
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
byte
[]
buffer
=
new
byte
[
1024
*
4
];
int
n
=
0
;
while
(-
1
!=
(
n
=
input
.
read
(
buffer
)))
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
String
link
=
"https://cdn.shopify.com/s/files/1/0079/8330/0705/products/0_-9_aee971dc-5661-46bb-9d7e-11f0a3ee5b35.jpg?v=1580133539"
;
InputStream
inputStream
=
getImageStream
(
link
);
byte
[]
bytes
=
toByteArray
(
inputStream
);
String
url
=
OssUtil
.
upload
(
bytes
,
IdUtil
.
simpleUUID
()
+
".jpg"
,
"zion"
);
System
.
out
.
println
(
url
);
}
}
platform-admin/src/main/test/resource/applicationContext-test.xml
0 → 100644
浏览文件 @
e94a2d49
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns=
"http://www.springframework.org/schema/beans"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:context=
"http://www.springframework.org/schema/context"
xmlns:tx=
"http://www.springframework.org/schema/tx"
xmlns:aop=
"http://www.springframework.org/schema/aop"
xmlns:mvc=
"http://www.springframework.org/schema/mvc"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"
>
<context:component-scan
base-package=
"com.platform.dao,com.platform.service"
>
<!--过滤定时任务service-->
<context:exclude-filter
type=
"regex"
expression=
"com.platform.service.impl.ScheduleJobServiceImpl"
/>
</context:component-scan>
<context:property-placeholder
location=
"classpath:platform.properties"
/>
<context:annotation-config/>
<mvc:default-servlet-handler/>
<aop:aspectj-autoproxy
proxy-target-class=
"true"
/>
<mvc:annotation-driven>
<mvc:message-converters
register-defaults=
"true"
>
<bean
class=
"com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter"
>
<property
name=
"supportedMediaTypes"
>
<list>
<value>
text/html;charset=UTF-8
</value>
<value>
application/json;charset=UTF-8
</value>
</list>
</property>
<property
name=
"features"
>
<list>
<value>
WriteMapNullValue
</value>
<value>
QuoteFieldNames
</value>
<value>
WriteDateUseDateFormat
</value>
<!-- 禁用fastjson循环引用检测 -->
<value>
DisableCircularReferenceDetect
</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<tx:annotation-driven/>
<bean
id=
"dataSource"
class=
"com.alibaba.druid.pool.DruidDataSource"
init-method=
"init"
destroy-method=
"close"
>
<property
name=
"url"
>
<value>
${jdbc.url}
</value>
</property>
<property
name=
"username"
>
<value>
${jdbc.username}
</value>
</property>
<property
name=
"password"
>
<value>
${jdbc.password}
</value>
</property>
<property
name=
"initialSize"
>
<value>
${jdbc.initialSize}
</value>
</property>
<property
name=
"maxActive"
>
<value>
${jdbc.maxActive}
</value>
</property>
<property
name=
"proxyFilters"
>
<list>
<ref
bean=
"stat-filter"
/>
<!--过滤永真条件 防止注入-->
<ref
bean=
"wall-filter"
/>
</list>
</property>
<property
name=
"connectionInitSqls"
value=
"set names utf8mb4;"
/>
</bean>
<bean
id=
"stat-filter"
class=
"com.alibaba.druid.filter.stat.StatFilter"
>
<property
name=
"slowSqlMillis"
value=
"1000"
/>
<property
name=
"logSlowSql"
value=
"true"
/>
<property
name=
"mergeSql"
value=
"true"
/>
</bean>
<bean
id=
"wall-filter"
class=
"com.alibaba.druid.wall.WallFilter"
>
<property
name=
"dbType"
value=
"mysql"
/>
<property
name=
"config"
ref=
"wall-filter-config"
/>
</bean>
<bean
id=
"wall-filter-config"
class=
"com.alibaba.druid.wall.WallConfig"
>
<property
name=
"multiStatementAllow"
value=
"true"
/>
</bean>
<bean
id=
"druid-stat-interceptor"
class=
"com.alibaba.druid.support.spring.stat.DruidStatInterceptor"
></bean>
<bean
id=
"druid-stat-pointcut"
class=
"org.springframework.aop.support.JdkRegexpMethodPointcut"
scope=
"prototype"
>
<property
name=
"patterns"
>
<list>
<value>
com.platform.service.*
</value>
</list>
</property>
</bean>
<aop:config>
<aop:advisor
advice-ref=
"druid-stat-interceptor"
pointcut-ref=
"druid-stat-pointcut"
/>
</aop:config>
<!-- 配置事务管理器 -->
<bean
id=
"transactionManager"
class=
"org.springframework.jdbc.datasource.DataSourceTransactionManager"
>
<property
name=
"dataSource"
ref=
"dataSource"
></property>
</bean>
<bean
id=
"jdbcTemplate"
class=
"org.springframework.jdbc.core.JdbcTemplate"
>
<property
name=
"dataSource"
>
<ref
bean=
"dataSource"
/>
</property>
</bean>
<!-- JDBC配置 -->
<bean
id=
"namedParameterJdbcTemplate"
class=
"org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate"
>
<constructor-arg
ref=
"dataSource"
/>
</bean>
<bean
id=
"sqlSessionFactory"
class=
"org.mybatis.spring.SqlSessionFactoryBean"
>
<property
name=
"configLocation"
value=
"classpath:mybatis.xml"
/>
<property
name=
"dataSource"
ref=
"dataSource"
/>
</bean>
<bean
class=
"org.mybatis.spring.mapper.MapperScannerConfigurer"
>
<property
name=
"basePackage"
value=
"com.platform.dao,com.platform.*.dao"
/>
</bean>
</beans>
platform-admin/src/main/test/resource/log4j.properties
0 → 100644
浏览文件 @
e94a2d49
log4j.rootLogger
=
INFO,stdout,info,warn,error,file
#控制台输出
log4j.appender.stdout
=
org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target
=
System.out
log4j.appender.stdout.Threshold
=
INFO
log4j.appender.stdout.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#INFO所有日志
log4j.logger.file
=
info
log4j.appender.file
=
org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File
=
../logs/info.log
log4j.appender.file.datePattern
=
'.'yyyy-MM-dd'.log'
log4j.appender.file.append
=
true
log4j.appender.file.Threshold
=
INFO
log4j.appender.file.encoding
=
UTF-8
log4j.appender.file.ImmediateFlush
=
true
log4j.appender.file.layout
=
org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#INFO日志
log4j.logger.info
=
info
log4j.appender.info
=
com.platform.log4j.GradeLogDailyRollingFileAppender
log4j.appender.info.File
=
../logs/info/info.log
log4j.appender.info.datePattern
=
'.'yyyy-MM-dd'.log'
log4j.appender.info.append
=
true
log4j.appender.info.Threshold
=
INFO
log4j.appender.info.encoding
=
UTF-8
log4j.appender.info.ImmediateFlush
=
true
log4j.appender.info.layout
=
org.apache.log4j.PatternLayout
log4j.appender.info.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#WARN日志
log4j.appender.warn
=
com.platform.log4j.GradeLogDailyRollingFileAppender
log4j.appender.warn.File
=
../logs/warn/warn.log
log4j.appender.warn.datePattern
=
'.'yyyy-MM-dd'.log'
log4j.appender.warn.append
=
true
log4j.appender.warn.Threshold
=
WARN
log4j.appender.warn.encoding
=
UTF-8
log4j.appender.warn.ImmediateFlush
=
true
log4j.appender.warn.layout
=
org.apache.log4j.PatternLayout
log4j.appender.warn.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#ERROR日志
log4j.appender.error
=
com.platform.log4j.GradeLogDailyRollingFileAppender
log4j.appender.error.File
=
../logs/error/error.log
log4j.appender.error.datePattern
=
'.'yyyy-MM-dd'.log'
log4j.appender.error.append
=
true
log4j.appender.error.Threshold
=
ERROR
log4j.appender.error.encoding
=
UTF-8
log4j.appender.error.ImmediateFlush
=
true
log4j.appender.error.layout
=
org.apache.log4j.PatternLayout
log4j.appender.error.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss SSS}|%5p|%F.%M:%L|%m%n
#执行慢的SQL
log4j.logger.com.alibaba.druid.filter.stat.StatFilter
=
ERROR,slowsql
log4j.appender.slowsql
=
org.apache.log4j.DailyRollingFileAppender
log4j.appender.slowsql.File
=
../logs/slow_sql/slow_sql.log
log4j.appender.slowsql.datePattern
=
'.'yyyy-MM-dd'.log'
log4j.appender.slowsql.append
=
true
log4j.appender.slowsql.encoding
=
UTF-8
log4j.appender.slowsql.ImmediateFlush
=
true
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
#控制台输出所有SQL
#便于调试 生产环境注释
log4j.logger.com.platform.dao
=
DEBUG,sql
log4j.appender.sql
=
org.apache.log4j.ConsoleAppender
log4j.appender.sql.Target
=
System.out
log4j.appender.sql.layout
=
org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern
=
%m %n
platform-admin/src/main/test/resource/platform.properties
0 → 100644
浏览文件 @
e94a2d49
#jdbc.url=jdbc:mysql://localhost:3306/chinafrica?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8
#jdbc.username=root
#jdbc.password=root
jdbc.url
=
jdbc:mysql://47.106.242.175:3306/chinafrica?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8
jdbc.username
=
root
jdbc.password
=
diaoyun666
#jdbc.url: jdbc:mysql://159.138.48.71:3306/chinafrica?useUnicode=true&characterEncoding=UTF-8&rewriteBatchedStatements=true&autoReconnect=true&failOverReadOnly=false&zeroDateTimeBehavior=convertToNull&useSSL=false
#jdbc.username: root
#jdbc.password: Diaoyunnuli.8
jdbc.initialSize
=
5
jdbc.maxActive
=
30
jdbc.minPoolSize
=
2
jdbc.maxIdleTime
=
30000
jdbc.idleConnectionTestPeriod
=
100
pom.xml
浏览文件 @
e94a2d49
...
...
@@ -291,6 +291,11 @@
<artifactId>
jgroups
</artifactId>
<version>
${jgroups.version}
</version>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.1.1
</version>
</dependency>
</dependencies>
<build>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论