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
7f912342
Commit
7f912342
authored
Aug 31, 2019
by
hezhen
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://113.105.137.151:22280/youjj/cloud-platform
parents
ac0879fa
df1077ca
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
580 additions
and
474 deletions
+580
-474
OrderDepositRefundRecordBiz.java
.../xxfc/platform/order/biz/OrderDepositRefundRecordBiz.java
+4
-2
bootstrap.yml
xx-order/xx-order-server/src/main/resources/bootstrap.yml
+1
-1
VehicleActiveService.java
...a/com/xxfc/platform/vehicle/biz/VehicleActiveService.java
+69
-49
VehicleBiz.java
...c/main/java/com/xxfc/platform/vehicle/biz/VehicleBiz.java
+410
-370
VehicleBookHourInfoBiz.java
...com/xxfc/platform/vehicle/biz/VehicleBookHourInfoBiz.java
+20
-19
VehicleBookInfoBiz.java
...ava/com/xxfc/platform/vehicle/biz/VehicleBookInfoBiz.java
+28
-23
VehicleBookRecordBiz.java
...a/com/xxfc/platform/vehicle/biz/VehicleBookRecordBiz.java
+6
-0
VehicleDepartureService.java
...om/xxfc/platform/vehicle/biz/VehicleDepartureService.java
+7
-7
VehicleBookInfoMapper.java
...m/xxfc/platform/vehicle/mapper/VehicleBookInfoMapper.java
+2
-0
VehicleBookRecordMapper.java
...xxfc/platform/vehicle/mapper/VehicleBookRecordMapper.java
+3
-0
VehicleDepartureLogMapper.java
...fc/platform/vehicle/mapper/VehicleDepartureLogMapper.java
+1
-1
VehicleMapper.java
.../java/com/xxfc/platform/vehicle/mapper/VehicleMapper.java
+2
-0
VehicleBookInfoMapper.xml
...erver/src/main/resources/mapper/VehicleBookInfoMapper.xml
+6
-1
VehicleBookRecordMapper.xml
...ver/src/main/resources/mapper/VehicleBookRecordMapper.xml
+8
-1
VehicleDepartureLogMapper.xml
...r/src/main/resources/mapper/VehicleDepartureLogMapper.xml
+7
-0
VehicleMapper.xml
...ehicle-server/src/main/resources/mapper/VehicleMapper.xml
+6
-0
No files found.
xx-order/xx-order-server/src/main/java/com/xxfc/platform/order/biz/OrderDepositRefundRecordBiz.java
View file @
7f912342
...
...
@@ -115,8 +115,10 @@ public class OrderDepositRefundRecordBiz extends BaseBiz<DepositRefundRecordMapp
if
(
depositRefundRecord
.
getStatus
()
==
DepositRefundStatus
.
VIOLATIONARRIVAL
.
getCode
())
{
Map
<
String
,
Dictionary
>
dictionaryMap
=
thirdFeign
.
dictionaryGetAll4Map
().
getData
();
Integer
rentDepositAutoRefundTime
=
new
Integer
(
dictionaryMap
.
get
(
APP_ORDER
+
"_"
+
DictionaryKey
.
RENT_DEPOSIT_AUTO_REFUND_TIME
).
getDetail
());
depositRefundRecord
.
setRentDepositAutoRefundTime
(
depositRefundRecord
.
getCrtTime
()
+
(
rentDepositAutoRefundTime
==
null
?
0
:
rentDepositAutoRefundTime
*
60
*
60
*
1000
));
if
(
rentDepositAutoRefundTime
!=
null
)
{
Long
time
=
Long
.
parseLong
(
rentDepositAutoRefundTime
+
""
);
depositRefundRecord
.
setRentDepositAutoRefundTime
(
depositRefundRecord
.
getCrtTime
()
+
time
*
60
*
60
*
1000
);
}
}
}
return
list
;
...
...
xx-order/xx-order-server/src/main/resources/bootstrap.yml
View file @
7f912342
...
...
@@ -13,7 +13,7 @@ spring:
cloud
:
nacos
:
config
:
server-addr
:
127.0.0.1:8848
, 10.1.37.166:8848
server-addr
:
127.0.0.1:8848
#共用配置,+ mongodb日志配置
shared-dataids
:
common-dev.yaml,mongodb-log-dev.yaml
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleActiveService.java
View file @
7f912342
...
...
@@ -9,6 +9,7 @@ import com.xxfc.platform.vehicle.constant.ResCode.ResCode;
import
com.xxfc.platform.vehicle.entity.*
;
import
com.xxfc.platform.vehicle.mapper.*
;
import
com.xxfc.platform.vehicle.pojo.*
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.joda.time.DateTime
;
import
org.joda.time.format.DateTimeFormat
;
...
...
@@ -23,6 +24,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import
java.util.*
;
@Service
@Slf4j
public
class
VehicleActiveService
{
@Autowired
...
...
@@ -63,7 +65,7 @@ public class VehicleActiveService {
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getCode
());
}
if
(
StringUtils
.
isBlank
(
departureVo
.
getCheckMan
())
||
StringUtils
.
isBlank
(
departureVo
.
getCheckManTel
()))
{
if
(
StringUtils
.
isBlank
(
departureVo
.
getCheckMan
())
||
StringUtils
.
isBlank
(
departureVo
.
getCheckManTel
()))
{
throw
new
BaseException
(
ResCode
.
CHECKUSER_AND_PHONE_NOT_NULL
.
getDesc
(),
ResCode
.
CHECKUSER_AND_PHONE_NOT_NULL
.
getCode
());
}
...
...
@@ -73,13 +75,13 @@ public class VehicleActiveService {
}
//添加出车时间过滤 再出车开始时间前一天至结束时间内可以出车,并且预定记录为已审核状态
checkDateInvalide
(
departureVo
);
Integer
MileageLift
=
vehicle
.
getMileageLastUpdate
();
Integer
MileageLift1
=
departureVo
.
getMileage
();
if
(
MileageLift1
==
null
)
{
Integer
MileageLift
=
vehicle
.
getMileageLastUpdate
();
Integer
MileageLift1
=
departureVo
.
getMileage
();
if
(
MileageLift1
==
null
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED
.
getDesc
(),
ResCode
.
VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED
.
getCode
());
}
if
(
MileageLift
==
null
||
MileageLift1
>=
MileageLift
)
{
if
(
MileageLift
==
null
||
MileageLift1
>=
MileageLift
)
{
// 写入车辆公里数,预计目的地
vehicle
.
setMileageLastUpdate
(
MileageLift1
);
vehicle
.
setExpectDestinationBranchCompanyId
(
departureVo
.
getExpectArrivalBranchCompanyId
());
...
...
@@ -95,19 +97,19 @@ public class VehicleActiveService {
}
//修改预约记录状态
VehicleBookRecord
vehicleBookRecord
=
null
;
if
(
departureVo
.
getBookRecordId
()
!=
null
)
{
if
(
departureVo
.
getBookRecordId
()
!=
null
)
{
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
departureVo
.
getBookRecordId
());
updateBookRecordStatus
(
vehicleBookRecord
,
1
);
}
VehicleDepartureLogVo
vehicleDepartureLogVo
=
vehicleDepartureLogMapper
.
selectByBookRecordId
(
departureVo
.
getBookRecordId
());
if
(
vehicleDepartureLogVo
!=
null
)
{
if
(
vehicleDepartureLogVo
!=
null
)
{
BeanUtil
.
copyProperties
(
departureVo
,
vehicleDepartureLogVo
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
).
setIgnoreError
(
true
));
VehicleDepartureLog
departureLog
=
vehicleDepartureLogVo
.
getVehicleDeparture
(
vehicleDepartureLogVo
);
departureLog
.
setDepartureTime
(
new
Date
());
departureLog
.
setUpdateTime
(
new
Date
());
departureLog
.
setState
(
VehicleDepartureState
.
DEPARTURE
.
getCode
());
departureLog
.
setDepartureRemark
(
departureVo
.
getRemark
());
if
(
vehicleBookRecord
!=
null
)
{
if
(
vehicleBookRecord
!=
null
)
{
departureLog
.
setDepartureBranchCompanyId
(
vehicleBookRecord
.
getLiftCompany
());
departureLog
.
setUse
(
BookType
.
getByCode
(
vehicleBookRecord
.
getBookType
()));
departureLog
.
setUser
(
vehicleBookRecord
.
getVehicleUsername
());
...
...
@@ -124,7 +126,7 @@ public class VehicleActiveService {
departureLog
.
setState
(
VehicleDepartureState
.
DEPARTURE
.
getCode
());
departureLog
.
setBookRecordId
(
departureVo
.
getBookRecordId
());
departureLog
.
setDepartureRemark
(
departureVo
.
getRemark
());
if
(
vehicleBookRecord
!=
null
)
{
if
(
vehicleBookRecord
!=
null
)
{
departureLog
.
setDepartureBranchCompanyId
(
vehicleBookRecord
.
getLiftCompany
());
departureLog
.
setUse
(
BookType
.
getByCode
(
vehicleBookRecord
.
getBookType
()));
departureLog
.
setUser
(
vehicleBookRecord
.
getVehicleUsername
());
...
...
@@ -141,7 +143,7 @@ public class VehicleActiveService {
activeLog
.
setStartTime
(
new
Date
());
activeLog
.
setCreateTime
(
new
Date
());
vehicleActiveLogMapper
.
insert
(
activeLog
);
}
else
{
}
else
{
throw
new
BaseException
(
ResCode
.
VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED
.
getDesc
(),
ResCode
.
VEHICLE_BOOKED_RECORD_MILEAGE_CHANGED
.
getCode
());
}
...
...
@@ -168,14 +170,20 @@ public class VehicleActiveService {
break
;
}
List
<
VehicleBookRecordVo
>
vehicleBookRecordVos
=
vehicleBookRecordBiz
.
selectByVehicleId
(
vehicleId
);
if
(
vehicleBookRecordVos
!=
null
&&
vehicleBookRecordVos
.
size
()
>
0
&&
vehicleBookRecordVos
.
get
(
0
).
getVehicleDepartureLogVo
()
!=
null
&&
vehicleBookRecordVos
.
get
(
0
).
getVehicleDepartureLogVo
().
getState
()
!=
1
)
{
stringBuilder
.
append
(
"中,使用人:"
);
stringBuilder
.
append
(
vehicleBookRecordVos
.
get
(
0
).
getVehicleUsername
());
stringBuilder
.
append
(
" 使用人电话:"
);
stringBuilder
.
append
(
vehicleBookRecordVos
.
get
(
0
).
getVehicleUserPhone
());
}
else
{
stringBuilder
.
append
(
", 请联系管理员修改车辆状态为正常状态"
);
if
(
vehicleBookRecordVos
!=
null
&&
vehicleBookRecordVos
.
size
()
>
0
)
{
Iterator
<
VehicleBookRecordVo
>
iterator
=
vehicleBookRecordVos
.
iterator
();
while
(
iterator
.
hasNext
())
{
VehicleBookRecordVo
vehicleBookRecordVo
=
iterator
.
next
();
if
(
vehicleBookRecordVo
.
getVehicleDepartureLogVo
()
!=
null
&&
vehicleBookRecordVo
.
getVehicleDepartureLogVo
().
getState
()
!=
1
)
{
//已经出车
stringBuilder
.
append
(
"中,使用人:"
);
stringBuilder
.
append
(
vehicleBookRecordVo
.
getVehicleUsername
());
stringBuilder
.
append
(
" 使用人电话:"
);
stringBuilder
.
append
(
vehicleBookRecordVo
.
getVehicleUserPhone
());
return
stringBuilder
.
toString
();
}
}
}
stringBuilder
.
append
(
", 请联系管理员修改车辆状态为正常状态"
);
return
stringBuilder
.
toString
();
}
...
...
@@ -186,14 +194,14 @@ public class VehicleActiveService {
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getCode
());
}
if
(
StringUtils
.
isBlank
(
arrivalVo
.
getRecycleMan
())
||
StringUtils
.
isBlank
(
arrivalVo
.
getRecycleManTel
()))
{
if
(
StringUtils
.
isBlank
(
arrivalVo
.
getRecycleMan
())
||
StringUtils
.
isBlank
(
arrivalVo
.
getRecycleManTel
()))
{
throw
new
BaseException
(
ResCode
.
CHECKUSER_AND_PHONE_NOT_NULL
.
getDesc
(),
ResCode
.
CHECKUSER_AND_PHONE_NOT_NULL
.
getCode
());
}
if
(!
vehicle
.
getStatus
().
equals
(
VehicleStatus
.
DEPARTURE
.
getCode
()))
{
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getDesc
()
+
", 车辆状态是:"
+
getVehicleStatus
(
vehicle
.
getStatus
(),
vehicle
.
getId
()),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getCode
());
}
//
if (!vehicle.getStatus().equals(VehicleStatus.DEPARTURE.getCode())) {
//
throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getDesc() + ", 车辆状态是:" + getVehicleStatus(vehicle.getStatus(), vehicle.getId()),
//
ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getCode());
//
}
Integer
Mileagerest
=
vehicle
.
getMileageLastUpdate
();
Integer
Mileagerest1
=
arrivalVo
.
getMileage
();
if
(
Mileagerest1
==
null
)
{
...
...
@@ -202,38 +210,50 @@ public class VehicleActiveService {
}
if
(
Mileagerest
!=
null
&&
Mileagerest1
>=
Mileagerest
)
{
VehicleBookRecord
vehicleBookRecord
=
null
;
if
(
arrivalVo
.
getBookRecordId
()
!=
null
)
{
if
(
arrivalVo
.
getBookRecordId
()
!=
null
)
{
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
arrivalVo
.
getBookRecordId
());
updateBookRecordStatus
(
vehicleBookRecord
,
2
);
}
// 写入车辆公里数,还车分公司id
vehicle
.
setMileageLastUpdate
(
Mileagerest1
);
if
(
vehicleBookRecord
!=
null
)
{
if
(
vehicleBookRecord
!=
null
)
{
vehicle
.
setParkBranchCompanyId
(
vehicleBookRecord
.
getRetCompany
());
}
vehicle
.
setExpectDestinationBranchCompanyId
(
0
);
vehicleMapper
.
updateByPrimaryKeySelective
(
vehicle
);
// 修改状态,确认是出车状态
int
result
=
vehicleMapper
.
updateStatusByIdAndStatus
(
arrivalVo
.
getVehicleId
(),
VehicleStatus
.
NORMAL
.
getCode
(),
VehicleStatus
.
DEPARTURE
.
getCode
());
if
(
result
==
0
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getCode
());
}
// 出车记录
VehicleDepartureLog
departureLog
=
vehicleDepartureLogMapper
.
selectLastByVehicleId
(
arrivalVo
.
getVehicleId
());
if
(
departureLog
==
null
)
{
VehicleDepartureLogVo
departureLogVo
=
vehicleDepartureLogMapper
.
selectByBookRecordId
(
arrivalVo
.
getBookRecordId
());
if
(
departureLogVo
==
null
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE
.
getCode
());
}
// 修改状态,确认是出车状态
//兼容错误还车流程,先查询,是否有其他出行记录
boolean
flag
=
true
;
VehicleDepartureLog
departureLog
=
departureLogVo
.
getVehicleDeparture
(
departureLogVo
);
List
<
VehicleDepartureLog
>
list
=
vehicleDepartureLogMapper
.
selectByVehicle
(
arrivalVo
.
getVehicleId
());
for
(
VehicleDepartureLog
vehicleDepartureLogVo
:
list
)
{
if
(
vehicleDepartureLogVo
.
getState
()
!=
1
&&
vehicleDepartureLogVo
.
getId
()
>
departureLog
.
getId
())
{
//后面还有未收车的记录
flag
=
false
;
}
}
if
(
flag
)
{
//如果此条记录后面还有未收车记录,就不修改车辆状态
int
result
=
vehicleMapper
.
updateStatus
(
arrivalVo
.
getVehicleId
(),
VehicleStatus
.
NORMAL
.
getCode
());
// if (result == 0) {
// throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getDesc(),
// ResCode.VEHICLE_DEPARTURE_VEHICLE_UNDEPARTURE.getCode());
// }
}
DateTime
arrivalDate
=
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
());
DateTime
actualArrivalDate
=
new
DateTime
(
new
Date
());
//提前还车处理
if
(
actualArrivalDate
.
compareTo
(
arrivalDate
)
<
0
)
{
//实际还车时间小于预计还车时间,需要释放后面的时间
if
(
actualArrivalDate
.
compareTo
(
arrivalDate
)
<
0
)
{
//实际还车时间小于预计还车时间,需要释放后面的时间
BookVehicleVO
bookVehicleVo
=
new
BookVehicleVO
();
BeanUtils
.
copyProperties
(
vehicleBookRecord
,
bookVehicleVo
);
bookVehicleVo
.
setNotCheckTimeLegal
(
Boolean
.
TRUE
);
...
...
@@ -243,10 +263,10 @@ public class VehicleActiveService {
bookVehicleVo
.
setUnbookEndDate
(
arrivalDate
.
toString
(
DATE_TIME_FORMATTER
));
try
{
Boolean
hasSuc
=
vehicleBiz
.
unbookVehicle
(
bookVehicleVo
);
if
(!
hasSuc
)
{
if
(!
hasSuc
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_UNBOOK_FAIL
.
getDesc
(),
ResCode
.
VEHICLE_UNBOOK_FAIL
.
getCode
());
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
...
...
@@ -261,7 +281,7 @@ public class VehicleActiveService {
departureLog
.
setIllegalAmount
(
arrivalVo
.
getIllegalAmount
());
departureLog
.
setArrivalPic
(
arrivalVo
.
getArrivalPic
());
departureLog
.
setArrivalRemark
(
arrivalVo
.
getRemark
());
if
(
vehicleBookRecord
!=
null
)
{
if
(
vehicleBookRecord
!=
null
)
{
departureLog
.
setArrivalBranchCompanyId
(
vehicleBookRecord
.
getRetCompany
());
}
vehicleDepartureLogMapper
.
updateByPrimaryKeySelective
(
departureLog
);
...
...
@@ -299,20 +319,20 @@ public class VehicleActiveService {
//添加出车时间过滤 再出车开始时间前一天至结束时间内可以出车,并且预定记录为已审核状态
public
void
checkDateInvalide
(
VehicleDepartureVo
arrivalVo
)
{
if
(
arrivalVo
.
getBookRecordId
()
!=
null
)
{
VehicleBookRecord
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
arrivalVo
.
getBookRecordId
());
if
(
vehicleBookRecord
!=
null
)
{
if
(
arrivalVo
.
getBookRecordId
()
!=
null
)
{
VehicleBookRecord
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
arrivalVo
.
getBookRecordId
());
if
(
vehicleBookRecord
!=
null
)
{
DateTime
startDate
=
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
());
DateTime
endDate
=
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
());
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"vehicleId"
,
vehicleBookRecord
.
getVehicleId
());
param
.
put
(
"bookedEndDate"
,
vehicleBookRecord
.
getBookStartDate
());
List
<
VehicleBookRecordVo
>
list
=
vehicleBookRecordBiz
.
selectByVehicleIdAndTime
(
param
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
Iterator
<
VehicleBookRecordVo
>
iterator
=
list
.
iterator
();
while
(
iterator
.
hasNext
())
{
VehicleBookRecordVo
vehicleBookRecordVo
=
iterator
.
next
();
if
(
vehicleBookRecordVo
.
getVehicleDepartureLogVo
()
==
null
&&
vehicleBookRecordVo
.
getBookEndDate
().
getTime
()
-
new
Date
().
getTime
()
<
0
)
{
if
(
vehicleBookRecordVo
.
getVehicleDepartureLogVo
()
==
null
&&
vehicleBookRecordVo
.
getBookEndDate
().
getTime
()
-
new
Date
().
getTime
()
<
0
)
{
iterator
.
remove
();
}
}
...
...
@@ -328,8 +348,8 @@ public class VehicleActiveService {
public
void
updateBookRecordStatus
(
VehicleBookRecord
vehicleBookRecord
,
Integer
type
)
{
if
(
vehicleBookRecord
!=
null
)
{
if
(
type
==
1
)
{
if
(
vehicleBookRecord
!=
null
)
{
if
(
type
==
1
)
{
vehicleBookRecord
.
setActualStartDate
(
new
Date
());
}
else
{
vehicleBookRecord
.
setActualEndDate
(
new
Date
());
...
...
@@ -360,9 +380,9 @@ public class VehicleActiveService {
throw
new
BaseException
(
ResCode
.
VEHICLE_UPKEEP_VEHICLE_DISABLE
.
getDesc
(),
ResCode
.
VEHICLE_UPKEEP_VEHICLE_DISABLE
.
getCode
());
}
Integer
lastMileage
=
vehicleUpkeepVo
.
getMileage
();
Integer
lastMileage
=
vehicleUpkeepVo
.
getMileage
();
int
result
=
vehicleMapper
.
upMileageByIdAndStatus
(
vehicleUpkeepVo
.
getVehicleId
(),
VehicleStatus
.
UPKEEP
.
getCode
(),
VehicleStatus
.
NORMAL
.
getCode
(),
lastMileage
);
VehicleStatus
.
NORMAL
.
getCode
(),
lastMileage
);
if
(
result
==
0
)
{
// 车辆状态异常
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
...
...
@@ -413,9 +433,9 @@ public class VehicleActiveService {
throw
new
BaseException
(
ResCode
.
VEHICLE_UPKEEP_VEHICLE_UNUPKEEP
.
getDesc
(),
ResCode
.
VEHICLE_UPKEEP_VEHICLE_UNUPKEEP
.
getCode
());
}
Integer
mileageLastUpdate
=
vehicle
.
getMileageLastUpdate
()==
null
?
0
:
vehicle
.
getMileageLastUpdate
();
Integer
maintenance_mileage
=
Mileage
+
mileageLastUpdate
;
int
result
=
vehicleMapper
.
updateMileageStatusByIdAndStatus
(
vehicleId
,
VehicleStatus
.
NORMAL
.
getCode
(),
VehicleStatus
.
UPKEEP
.
getCode
(),
maintenance_mileage
);
Integer
mileageLastUpdate
=
vehicle
.
getMileageLastUpdate
()
==
null
?
0
:
vehicle
.
getMileageLastUpdate
();
Integer
maintenance_mileage
=
Mileage
+
mileageLastUpdate
;
int
result
=
vehicleMapper
.
updateMileageStatusByIdAndStatus
(
vehicleId
,
VehicleStatus
.
NORMAL
.
getCode
(),
VehicleStatus
.
UPKEEP
.
getCode
(),
maintenance_mileage
);
if
(
result
==
0
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_UPKEEP_VEHICLE_UNUPKEEP
.
getDesc
(),
ResCode
.
VEHICLE_UPKEEP_VEHICLE_UNUPKEEP
.
getCode
());
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleBiz.java
View file @
7f912342
...
...
@@ -89,6 +89,9 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
private
VehicleBookHourInfoBiz
vehicleBookHourInfoBiz
;
@Autowired
UserFeign
userFeign
;
@Autowired
private
VehicleBookInfoBiz
vehicleBookInfoBiz
;
@Override
public
UserFeign
getUserFeign
()
{
...
...
@@ -96,9 +99,9 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
@Value
(
"${vehicle.baseUploadPath}"
)
private
String
baseUploadPath
;
private
String
baseUploadPath
;
@Value
(
"${vehicle.fristMileage}"
)
private
Integer
fristMileage
;
private
Integer
fristMileage
;
/**
* 每批次最大更、插入车辆最大条目数
...
...
@@ -107,17 +110,18 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 写入上传文件,返回相对路径
*
* @param file
* @return
*/
public
RestResponse
<
String
>
uploadDrivingLicense
(
MultipartFile
file
)
throws
Exception
{
public
RestResponse
<
String
>
uploadDrivingLicense
(
MultipartFile
file
)
throws
Exception
{
//创建本日存放目录
DateTime
now
=
DateTime
.
now
();
String
dirPathToday
=
File
.
separator
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
String
dirPathToday
=
File
.
separator
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
String
redisNoKey
=
RedisKey
.
UPLOAD_FILE_NO_PREFIX
+
now
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
Long
no
=
customRedisTemplate
.
opsForValue
().
increment
(
redisNoKey
);
if
(
no
.
equals
(
1
l
))
{
customRedisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
if
(
no
.
equals
(
1
l
))
{
customRedisTemplate
.
expire
(
redisNoKey
,
1
,
TimeUnit
.
DAYS
);
}
String
fileName
=
file
.
getOriginalFilename
();
String
realFileRelPath
=
dirPathToday
+
File
.
separator
+
no
+
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
...
...
@@ -130,11 +134,12 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 下载行驶证图片
*
* @param realFileRelPath
* @return
* @throws Exception
*/
public
ResponseEntity
<
byte
[]>
downloadDrivingLicense
(
String
realFileRelPath
)
throws
Exception
{
public
ResponseEntity
<
byte
[]>
downloadDrivingLicense
(
String
realFileRelPath
)
throws
Exception
{
String
filePath
=
baseUploadPath
+
realFileRelPath
;
File
file
=
new
File
(
filePath
);
//新建一个文件
...
...
@@ -142,37 +147,39 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
String
downloadFileName
=
new
String
(
file
.
getName
());
//设置编码
headers
.
setContentDispositionFormData
(
"attachment"
,
downloadFileName
);
headers
.
setContentType
(
MediaType
.
APPLICATION_OCTET_STREAM
);
return
new
ResponseEntity
<
byte
[]>(
FileUtils
.
readFileToByteArray
(
file
),
headers
,
HttpStatus
.
CREATED
);
return
new
ResponseEntity
<
byte
[]>(
FileUtils
.
readFileToByteArray
(
file
),
headers
,
HttpStatus
.
CREATED
);
}
// @Cache(key = "vehical")
public
Vehicle
get
(
String
id
){
// @Cache(key = "vehical")
public
Vehicle
get
(
String
id
)
{
Vehicle
vehicle
=
mapper
.
selectByPrimaryKey
(
id
);
return
vehicle
;
}
/**
* 获取相关预订记录
*
* @param vehicle
* @param yearMonth
* @return
*/
public
VehicleBookInfo
getByVehicleIdAndYearMonth
(
String
vehicle
,
String
yearMonth
)
{
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicle"
,
vehicle
);
params
.
put
(
"yearMonth"
,
yearMonth
);
public
VehicleBookInfo
getByVehicleIdAndYearMonth
(
String
vehicle
,
String
yearMonth
)
{
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicle"
,
vehicle
);
params
.
put
(
"yearMonth"
,
yearMonth
);
List
<
VehicleBookInfo
>
vehicleBookInfoList
=
vehicleBookInfoMapper
.
getByVehicleIdAndYearMonth
(
params
);
return
CollectionUtils
.
isEmpty
(
vehicleBookInfoList
)
?
null
:
vehicleBookInfoList
.
get
(
0
);
return
CollectionUtils
.
isEmpty
(
vehicleBookInfoList
)
?
null
:
vehicleBookInfoList
.
get
(
0
);
}
/**
* 获取相关预订记录
*
* @param vehicle
* @return
*/
public
List
<
VehicleBookInfo
>
getByVehicleIdAndYearMonth
(
String
vehicle
){
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicle"
,
vehicle
);
public
List
<
VehicleBookInfo
>
getByVehicleIdAndYearMonth
(
String
vehicle
)
{
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicle"
,
vehicle
);
params
.
put
(
"yearMonths"
,
Lists
.
newArrayList
(
DateTime
.
now
().
toString
(
YEARMONTH_DATE_TIME_FORMATTER
),
...
...
@@ -187,7 +194,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 检查常量是否合法
*/
private
void
checkIfConstantValid
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
){
private
void
checkIfConstantValid
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
)
{
//检查常量是否合法
if
(
addOrUpdateVehicleVo
.
getUseType
()
!=
null
&&
addOrUpdateVehicleVo
.
getUseType
()
>
0
)
{
constantBiz
.
checkIfExists
(
ConstantType
.
VEHICLE_USE
.
getCode
(),
addOrUpdateVehicleVo
.
getUseType
());
...
...
@@ -199,30 +206,31 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 增加车辆
*
* @param addOrUpdateVehicleVoList
*/
@Transactional
public
RestResponse
add
(
List
<
AddOrUpdateVehicleVo
>
addOrUpdateVehicleVoList
)
throws
Exception
{
public
RestResponse
add
(
List
<
AddOrUpdateVehicleVo
>
addOrUpdateVehicleVoList
)
throws
Exception
{
if
(
addOrUpdateVehicleVoList
.
size
()>
MAX_BATCH_SIZE_VEHICLE
)
{
if
(
addOrUpdateVehicleVoList
.
size
()
>
MAX_BATCH_SIZE_VEHICLE
)
{
throw
new
BaseException
(
ResultCode
.
ADD_VEHICLE_MORE
);
}
for
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo:
addOrUpdateVehicleVoList
)
{
for
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
:
addOrUpdateVehicleVoList
)
{
Vehicle
vehicle
=
new
Vehicle
();
BeanUtilsBean
.
getInstance
().
copyProperties
(
vehicle
,
addOrUpdateVehicleVo
);
if
(
addOrUpdateVehicleVo
.
getParkBranchCompanyId
()
==
null
)
{
if
(
addOrUpdateVehicleVo
.
getParkBranchCompanyId
()
==
null
)
{
throw
new
BaseException
(
ResultCode
.
RET_COMPANY_CAN_NOT_BE_NULL
);
}
vehicle
.
setId
(
UUID
.
randomUUID
().
toString
());
// 检查车牌或者编码是否已存在,已存在则返回失败
List
<
Vehicle
>
exitsVehicles
=
lockByCode
(
addOrUpdateVehicleVo
);
if
(
CollectionUtils
.
isNotEmpty
(
exitsVehicles
))
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS
.
getCode
(),
ResCode
.
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS
.
getDesc
());
if
(
CollectionUtils
.
isNotEmpty
(
exitsVehicles
))
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS
.
getCode
(),
ResCode
.
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS
.
getDesc
());
// if(addOrUpdateVehicleVo.getCode()!= null &&
// addOrUpdateVehicleVo.getCode().equals(exitsVehicles.get(0).getCode())){
...
...
@@ -239,15 +247,16 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 此方法必须置于事务中以使锁生效
* 符合查询条件记录的修改活且相关记录的锁获取操作将被锁定
*
* @param addOrUpdateVehicleVo
* @return 锁定成功返回
*/
private
List
<
Vehicle
>
lockByCode
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
)
throws
CustomIllegalParamException
{
private
List
<
Vehicle
>
lockByCode
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
)
throws
CustomIllegalParamException
{
// if(addOrUpdateVehicleVo.getCode() == null){
// return null;
// }
if
(
addOrUpdateVehicleVo
.
getNumberPlate
()
==
null
)
{
if
(
addOrUpdateVehicleVo
.
getNumberPlate
()
==
null
)
{
throw
new
BaseException
(
ResultCode
.
NUMBER_PLAT_CAN_NOT_BE_NULL
);
}
List
<
Vehicle
>
vehicles
=
mapper
.
lockByCode
(
addOrUpdateVehicleVo
);
...
...
@@ -256,27 +265,28 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 修改汽车信息
*
* @param addOrUpdateVehicleVoList
* @return
*/
@Transactional
public
RestResponse
update
(
List
<
AddOrUpdateVehicleVo
>
addOrUpdateVehicleVoList
)
throws
Exception
{
if
(
addOrUpdateVehicleVoList
.
size
()>
MAX_BATCH_SIZE_VEHICLE
)
{
public
RestResponse
update
(
List
<
AddOrUpdateVehicleVo
>
addOrUpdateVehicleVoList
)
throws
Exception
{
if
(
addOrUpdateVehicleVoList
.
size
()
>
MAX_BATCH_SIZE_VEHICLE
)
{
throw
new
BaseException
(
ResultCode
.
ADD_VEHICLE_MORE
);
}
for
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo:
addOrUpdateVehicleVoList
)
{
for
(
AddOrUpdateVehicleVo
addOrUpdateVehicleVo
:
addOrUpdateVehicleVoList
)
{
Vehicle
vehicle
=
new
Vehicle
();
BeanUtilsBean
.
getInstance
().
copyProperties
(
vehicle
,
addOrUpdateVehicleVo
);
if
(
addOrUpdateVehicleVo
.
getParkBranchCompanyId
()
==
null
)
{
if
(
addOrUpdateVehicleVo
.
getParkBranchCompanyId
()
==
null
)
{
throw
new
BaseException
(
ResultCode
.
RET_COMPANY_CAN_NOT_BE_NULL
);
}
//悲观锁,检查是否已存在车牌或编码
List
<
Vehicle
>
exitsVehicles
=
lockByCode
(
addOrUpdateVehicleVo
);
if
(
CollectionUtils
.
isNotEmpty
(
exitsVehicles
))
{
for
(
Vehicle
exitsVehicle:
exitsVehicles
)
{
if
(
exitsVehicle
.
getId
().
equals
(
addOrUpdateVehicleVo
.
getId
()))
{
if
(
CollectionUtils
.
isNotEmpty
(
exitsVehicles
))
{
for
(
Vehicle
exitsVehicle
:
exitsVehicles
)
{
if
(
exitsVehicle
.
getId
().
equals
(
addOrUpdateVehicleVo
.
getId
()))
{
continue
;
}
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_INFO_SAME_NUM_PLATE_EXISTS
.
getCode
(),
...
...
@@ -297,15 +307,16 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 废弃车辆(状态设置为废弃)
*
* @param idList
* @return
*/
public
RestResponse
discard
(
List
<
String
>
idList
){
if
(
idList
.
size
()>
MAX_BATCH_SIZE_VEHICLE
)
{
public
RestResponse
discard
(
List
<
String
>
idList
)
{
if
(
idList
.
size
()
>
MAX_BATCH_SIZE_VEHICLE
)
{
throw
new
BaseException
(
ResultCode
.
ADD_VEHICLE_MORE
);
}
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"idList"
,
idList
);
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"idList"
,
idList
);
params
.
put
(
"status"
,
VehicleStatus
.
DISCARD
.
getCode
());
mapper
.
updateStatusById
(
params
);
return
RestResponse
.
suc
();
...
...
@@ -402,6 +413,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 不需要审核
*
* @param userId
* @param bookVehicleVo
* @param userName
...
...
@@ -409,11 +421,11 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
* @throws Exception
*/
@Transactional
public
VehicleBookRecord
applyVehicle
(
Integer
userId
,
BookVehicleVO
bookVehicleVo
,
String
userName
)
throws
Exception
{
public
VehicleBookRecord
applyVehicle
(
Integer
userId
,
BookVehicleVO
bookVehicleVo
,
String
userName
)
throws
Exception
{
log
.
info
(
"预定车辆参数:userId = {}, bookVehicleVo = {},username = {}"
,
userId
,
bookVehicleVo
,
userName
);
//检查车辆信息是否合法
Vehicle
vehicle
=
mapper
.
selectByPrimaryKey
(
bookVehicleVo
.
getVehicleId
());
if
(
vehicle
==
null
)
{
if
(
vehicle
==
null
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_UNEXIST
.
getCode
());
}
if
(
vehicle
.
getStatus
().
equals
(
VehicleStatus
.
DISCARD
.
getCode
()))
{
...
...
@@ -424,31 +436,26 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_DELETE
.
getDesc
(),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_DELETE
.
getCode
());
}
if
(
StringUtils
.
isBlank
(
bookVehicleVo
.
getBookStartDate
())
||
StringUtils
.
isBlank
(
bookVehicleVo
.
getBookEndDate
()))
{
if
(
StringUtils
.
isBlank
(
bookVehicleVo
.
getBookStartDate
())
||
StringUtils
.
isBlank
(
bookVehicleVo
.
getBookEndDate
()))
{
throw
new
BaseException
(
ResultCode
.
DATE_TIME_IS_NULL
);
}
//提取日期和相应的预定目标日期
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookEndDate
(),
DATE_TIME_FORMATTER
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookEndDate
(),
DATE_TIME_FORMATTER
);
//转换日期范围为列表,并检查是否合法
fillDateList4DatePeriod
(
yearMonthAndDate
,
startDay
,
endDay
);
if
(
yearMonthAndDate
.
size
()>
3
)
{
//连续的日期最多夸3个月
fillDateList4DatePeriod
(
yearMonthAndDate
,
DateTime
.
parse
(
startDay
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
DEFAULT_DATE_TIME_FORMATTER
),
DateTime
.
parse
(
endDay
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
DEFAULT_DATE_TIME_FORMATTER
)
);
if
(
yearMonthAndDate
.
size
()
>
3
)
{
//连续的日期最多夸3个月
throw
new
BaseException
(
ResultCode
.
ONLY_BOOK_TWO_MONTH
);
}
//检验时间是否可以预定
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
//加入预定申请记录
VehicleBookRecord
vehicleBookRecord
=
null
;
if
(
bookVehicleVo
.
getVehicleBookRecordId
()
==
null
)
{
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
bookVehicleVo
.
getBookStartDate
(),
bookVehicleVo
.
getBookEndDate
(),
bookVehicleVo
.
getNotCheckTimeLegal
());
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDate
.
entrySet
()){
Boolean
rsEach
=
applyVehicle4EmployeePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
(),
map
);
if
(
Boolean
.
FALSE
.
equals
(
rsEach
)){
throw
new
BaseException
(
ResultCode
.
VEHICLE_IS_BOOKED
);
}
}
if
(
bookVehicleVo
.
getVehicleBookRecordId
()
==
null
)
{
//检验时间是否可以预定
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
bookVehicleVo
.
getBookStartDate
(),
bookVehicleVo
.
getBookEndDate
(),
bookVehicleVo
.
getNotCheckTimeLegal
());
vehicleBookRecord
=
new
VehicleBookRecord
();
BeanUtil
.
copyProperties
(
bookVehicleVo
,
vehicleBookRecord
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
).
setIgnoreError
(
true
));
vehicleBookRecord
.
setBookStartDate
(
startDay
.
toDate
());
...
...
@@ -460,29 +467,35 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
vehicleBookRecordBiz
.
save
(
vehicleBookRecord
);
}
else
{
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
bookVehicleVo
.
getVehicleBookRecordId
());
if
(
vehicleBookRecord
==
null
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_BOOKED_RECORD_NOT_EXIST
.
getDesc
(),
ResCode
.
VEHICLE_BOOKED_RECORD_NOT_EXIST
.
getCode
());
}
else
{
//先取消预定,然后再修改
bookVehicleVo
.
setUnbookStartDate
(
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
()).
toString
(
DATE_TIME_FORMATTER
));
bookVehicleVo
.
setUnbookEndDate
(
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DATE_TIME_FORMATTER
));
unbookVehicle
(
bookVehicleVo
);
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
bookVehicleVo
.
getBookStartDate
(),
bookVehicleVo
.
getBookEndDate
(),
bookVehicleVo
.
getNotCheckTimeLegal
());
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDate
.
entrySet
()){
Boolean
rsEach
=
applyVehicle4EmployeePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
(),
map
);
if
(
Boolean
.
FALSE
.
equals
(
rsEach
)){
throw
new
BaseException
(
ResultCode
.
VEHICLE_IS_BOOKED
);
}
}
vehicleBookRecord
.
setBookStartDate
(
startDay
.
toDate
());
vehicleBookRecord
.
setBookEndDate
(
endDay
.
toDate
());
vehicleBookRecordBiz
.
updateSelectiveByIdRe
(
vehicleBookRecord
);
}
if
(
vehicleBookRecord
==
null
)
{
throw
new
BaseException
(
ResCode
.
VEHICLE_BOOKED_RECORD_NOT_EXIST
.
getDesc
(),
ResCode
.
VEHICLE_BOOKED_RECORD_NOT_EXIST
.
getCode
());
}
else
{
//先取消预定,然后再修改
//先取消之前预定时间,然后再修改
bookVehicleVo
.
setUnbookStartDate
(
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
()).
toString
(
DATE_TIME_FORMATTER
));
bookVehicleVo
.
setUnbookEndDate
(
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DATE_TIME_FORMATTER
));
unbookVehicle
(
bookVehicleVo
);
//检验时间是否可以预定
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
bookVehicleVo
.
getBookStartDate
(),
bookVehicleVo
.
getBookEndDate
(),
bookVehicleVo
.
getNotCheckTimeLegal
());
vehicleBookRecord
.
setBookStartDate
(
startDay
.
toDate
());
vehicleBookRecord
.
setBookEndDate
(
endDay
.
toDate
());
vehicleBookRecordBiz
.
updateSelectiveByIdRe
(
vehicleBookRecord
);
}
}
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
yearMonthAndDate
.
entrySet
())
{
Boolean
rsEach
=
applyVehicle4EmployeePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
(),
map
);
if
(
Boolean
.
FALSE
.
equals
(
rsEach
))
{
throw
new
BaseException
(
ResultCode
.
VEHICLE_IS_BOOKED
);
}
}
//添加预定日期记录
Boolean
hasSuc
=
bookedVehicle
(
bookVehicleVo
);
if
(!
hasSuc
)
{
throw
new
BaseException
(
ResultCode
.
BOOKED_FAILED_CODE
);
}
// //添加预定时间记录
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
VehicleBookHourInfoDto
vehicleBookHourInfoDto
=
new
VehicleBookHourInfoDto
();
vehicleBookHourInfoDto
.
setVehicleId
(
bookVehicleVo
.
getVehicleId
());
vehicleBookHourInfoDto
.
setYearMonthDay
(
entry
.
getKey
());
...
...
@@ -490,20 +503,14 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
vehicleBookHourInfoBiz
.
save
(
vehicleBookHourInfoDto
);
}
//修改相关车辆预定记录
Boolean
hasSuc
=
bookedVehicle
(
bookVehicleVo
);
if
(!
hasSuc
){
throw
new
BaseException
(
ResultCode
.
BOOKED_FAILED_CODE
);
}
//添加随车物品
List
<
Map
<
String
,
Object
>>
params
=
Lists
.
newArrayList
();
if
(
MapUtils
.
isNotEmpty
(
bookVehicleVo
.
getSelectedAccItem
()))
{
for
(
Map
.
Entry
<
Integer
,
Integer
>
idAndAmount
:
bookVehicleVo
.
getSelectedAccItem
().
entrySet
())
{
Map
<
String
,
Object
>
row
=
Maps
.
newHashMap
();
row
.
put
(
"id"
,
idAndAmount
.
getKey
());
row
.
put
(
"amount"
,
idAndAmount
.
getValue
());
row
.
put
(
"bookRecordId"
,
vehicleBookRecord
.
getId
());
List
<
Map
<
String
,
Object
>>
params
=
Lists
.
newArrayList
();
if
(
MapUtils
.
isNotEmpty
(
bookVehicleVo
.
getSelectedAccItem
()))
{
for
(
Map
.
Entry
<
Integer
,
Integer
>
idAndAmount
:
bookVehicleVo
.
getSelectedAccItem
().
entrySet
())
{
Map
<
String
,
Object
>
row
=
Maps
.
newHashMap
();
row
.
put
(
"id"
,
idAndAmount
.
getKey
());
row
.
put
(
"amount"
,
idAndAmount
.
getValue
());
row
.
put
(
"bookRecordId"
,
vehicleBookRecord
.
getId
());
params
.
add
(
row
);
}
bookRecordAccItemMapper
.
batchAdd
(
params
);
...
...
@@ -514,38 +521,48 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
@Transactional
public
Boolean
applyVehicle4EmployeePerMonth
(
String
vehicleId
,
List
<
String
>
bookedDates
,
String
yearMonth
,
Map
<
String
,
Integer
>
hourInfo
){
public
Boolean
applyVehicle4EmployeePerMonth
(
String
vehicleId
,
List
<
String
>
bookedDates
,
String
yearMonth
,
Map
<
String
,
Integer
>
hourInfo
)
{
//检查车辆是否有空档
//获得当月预定记录
VehicleBookInfo
vehicleBookInfo
=
getByVehicleIdAndYearMonth
(
vehicleId
,
yearMonth
);
VehicleBookInfo
vehicleBookInfo
=
getByVehicleIdAndYearMonth
(
vehicleId
,
yearMonth
);
//位操作确定目标日期是否可预订
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
yearMonth
,
bookedDates
);
fillBookedDateSearchParam
(
params
,
null
,
yearMonthAndDate
);
//转换为查询对应日期未预定的条件
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
yearMonth
);
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
yearMonth
,
bookedDates
);
fillBookedDateSearchParam
(
params
,
null
,
yearMonthAndDate
);
//转换为查询对应日期未预定的条件
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
yearMonth
);
Integer
andOperationFactor
=
andOpratorParam
.
get
(
"andOperationFactor"
);
Integer
andOperationRs
=
andOpratorParam
.
get
(
"andOperationRs"
);
if
(
vehicleBookInfo
!=
null
&&
vehicleBookInfo
.
getBookedDate
()
!=
null
&&
((
vehicleBookInfo
.
getBookedDate
()
&
andOperationFactor
)
!=
andOperationRs
))
{
//已经被预定
if
(
vehicleBookInfo
!=
null
&&
vehicleBookInfo
.
getBookedDate
()
!=
null
&&
((
vehicleBookInfo
.
getBookedDate
()
&
andOperationFactor
)
!=
0
))
{
//已经被预定
//当天已经被预定检查小时是否也被预定
return
filterHourInfoBooked
(
vehicleId
,
hourInfo
);
}
else
if
(
vehicleBookInfo
!=
null
&&
vehicleBookInfo
.
getBookedDate
()
!=
null
&&
(
vehicleBookInfo
.
getBookedDate
()
&
andOperationFactor
)
==
0
){
//未被预定,查看时间是否被预定
return
filterHourInfoBooked
(
vehicleId
,
hourInfo
);
}
return
Boolean
.
TRUE
;
}
public
boolean
filterHourInfoBooked
(
String
vehicleId
,
Map
<
String
,
Integer
>
hourInfo
)
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
hourInfo
.
entrySet
())
{
if
(
MapUtils
.
isEmpty
(
hourInfo
))
{
return
false
;
}
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
hourInfo
.
entrySet
())
{
if
(
entry
.
getValue
()
==
0
)
{
//0点 查询是否有已经预约的记录
Map
<
String
,
Object
>
param
=
new
HashMap
<>();
param
.
put
(
"vehicleId"
,
vehicleId
);
param
.
put
(
"bookedEndDate"
,
DateTime
.
parse
(
entry
.
getKey
()
+
" 00:00:00"
,
DATE_TIME_FORMATTER
));
List
<
VehicleBookRecordVo
>
vehicleBookRecordVos
=
vehicleBookRecordBiz
.
selectZeroHourRecord
(
param
);
if
(
vehicleBookRecordVos
!=
null
&&
vehicleBookRecordVos
.
size
()
>
0
)
{
return
false
;
}
}
VehicleBookHourInfoDto
vehicleBookHourInfoDto
=
new
VehicleBookHourInfoDto
();
vehicleBookHourInfoDto
.
setYearMonthDay
(
entry
.
getKey
());
vehicleBookHourInfoDto
.
setVehicleId
(
vehicleId
);
List
<
VehicleBookHourInfo
>
vehicleBookHourInfos
=
vehicleBookHourInfoBiz
.
selectByVehicleAndDate
(
vehicleBookHourInfoDto
);
if
(
vehicleBookHourInfos
!=
null
&&
vehicleBookHourInfos
.
size
()
>
0
)
{
if
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
entry
.
getValue
())
!=
0
)
{
// 已经被预定
if
(
vehicleBookHourInfos
!=
null
&&
vehicleBookHourInfos
.
size
()
>
0
)
{
if
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
entry
.
getValue
())
!=
0
)
{
// 已经被预定
log
.
info
(
entry
.
getKey
()
+
"预定的时间段已经被预约!"
);
return
Boolean
.
FALSE
;
}
...
...
@@ -556,48 +573,49 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 批准预定车辆预定
*
* @param operatorId
* @param bookRecordId
* @return
*/
@Transactional
public
RestResponse
<
Integer
>
reviewVehicleBooking
(
Integer
operatorId
,
Long
bookRecordId
,
Integer
rsStatus
,
String
userName
,
String
rejectRemark
,
Boolean
notCheckTimeLegal
)
throws
Exception
{
public
RestResponse
<
Integer
>
reviewVehicleBooking
(
Integer
operatorId
,
Long
bookRecordId
,
Integer
rsStatus
,
String
userName
,
String
rejectRemark
,
Boolean
notCheckTimeLegal
)
throws
Exception
{
try
{
//获取相关申请记录
VehicleBookRecord
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
bookRecordId
);
//申请记录验证
if
(
vehicleBookRecord
==
null
)
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getCode
(),
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getDesc
());
}
if
(
VehicleBookRecordStatus
.
APPROVE
.
getCode
().
equals
(
vehicleBookRecord
.
getStatus
()))
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getCode
(),
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getDesc
());
}
//转换为相应预定参数
BookVehicleVO
bookVehicleVo
=
new
BookVehicleVO
();
BeanUtils
.
copyProperties
(
bookVehicleVo
,
vehicleBookRecord
);
bookVehicleVo
.
setBookStartDate
(
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
()).
toString
(
DATE_TIME_FORMATTER
));
bookVehicleVo
.
setBookEndDate
(
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DATE_TIME_FORMATTER
));
//获取相关申请记录
VehicleBookRecord
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
bookRecordId
);
//申请记录验证
if
(
vehicleBookRecord
==
null
)
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getCode
(),
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getDesc
());
}
if
(
VehicleBookRecordStatus
.
APPROVE
.
getCode
().
equals
(
vehicleBookRecord
.
getStatus
()))
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getCode
(),
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getDesc
());
}
//转换为相应预定参数
BookVehicleVO
bookVehicleVo
=
new
BookVehicleVO
();
BeanUtils
.
copyProperties
(
bookVehicleVo
,
vehicleBookRecord
);
bookVehicleVo
.
setBookStartDate
(
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
()).
toString
(
DATE_TIME_FORMATTER
));
bookVehicleVo
.
setBookEndDate
(
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DATE_TIME_FORMATTER
));
//成功后修改预定记录状态
Map
<
String
,
Object
>
updateParam
=
Maps
.
newHashMap
();
updateParam
.
put
(
"id"
,
bookRecordId
);
updateParam
.
put
(
"status"
,
rsStatus
);
updateParam
.
put
(
"reviewerApply"
,
operatorId
);
updateParam
.
put
(
"reviewerNameApply"
,
userName
);
updateParam
.
put
(
"statusCondition"
,
VehicleBookRecordStatus
.
APPLY
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
rejectRemark
))
{
updateParam
.
put
(
"rejectRemark"
,
rejectRemark
);
Map
<
String
,
Object
>
updateParam
=
Maps
.
newHashMap
();
updateParam
.
put
(
"id"
,
bookRecordId
);
updateParam
.
put
(
"status"
,
rsStatus
);
updateParam
.
put
(
"reviewerApply"
,
operatorId
);
updateParam
.
put
(
"reviewerNameApply"
,
userName
);
updateParam
.
put
(
"statusCondition"
,
VehicleBookRecordStatus
.
APPLY
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
rejectRemark
))
{
updateParam
.
put
(
"rejectRemark"
,
rejectRemark
);
}
Integer
effected
=
vehicleBookRecordBiz
.
changeRecordStatus
(
updateParam
);
if
(
effected
==
0
)
{
//修改失败,手动回滚
if
(
effected
==
0
)
{
//修改失败,手动回滚
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
//手动回滚
return
RestResponse
.
code
(
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getCode
());
}
else
if
(
VehicleBookRecordStatus
.
REJECTED
.
getCode
().
equals
(
rsStatus
))
{
}
else
if
(
VehicleBookRecordStatus
.
REJECTED
.
getCode
().
equals
(
rsStatus
))
{
//拒绝,则释放bookinfo
bookVehicleVo
.
setUnbookStartDate
(
bookVehicleVo
.
getBookStartDate
());
bookVehicleVo
.
setUnbookEndDate
(
bookVehicleVo
.
getBookEndDate
());
Boolean
hasSuc
=
unbookVehicle
(
bookVehicleVo
);
if
(
hasSuc
)
{
if
(
hasSuc
)
{
return
RestResponse
.
suc
();
}
}
...
...
@@ -610,23 +628,24 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 取消预定
*
* @return
*/
@Transactional
public
RestResponse
unbookVehicle4Employee
(
Integer
operatorId
,
Long
bookRecordId
,
String
userName
,
String
rejectRemark
,
Boolean
notCheckTimeLegal
)
throws
Exception
{
public
RestResponse
unbookVehicle4Employee
(
Integer
operatorId
,
Long
bookRecordId
,
String
userName
,
String
rejectRemark
,
Boolean
notCheckTimeLegal
)
throws
Exception
{
//获取相关申请记录
VehicleBookRecord
vehicleBookRecord
=
vehicleBookRecordBiz
.
selectById
(
bookRecordId
);
//申请记录验证
if
(
vehicleBookRecord
==
null
)
{
if
(
vehicleBookRecord
==
null
)
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getCode
(),
ResCode
.
VEHICLE_BOOK_RECORD_IS_NOT_EXIST
.
getDesc
());
}
//已通过审核的可以取消预定
if
(!
VehicleBookRecordStatus
.
APPROVE
.
getCode
().
equals
(
vehicleBookRecord
.
getStatus
()))
{
if
(!
VehicleBookRecordStatus
.
APPROVE
.
getCode
().
equals
(
vehicleBookRecord
.
getStatus
()))
{
return
RestResponse
.
code
(
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getCode
());
}
//转换为相应取消预定参数
BookVehicleVO
bookVehicleVo
=
new
BookVehicleVO
();
BeanUtils
.
copyProperties
(
bookVehicleVo
,
vehicleBookRecord
);
BeanUtils
.
copyProperties
(
bookVehicleVo
,
vehicleBookRecord
);
bookVehicleVo
.
setNotCheckTimeLegal
(
notCheckTimeLegal
);
bookVehicleVo
.
setBookStartDate
(
null
);
bookVehicleVo
.
setBookEndDate
(
null
);
...
...
@@ -634,21 +653,21 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
bookVehicleVo
.
setUnbookEndDate
(
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DATE_TIME_FORMATTER
));
//取消预定
Boolean
hasSuc
=
unbookVehicle
(
bookVehicleVo
);
if
(!
hasSuc
)
{
if
(!
hasSuc
)
{
return
RestResponse
.
codeAndMessage
(
ResCode
.
VEHICLE_UNBOOK_FAIL
.
getCode
(),
ResCode
.
VEHICLE_UNBOOK_FAIL
.
getDesc
());
}
//修改预定状态,写入取消人
Map
<
String
,
Object
>
updateParam
=
Maps
.
newHashMap
();
updateParam
.
put
(
"id"
,
bookRecordId
);
updateParam
.
put
(
"status"
,
VehicleBookRecordStatus
.
CANCEL_APPLY
.
getCode
());
updateParam
.
put
(
"reviewerCancel"
,
operatorId
);
updateParam
.
put
(
"reviewerNameCancel"
,
userName
);
updateParam
.
put
(
"statusCondition"
,
VehicleBookRecordStatus
.
APPROVE
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
rejectRemark
))
{
updateParam
.
put
(
"rejectRemark"
,
rejectRemark
);
Map
<
String
,
Object
>
updateParam
=
Maps
.
newHashMap
();
updateParam
.
put
(
"id"
,
bookRecordId
);
updateParam
.
put
(
"status"
,
VehicleBookRecordStatus
.
CANCEL_APPLY
.
getCode
());
updateParam
.
put
(
"reviewerCancel"
,
operatorId
);
updateParam
.
put
(
"reviewerNameCancel"
,
userName
);
updateParam
.
put
(
"statusCondition"
,
VehicleBookRecordStatus
.
APPROVE
.
getCode
());
if
(
StringUtils
.
isNotBlank
(
rejectRemark
))
{
updateParam
.
put
(
"rejectRemark"
,
rejectRemark
);
}
Integer
effected
=
vehicleBookRecordBiz
.
changeRecordStatus
(
updateParam
);
if
(
effected
==
0
)
{
//修改失败,手动回滚
if
(
effected
==
0
)
{
//修改失败,手动回滚
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
//手动回滚
return
RestResponse
.
code
(
ResCode
.
VEHICLE_BOOKED_RECORD_ALREADY_CHANGED
.
getCode
());
}
...
...
@@ -667,54 +686,56 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 获取预定车辆相关与操作参数
*
* @return
*/
private
Integer
getBitOpratorFactor4Booked
(
List
<
String
>
dates
){
private
Integer
getBitOpratorFactor4Booked
(
List
<
String
>
dates
)
{
Integer
andOperationFactor
=
0
;
for
(
String
dateStr
:
dates
)
{
//已预定作为条件,该位与1作与运算必定为1
for
(
String
dateStr
:
dates
)
{
//已预定作为条件,该位与1作与运算必定为1
DateTime
dateTime
=
DateTime
.
parse
(
dateStr
,
DEFAULT_DATE_TIME_FORMATTER
);
//仅对应位为1的整形值
andOperationFactor
|=
1
<<(
dateTime
.
dayOfMonth
().
get
()-
1
);
andOperationFactor
|=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
}
return
andOperationFactor
;
}
/**
* 获取预定车辆相关与操作参数
*
* @return
*/
private
Integer
getBitOpratorFactor4UnBooked
(
List
<
String
>
dates
){
private
Integer
getBitOpratorFactor4UnBooked
(
List
<
String
>
dates
)
{
Integer
andOperationFactor
=
Integer
.
MAX_VALUE
;
for
(
String
dateStr
:
dates
)
{
//已预定作为条件,该位与1作与运算必定为1
for
(
String
dateStr
:
dates
)
{
//已预定作为条件,该位与1作与运算必定为1
DateTime
dateTime
=
DateTime
.
parse
(
dateStr
,
DEFAULT_DATE_TIME_FORMATTER
);
//仅对应位为1的整形值
andOperationFactor
^=
1
<<(
dateTime
.
dayOfMonth
().
get
()-
1
);
andOperationFactor
^=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
}
return
andOperationFactor
;
}
/**
* 根据预定日期逐条修改预定记录
*
* @param bookVehicleVo
* @return
*/
@Transactional
public
Boolean
bookedVehicle
(
BookVehicleVO
bookVehicleVo
)
throws
Exception
{
public
Boolean
bookedVehicle
(
BookVehicleVO
bookVehicleVo
)
throws
Exception
{
//提取日期和相应的预定目标日期
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookEndDate
(),
DATE_TIME_FORMATTER
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getBookEndDate
(),
DATE_TIME_FORMATTER
);
//转换日期范围为列表,并检查是否合法
fillDateList4DatePeriod
(
yearMonthAndDate
,
startDay
,
endDay
);
if
(
yearMonthAndDate
.
size
()>
3
)
{
//连续的日期最多夸3个月
fillDateList4DatePeriod
(
yearMonthAndDate
,
startDay
,
endDay
);
if
(
yearMonthAndDate
.
size
()
>
3
)
{
//连续的日期最多夸3个月
throw
new
BaseException
(
ResultCode
.
ONLY_BOOK_TWO_MONTH
);
}
Boolean
rs
=
Boolean
.
TRUE
;
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDate
.
entrySet
())
{
Boolean
rsEach
=
bookedVehiclePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
());
if
(
Boolean
.
FALSE
.
equals
(
rsEach
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
yearMonthAndDate
.
entrySet
())
{
Boolean
rsEach
=
bookedVehiclePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
());
if
(
Boolean
.
FALSE
.
equals
(
rsEach
))
{
rs
=
Boolean
.
FALSE
;
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
//手动回滚
}
...
...
@@ -724,13 +745,14 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 不存在插入、存在更新,利用唯一索引确保相同车辆以及年月序列化提交事务
*
* @param vehicleId
* @param bookedDates
* @param yearMonth
* @return 是否更新或插入成功
*/
@Transactional
public
Boolean
bookedVehiclePerMonth
(
String
vehicleId
,
List
<
String
>
bookedDates
,
String
yearMonth
)
throws
Exception
{
public
Boolean
bookedVehiclePerMonth
(
String
vehicleId
,
List
<
String
>
bookedDates
,
String
yearMonth
)
throws
Exception
{
VehicleBookInfo
vehicleBookInfo
=
new
VehicleBookInfo
();
vehicleBookInfo
.
setVehicle
(
vehicleId
);
vehicleBookInfo
.
setYearMonth
(
yearMonth
);
...
...
@@ -738,53 +760,54 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
checkIfVehicleExists
(
vehicleId
);
Integer
orRsOperationFactor
=
getBitOpratorFactor4Booked
(
bookedDates
);
//预定的相关或运算因子,当前月份没有预定记录时同时也是结果
vehicleBookInfo
.
setBookedDate
(
orRsOperationFactor
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"vehicle"
,
vehicleId
);
map
.
put
(
"yearMonth"
,
yearMonth
);
List
<
VehicleBookInfo
>
vehicleBookInfos
=
vehicleBookInfoMapper
.
getByVehicleIdAndYearMonth
(
map
);
if
(
vehicleBookInfos
!=
null
&&
vehicleBookInfos
.
size
()
>
0
)
{
if
((
vehicleBookInfos
.
get
(
0
).
getBookedDate
()
&
orRsOperationFactor
)
==
orRsOperationFactor
)
{
if
(
vehicleBookInfos
!=
null
&&
vehicleBookInfos
.
size
()
>
0
)
{
if
((
vehicleBookInfos
.
get
(
0
).
getBookedDate
()
&
orRsOperationFactor
)
==
orRsOperationFactor
)
{
return
Boolean
.
TRUE
;
}
}
Integer
effected
=
vehicleBookInfoMapper
.
insertIgnore
(
vehicleBookInfo
);
if
(
effected
==
0
)
{
//已存在则需要更新
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicleId"
,
vehicleBookInfo
.
getVehicle
());
params
.
put
(
"yearMonth"
,
yearMonth
);
if
(
effected
==
0
)
{
//已存在则需要更新
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicleId"
,
vehicleBookInfo
.
getVehicle
());
params
.
put
(
"yearMonth"
,
yearMonth
);
//加入更新条件
if
(
CollectionUtils
.
isEmpty
(
bookedDates
))
{
if
(
CollectionUtils
.
isEmpty
(
bookedDates
))
{
throw
new
BaseException
(
ResultCode
.
BOOKED_DATE_IS_EMPTY
);
}
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
vehicleBookInfo
.
getYearMonth
(),
bookedDates
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
vehicleBookInfo
.
getYearMonth
(),
bookedDates
);
//转换为查询对应日期未预定的条件
fillBookedDateSearchParam
(
params
,
null
,
yearMonthAndDate
);
fillBookedDateSearchParam
(
params
,
null
,
yearMonthAndDate
);
//提取相关参数组装更细条件
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
vehicleBookInfo
.
getYearMonth
());
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
vehicleBookInfo
.
getYearMonth
());
params
.
putAll
(
andOpratorParam
);
params
.
put
(
"orRsOperationFactor"
,
orRsOperationFactor
);
effected
=
vehicleBookInfoMapper
.
updateBookedInfo
(
params
);
}
return
effected
>
0
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
return
effected
>
0
?
Boolean
.
TRUE
:
Boolean
.
FALSE
;
}
/**
* 检查车辆是否存在
*
* @param id
*/
public
boolean
checkIfVehicleExists
(
String
id
){
public
boolean
checkIfVehicleExists
(
String
id
)
{
Vehicle
vehicle
=
mapper
.
selectByPrimaryKey
(
id
);
if
(
vehicle
==
null
)
{
if
(
vehicle
==
null
)
{
return
false
;
}
if
(
vehicle
.
getStatus
().
equals
(
VehicleStatus
.
DISCARD
.
getCode
()))
{
throw
new
BaseException
(
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_DISABLE
.
getDesc
()
+
", 车辆状态是:"
+
getVehicleStatus
(
vehicle
.
getStatus
(),
vehicle
.
getId
()),
ResCode
.
VEHICLE_DEPARTURE_VEHICLE_DISABLE
.
getCode
());
}
//
if (vehicle.getStatus().equals(VehicleStatus.DISCARD.getCode())) {
//
throw new BaseException(ResCode.VEHICLE_DEPARTURE_VEHICLE_DISABLE.getDesc() + ", 车辆状态是:" + getVehicleStatus(vehicle.getStatus(), vehicle.getId()),
//
ResCode.VEHICLE_DEPARTURE_VEHICLE_DISABLE.getCode());
//
}
return
true
;
}
...
...
@@ -808,81 +831,87 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
break
;
}
List
<
VehicleBookRecordVo
>
vehicleBookRecordVos
=
vehicleBookRecordBiz
.
selectByVehicleId
(
vehicleId
);
if
(
vehicleBookRecordVos
!=
null
&&
vehicleBookRecordVos
.
size
()
>
0
)
{
vehicleBookRecordBiz
.
removeStatus2
(
vehicleBookRecordVos
);
if
(
vehicleBookRecordVos
!=
null
&&
vehicleBookRecordVos
.
size
()
>
0
&&
vehicleBookRecordVos
.
get
(
0
).
getBookEndDate
()
!=
null
&&
vehicleBookRecordVos
.
get
(
0
).
getBookEndDate
().
after
(
new
Date
()))
{
stringBuilder
.
append
(
"中,使用人:"
);
stringBuilder
.
append
(
vehicleBookRecordVos
.
get
(
0
).
getVehicleUsername
());
stringBuilder
.
append
(
" 使用人电话:"
);
stringBuilder
.
append
(
vehicleBookRecordVos
.
get
(
0
).
getVehicleUserPhone
());
}
else
{
stringBuilder
.
append
(
", 请联系管理员修改车辆状态为正常状态"
);
}
return
stringBuilder
.
toString
();
}
/**
* 把日期范围转换为列表,并检查操作范围是否合法
*
* @param yearMonthAndDate
* @param startDay
* @param endDay
*/
private
void
fillDateList4DatePeriod
(
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
DateTime
startDay
,
DateTime
endDay
)
{
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)<=
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
private
void
fillDateList4DatePeriod
(
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
DateTime
startDay
,
DateTime
endDay
)
{
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)
<=
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
String
curDateStr
=
curDate
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
if
(
curDateStr
.
compareTo
(
DateTime
.
now
().
toString
(
DEFAULT_DATE_TIME_FORMATTER
))<
0
)
{
if
(
curDateStr
.
compareTo
(
DateTime
.
now
().
toString
(
DEFAULT_DATE_TIME_FORMATTER
))
<
0
)
{
throw
new
BaseException
(
ResultCode
.
ONLY_BOOK_FROM_TODAY
);
}
String
curYearMonth
=
curDate
.
toString
(
YEARMONTH_DATE_TIME_FORMATTER
);
if
(!
yearMonthAndDate
.
containsKey
(
curYearMonth
))
{
yearMonthAndDate
.
put
(
curYearMonth
,
Lists
.
newArrayList
());
if
(!
yearMonthAndDate
.
containsKey
(
curYearMonth
))
{
yearMonthAndDate
.
put
(
curYearMonth
,
Lists
.
newArrayList
());
}
List
<
String
>
curBookedDateList
=
yearMonthAndDate
.
get
(
curYearMonth
);
curBookedDateList
.
add
(
curDateStr
);
}
if
(
yearMonthAndDate
.
size
()>
3
)
{
//连续的日期最多夸3个月
if
(
yearMonthAndDate
.
size
()
>
3
)
{
//连续的日期最多夸3个月
throw
new
BaseException
(
" 只可以预约两个月内的车辆"
);
}
}
private
void
uinbookDateList4DatePeriod
(
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
DateTime
startDay
,
DateTime
endDay
){
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)<=
0
;
curDate
=
curDate
.
plusDays
(
1
)){
private
void
unbookDateList4DatePeriod
(
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
DateTime
startDay
,
DateTime
endDay
)
{
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)
<=
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
String
curDateStr
=
curDate
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
// if(curDateStr.compareTo(DateTime.now().toString(DEFAULT_DATE_TIME_FORMATTER))<0){
// throw new BaseException("只可以取消当前时间之后的车辆");
// }
String
curYearMonth
=
curDate
.
toString
(
YEARMONTH_DATE_TIME_FORMATTER
);
if
(!
yearMonthAndDate
.
containsKey
(
curYearMonth
))
{
yearMonthAndDate
.
put
(
curYearMonth
,
Lists
.
newArrayList
());
if
(!
yearMonthAndDate
.
containsKey
(
curYearMonth
))
{
yearMonthAndDate
.
put
(
curYearMonth
,
Lists
.
newArrayList
());
}
List
<
String
>
curBookedDateList
=
yearMonthAndDate
.
get
(
curYearMonth
);
curBookedDateList
.
add
(
curDateStr
);
}
if
(
yearMonthAndDate
.
size
()>
3
)
{
//连续的日期最多夸3个月
if
(
yearMonthAndDate
.
size
()
>
3
)
{
//连续的日期最多夸3个月
throw
new
BaseException
(
ResultCode
.
ONLY_BOOK_TWO_MONTH
);
}
}
/**
* 取消预定(释放bookinfo)
*
* @return
*/
@Transactional
public
Boolean
unbookVehicle
(
BookVehicleVO
bookVehicleVo
)
throws
Exception
{
public
Boolean
unbookVehicle
(
BookVehicleVO
bookVehicleVo
)
throws
Exception
{
//提取日期参数,改为每月一份
//提取日期和相应的预定目标日期
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getUnbookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getUnbookEndDate
(),
DATE_TIME_FORMATTER
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
Maps
.
newHashMap
();
DateTime
startDay
=
DateTime
.
parse
(
bookVehicleVo
.
getUnbookStartDate
(),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
bookVehicleVo
.
getUnbookEndDate
(),
DATE_TIME_FORMATTER
);
//转换日期范围为列表,并检查是否合法
u
inbookDateList4DatePeriod
(
yearMonthAndDate
,
startDay
,
endDay
);
u
nbookDateList4DatePeriod
(
yearMonthAndDate
,
DateTime
.
parse
(
startDay
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
DEFAULT_DATE_TIME_FORMATTER
),
DateTime
.
parse
(
endDay
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
DEFAULT_DATE_TIME_FORMATTER
)
);
//原设计为 读取 bookVehicleVo.getNotCheckTimeLegal(), 现在取消/拒绝 true
Map
<
String
,
Integer
>
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
bookVehicleVo
.
getUnbookStartDate
(),
bookVehicleVo
.
getUnbookEndDate
(),
Boolean
.
TRUE
);
if
(
yearMonthAndDate
.
size
()>
3
)
{
//连续的日期最多夸3个月
if
(
yearMonthAndDate
.
size
()
>
3
)
{
//连续的日期最多夸3个月
throw
new
BaseException
(
ResultCode
.
ONLY_UNBOOK_TWO_MONTH
);
}
Boolean
rs
=
Boolean
.
TRUE
;
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDate
.
entrySet
())
{
Boolean
rsEach
=
unbookVehiclePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
(),
map
);
if
(
Boolean
.
FALSE
.
equals
(
rsEach
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
yearMonthAndDate
.
entrySet
())
{
Boolean
rsEach
=
unbookVehiclePerMonth
(
bookVehicleVo
.
getVehicleId
(),
entry
.
getValue
(),
entry
.
getKey
(),
map
);
if
(
Boolean
.
FALSE
.
equals
(
rsEach
))
{
rs
=
Boolean
.
FALSE
;
TransactionAspectSupport
.
currentTransactionStatus
().
setRollbackOnly
();
//手动回滚
}
...
...
@@ -892,54 +921,56 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
@Transactional
public
Boolean
unbookVehiclePerMonth
(
String
vehicleId
,
List
<
String
>
unbookDates
,
String
yearMonth
,
Map
<
String
,
Integer
>
hourInfo
){
public
Boolean
unbookVehiclePerMonth
(
String
vehicleId
,
List
<
String
>
unbookDates
,
String
yearMonth
,
Map
<
String
,
Integer
>
hourInfo
)
{
checkIfVehicleExists
(
vehicleId
);
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicleId"
,
vehicleId
);
params
.
put
(
"yearMonth"
,
yearMonth
);
Map
<
String
,
Object
>
params
=
Maps
.
newHashMap
();
params
.
put
(
"vehicleId"
,
vehicleId
);
params
.
put
(
"yearMonth"
,
yearMonth
);
//加入更新条件
if
(
CollectionUtils
.
isEmpty
(
unbookDates
))
{
if
(
CollectionUtils
.
isEmpty
(
unbookDates
))
{
throw
new
BaseException
(
ResultCode
.
VEHICLE_CAN_NOT_UNBOOK
);
}
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
yearMonth
,
unbookDates
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
yearMonthAndDate
.
put
(
yearMonth
,
unbookDates
);
//转换为查询对应日期未预定的条件
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
null
);
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
null
);
//提取相关参数组装更细条件
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
yearMonth
);
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
(
Map
<
String
,
Map
<
String
,
Integer
>>)
params
.
get
(
"yearMonthAndParam"
);
Map
<
String
,
Integer
>
andOpratorParam
=
yearMonthAndParam
.
get
(
yearMonth
);
params
.
putAll
(
andOpratorParam
);
Integer
andRsOperationFactor
=
getBitOpratorFactor4UnBooked
(
unbookDates
);
//预定的相关或运算因子,当前月份没有预定记录时同时也是结果
params
.
put
(
"andRsOperationFactor"
,
andRsOperationFactor
);
return
unbookHourInfo
(
vehicleId
,
hourInfo
,
params
);
return
unbookHourInfo
(
vehicleId
,
hourInfo
,
params
);
}
public
boolean
unbookHourInfo
(
String
vehicleId
,
Map
<
String
,
Integer
>
hourInfo
,
Map
<
String
,
Object
>
params
)
{
boolean
flag
=
false
;
public
boolean
unbookHourInfo
(
String
vehicleId
,
Map
<
String
,
Integer
>
hourInfo
,
Map
<
String
,
Object
>
params
)
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
hourInfo
.
entrySet
())
{
VehicleBookHourInfoDto
vehicleBookHourInfoDto
=
new
VehicleBookHourInfoDto
();
vehicleBookHourInfoDto
.
setYearMonthDay
(
entry
.
getKey
());
vehicleBookHourInfoDto
.
setVehicleId
(
vehicleId
);
List
<
VehicleBookHourInfo
>
vehicleBookHourInfos
=
vehicleBookHourInfoBiz
.
selectByVehicleAndDate
(
vehicleBookHourInfoDto
);
if
(
vehicleBookHourInfos
!=
null
&&
vehicleBookHourInfos
.
size
()
>
0
)
{
vehicleBookHourInfos
.
get
(
0
).
setBookedHour
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
~
entry
.
getValue
()));
if
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
~
entry
.
getValue
())
==
0
)
{
if
(!
flag
)
{
//解决重复执行的问题
Integer
effected
=
vehicleBookInfoMapper
.
updateBookedInfo
(
params
);
if
(
effected
<
1
)
{
return
Boolean
.
FALSE
;
}
flag
=
true
;
}
}
int
effect
=
vehicleBookHourInfoBiz
.
updateByIdRe
(
vehicleBookHourInfos
.
get
(
0
));
if
(
effect
<
0
)
{
return
Boolean
.
FALSE
;
}
else
{
continue
;
}
if
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
~
entry
.
getValue
())
==
0
)
{
//时间取与运算为0说明当天全部取消预定
DateTime
dateTime
=
DateTime
.
parse
(
entry
.
getKey
(),
DEFAULT_DATE_TIME_FORMATTER
);
Integer
andOperationFactor
=
0
;
andOperationFactor
|=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
VehicleBookInfo
vehicleBookInfo
=
getByVehicleIdAndYearMonth
(
vehicleId
,
dateTime
.
toString
(
YEARMONTH_DATE_TIME_FORMATTER
));
if
(
vehicleBookInfo
!=
null
)
{
vehicleBookInfo
.
setBookedDate
(
vehicleBookInfo
.
getBookedDate
()
&
~
andOperationFactor
);
int
effected
=
vehicleBookInfoBiz
.
update
(
vehicleBookInfo
);
if
(
effected
<
1
)
{
return
Boolean
.
FALSE
;
}
}
}
vehicleBookHourInfos
.
get
(
0
).
setBookedHour
((
vehicleBookHourInfos
.
get
(
0
).
getBookedHour
()
&
~
entry
.
getValue
()));
int
effect
=
vehicleBookHourInfoBiz
.
updateByIdRe
(
vehicleBookHourInfos
.
get
(
0
));
if
(
effect
<
1
)
{
return
Boolean
.
FALSE
;
}
else
{
continue
;
}
}
else
{
return
Boolean
.
FALSE
;
}
...
...
@@ -949,77 +980,78 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 获取某月份相应预定日期查询条件
* @param yearMonthAndDate 年月 - 预定日期条件字符串(yyyy-MM-dd)
*
* @param yearMonthAndDate 年月 - 预定日期条件字符串(yyyy-MM-dd)
* @param yearMonthAndDateNotBooked 年月 - 未预定日期条件字符串
* @return
*/
public
void
fillBookedDateSearchParam
(
Map
<
String
,
Object
>
params
,
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
)
{
if
(
MapUtils
.
isEmpty
(
yearMonthAndDate
)&&
MapUtils
.
isEmpty
(
yearMonthAndDateNotBooked
))
{
//没有预定信息查询条件
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
)
{
if
(
MapUtils
.
isEmpty
(
yearMonthAndDate
)
&&
MapUtils
.
isEmpty
(
yearMonthAndDateNotBooked
))
{
//没有预定信息查询条件
throw
new
BaseException
(
ResultCode
.
BOOKED_DATE_IS_EMPTY
);
}
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
new
HashMap
<>();
Map
<
String
,
Map
<
String
,
Integer
>>
yearMonthAndParam
=
new
HashMap
<>();
Set
<
String
>
bookedYearMonth
=
new
HashSet
<>();
//记录未预定查询条件,供检查是否是否存在同一天既是已预定,又是没有预定
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndDate
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDate
.
entrySet
())
{
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndDate
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
yearMonthAndDate
.
entrySet
())
{
String
curYearMonth
=
entry
.
getKey
();
if
(
CollectionUtils
.
isEmpty
(
entry
.
getValue
()))
{
if
(
CollectionUtils
.
isEmpty
(
entry
.
getValue
()))
{
continue
;
}
Integer
andOperationFactor
=
0
;
//查找条件中作与运算的参数
Integer
andOperationRs
=
0
;
//与运算结果
for
(
String
dateStr
:
entry
.
getValue
())
{
//已预定作为条件,该位与1作与运算必定为1
for
(
String
dateStr
:
entry
.
getValue
())
{
//已预定作为条件,该位与1作与运算必定为1
DateTime
dateTime
=
DateTime
.
parse
(
dateStr
,
DEFAULT_DATE_TIME_FORMATTER
);
bookedYearMonth
.
add
(
dateStr
);
//仅对应位为1的整形值
andOperationFactor
|=
1
<<(
dateTime
.
dayOfMonth
().
get
()-
1
);
andOperationRs
|=
1
<<(
dateTime
.
dayOfMonth
().
get
()-
1
);
andOperationFactor
|=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
andOperationRs
|=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
}
Map
<
String
,
Integer
>
andOperationParam
=
Maps
.
newHashMap
();
andOperationParam
.
put
(
"andOperationFactor"
,
andOperationFactor
);
andOperationParam
.
put
(
"andOperationRs"
,
andOperationRs
);
yearMonthAndParam
.
put
(
curYearMonth
,
andOperationParam
);
Map
<
String
,
Integer
>
andOperationParam
=
Maps
.
newHashMap
();
andOperationParam
.
put
(
"andOperationFactor"
,
andOperationFactor
);
andOperationParam
.
put
(
"andOperationRs"
,
andOperationRs
);
yearMonthAndParam
.
put
(
curYearMonth
,
andOperationParam
);
}
}
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndDateNotBooked
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry:
yearMonthAndDateNotBooked
.
entrySet
())
{
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndDateNotBooked
))
{
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
yearMonthAndDateNotBooked
.
entrySet
())
{
String
curYearMonth
=
entry
.
getKey
();
if
(
CollectionUtils
.
isEmpty
(
entry
.
getValue
()))
{
if
(
CollectionUtils
.
isEmpty
(
entry
.
getValue
()))
{
continue
;
}
Map
<
String
,
Integer
>
andOperationParam
=
Maps
.
newHashMap
();
andOperationParam
.
put
(
"andOperationFactor"
,
0
);
andOperationParam
.
put
(
"andOperationRs"
,
0
);
Integer
andOperationFactor
=
0
;
//查找条件中作与运算的参数
if
(
yearMonthAndParam
.
containsKey
(
curYearMonth
))
{
Map
<
String
,
Integer
>
andOperationParam
=
Maps
.
newHashMap
();
andOperationParam
.
put
(
"andOperationFactor"
,
0
);
andOperationParam
.
put
(
"andOperationRs"
,
0
);
Integer
andOperationFactor
=
0
;
//查找条件中作与运算的参数
if
(
yearMonthAndParam
.
containsKey
(
curYearMonth
))
{
andOperationParam
=
yearMonthAndParam
.
get
(
curYearMonth
);
andOperationFactor
=
andOperationParam
.
get
(
"andOperationFactor"
);
}
else
{
yearMonthAndParam
.
put
(
curYearMonth
,
andOperationParam
);
}
else
{
yearMonthAndParam
.
put
(
curYearMonth
,
andOperationParam
);
}
for
(
String
dateStr
:
entry
.
getValue
())
{
//已预定作为条件,该位与1作与运算必定为1
if
(
bookedYearMonth
.
contains
(
dateStr
))
{
for
(
String
dateStr
:
entry
.
getValue
())
{
//已预定作为条件,该位与1作与运算必定为1
if
(
bookedYearMonth
.
contains
(
dateStr
))
{
log
.
info
(
"当天不可预定,日期为:dateStr = {}"
,
dateStr
);
throw
new
BaseException
(
ResultCode
.
TODAY_CAN_NOT_BOOK
);
}
DateTime
dateTime
=
DateTime
.
parse
(
dateStr
,
DEFAULT_DATE_TIME_FORMATTER
);
//仅对应位为1的整形值
andOperationFactor
|=
1
<<(
dateTime
.
dayOfMonth
().
get
()-
1
);
andOperationFactor
|=
1
<<
(
dateTime
.
dayOfMonth
().
get
()
-
1
);
}
andOperationParam
.
put
(
"andOperationFactor"
,
andOperationFactor
);
andOperationParam
.
put
(
"andOperationFactor"
,
andOperationFactor
);
// if(!bookedYearMonth.contains(curYearMonth)){//仅以未预定日期条件查询时,不存在预定记录即为没有预定
// andOperationParam.put("notBookedOnly",1);
// }
}
}
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndParam
))
{
params
.
put
(
"yearMonthAndParam"
,
yearMonthAndParam
);
if
(
MapUtils
.
isNotEmpty
(
yearMonthAndParam
))
{
params
.
put
(
"yearMonthAndParam"
,
yearMonthAndParam
);
String
bitStr
=
""
;
for
(
String
key
:
yearMonthAndParam
.
keySet
())
{
bitStr
+=
"1"
;
for
(
String
key
:
yearMonthAndParam
.
keySet
())
{
bitStr
+=
"1"
;
}
params
.
put
(
"yearMonthAndParamBitStr"
,
bitStr
);
}
...
...
@@ -1028,15 +1060,15 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 根据月份分类到map中
*/
private
void
classifyByYearMonth
(
List
<
String
>
target
,
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
Set
<
String
>
allYearMonth
)
{
if
(
CollectionUtils
.
isNotEmpty
(
target
))
{
//已预约
private
void
classifyByYearMonth
(
List
<
String
>
target
,
Map
<
String
,
List
<
String
>>
yearMonthAndDate
,
Set
<
String
>
allYearMonth
)
{
if
(
CollectionUtils
.
isNotEmpty
(
target
))
{
//已预约
for
(
String
dateStr
:
target
)
{
String
curYearMonth
=
DateTime
.
parse
(
dateStr
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
YEARMONTH_DATE_TIME_FORMATTER
);
allYearMonth
.
add
(
curYearMonth
);
List
<
String
>
dateStrList
=
yearMonthAndDate
.
get
(
curYearMonth
);
if
(
dateStrList
==
null
)
{
if
(
dateStrList
==
null
)
{
dateStrList
=
Lists
.
newArrayList
();
yearMonthAndDate
.
put
(
curYearMonth
,
dateStrList
);
yearMonthAndDate
.
put
(
curYearMonth
,
dateStrList
);
}
dateStrList
.
add
(
dateStr
);
}
...
...
@@ -1045,15 +1077,16 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 把日期范围转换成列表
*
* @param startDate
* @param endDate
* @return
*/
private
List
<
String
>
convertDatePeriod2List
(
String
startDate
,
String
endDate
)
{
DateTime
startDay
=
DateTime
.
parse
(
startDate
,
DEFAULT_DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
endDate
,
DEFAULT_DATE_TIME_FORMATTER
);
private
List
<
String
>
convertDatePeriod2List
(
String
startDate
,
String
endDate
)
{
DateTime
startDay
=
DateTime
.
parse
(
startDate
,
DEFAULT_DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
endDate
,
DEFAULT_DATE_TIME_FORMATTER
);
List
<
String
>
rs
=
Lists
.
newArrayList
();
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)<=
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
for
(
DateTime
curDate
=
startDay
;
curDate
.
compareTo
(
endDay
)
<=
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
String
curDateStr
=
curDate
.
toString
(
DEFAULT_DATE_TIME_FORMATTER
);
rs
.
add
(
curDateStr
);
}
...
...
@@ -1062,13 +1095,14 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 根据前端预定日期查询条件转换为实际查询条件
*
* @param params
* @return
*/
public
void
adjustBookedInfoParam
(
Map
<
String
,
Object
>
params
,
VehiclePageQueryVo
vehiclePageQueryVo
)
{
public
void
adjustBookedInfoParam
(
Map
<
String
,
Object
>
params
,
VehiclePageQueryVo
vehiclePageQueryVo
)
{
//加入每月预定信息查询条件
List
<
String
>
bookedDates
=
Lists
.
newArrayList
();
if
(
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getBookedStartDate
())
&&
if
(
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getBookedStartDate
())
&&
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getBookedEndDate
()))
{
bookedDates
=
convertDatePeriod2List
(
vehiclePageQueryVo
.
getBookedStartDate
(),
vehiclePageQueryVo
.
getBookedEndDate
());
...
...
@@ -1077,7 +1111,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
params
.
remove
(
"bookEndDate"
);
List
<
String
>
notBookedDates
=
Lists
.
newArrayList
();
if
(
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getNotBookedStartDate
())
&&
if
(
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getNotBookedStartDate
())
&&
StringUtils
.
isNotBlank
(
vehiclePageQueryVo
.
getNotBookedEndDate
()))
{
notBookedDates
=
convertDatePeriod2List
(
vehiclePageQueryVo
.
getNotBookedStartDate
(),
vehiclePageQueryVo
.
getNotBookedEndDate
());
...
...
@@ -1086,68 +1120,71 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
params
.
remove
(
"norBookedEndDate"
);
//若传入预定信息查询条件,则查询对应月份预定信息查询条件(不超过3个月)
if
(
CollectionUtils
.
isEmpty
(
bookedDates
)
&&
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
if
(
CollectionUtils
.
isEmpty
(
bookedDates
)
&&
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
return
;
}
//筛选出查询条件所在月份
Set
<
String
>
allYearMonth
=
new
HashSet
<>();
//记录所有年月
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//预定年月 - 预定日期列表
classifyByYearMonth
(
bookedDates
,
yearMonthAndDate
,
allYearMonth
);
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//未预定年月 - 未预定日期列表
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()>
0
&&
params
.
get
(
"subordinateBranch"
)
==
null
)
{
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//预定年月 - 预定日期列表
classifyByYearMonth
(
bookedDates
,
yearMonthAndDate
,
allYearMonth
);
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//未预定年月 - 未预定日期列表
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()
>
0
&&
params
.
get
(
"subordinateBranch"
)
==
null
)
{
throw
new
BaseException
(
" <subordinateBranch> must included in params while using <bookedInfo> param. "
);
}
if
(
allYearMonth
.
size
()>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
if
(
allYearMonth
.
size
()
>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
}
//加入预定信息查询条件
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
}
/**
* 按页查询
*
* @param vehiclePageQueryVo
* @return
* @throws Exception
*/
public
PageDataVO
<
ResultVehicleVo
>
getByPage
(
VehiclePageQueryVo
vehiclePageQueryVo
)
throws
Exception
{
public
PageDataVO
<
ResultVehicleVo
>
getByPage
(
VehiclePageQueryVo
vehiclePageQueryVo
)
throws
Exception
{
Map
<
String
,
Object
>
params
=
PropertyUtils
.
describe
(
vehiclePageQueryVo
);
Integer
pageSize
=
(
Integer
)
params
.
get
(
"limit"
);
params
.
remove
(
"pageSize"
);
Integer
pageNo
=
(
Integer
)
params
.
get
(
"page"
);
params
.
remove
(
"pageNo"
);
//处理预定日期相关参数
adjustBookedInfoParam
(
params
,
vehiclePageQueryVo
);
adjustBookedInfoParam
(
params
,
vehiclePageQueryVo
);
params
.
get
(
"yearMonthAndParam"
);
if
(
vehiclePageQueryVo
.
getModelId
()
==
null
)
{
if
(
vehiclePageQueryVo
.
getModelId
()
==
null
)
{
params
.
remove
(
"modelId"
);
}
PageHelper
.
startPage
(
pageNo
,
pageSize
);
PageHelper
.
startPage
(
pageNo
,
pageSize
);
List
<
ResultVehicleVo
>
vehicles
=
mapper
.
getByPage
(
params
);
PageInfo
<
ResultVehicleVo
>
vehiclePageInfo
=
new
PageInfo
<>(
vehicles
);
return
PageDataVO
.
pageInfo
(
vehiclePageInfo
);
}
/**
* 按页查询(非所有数据,过滤分公司信息)
*
* @param vehiclePageQueryVo
* @return
* @throws Exception
*/
public
PageDataVO
<
ResultVehicleVo
>
getByPageNotAllData
(
VehiclePageQueryVo
vehiclePageQueryVo
,
List
<
Integer
>
companyList
)
throws
Exception
{
public
PageDataVO
<
ResultVehicleVo
>
getByPageNotAllData
(
VehiclePageQueryVo
vehiclePageQueryVo
,
List
<
Integer
>
companyList
)
throws
Exception
{
Map
<
String
,
Object
>
params
=
PropertyUtils
.
describe
(
vehiclePageQueryVo
);
Integer
pageSize
=
(
Integer
)
params
.
get
(
"limit"
);
params
.
remove
(
"pageSize"
);
Integer
pageNo
=
(
Integer
)
params
.
get
(
"page"
);
params
.
remove
(
"pageNo"
);
//处理预定日期相关参数
adjustBookedInfoParam
(
params
,
vehiclePageQueryVo
);
adjustBookedInfoParam
(
params
,
vehiclePageQueryVo
);
if
(
companyList
!=
null
&&
companyList
.
size
()
>
0
)
{
params
.
put
(
"companyList"
,
companyList
);
}
else
{
params
.
put
(
"companyList"
,
Arrays
.
asList
(-
1
));
}
PageHelper
.
startPage
(
pageNo
,
pageSize
);
PageHelper
.
startPage
(
pageNo
,
pageSize
);
List
<
ResultVehicleVo
>
vehicles
=
mapper
.
getByPageNotAllData
(
params
);
PageInfo
<
ResultVehicleVo
>
vehiclePageInfo
=
new
PageInfo
<>(
vehicles
);
return
PageDataVO
.
pageInfo
(
vehiclePageInfo
);
...
...
@@ -1155,9 +1192,9 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
public
List
<
Integer
>
dataCompany
(
String
dataZone
,
String
dataCompany
)
{
List
<
BranchCompany
>
zoneCompanys
=
branchCompanyBiz
.
dataCompany
(
dataZone
);
//((VehicleBiz)AopContext.currentProxy()).dataCompany(dataZone);
//((VehicleBiz)AopContext.currentProxy()).dataCompany(dataZone);
List
<
Integer
>
zoneCompanyIds
=
zoneCompanys
.
parallelStream
().
map
(
BranchCompany:
:
getId
).
collect
(
Collectors
.
toList
());
if
(
StringUtils
.
isNotBlank
(
dataCompany
))
{
if
(
StringUtils
.
isNotBlank
(
dataCompany
))
{
List
<
Integer
>
dataCompanyIds
=
Arrays
.
asList
(
dataCompany
.
split
(
","
)).
parallelStream
().
map
(
s
->
Integer
.
valueOf
(
s
)).
collect
(
Collectors
.
toList
());
zoneCompanyIds
.
addAll
(
dataCompanyIds
);
}
...
...
@@ -1165,15 +1202,15 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
return
zoneCompanyIds
.
parallelStream
().
distinct
().
collect
(
Collectors
.
toList
());
}
public
PageDataVO
<
UsableVehicleModelVO
>
searchUsableModel
(
UsableVeicleDTO
dto
){
public
PageDataVO
<
UsableVehicleModelVO
>
searchUsableModel
(
UsableVeicleDTO
dto
)
{
Map
<
String
,
Object
>
params
=
BeanUtil
.
beanToMap
(
dto
);
if
(
StrUtil
.
isNotBlank
(
dto
.
getStartDate
())
&&
StrUtil
.
isNotBlank
(
dto
.
getEndDate
()))
{
if
(
StrUtil
.
isNotBlank
(
dto
.
getStartDate
())
&&
StrUtil
.
isNotBlank
(
dto
.
getEndDate
()))
{
initBookSearchParam
(
dto
,
params
);
}
return
PageDataVO
.
pageInfo
(
dto
.
getPage
(),
dto
.
getLimit
(),
()
->
mapper
.
searchUsableModel
(
params
));
}
public
PageDataVO
<
UsableVehicleModelVO
>
hotModel
(
HotVeicleDTO
dto
){
public
PageDataVO
<
UsableVehicleModelVO
>
hotModel
(
HotVeicleDTO
dto
)
{
dto
.
setHotSign
(
1
);
Map
<
String
,
Object
>
params
=
BeanUtil
.
beanToMap
(
dto
);
return
PageDataVO
.
pageInfo
(
dto
.
getPage
(),
dto
.
getLimit
(),
()
->
mapper
.
searchUsableModel
(
params
));
...
...
@@ -1181,7 +1218,7 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
private
void
initBookSearchParam
(
UsableVeicleDTO
dto
,
Map
<
String
,
Object
>
params
)
{
List
<
String
>
notBookedDates
=
Lists
.
newArrayList
();
if
(
StringUtils
.
isNotBlank
(
dto
.
getStartDate
())
&&
if
(
StringUtils
.
isNotBlank
(
dto
.
getStartDate
())
&&
StringUtils
.
isNotBlank
(
dto
.
getEndDate
()))
{
// notBookedDates = convertDatePeriod2List(dto.getStartDate(),
// dto.getEndDate());
...
...
@@ -1190,27 +1227,27 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
//若传入预定信息查询条件,则查询对应月份预定信息查询条件(不超过3个月)
if
(
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
if
(
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
throw
new
BaseException
(
ResultCode
.
NOTEXIST_CODE
);
}
//筛选出查询条件所在月份 如 想预定 8月29 ~ 9月 4日
Set
<
String
>
allYearMonth
=
new
HashSet
<>();
//记录所有年月 "2019-08","2019-09"
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//需比较已预定的年月 - 预定日期列表 为空(拒绝 预约记录时用到)
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//需比较未预定的年月 - 未预定日期列表 "2019-08-29"...."2019-09-04",
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//需比较已预定的年月 - 预定日期列表 为空(拒绝 预约记录时用到)
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//需比较未预定的年月 - 未预定日期列表 "2019-08-29"...."2019-09-04",
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()
>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
}
//加入预定信息查询条件
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
}
public
PageDataVO
<
Vehicle
>
searchUsableVehicle
(
RentVehicleBookDTO
dto
)
{
public
PageDataVO
<
Vehicle
>
searchUsableVehicle
(
RentVehicleBookDTO
dto
)
{
Map
<
String
,
Object
>
params
=
BeanUtil
.
beanToMap
(
dto
);
List
<
String
>
notBookedDates
=
Lists
.
newArrayList
();
if
(
StringUtils
.
isNotBlank
(
dto
.
getBookEndDate
())
&&
if
(
StringUtils
.
isNotBlank
(
dto
.
getBookEndDate
())
&&
StringUtils
.
isNotBlank
(
dto
.
getBookEndDate
()))
{
// notBookedDates = convertDatePeriod2List(dto.getBookStartDate(),
// dto.getBookEndDate());
...
...
@@ -1219,19 +1256,19 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
//若传入预定信息查询条件,则查询对应月份预定信息查询条件(不超过3个月)
if
(
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
if
(
CollectionUtils
.
isEmpty
(
notBookedDates
))
{
//return;
}
//筛选出查询条件所在月份
Set
<
String
>
allYearMonth
=
new
HashSet
<>();
//记录所有年月
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//预定年月 - 预定日期列表
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//未预定年月 - 未预定日期列表
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
Map
<
String
,
List
<
String
>>
yearMonthAndDate
=
new
HashMap
<>();
//预定年月 - 预定日期列表
Map
<
String
,
List
<
String
>>
yearMonthAndDateNotBooked
=
new
HashMap
<>();
//未预定年月 - 未预定日期列表
classifyByYearMonth
(
notBookedDates
,
yearMonthAndDateNotBooked
,
allYearMonth
);
if
(
allYearMonth
.
size
()
>
MAX_MONTH_COUNT_BOOKED_INFO_QUERY
)
{
throw
new
BaseException
(
" only 3 month can be included <bookedInfo> param."
);
}
//加入预定信息查询条件
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
fillBookedDateSearchParam
(
params
,
yearMonthAndDate
,
yearMonthAndDateNotBooked
);
PageHelper
.
startPage
(
dto
.
getPage
(),
dto
.
getLimit
());
List
<
Vehicle
>
lists
=
mapper
.
searchUsableVehicle
(
params
);
...
...
@@ -1241,38 +1278,40 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 保存
*
* @param vehicle
* @return
*/
@Transactional
public
ObjectRestResponse
save
(
Vehicle
vehicle
){
if
(
vehicle
==
null
)
{
ObjectRestResponse
.
paramIsEmpty
();
public
ObjectRestResponse
save
(
Vehicle
vehicle
)
{
if
(
vehicle
==
null
)
{
ObjectRestResponse
.
paramIsEmpty
();
}
String
id
=
vehicle
.
getId
();
if
(
StringUtils
.
isBlank
(
id
))
{
insertSelective
(
vehicle
);
insertSelective
(
vehicle
);
}
else
{
updateSelectiveById
(
vehicle
);
insertSelective
(
vehicle
);
}
else
{
updateSelectiveById
(
vehicle
);
}
return
ObjectRestResponse
.
succ
();
return
ObjectRestResponse
.
succ
();
}
/**
* 查找
*
* @param vehicleVo
* @param page
* @param limit
* @return
*/
public
ObjectRestResponse
findListByVehicle
(
VehicleVo
vehicleVo
,
Integer
page
,
Integer
limit
){
public
ObjectRestResponse
findListByVehicle
(
VehicleVo
vehicleVo
,
Integer
page
,
Integer
limit
)
{
Vehicle
vehicle
=
new
Vehicle
();
// vehicleVo复制一份到vehicle
try
{
BeanUtilsBean
.
getInstance
().
copyProperties
(
vehicle
,
vehicleVo
);
BeanUtilsBean
.
getInstance
().
copyProperties
(
vehicle
,
vehicleVo
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
...
...
@@ -1283,33 +1322,33 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
WeekendSqls
<
Vehicle
>
sqls
=
WeekendSqls
.<
Vehicle
>
custom
();
//车辆状态
if
(
vehicle
.
getStatus
()!=
null
||
vehicle
.
getStatus
()!=
0
)
{
sqls
.
andEqualTo
(
Vehicle:
:
getStatus
,
vehicle
.
getStatus
());
}
//车牌号
if
(
StringUtils
.
isBlank
(
vehicle
.
getNumberPlate
()))
{
sqls
.
andEqualTo
(
Vehicle:
:
getNumberPlate
,
vehicle
.
getNumberPlate
());
Function
<
Vehicle
,
Integer
>
getStatus
=
Vehicle:
:
getStatus
;
}
//公司
if
(
vehicle
.
getSubordinateBranch
()==
null
||
vehicle
.
getSubordinateBranch
()==
0
)
{
sqls
.
andEqualTo
(
Vehicle:
:
getSubordinateBranch
,
vehicle
.
getSubordinateBranch
());
}
//大区
if
(
vehicleVo
.
getZoneId
()==
null
||
vehicleVo
.
getZoneId
()==
0
)
{
//获取大区内的公司id
Example
example
=
Example
.
builder
(
BranchCompany
.
class
).
where
(
WeekendSqls
.<
BranchCompany
>
custom
()
.
andEqualTo
(
BranchCompany:
:
getZoneId
,
vehicleVo
.
getZoneId
())).
build
();
List
<
BranchCompany
>
branchCompanies
=
branchCompanyBiz
.
selectByExample
(
example
);
ArrayList
<
Integer
>
bIds
=
new
ArrayList
<>();
for
(
BranchCompany
branchCompany
:
branchCompanies
)
{
bIds
.
add
(
branchCompany
.
getId
());
}
sqls
.
andIn
(
Vehicle:
:
getSubordinateBranch
,
bIds
);
}
sqls
.
andEqualTo
(
Vehicle:
:
getStatus
,
0
);
if
(
vehicle
.
getStatus
()
!=
null
||
vehicle
.
getStatus
()
!=
0
)
{
sqls
.
andEqualTo
(
Vehicle:
:
getStatus
,
vehicle
.
getStatus
());
}
//车牌号
if
(
StringUtils
.
isBlank
(
vehicle
.
getNumberPlate
()))
{
sqls
.
andEqualTo
(
Vehicle:
:
getNumberPlate
,
vehicle
.
getNumberPlate
());
Function
<
Vehicle
,
Integer
>
getStatus
=
Vehicle:
:
getStatus
;
}
//公司
if
(
vehicle
.
getSubordinateBranch
()
==
null
||
vehicle
.
getSubordinateBranch
()
==
0
)
{
sqls
.
andEqualTo
(
Vehicle:
:
getSubordinateBranch
,
vehicle
.
getSubordinateBranch
());
}
//大区
if
(
vehicleVo
.
getZoneId
()
==
null
||
vehicleVo
.
getZoneId
()
==
0
)
{
//获取大区内的公司id
Example
example
=
Example
.
builder
(
BranchCompany
.
class
).
where
(
WeekendSqls
.<
BranchCompany
>
custom
()
.
andEqualTo
(
BranchCompany:
:
getZoneId
,
vehicleVo
.
getZoneId
())).
build
();
List
<
BranchCompany
>
branchCompanies
=
branchCompanyBiz
.
selectByExample
(
example
);
ArrayList
<
Integer
>
bIds
=
new
ArrayList
<>();
for
(
BranchCompany
branchCompany
:
branchCompanies
)
{
bIds
.
add
(
branchCompany
.
getId
());
}
sqls
.
andIn
(
Vehicle:
:
getSubordinateBranch
,
bIds
);
}
sqls
.
andEqualTo
(
Vehicle:
:
getStatus
,
0
);
Example
exa
=
Example
.
builder
(
Vehicle
.
class
).
where
(
sqls
).
build
();
PageDataVO
<
Object
>
objectPageDataVO
=
PageDataVO
.
pageInfo
(
page
,
limit
,
()
->
selectByExample
(
exa
));
return
ObjectRestResponse
.
succ
(
objectPageDataVO
);
...
...
@@ -1317,17 +1356,18 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
/**
* 查询条
*
* @param id
* @return
*/
public
ObjectRestResponse
getOneById
(
Integer
id
){
public
ObjectRestResponse
getOneById
(
Integer
id
)
{
return
ObjectRestResponse
.
succ
(
selectByExample
(
Example
.
builder
(
Vehicle
.
class
)
.
where
(
WeekendSqls
.<
Vehicle
>
custom
()
.
andEqualTo
(
Vehicle:
:
getId
,
id
)
.
andEqualTo
(
Vehicle:
:
getStatus
,
0
))
.
build
()));
return
ObjectRestResponse
.
succ
(
selectByExample
(
Example
.
builder
(
Vehicle
.
class
)
.
where
(
WeekendSqls
.<
Vehicle
>
custom
()
.
andEqualTo
(
Vehicle:
:
getId
,
id
)
.
andEqualTo
(
Vehicle:
:
getStatus
,
0
))
.
build
()));
}
...
...
@@ -1342,21 +1382,21 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
public
ObjectRestResponse
<
PageDataVO
<
VehicleAndModelInfoVo
>>
getVehicle
(
VehiclePlanDto
vehiclePlanDto
)
{
Integer
page
=
vehiclePlanDto
.
getPage
()
==
null
?
1
:
vehiclePlanDto
.
getPage
();
Integer
page
=
vehiclePlanDto
.
getPage
()
==
null
?
1
:
vehiclePlanDto
.
getPage
();
Integer
limit
=
vehiclePlanDto
.
getLimit
()
==
null
?
10
:
vehiclePlanDto
.
getLimit
();
vehiclePlanDto
.
setPage
(
page
);
vehiclePlanDto
.
setLimit
(
limit
);
UserDTO
userDTO
=
getAdminUserInfo
();
if
(
userDTO
==
null
)
{
if
(
userDTO
==
null
)
{
return
ObjectRestResponse
.
createFailedResult
(
ResultCode
.
RSTOKEN_EXPIRED_CODE
,
"token失效"
);
}
List
<
Integer
>
companyList
=
Lists
.
newArrayList
();
List
<
Integer
>
companyList
=
Lists
.
newArrayList
();
List
<
BranchCompany
>
branchCompany
=
branchCompanyBiz
.
getListByUser
(
userDTO
);
companyList
=
branchCompany
.
stream
().
map
(
BranchCompany:
:
getId
).
collect
(
Collectors
.
toList
());
if
(
vehiclePlanDto
.
getParkBranchCompanyId
()
!=
null
)
{
if
(
companyList
.
size
()
>
0
)
{
if
(
companyList
.
contains
(
vehiclePlanDto
.
getParkBranchCompanyId
()))
{
if
(
vehiclePlanDto
.
getParkBranchCompanyId
()
!=
null
)
{
if
(
companyList
.
size
()
>
0
)
{
if
(
companyList
.
contains
(
vehiclePlanDto
.
getParkBranchCompanyId
()))
{
companyList
.
clear
();
companyList
.
add
(
vehiclePlanDto
.
getParkBranchCompanyId
());
}
else
{
...
...
@@ -1374,27 +1414,27 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
//删除车辆信息
public
RestResponse
delVehicleById
(
String
id
)
{
Vehicle
vehicle
=
new
Vehicle
();
public
RestResponse
delVehicleById
(
String
id
)
{
Vehicle
vehicle
=
new
Vehicle
();
vehicle
.
setId
(
id
);
vehicle
.
setIsDel
(
1
);
updateSelectiveById
(
vehicle
);
return
RestResponse
.
suc
();
return
RestResponse
.
suc
();
}
public
List
<
String
>
getHourList
(
String
result
)
{
StringBuffer
stringBuffer
=
new
StringBuffer
();
if
(
result
.
length
()
<
24
)
{
//如果不足24位补0
for
(
int
i
=
0
;
i
<
24
-
result
.
length
();
i
++)
{
if
(
result
.
length
()
<
24
)
{
//如果不足24位补0
for
(
int
i
=
0
;
i
<
24
-
result
.
length
();
i
++)
{
stringBuffer
.
append
(
"0"
);
}
log
.
info
(
stringBuffer
.
toString
());
}
stringBuffer
.
append
(
result
);
List
<
String
>
list
=
new
ArrayList
<>(
24
);
for
(
int
i
=
0
;
i
<
stringBuffer
.
toString
().
length
();
i
++)
{
if
(
"1"
.
equals
(
stringBuffer
.
toString
().
charAt
(
i
)+
""
))
{
for
(
int
i
=
0
;
i
<
stringBuffer
.
toString
().
length
();
i
++)
{
if
(
"1"
.
equals
(
stringBuffer
.
toString
().
charAt
(
i
)
+
""
))
{
list
.
add
(
i
,
"1"
);
}
else
{
list
.
add
(
i
,
"0"
);
...
...
@@ -1404,6 +1444,6 @@ public class VehicleBiz extends BaseBiz<VehicleMapper, Vehicle> implements UserR
}
public
List
<
String
>
findExistVehicleIds
()
{
return
mapper
.
findExistVehicleIds
();
return
mapper
.
findExistVehicleIds
();
}
}
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleBookHourInfoBiz.java
View file @
7f912342
...
...
@@ -41,19 +41,19 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
public
static
final
DateTimeFormatter
DEFAULT_DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM-dd HH:mm:ss"
);
public
static
final
DateTimeFormatter
DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM-dd"
);
public
Map
<
String
,
Integer
>
getPredictableHours
(
String
bookStartDate
,
String
bookEndDate
,
Boolean
notCheckTimeLegal
)
{
public
Map
<
String
,
Integer
>
getPredictableHours
(
String
bookStartDate
,
String
bookEndDate
,
Boolean
notCheckTimeLegal
)
{
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
Date
startDate
=
null
;
Date
endDate
=
null
;
try
{
try
{
startDate
=
simpleDateFormat
.
parse
(
bookStartDate
);
endDate
=
simpleDateFormat
.
parse
(
bookEndDate
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//判定时间是否合法
if
(!
Boolean
.
TRUE
.
equals
(
notCheckTimeLegal
))
{
if
(!
Boolean
.
TRUE
.
equals
(
notCheckTimeLegal
))
{
if
(
bookStartDate
.
compareTo
(
DateTime
.
now
().
toString
(
DEFAULT_DATE_TIME_FORMATTER
))
<
0
)
{
throw
new
BaseException
(
ResultCode
.
ONLY_BOOK_FROM_TODAY
);
}
...
...
@@ -78,17 +78,17 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
}
DateTime
startDay
=
DateTime
.
parse
(
DateTime
.
parse
(
bookStartDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
),
DATE_TIME_FORMATTER
);
DateTime
endDay
=
DateTime
.
parse
(
DateTime
.
parse
(
bookEndDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
),
DATE_TIME_FORMATTER
);
if
(
startPredictableHour
==
0
)
{
//如果是0点就直接预订全天
if
(
startPredictableHour
==
0
)
{
//如果是0点就直接预订全天
startPredictableHour
=
16777215
;
}
if
(
DateTime
.
parse
(
bookStartDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
).
equals
(
DateTime
.
parse
(
bookEndDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
)))
{
//同一天预定
if
(
DateTime
.
parse
(
bookStartDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
).
equals
(
DateTime
.
parse
(
bookEndDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
)))
{
//同一天预定
//如果开始时间是0点开始
predictableHours
.
put
(
DateTime
.
parse
(
bookStartDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
),
startPredictableHour
&
endPredictableHour
);
}
else
{
//非同一天开始
predictableHours
.
put
(
DateTime
.
parse
(
bookStartDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
),
startPredictableHour
);
predictableHours
.
put
(
DateTime
.
parse
(
bookEndDate
,
DEFAULT_DATE_TIME_FORMATTER
).
toString
(
DATE_TIME_FORMATTER
),
endPredictableHour
);
}
if
(
endDay
.
getMillis
()
-
startDay
.
getMillis
()
>
24
*
3600
*
1000
)
{
//
if
(
endDay
.
getMillis
()
-
startDay
.
getMillis
()
>
24
*
3600
*
1000
)
{
//
for
(
DateTime
curDate
=
startDay
.
plusDays
(
1
);
curDate
.
compareTo
(
endDay
)
<
0
;
curDate
=
curDate
.
plusDays
(
1
))
{
String
curDateStr
=
curDate
.
toString
(
DATE_TIME_FORMATTER
);
//全天预定
...
...
@@ -115,14 +115,14 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
@Transactional
@CacheClear
(
key
=
"vehicle.hourInfo"
)
public
ObjectRestResponse
save
(
VehicleBookHourInfoDto
vehicleBookHourInfoDto
)
{
if
(
vehicleBookHourInfoDto
==
null
)
{
if
(
vehicleBookHourInfoDto
==
null
)
{
return
ObjectRestResponse
.
paramIsEmpty
();
}
List
<
VehicleBookHourInfo
>
vehicleBookHourInfos
=
mapper
.
selectByVehicleAndDate
(
vehicleBookHourInfoDto
);
//有数据直接更新
if
(
vehicleBookHourInfos
.
size
()
>=
1
)
{
for
(
VehicleBookHourInfo
vehicleBookHourInfo
:
vehicleBookHourInfos
)
{
if
(
vehicleBookHourInfo
.
getBookedHour
().
equals
(
vehicleBookHourInfoDto
.
getBookedHour
()))
{
if
(
vehicleBookHourInfos
.
size
()
>=
1
)
{
for
(
VehicleBookHourInfo
vehicleBookHourInfo
:
vehicleBookHourInfos
)
{
if
(
vehicleBookHourInfo
.
getBookedHour
().
equals
(
vehicleBookHourInfoDto
.
getBookedHour
()))
{
return
ObjectRestResponse
.
createFailedResult
(
ResCode
.
VEHICLE_IS_BOOKED_TODAY
.
getCode
(),
ResCode
.
VEHICLE_IS_BOOKED_TODAY
.
getDesc
());
}
else
{
vehicleBookHourInfo
.
setBookedHour
(
vehicleBookHourInfo
.
getBookedHour
()
|
vehicleBookHourInfoDto
.
getBookedHour
());
...
...
@@ -138,6 +138,7 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
/**
* 删除预定车辆小时记录信息
*
* @param vehicleId 车辆Id
* @param dateList 日期列表
* @return
...
...
@@ -145,7 +146,7 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
@Transactional
@CacheClear
(
key
=
"vehicle.hourInfo"
)
public
ObjectRestResponse
delete
(
String
vehicleId
,
List
<
String
>
dateList
)
{
if
(
StringUtils
.
isBlank
(
vehicleId
)
||
dateList
.
size
()
<=
0
)
{
if
(
StringUtils
.
isBlank
(
vehicleId
)
||
dateList
.
size
()
<=
0
)
{
return
ObjectRestResponse
.
paramIsEmpty
();
}
Map
<
String
,
Object
>
param
=
Maps
.
newHashMap
();
...
...
@@ -156,15 +157,15 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
return
ObjectRestResponse
.
succ
();
}
public
ObjectRestResponse
checkBookHourInfo
()
{
public
ObjectRestResponse
checkBookHourInfo
()
{
List
<
VehicleBookHourInfoDto
>
vehicleBookHourInfos
=
new
ArrayList
<>();
List
<
VehicleBookRecord
>
list
=
vehicleBookRecordBiz
.
selectListAll
();
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
for
(
VehicleBookRecord
vehicleBookRecord
:
list
)
{
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
for
(
VehicleBookRecord
vehicleBookRecord
:
list
)
{
VehicleDepartureLogVo
vehicleDepartureLog
=
vehicleDepartureService
.
getByRecordId
(
vehicleBookRecord
.
getId
());
if
((
vehicleDepartureLog
==
null
||
vehicleDepartureLog
.
getState
()
!=
1
)
&&
(
vehicleBookRecord
.
getStatus
()
==
2
||
vehicleBookRecord
.
getStatus
()
==
1
))
{
//未出车或未还车
if
((
vehicleDepartureLog
==
null
||
vehicleDepartureLog
.
getState
()
!=
1
)
&&
(
vehicleBookRecord
.
getStatus
()
==
2
||
vehicleBookRecord
.
getStatus
()
==
1
))
{
//未出车或未还车
Map
<
String
,
Integer
>
map
=
getPredictableHours
(
new
DateTime
(
vehicleBookRecord
.
getBookStartDate
()).
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
new
DateTime
(
vehicleBookRecord
.
getBookEndDate
()).
toString
(
DEFAULT_DATE_TIME_FORMATTER
),
Boolean
.
TRUE
);
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
VehicleBookHourInfoDto
vehicleBookHourInfoDto
=
new
VehicleBookHourInfoDto
();
vehicleBookHourInfoDto
.
setVehicleId
(
vehicleBookRecord
.
getVehicleId
());
vehicleBookHourInfoDto
.
setYearMonthDay
(
entry
.
getKey
());
...
...
@@ -204,10 +205,10 @@ public class VehicleBookHourInfoBiz extends BaseBiz<VehicleBookHourInfoMapper, V
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
VehicleBookHourInfoBiz
vehicleBookHourInfoBiz
=
new
VehicleBookHourInfoBiz
();
Map
<
String
,
Integer
>
map
=
vehicleBookHourInfoBiz
.
getPredictableHours
(
"2019-08-26 10:00:00"
,
"2019-08-27 10:00:00"
,
Boolean
.
TRUE
);
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
for
(
Map
.
Entry
<
String
,
Integer
>
entry
:
map
.
entrySet
())
{
System
.
out
.
println
(
entry
.
getKey
());
System
.
out
.
println
(
entry
.
getValue
());
}
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleBookInfoBiz.java
View file @
7f912342
...
...
@@ -29,7 +29,7 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
public
static
final
DateTimeFormatter
YEARMONTH_DATE_TIME_FORMATTER
=
DateTimeFormat
.
forPattern
(
"yyyy-MM"
);
public
static
final
Integer
DEL_BATCH_SIZE
=
1000
;
public
static
final
Integer
COPY_BATCH_SIZE
=
100
;
public
static
final
int
MONTH_INTERVAL
=
2
;
public
static
final
int
MONTH_INTERVAL
=
2
;
@Autowired
private
RedisTemplate
customRedisTemplate
;
...
...
@@ -40,14 +40,14 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
*/
@Scheduled
(
cron
=
"0 0 0 1 * ?"
)
//每月1号0点触发
@Transactional
public
void
transfer2HistoryTb
(){
public
void
transfer2HistoryTb
()
{
//获取表格名称
String
tbName
=
getTbNameNow
();
DateTime
now
=
DateTime
.
now
();
//当前获取的时间为标准
log
.
info
(
"开始预定信息迁移至历史表的定时任务。"
);
//每月初将上月数据复制到历史表
Boolean
needRun
=
copyDataLastMoth
(
now
,
tbName
);
if
(
needRun
)
{
Boolean
needRun
=
copyDataLastMoth
(
now
,
tbName
);
if
(
needRun
)
{
//每月初将上上月数据从当前信息表中删除
delDataTheMonthBeforeLast
(
now
,
tbName
);
}
...
...
@@ -57,14 +57,14 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
* 获取上月数据,并复制到历史表
*/
@Transactional
public
Boolean
copyDataLastMoth
(
DateTime
now
,
String
tbName
)
{
public
Boolean
copyDataLastMoth
(
DateTime
now
,
String
tbName
)
{
String
lastMonthStr
=
now
.
plusMonths
(-
1
).
toString
(
YEARMONTH_DATE_TIME_FORMATTER
);
String
redisKey
=
RedisKey
.
DEL_BOOK_INFO_LOCK_PREFIX
+
lastMonthStr
;
String
redisKey
=
RedisKey
.
DEL_BOOK_INFO_LOCK_PREFIX
+
lastMonthStr
;
Boolean
hasSuc
=
customRedisTemplate
.
opsForValue
().
setIfAbsent
(
redisKey
,
String
.
valueOf
(
DateTime
.
now
().
getMillis
()));
if
(
hasSuc
)
{
//设置1天后过期
customRedisTemplate
.
expire
(
redisKey
,
1
,
TimeUnit
.
DAYS
);
}
else
{
Boolean
hasSuc
=
customRedisTemplate
.
opsForValue
().
setIfAbsent
(
redisKey
,
String
.
valueOf
(
DateTime
.
now
().
getMillis
()));
if
(
hasSuc
)
{
//设置1天后过期
customRedisTemplate
.
expire
(
redisKey
,
1
,
TimeUnit
.
DAYS
);
}
else
{
log
.
info
(
"[预定信息迁移]乐观锁获取失败,该线程不执行任务。"
);
return
Boolean
.
FALSE
;
}
...
...
@@ -78,9 +78,9 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
params
.
put
(
"pageStart"
,
(
curPageNo
-
1
)
*
COPY_BATCH_SIZE
);
params
.
put
(
"pageSize"
,
COPY_BATCH_SIZE
);
vehicleBookInfoList
=
mapper
.
getByPage4YearMonth
(
params
);
if
(
CollectionUtils
.
isNotEmpty
(
vehicleBookInfoList
))
{
if
(
CollectionUtils
.
isNotEmpty
(
vehicleBookInfoList
))
{
//插入数据到历史表
for
(
VehicleBookInfo
vehicleBookInfo
:
vehicleBookInfoList
)
{
for
(
VehicleBookInfo
vehicleBookInfo
:
vehicleBookInfoList
)
{
Map
<
String
,
Object
>
insertHisParams
=
Maps
.
newHashMap
();
insertHisParams
.
put
(
"tbName"
,
tbName
);
insertHisParams
.
put
(
"id"
,
vehicleBookInfo
.
getId
());
...
...
@@ -91,17 +91,18 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
}
}
curPageNo
++;
log
.
info
(
"【复制上月预定信息至历史表中】,当前复制页【"
+
curPageNo
+
"】,页大小【"
+
COPY_BATCH_SIZE
+
"】"
);
}
while
(
CollectionUtils
.
isNotEmpty
(
vehicleBookInfoList
));
log
.
info
(
"复制上月预定信息至历史表中完成,总页数【"
+(
curPageNo
-
1
)+
"】"
);
;
return
Boolean
.
TRUE
;
log
.
info
(
"【复制上月预定信息至历史表中】,当前复制页【"
+
curPageNo
+
"】,页大小【"
+
COPY_BATCH_SIZE
+
"】"
);
}
while
(
CollectionUtils
.
isNotEmpty
(
vehicleBookInfoList
));
log
.
info
(
"复制上月预定信息至历史表中完成,总页数【"
+
(
curPageNo
-
1
)
+
"】"
);
;
return
Boolean
.
TRUE
;
}
/**
* 删除上上月数据
*/
@Transactional
public
void
delDataTheMonthBeforeLast
(
DateTime
now
,
String
tbName
)
{
public
void
delDataTheMonthBeforeLast
(
DateTime
now
,
String
tbName
)
{
String
theMonthBeforeLastStr
=
now
.
plusMonths
(-
2
).
toString
(
YEARMONTH_DATE_TIME_FORMATTER
);
Integer
effected
=
0
;
Integer
total
=
0
;
...
...
@@ -110,25 +111,29 @@ public class VehicleBookInfoBiz extends BaseBiz<VehicleBookInfoMapper, VehicleBo
params
.
put
(
"batchSize"
,
DEL_BATCH_SIZE
);
do
{
effected
=
mapper
.
del4YearMoth
(
params
);
total
+=
effected
;
log
.
info
(
"开始删除预定信息数据,删除总数【"
+
total
+
"】"
);
}
while
(
effected
!=
0
);
total
+=
effected
;
log
.
info
(
"开始删除预定信息数据,删除总数【"
+
total
+
"】"
);
}
while
(
effected
!=
0
);
log
.
info
(
"删除预定信息数据完成"
);
}
private
String
getTbNameNow
(){
return
TB_NAME_PREFIX
+
DateTime
.
now
().
toString
(
YEAR_DATE_TIME_FORMATTER
);
private
String
getTbNameNow
()
{
return
TB_NAME_PREFIX
+
DateTime
.
now
().
toString
(
YEAR_DATE_TIME_FORMATTER
);
}
/**
* 创建当年相关表格
*/
private
void
createTbIfNotExists
(
String
tbName
){
private
void
createTbIfNotExists
(
String
tbName
)
{
mapper
.
createTbIfNotExists
(
tbName
);
}
public
void
InsertBatch
(
List
<
VehicleBookInfo
>
bookInfos
)
{
mapper
.
insertBatch
(
bookInfos
);
}
public
int
update
(
VehicleBookInfo
vehicleBookInfo
)
{
return
mapper
.
updateById
(
vehicleBookInfo
);
}
}
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleBookRecordBiz.java
View file @
7f912342
...
...
@@ -93,6 +93,12 @@ public class VehicleBookRecordBiz extends BaseBiz<VehicleBookRecordMapper, Vehic
return
list
;
}
public
List
<
VehicleBookRecordVo
>
selectZeroHourRecord
(
Map
<
String
,
Object
>
param
)
{
List
<
VehicleBookRecordVo
>
list
=
mapper
.
selectZeroHourRecord
(
param
);
removeStatus2
(
list
);
return
list
;
}
public
int
changeRecordStatus
(
Map
<
String
,
Object
>
updateParam
)
{
return
mapper
.
changeRecordStatus
(
updateParam
);
}
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/biz/VehicleDepartureService.java
View file @
7f912342
...
...
@@ -86,7 +86,7 @@ public class VehicleDepartureService extends BaseBiz<VehicleDepartureLogMapper,
}
else
{
vehicleDepartureLog
.
setUpdateTime
(
new
Date
());
VehicleDepartureLog
oldValue
=
mapper
.
selectByPrimaryKey
(
vehicleDepartureLog
);
if
(
oldValue
!=
null
)
{
if
(
oldValue
!=
null
)
{
log
.
info
(
"更新出行记录: vehicleDepartureLog = {}"
,
oldValue
);
BeanUtil
.
copyProperties
(
vehicleDepartureLog
,
oldValue
,
CopyOptions
.
create
().
setIgnoreNullValue
(
true
).
setIgnoreError
(
true
));
oldValue
.
setUpdateTime
(
new
Date
());
...
...
@@ -116,7 +116,7 @@ public class VehicleDepartureService extends BaseBiz<VehicleDepartureLogMapper,
List
<
VehicleDepartureLog
>
vehicleDepartureLogs
=
mapper
.
selectByExample
(
exm
);
if
(
vehicleDepartureLogs
.
size
()
==
1
)
{
VehicleDepartureLog
vehicleDepartureLog
=
vehicleDepartureLogs
.
get
(
0
);
if
(
vehicleDepartureLog
!=
null
)
{
if
(
vehicleDepartureLog
!=
null
)
{
return
ObjectRestResponse
.
succ
(
vehicleDepartureLog
);
}
}
...
...
@@ -124,11 +124,11 @@ public class VehicleDepartureService extends BaseBiz<VehicleDepartureLogMapper,
}
@Transactional
public
ObjectRestResponse
collect
(
VehicleDepartureLog
vdl
){
vdl
.
setArrivalTime
(
new
Date
());
vdl
.
setState
(
1
);
updateSelectiveById
(
vdl
);
return
ObjectRestResponse
.
succ
();
public
ObjectRestResponse
collect
(
VehicleDepartureLog
vdl
)
{
vdl
.
setArrivalTime
(
new
Date
());
vdl
.
setState
(
1
);
updateSelectiveById
(
vdl
);
return
ObjectRestResponse
.
succ
();
}
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/mapper/VehicleBookInfoMapper.java
View file @
7f912342
...
...
@@ -45,4 +45,6 @@ public interface VehicleBookInfoMapper extends Mapper<VehicleBookInfo> {
public
Integer
del4YearMoth
(
Map
<
String
,
Object
>
params
);
void
insertBatch
(
@Param
(
"vbfs"
)
List
<
VehicleBookInfo
>
bookInfos
);
public
Integer
updateById
(
VehicleBookInfo
vehicleBookInfo
);
}
\ No newline at end of file
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/mapper/VehicleBookRecordMapper.java
View file @
7f912342
...
...
@@ -37,4 +37,7 @@ public interface VehicleBookRecordMapper extends Mapper<VehicleBookRecord> {
public
List
<
VehicleBookRecordVo
>
getBookRecordInfo
(
Map
<
String
,
Object
>
param
);
public
List
<
VehicleBookRecordVo
>
selectByVehicleIdAndTime
(
Map
<
String
,
Object
>
param
);
public
List
<
VehicleBookRecordVo
>
selectZeroHourRecord
(
Map
<
String
,
Object
>
param
);
}
\ No newline at end of file
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/mapper/VehicleDepartureLogMapper.java
View file @
7f912342
...
...
@@ -13,7 +13,7 @@ public interface VehicleDepartureLogMapper extends BaseMapper<VehicleDepartureLo
VehicleDepartureLog
selectLastByVehicleId
(
String
vehicleId
);
List
<
VehicleDepartureLogVo
>
selectByVehicleId
(
String
vehicleId
);
List
<
VehicleDepartureLog
>
selectByVehicle
(
String
vehicleId
);
List
<
VehicleDepartureLogVo
>
selectVoAll
(
@Param
(
"numberPlate"
)
String
numberPlate
,
@Param
(
"time"
)
String
time
);
List
<
VehicleDepartureLogVo
>
selectVoAllNotAllData
(
@Param
(
"numberPlate"
)
String
numberPlate
,
@Param
(
"time"
)
String
time
,
@Param
(
"companyList"
)
List
<
Integer
>
companyList
);
...
...
xx-vehicle/xx-vehicle-server/src/main/java/com/xxfc/platform/vehicle/mapper/VehicleMapper.java
View file @
7f912342
...
...
@@ -29,6 +29,8 @@ public interface VehicleMapper extends Mapper<Vehicle> {
int
updateStatusByIdAndStatus
(
@Param
(
"vehicleId"
)
String
vehicleId
,
@Param
(
"status"
)
Integer
status
,
@Param
(
"lastStatus"
)
Integer
lastStatus
);
int
updateStatus
(
@Param
(
"vehicleId"
)
String
vehicleId
,
@Param
(
"status"
)
Integer
status
);
Vehicle
selectByNumberPlate
(
String
numberPlate
);
List
<
UsableVehicleModelVO
>
searchUsableModel
(
Map
<
String
,
Object
>
params
);
...
...
xx-vehicle/xx-vehicle-server/src/main/resources/mapper/VehicleBookInfoMapper.xml
View file @
7f912342
...
...
@@ -26,7 +26,6 @@
</foreach>
</select>
<insert
id=
"insertIgnore"
parameterType=
"com.xxfc.platform.vehicle.entity.VehicleBookInfo"
>
insert ignore into vehicle_book_info ( vehicle, `year_month`, booked_date)
values(#{vehicle},#{yearMonth},#{bookedDate})
...
...
@@ -47,6 +46,12 @@
vehicle = #{vehicleId} and `year_month`=#{yearMonth} and
booked_date
&
#{andOperationFactor} = #{andOperationRs}
</update>
<update
id=
"updateById"
parameterType=
"com.xxfc.platform.vehicle.entity.VehicleBookInfo"
>
update vehicle_book_info set
booked_date = #{bookedDate}
where
vehicle = #{vehicle} and `year_month`=#{yearMonth}
</update>
<select
id=
"getByPage4YearMonth"
parameterType=
"java.util.Map"
resultType=
"com.xxfc.platform.vehicle.entity.VehicleBookInfo"
>
select id, vehicle, `year_month`, booked_date, create_time, update_time from vehicle_book_info where `year_month` = #{yearMonth} order by id limit #{pageStart},#{pageSize}
...
...
xx-vehicle/xx-vehicle-server/src/main/resources/mapper/VehicleBookRecordMapper.xml
View file @
7f912342
...
...
@@ -330,6 +330,13 @@
where v1.vehicle_id = #{vehicleId} and v1.book_end_date
<
= #{bookedEndDate} and v1.status BETWEEN 1 and 2
</select>
<select
id=
"selectZeroHourRecord"
resultMap=
"searchBookRecord"
parameterType=
"java.util.Map"
>
select v1.* from vehicle_book_record v1
where v1.vehicle_id = #{vehicleId}
and (v1.book_end_date = #{bookedEndDate} or v1.book_start_date = #{bookedEndDate})
and v1.status BETWEEN 1 and 2
</select>
<select
id=
"getById"
parameterType=
"java.util.Map"
resultType=
"com.xxfc.platform.vehicle.entity.VehicleBookRecord"
>
select
vbr.`id`,
...
...
@@ -373,7 +380,7 @@
</select>
<select
id=
"selectByVehicleId"
parameterType=
"java.lang.String"
result
Type=
"com.xxfc.platform.vehicle.pojo.VehicleBookRecordVo
"
>
result
Map=
"searchBookRecord
"
>
SELECT v1.*,bc2.name retCompanyName from vehicle_book_record v1
LEFT JOIN branch_company bc2 on v1.ret_company = bc2.id
where v1.vehicle_id = #{vehicleId} and v1.status BETWEEN 1 and 2
...
...
xx-vehicle/xx-vehicle-server/src/main/resources/mapper/VehicleDepartureLogMapper.xml
View file @
7f912342
...
...
@@ -17,6 +17,13 @@
order by create_time desc
</select>
<select
id=
"selectByVehicle"
parameterType=
"java.lang.String"
resultType=
"com.xxfc.platform.vehicle.entity.VehicleDepartureLog"
>
select vehicle_departure_log.*
from vehicle_departure_log
where vehicle_id = #{vehicleId}
order by create_time desc
</select>
<select
id=
"selectByBookRecordId"
parameterType=
"java.lang.Long"
resultType=
"com.xxfc.platform.vehicle.pojo.VehicleDepartureLogVo"
>
select vehicle_departure_log.*
from vehicle_departure_log
...
...
xx-vehicle/xx-vehicle-server/src/main/resources/mapper/VehicleMapper.xml
View file @
7f912342
...
...
@@ -359,6 +359,12 @@
where id = #{vehicleId} and status = #{lastStatus}
</update>
<update
id=
"updateStatus"
>
update vehicle
set status = #{status}
where id = #{vehicleId} and status != 3
</update>
<update
id=
"updateMileageStatusByIdAndStatus"
>
update vehicle
set status = #{status},maintenance_mileage=#{mileage}
...
...
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