Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
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
pseer
gxpt_ht
Commits
524b139a
Commit
524b139a
authored
Jul 17, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化订单查询接口
parent
ad8ed8a4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
64 deletions
+101
-64
SOrderServiceImpl.java
...ain/java/share/system/service/impl/SOrderServiceImpl.java
+101
-64
No files found.
share-system/src/main/java/share/system/service/impl/SOrderServiceImpl.java
View file @
524b139a
...
...
@@ -354,34 +354,38 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
public
TableDataInfoVo
pageList
(
SOrder
sOrder
)
{
List
<
SOrder
>
sOrders
=
selectSOrderList
(
sOrder
);
List
<
SOrderVo
>
sOrderVos
=
convertDosToVos
(
sOrders
);
BigDecimal
totalAmount
=
new
BigDecimal
(
"0.00"
)
;
BigDecimal
amount
=
new
BigDecimal
(
"0.00"
)
;
final
BigDecimal
[]
totalAmount
=
{
new
BigDecimal
(
"0.00"
)}
;
final
BigDecimal
[]
amount
=
{
new
BigDecimal
(
"0.00"
)}
;
//优惠卷售卖总金额
final
BigDecimal
[]
totalSalesAmount
=
{
new
BigDecimal
(
"0.00"
)};
//申请退款总金额
BigDecimal
totalRefundAmount
=
new
BigDecimal
(
"0.00"
)
;
final
BigDecimal
[]
totalRefundAmount
=
{
new
BigDecimal
(
"0.00"
)}
;
//实际退款总金额
BigDecimal
totalRealRefundAmount
=
new
BigDecimal
(
"0.00"
);
List
<
SConsumerCoupon
>
sConsumerCoupons
=
consumerCouponService
.
queryList
();
final
BigDecimal
[]
totalRealRefundAmount
=
{
new
BigDecimal
(
"0.00"
)};
Map
<
Long
,
SConsumerCoupon
>
couponMap
=
consumerCouponService
.
listByIds
(
sOrders
.
stream
().
map
(
SOrder:
:
getCouponId
).
distinct
().
collect
(
Collectors
.
toList
()))
.
stream
().
collect
(
Collectors
.
toMap
(
SConsumerCoupon:
:
getId
,
s
->
s
));
if
(
CollectionUtils
.
isNotEmpty
(
sOrderVos
))
{
for
(
SOrderVo
item
:
sOrderVos
)
{
totalAmount
=
totalAmount
.
add
(
item
.
getTotalPrice
());
amount
=
amount
.
add
(
item
.
getPayPrice
());
sConsumerCoupons
.
stream
().
filter
(
sConsumerCoupon
->
sConsumerCoupon
.
getId
().
equals
(
item
.
getCouponId
())).
findFirst
().
ifPresent
(
sConsumerCoupon
->
{
item
.
setCouponPayPrice
(
sConsumerCoupon
.
getCouponPayPrice
());
item
.
setPlatformType
(
sConsumerCoupon
.
getPlatformType
());
if
(
sConsumerCoupon
.
getPlatformType
().
equals
(
PlatformTypeEnum
.
MEITUAN
.
getCode
()))
{
item
.
setCouponSkuId
(
String
.
valueOf
(
sConsumerCoupon
.
getDealgroupId
()));
}
else
if
(
sConsumerCoupon
.
getPlatformType
().
equals
(
PlatformTypeEnum
.
TIKTOK
.
getCode
()))
{
item
.
setCouponSkuId
(
String
.
valueOf
(
sConsumerCoupon
.
getTiktokSkuId
()));
sOrderVos
.
stream
().
forEach
(
item
->
{
totalAmount
[
0
]
=
totalAmount
[
0
].
add
(
item
.
getTotalPrice
());
amount
[
0
]
=
amount
[
0
].
add
(
item
.
getPayPrice
());
if
(
Objects
.
nonNull
(
item
.
getCouponId
()))
{
SConsumerCoupon
userCoupon
=
couponMap
.
get
(
item
.
getCouponId
());
if
(
userCoupon
!=
null
)
{
item
.
setCouponPayPrice
(
userCoupon
.
getCouponPayPrice
());
item
.
setPlatformType
(
userCoupon
.
getPlatformType
());
if
(
userCoupon
.
getPlatformType
().
equals
(
PlatformTypeEnum
.
MEITUAN
.
getCode
()))
{
item
.
setCouponSkuId
(
String
.
valueOf
(
userCoupon
.
getDealgroupId
()));
}
else
if
(
userCoupon
.
getPlatformType
().
equals
(
PlatformTypeEnum
.
TIKTOK
.
getCode
()))
{
item
.
setCouponSkuId
(
String
.
valueOf
(
userCoupon
.
getTiktokSkuId
()));
}
totalSalesAmount
[
0
]
=
totalSalesAmount
[
0
].
add
(
ObjectUtil
.
isEmpty
(
userCoupon
.
getCouponPayPrice
())
?
new
BigDecimal
(
"0.00"
)
:
userCoupon
.
getCouponPayPrice
());
}
totalSalesAmount
[
0
]
=
totalSalesAmount
[
0
].
add
(
ObjectUtil
.
isEmpty
(
sConsumerCoupon
.
getCouponPayPrice
())
?
new
BigDecimal
(
"0.00"
)
:
sConsumerCoupon
.
getCouponPayPrice
());
});
}
if
(
item
.
getPayStatus
().
equals
(
YesNoEnum
.
yes
.
getIndex
())
&&
item
.
getRefundStatus
().
equals
(
RefundStatusEnum
.
REFUNDED
.
getCode
()))
{
totalRefundAmount
=
totalRefundAmount
.
add
(
ObjectUtil
.
isEmpty
(
item
.
getPayPrice
())
?
new
BigDecimal
(
"0.00"
)
:
item
.
getPayPrice
());
totalRealRefundAmount
=
totalRealRefundAmount
.
add
(
ObjectUtil
.
isEmpty
(
item
.
getRefundPrice
())
?
new
BigDecimal
(
"0.00"
)
:
item
.
getRefundPrice
());
totalRefundAmount
[
0
]
=
totalRefundAmount
[
0
]
.
add
(
ObjectUtil
.
isEmpty
(
item
.
getPayPrice
())
?
new
BigDecimal
(
"0.00"
)
:
item
.
getPayPrice
());
totalRealRefundAmount
[
0
]
=
totalRealRefundAmount
[
0
]
.
add
(
ObjectUtil
.
isEmpty
(
item
.
getRefundPrice
())
?
new
BigDecimal
(
"0.00"
)
:
item
.
getRefundPrice
());
}
}
}
);
}
sOrderVos
.
sort
(
Comparator
.
comparing
(
SOrderVo:
:
getCreateTime
).
reversed
());
PageDomain
pageDomain
=
TableSupport
.
buildPageRequest
();
...
...
@@ -395,11 +399,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
tableDataInfo
.
setTotal
(
sOrderVos
.
size
());
tableDataInfo
.
setCode
(
200
);
tableDataInfo
.
setMsg
(
"查询成功"
);
tableDataInfo
.
setTotalAmount
(
totalAmount
);
tableDataInfo
.
setAmount
(
amount
);
tableDataInfo
.
setTotalAmount
(
totalAmount
[
0
]
);
tableDataInfo
.
setAmount
(
amount
[
0
]
);
tableDataInfo
.
setTotalSalesAmount
(
totalSalesAmount
[
0
]);
tableDataInfo
.
setTotalRefundAmount
(
totalRefundAmount
);
tableDataInfo
.
setTotalRealRefundAmount
(
totalRealRefundAmount
);
tableDataInfo
.
setTotalRefundAmount
(
totalRefundAmount
[
0
]
);
tableDataInfo
.
setTotalRealRefundAmount
(
totalRealRefundAmount
[
0
]
);
return
tableDataInfo
;
}
...
...
@@ -1946,55 +1950,88 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private
List
<
SOrderVo
>
convertDosToVos
(
List
<
SOrder
>
orderList
)
{
List
<
SOrderVo
>
voList
=
new
ArrayList
<>();
if
(
CollectionUtils
.
isNotEmpty
(
orderList
))
{
// 使用Map缓存查询结果,减少重复查询
Map
<
Long
,
SStore
>
storeMap
=
storeService
.
listByIds
(
orderList
.
stream
().
map
(
SOrder:
:
getStoreId
).
collect
(
Collectors
.
toSet
()))
.
stream
().
collect
(
Collectors
.
toMap
(
SStore:
:
getId
,
s
->
s
));
Map
<
Long
,
SRoom
>
roomMap
=
roomService
.
listByIds
(
orderList
.
stream
().
map
(
SOrder:
:
getRoomId
).
collect
(
Collectors
.
toSet
()))
.
stream
().
collect
(
Collectors
.
toMap
(
SRoom:
:
getId
,
s
->
s
));
Map
<
Long
,
SConsumerCoupon
>
couponMap
=
consumerCouponService
.
queryByIds
(
orderList
.
stream
().
map
(
SOrder:
:
getCouponId
).
distinct
().
collect
(
Collectors
.
toList
()))
.
stream
().
collect
(
Collectors
.
toMap
(
SConsumerCoupon:
:
getId
,
s
->
s
));
Map
<
Long
,
SPack
>
packMap
=
packService
.
listByIds
(
orderList
.
stream
().
map
(
SOrder:
:
getPackId
).
distinct
().
collect
(
Collectors
.
toList
()))
.
stream
().
collect
(
Collectors
.
toMap
(
SPack:
:
getId
,
s
->
s
));
orderList
.
forEach
(
o
->
{
SOrderVo
vo
=
new
SOrderVo
();
BeanUtils
.
copyProperties
(
o
,
vo
);
SStore
store
=
storeMap
.
get
(
vo
.
getStoreId
());
if
(
store
!=
null
)
{
vo
.
setStoreName
(
store
.
getName
());
vo
.
setAddress
(
store
.
getAddress
());
try
{
// 使用Map缓存查询结果,减少重复查询
// 合并查询逻辑以减少N+1查询问题
Set
<
Long
>
storeIds
=
orderList
.
stream
().
map
(
SOrder:
:
getStoreId
).
collect
(
Collectors
.
toSet
());
Set
<
Long
>
roomIds
=
orderList
.
stream
().
map
(
SOrder:
:
getRoomId
).
distinct
().
collect
(
Collectors
.
toSet
());
Set
<
Long
>
couponIds
=
orderList
.
stream
().
map
(
SOrder:
:
getCouponId
).
distinct
().
collect
(
Collectors
.
toSet
());
Set
<
Long
>
packIds
=
orderList
.
stream
().
map
(
SOrder:
:
getPackId
).
distinct
().
collect
(
Collectors
.
toSet
());
Map
<
Long
,
SStore
>
storeMap
;
if
(!
storeIds
.
isEmpty
())
{
List
<
SStore
>
stores
=
storeService
.
listByIds
(
storeIds
);
storeMap
=
stores
.
stream
().
collect
(
Collectors
.
toMap
(
SStore:
:
getId
,
s
->
s
));
}
else
{
storeMap
=
new
HashMap
<>();
}
SRoom
room
=
roomMap
.
get
(
vo
.
getRoomId
());
if
(
room
!=
null
)
{
vo
.
setRoomName
(
room
.
getName
());
vo
.
setRoomImages
(
room
.
getImages
());
vo
.
setRoomType
(
room
.
getRoomType
());
vo
.
setRoomTypeName
(
RoomType
.
getNameByCode
(
room
.
getRoomType
()));
Map
<
Long
,
SRoom
>
roomMap
;
if
(!
roomIds
.
isEmpty
())
{
List
<
SRoom
>
rooms
=
roomService
.
listByIds
(
roomIds
);
roomMap
=
rooms
.
stream
().
collect
(
Collectors
.
toMap
(
SRoom:
:
getId
,
s
->
s
));
}
else
{
roomMap
=
new
HashMap
<>();
}
if
(
Objects
.
nonNull
(
vo
.
getCouponId
()))
{
SConsumerCoupon
userCoupon
=
couponMap
.
get
(
vo
.
getCouponId
());
if
(
userCoupon
!=
null
)
{
// 判断是否可以退款
vo
.
setIsRefund
(
isRefund
(
vo
,
userCoupon
));
vo
.
setCouponName
(
userCoupon
.
getName
());
}
else
{
// 如果优惠券为空,则调用isRefund方法时需要传入null
vo
.
setIsRefund
(
isRefund
(
vo
,
null
));
}
Map
<
Long
,
SConsumerCoupon
>
couponMap
;
if
(!
couponIds
.
isEmpty
())
{
List
<
SConsumerCoupon
>
coupons
=
consumerCouponService
.
listByIds
(
couponIds
);
couponMap
=
coupons
.
stream
().
collect
(
Collectors
.
toMap
(
SConsumerCoupon:
:
getId
,
s
->
s
));
}
else
{
// 判断是否可以退款
vo
.
setIsRefund
(
isRefund
(
vo
,
null
));
couponMap
=
new
HashMap
<>();
}
SPack
pack
=
packMap
.
get
(
vo
.
getPackId
());
if
(
pack
!=
null
)
{
vo
.
setPackName
(
pack
.
getName
());
Map
<
Long
,
SPack
>
packMap
;
if
(!
packIds
.
isEmpty
())
{
List
<
SPack
>
packs
=
packService
.
listByIds
(
packIds
);
packMap
=
packs
.
stream
().
collect
(
Collectors
.
toMap
(
SPack:
:
getId
,
s
->
s
));
}
else
{
packMap
=
new
HashMap
<>();
}
voList
.
add
(
vo
);
});
orderList
.
forEach
(
o
->
{
SOrderVo
vo
=
new
SOrderVo
();
BeanUtils
.
copyProperties
(
o
,
vo
);
SStore
store
=
storeMap
.
get
(
vo
.
getStoreId
());
if
(
store
!=
null
)
{
vo
.
setStoreName
(
store
.
getName
());
vo
.
setAddress
(
store
.
getAddress
());
}
SRoom
room
=
roomMap
.
get
(
vo
.
getRoomId
());
if
(
room
!=
null
)
{
vo
.
setRoomName
(
room
.
getName
());
vo
.
setRoomImages
(
room
.
getImages
());
vo
.
setRoomType
(
room
.
getRoomType
());
vo
.
setRoomTypeName
(
RoomType
.
getNameByCode
(
room
.
getRoomType
()));
}
if
(
Objects
.
nonNull
(
vo
.
getCouponId
()))
{
SConsumerCoupon
userCoupon
=
couponMap
.
get
(
vo
.
getCouponId
());
if
(
userCoupon
!=
null
)
{
vo
.
setIsRefund
(
isRefund
(
vo
,
userCoupon
));
vo
.
setCouponName
(
userCoupon
.
getName
());
}
else
{
vo
.
setIsRefund
(
isRefund
(
vo
,
null
));
}
}
else
{
vo
.
setIsRefund
(
isRefund
(
vo
,
null
));
}
SPack
pack
=
packMap
.
get
(
vo
.
getPackId
());
if
(
pack
!=
null
)
{
vo
.
setPackName
(
pack
.
getName
());
}
voList
.
add
(
vo
);
});
}
catch
(
Exception
e
)
{
// 记录日志并处理异常,例如返回错误信息或执行其他错误处理逻辑
// log.error("订单数据转换异常", e);
throw
new
RuntimeException
(
"订单数据转换异常"
,
e
);
}
}
return
voList
;
}
@Override
public
String
openDoor
(
String
orderNo
)
{
LambdaQueryWrapper
<
SOrder
>
orderLambdaQueryWrapper
=
new
LambdaQueryWrapper
<>();
...
...
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