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
230db194
Commit
230db194
authored
Nov 06, 2019
by
libin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
租车日历价格
parent
1f8665dd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
22 deletions
+69
-22
VehicleModelCalendarPriceBiz.java
...fc/platform/vehicle/biz/VehicleModelCalendarPriceBiz.java
+64
-18
VehicleModelCalendarPriceController.java
...orm/vehicle/rest/VehicleModelCalendarPriceController.java
+5
-4
No files found.
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleModelCalendarPriceBiz.java
View file @
230db194
...
...
@@ -5,6 +5,9 @@ import com.github.wxiaoqi.security.admin.entity.BaseUserMember;
import
com.github.wxiaoqi.security.admin.entity.BaseUserMemberLevel
;
import
com.github.wxiaoqi.security.admin.feign.UserFeign
;
import
com.github.wxiaoqi.security.common.biz.BaseBiz
;
import
com.xxfc.platform.universal.constant.DictionaryKey
;
import
com.xxfc.platform.universal.entity.Dictionary
;
import
com.xxfc.platform.universal.feign.ThirdFeign
;
import
com.xxfc.platform.vehicle.entity.VehicleModelCalendarPrice
;
import
com.xxfc.platform.vehicle.mapper.VehicleModelCalendarPriceMapper
;
import
com.xxfc.platform.vehicle.pojo.dto.VehicleModelCalendarPriceDTO
;
...
...
@@ -32,6 +35,8 @@ import java.util.concurrent.atomic.AtomicReference;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
import
static
com
.
xxfc
.
platform
.
universal
.
constant
.
DictionaryKey
.
APP_ORDER
;
/**
* @author libin
* @version 1.0
...
...
@@ -49,12 +54,13 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
private
static
final
Integer
DEFAULT_FREE_DAYS
=
1
;
private
static
final
Integer
DEFAULT_MEMBER_LEVEL
=
0
;
private
static
final
String
PRICE_VAL
=
"price"
;
private
static
final
String
BASE_PRICE_VAL
=
"basePrice"
;
private
static
final
String
BASE_PRICE_VAL
=
"basePrice"
;
private
static
final
String
DAYS_VAL
=
"freeDays"
;
private
final
VehicleModelHolidayPriceBiz
vehicleModelHolidayPriceBiz
;
private
final
VehicleModelBiz
vehicleModelBiz
;
private
final
UserFeign
userFeign
;
private
final
ThirdFeign
thirdFeign
;
/**
...
...
@@ -138,7 +144,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicleModelDayPriceVo
.
setMultiple
(
multiple
);
BigDecimal
aPrice
=
isNullOfVehicleModelPrice
?
BigDecimal
.
ZERO
:
vehicleModelCalendarPriceMap
.
get
(
vehicleModelDTO
.
getVehicleModelId
()).
getPrice
();
vehicleModelDayPriceVo
.
setPrice
(
aPrice
);
Integer
level
=
isNullOfVehicleModelPrice
?
null
:
vehicleModelCalendarPriceMap
.
get
(
vehicleModelDTO
.
getVehicleModelId
()).
getLevel
();
Integer
level
=
isNullOfVehicleModelPrice
?
null
:
vehicleModelCalendarPriceMap
.
get
(
vehicleModelDTO
.
getVehicleModelId
()).
getLevel
();
vehicleModelDayPriceVo
.
setLevel
(
level
);
vehicleModelDayPriceVos
.
add
(
vehicleModelDayPriceVo
);
}
...
...
@@ -176,7 +182,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
Map
<
Date
,
Optional
<
VehicleModelCalendarPriceSaveDTO
>>
result
=
vehicleModelCalendarPriceSaveDTOS
.
stream
()
.
collect
(
Collectors
.
groupingBy
(
VehicleModelCalendarPriceSaveDTO:
:
getVehicleModelDay
,
Collectors
.
maxBy
(
Comparator
.
comparing
(
VehicleModelCalendarPriceSaveDTO:
:
getId
))));
vehicleModelCalendarPriceSaveDTOS
=
result
.
values
().
stream
().
map
(
x
->
x
.
orElseGet
(
null
)).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
vehicleModelCalendarPriceSaveDTOS
=
result
.
values
().
stream
().
map
(
x
->
x
.
orElseGet
(
null
)).
filter
(
Objects:
:
nonNull
).
collect
(
Collectors
.
toList
());
return
vehicleModelCalendarPriceSaveDTOS
;
}
...
...
@@ -205,21 +211,61 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
public
List
<
VehicleModelCalendarPriceDTO
>
listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId
(
Date
startDate
,
Date
endDate
,
Integer
vehicleModelId
,
Integer
userId
)
{
LocalDate
startLocalDate
=
DateUtils
.
dateToLocalDate
(
startDate
);
LocalDate
endLocalDate
=
DateUtils
.
dateToLocalDate
(
endDate
);
boolean
isSelect
=
false
;
//处理后延伸的开始时间
AtomicReference
<
Date
>
startReference
=
new
AtomicReference
<>(
startDate
);
//处理后延伸的结束时间
AtomicReference
<
Date
>
endReference
=
new
AtomicReference
<>(
endDate
);
transformStartDateAndEndDate
(
startReference
,
endReference
);
List
<
VehicleModelCalendarPriceDTO
>
vehicleModelCalendarPrice
=
findVehicleModelCalendarPrice
(
startReference
.
get
(),
endReference
.
get
(),
vehicleModelId
,
userId
);
for
(
VehicleModelCalendarPriceDTO
vehicleModelCalendarPriceDTO
:
vehicleModelCalendarPrice
)
{
Integer
days
=
getIncludeDays
(
startDate
.
getTime
(),
endDate
.
getTime
());
for
(
int
i
=
0
,
y
=
0
;
i
<
vehicleModelCalendarPrice
.
size
();
i
++)
{
VehicleModelCalendarPriceDTO
vehicleModelCalendarPriceDTO
=
vehicleModelCalendarPrice
.
get
(
i
);
LocalDate
current_date
=
DateUtils
.
dateToLocalDate
(
vehicleModelCalendarPriceDTO
.
getDate
());
boolean
isSelect
=
(
current_date
.
isAfter
(
startLocalDate
)
&&
current_date
.
isBefore
(
endLocalDate
))
||
current_date
.
isEqual
(
startLocalDate
)
||
current_date
.
isEqual
(
endLocalDate
);
if
(
y
==
0
)
{
isSelect
=
(
current_date
.
isAfter
(
startLocalDate
)
&&
current_date
.
isBefore
(
endLocalDate
))
||
current_date
.
isEqual
(
startLocalDate
)
||
current_date
.
isEqual
(
endLocalDate
);
}
if
(
isSelect
)
{
if
(
y
<
days
)
{
vehicleModelCalendarPriceDTO
.
setIsSelect
(
isSelect
?
true
:
false
);
y
++;
}
}
}
return
vehicleModelCalendarPrice
;
}
/**
* 计算包含多少天
*
* @param startLong
* @param endLong
* @return
*/
public
Integer
getIncludeDays
(
Long
startLong
,
Long
endLong
)
{
Map
<
String
,
Dictionary
>
dictionaryMap
=
thirdFeign
.
dictionaryGetAll4Map
().
getData
();
Long
hourLong
=
(
60L
*
60L
*
1000L
);
Long
dayLong
=
hourLong
*
24
;
Long
bufferLong
=
Long
.
valueOf
(
dictionaryMap
.
get
(
APP_ORDER
+
"_"
+
DictionaryKey
.
RENT_TIME_BUFFER
).
getDetail
())
*
hourLong
;
//计算:使用天数 当前时间 - 开始时间的0时0分0秒
Long
bookTimeLag
=
endLong
-
startLong
;
log
.
info
(
"bookTimeLag {}"
,
new
BigDecimal
(
bookTimeLag
+
""
));
log
.
info
(
"divide {}"
,
new
BigDecimal
((
24
*
60
*
60
*
1000
)
+
""
));
Integer
bookDays
=
new
BigDecimal
(
bookTimeLag
+
""
).
divide
(
new
BigDecimal
(
dayLong
+
""
),
0
,
RoundingMode
.
DOWN
).
intValue
();
Long
excess
=
bookTimeLag
%
dayLong
;
if
(
excess
>
bufferLong
)
{
bookDays
+=
1
;
}
if
(
0
==
bookDays
)
{
bookDays
=
1
;
}
return
bookDays
;
}
/**
* 日历价格查询
*
...
...
@@ -246,10 +292,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
BigDecimal
vehicle_base_price
=
new
BigDecimal
(
0
);
BigDecimal
vehicle_price
=
vehicleModelBiz
.
findVehicleModelPriceByVehicleModelId
(
vehicleModelId
);
vehicle_base_price
=
vehicle_base_price
.
add
(
vehicle_price
);
log
.
info
(
"用户id【{}】"
,
userId
);
log
.
info
(
"用户id【{}】"
,
userId
);
if
(
Objects
.
nonNull
(
userId
))
{
BaseUserMember
baseUserMember
=
userFeign
.
findBaseUserMemberByUserId
(
userId
);
log
.
info
(
"用户会员信息:【{}】"
,
baseUserMember
);
log
.
info
(
"用户会员信息:【{}】"
,
baseUserMember
);
discount
=
baseUserMember
==
null
?
discount
:
baseUserMember
.
getDiscount
();
memberLevel
=
baseUserMember
==
null
?
memberLevel
:
baseUserMember
.
getMemberLevel
();
}
...
...
@@ -319,10 +365,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
* @return
*/
public
Map
<
String
,
Object
>
transfromPriceAndFreeDaysByDate
(
Map
<
Date
,
VehicleModelHolidayPriceDTO
>
festivalDayMap
,
Date
current_date
,
BigDecimal
vehicle_price
,
Integer
discount
)
{
log
.
info
(
"参数:【{}==当前时间:{}==价格:{}==折扣:{}】"
,
festivalDayMap
,
current_date
,
vehicle_price
,
discount
);
log
.
info
(
"参数:【{}==当前时间:{}==价格:{}==折扣:{}】"
,
festivalDayMap
,
current_date
,
vehicle_price
,
discount
);
Map
<
String
,
Object
>
vehicle_price_days_map
=
new
HashMap
<>(
3
);
Integer
free_days
=
DEFAULT_FREE_DAYS
;
vehicle_price_days_map
.
put
(
BASE_PRICE_VAL
,
vehicle_price
);
vehicle_price_days_map
.
put
(
BASE_PRICE_VAL
,
vehicle_price
);
if
(
MapUtil
.
isNotEmpty
(
festivalDayMap
))
{
VehicleModelHolidayPriceDTO
vehicleModelHolidayPriceDTO
=
festivalDayMap
.
get
(
current_date
);
if
(
Objects
.
nonNull
(
vehicleModelHolidayPriceDTO
))
{
...
...
@@ -333,7 +379,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
vehicle_price
=
vehicle_price
.
multiply
(
new
BigDecimal
(
Objects
.
toString
(
discount
/
100.00
)));
vehicle_price_days_map
.
put
(
PRICE_VAL
,
vehicle_price
);
vehicle_price_days_map
.
put
(
DAYS_VAL
,
free_days
);
log
.
info
(
"(节假日|非节假日未设置的)价格和免费天数 处理【{}】"
,
vehicle_price_days_map
);
log
.
info
(
"(节假日|非节假日未设置的)价格和免费天数 处理【{}】"
,
vehicle_price_days_map
);
return
vehicle_price_days_map
;
}
...
...
@@ -383,10 +429,10 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
LocalDate
startLocalDate
=
DateUtils
.
dateToLocalDate
(
startDate
);
int
start_week
=
startLocalDate
.
getDayOfWeek
().
getValue
();
if
(
START_OF_WEEK
<
start_week
&&
start_week
<
END_OF_WEEK
)
{
days
=
start_week
-
START_OF_WEEK
;
days
=
start_week
-
START_OF_WEEK
;
}
else
{
if
(
END_OF_WEEK
==
start_week
)
{
days
=
END_OF_WEEK
-
1
;
days
=
END_OF_WEEK
-
1
;
}
}
LocalDate
start_startLocalDate
=
startLocalDate
.
minusDays
(
days
);
...
...
@@ -400,7 +446,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
days
=
END_OF_WEEK
-
end_week
;
}
else
{
if
(
START_OF_WEEK
==
end_week
)
{
days
=
END_OF_WEEK
-
1
;
days
=
END_OF_WEEK
-
1
;
}
}
LocalDate
end_endLocalDate
=
endLocalDate
.
plusDays
(
days
);
...
...
@@ -417,7 +463,7 @@ public class VehicleModelCalendarPriceBiz extends BaseBiz<VehicleModelCalendarPr
AtomicReference
<
Date
>
start
=
new
AtomicReference
<>(
Date
.
from
(
LocalDate
.
parse
(
"2019-10-03"
).
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
()));
AtomicReference
<
Date
>
end
=
new
AtomicReference
<>(
Date
.
from
(
LocalDate
.
parse
(
"2019-10-29"
).
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
()));
transformStartDateAndEndDate
(
start
,
end
);
transformStartDateAndEndDate
(
start
,
end
);
System
.
out
.
println
(
start
.
get
());
System
.
out
.
println
(
end
.
get
());
}
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/rest/VehicleModelCalendarPriceController.java
View file @
230db194
...
...
@@ -16,8 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.time.LocalDateTime
;
import
java.time.ZoneOffset
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -47,8 +48,8 @@ public class VehicleModelCalendarPriceController {
if
(
StringUtils
.
isEmpty
(
start
)
||
StringUtils
.
isEmpty
(
end
))
{
throw
new
BaseException
(
"缺少开始时间或结束时间"
);
}
Date
startDate
=
Date
.
from
(
LocalDate
.
parse
(
start
).
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
(
));
Date
endDate
=
Date
.
from
(
LocalDate
.
parse
(
end
).
atStartOfDay
(
ZoneId
.
systemDefault
()).
toInstant
(
));
Date
startDate
=
Date
.
from
(
LocalDate
Time
.
parse
(
start
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)).
toInstant
(
ZoneOffset
.
ofHours
(
8
)
));
Date
endDate
=
Date
.
from
(
LocalDate
Time
.
parse
(
end
,
DateTimeFormatter
.
ofPattern
(
"yyyy-MM-dd HH:mm:ss"
)).
toInstant
(
ZoneOffset
.
ofHours
(
8
)
));
List
<
VehicleModelCalendarPriceDTO
>
vehicleModelCalendarPriceVos
=
vehicleModelCalendarPriceBiz
.
listVehicleModelCalendarPriceByDateAndVehicleModelIdAndUserId
(
startDate
,
endDate
,
vehicleModelId
,
appUserDTO
.
getUserid
());
return
ObjectRestResponse
.
succ
(
vehicleModelCalendarPriceVos
);
}
...
...
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