Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
13e31a98
提交
13e31a98
authored
11月 20, 2019
作者:
zgy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
为shopify的所有商品添加到缓存中
上级
1c3e0710
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
53 行增加
和
14 行删除
+53
-14
KeyConstant.java
...ava/com/diaoyun/zion/chinafrica/constant/KeyConstant.java
+7
-1
ShopifyServiceImpl.java
...oyun/zion/chinafrica/service/impl/ShopifyServiceImpl.java
+35
-12
ShopifyConstant.java
.../java/com/diaoyun/zion/chinafrica/vo/ShopifyConstant.java
+1
-1
PayTest.java
src/test/java/com/diaoyun/zion/PayTest.java
+10
-0
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/constant/KeyConstant.java
浏览文件 @
13e31a98
...
@@ -28,6 +28,12 @@ public class KeyConstant {
...
@@ -28,6 +28,12 @@ public class KeyConstant {
public
final
static
String
CAPTCHA_PHONE
=
"captcha_phone"
;
public
final
static
String
CAPTCHA_PHONE
=
"captcha_phone"
;
//自定义id头部
//自定义id头部
public
final
static
String
CUSTOMIZE_ID
=
"customizeId_"
;
public
final
static
String
CUSTOMIZE_ID
=
"customizeId_"
;
//shopify商品
//首页商品
public
final
static
String
SHOPIFY_ITEMS
=
"shopify_items"
;
//分类商品
public
final
static
String
SHOPIFY_TYPE_ITEMS
=
"shopify_type_items"
;
//商品详情
public
final
static
String
SHOPIFY_ITEM
=
"shopify_item"
;
public
final
static
String
SHOPIFY_ITEM
=
"shopify_item"
;
//商品类型
public
final
static
String
SHOPIFY_TYPE
=
"shopify_item"
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/impl/ShopifyServiceImpl.java
浏览文件 @
13e31a98
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
import
com.diaoyun.zion.chinafrica.constant.KeyConstant
;
import
com.diaoyun.zion.chinafrica.service.ShopifyService
;
import
com.diaoyun.zion.chinafrica.service.ShopifyService
;
import
com.diaoyun.zion.chinafrica.vo.ShopifyConstant
;
import
com.diaoyun.zion.chinafrica.vo.ShopifyConstant
;
import
com.diaoyun.zion.master.base.Result
;
import
com.diaoyun.zion.master.base.Result
;
...
@@ -34,7 +35,7 @@ import java.util.Map;
...
@@ -34,7 +35,7 @@ import java.util.Map;
public
class
ShopifyServiceImpl
implements
ShopifyService
{
public
class
ShopifyServiceImpl
implements
ShopifyService
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ShopifyServiceImpl
.
class
);
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ShopifyServiceImpl
.
class
);
@Resource
@Resource
private
RedisCache
<
Object
>
orderR
edisCache
;
private
RedisCache
<
Object
>
r
edisCache
;
/**
/**
* 查询商品
* 查询商品
...
@@ -47,12 +48,22 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -47,12 +48,22 @@ public class ShopifyServiceImpl implements ShopifyService {
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
List
<
String
>
list
=
new
ArrayList
();
List
<
String
>
list
=
new
ArrayList
();
try
{
try
{
List
type
=
getProductType
();
List
products
=
(
List
)
redisCache
.
get
(
KeyConstant
.
SHOPIFY_ITEMS
);
if
(
products
!=
null
)
{
JSONArray
jsonArray
=
JSONArray
.
fromObject
(
products
);
result
.
setData
(
jsonArray
);
return
result
;
}
List
type
=
(
List
)
redisCache
.
get
(
KeyConstant
.
SHOPIFY_TYPE
);
if
(
type
==
null
)
{
type
=
getProductType
();
}
for
(
int
i
=
0
;
i
<
type
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
type
.
size
();
i
++)
{
params
.
put
(
"product_type"
,
type
.
get
(
i
));
params
.
put
(
"product_type"
,
type
.
get
(
i
));
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_LIMIT
);
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_LIMIT
);
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
list
.
add
(
data
);
list
.
add
(
data
);
redisCache
.
set
(
KeyConstant
.
SHOPIFY_ITEMS
,
list
);
}
}
JSONArray
jsonArr
=
JSONArray
.
fromObject
(
list
);
JSONArray
jsonArr
=
JSONArray
.
fromObject
(
list
);
result
.
setData
(
jsonArr
).
setMessage
(
"success"
);
result
.
setData
(
jsonArr
).
setMessage
(
"success"
);
...
@@ -73,6 +84,12 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -73,6 +84,12 @@ public class ShopifyServiceImpl implements ShopifyService {
@Override
@Override
public
Result
queryProductsByType
(
String
product_type
,
String
product_id
)
{
public
Result
queryProductsByType
(
String
product_type
,
String
product_id
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
String
typeProducts
=
(
String
)
redisCache
.
get
(
KeyConstant
.
SHOPIFY_TYPE_ITEMS
+
product_id
);
if
(
typeProducts
!=
null
)
{
JSONObject
object
=
JSONObject
.
fromObject
(
typeProducts
);
result
.
setData
(
object
);
return
result
;
}
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"product_type"
,
product_type
);
params
.
put
(
"product_type"
,
product_type
);
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_PAGE_SIZE
);
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_PAGE_SIZE
);
...
@@ -80,8 +97,8 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -80,8 +97,8 @@ public class ShopifyServiceImpl implements ShopifyService {
try
{
try
{
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
System
.
out
.
println
(
jsonObject
);
result
.
setData
(
jsonObject
);
result
.
setData
(
jsonObject
);
redisCache
.
set
(
KeyConstant
.
SHOPIFY_TYPE_ITEMS
+
product_id
,
data
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
result
.
setCode
(
ResultCodeEnum
.
QUERY_ERROR
.
getCode
()).
setMessage
(
e
.
getMessage
());
result
.
setCode
(
ResultCodeEnum
.
QUERY_ERROR
.
getCode
()).
setMessage
(
e
.
getMessage
());
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
@@ -99,13 +116,19 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -99,13 +116,19 @@ public class ShopifyServiceImpl implements ShopifyService {
@Override
@Override
public
Result
queryProductsDetails
(
String
product_id
)
{
public
Result
queryProductsDetails
(
String
product_id
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
JSONObject
jsonProduct
=
null
;
params
.
put
(
"ids"
,
product_id
);
try
{
try
{
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
String
product
=
(
String
)
redisCache
.
get
(
KeyConstant
.
SHOPIFY_ITEM
+
product_id
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
if
(
product
!=
null
)
{
System
.
out
.
println
(
jsonObject
);
jsonProduct
=
JSONObject
.
fromObject
(
product
);
result
.
setData
(
jsonObject
);
}
else
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"ids"
,
product_id
);
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
jsonProduct
=
JSONObject
.
fromObject
(
data
);
redisCache
.
set
(
KeyConstant
.
SHOPIFY_ITEM
+
product_id
,
data
);
}
result
.
setData
(
jsonProduct
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
result
.
setCode
(
ResultCodeEnum
.
QUERY_ERROR
.
getCode
()).
setMessage
(
e
.
getMessage
());
result
.
setCode
(
ResultCodeEnum
.
QUERY_ERROR
.
getCode
()).
setMessage
(
e
.
getMessage
());
logger
.
error
(
e
.
getMessage
(),
e
);
logger
.
error
(
e
.
getMessage
(),
e
);
...
@@ -127,13 +150,13 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -127,13 +150,13 @@ public class ShopifyServiceImpl implements ShopifyService {
List
list
=
new
ArrayList
();
List
list
=
new
ArrayList
();
JSONArray
products
=
JSONObject
.
fromObject
(
connection
).
getJSONArray
(
"products"
);
JSONArray
products
=
JSONObject
.
fromObject
(
connection
).
getJSONArray
(
"products"
);
for
(
int
i
=
0
;
i
<
products
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
products
.
size
();
i
++)
{
String
string
=
products
.
getString
(
i
);
String
product_type
=
products
.
getJSONObject
(
i
).
getString
(
"product_type"
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
string
);
String
product_type
=
jsonObject
.
getString
(
"product_type"
);
if
(!
""
.
equals
(
product_type
)
&&
!
list
.
contains
(
product_type
))
{
if
(!
""
.
equals
(
product_type
)
&&
!
list
.
contains
(
product_type
))
{
list
.
add
(
product_type
);
list
.
add
(
product_type
);
}
}
}
}
//将商品类型放到缓存中
redisCache
.
set
(
KeyConstant
.
SHOPIFY_TYPE
,
list
);
return
list
;
return
list
;
}
}
}
}
src/main/java/com/diaoyun/zion/chinafrica/vo/ShopifyConstant.java
浏览文件 @
13e31a98
package
com
.
diaoyun
.
zion
.
chinafrica
.
vo
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
vo
;
import
io.swagger.models.auth.In
;
/**
/**
* @Auther: wudepeng
* @Auther: wudepeng
...
@@ -20,6 +19,7 @@ public class ShopifyConstant {
...
@@ -20,6 +19,7 @@ public class ShopifyConstant {
public
static
String
SHOPIFY_PASSWORD
=
"1c97a1222c5b40e0597c816c6dfecac0"
;
public
static
String
SHOPIFY_PASSWORD
=
"1c97a1222c5b40e0597c816c6dfecac0"
;
//api
//api
public
static
String
SHOPIFY_PRODUCTS_API
=
"/admin/api/2019-10/products.json"
;
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;
//https://7f0e048ac4016b9357bb1eb2217e4201:1c97a1222c5b40e0597c816c6dfecac0@mollykitty.myshopify.com/admin/api/2019-10/products.json?fields=product_type;
public
static
String
productTypeUrl
()
{
public
static
String
productTypeUrl
()
{
...
...
src/test/java/com/diaoyun/zion/PayTest.java
浏览文件 @
13e31a98
...
@@ -7,6 +7,7 @@ import com.diaoyun.zion.master.enums.ResultCodeEnum;
...
@@ -7,6 +7,7 @@ import com.diaoyun.zion.master.enums.ResultCodeEnum;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.github.pagehelper.PageInfo
;
import
com.github.pagehelper.PageInfo
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonArray
;
import
io.swagger.models.auth.In
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
net.sf.json.JSONObject
;
import
org.junit.Test
;
import
org.junit.Test
;
...
@@ -81,4 +82,13 @@ public class PayTest {
...
@@ -81,4 +82,13 @@ public class PayTest {
}
}
}
}
@Test
public
void
test3
(){
Integer
count
=
0
;
while
(
count
<
4
){
System
.
out
.
println
(
"helloworld!"
);
count
++;
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论