Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
soss
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hooloo
ms
soss
Commits
8c8e8d72
Commit
8c8e8d72
authored
Apr 17, 2023
by
weijiguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加错误日志
parent
0e6988c6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
54 deletions
+53
-54
soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java
+53
-54
No files found.
soss-system/src/main/java/com/soss/system/service/impl/MachineApiServiceImpl.java
View file @
8c8e8d72
...
@@ -56,28 +56,28 @@ public class MachineApiServiceImpl {
...
@@ -56,28 +56,28 @@ public class MachineApiServiceImpl {
List
<
String
>
skuIds
=
JSONObject
.
parseArray
(
skuIDs
,
String
.
class
);
List
<
String
>
skuIds
=
JSONObject
.
parseArray
(
skuIDs
,
String
.
class
);
String
robotID
=
jsonObject
.
getString
(
"robotId"
);
String
robotID
=
jsonObject
.
getString
(
"robotId"
);
String
status
=
jsonObject
.
getString
(
"status"
);
String
status
=
jsonObject
.
getString
(
"status"
);
if
(
StringUtils
.
isEmpty
(
skuIDs
))
{
if
(
StringUtils
.
isEmpty
(
skuIDs
))
{
throw
new
ServiceException
(
"sku不能为空"
);
throw
new
ServiceException
(
"sku不能为空"
);
}
}
ShopGoodsSku
shopGoodsSku
=
new
ShopGoodsSku
();
ShopGoodsSku
shopGoodsSku
=
new
ShopGoodsSku
();
shopGoodsSku
.
setShopId
(
Long
.
parseLong
(
shopID
));
shopGoodsSku
.
setShopId
(
Long
.
parseLong
(
shopID
));
Map
<
Long
,
List
<
Long
>>
map
=
new
HashMap
<>();
Map
<
Long
,
List
<
Long
>>
map
=
new
HashMap
<>();
for
(
String
skuId
:
skuIds
)
{
for
(
String
skuId
:
skuIds
)
{
shopGoodsSku
.
setSkuId
(
Long
.
parseLong
(
skuId
));
shopGoodsSku
.
setSkuId
(
Long
.
parseLong
(
skuId
));
List
<
ShopGoodsSku
>
shopGoodsSkus
=
shopGoodsSkuMapper
.
selectShopGoodsSkuList
(
shopGoodsSku
);
List
<
ShopGoodsSku
>
shopGoodsSkus
=
shopGoodsSkuMapper
.
selectShopGoodsSkuList
(
shopGoodsSku
);
if
(
CollectionUtils
.
isEmpty
(
shopGoodsSkus
))
{
if
(
CollectionUtils
.
isEmpty
(
shopGoodsSkus
))
{
log
.
info
(
skuId
+
"不存在"
);
log
.
info
(
skuId
+
"不存在"
);
continue
;
continue
;
// throw new ServiceException(skuId+"不存在");
// throw new ServiceException(skuId+"不存在");
}
}
for
(
ShopGoodsSku
goodsSkus
:
shopGoodsSkus
)
{
for
(
ShopGoodsSku
goodsSkus
:
shopGoodsSkus
)
{
Long
goodsId
=
goodsSkus
.
getGoodsId
();
Long
goodsId
=
goodsSkus
.
getGoodsId
();
List
<
Long
>
strings
=
map
.
get
(
goodsId
);
List
<
Long
>
strings
=
map
.
get
(
goodsId
);
if
(
strings
==
null
)
{
if
(
strings
==
null
)
{
strings
=
new
ArrayList
<>();
strings
=
new
ArrayList
<>();
}
}
strings
.
add
(
goodsSkus
.
getSkuId
());
strings
.
add
(
goodsSkus
.
getSkuId
());
map
.
put
(
goodsId
,
strings
);
map
.
put
(
goodsId
,
strings
);
}
}
}
}
int
i
=
shopGoodsSkuMapper
.
updateSkuStatus
(
skuIds
,
robotID
,
shopID
,
status
);
int
i
=
shopGoodsSkuMapper
.
updateSkuStatus
(
skuIds
,
robotID
,
shopID
,
status
);
...
@@ -85,7 +85,7 @@ public class MachineApiServiceImpl {
...
@@ -85,7 +85,7 @@ public class MachineApiServiceImpl {
Machine
machine
=
machineMapper
.
selectMachineById
(
robotID
);
Machine
machine
=
machineMapper
.
selectMachineById
(
robotID
);
this
.
push
(
machine
,
status
,
map
);
this
.
push
(
machine
,
status
,
map
);
return
""
+
i
;
return
""
+
i
;
}
}
...
@@ -103,6 +103,7 @@ public class MachineApiServiceImpl {
...
@@ -103,6 +103,7 @@ public class MachineApiServiceImpl {
* "state": 2
* "state": 2
* }
* }
* }
* }
*
* @param machine
* @param machine
* @param status
* @param status
* @param map
* @param map
...
@@ -128,27 +129,27 @@ public class MachineApiServiceImpl {
...
@@ -128,27 +129,27 @@ public class MachineApiServiceImpl {
Long
orderID
=
jsonObject
.
getLong
(
"orderId"
);
Long
orderID
=
jsonObject
.
getLong
(
"orderId"
);
String
status
=
jsonObject
.
getString
(
"status"
);
String
status
=
jsonObject
.
getString
(
"status"
);
Order
order1
=
orderService
.
selectById
(
orderID
);
Order
order1
=
orderService
.
selectById
(
orderID
);
if
(
order1
==
null
)
{
if
(
order1
==
null
)
{
throw
new
ServiceException
(
"该订单不存在"
);
throw
new
ServiceException
(
"该订单不存在"
);
}
}
order1
.
setState
(
status
);
order1
.
setState
(
status
);
order1
.
setUpdatedAt
(
new
Date
());
order1
.
setUpdatedAt
(
new
Date
());
if
(
OrderStatusConstant
.
completed
.
equals
(
status
))
{
if
(
OrderStatusConstant
.
completed
.
equals
(
status
))
{
order1
.
setFinishTime
(
new
Date
());
order1
.
setFinishTime
(
new
Date
());
}
}
int
i
=
orderService
.
updateOrder
(
order1
);
int
i
=
orderService
.
updateOrder
(
order1
);
return
i
+
""
;
return
i
+
""
;
}
}
public
void
testOrder
(
Long
orderId
)
{
public
void
testOrder
(
Long
orderId
)
{
try
{
try
{
if
(
orderId
==
null
)
{
if
(
orderId
==
null
)
{
orderId
=
8L
;
orderId
=
8L
;
}
}
Order
order
=
orderService
.
selectById
(
orderId
);
Order
order
=
orderService
.
selectById
(
orderId
);
OrderDetail
orderDetail
=
new
OrderDetail
();
OrderDetail
orderDetail
=
new
OrderDetail
();
orderDetail
.
setOrderId
(
order
.
getId
());
orderDetail
.
setOrderId
(
order
.
getId
());
List
<
OrderDetail
>
orderDetails
=
orderDetailMapper
.
selectOrderDetailList
(
orderDetail
);
List
<
OrderDetail
>
orderDetails
=
orderDetailMapper
.
selectOrderDetailList
(
orderDetail
);
for
(
OrderDetail
detail
:
orderDetails
)
{
for
(
OrderDetail
detail
:
orderDetails
)
{
...
@@ -157,26 +158,26 @@ public class MachineApiServiceImpl {
...
@@ -157,26 +158,26 @@ public class MachineApiServiceImpl {
}
}
order
.
setOrderDetails
(
orderDetails
);
order
.
setOrderDetails
(
orderDetails
);
createOrder
(
order
);
createOrder
(
order
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
""
,
e
);
log
.
error
(
""
,
e
);
}
}
}
}
public
ResultVo
createOrder
(
Order
order
){
public
ResultVo
createOrder
(
Order
order
)
{
String
orderInfo
=
null
;
String
orderInfo
=
null
;
JSONObject
orderJson
=
null
;
JSONObject
orderJson
=
null
;
try
{
try
{
ObjectMapper
objectMapper
=
new
ObjectMapper
();
ObjectMapper
objectMapper
=
new
ObjectMapper
();
orderInfo
=
objectMapper
.
writeValueAsString
(
order
);
orderInfo
=
objectMapper
.
writeValueAsString
(
order
);
log
.
info
(
"创建订单数据为:【{}】"
,
orderInfo
);
log
.
info
(
"创建订单数据为:【{}】"
,
orderInfo
);
orderJson
=
JSONObject
.
parseObject
(
orderInfo
);
orderJson
=
JSONObject
.
parseObject
(
orderInfo
);
orderJson
.
put
(
"goodsNum"
,
orderJson
.
getLong
(
"goodsNum"
));
orderJson
.
put
(
"goodsNum"
,
orderJson
.
getLong
(
"goodsNum"
));
orderJson
.
put
(
"machineId"
,
orderJson
.
getLong
(
"machineId"
));
orderJson
.
put
(
"machineId"
,
orderJson
.
getLong
(
"machineId"
));
orderJson
.
put
(
"shopId"
,
orderJson
.
getLong
(
"shopId"
));
orderJson
.
put
(
"shopId"
,
orderJson
.
getLong
(
"shopId"
));
orderJson
.
put
(
"state"
,
orderJson
.
getLong
(
"state"
));
orderJson
.
put
(
"state"
,
orderJson
.
getLong
(
"state"
));
List
<
JSONObject
>
goodsList
=
new
ArrayList
<>();
List
<
JSONObject
>
goodsList
=
new
ArrayList
<>();
orderJson
.
put
(
"goodsList"
,
goodsList
);
orderJson
.
put
(
"goodsList"
,
goodsList
);
List
<
OrderDetail
>
orderDetails
=
order
.
getOrderDetails
();
List
<
OrderDetail
>
orderDetails
=
order
.
getOrderDetails
();
for
(
OrderDetail
detail
:
orderDetails
)
{
for
(
OrderDetail
detail
:
orderDetails
)
{
JSONObject
jsonObject
=
new
JSONObject
();
JSONObject
jsonObject
=
new
JSONObject
();
...
@@ -196,17 +197,17 @@ public class MachineApiServiceImpl {
...
@@ -196,17 +197,17 @@ public class MachineApiServiceImpl {
// }
// }
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"初始化订单发生异常"
,
e
);
log
.
error
(
"初始化订单发生异常"
,
e
);
throw
new
ServiceException
(
"初始订单数据异常,请重试"
);
throw
new
ServiceException
(
"初始订单数据异常,请重试"
);
}
}
ResultVo
resultVo
=
sendRequest
(
orderJson
.
toJSONString
(),
"/v1/order"
);
ResultVo
resultVo
=
sendRequest
(
orderJson
.
toJSONString
(),
"/v1/order"
);
String
code
=
resultVo
.
getCode
();
String
code
=
resultVo
.
getCode
();
if
(
"2001"
.
equals
(
code
))
{
if
(
"2001"
.
equals
(
code
))
{
throw
new
ServiceException
(
"库存不足"
);
throw
new
ServiceException
(
"库存不足"
);
}
else
if
(
"3001"
.
equals
(
code
))
{
}
else
if
(
"3001"
.
equals
(
code
))
{
throw
new
ServiceException
(
"机器繁忙"
);
throw
new
ServiceException
(
"机器繁忙"
);
}
}
return
resultVo
;
return
resultVo
;
...
@@ -214,38 +215,36 @@ public class MachineApiServiceImpl {
...
@@ -214,38 +215,36 @@ public class MachineApiServiceImpl {
}
}
public
ResultVo
sendRequest
(
String
param
,
String
interfaceName
)
{
try
{
public
ResultVo
sendRequest
(
String
param
,
String
interfaceName
){
String
postUrl
=
url
+
interfaceName
;
try
{
log
.
info
(
"请求订单接口[{}]:【{}】"
,
postUrl
,
param
);
String
postUrl
=
url
+
interfaceName
;
log
.
info
(
"请求订单接口[{}]:【{}】"
,
postUrl
,
param
);
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
HttpHeaders
requestHeaders
=
new
HttpHeaders
();
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
requestHeaders
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
HttpEntity
requestEntity
=
new
HttpEntity
(
param
,
requestHeaders
);
HttpEntity
requestEntity
=
new
HttpEntity
(
param
,
requestHeaders
);
JSONObject
.
toJSONString
(
param
);
JSONObject
.
toJSONString
(
param
);
ResponseEntity
<
String
>
stringResponseEntity
=
restTemplate
.
postForEntity
(
postUrl
,
requestEntity
,
String
.
class
);
ResponseEntity
<
String
>
stringResponseEntity
=
restTemplate
.
postForEntity
(
postUrl
,
requestEntity
,
String
.
class
);
log
.
info
(
"请求接口返回结果为[{}]:【{}】"
,
postUrl
,
stringResponseEntity
.
getBody
());
log
.
info
(
"请求接口返回结果为[{}]:【{}】"
,
postUrl
,
stringResponseEntity
.
getBody
());
ResultVo
resultVo
=
JSONObject
.
parseObject
(
stringResponseEntity
.
getBody
(),
ResultVo
.
class
);
ResultVo
resultVo
=
JSONObject
.
parseObject
(
stringResponseEntity
.
getBody
(),
ResultVo
.
class
);
return
resultVo
;
return
resultVo
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"请求发生异常:"
,
e
);
log
.
error
(
"请求发生异常:"
,
e
);
throw
new
ServiceException
(
"服务器繁忙,请重试"
);
throw
new
ServiceException
(
"服务器繁忙,请重试"
);
}
}
}
}
public
void
testOrderUpdate
(
String
orderId
)
{
public
void
testOrderUpdate
(
String
orderId
)
{
if
(
StringUtils
.
isEmpty
(
orderId
))
{
if
(
StringUtils
.
isEmpty
(
orderId
))
{
orderId
=
"8"
;
orderId
=
"8"
;
}
}
JSONObject
param
=
new
JSONObject
();
JSONObject
param
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"state"
,
2
);
data
.
put
(
"state"
,
2
);
data
.
put
(
"payTime"
,
new
Date
());
data
.
put
(
"payTime"
,
new
Date
());
param
.
put
(
"data"
,
data
.
toJSONString
());
param
.
put
(
"data"
,
data
.
toJSONString
());
param
.
put
(
"orderId"
,
orderId
);
param
.
put
(
"orderId"
,
orderId
);
sendRequest
(
param
.
toJSONString
(),
"/v1/order/update"
);
sendRequest
(
param
.
toJSONString
(),
"/v1/order/update"
);
}
}
public
Object
robotUpdate
(
JSONObject
jsonObject
)
{
public
Object
robotUpdate
(
JSONObject
jsonObject
)
{
...
@@ -256,8 +255,8 @@ public class MachineApiServiceImpl {
...
@@ -256,8 +255,8 @@ public class MachineApiServiceImpl {
machine
.
setShopId
(
shopID
);
machine
.
setShopId
(
shopID
);
machine
.
setId
(
robotID
);
machine
.
setId
(
robotID
);
List
<
Machine
>
machines
=
machineMapper
.
selectMachineList
(
machine
);
List
<
Machine
>
machines
=
machineMapper
.
selectMachineList
(
machine
);
if
(
machines
.
isEmpty
())
{
if
(
machines
.
isEmpty
())
{
throw
new
ServiceException
(
"该机器未绑定店铺"
)
;
throw
new
ServiceException
(
"该机器未绑定店铺"
);
}
}
machine
.
setState
(
status
);
machine
.
setState
(
status
);
return
machineMapper
.
updateMachine
(
machine
);
return
machineMapper
.
updateMachine
(
machine
);
...
@@ -266,14 +265,14 @@ public class MachineApiServiceImpl {
...
@@ -266,14 +265,14 @@ public class MachineApiServiceImpl {
public
void
updateOrder
(
Order
order
)
{
public
void
updateOrder
(
Order
order
)
{
JSONObject
param
=
new
JSONObject
();
JSONObject
param
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
JSONObject
data
=
new
JSONObject
();
data
.
put
(
"state"
,
Integer
.
parseInt
(
order
.
getState
()));
data
.
put
(
"state"
,
Integer
.
parseInt
(
order
.
getState
()));
if
(
Objects
.
equals
(
OrderStatusConstant
.
Paid
,
order
.
getState
()))
{
if
(
Objects
.
equals
(
OrderStatusConstant
.
Paid
,
order
.
getState
()))
{
data
.
put
(
"payTime"
,
DateUtils
.
parseDateToStr
(
"yyyy-MM-dd HH:mm:ss"
,
order
.
getPayTime
()));
data
.
put
(
"payTime"
,
DateUtils
.
parseDateToStr
(
"yyyy-MM-dd HH:mm:ss"
,
order
.
getPayTime
()));
}
}
param
.
put
(
"data"
,
data
.
toJSONString
());
param
.
put
(
"data"
,
data
.
toJSONString
());
param
.
put
(
"orderId"
,
order
.
getId
());
param
.
put
(
"orderId"
,
order
.
getId
());
ResultVo
resultVo
=
sendRequest
(
param
.
toJSONString
(),
"/v1/order/update"
);
ResultVo
resultVo
=
sendRequest
(
param
.
toJSONString
(),
"/v1/order/update"
);
operationLogService
.
insertOrderOperationLog
(
order
,
resultVo
);
operationLogService
.
insertOrderOperationLog
(
order
,
resultVo
);
}
}
...
@@ -281,10 +280,10 @@ public class MachineApiServiceImpl {
...
@@ -281,10 +280,10 @@ public class MachineApiServiceImpl {
String
orderId
=
jsonObject
.
getString
(
"orderId"
);
String
orderId
=
jsonObject
.
getString
(
"orderId"
);
String
secret
=
jsonObject
.
getString
(
"secret"
);
String
secret
=
jsonObject
.
getString
(
"secret"
);
String
value
=
stringRedisTemplate
.
opsForValue
().
get
(
secret
);
String
value
=
stringRedisTemplate
.
opsForValue
().
get
(
secret
);
if
(
value
==
null
)
{
if
(
value
==
null
)
{
throw
new
ServiceException
(
"该密钥错误或者已经失效"
);
throw
new
ServiceException
(
"该密钥错误或者已经失效"
);
}
}
if
(
orderId
.
equals
(
value
))
{
if
(
orderId
.
equals
(
value
))
{
throw
new
ServiceException
(
"密钥获取订单失败"
);
throw
new
ServiceException
(
"密钥获取订单失败"
);
}
}
return
null
;
return
null
;
...
...
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