Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
eshiled-new
/
ne-shield-standard-interfaces
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d6bf9868
authored
Apr 08, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
设置关联id
1 parent
bea69a42
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
8 deletions
src/main/java/cn/com/glsx/stdinterface/modules/entity/DeviceJourney.java
src/main/java/cn/com/glsx/stdinterface/modules/entity/DeviceJourneyOverview.java
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
src/main/java/cn/com/glsx/stdinterface/modules/entity/DeviceJourney.java
View file @
d6bf986
...
...
@@ -20,7 +20,7 @@ public class DeviceJourney extends BaseEntity{
* 车辆、设备关系id
*/
@Column
(
name
=
"vd_id"
)
private
Integer
vdId
;
private
Long
vdId
;
/**
* 里程开始时间
...
...
src/main/java/cn/com/glsx/stdinterface/modules/entity/DeviceJourneyOverview.java
View file @
d6bf986
...
...
@@ -19,7 +19,7 @@ public class DeviceJourneyOverview extends BaseEntity {
* 车辆、设备关系id
*/
@Column
(
name
=
"vd_id"
)
private
Integer
vdId
;
private
Long
vdId
;
/**
* 总行驶次数
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
View file @
d6bf986
...
...
@@ -4,10 +4,13 @@ import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO;
import
cn.com.glsx.stdinterface.modules.entity.DeviceJourney
;
import
cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.entity.VehicleDevice
;
import
cn.com.glsx.stdinterface.modules.mapper.DeviceJourneyMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.DeviceJourneyOverviewMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -34,6 +37,9 @@ public class JourneyService {
@Resource
private
VehicleMapper
vehicleMapper
;
@Resource
private
VehicleDeviceMapper
vehicleDeviceMapper
;
/**
* 行程数据新增
*/
...
...
@@ -42,6 +48,7 @@ public class JourneyService {
if
(
Objects
.
isNull
(
deviceJourneyDTO
))
{
return
;
}
//从车辆信息中获取创建人信息
Vehicle
vehicle
=
getVehicleBySn
(
deviceJourneyDTO
.
getSn
());
if
(
Objects
.
isNull
(
vehicle
))
{
log
.
warn
(
"该设备没有绑定车辆"
+
deviceJourneyDTO
.
getSn
());
...
...
@@ -49,18 +56,26 @@ public class JourneyService {
}
deviceJourneyDTO
.
setCreatedBy
(
vehicle
.
getCreatedBy
());
deviceJourneyDTO
.
setUpdatedBy
(
vehicle
.
getUpdatedBy
());
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
);
//从关联表从获取关联id
VehicleDevice
vehicleDevice
=
vehicleDeviceMapper
.
getVdIdbySn
(
deviceJourneyDTO
.
getSn
());
Long
vnId
=
null
;
if
(
Objects
.
nonNull
(
vehicleDevice
))
{
vnId
=
vehicleDevice
.
getId
();
}
//行程信息入库
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
,
vnId
);
deviceJourneyMapper
.
insert
(
deviceJourney
);
//更新总行程次数 总里程
DeviceJourneyOverview
overview
=
buildOverviewWitheJourney
(
deviceJourneyDTO
);
DeviceJourneyOverview
overview
=
buildOverviewWitheJourney
(
deviceJourneyDTO
,
vnId
);
deviceJourneyOverviewMapper
.
insertOrSumDistanceAndCount
(
overview
);
}
public
DeviceJourneyOverview
buildOverviewWitheJourney
(
DeviceJourneyDTO
deviceJourneyDTO
)
{
public
DeviceJourneyOverview
buildOverviewWitheJourney
(
DeviceJourneyDTO
deviceJourneyDTO
,
Long
vnId
)
{
DeviceJourneyOverview
deviceJourneyOverview
=
new
DeviceJourneyOverview
();
deviceJourneyOverview
.
setSn
(
deviceJourneyDTO
.
getSn
());
deviceJourneyOverview
.
setVdId
(
deviceJourneyDTO
.
getVdId
()
);
deviceJourneyOverview
.
setVdId
(
vnId
);
//每条数据加一
deviceJourneyOverview
.
setTotalJourneyCount
(
1
);
deviceJourneyOverview
.
setDistance
(
deviceJourneyDTO
.
getMileage
());
...
...
@@ -76,10 +91,11 @@ public class JourneyService {
/**
* 转换为数据库对象
*/
public
DeviceJourney
convertTo
(
DeviceJourneyDTO
deviceJourneyDTO
)
{
public
DeviceJourney
convertTo
(
DeviceJourneyDTO
deviceJourneyDTO
,
Long
vnId
)
{
DeviceJourney
deviceJourney
=
new
DeviceJourney
();
deviceJourney
.
setSn
(
deviceJourneyDTO
.
getSn
());
deviceJourney
.
setVdId
(
deviceJourneyDTO
.
getVdId
());
//获取关联id
deviceJourney
.
setVdId
(
vnId
);
deviceJourney
.
setBeginTime
(
deviceJourneyDTO
.
getBeginTime
());
deviceJourney
.
setEndTime
(
deviceJourneyDTO
.
getEndTime
());
deviceJourney
.
setBeginAddress
(
deviceJourneyDTO
.
getBeginAddress
());
...
...
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