Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
2d935462
Commit
2d935462
authored
Nov 25, 2019
by
周健威
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master-zjw' into dev
parents
c118b35a
b7e84840
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
116 additions
and
52 deletions
+116
-52
OrderRentVehicleService.java
.../xxfc/platform/order/service/OrderRentVehicleService.java
+116
-52
No files found.
xx-order/xx-order-server/src/main/java/com/xxfc/platform/order/service/OrderRentVehicleService.java
View file @
2d935462
...
...
@@ -31,6 +31,7 @@ import com.xxfc.platform.order.pojo.order.VehicleItemDTO;
import
com.xxfc.platform.order.pojo.price.RentVehiclePriceVO
;
import
com.xxfc.platform.universal.constant.DictionaryKey
;
import
com.xxfc.platform.universal.feign.ThirdFeign
;
import
com.xxfc.platform.vehicle.common.RestResponse
;
import
com.xxfc.platform.vehicle.constant.AccompanyingItemType
;
import
com.xxfc.platform.vehicle.entity.BranchCompany
;
import
com.xxfc.platform.vehicle.entity.VehicleBookRecord
;
...
...
@@ -143,75 +144,138 @@ public class OrderRentVehicleService extends AbstractOrderHandle<OrderRentVehicl
//设置订单名称
bo
.
getOrder
().
setName
(
bo
.
getVehicleModel
().
getName
());
//是否有使用会员权益 则调用接口触发新增消费记录次数
//扣减免费天数
if
(
SYS_TRUE
.
equals
(
bo
.
getOrder
().
getHasMemberRight
()))
{
if
(
null
==
bo
.
getFreeDays
())
{
bo
.
setFreeDays
(
0
);
}
int
result
=
userFeign
.
memberDays
(
bo
.
getAppUserDTO
().
getUserid
(),
bo
.
getFreeDays
(),
UserFeign
.
MEMBER_DAYS_LOCK
);
if
(
result
<
0
)
{
throw
new
BaseException
(
ResultCode
.
FAILED_CODE
);
}
}
OrderItem
vehicleModelItem
=
bo
.
getItemByTypeEnum
(
ItemTypeEnum
.
VEHICLE_MODEL
);
BigDecimal
amount
=
vehicleModelItem
.
getTotalAmount
();
//如果有使用优惠券,则扣减
if
(
BigDecimal
.
ZERO
.
compareTo
(
bo
.
getOrder
().
getCouponAmount
())
<
0
)
{
activityFeign
.
use
(
bo
.
getAppUserDTO
().
getUserid
(),
Convert
.
toList
(
String
.
class
,
bo
.
getOrder
().
getCouponTickerNos
()),
bo
.
getOrder
().
getNo
(),
channel
,
amount
,
ActivityFeign
.
TYPE_USE
);
}
//分布式事务执行标记
Integer
cloudTransact
=
0
;
//插入随声物品item
List
<
OrderAccompanyDTO
>
oads
=
new
ArrayList
<
OrderAccompanyDTO
>();
List
<
AccompanyingItemVo
>
accompanyingItemList
=
vehicleFeign
.
listAccompanyingItem
().
getData
();
try
{
//插入随声物品item
List
<
OrderAccompanyDTO
>
oads
=
new
ArrayList
<
OrderAccompanyDTO
>();
List
<
AccompanyingItemVo
>
accompanyingItemList
=
vehicleFeign
.
listAccompanyingItem
().
getData
();
// Map<String, AccompanyingItemVo> accompanyingItemMap = vehicleFeign.listAccompanyingItem().getData()
// .parallelStream().collect(Collectors.toMap(en -> en.getId().toString(), en -> en));
if
(
null
==
bo
.
getAccompanyItems
())
{
bo
.
setAccompanyItems
(
new
ArrayList
<
OrderAccompanyDTO
>());
}
Map
<
String
,
OrderAccompanyDTO
>
orderAccompanyDTOMap
=
bo
.
getAccompanyItems
()
.
parallelStream
().
collect
(
Collectors
.
toMap
(
en
->
en
.
getId
().
toString
(),
en
->
en
));
for
(
AccompanyingItemVo
aiv
:
accompanyingItemList
)
{
if
(
AccompanyingItemType
.
TOOL
.
getCode
().
equals
(
aiv
.
getType
())
||
AccompanyingItemType
.
EQUIPMENT
.
getCode
().
equals
(
aiv
.
getType
()))
{
OrderAccompanyDTO
orderAccompanyDTO
=
BeanUtil
.
toBean
(
aiv
,
OrderAccompanyDTO
.
class
);
orderAccompanyDTO
.
setUnitPrice
(
aiv
.
getPrice
());
orderAccompanyDTO
.
setNum
(
aiv
.
getNumber
());
oads
.
add
(
orderAccompanyDTO
);
}
else
{
OrderAccompanyDTO
orderAccompanyDTO
=
orderAccompanyDTOMap
.
get
(
aiv
.
getId
().
toString
());
if
(
null
!=
orderAccompanyDTO
)
{
BeanUtil
.
copyProperties
(
aiv
,
orderAccompanyDTO
);
if
(
null
==
bo
.
getAccompanyItems
())
{
bo
.
setAccompanyItems
(
new
ArrayList
<
OrderAccompanyDTO
>());
}
Map
<
String
,
OrderAccompanyDTO
>
orderAccompanyDTOMap
=
bo
.
getAccompanyItems
()
.
parallelStream
().
collect
(
Collectors
.
toMap
(
en
->
en
.
getId
().
toString
(),
en
->
en
));
for
(
AccompanyingItemVo
aiv
:
accompanyingItemList
)
{
if
(
AccompanyingItemType
.
TOOL
.
getCode
().
equals
(
aiv
.
getType
())
||
AccompanyingItemType
.
EQUIPMENT
.
getCode
().
equals
(
aiv
.
getType
()))
{
OrderAccompanyDTO
orderAccompanyDTO
=
BeanUtil
.
toBean
(
aiv
,
OrderAccompanyDTO
.
class
);
orderAccompanyDTO
.
setUnitPrice
(
aiv
.
getPrice
());
orderAccompanyDTO
.
setNum
(
aiv
.
getNumber
());
oads
.
add
(
orderAccompanyDTO
);
}
else
{
OrderAccompanyDTO
orderAccompanyDTO
=
orderAccompanyDTOMap
.
get
(
aiv
.
getId
().
toString
());
if
(
null
!=
orderAccompanyDTO
)
{
BeanUtil
.
copyProperties
(
aiv
,
orderAccompanyDTO
);
orderAccompanyDTO
.
setUnitPrice
(
aiv
.
getPrice
());
oads
.
add
(
orderAccompanyDTO
);
}
}
}
}
bo
.
setAccompanyItems
(
oads
);
bo
.
setAccompanyItems
(
oads
);
//获取可用车辆
acquireVehicle
(
bo
,
null
,
null
);
//获取可用车辆
acquireVehicle
(
bo
,
null
,
null
);
cloudTransact
=
1
;
OrderItem
accompanyItem
=
orderItemBiz
.
initOrderItem
(
BigDecimal
.
ZERO
,
1
,
"随车物品"
,
null
,
ACCOMPANY
);
accompanyItem
.
setRealAmount
(
BigDecimal
.
ZERO
);
accompanyItem
.
setDetail
(
JSONUtil
.
toJsonStr
(
bo
.
getAccompanyItems
()));
accompanyItem
.
setOrderId
(
bo
.
getOrder
().
getId
());
orderItemBiz
.
insertSelective
(
accompanyItem
);
//添加随声物品项
OrderItem
accompanyItem
=
orderItemBiz
.
initOrderItem
(
BigDecimal
.
ZERO
,
1
,
"随车物品"
,
null
,
ACCOMPANY
);
accompanyItem
.
setRealAmount
(
BigDecimal
.
ZERO
);
accompanyItem
.
setDetail
(
JSONUtil
.
toJsonStr
(
bo
.
getAccompanyItems
()));
accompanyItem
.
setOrderId
(
bo
.
getOrder
().
getId
());
orderItemBiz
.
insertSelective
(
accompanyItem
);
//是否有使用会员权益 则调用接口触发新增消费记录次数
//扣减免费天数
useOrBackFreeDays
(
bo
,
UserFeign
.
MEMBER_DAYS_LOCK
);
cloudTransact
=
2
;
//设置后台系统创建人
if
(
StrUtil
.
isNotBlank
(
bo
.
getCrtUser
()))
{
bo
.
getOrder
().
setCrtUser
(
bo
.
getCrtUser
());
OrderItem
vehicleModelItem
=
bo
.
getItemByTypeEnum
(
ItemTypeEnum
.
VEHICLE_MODEL
);
BigDecimal
amount
=
vehicleModelItem
.
getTotalAmount
();
//如果有使用优惠券,则扣减
if
(
BigDecimal
.
ZERO
.
compareTo
(
bo
.
getOrder
().
getCouponAmount
())
<
0
)
{
activityFeign
.
use
(
bo
.
getAppUserDTO
().
getUserid
(),
Convert
.
toList
(
String
.
class
,
bo
.
getOrder
().
getCouponTickerNos
()),
bo
.
getOrder
().
getNo
(),
channel
,
amount
,
ActivityFeign
.
TYPE_USE
);
}
cloudTransact
=
3
;
//设置后台系统创建人
if
(
StrUtil
.
isNotBlank
(
bo
.
getCrtUser
()))
{
bo
.
getOrder
().
setCrtUser
(
bo
.
getCrtUser
());
}
super
.
handleDetail
(
bo
);
}
catch
(
Exception
e
)
{
//事务补偿处理
log
.
error
(
"cloudTransact : {}"
,
cloudTransact
);
RestResponse
<
Integer
>
restResponse
;
try
{
//判断分布式事务执行到哪里
switch
(
cloudTransact
)
{
case
1
:
//取消车辆预定
//未支付,拒绝之前的预约
errorRejectVehicle
(
bo
);
break
;
case
2
:
//取消车辆预定
//未支付,拒绝之前的预约
errorRejectVehicle
(
bo
);
useOrBackFreeDays
(
bo
,
UserFeign
.
MEMBER_DAYS_WITHDRAW
);
break
;
case
3
:
//取消车辆预定
//未支付,拒绝之前的预约
errorRejectVehicle
(
bo
);
//退还天数
useOrBackFreeDays
(
bo
,
UserFeign
.
MEMBER_DAYS_WITHDRAW
);
//退还优惠券
for
(
String
backCoupon
:
Convert
.
toList
(
String
.
class
,
bo
.
getOrder
().
getCouponTickerNos
()))
{
activityFeign
.
cancelUse
(
backCoupon
);
}
break
;
default
:
break
;
}
}
catch
(
Exception
ex
)
{
log
.
error
(
ex
.
getMessage
(),
ex
);
}
finally
{
throw
e
;
}
}
super
.
handleDetail
(
bo
);
//发送定时取消订单(数据字典设置--5分钟)
rabbitProduct
.
sendDelayMessage
(
bo
.
getOrder
(),
autoCancelTime
);
}
private
void
useOrBackFreeDays
(
RentVehicleBO
bo
,
int
memberDaysWithdraw
)
{
//退还天数
if
(
SYS_TRUE
.
equals
(
bo
.
getOrder
().
getHasMemberRight
()))
{
if
(
null
==
bo
.
getFreeDays
())
{
bo
.
setFreeDays
(
0
);
}
int
result
=
userFeign
.
memberDays
(
bo
.
getAppUserDTO
().
getUserid
(),
bo
.
getFreeDays
(),
memberDaysWithdraw
);
if
(
result
<
0
)
{
throw
new
BaseException
(
ResultCode
.
FAILED_CODE
);
}
}
}
private
void
errorRejectVehicle
(
RentVehicleBO
bo
)
{
//取消车辆预定
//未支付,拒绝之前的预约
RestResponse
<
Integer
>
restResponse
=
vehicleFeign
.
rentRejectVehicleBooking
(
bo
.
getBookRecordId
());
log
.
info
(
"下单失败,拒绝预约{}, 结果: {}"
,
bo
.
getBookRecordId
(),
restResponse
.
toString
());
}
@Override
public
void
handleCalculate
(
RentVehicleBO
bo
)
{
RentVehiclePriceVO
rvpv
=
calculatePrice
(
bo
);
...
...
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