Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
Z
zion
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
zhengfg
zion
Commits
9d17852f
提交
9d17852f
authored
12月 03, 2019
作者:
zgy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
完成shopify商品分页
上级
830bc294
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
114 行增加
和
12 行删除
+114
-12
ShopifyController.java
...diaoyun/zion/chinafrica/controller/ShopifyController.java
+6
-5
ProductPageInfo.java
...a/com/diaoyun/zion/chinafrica/entity/ProductPageInfo.java
+38
-0
ShopifyService.java
...a/com/diaoyun/zion/chinafrica/service/ShopifyService.java
+1
-1
ShopifyServiceImpl.java
...oyun/zion/chinafrica/service/impl/ShopifyServiceImpl.java
+33
-6
HttpClientUtil.java
...ain/java/com/diaoyun/zion/master/util/HttpClientUtil.java
+36
-0
没有找到文件。
src/main/java/com/diaoyun/zion/chinafrica/controller/ShopifyController.java
浏览文件 @
9d17852f
...
@@ -45,19 +45,20 @@ public class ShopifyController {
...
@@ -45,19 +45,20 @@ public class ShopifyController {
/**
/**
* 查询分类商品
* 查询分类商品
*
*
* @param product_type
商品分类
* @param product_type
* @param p
roduct_id 商品ID
* @param p
age_info
* @return
* @return
*/
*/
@ApiOperation
(
value
=
"查询分类商品"
)
@ApiOperation
(
value
=
"查询分类商品"
)
@GetMapping
(
"/queryproductsbytype"
)
@GetMapping
(
"/queryproductsbytype"
)
public
Result
queryProductsByType
(
@ApiParam
(
"商品分类"
)
@RequestParam
(
"product_type"
)
String
product_type
,
public
Result
queryProductsByType
(
@ApiParam
(
"商品分类"
)
@RequestParam
(
value
=
"product_type"
,
required
=
false
)
String
product_type
,
@ApiParam
(
"商品ID"
)
@RequestParam
(
value
=
"p
roduct_id"
,
required
=
false
)
String
product_id
@ApiParam
(
"商品ID"
)
@RequestParam
(
value
=
"p
age_info"
,
required
=
false
)
String
page_info
)
{
)
{
return
shopifyService
.
queryProductsByType
(
product_type
,
p
roduct_id
);
return
shopifyService
.
queryProductsByType
(
product_type
,
p
age_info
);
}
}
/**
/**
* 查看商品详情
* 查看商品详情
*
*
...
...
src/main/java/com/diaoyun/zion/chinafrica/entity/ProductPageInfo.java
0 → 100644
浏览文件 @
9d17852f
package
com
.
diaoyun
.
zion
.
chinafrica
.
entity
;
import
java.util.List
;
/**
* @Auther: wudepeng
* @Date: 2019/12/03
* @Description:
*/
public
class
ProductPageInfo
{
private
String
next
;
private
String
previous
;
private
List
productInfo
;
public
String
getNext
()
{
return
next
;
}
public
void
setNext
(
String
next
)
{
this
.
next
=
next
;
}
public
String
getPrevious
()
{
return
previous
;
}
public
void
setPrevious
(
String
previous
)
{
this
.
previous
=
previous
;
}
public
List
getProductInfo
()
{
return
productInfo
;
}
public
void
setProductInfo
(
List
productInfo
)
{
this
.
productInfo
=
productInfo
;
}
}
src/main/java/com/diaoyun/zion/chinafrica/service/ShopifyService.java
浏览文件 @
9d17852f
...
@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
...
@@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RequestParam;
public
interface
ShopifyService
{
public
interface
ShopifyService
{
Result
queryShopifyProducts
();
Result
queryShopifyProducts
();
Result
queryProductsByType
(
String
product_type
,
String
p
roduct_id
);
Result
queryProductsByType
(
String
product_type
,
String
p
age_info
);
Result
queryProductsDetails
(
String
product_id
);
Result
queryProductsDetails
(
String
product_id
);
...
...
src/main/java/com/diaoyun/zion/chinafrica/service/impl/ShopifyServiceImpl.java
浏览文件 @
9d17852f
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
package
com
.
diaoyun
.
zion
.
chinafrica
.
service
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.diaoyun.zion.chinafrica.constant.KeyConstant
;
import
com.diaoyun.zion.chinafrica.constant.KeyConstant
;
import
com.diaoyun.zion.chinafrica.entity.ProductPageInfo
;
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
;
...
@@ -9,8 +9,12 @@ import com.diaoyun.zion.master.common.RedisCache;
...
@@ -9,8 +9,12 @@ import com.diaoyun.zion.master.common.RedisCache;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.enums.ResultCodeEnum
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.HttpClientUtil
;
import
com.diaoyun.zion.master.util.ListUtil
;
import
com.diaoyun.zion.master.util.ListUtil
;
import
com.github.pagehelper.PageInfo
;
import
com.google.gson.JsonObject
;
import
net.sf.json.JSON
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -81,16 +85,39 @@ public class ShopifyServiceImpl implements ShopifyService {
...
@@ -81,16 +85,39 @@ public class ShopifyServiceImpl implements ShopifyService {
* @return
* @return
*/
*/
@Override
@Override
public
Result
queryProductsByType
(
String
product_type
,
String
p
roduct_id
)
{
public
Result
queryProductsByType
(
String
product_type
,
String
p
age_info
)
{
Result
result
=
new
Result
();
Result
result
=
new
Result
();
String
url
=
ShopifyConstant
.
productTypeUrl
()
+
"?limit="
+
ShopifyConstant
.
SHOPIFY_PAGE_SIZE
;
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"product_type"
,
product_type
);
if
(
StringUtils
.
isNotBlank
(
product_type
))
{
params
.
put
(
"product_type"
,
product_type
);
url
=
url
+
"&product_type="
+
product_type
;
}
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_PAGE_SIZE
);
params
.
put
(
"limit"
,
ShopifyConstant
.
SHOPIFY_PAGE_SIZE
);
try
{
try
{
if
(
StringUtils
.
isNotBlank
(
page_info
))
{
params
.
remove
(
"product_type"
);
params
.
put
(
"page_info"
,
page_info
);
url
=
url
.
substring
(
0
,
url
.
lastIndexOf
(
"&"
))
+
"&page_info="
+
page_info
;
}
List
<
String
>
headers
=
HttpClientUtil
.
getHeaders
(
url
);
ProductPageInfo
pageInfo
=
new
ProductPageInfo
();
String
flag
=
headers
.
get
(
headers
.
size
()
-
1
);
if
(
"first"
.
equals
(
flag
))
{
pageInfo
.
setNext
(
headers
.
get
(
0
));
}
else
if
(
"middle"
.
equals
(
flag
))
{
pageInfo
.
setPrevious
(
headers
.
get
(
0
));
pageInfo
.
setNext
(
headers
.
get
(
1
));
}
else
{
pageInfo
.
setPrevious
(
headers
.
get
(
0
));
}
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
String
data
=
HttpClientUtil
.
createConnection
(
ShopifyConstant
.
productTypeUrl
(),
params
,
"UTF-8"
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
data
);
List
<
String
>
list
=
new
ArrayList
<>();
result
.
setData
(
jsonObject
);
list
.
add
(
data
);
}
catch
(
IOException
e
)
{
pageInfo
.
setProductInfo
(
list
);
JSONObject
jsonObject
=
JSONObject
.
fromObject
(
pageInfo
);
result
.
setData
(
jsonObject
).
setMessage
(
ResultCodeEnum
.
SUCCESS
.
getDesc
());
}
catch
(
Exception
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
);
return
result
;
return
result
;
...
...
src/main/java/com/diaoyun/zion/master/util/HttpClientUtil.java
浏览文件 @
9d17852f
...
@@ -2,6 +2,7 @@ package com.diaoyun.zion.master.util;
...
@@ -2,6 +2,7 @@ package com.diaoyun.zion.master.util;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.diaoyun.zion.chinafrica.enums.PlatformEnum
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.mashape.unirest.http.Unirest
;
import
org.apache.http.*
;
import
org.apache.http.*
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.CookieStore
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
...
@@ -306,4 +307,39 @@ public class HttpClientUtil {
...
@@ -306,4 +307,39 @@ public class HttpClientUtil {
Header
header
=
sibResult
.
getContentEncoding
();
Header
header
=
sibResult
.
getContentEncoding
();
return
EntityUtils
.
toString
(
sibResult
)
+
"#"
+
header
;
return
EntityUtils
.
toString
(
sibResult
)
+
"#"
+
header
;
}
}
/**
* 获取shopify接口 headers里的参数【Link】
*
* @param url
* @return
* @throws Exception
*/
public
static
List
<
String
>
getHeaders
(
String
url
)
throws
Exception
{
List
<
String
>
list
=
new
ArrayList
();
com
.
mashape
.
unirest
.
http
.
HttpResponse
<
String
>
response
=
Unirest
.
get
(
url
)
.
headers
(
new
HashMap
<>())
.
asString
();
List
<
String
>
link
=
response
.
getHeaders
().
get
(
"Link"
);
String
linkString
=
link
.
toString
();
boolean
next
=
linkString
.
contains
(
"next"
);
boolean
previous
=
linkString
.
contains
(
"previous"
);
String
str
=
link
.
get
(
0
);
String
[]
split
=
str
.
split
(
","
);
for
(
int
i
=
0
;
i
<
split
.
length
;
i
++)
{
String
s
=
split
[
i
];
String
sub
=
s
.
substring
(
s
.
indexOf
(
"page_info="
),
s
.
lastIndexOf
(
">;"
));
String
substring
=
sub
.
substring
(
10
);
list
.
add
(
substring
);
}
if
(
next
)
{
list
.
add
(
"first"
);
if
(
previous
)
{
list
.
add
(
"middle"
);
}
}
else
{
list
.
add
(
"last"
);
}
return
list
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论