Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-trialdrive-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 592c092e
authored
Jun 07, 2024
by
谢海旭
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
车辆用量分析接口调整
1 parent
907bd685
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
495 additions
and
43 deletions
src/main/java/cn/com/glsx/admin/modules/controller/RiskAssessmentController.java
src/main/java/cn/com/glsx/admin/modules/entity/DeviceJourneyOverview.java
src/main/java/cn/com/glsx/admin/modules/mapper/DeviceJourneyMapper.java
src/main/java/cn/com/glsx/admin/modules/mapper/DeviceJourneyOverviewMapper.java
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleDeviceMapper.java
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleMapper.java
src/main/java/cn/com/glsx/admin/modules/model/vo/VehicleUsageAnalysisVO.java
src/main/java/cn/com/glsx/admin/modules/service/DeviceService.java
src/main/java/cn/com/glsx/admin/modules/service/RiskAssessmentService.java
src/main/java/cn/com/glsx/admin/modules/utils/DateUtil.java
src/main/resources/mapper/DeviceJourneyMapper.xml
src/main/resources/mapper/DeviceJourneyOverviewMapper.xml
src/main/resources/mapper/VehicleDeviceMapper.xml
src/main/resources/mapper/VehicleMapper.xml
src/main/java/cn/com/glsx/admin/modules/controller/RiskAssessmentController.java
View file @
592c092
...
@@ -104,45 +104,7 @@ public class RiskAssessmentController extends AbstractController {
...
@@ -104,45 +104,7 @@ public class RiskAssessmentController extends AbstractController {
@ApiResponses
({
@ApiResponse
(
code
=
200
,
message
=
"OK"
,
response
=
VehicleUsageAnalysisVO
.
class
)})
@ApiResponses
({
@ApiResponse
(
code
=
200
,
message
=
"OK"
,
response
=
VehicleUsageAnalysisVO
.
class
)})
@GetMapping
(
value
=
"/usageAnalysis"
)
@GetMapping
(
value
=
"/usageAnalysis"
)
public
R
<
VehicleUsageAnalysisVO
>
usageAnalysis
(
@RequestParam
(
"vehicleId"
)
Long
vehicleId
)
{
public
R
<
VehicleUsageAnalysisVO
>
usageAnalysis
(
@RequestParam
(
"vehicleId"
)
Long
vehicleId
)
{
// VehicleUsageAnalysisVO vehicleUsageAnalysisVO = riskAssessmentService.usageAnalysis(vehicleId);
VehicleUsageAnalysisVO
vehicleUsageAnalysisVO
=
riskAssessmentService
.
usageAnalysis
(
vehicleId
);
VehicleUsageAnalysisVO
vehicleUsageAnalysisVO
=
new
VehicleUsageAnalysisVO
();
vehicleUsageAnalysisVO
.
setAverage
(
100
);
vehicleUsageAnalysisVO
.
setPercentage
(
73
);
vehicleUsageAnalysisVO
.
setDays
(
350
);
vehicleUsageAnalysisVO
.
setLevel
(
2
);
vehicleUsageAnalysisVO
.
setTips
(
"重点观察"
);
List
<
VehicleUsageAnalysisPointVO
>
mileage
=
new
ArrayList
<>();
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-10"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-11"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-12"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-13"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-14"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-15"
,
55
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-16"
,
90
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-17"
,
80
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-18"
,
86
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-19"
,
47
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-20"
,
53
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-21"
,
82
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-22"
,
45
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-23"
,
90
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-24"
,
86
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-25"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-26"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-27"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-28"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-29"
,
0
));
mileage
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-30"
,
0
));
List
<
VehicleUsageAnalysisPointVO
>
daysOfVehicle
=
new
ArrayList
<>();
daysOfVehicle
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-16"
,
2
));
daysOfVehicle
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-23"
,
7
));
daysOfVehicle
.
add
(
new
VehicleUsageAnalysisPointVO
(
"2024-06-30"
,
1
));
vehicleUsageAnalysisVO
.
setMileage
(
mileage
);
vehicleUsageAnalysisVO
.
setDaysOfVehicle
(
daysOfVehicle
);
return
R
.
ok
().
data
(
vehicleUsageAnalysisVO
);
return
R
.
ok
().
data
(
vehicleUsageAnalysisVO
);
}
}
}
}
src/main/java/cn/com/glsx/admin/modules/entity/DeviceJourneyOverview.java
0 → 100644
View file @
592c092
package
cn
.
com
.
glsx
.
admin
.
modules
.
entity
;
import
com.glsx.plat.mybatis.base.BaseEntity
;
import
javax.persistence.Column
;
import
javax.persistence.Table
;
import
java.util.Date
;
@Table
(
name
=
"t_device_journey_overview"
)
public
class
DeviceJourneyOverview
extends
BaseEntity
{
/**
* 设备序列号
*/
private
String
sn
;
/**
* 车辆、设备关系id
*/
@Column
(
name
=
"vd_id"
)
private
Integer
vdId
;
/**
* 总行驶次数
*/
@Column
(
name
=
"total_journey_count"
)
private
Integer
totalJourneyCount
;
/**
* 总里程m
*/
private
Integer
distance
;
/**
* 创建时间|入库时间
*/
@Column
(
name
=
"created_date"
)
private
Date
createdDate
;
/**
* 更新时间
*/
@Column
(
name
=
"updated_date"
)
private
Date
updatedDate
;
/**
* 更新人用户id
*/
@Column
(
name
=
"updated_by"
)
private
Integer
updatedBy
;
private
static
final
long
serialVersionUID
=
1L
;
/**
* 获取设备序列号
*
* @return sn - 设备序列号
*/
public
String
getSn
()
{
return
sn
;
}
/**
* 设置设备序列号
*
* @param sn 设备序列号
*/
public
void
setSn
(
String
sn
)
{
this
.
sn
=
sn
==
null
?
null
:
sn
.
trim
();
}
/**
* 获取车辆、设备关系id
*
* @return vd_id - 车辆、设备关系id
*/
public
Integer
getVdId
()
{
return
vdId
;
}
/**
* 设置车辆、设备关系id
*
* @param vdId 车辆、设备关系id
*/
public
void
setVdId
(
Integer
vdId
)
{
this
.
vdId
=
vdId
;
}
/**
* 获取总行驶次数
*
* @return total_journey_count - 总行驶次数
*/
public
Integer
getTotalJourneyCount
()
{
return
totalJourneyCount
;
}
/**
* 设置总行驶次数
*
* @param totalJourneyCount 总行驶次数
*/
public
void
setTotalJourneyCount
(
Integer
totalJourneyCount
)
{
this
.
totalJourneyCount
=
totalJourneyCount
;
}
/**
* 获取总里程m
*
* @return distance - 总里程m
*/
public
Integer
getDistance
()
{
return
distance
;
}
/**
* 设置总里程m
*
* @param distance 总里程m
*/
public
void
setDistance
(
Integer
distance
)
{
this
.
distance
=
distance
;
}
/**
* 获取创建时间|入库时间
*
* @return created_date - 创建时间|入库时间
*/
public
Date
getCreatedDate
()
{
return
createdDate
;
}
/**
* 获取更新时间
*
* @return updated_date - 更新时间
*/
public
Date
getUpdatedDate
()
{
return
updatedDate
;
}
/**
* 设置更新人用户id
*
* @param updatedBy 更新人用户id
*/
public
void
setUpdatedBy
(
Integer
updatedBy
)
{
this
.
updatedBy
=
updatedBy
;
}
@Override
public
String
toString
()
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
getClass
().
getSimpleName
());
sb
.
append
(
" ["
);
sb
.
append
(
"Hash = "
).
append
(
hashCode
());
sb
.
append
(
", id="
).
append
(
id
);
sb
.
append
(
", sn="
).
append
(
sn
);
sb
.
append
(
", vdId="
).
append
(
vdId
);
sb
.
append
(
", totalJourneyCount="
).
append
(
totalJourneyCount
);
sb
.
append
(
", distance="
).
append
(
distance
);
sb
.
append
(
", delFlag="
).
append
(
getDelFlag
());
sb
.
append
(
", createdDate="
).
append
(
createdDate
);
sb
.
append
(
", createdBy="
).
append
(
getCreatedBy
());
sb
.
append
(
", updatedDate="
).
append
(
updatedDate
);
sb
.
append
(
", updatedBy="
).
append
(
updatedBy
);
sb
.
append
(
", serialVersionUID="
).
append
(
serialVersionUID
);
sb
.
append
(
"]"
);
return
sb
.
toString
();
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/admin/modules/mapper/DeviceJourneyMapper.java
View file @
592c092
...
@@ -3,7 +3,7 @@ package cn.com.glsx.admin.modules.mapper;
...
@@ -3,7 +3,7 @@ package cn.com.glsx.admin.modules.mapper;
import
cn.com.glsx.admin.modules.entity.DeviceJourney
;
import
cn.com.glsx.admin.modules.entity.DeviceJourney
;
import
cn.com.glsx.admin.modules.model.dto.UserBehaviorDayDTO
;
import
cn.com.glsx.admin.modules.model.dto.UserBehaviorDayDTO
;
import
cn.com.glsx.admin.modules.model.dto.UserBehaviorWeekDTO
;
import
cn.com.glsx.admin.modules.model.dto.UserBehaviorWeekDTO
;
import
cn.com.glsx.admin.modules.model.vo.
UserBehaviorInformation
VO
;
import
cn.com.glsx.admin.modules.model.vo.
VehicleUsageAnalysisPoint
VO
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
...
@@ -54,4 +54,20 @@ public interface DeviceJourneyMapper extends CommonBaseMapper<DeviceJourney> {
...
@@ -54,4 +54,20 @@ public interface DeviceJourneyMapper extends CommonBaseMapper<DeviceJourney> {
* @return 行程按照天统计信息
* @return 行程按照天统计信息
*/
*/
List
<
UserBehaviorDayDTO
>
statisticsDeviceJourneyWithDay
(
@Param
(
"sn"
)
String
sn
);
List
<
UserBehaviorDayDTO
>
statisticsDeviceJourneyWithDay
(
@Param
(
"sn"
)
String
sn
);
/**
* 通过设备的里程记录来统计车辆每周的使用天数
*
* @param sn
* @return
*/
List
<
VehicleUsageAnalysisPointVO
>
statisUsageBySnGroupByWeek
(
@Param
(
"sn"
)
String
sn
);
/**
* 统计设备每日的里程
*
* @param sn
* @return
*/
List
<
VehicleUsageAnalysisPointVO
>
statisMileageBySnGroupByDate
(
@Param
(
"sn"
)
String
sn
);
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/admin/modules/mapper/DeviceJourneyOverviewMapper.java
0 → 100644
View file @
592c092
package
cn
.
com
.
glsx
.
admin
.
modules
.
mapper
;
import
cn.com.glsx.admin.modules.entity.DeviceJourneyOverview
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
@Mapper
public
interface
DeviceJourneyOverviewMapper
extends
CommonBaseMapper
<
DeviceJourneyOverview
>
{
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleDeviceMapper.java
View file @
592c092
...
@@ -133,4 +133,29 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
...
@@ -133,4 +133,29 @@ public interface VehicleDeviceMapper extends CommonBaseMapper<VehicleDevice> {
* @return
* @return
*/
*/
List
<
DeviceInformationVO
>
getByVehicleId
(
@Param
(
"vehicleId"
)
Long
vehicleId
);
List
<
DeviceInformationVO
>
getByVehicleId
(
@Param
(
"vehicleId"
)
Long
vehicleId
);
/**
* 查找车辆最早安装的有线设备sn码
*
* @param vehicleId
* @return
*/
String
getEarliestInstallDeviceSn
(
@Param
(
"vehicleId"
)
Long
vehicleId
);
/**
* 根据userId列表查询所有车辆最早绑定的有线设备的sn码列表
*
* @param userIds
* @return
*/
List
<
String
>
getVehicleEarliestWireDeviceSnByUserIds
(
@Param
(
"userIds"
)
List
<
Long
>
userIds
);
/**
* 查找账号权限下所有车辆最早绑定的有线设备id列表
*
* @return
*/
@DataPerm
(
showSql
=
true
)
@DataPermShare
(
showSql
=
true
)
List
<
Long
>
getVehicleEarliestWireDeviceIdsByPermit
();
}
}
src/main/java/cn/com/glsx/admin/modules/mapper/VehicleMapper.java
View file @
592c092
...
@@ -17,6 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -17,6 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.Collection
;
import
java.util.Collection
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
@Mapper
@Mapper
...
@@ -403,4 +404,12 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
...
@@ -403,4 +404,12 @@ public interface VehicleMapper extends CommonBaseMapper<Vehicle> {
* @return 设备离线数据
* @return 设备离线数据
*/
*/
List
<
OfflineExport
>
findOfflineDataByVehicleId
(
@Param
(
"vehicleId"
)
Long
vehicleId
,
@Param
(
"offlineStartTime"
)
String
OfflineStartTime
);
List
<
OfflineExport
>
findOfflineDataByVehicleId
(
@Param
(
"vehicleId"
)
Long
vehicleId
,
@Param
(
"offlineStartTime"
)
String
OfflineStartTime
);
/**
* 获取车辆(设备)激活时间(因为车辆绑定设备的激活时间取值顺序是:工单完成时间、车辆入库时间)
*
* @param vehicleId
* @return
*/
Date
getActiveDate
(
@Param
(
"vehicleId"
)
Long
vehicleId
);
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/admin/modules/model/vo/VehicleUsageAnalysisVO.java
View file @
592c092
...
@@ -17,7 +17,7 @@ public class VehicleUsageAnalysisVO implements Serializable {
...
@@ -17,7 +17,7 @@ public class VehicleUsageAnalysisVO implements Serializable {
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
@ApiModelProperty
(
value
=
"日均里程,单位km"
)
@ApiModelProperty
(
value
=
"日均里程,单位km"
)
private
Integer
average
;
private
Double
average
;
@ApiModelProperty
(
value
=
"超过全平台百分之多少的车主,单位%"
)
@ApiModelProperty
(
value
=
"超过全平台百分之多少的车主,单位%"
)
private
Integer
percentage
;
private
Integer
percentage
;
...
...
src/main/java/cn/com/glsx/admin/modules/service/DeviceService.java
View file @
592c092
...
@@ -276,7 +276,6 @@ public class DeviceService {
...
@@ -276,7 +276,6 @@ public class DeviceService {
}
}
List
<
DeviceInformationVO
>
deviceStatusInfoVOList
=
vehicleDeviceMapper
.
getByVehicleId
(
vehicleId
);
List
<
DeviceInformationVO
>
deviceStatusInfoVOList
=
vehicleDeviceMapper
.
getByVehicleId
(
vehicleId
);
if
(
CollectionUtils
.
isEmpty
(
deviceStatusInfoVOList
))
{
if
(
CollectionUtils
.
isEmpty
(
deviceStatusInfoVOList
))
{
return
deviceStatusInfoVOList
;
return
deviceStatusInfoVOList
;
}
}
...
@@ -297,7 +296,6 @@ public class DeviceService {
...
@@ -297,7 +296,6 @@ public class DeviceService {
snLocationMap
=
finalPositioningList
.
stream
().
collect
(
Collectors
.
toMap
(
FinalPositioningExport:
:
getSn
,
Function
.
identity
(),
(
o
,
n
)
->
n
));
snLocationMap
=
finalPositioningList
.
stream
().
collect
(
Collectors
.
toMap
(
FinalPositioningExport:
:
getSn
,
Function
.
identity
(),
(
o
,
n
)
->
n
));
}
}
for
(
DeviceInformationVO
vo
:
deviceStatusInfoVOList
)
{
for
(
DeviceInformationVO
vo
:
deviceStatusInfoVOList
)
{
String
sn
=
vo
.
getSn
();
String
sn
=
vo
.
getSn
();
DeviceStatusModel
deviceStatusModel
=
deviceStatusMap
.
get
(
sn
);
DeviceStatusModel
deviceStatusModel
=
deviceStatusMap
.
get
(
sn
);
...
...
src/main/java/cn/com/glsx/admin/modules/service/RiskAssessmentService.java
View file @
592c092
...
@@ -26,6 +26,7 @@ import cn.com.glsx.devicemonitor.api.dto.request.ResidentRequest;
...
@@ -26,6 +26,7 @@ import cn.com.glsx.devicemonitor.api.dto.request.ResidentRequest;
import
cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest
;
import
cn.com.glsx.devicemonitor.api.dto.request.StayPointRequest
;
import
cn.com.glsx.devicemonitor.api.dto.response.*
;
import
cn.com.glsx.devicemonitor.api.dto.response.*
;
import
cn.com.glsx.devicemonitor.api.enums.DeviceStatusEnum
;
import
cn.com.glsx.devicemonitor.api.enums.DeviceStatusEnum
;
import
cn.hutool.core.date.DateUnit
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.glsx.plat.common.utils.StringUtils
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
...
@@ -36,6 +37,8 @@ import org.apache.commons.collections.CollectionUtils;
...
@@ -36,6 +37,8 @@ import org.apache.commons.collections.CollectionUtils;
import
org.apache.commons.lang.time.DateUtils
;
import
org.apache.commons.lang.time.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
tk.mybatis.mapper.entity.Example
;
import
tk.mybatis.mapper.weekend.WeekendSqls
;
import
java.text.ParseException
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
...
@@ -91,6 +94,9 @@ public class RiskAssessmentService {
...
@@ -91,6 +94,9 @@ public class RiskAssessmentService {
@Autowired
@Autowired
private
DeviceLocationMapper
deviceLocationMapper
;
private
DeviceLocationMapper
deviceLocationMapper
;
@Autowired
private
DeviceJourneyOverviewMapper
deviceJourneyOverviewMapper
;
/**
/**
* 获取停留点列表
* 获取停留点列表
*
*
...
@@ -774,4 +780,118 @@ public class RiskAssessmentService {
...
@@ -774,4 +780,118 @@ public class RiskAssessmentService {
)
)
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
}
}
public
VehicleUsageAnalysisVO
usageAnalysis
(
Long
vehicleId
)
{
VehicleUsageAnalysisVO
analysisVO
=
new
VehicleUsageAnalysisVO
();
//每日平均里程数
String
sn
=
vehicleDeviceMapper
.
getEarliestInstallDeviceSn
(
vehicleId
);
Example
overviewExample
=
new
Example
.
Builder
(
DeviceJourneyOverview
.
class
).
where
(
WeekendSqls
.<
DeviceJourneyOverview
>
custom
()
.
andEqualTo
(
DeviceJourneyOverview:
:
getSn
,
sn
).
andEqualTo
(
DeviceJourneyOverview:
:
getDelFlag
,
0
)).
build
();
DeviceJourneyOverview
overview
=
deviceJourneyOverviewMapper
.
selectOneByExample
(
overviewExample
);
//激活日期
Date
activeDate
=
vehicleMapper
.
getActiveDate
(
vehicleId
);
int
activeDays
=
(
int
)
cn
.
hutool
.
core
.
date
.
DateUtil
.
between
(
activeDate
,
DateUtils
.
addDays
(
new
Date
(),
-
1
),
DateUnit
.
DAY
);
Integer
distance
=
overview
.
getDistance
();
analysisVO
.
setAverage
((((
distance
*
1.00
))/
activeDays
)/
1000
);
//超过全平台百分比车主
List
<
Long
>
vehicleDeviceIds
=
vehicleDeviceMapper
.
getVehicleEarliestWireDeviceIdsByPermit
();
Example
vdExample
=
new
Example
.
Builder
(
VehicleDevice
.
class
).
where
(
WeekendSqls
.<
VehicleDevice
>
custom
()
.
andIn
(
VehicleDevice:
:
getId
,
vehicleDeviceIds
)).
build
();
List
<
VehicleDevice
>
devices
=
vehicleDeviceMapper
.
selectByExample
(
vdExample
);
List
<
String
>
snList
=
devices
.
stream
().
map
(
VehicleDevice:
:
getSn
).
collect
(
Collectors
.
toList
());
Example
allOverviewExample
=
new
Example
.
Builder
(
DeviceJourneyOverview
.
class
)
.
where
(
WeekendSqls
.<
DeviceJourneyOverview
>
custom
()
.
andIn
(
DeviceJourneyOverview:
:
getSn
,
snList
).
andEqualTo
(
DeviceJourneyOverview:
:
getDelFlag
,
0
))
.
orderByDesc
(
"distance"
).
build
();
List
<
DeviceJourneyOverview
>
overviews
=
deviceJourneyOverviewMapper
.
selectByExample
(
allOverviewExample
);
List
<
Integer
>
allDistance
=
overviews
.
stream
().
map
(
DeviceJourneyOverview:
:
getDistance
).
collect
(
Collectors
.
toList
());
// TODO 取小数点
int
percentage
=
((
allDistance
.
indexOf
(
distance
)
+
1
)
*
100
)
/
snList
.
size
();
analysisVO
.
setPercentage
(
100
-
percentage
);
//用车活跃度
if
(
percentage
<=
33
)
{
analysisVO
.
setLevel
(
3
);
analysisVO
.
setTips
(
"建议电呼,核实用车行为"
);
}
else
if
(
percentage
<=
66
)
{
analysisVO
.
setLevel
(
2
);
analysisVO
.
setTips
(
"重点观察"
);
}
else
{
analysisVO
.
setLevel
(
1
);
analysisVO
.
setTips
(
"继续观察"
);
}
//用车天数 最后定位日期-激活日期
Example
locationExample
=
new
Example
.
Builder
(
DeviceLocation
.
class
).
where
(
WeekendSqls
.<
DeviceLocation
>
custom
()
.
andEqualTo
(
DeviceLocation:
:
getSn
,
sn
)).
build
();
DeviceLocation
deviceLocation
=
deviceLocationMapper
.
selectOneByExample
(
locationExample
);
Date
locationDate
=
DateUtil
.
getMaxDate
(
deviceLocation
.
getLastGpsTime
(),
deviceLocation
.
getLastBsTime
());
int
daysOfUsage
=
(
int
)
cn
.
hutool
.
core
.
date
.
DateUtil
.
between
(
activeDate
,
locationDate
,
DateUnit
.
DAY
);
analysisVO
.
setDays
(
daysOfUsage
);
//日里程
List
<
VehicleUsageAnalysisPointVO
>
mileage
=
deviceJourneyMapper
.
statisMileageBySnGroupByDate
(
sn
);
String
firstDateStr
=
mileage
.
get
(
0
).
getX
();
String
lastDateStr
=
mileage
.
get
(
mileage
.
size
()
-
1
).
getX
();
if
(
DateUtil
.
isSameWeek
(
DateUtil
.
parseDateYmd
(
firstDateStr
),
DateUtil
.
parseDateYmd
(
lastDateStr
)))
{
mileage
=
fillBlankDate
(
mileage
,
DateUtil
.
getFirstDateOfWeek
(
DateUtil
.
parseDateYmd
(
firstDateStr
)),
DateUtil
.
getLastDateOfWeek
(
DateUtil
.
parseDateYmd
(
firstDateStr
)),
1
);
analysisVO
.
setMileage
(
mileage
);
return
analysisVO
;
}
else
{
mileage
=
fillBlankDate
(
mileage
,
DateUtil
.
getFirstDateOfWeek
(
DateUtil
.
parseDateYmd
(
firstDateStr
)),
DateUtil
.
getLastDateOfWeek
(
DateUtil
.
parseDateYmd
(
lastDateStr
)),
1
);
analysisVO
.
setMileage
(
mileage
);
}
// 周用车天数
List
<
VehicleUsageAnalysisPointVO
>
usage
=
deviceJourneyMapper
.
statisUsageBySnGroupByWeek
(
sn
);
String
firstWeek
=
usage
.
get
(
0
).
getX
();
String
lastWeek
=
usage
.
get
(
usage
.
size
()
-
1
).
getX
();
usage
=
fillBlankDate
(
mileage
,
DateUtil
.
parseDateYmd
(
firstWeek
),
DateUtil
.
parseDateYmd
(
lastWeek
),
7
);
analysisVO
.
setDaysOfVehicle
(
usage
);
return
analysisVO
;
}
/**
* 根据步长填充前后日期之间缺少的数据
*
* @param mileage
* @param startDate
* @param endDate
* @param factor
* @return
*/
private
List
<
VehicleUsageAnalysisPointVO
>
fillBlankDate
(
List
<
VehicleUsageAnalysisPointVO
>
mileage
,
Date
startDate
,
Date
endDate
,
int
factor
)
{
long
between
=
cn
.
hutool
.
core
.
date
.
DateUtil
.
between
(
startDate
,
endDate
,
DateUnit
.
DAY
);
//间隔大于12周则设置开始日期和节数日期间隔为12周,否则不调整
if
(
between
>
12
*
7
)
{
if
(
factor
==
1
)
{
startDate
=
DateUtil
.
addDays
(
endDate
,
-
12
*
7
+
1
);
}
else
if
(
factor
==
7
)
{
startDate
=
DateUtil
.
addDays
(
endDate
,
-
11
*
7
);
}
}
List
<
VehicleUsageAnalysisPointVO
>
resultList
=
new
ArrayList
<>();
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
for
(;
startDate
.
before
(
endDate
);)
{
map
.
put
(
DateUtil
.
formatDateYmd
(
startDate
),
0
);
startDate
=
DateUtils
.
addDays
(
startDate
,
factor
);
}
map
.
put
(
DateUtil
.
formatDateYmd
(
endDate
),
0
);
Map
<
String
,
Integer
>
mapTemp
=
mileage
.
stream
().
collect
(
Collectors
.
toMap
(
VehicleUsageAnalysisPointVO:
:
getX
,
VehicleUsageAnalysisPointVO:
:
getY
));
map
.
forEach
((
k
,
v
)
->
{
if
(
mapTemp
.
containsKey
(
k
))
{
resultList
.
add
(
new
VehicleUsageAnalysisPointVO
(
k
,
mapTemp
.
get
(
k
)));
}
else
{
resultList
.
add
(
new
VehicleUsageAnalysisPointVO
(
k
,
v
));
}
});
resultList
.
sort
(
Comparator
.
comparing
(
o
->
DateUtil
.
parseDateYmd
(
o
.
getX
())));
return
resultList
;
}
}
}
src/main/java/cn/com/glsx/admin/modules/utils/DateUtil.java
View file @
592c092
...
@@ -1585,6 +1585,70 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
...
@@ -1585,6 +1585,70 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
return
weekCount
;
// 获取该年共有多少周
return
weekCount
;
// 获取该年共有多少周
}
}
/**
* 比较返回最大的日期
*
* @param date1
* @param date2
* @return
*/
public
static
Date
getMaxDate
(
Date
date1
,
Date
date2
)
{
if
(
date1
==
null
)
{
return
date2
;
}
if
(
date2
==
null
)
{
return
date1
;
}
return
date1
.
after
(
date2
)
?
date1
:
date2
;
}
/**
* 判断两个日期是否是在同一周内
*
* @param date1
* @param date2
* @return
*/
public
static
boolean
isSameWeek
(
Date
date1
,
Date
date2
)
{
if
(
date1
==
null
||
date2
==
null
)
{
throw
new
IllegalArgumentException
(
"Both dates must not be null"
);
}
Calendar
c1
=
Calendar
.
getInstance
();
c1
.
setTime
(
date1
);
int
week1
=
c1
.
get
(
Calendar
.
WEEK_OF_YEAR
);
int
year1
=
c1
.
get
(
Calendar
.
YEAR
);
Calendar
c2
=
Calendar
.
getInstance
();
c2
.
setTime
(
date2
);
int
week2
=
c2
.
get
(
Calendar
.
WEEK_OF_YEAR
);
int
year2
=
c2
.
get
(
Calendar
.
YEAR
);
return
year1
==
year2
&&
week1
==
week2
;
}
public
static
Date
getFirstDateOfWeek
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
// 将周的开始设置为周一
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
// 获取周一日期
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
Calendar
.
MONDAY
);
return
calendar
.
getTime
();
}
public
static
Date
getLastDateOfWeek
(
Date
date
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
date
);
// 将周的开始设置为周一
calendar
.
setFirstDayOfWeek
(
Calendar
.
MONDAY
);
calendar
.
set
(
Calendar
.
DAY_OF_WEEK
,
Calendar
.
MONDAY
);
calendar
.
add
(
Calendar
.
DAY_OF_MONTH
,
6
);
return
calendar
.
getTime
();
}
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
System
.
out
.
println
(
getMaxDayOfCurrentMonth
());
System
.
out
.
println
(
getMaxDayOfCurrentMonth
());
...
...
src/main/resources/mapper/DeviceJourneyMapper.xml
View file @
592c092
...
@@ -78,4 +78,20 @@
...
@@ -78,4 +78,20 @@
GROUP BY dayInt
GROUP BY dayInt
ORDER BY dayInt
ORDER BY dayInt
</select>
</select>
<select
id=
"statisUsageBySnGroupByWeek"
resultType=
"cn.com.glsx.admin.modules.model.vo.VehicleUsageAnalysisPointVO"
>
SELECT DATE_FORMAT(DATE_ADD(begin_time, INTERVAL (6-WEEKDAY(begin_time)) DAY), '%Y-%m-%d') AS x, count(distinct date(begin_time)) AS y
FROM t_device_journey
where sn = #{sn} and del_flag = 0
group by x
order by x
</select>
<select
id=
"statisMileageBySnGroupByDate"
resultType=
"cn.com.glsx.admin.modules.model.vo.VehicleUsageAnalysisPointVO"
>
SELECT DATE_FORMAT(begin_time, '%Y-%m-%d') AS x, sum(mileage) AS y
FROM t_device_journey
WHERE sn = #{sn} and del_flag = 0
GROUP BY x
ORDER BY x
</select>
</mapper>
</mapper>
\ No newline at end of file
\ No newline at end of file
src/main/resources/mapper/DeviceJourneyOverviewMapper.xml
0 → 100644
View file @
592c092
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"cn.com.glsx.admin.modules.mapper.DeviceJourneyOverviewMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"cn.com.glsx.admin.modules.entity.DeviceJourneyOverview"
>
<!--
WARNING - @mbg.generated
-->
<id
column=
"id"
jdbcType=
"INTEGER"
property=
"id"
/>
<result
column=
"sn"
jdbcType=
"VARCHAR"
property=
"sn"
/>
<result
column=
"vd_id"
jdbcType=
"INTEGER"
property=
"vdId"
/>
<result
column=
"total_journey_count"
jdbcType=
"INTEGER"
property=
"totalJourneyCount"
/>
<result
column=
"distance"
jdbcType=
"INTEGER"
property=
"distance"
/>
<result
column=
"del_flag"
jdbcType=
"TINYINT"
property=
"delFlag"
/>
<result
column=
"created_date"
jdbcType=
"TIMESTAMP"
property=
"createdDate"
/>
<result
column=
"created_by"
jdbcType=
"INTEGER"
property=
"createdBy"
/>
<result
column=
"updated_date"
jdbcType=
"TIMESTAMP"
property=
"updatedDate"
/>
<result
column=
"updated_by"
jdbcType=
"INTEGER"
property=
"updatedBy"
/>
</resultMap>
<sql
id=
"Base_Column_List"
>
<!--
WARNING - @mbg.generated
-->
id, sn, vd_id, total_journey_count, distance, del_flag, created_date, created_by,
updated_date, updated_by
</sql>
</mapper>
\ No newline at end of file
\ No newline at end of file
src/main/resources/mapper/VehicleDeviceMapper.xml
View file @
592c092
...
@@ -352,4 +352,30 @@
...
@@ -352,4 +352,30 @@
and tvd.del_flag = 0
and tvd.del_flag = 0
order by tvd.wire_type desc, tvd.created_date
order by tvd.wire_type desc, tvd.created_date
</select>
</select>
<select
id=
"getEarliestInstallDeviceSn"
resultType=
"java.lang.String"
>
select tvd.sn
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.id = #{vehicleId} and tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1 and tvd.wire_type = 1
order by tvd.id asc limit 1
</select>
<select
id=
"getVehicleEarliestWireDeviceSnByUserIds"
resultType=
"java.lang.String"
>
SELECT t1.sn FROM neshield.t_vehicle_device t1
inner join (
SELECT min(id) id, vehicle_id FROM neshield.t_vehicle_device
where wire_type = 1 and bind_status = 1 and del_flag = 0
and created_by in
<foreach
collection=
"userIds"
item=
"userId"
open=
"("
close=
")"
separator=
","
>
#{userId}
</foreach>
group by vehicle_id
) t2 on t2.id = t1.id
</select>
<select
id=
"getVehicleEarliestWireDeviceIdsByPermit"
resultType=
"java.lang.Long"
>
select min(tv.id)
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1 and tvd.wire_type = 1
group by tv.id
</select>
</mapper>
</mapper>
\ No newline at end of file
\ No newline at end of file
src/main/resources/mapper/VehicleMapper.xml
View file @
592c092
...
@@ -1582,4 +1582,12 @@
...
@@ -1582,4 +1582,12 @@
</if>
</if>
order by vdId desc
order by vdId desc
</select>
</select>
<select
id=
"getActiveDate"
resultType=
"java.util.Date"
>
select
IFNULL(tw.finished_time, tv.created_date)
from t_vehicle tv
left join t_workorder tw on tw.id = tv.workorder_id
where tv.id = #{vehicleId}
and tv.del_flag = 0
</select>
</mapper>
</mapper>
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment