Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
聂康
ivccs
Commits
07602a7b
Commit
07602a7b
authored
Apr 18, 2023
by
kang.nie@inzymeits.com
Browse files
提交代码
parent
e0c7be76
Changes
479
Hide whitespace changes
Inline
Side-by-side
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VehicleTroubleServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.ssi.entity.VmsVehicle
;
import
com.ssi.entity.VmsVehicleAlertHistory
;
import
com.ssi.entity.vo.TaskAnalysisVo
;
import
com.ssi.entity.vo.VmsVehicleAlertHistoryVo
;
import
com.ssi.entity.vo.VmsVehicleFaultAnalysisVo
;
import
com.ssi.entity.vo.VmsVehicleFaultAnalysisVo.AnalysisInfoVo
;
import
com.ssi.entity.vo.VmsVehicleFaultVo
;
import
com.ssi.mapper.VehicleTroubleHistoryMapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.service.VehicleTroubleService
;
import
com.ssi.service.VmsVehicleService
;
import
com.ssi.utils.DateUtils
;
import
com.ssi.utils.PoiUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletResponse
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.LocalTime
;
import
java.time.ZoneOffset
;
import
java.time.temporal.ChronoUnit
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* 故障历史服务实现类
*/
@Service
(
"vehicleTroubleService"
)
public
class
VehicleTroubleServiceImpl
extends
ServiceImpl
<
VehicleTroubleHistoryMapper
,
VmsVehicleAlertHistory
>
implements
VehicleTroubleService
{
@Autowired
private
VmsVehicleService
vmsVehicleService
;
@Autowired
private
VehicleTroubleHistoryMapper
vehicleTroubleHistoryMapper
;
private
static
String
[]
faultTypes
=
{
"V"
,
"I"
,
"P"
,
"OBU"
};
private
static
String
[]
faultLevels
=
{
"1"
,
"2"
,
"3"
,
"4"
};
/**
* 故障列表分页
*/
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
List
<
VmsVehicle
>
list
=
vmsVehicleService
.
list
();
Map
<
String
,
VmsVehicle
>
vinMap
=
list
.
stream
().
collect
(
Collectors
.
toMap
(
VmsVehicle:
:
getVin
,
Function
.
identity
()));
String
vehicleNum
=
(
String
)
params
.
get
(
"vehicleNum"
);
Integer
pageSize
=
params
.
get
(
"pageSize"
)
==
null
?
0
:
(
Integer
)
params
.
get
(
"pageSize"
);
Integer
pageIndex
=
params
.
get
(
"pageIndex"
)
==
null
?
10
:
(
Integer
)
params
.
get
(
"pageIndex"
);
Long
startTime
=
(
Long
)
params
.
get
(
"startTime"
);
Long
stopTime
=
(
Long
)
params
.
get
(
"stopTime"
);
Date
startDate
=
startTime
==
null
?
null
:
new
Date
(
startTime
);
Date
stopDate
=
stopTime
==
null
?
null
:
new
Date
(
stopTime
);
params
.
put
(
"startTime"
,
startDate
);
params
.
put
(
"stopTime"
,
stopDate
);
if
(
StringUtils
.
isNotBlank
(
vehicleNum
))
{
List
<
String
>
vins
=
list
.
parallelStream
().
filter
(
vehicle
->
vehicle
.
getVehicleNum
().
contains
(
vehicleNum
)).
map
(
VmsVehicle:
:
getVin
).
collect
(
Collectors
.
toList
());
if
(
vins
.
isEmpty
())
{
return
new
SSIPage
(
Lists
.
newArrayList
(),
0
,
pageSize
,
pageIndex
);
}
params
.
put
(
"vins"
,
vins
);
}
IPage
<
VmsVehicleAlertHistoryVo
>
page
=
new
Page
<>(
pageIndex
,
pageSize
);
page
=
this
.
getBaseMapper
().
getAlertHistoryList
(
page
,
params
);
// page.getRecords().parallelStream().forEach(vmsVehicleAlertHistory -> {
// VmsVehicle vehicle = vinMap.get(vmsVehicleAlertHistory.getVin());
// vmsVehicleAlertHistory.setVehicleNum(vehicle == null ? null : vehicle.getVehicleNum());
// });
return
new
SSIPage
(
page
);
}
@Override
public
void
export
(
Map
<
String
,
Object
>
params
,
HttpServletResponse
response
)
{
// TODO Auto-generated method stub
Integer
exportType
=
(
Integer
)
params
.
get
(
"exportType"
);
List
<
VmsVehicleAlertHistoryVo
>
list
;
ExcelDataHandlerDefaultImpl
<
Object
>
excelDataHandler
=
new
ExcelDataHandlerDefaultImpl
<
Object
>()
{
@Override
public
String
[]
getNeedHandlerFields
()
{
return
new
String
[]{
"报警时间"
,
"解除时间"
};
}
// @Override
public
Object
exportHandler
(
Object
obj
,
String
name
,
Object
value
)
{
if
(
"报警时间"
.
equals
(
name
))
{
VmsVehicleAlertHistoryVo
vo
=(
VmsVehicleAlertHistoryVo
)
obj
;
return
DateUtils
.
format
(
vo
.
getAlarmTime
(),
2
);
}
if
(
"解除时间"
.
equals
(
name
))
{
VmsVehicleAlertHistoryVo
vo
=(
VmsVehicleAlertHistoryVo
)
obj
;
return
DateUtils
.
format
(
vo
.
getRelieveAlarmTime
(),
2
);
}
return
super
.
exportHandler
(
obj
,
name
,
value
);
}
};
if
(
exportType
==
0
)
{
SSIPage
ssiPage
=
queryPage
(
params
);
list
=
(
List
<
VmsVehicleAlertHistoryVo
>)
ssiPage
.
getList
();
PoiUtils
.
exportExcel
(
excelDataHandler
,
list
,
"车辆异常报警"
,
"VmsVehicle"
,
VmsVehicleAlertHistoryVo
.
class
,
"车辆异常报警"
+
".xls"
,
true
,
response
);
}
else
{
params
.
put
(
"pageIndex"
,
1
);
params
.
put
(
"pageSize"
,
1000000
);
SSIPage
ssiPage
=
queryPage
(
params
);
list
=
(
List
<
VmsVehicleAlertHistoryVo
>)
ssiPage
.
getList
();
PoiUtils
.
exportExcel
(
excelDataHandler
,
list
,
"车辆异常报警"
,
"VmsVehicle"
,
VmsVehicleAlertHistoryVo
.
class
,
"车辆异常报警"
+
".xls"
,
true
,
response
);
}
}
@Override
public
SSIResponse
getFaultTrend
(
Map
<
String
,
Object
>
params
)
throws
Exception
{
Integer
timeType
=
(
Integer
)
params
.
get
(
"timeType"
);
switch
(
timeType
)
{
//日
case
1
:
LocalDateTime
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
LocalDateTime
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
Long
startTimeStamp
=
startTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
List
<
VmsVehicleFaultVo
>
taskTrendByHour
=
vehicleTroubleHistoryMapper
.
getFaultTrendByHour
(
startTime
,
endTime
,
startTimeStamp
,
params
);
return
SSIResponse
.
ok
(
TaskAnalysisVo
.
fillBlankHour
(
taskTrendByHour
,
VmsVehicleFaultVo
.
class
));
//周
case
2
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
7
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
List
<
VmsVehicleFaultVo
>
taskTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
TaskAnalysisVo
.
fillBlankDay
(
taskTrendByDay
,
VmsVehicleFaultVo
.
class
,
startTime
,
endTime
));
//月
case
3
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
30
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
taskTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
TaskAnalysisVo
.
fillBlankDay
(
taskTrendByDay
,
VmsVehicleFaultVo
.
class
,
startTime
,
endTime
));
}
return
null
;
}
@Override
public
SSIResponse
getFaultDistribution
(
Map
<
String
,
Object
>
params
)
throws
Exception
{
Integer
timeType
=
(
Integer
)
params
.
get
(
"timeType"
);
LocalDate
startTime
=
null
;
LocalDateTime
endTime
=
null
;
switch
(
timeType
)
{
//日
case
1
:
startTime
=
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
();
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
break
;
//周
case
2
:
startTime
=
LocalDateTime
.
now
().
minus
(
7
,
ChronoUnit
.
DAYS
).
toLocalDate
();
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
break
;
//月
case
3
:
startTime
=
LocalDateTime
.
now
().
minus
(
30
,
ChronoUnit
.
DAYS
).
toLocalDate
();
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
break
;
default
:
return
null
;
}
List
<
VmsVehicleFaultVo
>
distribution
=
vehicleTroubleHistoryMapper
.
getFaultDistribution
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
distribution
);
}
@Override
public
SSIResponse
getFaultTypeTrend
(
Map
<
String
,
Object
>
params
)
throws
Exception
{
Integer
timeType
=
(
Integer
)
params
.
get
(
"timeType"
);
switch
(
timeType
)
{
//日
case
1
:
LocalDateTime
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
LocalDateTime
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
Long
startTimeStamp
=
startTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
List
<
VmsVehicleFaultVo
>
faultTrendByHour
=
vehicleTroubleHistoryMapper
.
getFaultTypeTrendByHour
(
startTime
,
endTime
,
startTimeStamp
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultTypeList
(
faultTrendByHour
));
//周
case
2
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
7
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
List
<
VmsVehicleFaultVo
>
faultTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultTypeTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultTypeList
(
faultTrendByDay
,
startTime
,
endTime
));
//月
case
3
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
30
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
faultTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultTypeTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultTypeList
(
faultTrendByDay
,
startTime
,
endTime
));
}
return
null
;
}
public
static
List
<
VmsVehicleFaultAnalysisVo
>
fillFaultTypeList
(
List
<
VmsVehicleFaultVo
>
list
)
throws
Exception
{
List
<
VmsVehicleFaultAnalysisVo
>
resList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
24
;
i
++)
{
VmsVehicleFaultAnalysisVo
faultAnalysisVo
=
new
VmsVehicleFaultAnalysisVo
();
faultAnalysisVo
.
setHour
(
i
);
Map
<
String
,
Integer
>
hourMap
=
new
HashMap
<>();
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
VmsVehicleFaultVo
vo1
=
list
.
get
(
j
);
if
(
vo1
.
getHour
()
==
i
)
{
hourMap
.
put
(
vo1
.
getFaultType
(),
vo1
.
getFaultNum
());
}
if
(
vo1
.
getHour
()
>
i
){
break
;
}
}
List
<
AnalysisInfoVo
>
faultList
=
new
ArrayList
<>();
for
(
String
faultType
:
faultTypes
){
AnalysisInfoVo
analysisInfoVo
=
new
AnalysisInfoVo
();
analysisInfoVo
.
setFaultType
(
faultType
);
if
(
hourMap
.
get
(
faultType
)
!=
null
)
{
analysisInfoVo
.
setFaultNum
(
hourMap
.
get
(
faultType
));
}
faultList
.
add
(
analysisInfoVo
);
}
faultAnalysisVo
.
setList
(
faultList
);
resList
.
add
(
faultAnalysisVo
);
}
return
resList
;
}
public
static
List
<
VmsVehicleFaultAnalysisVo
>
fillFaultTypeList
(
List
<
VmsVehicleFaultVo
>
list
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
throws
Exception
{
List
<
VmsVehicleFaultAnalysisVo
>
resList
=
new
ArrayList
<>();
LocalDate
date
=
startTime
.
toLocalDate
();
do
{
VmsVehicleFaultAnalysisVo
faultAnalysisVo
=
new
VmsVehicleFaultAnalysisVo
();
faultAnalysisVo
.
setDate
(
date
);
Map
<
String
,
Integer
>
dayMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
VmsVehicleFaultVo
vo1
=
list
.
get
(
i
);
if
(
date
.
compareTo
(
vo1
.
getDate
())
==
0
)
{
dayMap
.
put
(
vo1
.
getFaultType
(),
vo1
.
getFaultNum
());
}
if
(
date
.
compareTo
(
vo1
.
getDate
())
<
0
)
{
break
;
}
}
List
<
AnalysisInfoVo
>
faultList
=
new
ArrayList
<>();
for
(
String
faultType
:
faultTypes
)
{
AnalysisInfoVo
analysisInfoVo
=
new
AnalysisInfoVo
();
analysisInfoVo
.
setFaultType
(
faultType
);
if
(
dayMap
.
get
(
faultType
)
!=
null
)
{
analysisInfoVo
.
setFaultNum
(
dayMap
.
get
(
faultType
));
}
faultList
.
add
(
analysisInfoVo
);
}
faultAnalysisVo
.
setList
(
faultList
);
resList
.
add
(
faultAnalysisVo
);
date
=
date
.
plusDays
(
1
);
}
while
(
date
.
compareTo
(
endTime
.
toLocalDate
())
<=
0
);
return
resList
;
}
@Override
public
SSIResponse
getFaultLevelTrend
(
Map
<
String
,
Object
>
params
)
throws
Exception
{
Integer
timeType
=
(
Integer
)
params
.
get
(
"timeType"
);
switch
(
timeType
)
{
//日
case
1
:
LocalDateTime
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
LocalDateTime
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
Long
startTimeStamp
=
startTime
.
toInstant
(
ZoneOffset
.
of
(
"+8"
)).
toEpochMilli
();
List
<
VmsVehicleFaultVo
>
faultTrendByHour
=
vehicleTroubleHistoryMapper
.
getFaultLevelTrendByHour
(
startTime
,
endTime
,
startTimeStamp
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultLevelList
(
faultTrendByHour
));
//周
case
2
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
7
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
List
<
VmsVehicleFaultVo
>
faultTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultLevelTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultLevelList
(
faultTrendByDay
,
startTime
,
endTime
));
//月
case
3
:
startTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
30
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MIN
);
endTime
=
LocalDateTime
.
of
(
LocalDateTime
.
now
().
minus
(
1
,
ChronoUnit
.
DAYS
).
toLocalDate
(),
LocalTime
.
MAX
);
faultTrendByDay
=
vehicleTroubleHistoryMapper
.
getFaultLevelTrendByDay
(
startTime
,
endTime
,
params
);
return
SSIResponse
.
ok
(
this
.
fillFaultLevelList
(
faultTrendByDay
,
startTime
,
endTime
));
}
return
null
;
}
public
static
List
<
VmsVehicleFaultAnalysisVo
>
fillFaultLevelList
(
List
<
VmsVehicleFaultVo
>
list
)
throws
Exception
{
List
<
VmsVehicleFaultAnalysisVo
>
resList
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
24
;
i
++)
{
VmsVehicleFaultAnalysisVo
faultAnalysisVo
=
new
VmsVehicleFaultAnalysisVo
();
faultAnalysisVo
.
setHour
(
i
);
Map
<
String
,
Integer
>
hourMap
=
new
HashMap
<>();
for
(
int
j
=
0
;
j
<
list
.
size
();
j
++)
{
VmsVehicleFaultVo
vo1
=
list
.
get
(
j
);
if
(
vo1
.
getHour
()
==
i
)
{
hourMap
.
put
(
vo1
.
getFaultGrade
(),
vo1
.
getFaultNum
());
}
if
(
vo1
.
getHour
()
>
i
){
break
;
}
}
List
<
AnalysisInfoVo
>
faultList
=
new
ArrayList
<>();
for
(
String
faultLevel
:
faultLevels
){
AnalysisInfoVo
analysisInfoVo
=
new
AnalysisInfoVo
();
analysisInfoVo
.
setFaultGrade
(
faultLevel
);
if
(
hourMap
.
get
(
faultLevel
)
!=
null
)
{
analysisInfoVo
.
setFaultNum
(
hourMap
.
get
(
faultLevel
));
}
faultList
.
add
(
analysisInfoVo
);
}
faultAnalysisVo
.
setList
(
faultList
);
resList
.
add
(
faultAnalysisVo
);
}
return
resList
;
}
public
static
List
<
VmsVehicleFaultAnalysisVo
>
fillFaultLevelList
(
List
<
VmsVehicleFaultVo
>
list
,
LocalDateTime
startTime
,
LocalDateTime
endTime
)
throws
Exception
{
List
<
VmsVehicleFaultAnalysisVo
>
resList
=
new
ArrayList
<>();
LocalDate
date
=
startTime
.
toLocalDate
();
do
{
VmsVehicleFaultAnalysisVo
faultAnalysisVo
=
new
VmsVehicleFaultAnalysisVo
();
faultAnalysisVo
.
setDate
(
date
);
Map
<
String
,
Integer
>
dayMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
VmsVehicleFaultVo
vo1
=
list
.
get
(
i
);
if
(
date
.
compareTo
(
vo1
.
getDate
())
==
0
)
{
dayMap
.
put
(
vo1
.
getFaultGrade
(),
vo1
.
getFaultNum
());
}
if
(
date
.
compareTo
(
vo1
.
getDate
())
<
0
)
{
break
;
}
}
List
<
AnalysisInfoVo
>
faultList
=
new
ArrayList
<>();
for
(
String
faultLevel
:
faultLevels
)
{
AnalysisInfoVo
analysisInfoVo
=
new
AnalysisInfoVo
();
analysisInfoVo
.
setFaultGrade
(
faultLevel
);
if
(
dayMap
.
get
(
faultLevel
)
!=
null
)
{
analysisInfoVo
.
setFaultNum
(
dayMap
.
get
(
faultLevel
));
}
faultList
.
add
(
analysisInfoVo
);
}
faultAnalysisVo
.
setList
(
faultList
);
resList
.
add
(
faultAnalysisVo
);
date
=
date
.
plusDays
(
1
);
}
while
(
date
.
compareTo
(
endTime
.
toLocalDate
())
<=
0
);
return
resList
;
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsAlertThresholdNewServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsAlertThreshold
;
import
com.ssi.entity.VmsAlertThresholdNew
;
import
com.ssi.mapper.VmsAlertThresholdMapper
;
import
com.ssi.mapper.VmsAlertThresholdNewMapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.service.VmsAlertThresholdNewService
;
import
com.ssi.service.VmsAlertThresholdService
;
import
com.ssi.utils.QueryUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
/**
* 报警阀值服务实现类
*/
@Service
(
"alertThresholdNewService"
)
public
class
VmsAlertThresholdNewServiceImpl
extends
ServiceImpl
<
VmsAlertThresholdNewMapper
,
VmsAlertThresholdNew
>
implements
VmsAlertThresholdNewService
{
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
VmsAlertThresholdNew
vmsAlertThresholdNew
=
new
VmsAlertThresholdNew
();
vmsAlertThresholdNew
.
setIsDel
(
1
);
IPage
<
VmsAlertThresholdNew
>
page
=
this
.
page
(
new
QueryUtils
<
VmsAlertThresholdNew
>().
getPage
(
params
),
new
QueryWrapper
<
VmsAlertThresholdNew
>(
vmsAlertThresholdNew
)
);
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsAlertThresholdServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.ssi.entity.VmsAlertThresholdNew
;
import
com.ssi.mapper.VmsAlertThresholdMapper
;
import
com.ssi.response.SSIPage
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.utils.QueryUtils
;
import
com.ssi.entity.VmsAlertThreshold
;
import
com.ssi.service.VmsAlertThresholdService
;
/**
* 报警阀值服务实现类
*/
@Service
(
"alertThresholdService"
)
public
class
VmsAlertThresholdServiceImpl
extends
ServiceImpl
<
VmsAlertThresholdMapper
,
VmsAlertThreshold
>
implements
VmsAlertThresholdService
{
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
VmsAlertThreshold
vmsAlertThresholdNew
=
new
VmsAlertThreshold
();
vmsAlertThresholdNew
.
setIsDel
(
1
);
IPage
<
VmsAlertThreshold
>
page
=
this
.
page
(
new
QueryUtils
<
VmsAlertThreshold
>().
getPage
(
params
),
new
QueryWrapper
<
VmsAlertThreshold
>(
vmsAlertThresholdNew
)
);
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsAreaBarrierServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.constant.URL
;
import
com.ssi.entity.VmsAreaBarrier
;
import
com.ssi.entity.map.MapDataDto
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.service.VmsAreaBarrierService
;
import
com.ssi.mapper.VmsAreaBarrierMapper
;
import
com.ssi.utils.RestTemplateUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
/**
*
*/
@Slf4j
@Service
public
class
VmsAreaBarrierServiceImpl
extends
ServiceImpl
<
VmsAreaBarrierMapper
,
VmsAreaBarrier
>
implements
VmsAreaBarrierService
{
@Value
(
"${map-edit-url}"
)
private
String
mapEditUrl
;
@Override
public
SSIResponse
saveMapData
(
MapDataDto
mapdata
)
{
// List<VmsAreaBarrier> list = this.lambdaQuery().eq(VmsAreaBarrier::getName, mapdata.getNumber()).list();
// if(CollectionUtils.isNotEmpty(list)){
// return SSIResponse.no("已存在同名数据");
// }
// VmsAreaBarrier saveEntity = getVmsAreaBarrier(mapdata);
log
.
info
(
String
.
format
(
"绘制电子围栏区域保存请求发送:----%s"
,
mapdata
));
String
result
=
RestTemplateUtil
.
post
(
String
.
format
(
"%s%s"
,
mapEditUrl
,
URL
.
FENCE_ADD_URL
),
JSON
.
toJSONString
(
mapdata
)
,
null
);
log
.
info
(
String
.
format
(
"绘制电子围栏区域保存返回结果:----%s"
,
result
));
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
// this.saveOrUpdate(saveEntity);
return
SSIResponse
.
ok
(
jsonObject
);
}
private
VmsAreaBarrier
getVmsAreaBarrier
(
MapDataDto
mapdata
)
{
VmsAreaBarrier
saveEntity
=
new
VmsAreaBarrier
();
if
(
StringUtils
.
isNotBlank
(
mapdata
.
getId
())){
saveEntity
.
setId
(
Integer
.
valueOf
(
mapdata
.
getId
()));
}
saveEntity
.
setEndPoint
(
mapdata
.
getField
());
saveEntity
.
setName
(
mapdata
.
getNumber
());
saveEntity
.
setAreaType
(
Integer
.
valueOf
(
mapdata
.
getPlacetype
()));
saveEntity
.
setType
(
Integer
.
valueOf
(
mapdata
.
getType
()));
saveEntity
.
setDr
(
Integer
.
valueOf
(
mapdata
.
getState
()));
String
[]
points
=
mapdata
.
getPoints
().
split
(
";"
);
List
<
Map
>
maps
=
new
ArrayList
<>();
for
(
String
point
:
points
)
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
String
[]
loglat
=
point
.
split
(
","
);
map
.
put
(
"lng"
,
loglat
[
0
]);
map
.
put
(
"lat"
,
loglat
[
1
]);
maps
.
add
(
map
);
}
saveEntity
.
setLocations
(
JSON
.
toJSONString
(
maps
));
return
saveEntity
;
}
@Override
public
SSIResponse
deleteMapData
(
MapDataDto
mapdata
)
{
// this.removeById(mapdata.getId());
log
.
info
(
String
.
format
(
"删除电子围栏区域保存请求发送:----%s"
,
mapdata
));
String
result
=
RestTemplateUtil
.
get
(
String
.
format
(
"%s%s?id=%s"
,
mapEditUrl
,
URL
.
FENCE_DELETE_URL
,
mapdata
.
getId
()),
null
);
log
.
info
(
String
.
format
(
"删除电子围栏区域保存返回结果:----%s"
,
result
));
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
return
SSIResponse
.
ok
(
jsonObject
);
}
@Override
public
SSIResponse
addBarrierMap
(
MapDataDto
mapdata
,
JSONObject
jsonObject
)
{
if
(
StringUtils
.
isNotBlank
(
mapdata
.
getType
())&&!
"11"
.
equalsIgnoreCase
(
mapdata
.
getType
())){
return
SSIResponse
.
ok
();
}
try
{
VmsAreaBarrier
qryEntity
=
new
VmsAreaBarrier
();
if
(
StringUtils
.
isNotBlank
(
mapdata
.
getNumber
()))
{
qryEntity
.
setName
(
mapdata
.
getNumber
());
// 名称
}
if
(
StringUtils
.
isNotBlank
((
mapdata
.
getPlacetype
())))
{
qryEntity
.
setAreaType
(
Integer
.
valueOf
(
mapdata
.
getPlacetype
()));
// 状态。0可用;1不可用(初始状态);2已计划;3有车
}
log
.
info
(
String
.
format
(
"电子围栏区域查询请求发送:----%s"
,
mapdata
));
String
result
=
RestTemplateUtil
.
post
(
String
.
format
(
"%s%s"
,
mapEditUrl
,
URL
.
FENCE_QUERY_URL
),
JSON
.
toJSONString
(
mapdata
),
null
);
// log.info(String.format("子围栏区域查询返回结果:----%s", result));
// List<VmsAreaBarrier> vmsAreaBarriers = this.baseMapper.selectList(new QueryWrapper<>(qryEntity));
JSONArray
dataList
=
jsonObject
.
getJSONArray
(
"data"
);
JSONObject
jsonResult
=
JSONArray
.
parseObject
(
result
,
JSONObject
.
class
);
JSONArray
data
=
jsonResult
.
getJSONArray
(
"data"
);
if
(
Objects
.
isNull
(
data
)){
return
SSIResponse
.
ok
();
}
for
(
int
i
=
0
;
i
<
data
.
size
();
i
++){
JSONObject
tmpJsonObj
=
data
.
getJSONObject
(
i
);
JSONObject
tmpObj
=
new
JSONObject
();
dataList
.
add
(
tmpObj
);
tmpObj
.
put
(
"id"
,
tmpJsonObj
.
getIntValue
(
"id"
));
tmpObj
.
put
(
"name"
,
tmpJsonObj
.
getString
(
"name"
));
tmpObj
.
put
(
"state"
,
1
);
tmpObj
.
put
(
"type"
,
11
);
tmpObj
.
put
(
"placeType"
,
tmpJsonObj
.
getString
(
"fenceType"
));
String
points
=
tmpJsonObj
.
getString
(
"points"
);
if
(
StringUtils
.
isNotBlank
(
points
))
{
String
[]
locations
=
points
.
split
(
";"
);
tmpObj
.
put
(
"locateNum"
,
locations
.
length
);
for
(
int
j
=
0
;
j
<
locations
.
length
;
j
++)
{
String
[]
tmpLocation
=
locations
[
j
].
split
(
","
);
tmpObj
.
put
(
"lng"
+
(
j
+
1
),
tmpLocation
[
0
]);
tmpObj
.
put
(
"lat"
+
(
j
+
1
),
tmpLocation
[
1
]);
}
}
}
return
SSIResponse
.
ok
();
}
catch
(
Exception
e
){
log
.
error
(
"addBarrierMap occur error :"
,
e
);
return
SSIResponse
.
ok
();
}
}
@Override
public
SSIResponse
updateMapData
(
MapDataDto
mapdata
)
{
log
.
info
(
String
.
format
(
"更新电子围栏区域保存请求发送:----%s"
,
mapdata
));
String
result
=
RestTemplateUtil
.
post
(
String
.
format
(
"%s%s"
,
mapEditUrl
,
URL
.
FENCE_UPDATE_URL
),
JSON
.
toJSONString
(
mapdata
)
,
null
);
log
.
info
(
String
.
format
(
"更新电子围栏区域保存返回结果:----%s"
,
result
));
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
// this.saveOrUpdate(saveEntity);
return
SSIResponse
.
ok
(
jsonObject
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsAreaBusinessInfoServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsAreaBusinessInfo
;
import
com.ssi.entity.map.MapDataDto
;
import
com.ssi.service.VmsAreaBusinessInfoService
;
import
com.ssi.mapper.VmsAreaBusinessInfoMapper
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
*
*/
@Service
public
class
VmsAreaBusinessInfoServiceImpl
extends
ServiceImpl
<
VmsAreaBusinessInfoMapper
,
VmsAreaBusinessInfo
>
implements
VmsAreaBusinessInfoService
{
@Override
public
List
<
String
>
getByCrane
(
String
portCode
,
Integer
taskType
,
List
<
Integer
>
taskTypes
)
{
return
this
.
baseMapper
.
getByCrane
(
portCode
,
taskType
,
taskTypes
);
}
@Override
@Transactional
public
void
updatePassArea
(
@RequestBody
MapDataDto
mapdata
)
{
VmsAreaBusinessInfo
deleteEntity
=
new
VmsAreaBusinessInfo
();
deleteEntity
.
setAreaId
(
mapdata
.
getId
());
deleteEntity
.
setTaskType
(
mapdata
.
getTaskType
());
this
.
baseMapper
.
delete
(
new
QueryWrapper
<>(
deleteEntity
));
if
(
StringUtils
.
isBlank
(
mapdata
.
getBridge
())){
return
;
}
String
[]
split
=
mapdata
.
getBridge
().
split
(
","
);
for
(
int
i
=
0
;
i
<
split
.
length
;
i
++)
{
this
.
baseMapper
.
deleteByCrane
(
split
[
i
],
mapdata
.
getTaskType
());
VmsAreaBusinessInfo
saveEntity
=
new
VmsAreaBusinessInfo
();
saveEntity
.
setAreaId
(
mapdata
.
getId
());
saveEntity
.
setPlacetype
(
mapdata
.
getPlacetype
());
saveEntity
.
setAreaNo
(
mapdata
.
getNumber
());
saveEntity
.
setAreaType
(
mapdata
.
getType
());
saveEntity
.
setTaskType
(
mapdata
.
getTaskType
());
saveEntity
.
setBridge
(
split
[
i
]);
this
.
save
(
saveEntity
);
}
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsAreaPositionServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsAreaPosition
;
import
com.ssi.mapper.VmsAreaPositionMapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.service.VmsAreaPositionService
;
import
com.ssi.utils.QueryUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
/**
* 区域服务实现类
*/
@Service
(
"dragonLockAreaService"
)
public
class
VmsAreaPositionServiceImpl
extends
ServiceImpl
<
VmsAreaPositionMapper
,
VmsAreaPosition
>
implements
VmsAreaPositionService
{
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
VmsAreaPosition
>
page
=
this
.
page
(
new
QueryUtils
<
VmsAreaPosition
>().
getPage
(
params
),
new
QueryWrapper
<
VmsAreaPosition
>()
);
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsCarControlCommandServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
cn.afterturn.easypoi.excel.entity.ExportParams
;
import
cn.afterturn.easypoi.excel.export.ExcelBatchExportService
;
import
cn.afterturn.easypoi.handler.impl.ExcelDataHandlerDefaultImpl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.constant.enums.CommandResultEnum
;
import
com.ssi.constant.enums.CommandTypeEnum
;
import
com.ssi.entity.VmsCarControlCommand
;
import
com.ssi.entity.VmsVehicle
;
import
com.ssi.entity.dto.CarControlCommandParam
;
import
com.ssi.entity.vo.CarControlCommandVo
;
import
com.ssi.mapper.VmsCarControlCommandMapper
;
import
com.ssi.mapper.VmsVehicleMapper
;
import
com.ssi.model.RedisDataModel
;
import
com.ssi.response.AccessResponse
;
import
com.ssi.response.SSIPage
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.service.VmsCarControlCommandService
;
import
com.ssi.utils.AuthorizationUtils
;
import
com.ssi.utils.PoiUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
org.springframework.util.Assert
;
import
org.springframework.web.client.RestTemplate
;
import
javax.servlet.http.HttpServletResponse
;
import
java.util.*
;
/**
* 车辆远程控制服务实现类
*/
@Service
(
"vmsCarControlCommandService"
)
@Slf4j
public
class
VmsCarControlCommandServiceImpl
extends
ServiceImpl
<
VmsCarControlCommandMapper
,
VmsCarControlCommand
>
implements
VmsCarControlCommandService
{
@Autowired
private
RestTemplate
restTemplate
;
@Autowired
private
VmsVehicleMapper
vmsVehicleMapper
;
@Autowired
private
RedisDataModel
redisDataModel
;
@Value
(
"${command-url}"
)
private
String
commandUrl
;
/**
* 远程控制指令分页数据
* @param vo
* @return
*/
@Override
public
SSIPage
queryPage
(
CarControlCommandVo
vo
)
{
IPage
<
VmsCarControlCommand
>
page
=
new
Page
<>(
vo
.
getPageIndex
(),
vo
.
getPageSize
());
LambdaQueryWrapper
<
VmsCarControlCommand
>
wrapper
=
new
QueryWrapper
<
VmsCarControlCommand
>().
lambda
();
wrapper
.
eq
(
vo
.
getCommand
()
!=
null
,
VmsCarControlCommand:
:
getCommand
,
vo
.
getCommand
())
.
like
(
vo
.
getVehicleNum
()
!=
null
,
VmsCarControlCommand:
:
getVehicleNum
,
vo
.
getVehicleNum
())
.
ge
(
vo
.
getQueryStartTime
()
!=
null
,
VmsCarControlCommand:
:
getCreateTime
,
vo
.
getQueryStartTime
())
.
le
(
vo
.
getQueryEndTime
()
!=
null
,
VmsCarControlCommand:
:
getCreateTime
,
vo
.
getQueryEndTime
())
.
orderByDesc
(
VmsCarControlCommand:
:
getCreateTime
);
return
new
SSIPage
(
this
.
page
(
page
,
wrapper
));
}
/**
* 导出远程控制指令到Excel
* @param carControlCommandVo
* @param response
*/
@Override
public
void
export
(
CarControlCommandVo
carControlCommandVo
,
HttpServletResponse
response
)
{
int
exportType
=
carControlCommandVo
.
getExportType
();
if
(
exportType
==
0
)
{
SSIPage
page
=
queryPage
(
carControlCommandVo
);
List
<
VmsCarControlCommand
>
list
=
(
List
<
VmsCarControlCommand
>)
page
.
getList
();
ExcelDataHandlerDefaultImpl
<
Object
>
excelDataHandler
=
new
ExcelDataHandlerDefaultImpl
<
Object
>()
{
@Override
public
Object
exportHandler
(
Object
obj
,
String
name
,
Object
value
)
{
return
super
.
exportHandler
(
obj
,
name
,
value
);
}
};
PoiUtils
.
exportExcel
(
excelDataHandler
,
list
,
"远程指令清单"
,
"VmsCarControlCommand"
,
VmsCarControlCommand
.
class
,
"远程指令清单"
+
".xls"
,
true
,
response
);
}
else
{
ExcelBatchExportService
batchExportService
=
new
ExcelBatchExportService
();
ExportParams
exportParams
=
new
ExportParams
(
"远程指令清单"
,
"远程指令清单"
);
exportParams
.
setMaxNum
(
1000000
);
batchExportService
.
init
(
exportParams
,
VmsCarControlCommand
.
class
);
this
.
getBaseMapper
().
getListAsStream
(
carControlCommandVo
,
resultContext
->
{
VmsCarControlCommand
command
=
resultContext
.
getResultObject
();
batchExportService
.
appendData
(
Arrays
.
asList
(
command
));
});
Workbook
workbook
=
batchExportService
.
closeExportBigExcel
();
PoiUtils
.
downLoadExcel
(
"远程指令清单.xlsx"
,
response
,
workbook
);
}
}
/**
* 执行控车指令
* @param param 控车指令参数
*/
@Override
public
SSIResponse
executeCommand
(
CarControlCommandParam
param
)
{
VmsCarControlCommand
command
=
new
VmsCarControlCommand
();
Date
date
=
new
Date
();
String
vin
=
param
.
getVin
();
VmsVehicle
vehicle
=
vmsVehicleMapper
.
selectOne
(
new
LambdaQueryWrapper
<
VmsVehicle
>()
.
eq
(
VmsVehicle:
:
getVin
,
vin
));
if
(
vehicle
==
null
)
{
return
SSIResponse
.
no
(
"车辆不存在"
);
}
CommandTypeEnum
commandTypeEnum
=
CommandTypeEnum
.
find
(
param
.
getCommandType
());
if
(
commandTypeEnum
==
null
)
{
return
SSIResponse
.
no
(
"不支持的指令类型"
);
}
command
.
setVin
(
vin
);
command
.
setVehicleNum
(
vehicle
.
getVehicleNum
());
command
.
setCommand
(
param
.
getCommandType
());
command
.
setCreateTime
(
date
);
JSONObject
curUser
=
AuthorizationUtils
.
getCurUser
();
Integer
userId
=
(
Integer
)
curUser
.
get
(
"userId"
);
String
username
=
(
String
)
curUser
.
get
(
"username"
);
command
.
setOperatorId
(
userId
);
command
.
setOperatorName
(
username
);
String
url
=
commandUrl
+
"/command/sendF004"
;
param
.
setCollectTime
(
date
.
getTime
());
AccessResponse
accessResponse
=
restTemplate
.
postForObject
(
url
,
param
,
AccessResponse
.
class
);
if
(
accessResponse
.
isSuccess
())
{
Map
data
=
(
Map
)
accessResponse
.
getData
();
Integer
commandResult
=
(
Integer
)
data
.
get
(
"commandResult"
);
String
description
=
CommandResultEnum
.
find
(
commandResult
).
getDescription
();
command
.
setExecuteStatus
(
commandResult
);
command
.
setExecuteMessage
(
description
);
this
.
save
(
command
);
if
(
CommandResultEnum
.
isExecuteSuccess
(
commandResult
))
{
return
SSIResponse
.
ok
();
}
else
{
return
SSIResponse
.
no
(
description
);
}
}
else
{
String
msg
=
accessResponse
.
getStatus
().
getDetails
();
command
.
setExecuteStatus
(
CommandResultEnum
.
FAIL
.
getCode
());
command
.
setExecuteMessage
(
msg
);
this
.
save
(
command
);
return
SSIResponse
.
no
(
msg
);
}
}
/**
* 步进
* @param vin 车辆vin
* @param direction 方向 1-前进 ;2-后退
* @param distance 行驶距离(单位:CM)
* @return
*/
@Override
public
SSIResponse
stepping
(
String
vin
,
Integer
direction
,
Integer
distance
)
{
Assert
.
notNull
(
vin
,
"车辆vin不能为空"
);
Assert
.
notNull
(
direction
,
"方向参数direction不能为空"
);
Assert
.
notNull
(
distance
,
"行驶距离参数distance不能为空"
);
log
.
info
(
String
.
format
(
"调用步进接口,vin:%s,direction:%s,distance:%s"
,
vin
,
direction
,
distance
));
String
url
=
commandUrl
+
"/remote/app/stepping"
;
Map
param
=
new
HashMap
();
param
.
put
(
"vin"
,
vin
);
param
.
put
(
"direction"
,
direction
);
param
.
put
(
"distance"
,
distance
);
AccessResponse
accessResponse
=
restTemplate
.
postForObject
(
url
,
param
,
AccessResponse
.
class
);
if
(
accessResponse
.
isSuccess
())
{
log
.
info
(
String
.
format
(
"调用步进接口成功,vin:%s,direction:%s,distance:%s"
,
vin
,
direction
,
distance
));
return
SSIResponse
.
ok
();
}
else
{
String
msg
=
accessResponse
.
getStatus
().
getDetails
();
log
.
info
(
String
.
format
(
"调用步进接口失败,vin:%s,direction:%s,distance:%s"
,
vin
,
direction
,
distance
));
return
SSIResponse
.
no
(
msg
);
}
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsCarryCapacityAnalysisServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsCarryCapacityAnalysis
;
import
com.ssi.mapper.VmsCarryCapacityAnalysisMapper
;
import
com.ssi.service.VmsCarryCapacityAnalysisService
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
@Service
(
"vmsCarryCapacityAnalysisService"
)
public
class
VmsCarryCapacityAnalysisServiceImpl
extends
ServiceImpl
<
VmsCarryCapacityAnalysisMapper
,
VmsCarryCapacityAnalysis
>
implements
VmsCarryCapacityAnalysisService
{
@Override
public
IPage
<
VmsCarryCapacityAnalysis
>
queryPage
(
int
current
,
int
size
,
VmsCarryCapacityAnalysis
vmsCarryCapacityAnalysis
)
{
IPage
<
VmsCarryCapacityAnalysis
>
page
=
new
Page
<>(
current
,
size
);
QueryWrapper
<
VmsCarryCapacityAnalysis
>
wrapper
=
new
QueryWrapper
<>();
return
this
.
page
(
page
,
wrapper
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsCarryCapacityLatestServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.ssi.entity.VmsCarryCapacityLatest
;
import
com.ssi.mapper.VmsCarryCapacityLatestMapper
;
import
com.ssi.service.VmsCarryCapacityLatestService
;
import
org.springframework.stereotype.Service
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
@Service
(
"vmsCarryCapacityLatestService"
)
public
class
VmsCarryCapacityLatestServiceImpl
extends
ServiceImpl
<
VmsCarryCapacityLatestMapper
,
VmsCarryCapacityLatest
>
implements
VmsCarryCapacityLatestService
{
@Override
public
IPage
<
VmsCarryCapacityLatest
>
queryPage
(
int
current
,
int
size
,
VmsCarryCapacityLatest
vmsCarryCapacityLatest
)
{
IPage
<
VmsCarryCapacityLatest
>
page
=
new
Page
<>(
current
,
size
);
QueryWrapper
<
VmsCarryCapacityLatest
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
select
(
"SUM(FREE_MILE)"
,
"SUM(WORK_MILE)"
);
return
this
.
page
(
page
,
wrapper
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsChargingConnectorInfoServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.ssi.entity.VmsAreaPosition
;
import
com.ssi.entity.VmsChargingConnectorInfo
;
import
com.ssi.entity.VmsChargingEquipmentInfo
;
import
com.ssi.entity.VmsChargingPile
;
import
com.ssi.response.SSIPage
;
import
com.ssi.service.VmsChargingConnectorInfoService
;
import
com.ssi.mapper.VmsChargingConnectorInfoMapper
;
import
com.ssi.utils.QueryUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.http.util.Asserts
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
/**
*
*/
@Service
public
class
VmsChargingConnectorInfoServiceImpl
extends
ServiceImpl
<
VmsChargingConnectorInfoMapper
,
VmsChargingConnectorInfo
>
implements
VmsChargingConnectorInfoService
{
@Override
public
Runnable
saveConnectorInfo
(
JSONObject
data
)
{
return
()->{
try
{
JSONArray
stationInfos
=
data
.
getJSONArray
(
"StationInfos"
);
for
(
int
i
=
0
;
i
<
stationInfos
.
size
();
i
++)
{
JSONObject
stationInfo
=
stationInfos
.
getJSONObject
(
i
);
JSONArray
equipmentInfos
=
stationInfo
.
getJSONArray
(
"EquipmentInfos"
);
for
(
int
j
=
0
;
j
<
equipmentInfos
.
size
();
j
++)
{
JSONObject
equipmentInfo
=
equipmentInfos
.
getJSONObject
(
j
);
JSONArray
connectorInfos
=
equipmentInfo
.
getJSONArray
(
"ConnectorInfos"
);
for
(
int
k
=
0
;
k
<
connectorInfos
.
size
();
k
++)
{
VmsChargingConnectorInfo
chargingConnectorInfo
=
connectorInfos
.
getObject
(
i
,
VmsChargingConnectorInfo
.
class
);
chargingConnectorInfo
.
setEquipmentId
(
equipmentInfo
.
getString
(
"EquipmentID"
));
chargingConnectorInfo
.
setStationId
(
stationInfo
.
getString
(
"StationID"
));
chargingConnectorInfo
.
setUpdateTime
(
new
Date
());
this
.
saveOrUpdate
(
chargingConnectorInfo
);
}
}
}
}
catch
(
Exception
e
){
log
.
error
(
"saveConnectorInfo occur error:"
,
e
);
}
};
}
@Override
public
void
updateStatus
(
JSONObject
jsonObject
)
{
Asserts
.
notNull
(
jsonObject
,
"充电站"
);
String
stationID
=
jsonObject
.
getString
(
"StationID"
);
JSONArray
connectorStatusInfos
=
jsonObject
.
getJSONArray
(
"ConnectorStatusInfos"
);
for
(
int
i
=
0
;
i
<
connectorStatusInfos
.
size
();
i
++)
{
VmsChargingConnectorInfo
updateEntity
=
connectorStatusInfos
.
getObject
(
i
,
VmsChargingConnectorInfo
.
class
);
updateEntity
.
setStationId
(
stationID
);
this
.
updateById
(
updateEntity
);
}
}
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
Integer
connectorType
=
(
Integer
)
params
.
get
(
"connectorType"
);
Integer
workStatus
=
(
Integer
)
params
.
get
(
"status"
);
String
pileNum
=
(
String
)
params
.
get
(
"equipmentId"
);
String
gunNum
=
(
String
)
params
.
get
(
"connectorId"
);
IPage
<
VmsChargingConnectorInfo
>
page
=
this
.
page
(
new
QueryUtils
<
VmsChargingConnectorInfo
>().
getPage
(
params
),
new
LambdaQueryWrapper
<
VmsChargingConnectorInfo
>()
.
eq
(
workStatus
!=
null
,
VmsChargingConnectorInfo:
:
getStatus
,
workStatus
)
.
eq
(
connectorType
!=
null
,
VmsChargingConnectorInfo:
:
getConnectorType
,
connectorType
)
.
like
(
StringUtils
.
isNotBlank
(
gunNum
),
VmsChargingConnectorInfo:
:
getConnectorId
,
gunNum
)
.
like
(
StringUtils
.
isNotBlank
(
pileNum
),
VmsChargingConnectorInfo:
:
getEquipmentId
,
pileNum
)
);
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsChargingEquipmentInfoServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsChargingEquipmentInfo
;
import
com.ssi.mapper.VmsChargingEquipmentInfoMapper
;
import
com.ssi.service.VmsChargingEquipmentInfoService
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
*
*/
@Service
public
class
VmsChargingEquipmentInfoServiceImpl
extends
ServiceImpl
<
VmsChargingEquipmentInfoMapper
,
VmsChargingEquipmentInfo
>
implements
VmsChargingEquipmentInfoService
{
@Override
public
Runnable
saveEquipmentInfo
(
JSONObject
data
)
{
return
()->{
try
{
JSONArray
stationInfos
=
data
.
getJSONArray
(
"StationInfos"
);
for
(
int
i
=
0
;
i
<
stationInfos
.
size
();
i
++)
{
JSONObject
stationInfo
=
stationInfos
.
getJSONObject
(
i
);
JSONArray
equipmentInfos
=
stationInfo
.
getJSONArray
(
"EquipmentInfos"
);
for
(
int
j
=
0
;
j
<
equipmentInfos
.
size
();
j
++)
{
VmsChargingEquipmentInfo
equipmentInfo
=
equipmentInfos
.
getObject
(
j
,
VmsChargingEquipmentInfo
.
class
);
equipmentInfo
.
setStationId
(
stationInfo
.
getString
(
"StationID"
));
this
.
saveOrUpdate
(
equipmentInfo
);
}
}
}
catch
(
Exception
e
){
log
.
error
(
"saveEquipmentInfo occur error:"
,
e
);
}
};
}
@Override
public
List
<
VmsChargingEquipmentInfo
>
qryFreeEquipment
(
int
i
)
{
return
this
.
baseMapper
.
qryFreeEquipment
(
i
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsChargingOrderInfoServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsChargingOrderInfo
;
import
com.ssi.service.VmsChargingOrderInfoService
;
import
com.ssi.mapper.VmsChargingOrderInfoMapper
;
import
org.springframework.stereotype.Service
;
/**
*
*/
@Service
public
class
VmsChargingOrderInfoServiceImpl
extends
ServiceImpl
<
VmsChargingOrderInfoMapper
,
VmsChargingOrderInfo
>
implements
VmsChargingOrderInfoService
{
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsChargingPileServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.ssi.entity.VmsAreaPosition
;
import
com.ssi.mapper.VmsChargingPileMapper
;
import
com.ssi.model.RedisDataModel
;
import
com.ssi.response.SSIPage
;
import
com.ssi.service.VmsAreaPositionService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.ssi.utils.QueryUtils
;
import
com.ssi.entity.VmsChargingPile
;
import
com.ssi.service.VmsChargingPileService
;
/**
* 充电桩服务实现类
*/
@Service
(
"chargingPileService"
)
public
class
VmsChargingPileServiceImpl
extends
ServiceImpl
<
VmsChargingPileMapper
,
VmsChargingPile
>
implements
VmsChargingPileService
{
@Value
(
"${charging-pile.latest_key_prefix:harbor:charging:pile:info}"
)
private
String
latestKeyPrefix
;
@Value
(
"${charging-pile.charging_history_prefix:harbor:charging:history}"
)
private
String
chargingHistoryPrefix
;
@Value
(
"${vehicle.latestData.redis.prefix:ivccs:vms:vehicle:latest}"
)
private
String
latestRedisKeyPrefix
;
@Value
(
"${vehicle.latestData.redis.postfix:harbor_D00A}"
)
private
String
latestRedisKeyPostfix
;
@Value
(
"${vehicle.cache.key:ivccs:vms:vehicle:cache}"
)
private
String
vehicleCacheKey
;
@Autowired
private
RedisDataModel
redisDataModel
;
@Autowired
private
VmsAreaPositionService
vmsAreaPositionService
;
/**
* 充电桩分页数据
* @param params
* @return
*/
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
Integer
onlineStatus
=
(
Integer
)
params
.
get
(
"onlineStatus"
);
Integer
workStatus
=
(
Integer
)
params
.
get
(
"workStatus"
);
Integer
faultStatus
=
(
Integer
)
params
.
get
(
"faultStatus"
);
String
pileNum
=
(
String
)
params
.
get
(
"pileNum"
);
String
gunNum
=
(
String
)
params
.
get
(
"gunNum"
);
IPage
<
VmsChargingPile
>
page
=
this
.
page
(
new
QueryUtils
<
VmsChargingPile
>().
getPage
(
params
),
new
LambdaQueryWrapper
<
VmsChargingPile
>().
eq
(
onlineStatus
!=
null
,
VmsChargingPile:
:
getOnlineStatus
,
onlineStatus
)
.
eq
(
workStatus
!=
null
,
VmsChargingPile:
:
getWorkStatus
,
workStatus
)
.
eq
(
faultStatus
!=
null
,
VmsChargingPile:
:
getFaultStatus
,
faultStatus
)
.
like
(
StringUtils
.
isNotBlank
(
gunNum
),
VmsChargingPile:
:
getGunNum
,
gunNum
)
.
like
(
StringUtils
.
isNotBlank
(
pileNum
),
VmsChargingPile:
:
getPileNum
,
pileNum
)
);
//获取充电桩实时充电指令
Map
<
String
,
String
>
chargingHistoryInfo
=
getChargingHistoryInfo
();
//获取工作状态
page
.
getRecords
().
stream
().
forEach
(
chargingPile
->
{
if
(
StringUtils
.
isNotBlank
(
chargingPile
.
getGunNum
())){
List
<
Integer
>
allStatus
=
Lists
.
newArrayList
();
String
gunNumStr
=
chargingPile
.
getGunNum
();
String
[]
split
=
gunNumStr
.
split
(
","
);
List
<
String
>
gunNums
=
Arrays
.
asList
(
split
);
gunNums
.
stream
().
forEach
(
num
->
{
String
result
=
redisDataModel
.
get
(
String
.
format
(
"%s:%s"
,
latestKeyPrefix
,
num
));
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
result
);
if
(
jsonObject
==
null
){
return
;
}
Integer
status
=
jsonObject
.
getInteger
(
"status"
);
allStatus
.
add
(
status
);
});
if
(
allStatus
.
contains
(
255
)
||
allStatus
.
contains
(
0
)){
//异常状态
chargingPile
.
setWorkStatus
(
2
);
}
else
if
(
allStatus
.
contains
(
2
)
||
allStatus
.
contains
(
3
)
||
allStatus
.
contains
(
4
)){
//充电中
chargingPile
.
setWorkStatus
(
1
);
}
else
{
//空闲
chargingPile
.
setWorkStatus
(
0
);
}
//查询充电车辆
if
(
chargingPile
.
getWorkStatus
()
==
1
){
//根据充电桩和停车区充电枪是否有对应查询对应关系
List
<
VmsAreaPosition
>
areaPositionList
=
vmsAreaPositionService
.
list
();
String
areaNum
=
null
;
for
(
VmsAreaPosition
areaPosition
:
areaPositionList
){
boolean
isCorrespondArea
=
false
;
String
chargingInterfaceIds
=
areaPosition
.
getChargingInterfaceIds
();
for
(
String
gunNum1
:
gunNums
){
if
(
StringUtils
.
isNotBlank
(
chargingInterfaceIds
)
&&
chargingInterfaceIds
.
indexOf
(
gunNum1
)
>
-
1
){
isCorrespondArea
=
true
;
break
;
}
}
if
(
isCorrespondArea
){
areaNum
=
areaPosition
.
getAreaNum
();
break
;
}
}
if
(
StringUtils
.
isNotBlank
(
areaNum
)){
String
vin
=
chargingHistoryInfo
.
get
(
areaNum
);
if
(
StringUtils
.
isNotBlank
(
vin
)){
Map
<
String
,
Object
>
vehicleInfoRecord
=
redisDataModel
.
hgetJson2Map
(
vehicleCacheKey
,
vin
);
Map
<
String
,
Object
>
record
=
redisDataModel
.
getJson2Map
(
String
.
format
(
"%s:%s-%s"
,
latestRedisKeyPrefix
,
vin
,
latestRedisKeyPostfix
));
chargingPile
.
setChargingVehicleNum
((
String
)
vehicleInfoRecord
.
get
(
"vehicleNum"
));
chargingPile
.
setChargingPer
((
Integer
)
record
.
get
(
"soc"
));
}
}
}
}
else
{
chargingPile
.
setWorkStatus
(
2
);
}
});
return
new
SSIPage
(
page
);
}
private
Map
<
String
,
String
>
getChargingHistoryInfo
()
{
Map
<
String
,
String
>
res
=
new
HashMap
<>();
String
prefix
=
String
.
format
(
"%s:*"
,
chargingHistoryPrefix
);
Set
<
String
>
keysUnResolveRepeat
=
redisDataModel
.
keys
(
prefix
);
keysUnResolveRepeat
.
stream
().
forEach
(
key
->
{
Map
<
String
,
Object
>
record
=
redisDataModel
.
getJson2Map
(
key
);
res
.
put
((
String
)
record
.
get
(
"areaNum"
),(
String
)
record
.
get
(
"vin"
));
});
return
res
;
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsChargingStationServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsChargingStation
;
import
com.ssi.service.VmsChargingStationService
;
import
com.ssi.mapper.VmsChargingStationMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
/**
*
*/
@Service
@Slf4j
public
class
VmsChargingStationServiceImpl
extends
ServiceImpl
<
VmsChargingStationMapper
,
VmsChargingStation
>
implements
VmsChargingStationService
{
@Override
public
Runnable
saveStationInfo
(
JSONObject
data
)
{
return
()->{
try
{
JSONArray
stationInfos
=
data
.
getJSONArray
(
"StationInfos"
);
for
(
int
i
=
0
;
i
<
stationInfos
.
size
();
i
++)
{
VmsChargingStation
vmsChargingStation
=
stationInfos
.
getObject
(
i
,
VmsChargingStation
.
class
);
vmsChargingStation
.
setUpdateTime
(
new
Date
());
this
.
saveOrUpdate
(
vmsChargingStation
);
}
}
catch
(
Exception
e
){
log
.
error
(
"saveStationInfo occur error:"
,
e
);
}
};
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsCranePadBindServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.google.common.collect.Lists
;
import
com.ssi.constant.URL
;
import
com.ssi.entity.*
;
import
com.ssi.entity.vo.CargoShipConfigDto
;
import
com.ssi.entity.vo.CranePadBindVo
;
import
com.ssi.mapper.VmsCranePadBindMapper
;
import
com.ssi.model.RedisDataModel
;
import
com.ssi.response.SSIPage
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.service.CargoShipConfigInfoService
;
import
com.ssi.service.VmsCranePadBindService
;
import
com.ssi.service.VmsOrdersVehicleAlterService
;
import
com.ssi.service.VmsVehicleService
;
import
com.ssi.utils.RestTemplateUtil
;
import
com.ssi.utils.VehicleUtil
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
import
java.util.function.Function
;
import
java.util.stream.Collectors
;
/**
* 港机pad绑定服务实现类
*/
@Service
(
"cranePadBindService"
)
public
class
VmsCranePadBindServiceImpl
extends
ServiceImpl
<
VmsCranePadBindMapper
,
VmsCranePadBind
>
implements
VmsCranePadBindService
{
@Autowired
private
VmsVehicleService
vmsVehicleService
;
@Autowired
private
VmsOrdersVehicleAlterService
vmsOrdersVehicleAlterService
;
@Autowired
private
CargoShipConfigInfoService
cargoShipConfigInfoService
;
@Autowired
private
RedisDataModel
redisDataModel
;
@Value
(
"${order.latestOrderKeyPrefix:harbor:command:status}"
)
private
String
latestOrderKeyPrefix
;
@Value
(
"${map-edit-url}"
)
private
String
mapEditUrl
;
/**
* 吊具pad绑定列表
*/
@Override
public
SSIPage
queryPage
(
CranePadBindVo
cranePadBindVo
)
{
IPage
<
VmsCranePadBind
>
page
=
this
.
lambdaQuery
()
.
eq
(
Objects
.
nonNull
(
cranePadBindVo
.
getCraneType
()),
VmsCranePadBind:
:
getCraneType
,
cranePadBindVo
.
getCraneType
())
.
like
(
cranePadBindVo
.
getCraneNo
()
!=
null
,
VmsCranePadBind:
:
getCraneNo
,
cranePadBindVo
.
getCraneNo
())
.
orderByDesc
(
VmsCranePadBind:
:
getCreateTime
)
.
page
(
new
Page
<>(
cranePadBindVo
.
getPageIndex
(),
cranePadBindVo
.
getPageSize
()));
CargoShipConfigDto
queryDto
=
new
CargoShipConfigDto
();
queryDto
.
setIsActive
((
byte
)
1
);
JSONObject
resultMap
=
cargoShipConfigInfoService
.
listByCondition
(
queryDto
);
JSONArray
jsonArray
=
resultMap
.
getJSONArray
(
"result"
);
if
(
jsonArray
.
size
()>
0
){
List
<
CargoShipConfigDto
>
cargoShipConfigDtos
=
jsonArray
.
toJavaList
(
CargoShipConfigDto
.
class
);
List
<
String
>
collect
=
cargoShipConfigDtos
.
stream
().
map
(
CargoShipConfigDto:
:
getBridgeNo
).
collect
(
Collectors
.
toList
());
page
.
getRecords
().
stream
().
forEach
(
vmsCranePadBind
->
{
if
(
collect
.
contains
(
vmsCranePadBind
.
getCraneNo
())){
vmsCranePadBind
.
setInUsing
(
1
);
}
});
}
return
new
SSIPage
(
page
);
}
/**
* 根据mac获取桥吊信息
* @param padMac pad的MAC地址
*/
@Override
public
SSIResponse
getCraneByMac
(
String
padMac
)
{
List
<
VmsCranePadBind
>
list
=
this
.
list
(
new
LambdaQueryWrapper
<
VmsCranePadBind
>().
eq
(
VmsCranePadBind:
:
getPadMac
,
padMac
));
if
(
list
!=
null
&&
!
list
.
isEmpty
())
{
List
<
VmsVehicle
>
vehicleList
=
vmsVehicleService
.
list
();
Map
<
String
,
VmsVehicle
>
vinMap
=
vehicleList
.
stream
().
collect
(
Collectors
.
toMap
(
VmsVehicle:
:
getVin
,
Function
.
identity
()));
List
<
Map
<
String
,
Object
>>
ordersList
=
getCraneOrderList
(
vinMap
,
list
.
get
(
0
));
list
.
get
(
0
).
setOrdersList
(
ordersList
);
return
SSIResponse
.
ok
(
list
.
get
(
0
));
}
return
SSIResponse
.
ok
();
}
/**
* 获取港机对应的任务
* @param vinMap
* @param vmsCranePadBind
* @return
*/
@Override
public
List
<
Map
<
String
,
Object
>>
getCraneOrderList
(
Map
<
String
,
VmsVehicle
>
vinMap
,
VmsCranePadBind
vmsCranePadBind
)
{
List
<
Map
<
String
,
Object
>>
ordersList
=
Lists
.
newArrayList
();
List
<
VmsTosOrders
>
orders
=
getUnconfOrdersByPortCode
(
vmsCranePadBind
);
orders
.
stream
().
forEach
(
vmsTosOrders
->
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"taskNo"
,
vmsTosOrders
.
getTaskNo
());
map
.
put
(
"taskType"
,
vmsTosOrders
.
getTaskType
());
map
.
put
(
"portCode"
,
vmsTosOrders
.
getPortCode
());
map
.
put
(
"containerId"
,
vmsTosOrders
.
getContainerId
());
map
.
put
(
"vin"
,
vmsTosOrders
.
getVin
());
map
.
put
(
"status"
,
vmsTosOrders
.
getStatus
());
VmsVehicle
vmsVehicle
=
vinMap
.
get
(
vmsTosOrders
.
getVin
());
if
(
vmsVehicle
!=
null
){
map
.
put
(
"vehicleNum"
,
vmsVehicle
.
getVehicleNum
());
map
.
put
(
"vehicleType"
,
vmsVehicle
.
getVehicleType
()
==
null
?
0
:
vmsVehicle
.
getVehicleType
());
}
else
{
map
.
put
(
"vehicleNum"
,
"未知"
);
map
.
put
(
"vehicleType"
,
0
);
}
ordersList
.
add
(
map
);
});
return
ordersList
;
}
@Override
@Transactional
public
void
updateCraneBind
(
List
<
Integer
>
craneIds
,
String
id
,
String
number
,
String
bridgeNo
)
{
try
{
//更新原有为null;
this
.
baseMapper
.
clearByAreaNo
(
number
);
//更新
String
[]
bridgeNos
=
StringUtils
.
split
(
bridgeNo
,
","
);
this
.
baseMapper
.
updateByIds
(
id
,
number
,
Arrays
.
asList
(
bridgeNos
));
Map
param
=
new
HashMap
();
param
.
put
(
"bridgeNo"
,
bridgeNo
);
param
.
put
(
"name"
,
number
);
String
paramData
=
JSONObject
.
toJSONString
(
param
);
RestTemplateUtil
.
post
(
String
.
format
(
"%s%s"
,
mapEditUrl
,
URL
.
MAP_EDIT_LOCK_URL
),
paramData
,
null
);
}
catch
(
Exception
e
){
log
.
error
(
"更新桥吊扭锁区绑定关系错误"
,
e
);
}
}
@Override
public
void
addCarineInfo
(
JSONObject
jsonObject
)
{
JSONArray
dataList
=
jsonObject
.
getJSONArray
(
"data"
);
for
(
int
i
=
0
;
i
<
dataList
.
size
();
i
++){
JSONObject
tmpObject
=
dataList
.
getJSONObject
(
i
);
tmpObject
.
put
(
"bindCarine"
,
Collections
.
EMPTY_LIST
);
if
(
Objects
.
nonNull
(
tmpObject
)&&
tmpObject
.
getInteger
(
"type"
)==
6
){
List
<
VmsCranePadBind
>
list
=
this
.
lambdaQuery
().
eq
(
VmsCranePadBind:
:
getLockAreaId
,
tmpObject
.
getString
(
"id"
)).
list
();
tmpObject
.
put
(
"bindCarine"
,
list
);
}
}
}
private
List
<
VmsTosOrders
>
getUnconfOrdersByPortCode
(
VmsCranePadBind
vmsCranePadBind
)
{
if
(
vmsCranePadBind
==
null
||
vmsCranePadBind
.
getCraneType
()
==
null
||
StringUtils
.
isBlank
(
vmsCranePadBind
.
getCraneNo
())){
//港机信息不存在
return
new
ArrayList
<
VmsTosOrders
>();
}
//获取当前所有任务
Set
<
String
>
keys
=
redisDataModel
.
keys
(
latestOrderKeyPrefix
+
"*"
);
List
<
String
>
list
=
redisDataModel
.
mget
(
keys
.
toArray
(
new
String
[
keys
.
size
()]));
//获取已确认任务
List
<
String
>
confOrderNos
=
vmsOrdersVehicleAlterService
.
list
().
stream
().
map
(
VmsOrdersVehicleAlter:
:
getTaskNo
).
collect
(
Collectors
.
toList
());
//判断港机类型
Integer
taskLocationType
=
vmsCranePadBind
.
getCraneType
()
==
1
?
5
:
1
;
//过滤任务
if
(
CollectionUtils
.
isNotEmpty
(
keys
))
{
if
(
CollectionUtils
.
isNotEmpty
(
list
))
{
List
<
VmsTosOrders
>
res
=
list
.
stream
().
map
(
s
->
JSON
.
parseObject
(
s
,
VmsTosOrders
.
class
))
.
filter
(
vmsTosOrders
->
{
if
(
vmsCranePadBind
.
getCraneNo
().
equals
(
vmsTosOrders
.
getPortCode
())
&&
!
VehicleUtil
.
isTaskOver
(
vmsTosOrders
.
getStatus
())
&&
vmsTosOrders
.
getTaskLocationType
()
==
taskLocationType
&&
(
confOrderNos
.
isEmpty
()
||
!
confOrderNos
.
contains
(
vmsTosOrders
.
getTaskNo
()))
//暂时注释
// && (vmsTosOrders.getStatus() == VmsTosOrderStatusEnum.ARRIVED_DESTINATION.getCode()
// || vmsTosOrders.getStatus() == VmsTosOrderStatusEnum.VEHICLE_LOCKUP.getCode())
)
{
return
true
;
}
return
false
;
}).
collect
(
Collectors
.
toList
());
if
(!
res
.
isEmpty
())
{
res
=
res
.
stream
().
sorted
(
Comparator
.
comparing
(
VmsTosOrders:
:
getCollectTime
)).
collect
(
Collectors
.
toList
());
}
return
res
;
}
}
return
new
ArrayList
<
VmsTosOrders
>();
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsDebugAppServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.ssi.constant.VehicleConstant
;
import
com.ssi.entity.VmsVehicle
;
import
com.ssi.model.RedisDataModel
;
import
com.ssi.response.SSIPage
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.service.VmsVehicleService
;
import
com.ssi.utils.QueryUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.mapper.VmsDebugAppMapper
;
import
com.ssi.entity.VmsDebugApp
;
import
com.ssi.service.VmsDebugAppService
;
/**
* 调试APP服务实现类
*/
@Service
(
"debugAppService"
)
@Slf4j
public
class
VmsDebugAppServiceImpl
extends
ServiceImpl
<
VmsDebugAppMapper
,
VmsDebugApp
>
implements
VmsDebugAppService
{
@Value
(
"${debug-app.check-num.prefix}"
)
private
String
checkNumPrefix
;
@Value
(
"${harbor.remote.vehicle_status}"
)
private
String
remoteControlStatusKeyPrefix
;
@Autowired
private
RedisDataModel
redisDataModel
;
@Autowired
private
VmsVehicleService
vmsVehicleService
;
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
IPage
<
VmsDebugApp
>
page
=
this
.
page
(
new
QueryUtils
<
VmsDebugApp
>().
getPage
(
params
),
new
QueryWrapper
<
VmsDebugApp
>()
);
Set
<
String
>
keys
=
redisDataModel
.
keys
(
remoteControlStatusKeyPrefix
+
"*"
);
if
(
CollectionUtils
.
isNotEmpty
(
keys
)){
List
<
String
>
controlStatusList
=
redisDataModel
.
mget
(
keys
.
toArray
(
new
String
[
keys
.
size
()]));
if
(
CollectionUtils
.
isNotEmpty
(
controlStatusList
)){
List
<
VmsDebugApp
>
records
=
page
.
getRecords
();
if
(
CollectionUtils
.
isNotEmpty
(
records
)){
records
.
forEach
(
vmsDebugApp
->
{
String
appMac
=
vmsDebugApp
.
getAppMac
();
for
(
int
i
=
0
;
i
<
controlStatusList
.
size
();
i
++)
{
String
res
=
controlStatusList
.
get
(
i
);
JSONObject
obj
=
JSON
.
parseObject
(
res
);
String
mac
=
obj
.
getString
(
"appMac"
);
Integer
appControl
=
obj
.
getInteger
(
"appControl"
);
String
vin
=
obj
.
getString
(
"vin"
);
if
(
StringUtils
.
isNotBlank
(
mac
)
&&
appMac
.
equals
(
mac
)
&&
appControl
==
1
){
VmsVehicle
one
=
vmsVehicleService
.
lambdaQuery
().
eq
(
VmsVehicle:
:
getVin
,
vin
).
one
();
if
(
one
!=
null
){
vmsDebugApp
.
setVehicleNum
(
one
.
getVehicleNum
());
}
vmsDebugApp
.
setVin
(
vin
);
vmsDebugApp
.
setAppControl
(
appControl
);
}
}
});
}
}
}
return
new
SSIPage
(
page
);
}
@Override
public
String
getKey
()
{
String
key
=
baseMapper
.
getKey
(
VehicleConstant
.
DEBUG_APP_KEY
,
VehicleConstant
.
ADMIN_DATABASE_NAME
);
return
key
;
}
@Override
public
void
updateKey
(
String
key
)
{
String
curKey
=
this
.
getKey
();
boolean
flag
=
StringUtils
.
isNotBlank
(
curKey
);
baseMapper
.
updateKey
(
key
,
flag
,
VehicleConstant
.
DEBUG_APP_KEY
,
VehicleConstant
.
ADMIN_DATABASE_NAME
);
}
/**
* 密钥校验
*/
@Override
public
SSIResponse
checkApp
(
String
key
,
String
appMac
)
{
log
.
info
(
String
.
format
(
"遥控APP验证请求发送->appMac:%s,密钥:%s"
,
appMac
,
key
));
int
count
=
this
.
count
(
new
LambdaQueryWrapper
<
VmsDebugApp
>().
eq
(
VmsDebugApp:
:
getAppMac
,
appMac
));
if
(
count
<=
0
)
{
log
.
info
(
String
.
format
(
"遥控APP验证结果->设备未授权,appMac:%s"
,
appMac
));
return
SSIResponse
.
no
(
"设备未授权!"
);
}
String
checkNumKey
=
String
.
format
(
"%s:%S"
,
checkNumPrefix
,
appMac
);
Integer
num
=
StringUtils
.
isNotBlank
(
redisDataModel
.
get
(
checkNumKey
))
?
Integer
.
parseInt
(
redisDataModel
.
get
(
checkNumKey
))
:
0
;
if
(
num
>=
5
)
{
log
.
info
(
String
.
format
(
"遥控APP验证结果->当前设备密钥已输错5次,appMac:%s,key:%s"
,
appMac
,
key
));
return
SSIResponse
.
no
(
"密钥已输错5次,请稍后再试!"
);
}
String
curKey
=
this
.
getKey
();
if
(!
curKey
.
equalsIgnoreCase
(
key
))
{
//添加错误次数
num
++;
redisDataModel
.
set
(
checkNumKey
,
String
.
valueOf
(
num
),
5
*
60L
);
log
.
info
(
String
.
format
(
"遥控APP验证结果->密钥不正确,appMac:%s,key:%s"
,
appMac
,
key
));
return
SSIResponse
.
no
(
"密钥不正确!"
);
}
redisDataModel
.
del
(
checkNumKey
);
log
.
info
(
String
.
format
(
"遥控APP验证成功->appMac:%s,密钥:%s"
,
appMac
,
key
));
return
SSIResponse
.
ok
();
}
/**
* 修改遥控接管最大距离
*/
@Override
public
void
updateDiStance
(
Integer
distance
)
{
Integer
curDistance
=
this
.
getDistance
();
boolean
flag
=
curDistance
!=
null
;
baseMapper
.
updateDiStance
(
distance
,
flag
,
VehicleConstant
.
DEBUG_APP_DISTANCE
,
VehicleConstant
.
ADMIN_DATABASE_NAME
);
}
/**
* 获取遥控接管最大距离
*/
@Override
public
Integer
getDistance
()
{
String
distance
=
baseMapper
.
getDistance
(
VehicleConstant
.
DEBUG_APP_DISTANCE
,
VehicleConstant
.
ADMIN_DATABASE_NAME
);
return
StringUtils
.
isNotBlank
(
distance
)
?
Integer
.
parseInt
(
distance
)
:
null
;
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsDeviceVersionServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.utils.QueryUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.mapper.VmsDeviceVersionMapper
;
import
com.ssi.entity.VmsDeviceVersion
;
import
com.ssi.service.VmsDeviceVersionService
;
/**
* 终端版本服务实现类
*/
@Service
(
"deviceVersionService"
)
public
class
VmsDeviceVersionServiceImpl
extends
ServiceImpl
<
VmsDeviceVersionMapper
,
VmsDeviceVersion
>
implements
VmsDeviceVersionService
{
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
String
deviceName
=
(
String
)
params
.
get
(
"deviceName"
);
IPage
<
VmsDeviceVersion
>
page
=
this
.
page
(
new
QueryUtils
<
VmsDeviceVersion
>().
getPage
(
params
),
new
LambdaQueryWrapper
<
VmsDeviceVersion
>()
.
like
(
StringUtils
.
isNotBlank
(
deviceName
),
VmsDeviceVersion:
:
getDeviceName
,
deviceName
)
.
orderByDesc
(
VmsDeviceVersion:
:
getPublishTime
)
);
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsElectAlertInfoServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsElectAlertInfo
;
import
com.ssi.service.VmsElectAlertInfoService
;
import
com.ssi.mapper.VmsElectAlertInfoMapper
;
import
org.springframework.stereotype.Service
;
/**
*
*/
@Service
public
class
VmsElectAlertInfoServiceImpl
extends
ServiceImpl
<
VmsElectAlertInfoMapper
,
VmsElectAlertInfo
>
implements
VmsElectAlertInfoService
{
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsEventServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.utils.QueryUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.mapper.VmsEventMapper
;
import
com.ssi.entity.VmsEvent
;
import
com.ssi.service.VmsEventService
;
/**
* 事件服务实现类
*/
@Service
(
"eventService"
)
public
class
VmsEventServiceImpl
extends
ServiceImpl
<
VmsEventMapper
,
VmsEvent
>
implements
VmsEventService
{
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
String
eventType
=
(
String
)
params
.
get
(
"eventType"
);
Integer
eventSource
=
(
Integer
)
params
.
get
(
"eventSource"
);
Integer
eventStatus
=
(
Integer
)
params
.
get
(
"eventStatus"
);
Long
startTime
=
(
Long
)
params
.
get
(
"startTime"
);
Long
stopTime
=
(
Long
)
params
.
get
(
"stopTime"
);
Date
startDate
=
startTime
==
null
?
null
:
new
Date
(
startTime
);
Date
stopDate
=
stopTime
==
null
?
null
:
new
Date
(
stopTime
);
IPage
<
VmsEvent
>
page
=
this
.
page
(
new
QueryUtils
<
VmsEvent
>().
getPage
(
params
),
new
LambdaQueryWrapper
<
VmsEvent
>()
.
eq
(
StringUtils
.
isNotBlank
(
eventType
),
VmsEvent:
:
getEventType
,
eventType
)
.
eq
(
eventSource
!=
null
,
VmsEvent:
:
getEventSource
,
eventSource
)
//未来事件
.
gt
(
eventStatus
!=
null
&&
eventStatus
==
0
,
VmsEvent:
:
getEventStartTime
,
new
Date
())
//活动事件
.
le
(
eventStatus
!=
null
&&
eventStatus
==
1
,
VmsEvent:
:
getEventStartTime
,
new
Date
())
.
and
(
eventStatus
!=
null
&&
eventStatus
==
1
,
wrapper
->
wrapper
.
ge
(
VmsEvent:
:
getEventStopTime
,
new
Date
()))
//d过期事件
.
lt
(
eventStatus
!=
null
&&
eventStatus
==
2
,
VmsEvent:
:
getEventStopTime
,
new
Date
())
.
between
(
startTime
!=
null
&&
stopTime
!=
null
,
VmsEvent:
:
getEventStartTime
,
startDate
,
stopDate
)
);
page
.
getRecords
().
parallelStream
().
forEach
(
event
->
{
if
(
event
.
getEventStatus
()
==
null
)
{
if
(
event
.
getEventStartTime
().
getTime
()
<
new
Date
().
getTime
())
{
if
(
event
.
getEventStopTime
().
getTime
()
>
new
Date
().
getTime
())
{
event
.
setEventStatus
(
1
);
}
else
{
event
.
setEventStatus
(
2
);
}
}
else
{
event
.
setEventStatus
(
0
);
}
}
});
return
new
SSIPage
(
page
);
}
}
ivccs-vmm-backservice/src/main/java/com/ssi/service/impl/VmsFaultCodeServiceImpl.java
0 → 100644
View file @
07602a7b
package
com.ssi.service.impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.ssi.mapper.VmsFaultCodeMapper
;
import
com.ssi.response.SSIPage
;
import
com.ssi.response.SSIResponse
;
import
com.ssi.utils.PoiUtils
;
import
com.ssi.utils.QueryUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.stereotype.Service
;
import
java.io.InputStream
;
import
java.net.URLEncoder
;
import
java.util.List
;
import
java.util.Map
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.ssi.entity.VmsFaultCode
;
import
com.ssi.service.VmsFaultCodeService
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletResponse
;
/**
* 故障码服务实现类
*/
@Service
(
"faultCodeService"
)
public
class
VmsFaultCodeServiceImpl
extends
ServiceImpl
<
VmsFaultCodeMapper
,
VmsFaultCode
>
implements
VmsFaultCodeService
{
private
static
String
COMMA
=
","
;
private
static
String
LINENUM
=
"第%s行:"
;
private
static
String
END
=
"; <br/>"
;
/**
* 故障码列表分页
*/
@Override
public
SSIPage
queryPage
(
Map
<
String
,
Object
>
params
)
{
Integer
faultGrade
=
(
Integer
)
params
.
get
(
"faultGrade"
);
String
faultCode
=
(
String
)
params
.
get
(
"faultCode"
);
IPage
<
VmsFaultCode
>
page
=
this
.
page
(
new
QueryUtils
<
VmsFaultCode
>().
getPage
(
params
),
new
LambdaQueryWrapper
<
VmsFaultCode
>().
eq
(
faultGrade
!=
null
,
VmsFaultCode:
:
getFaultGrade
,
faultGrade
)
.
like
(
StringUtils
.
isNotBlank
(
faultCode
),
VmsFaultCode:
:
getFaultCode
,
faultCode
)
);
return
new
SSIPage
(
page
);
}
@Override
public
void
downloadExcel
(
InputStream
in
,
HttpServletResponse
response
,
String
fileName
)
throws
Exception
{
Workbook
workbook
=
getWorkbook
(
in
,
fileName
);
response
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setHeader
(
"content-Type"
,
"application/vnd.ms-excel"
);
response
.
setHeader
(
"Content-Disposition"
,
"attachment;filename="
+
URLEncoder
.
encode
(
fileName
,
"UTF-8"
));
workbook
.
write
(
response
.
getOutputStream
());
}
/**
* 导入故障码
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
SSIResponse
importList
(
MultipartFile
file
)
{
List
<
VmsFaultCode
>
vmsFaultCodes
=
PoiUtils
.
importExcel
(
file
,
0
,
1
,
VmsFaultCode
.
class
);
StringBuilder
msgSb
=
new
StringBuilder
();
checkImportEmpty
(
vmsFaultCodes
,
msgSb
);
if
(
StringUtils
.
isNotBlank
(
msgSb
.
toString
())){
return
SSIResponse
.
no
(
msgSb
.
toString
());
}
msgSb
=
checkRepeat
(
vmsFaultCodes
);
if
(
StringUtils
.
isNotBlank
(
msgSb
.
toString
())){
return
SSIResponse
.
no
(
msgSb
.
toString
());
}
this
.
saveBatch
(
vmsFaultCodes
);
return
SSIResponse
.
ok
();
}
private
void
checkImportEmpty
(
List
<
VmsFaultCode
>
vmsFaultCodes
,
StringBuilder
msgSb
)
{
for
(
int
i
=
0
;
i
<
vmsFaultCodes
.
size
();
i
++){
VmsFaultCode
vmsFaultCode
=
vmsFaultCodes
.
get
(
i
);
if
(
vmsFaultCode
!=
null
){
StringBuilder
lineMsg
=
checkParamNull
(
vmsFaultCode
);
StringBuilder
lineMsg2
=
checkCodeAndDesc
(
vmsFaultCode
);
lineMsg
.
append
(
lineMsg2
);
if
(
lineMsg
.
length
()
>
0
){
msgSb
.
append
(
String
.
format
(
LINENUM
,
i
+
1
)).
append
(
lineMsg
).
append
(
END
);
}
}
}
}
private
StringBuilder
checkRepeat
(
List
<
VmsFaultCode
>
vmsFaultCodes
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
vmsFaultCodes
.
size
();
i
++)
{
VmsFaultCode
vmsFaultCode
=
vmsFaultCodes
.
get
(
i
);
String
fmi
=
vmsFaultCode
.
getFmi
();
String
spn
=
vmsFaultCode
.
getSpn
();
String
sa
=
vmsFaultCode
.
getSa
();
Integer
count
=
this
.
lambdaQuery
().
eq
(
VmsFaultCode:
:
getFmi
,
fmi
)
.
eq
(
VmsFaultCode:
:
getSpn
,
spn
)
.
eq
(
VmsFaultCode:
:
getSa
,
sa
)
.
count
();
if
(
count
>
0
){
sb
.
append
(
"FMI:"
).
append
(
fmi
).
append
(
","
)
.
append
(
"SPN:"
).
append
(
spn
).
append
(
","
)
.
append
(
"SA:"
).
append
(
sa
)
.
append
(
"在数据库中已经存在"
);
return
sb
;
}
for
(
int
j
=
i
+
1
;
j
<
vmsFaultCodes
.
size
();
j
++)
{
VmsFaultCode
code
=
vmsFaultCodes
.
get
(
j
);
if
(
fmi
.
equals
(
code
.
getFmi
())
&&
spn
.
equals
(
code
.
getSpn
())
&&
sa
.
equals
(
code
.
getSa
())){
sb
.
append
(
"FMI:"
).
append
(
fmi
).
append
(
","
)
.
append
(
"SPN:"
).
append
(
spn
).
append
(
","
)
.
append
(
"SA:"
).
append
(
sa
)
.
append
(
"在excel中有重复值"
);
return
sb
;
}
}
}
return
sb
;
}
private
StringBuilder
checkParamNull
(
VmsFaultCode
vmsFaultCode
)
{
StringBuilder
lineMsg
=
new
StringBuilder
();
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getFaultCode
())){
lineMsg
.
append
(
"故障码为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getFaultName
())){
lineMsg
.
append
(
"故障名称为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getFaultGrade
())){
lineMsg
.
append
(
"故障等级为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getSpn
())){
lineMsg
.
append
(
"SPN为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getFmi
())){
lineMsg
.
append
(
"FMI为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getSa
())){
lineMsg
.
append
(
"SA为空"
).
append
(
COMMA
);
}
if
(
StringUtils
.
isBlank
(
vmsFaultCode
.
getDescribition
())){
lineMsg
.
append
(
"故障描述为空"
).
append
(
COMMA
);
}
if
(
lineMsg
.
length
()
>
0
){
lineMsg
=
lineMsg
.
deleteCharAt
(
lineMsg
.
length
()
-
1
);
}
return
lineMsg
;
}
private
StringBuilder
checkCodeAndDesc
(
VmsFaultCode
vmsFaultCode
)
{
StringBuilder
lineMsg
=
new
StringBuilder
();
if
(
StringUtils
.
isNotBlank
(
vmsFaultCode
.
getDescribition
())
&&
vmsFaultCode
.
getDescribition
().
length
()
>
200
){
lineMsg
.
append
(
"故障描述大于200字"
).
append
(
COMMA
);
}
if
(
lineMsg
.
length
()
>
0
){
lineMsg
=
lineMsg
.
deleteCharAt
(
lineMsg
.
length
()
-
1
);
}
return
lineMsg
;
}
private
Workbook
getWorkbook
(
InputStream
inStr
,
String
fileName
)
throws
Exception
{
Workbook
workbook
=
null
;
String
fileType
=
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
));
if
(
".xls"
.
equals
(
fileType
))
{
workbook
=
new
HSSFWorkbook
(
inStr
);
}
else
if
(
".xlsx"
.
equals
(
fileType
))
{
workbook
=
new
XSSFWorkbook
(
inStr
);
}
else
{
throw
new
Exception
(
"请上传excel文件!"
);
}
return
workbook
;
}
}
Prev
1
…
13
14
15
16
17
18
19
20
21
…
24
Next
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