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 34d47fe1
authored
Apr 15, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改里程计算方法
1 parent
822c4f34
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
19 deletions
src/main/java/cn/com/glsx/stdinterface/modules/mapper/DeviceJourneyOverviewMapper.java
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
src/main/resources/mapper/DeviceJourneyOverviewMapper.xml
src/main/java/cn/com/glsx/stdinterface/modules/mapper/DeviceJourneyOverviewMapper.java
View file @
34d47fe
...
@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
...
@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
import
cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview
;
import
cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview
;
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
;
/**
/**
* 新e盾|里程表总览
* 新e盾|里程表总览
...
@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
...
@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
public
interface
DeviceJourneyOverviewMapper
extends
CommonBaseMapper
<
DeviceJourneyOverview
>
{
public
interface
DeviceJourneyOverviewMapper
extends
CommonBaseMapper
<
DeviceJourneyOverview
>
{
/**
/**
*
* 根据sn和vdId获取唯一 的 设备 统计里程
* 如果不存在就新增。 如果存在则累加总行程 总次数
* @param sn 设备号
* @param deviceJourneyOverview 传入新的行程值
* @param vdId 关联id
* @return 统计里程
*/
*/
void
insertOrSumDistanceAndCount
(
DeviceJourneyOverview
deviceJourneyOverview
);
DeviceJourneyOverview
selectBySnAndVdId
(
@Param
(
"sn"
)
String
sn
,
@Param
(
"vdId"
)
Long
vdId
);
}
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
View file @
34d47fe
...
@@ -61,18 +61,30 @@ public class JourneyService {
...
@@ -61,18 +61,30 @@ public class JourneyService {
Vehicle
vehicle
=
getVehicleBySn
(
deviceJourneyDTO
.
getSn
());
Vehicle
vehicle
=
getVehicleBySn
(
deviceJourneyDTO
.
getSn
());
Long
createdBy
=
Optional
.
ofNullable
(
vehicle
).
map
(
Vehicle:
:
getCreatedBy
).
orElse
(
null
);
Long
createdBy
=
Optional
.
ofNullable
(
vehicle
).
map
(
Vehicle:
:
getCreatedBy
).
orElse
(
null
);
Long
updatedBy
=
Optional
.
ofNullable
(
vehicle
).
map
(
Vehicle:
:
getUpdatedBy
).
orElse
(
null
);
Long
updatedBy
=
Optional
.
ofNullable
(
vehicle
).
map
(
Vehicle:
:
getUpdatedBy
).
orElse
(
null
);
if
(
Objects
.
isNull
(
vehicle
))
{
log
.
warn
(
"该设备没有绑定车辆"
+
deviceJourneyDTO
.
getSn
());
}
//从关联表从获取关联id
//从关联表从获取关联id
Long
v
n
Id
=
vehicleService
.
getVdId
(
deviceJourneyDTO
.
getSn
());
Long
v
d
Id
=
vehicleService
.
getVdId
(
deviceJourneyDTO
.
getSn
());
//行程信息入库
//行程信息入库
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
,
v
n
Id
,
createdBy
,
updatedBy
);
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
,
v
d
Id
,
createdBy
,
updatedBy
);
deviceJourneyMapper
.
insert
(
deviceJourney
);
deviceJourneyMapper
.
insert
(
deviceJourney
);
//如果行程数据的设备未关联车辆 不计入从次数和总信息
if
(
Objects
.
isNull
(
vdId
))
{
log
.
warn
(
"该设备没有绑定车辆"
+
deviceJourneyDTO
.
getSn
());
return
;
}
//更新总行程次数 总里程
//更新总行程次数 总里程
DeviceJourneyOverview
overview
=
buildOverviewWitheJourney
(
deviceJourneyDTO
,
vnId
,
createdBy
,
updatedBy
);
DeviceJourneyOverview
overviewDO
=
buildOverviewWitheJourney
(
deviceJourneyDTO
,
vdId
,
createdBy
,
updatedBy
);
deviceJourneyOverviewMapper
.
insertOrSumDistanceAndCount
(
overview
);
DeviceJourneyOverview
overview
=
deviceJourneyOverviewMapper
.
selectBySnAndVdId
(
deviceJourneyDTO
.
getSn
(),
vdId
);
if
(
Objects
.
isNull
(
overview
))
{
//本设备的第一条里程数据
deviceJourneyOverviewMapper
.
insert
(
overviewDO
);
return
;
}
overview
.
setDistance
(
overview
.
getDistance
()
+
overviewDO
.
getDistance
());
overview
.
setDistance
(
overview
.
getTotalJourneyCount
()
+
1
);
overview
.
setUpdatedDate
(
new
Date
());
deviceJourneyOverviewMapper
.
updateByPrimaryKeySelective
(
overview
);
}
}
...
...
src/main/resources/mapper/DeviceJourneyOverviewMapper.xml
View file @
34d47fe
...
@@ -24,13 +24,17 @@
...
@@ -24,13 +24,17 @@
updated_date, updated_by
updated_date, updated_by
</sql>
</sql>
<insert
id=
"insertOrSumDistanceAndCount"
parameterType=
"cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview"
>
<select
id=
"selectBySnAndVdId"
resultMap=
"BaseResultMap"
>
insert into t_device_journey_overview (sn, vd_id, total_journey_count, distance, created_date, created_by, updated_date, updated_by)
select
values (#{sn}, #{vdId}, #{totalJourneyCount},#{distance}, #{createdDate},#{createdBy}, #{updatedDate}, #{updatedBy})
<include
refid=
"Base_Column_List"
/>
ON DUPLICATE key
from t_device_journey_overview
update
<where>
total_journey_count =total_journey_count + #{totalJourneyCount},
and sn = #{sn}
distance = distance + #{distance}
and vd_id = #{vdId}
</insert>
</where>
limit 1
</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