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
2a8b2fb7
Commit
2a8b2fb7
authored
Mar 15, 2019
by
张洪涛
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口优化,添加异常处理
parent
8015819f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
26 deletions
+33
-26
src/main/java/com/freemud/Constant/ResponseCode.java
+3
-2
src/main/java/com/freemud/Controller/OrdersController.java
+9
-16
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
+18
-6
src/main/java/com/freemud/Service/OrdersService.java
+3
-2
No files found.
src/main/java/com/freemud/Constant/ResponseCode.java
View file @
2a8b2fb7
...
...
@@ -15,9 +15,10 @@ import lombok.Data;
* 注意:本内容仅限于上海非码科技内部传阅,禁止外泄以及用于其他的商业目的
*/
public
enum
ResponseCode
{
RESPONSE_CODE_100
(
"100"
,
"
响应
成功"
),
RESPONSE_CODE_100
(
"100"
,
"成功"
),
RESPONSE_CODE_101
(
"101"
,
"请求参数不正确"
),
RESPONSE_CODE_102
(
"102"
,
"请求失败"
);
RESPONSE_CODE_102
(
"102"
,
"请求失败"
),
RESPONSE_CODE_ERROR_PARAM
(
"104"
,
"参数不对"
);
private
String
code
;
private
String
msg
;
...
...
src/main/java/com/freemud/Controller/OrdersController.java
View file @
2a8b2fb7
...
...
@@ -26,42 +26,35 @@ import java.util.List;
@Controller
@Api
(
"订单sku Controller"
)
@RequestMapping
(
"order"
)
public
class
OrdersController
{
@Autowired
private
OrdersService
ordersService
;
@ApiOperation
(
"获取订单的商品信息"
)
@GetMapping
(
"/
getOrder
"
)
@GetMapping
(
"/
detail
"
)
@ResponseBody
public
BaseResponse
getOrder
(
@RequestParam
(
"orderId"
)
String
orderId
){
if
(
orderId
==
null
){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_101
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_101
.
getMsg
(),
"1"
,
"请求参数为空"
);
}
List
<
OrderProductDTO
>
list
=
ordersService
.
getOrderProductDTOByOrderId
(
orderId
);
if
(
list
.
size
()
==
0
){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"查询不到订单,请输入正确的订单号"
);
}
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_100
.
getMsg
(),
"1"
,
list
);
return
ordersService
.
getOrderProductDTOByOrderId
(
orderId
);
}
@ApiOperation
(
"根据正确的sku进行补推"
)
@PostMapping
(
"/
getRightSkuAndOrder
Push"
)
@PostMapping
(
"/
fixSkuAnd
Push"
)
@ResponseBody
public
BaseResponse
getRightSkuAndOrderPush
(
@RequestBody
OrderProductDTO
orderProductDTO
){
String
sku
=
orderProductDTO
.
getSku
();
String
id
=
orderProductDTO
.
getId
();
if
(
sku
==
null
||
id
==
null
){
if
(
orderProductDTO
.
getId
()
==
null
||
orderProductDTO
.
getSku
()
==
null
||
orderProductDTO
.
getSku
().
equals
(
""
)
||
orderProductDTO
.
getId
().
equals
(
""
)){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_101
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_101
.
getMsg
(),
"1"
,
"请求参数为空"
);
}
// 修复sku
boolean
isMod
=
ordersService
.
RepairByRightSku
(
orderProductDTO
);
if
(
isMod
){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_100
.
getMsg
(),
"1"
,
"修复成功"
);
}
else
{
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"修复失败"
);
if
(
orderProductDTO
.
getSku
().
length
()
!=
8
){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_ERROR_PARAM
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_ERROR_PARAM
.
getMsg
(),
"1"
,
"输入的sku格式不对"
);
}
// 修复sku
return
ordersService
.
RepairByRightSku
(
orderProductDTO
);
}
}
src/main/java/com/freemud/Service/Impl/OrdersServiceImpl.java
View file @
2a8b2fb7
...
...
@@ -13,6 +13,7 @@
package
com
.
freemud
.
Service
.
Impl
;
import
com.alibaba.fastjson.JSON
;
import
com.freemud.Constant.ResponseCode
;
import
com.freemud.Mapper.OrderProductMapper
;
import
com.freemud.Service.OrdersService
;
import
com.freemud.dto.BaseResponse
;
...
...
@@ -25,6 +26,7 @@ import org.springframework.core.io.FileSystemResource;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.File
;
...
...
@@ -52,14 +54,18 @@ public class OrdersServiceImpl implements OrdersService {
@Override
public
List
<
OrderProductDTO
>
getOrderProductDTOByOrderId
(
String
orderId
)
{
public
BaseResponse
getOrderProductDTOByOrderId
(
String
orderId
)
{
List
<
OrderProductDTO
>
orderProductDTO
=
orderProductMapper
.
getOrderProductDTOByOrderId
(
orderId
);
log
.
info
(
"查询结果:{}"
,
JSON
.
toJSONString
(
orderProductDTO
));
return
orderProductDTO
;
if
(
orderProductDTO
.
size
()
==
0
||
orderProductDTO
==
null
){
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"查询不到订单,请输入正确的订单号"
);
}
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_100
.
getMsg
(),
"1"
,
orderProductDTO
);
}
@Override
public
Boolean
RepairByRightSku
(
OrderProductDTO
orderProductDTO
)
{
public
BaseResponse
RepairByRightSku
(
OrderProductDTO
orderProductDTO
)
{
// 请求修复接口
String
url
=
RequestUrl
+
"/order/repairByRightSku"
;
String
titles
[]
=
{
"订单联合表主键"
,
"正确的sku"
};
...
...
@@ -73,14 +79,20 @@ public class OrdersServiceImpl implements OrdersService {
FileSystemResource
resource
=
new
FileSystemResource
(
file
.
getPath
());
MultiValueMap
<
String
,
Object
>
param
=
new
LinkedMultiValueMap
<>();
param
.
add
(
"file"
,
resource
);
String
code
=
restTemplate
.
postForObject
(
url
,
param
,
String
.
class
);
String
code
=
""
;
try
{
code
=
restTemplate
.
postForObject
(
url
,
param
,
String
.
class
);
}
catch
(
RestClientException
e
)
{
log
.
error
(
"調用修復sku接口出錯"
);
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"調用修復接口出錯"
);
}
log
.
info
(
"调用接口{}返回的code:{}"
,
url
,
code
);
if
(
code
.
equals
(
returnCode
)){
log
.
info
(
"修改sku成功{}"
,
JSON
.
toJSONString
(
orderProductDTO
));
return
true
;
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_100
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_100
.
getMsg
(),
"1"
,
"修复成功"
)
;
}
log
.
info
(
"修改sku失败:{}"
,
JSON
.
toJSONString
(
orderProductDTO
));
return
false
;
return
new
BaseResponse
(
ResponseCode
.
RESPONSE_CODE_102
.
getCode
(),
ResponseCode
.
RESPONSE_CODE_102
.
getMsg
(),
"1"
,
"修复失败"
)
;
}
...
...
src/main/java/com/freemud/Service/OrdersService.java
View file @
2a8b2fb7
...
...
@@ -12,6 +12,7 @@
*/
package
com
.
freemud
.
Service
;
import
com.freemud.dto.BaseResponse
;
import
com.freemud.dto.OrderProductDTO
;
import
java.util.List
;
...
...
@@ -23,8 +24,8 @@ public interface OrdersService {
* @param orderId
* @return
*/
List
<
OrderProductDTO
>
getOrderProductDTOByOrderId
(
String
orderId
);
BaseResponse
getOrderProductDTOByOrderId
(
String
orderId
);
B
oolean
RepairByRightSku
(
OrderProductDTO
orderProductDTO
);
B
aseResponse
RepairByRightSku
(
OrderProductDTO
orderProductDTO
);
}
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