Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
A
Afrishop refactored project
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Whispa
Afrishop refactored project
Commits
66dc0609
提交
66dc0609
authored
11月 19, 2020
作者:
Whispa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/master'
上级
8f8a69cc
a33b827a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
51 行增加
和
29 行删除
+51
-29
OrderController.java
.../com/example/afrishop_v3/controllers/OrderController.java
+51
-29
没有找到文件。
src/main/java/com/example/afrishop_v3/controllers/OrderController.java
浏览文件 @
66dc0609
...
...
@@ -10,6 +10,8 @@ import com.example.afrishop_v3.repository.*;
import
com.example.afrishop_v3.security.services.AuthenticationUser
;
import
com.example.afrishop_v3.util.IdUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
...
...
@@ -40,6 +42,7 @@ public class OrderController extends Controller {
private
final
TbCfExpressTemplateRepository
templateRepository
;
private
final
TbCfExchangeRepository
exchangeRepository
;
private
final
AuthenticationUser
user
;
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OrderController
.
class
);
public
OrderController
(
TbCfOrderRepository
repository
,
TbCfCartRecordRRepository
cartRepository
,
TbCfAddressRepository
addressRepository
,
TbCfToicouponRepository
toicouponRepository
,
TbCfStationItemRepository
itemRepository
,
TbCfItemCommentRepository
commentRepository
,
TbCfExpressTemplateRepository
templateRepository
,
@Qualifier
(
"tbCfExchangeRepository"
)
TbCfExchangeRepository
exchangeRepository
,
AuthenticationUser
user
)
{
this
.
repository
=
repository
;
...
...
@@ -53,7 +56,7 @@ public class OrderController extends Controller {
this
.
user
=
user
;
}
private
TbCfCartRecordR
getCart
(
TbCfStationItem
item
,
String
itemSku
,
Integer
itemNum
,
Double
price
)
{
private
TbCfCartRecordR
getCart
(
TbCfStationItem
item
,
String
itemSku
,
Integer
itemNum
,
Double
price
)
{
TbCfCartRecordR
record
=
new
TbCfCartRecordR
();
...
...
@@ -72,10 +75,10 @@ public class OrderController extends Controller {
@GetMapping
(
"currencyConversion"
)
public
Result
convert
(
@RequestParam
(
"price"
)
BigDecimal
price
,
@RequestParam
(
"currency"
)
String
currency
)
{
public
Result
convert
(
@RequestParam
(
"price"
)
BigDecimal
price
,
@RequestParam
(
"currency"
)
String
currency
)
{
TbCfExchange
exchangeEntity
=
exchangeRepository
.
findByExchangeCurrency
(
currency
.
toUpperCase
());
if
(
exchangeEntity
==
null
)
{
return
new
Result
(
ResultCodeEnum
.
ILLEGAL_ARGUMENT
.
getCode
(),
"Currency Not Found"
);
if
(
exchangeEntity
==
null
)
{
return
new
Result
(
ResultCodeEnum
.
ILLEGAL_ARGUMENT
.
getCode
(),
"Currency Not Found"
);
}
BigDecimal
rate
=
exchangeEntity
.
getExchangeRate
();
BigDecimal
resultPrice
=
price
.
multiply
(
rate
);
...
...
@@ -86,7 +89,7 @@ public class OrderController extends Controller {
@GetMapping
(
"/payNow"
)
public
Result
<
TbCfOrder
>
payNow
(
@RequestParam
(
"itemId"
)
String
itemId
,
@RequestParam
(
"itemNum"
)
Integer
itemNum
,
@RequestParam
(
value
=
"itemSku"
,
defaultValue
=
""
)
String
itemSku
,
@RequestParam
(
value
=
"itemSku"
,
defaultValue
=
""
)
String
itemSku
,
@RequestParam
(
value
=
"itemPrice"
)
Double
itemPrice
,
@RequestParam
(
value
=
"toitableId"
,
required
=
false
)
String
toitableId
)
{
TbCfOrder
order
=
new
TbCfOrder
();
...
...
@@ -106,21 +109,21 @@ public class OrderController extends Controller {
List
<
TbCfCartRecordR
>
list
=
new
ArrayList
<>();
list
.
add
(
getCart
(
item
,
itemSku
,
itemNum
,
itemPrice
));
list
.
add
(
getCart
(
item
,
itemSku
,
itemNum
,
itemPrice
));
order
.
setCouponId
(
toitableId
);
if
(
toitableId
!=
null
&&
!
toitableId
.
isEmpty
())
{
Optional
<
TbCfToicoupon
>
couponOptional
=
toicouponRepository
.
findById
(
toitableId
);
if
(
couponOptional
.
isPresent
()
)
{
if
(
couponOptional
.
isPresent
())
{
TbCfCoupon
coupon
=
couponOptional
.
get
().
getCoupon
();
order
.
setCoupon
(
coupon
);
}
}
order
.
getItemOrderListFromCartList
(
list
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
list
,
itemRepository
);
return
new
Result
<>(
order
);
}
...
...
@@ -145,21 +148,21 @@ public class OrderController extends Controller {
Optional
<
TbCfToicoupon
>
couponOptional
=
toicouponRepository
.
findById
(
toitableId
);
if
(
couponOptional
.
isPresent
()
)
{
if
(
couponOptional
.
isPresent
())
{
TbCfCoupon
coupon
=
couponOptional
.
get
().
getCoupon
();
order
.
setCoupon
(
coupon
);
}
}
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
return
new
Result
<>(
order
);
}
@GetMapping
(
value
=
"currentTime"
)
public
Result
<
Date
>
getTime
(){
public
Result
<
Date
>
getTime
()
{
return
new
Result
<>(
new
Date
());
}
...
...
@@ -168,9 +171,9 @@ public class OrderController extends Controller {
public
Result
<
TbCfOrder
>
placeOrder
(
@RequestBody
OrderRequest
tbCfOrder
,
@RequestParam
(
value
=
"toitableId"
,
required
=
false
)
String
toitableId
,
@RequestParam
(
value
=
"itemId"
,
required
=
false
)
String
itemId
,
@RequestParam
(
value
=
"itemNum"
,
required
=
false
)
Integer
itemNum
,
@RequestParam
(
value
=
"itemSku"
,
required
=
false
)
String
itemSku
,
@RequestParam
(
value
=
"itemPrice"
,
required
=
false
)
Double
itemPrice
,
@RequestParam
(
value
=
"itemNum"
,
required
=
false
)
Integer
itemNum
,
@RequestParam
(
value
=
"itemSku"
,
required
=
false
)
String
itemSku
,
@RequestParam
(
value
=
"itemPrice"
,
required
=
false
)
Double
itemPrice
,
@RequestParam
(
value
=
"web"
,
required
=
false
)
String
web
)
throws
IOException
,
URISyntaxException
,
ExecutionException
,
InterruptedException
,
TimeoutException
{
TbCfUserInfo
user
=
this
.
user
.
user
();
String
userId
=
user
.
getUserId
();
...
...
@@ -188,21 +191,29 @@ public class OrderController extends Controller {
return
new
Result
<>(
v_code
,
"Empty body"
);
List
<
TbCfCartRecordR
>
allByUserId
=
new
ArrayList
<>();
if
(!
noPayNow
)
{
Optional
<
TbCfStationItem
>
byId
=
itemRepository
.
findById
(
itemId
);
if
(!
byId
.
isPresent
())
return
new
Result
<>(
ResultCodeEnum
.
SERVICE_ERROR
.
getCode
(),
"Missing information !"
);
TbCfStationItem
stationItem
=
byId
.
get
();
allByUserId
.
add
(
getCart
(
stationItem
,
itemSku
,
itemNum
,
itemPrice
));
//减库存 Inventory reduction
subCount
(
itemId
,
itemNum
);
allByUserId
.
add
(
getCart
(
stationItem
,
itemSku
,
itemNum
,
itemPrice
));
}
else
{
System
.
out
.
println
(
Arrays
.
toString
(
tbCfOrder
.
getIds
()));
allByUserId
=
cartRepository
.
findAllByCartRecordIdIn
(
tbCfOrder
.
getIds
());
allByUserId
.
forEach
(
cart
->
{
String
id
=
cart
.
getItemId
();
Integer
num
=
cart
.
getItemNum
();
subCount
(
id
,
num
);
});
}
String
addressId
=
tbCfOrder
.
getDeliveryAddressId
();
if
(
addressId
==
null
||
addressId
.
isEmpty
())
return
new
Result
<>(
v_code
,
"Address id is required"
);
...
...
@@ -241,7 +252,7 @@ public class OrderController extends Controller {
Optional
<
TbCfToicoupon
>
couponOptional
=
toicouponRepository
.
findById
(
toitableId
);
if
(
couponOptional
.
isPresent
()
)
{
if
(
couponOptional
.
isPresent
())
{
tbCfToicoupon
=
couponOptional
.
get
();
TbCfCoupon
coupon
=
tbCfToicoupon
.
getCoupon
();
order
.
setCoupon
(
coupon
);
...
...
@@ -258,11 +269,11 @@ public class OrderController extends Controller {
}
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
order
.
getItemOrderListFromCartList
(
allByUserId
,
itemRepository
);
TbCfOrder
save
=
repository
.
save
(
order
);
if
(
tbCfToicoupon
!=
null
)
{
if
(
tbCfToicoupon
!=
null
)
{
tbCfToicoupon
.
setEnableFlag
(
0
);
toicouponRepository
.
save
(
tbCfToicoupon
);
}
...
...
@@ -278,13 +289,24 @@ public class OrderController extends Controller {
// implementation of coupon use
if
(
user
.
hasFcm
()
)
{
sendNotification
(
user
.
getFcm
(),
"Order alert !!"
,
"Order of $"
+
order
.
getRealityPay
()+
" has been created , proceed with payment"
);
if
(
user
.
hasFcm
())
{
sendNotification
(
user
.
getFcm
(),
"Order alert !!"
,
"Order of $"
+
order
.
getRealityPay
()
+
" has been created , proceed with payment"
);
}
return
new
Result
<>(
save
);
}
//减库存 Inventory reduction
public
void
subCount
(
String
itemId
,
Integer
num
)
{
logger
.
info
(
"减库存操作开始..."
);
Optional
<
TbCfStationItem
>
itemOptional
=
itemRepository
.
findById
(
itemId
);
if
(
itemOptional
.
isPresent
())
{
TbCfStationItem
item
=
itemOptional
.
get
();
logger
.
info
(
"商品["
+
item
.
getItemId
()
+
"]原库存:"
+
item
.
getItemCount
()
+
",购买数量:"
+
num
+
",现库存:"
+
(
item
.
getItemCount
()
-
num
));
item
.
setItemCount
(
item
.
getItemCount
()
-
num
);
}
}
@GetMapping
public
Result
getUserOrderList
(
@RequestParam
(
value
=
"num"
,
defaultValue
=
"0"
)
Integer
pageNum
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"20"
)
Integer
pageSize
,
...
...
@@ -294,7 +316,7 @@ public class OrderController extends Controller {
)
{
TbCfUserInfo
user
=
this
.
user
.
user
();
Page
<
OrderCount
>
list
=
repository
.
findAllByUserId
(
user
.
getUserId
(),
user
,
PageRequest
.
of
(
pageNum
,
pageSize
,
sort
(
sort
)));
list
.
forEach
(
v
->
v
.
getOrder
().
setCommentCount
(
v
.
getCommented
()));
list
.
forEach
(
v
->
v
.
getOrder
().
setCommentCount
(
v
.
getCommented
()));
Page
<
TbCfOrder
>
map
=
list
.
map
(
OrderCount:
:
getOrder
);
return
new
Result
<>(
map
);
}
...
...
@@ -310,9 +332,9 @@ public class OrderController extends Controller {
order
.
setOrderStatus
(
OrderStatusEnum
.
CLOSE
.
getValue
());
order
.
setRemarkInfo
(
reason
);
if
(
order
.
getCouponId
()
!=
null
)
{
if
(
order
.
getCouponId
()
!=
null
)
{
Optional
<
TbCfToicoupon
>
couponOptional
=
toicouponRepository
.
findById
(
order
.
getCouponId
());
if
(
couponOptional
.
isPresent
()
)
{
if
(
couponOptional
.
isPresent
())
{
TbCfToicoupon
toicoupon
=
couponOptional
.
get
();
toicoupon
.
setEnableFlag
(
1
);
toicouponRepository
.
save
(
toicoupon
);
...
...
@@ -360,8 +382,8 @@ public class OrderController extends Controller {
boolean
exists
=
commentRepository
.
existsByUserUserIdAndItemId
(
userId
,
itemId
);
if
(
exists
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Already reviewed this product!"
);
if
(
exists
)
{
return
new
Result
(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Already reviewed this product!"
);
}
comment
.
setItemId
(
itemId
);
...
...
@@ -377,7 +399,7 @@ public class OrderController extends Controller {
}
TbCfItemComment
save
=
commentRepository
.
save
(
comment
);
return
new
Result
<>(
save
,
"Comment on success!"
);
return
new
Result
<>(
save
,
"Comment on success!"
);
}
private
Sort
sort
(
String
order
)
{
...
...
@@ -387,7 +409,7 @@ public class OrderController extends Controller {
@GetMapping
(
"/details/{orderId}"
)
public
Result
getOrderDetails
(
@PathVariable
(
"orderId"
)
String
orderId
){
public
Result
getOrderDetails
(
@PathVariable
(
"orderId"
)
String
orderId
)
{
Optional
<
TbCfOrder
>
optionalTbCfOrder
=
repository
.
findById
(
orderId
);
return
optionalTbCfOrder
.
map
(
order
->
new
Result
<>(
order
,
"Order found !"
)).
orElseGet
(()
->
new
Result
<>(
ResultCodeEnum
.
VALIDATE_ERROR
.
getCode
(),
"Order not found"
));
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论