Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
smalltools
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王家辉
smalltools
Commits
272cf9ef
Commit
272cf9ef
authored
Mar 21, 2019
by
张洪涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改进批量推单的接口,添加结果校验
parent
130d4942
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
75 additions
and
22 deletions
+75
-22
src/main/java/com/freemud/Constant/ResponseCode.java
+4
-0
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
+71
-22
No files found.
src/main/java/com/freemud/Constant/ResponseCode.java
View file @
272cf9ef
...
...
@@ -18,6 +18,10 @@ public enum ResponseCode {
RESPONSE_CODE_100
(
"100"
,
"成功"
),
RESPONSE_CODE_101
(
"101"
,
"请求参数不正确"
),
RESPONSE_CODE_102
(
"102"
,
"请求失败"
),
RESPONSE_CODE_103
(
"103"
,
"商品我主档"
),
RESPONSE_CODE_205
(
"205"
,
"超过两小时没有推送"
),
RESPONSE_CODE_210
(
"210"
,
"未知原因"
),
RESPONSE_CODE_ERROR_PARAM
(
"104"
,
"参数不对"
);
private
String
code
;
...
...
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
View file @
272cf9ef
...
...
@@ -13,17 +13,14 @@
package
com
.
freemud
.
Service
.
Impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.freemud.Constant.ResponseCode
;
import
com.freemud.Mapper.OrderProductMapper
;
import
com.freemud.Service.OrdersService
;
import
com.freemud.dto.BaseResponse
;
import
com.freemud.dto.OrderInfo
;
import
com.freemud.dto.OrderProductDTO
;
import
com.freemud.utils.ExcelOperationUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.tomcat.util.http.fileupload.disk.DiskFileItem
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.io.FileSystemResource
;
...
...
@@ -35,7 +32,6 @@ import org.springframework.util.MultiValueMap;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.commons.CommonsMultipartFile
;
import
java.io.File
;
import
java.io.IOException
;
...
...
@@ -109,52 +105,102 @@ public class OrdersServiceImpl implements OrdersService {
public
BaseResponse
batchPush
(
MultipartFile
file
,
String
batchNumber
)
{
log
.
info
(
"请求参数:batchNumber:{}, Excel:{}"
,
batchNumber
,
file
.
getOriginalFilename
());
//导入Excel文件
BaseResponse
importResult
=
remoteRequest
(
batchNumber
,
"import"
,
file
);
BaseResponse
importResult
=
remoteRequest
OrderEx
(
batchNumber
,
"import"
,
file
);
log
.
info
(
"导入Excel结果:{}"
,
JSON
.
toJSONString
(
importResult
));
//推单过程
BaseResponse
getOrderHandleResult
=
new
BaseResponse
();
if
(
importResult
.
getCode
().
equals
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
())){
//处理对账的状态(初始化)
BaseResponse
handleOrderExStatusResult
=
remoteRequest
(
batchNumber
,
"handleOrderExStatus"
);
BaseResponse
handleOrderExStatusResult
=
remoteRequest
OrderEx
(
batchNumber
,
"handleOrderExStatus"
);
log
.
info
(
"处理对账的状态:{}"
,
handleOrderExStatusResult
);
if
(
handleOrderExStatusResult
.
getCode
().
equals
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
())){
//推送订单
BaseResponse
pushOrderResult
=
remoteRequest
(
batchNumber
,
"pushOrder"
,
null
);
BaseResponse
pushOrderResult
=
remoteRequest
OrderEx
(
batchNumber
,
"pushOrder"
,
null
);
log
.
info
(
"推送订单的结果:{}"
,
pushOrderResult
);
if
(
pushOrderResult
.
getCode
().
equals
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
())){
//获取订单的处理结果
getOrderHandleResult
=
remoteRequest
(
batchNumber
,
"getOrderHandleResult"
,
null
);
getOrderHandleResult
=
remoteRequest
OrderEx
(
batchNumber
,
"getOrderHandleResult"
,
null
);
log
.
info
(
"获取订单的处理结果:{}"
,
getOrderHandleResult
);
}
}
}
//检验过程
List
<
Map
>
mapResults
=
new
ArrayList
<>();
//检验过程,检查订单是否推送成功
if
(
getOrderHandleResult
.
getCode
().
equals
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
())){
List
<
LinkedHashMap
>
orderInfos
=
(
List
<
LinkedHashMap
>)
getOrderHandleResult
.
getResult
();
List
<
OrderInfo
>
orderInfoList
=
new
ArrayList
<>();
orderInfos
.
stream
().
forEach
(
linkedHashMap
->
{
OrderInfo
orderInfo
=
new
OrderInfo
();
orderInfo
.
setOrderId
(
linkedHashMap
.
get
(
"orderId"
).
toString
());
orderInfo
.
setPushResult
(
linkedHashMap
.
get
(
"pushResult"
).
toString
());
orderInfo
.
setResponseData
(
linkedHashMap
.
get
(
"responseData"
).
toString
());
orderInfoList
.
add
(
orderInfo
);
linkedHashMapPushStatus
->
{
List
<
LinkedHashMap
>
pushStatus
=
(
ArrayList
<
LinkedHashMap
>)
pushStatus
(
linkedHashMapPushStatus
.
get
(
"orderId"
).
toString
(),
"pushStatus"
).
getResult
();
log
.
info
(
"获取的结果:{}"
,
pushStatus
);
LinkedHashMap
queryStatus
=
(
LinkedHashMap
)
pushStatus
(
linkedHashMapPushStatus
.
get
(
"orderId"
).
toString
(),
"queryStatus"
).
getResult
();
boolean
compareStatus
=
pushStatus
.
stream
().
anyMatch
(
linkedHashMapOrderStatus
->
linkedHashMapOrderStatus
.
get
(
"status"
).
equals
(
queryStatus
.
get
(
"status"
))
&&
linkedHashMapOrderStatus
.
get
(
"result"
).
equals
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
())
);
if
(
compareStatus
==
true
){
Map
mapResult
=
new
HashMap
();
mapResult
.
put
(
"orderId"
,
linkedHashMapPushStatus
.
get
(
"orderId"
));
mapResult
.
put
(
"pushResult"
,
"推送成功"
);
mapResult
.
put
(
"pushStatus"
,
ResponseCode
.
RESPONSE_CODE_100
.
getCode
());
mapResults
.
add
(
mapResult
);
}
else
if
(
pushStatus
.
get
(
pushStatus
.
size
()-
1
).
get
(
"result"
)
==
ResponseCode
.
RESPONSE_CODE_103
.
getCode
()){
Map
mapResult
=
new
HashMap
();
mapResult
.
put
(
"orderId"
,
linkedHashMapPushStatus
.
get
(
"orderId"
));
mapResult
.
put
(
"pushResult"
,
"推送失败("
+
ResponseCode
.
RESPONSE_CODE_103
.
getMsg
()+
")"
);
mapResult
.
put
(
"pushStatus"
,
ResponseCode
.
RESPONSE_CODE_103
.
getCode
());
mapResults
.
add
(
mapResult
);
}
else
if
(
pushStatus
.
get
(
pushStatus
.
size
()-
1
).
get
(
"result"
)
==
ResponseCode
.
RESPONSE_CODE_205
.
getCode
()){
Map
mapResult
=
new
HashMap
();
mapResult
.
put
(
"orderId"
,
linkedHashMapPushStatus
.
get
(
"orderId"
));
mapResult
.
put
(
"pushResult"
,
"推送失败("
+
ResponseCode
.
RESPONSE_CODE_205
.
getMsg
()+
")"
);
mapResult
.
put
(
"pushStatus"
,
ResponseCode
.
RESPONSE_CODE_205
.
getCode
());
mapResults
.
add
(
mapResult
);
}
else
{
Map
mapResult
=
new
HashMap
();
mapResult
.
put
(
"orderId"
,
linkedHashMapPushStatus
.
get
(
"orderId"
));
mapResult
.
put
(
"pushResult"
,
"推送失败(未知原因)"
);
mapResult
.
put
(
"pushStatus"
,
ResponseCode
.
RESPONSE_CODE_210
.
getCode
());
mapResults
.
add
(
mapResult
);
}
}
);
}
return
getOrderHandleResult
;
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_100
.
getMsg
(),
"1"
,
mapResults
);
}
private
BaseResponse
pushStatus
(
String
orderId
,
String
urll
){
String
url
=
RequestUrl
+
"/order/"
+
urll
;
log
.
info
(
"请求的Url:{}"
,
url
);
MultiValueMap
<
String
,
Object
>
param
=
new
LinkedMultiValueMap
<>();
BaseResponse
importResult
=
new
BaseResponse
();
if
(
orderId
!=
null
&&
!
orderId
.
equals
(
""
)){
param
.
add
(
"orderId"
,
orderId
);
log
.
info
(
"{}接口请求参数:{}"
,
urll
,
param
);
try
{
importResult
=
restTemplate
.
postForObject
(
url
,
param
,
BaseResponse
.
class
);
}
catch
(
Exception
e
)
{
log
.
error
(
"调用{}接口出错:{}"
,
urll
,
e
.
fillInStackTrace
());
importResult
=
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"调用"
+
url
+
"接口出错"
);
}
}
return
importResult
;
}
private
BaseResponse
queryStatus
(
String
orderId
){
return
null
;
}
/**
* 请求远程接口
* 请求远程接口
(order-ex-handle-controller)
* @param batchNumber
* @return
*/
private
BaseResponse
remoteRequest
(
String
batchNumber
,
String
urll
,
MultipartFile
multipartFile
)
{
private
BaseResponse
remoteRequest
OrderEx
(
String
batchNumber
,
String
urll
,
MultipartFile
multipartFile
)
{
String
url
=
RequestUrl
+
"/orderEx/"
+
urll
;
log
.
info
(
"请求的Url:{}"
,
url
);
MultiValueMap
<
String
,
Object
>
param
=
new
LinkedMultiValueMap
<>();
...
...
@@ -182,7 +228,12 @@ public class OrdersServiceImpl implements OrdersService {
return
importResult
;
}
private
BaseResponse
remoteRequest
(
String
batchNumber
,
String
urll
)
{
/**
*重写请求远程接口(order-ex-handle-controller)
* @param batchNumber
* @return
*/
private
BaseResponse
remoteRequestOrderEx
(
String
batchNumber
,
String
urll
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
add
(
"Accept"
,
"application/json"
);
headers
.
add
(
"Content-Type"
,
"application/json;charset=UTF-8"
);
...
...
@@ -212,6 +263,4 @@ public class OrdersServiceImpl implements OrdersService {
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment