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 38056c38
authored
Apr 12, 2022
by
向延琳
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
保存电量信息
1 parent
6a742402
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
217 additions
and
7 deletions
src/main/java/cn/com/glsx/stdinterface/modules/controller/BatteryController.java
src/main/java/cn/com/glsx/stdinterface/modules/controller/JourneyController.java
src/main/java/cn/com/glsx/stdinterface/modules/entity/DevicePower.java
src/main/java/cn/com/glsx/stdinterface/modules/mapper/DevicePowerMapper.java
src/main/java/cn/com/glsx/stdinterface/modules/service/BatteryService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
src/main/java/cn/com/glsx/stdinterface/modules/service/VehicleService.java
src/main/resources/mapper/DevicePowerMapper.xml
src/main/java/cn/com/glsx/stdinterface/modules/controller/BatteryController.java
0 → 100644
View file @
38056c3
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
controller
;
import
cn.com.glsx.stdinterface.api.BatteryClient
;
import
cn.com.glsx.stdinterface.dto.DevicePowerDTO
;
import
cn.com.glsx.stdinterface.modules.service.BatteryService
;
import
com.glsx.plat.core.web.R
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
/**
* @author xiangyanlin
* @date 2022/4/12
*/
@RestController
@RequestMapping
(
"/battery"
)
public
class
BatteryController
implements
BatteryClient
{
@Resource
private
BatteryService
batteryService
;
@PostMapping
(
"/save"
)
@Override
public
R
saveBatteryInfo
(
DevicePowerDTO
devicePowerDTO
)
{
batteryService
.
saveBatteryInfo
(
devicePowerDTO
);
return
R
.
ok
();
}
}
src/main/java/cn/com/glsx/stdinterface/modules/controller/JourneyController.java
View file @
38056c3
...
@@ -25,7 +25,7 @@ public class JourneyController implements JourneyClient {
...
@@ -25,7 +25,7 @@ public class JourneyController implements JourneyClient {
@Resource
@Resource
private
JourneyService
journeyService
;
private
JourneyService
journeyService
;
@PostMapping
(
value
=
"/save
DeviceJourney
"
)
@PostMapping
(
value
=
"/save"
)
@Override
@Override
public
R
saveDeviceJourney
(
DeviceJourneyDTO
deviceJourneyDTO
)
{
public
R
saveDeviceJourney
(
DeviceJourneyDTO
deviceJourneyDTO
)
{
journeyService
.
saveDeviceJourney
(
deviceJourneyDTO
);
journeyService
.
saveDeviceJourney
(
deviceJourneyDTO
);
...
...
src/main/java/cn/com/glsx/stdinterface/modules/entity/DevicePower.java
0 → 100644
View file @
38056c3
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
entity
;
import
com.glsx.plat.mybatis.base.BaseEntity
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.Table
;
import
java.util.Date
;
@Data
@Table
(
name
=
"t_device_power"
)
public
class
DevicePower
extends
BaseEntity
{
/**
* 设备序列号
*/
private
String
sn
;
/**
* 车辆、设备关系id
*/
@Column
(
name
=
"vd_id"
)
private
Long
vdId
;
/**
* 电量上传时间
*/
@Column
(
name
=
"alarm_time"
)
private
Date
alarmTime
;
/**
* 设备剩余电量
*/
private
Integer
soc
;
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/stdinterface/modules/mapper/DevicePowerMapper.java
0 → 100644
View file @
38056c3
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
mapper
;
import
cn.com.glsx.stdinterface.modules.entity.DevicePower
;
import
com.glsx.plat.mybatis.mapper.CommonBaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
@Mapper
public
interface
DevicePowerMapper
extends
CommonBaseMapper
<
DevicePower
>
{
/**
* 根据设备号获取
* @param sn 设备号
* @return 电量信息
*/
DevicePower
selectBySn
(
String
sn
);
}
\ No newline at end of file
\ No newline at end of file
src/main/java/cn/com/glsx/stdinterface/modules/service/BatteryService.java
0 → 100644
View file @
38056c3
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.stdinterface.dto.DevicePowerDTO
;
import
cn.com.glsx.stdinterface.modules.entity.DevicePower
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.mapper.DevicePowerMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.util.Objects
;
/**
* 电量
* @author xiangyanlin
* @date 2022/4/12
*/
@Slf4j
@Service
public
class
BatteryService
{
@Resource
private
DevicePowerMapper
devicePowerMapper
;
@Resource
private
VehicleMapper
vehicleMapper
;
@Resource
private
VehicleService
vehicleService
;
/**
* 保存电量信息
*/
public
void
saveBatteryInfo
(
DevicePowerDTO
devicePowerDTO
)
{
//从车辆信息中获取创建人信息
Vehicle
vehicle
=
vehicleMapper
.
getVehicleBySn
(
devicePowerDTO
.
getSn
());
if
(
Objects
.
isNull
(
vehicle
))
{
log
.
warn
(
"该设备没有绑定车辆"
+
devicePowerDTO
.
getSn
());
return
;
}
//从关联表从获取关联id
Long
vnId
=
vehicleService
.
getVdId
(
devicePowerDTO
.
getSn
());
DevicePower
devicePower
=
convert
(
devicePowerDTO
,
vehicle
.
getCreatedBy
(),
vehicle
.
getUpdatedBy
(),
vnId
);
DevicePower
devicePowerOld
=
devicePowerMapper
.
selectBySn
(
devicePowerDTO
.
getSn
());
if
(
Objects
.
isNull
(
devicePowerOld
))
{
devicePowerMapper
.
insert
(
devicePower
);
return
;
}
devicePowerMapper
.
updateByPrimaryKeySelective
(
devicePower
);
}
public
DevicePower
convert
(
DevicePowerDTO
devicePowerDTO
,
Long
createBy
,
Long
updateBy
,
Long
vnId
)
{
DevicePower
devicePower
=
new
DevicePower
();
devicePower
.
setSn
(
devicePowerDTO
.
getSn
());
devicePower
.
setVdId
(
vnId
);
devicePower
.
setAlarmTime
(
devicePowerDTO
.
getAlarmTime
());
devicePower
.
setSoc
(
devicePowerDTO
.
getSoc
());
devicePower
.
setId
(
devicePowerDTO
.
getId
());
devicePower
.
setCreatedBy
(
createBy
);
devicePower
.
setUpdatedBy
(
updateBy
);
devicePower
.
setCreatedDate
(
devicePowerDTO
.
getCreatedDate
());
devicePower
.
setUpdatedDate
(
devicePowerDTO
.
getUpdatedDate
());
return
devicePower
;
}
}
src/main/java/cn/com/glsx/stdinterface/modules/service/JourneyService.java
View file @
38056c3
...
@@ -38,7 +38,7 @@ public class JourneyService {
...
@@ -38,7 +38,7 @@ public class JourneyService {
private
VehicleMapper
vehicleMapper
;
private
VehicleMapper
vehicleMapper
;
@Resource
@Resource
private
Vehicle
DeviceMapper
vehicleDeviceMapper
;
private
Vehicle
Service
vehicleService
;
/**
/**
* 行程数据新增
* 行程数据新增
...
@@ -64,11 +64,7 @@ public class JourneyService {
...
@@ -64,11 +64,7 @@ public class JourneyService {
deviceJourneyDTO
.
setUpdatedBy
(
vehicle
.
getUpdatedBy
());
deviceJourneyDTO
.
setUpdatedBy
(
vehicle
.
getUpdatedBy
());
//从关联表从获取关联id
//从关联表从获取关联id
VehicleDevice
vehicleDevice
=
vehicleDeviceMapper
.
getVdIdbySn
(
deviceJourneyDTO
.
getSn
());
Long
vnId
=
vehicleService
.
getVdId
(
deviceJourneyDTO
.
getSn
());
Long
vnId
=
null
;
if
(
Objects
.
nonNull
(
vehicleDevice
))
{
vnId
=
vehicleDevice
.
getId
();
}
//行程信息入库
//行程信息入库
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
,
vnId
);
DeviceJourney
deviceJourney
=
convertTo
(
deviceJourneyDTO
,
vnId
);
deviceJourneyMapper
.
insert
(
deviceJourney
);
deviceJourneyMapper
.
insert
(
deviceJourney
);
...
@@ -78,6 +74,8 @@ public class JourneyService {
...
@@ -78,6 +74,8 @@ public class JourneyService {
deviceJourneyOverviewMapper
.
insertOrSumDistanceAndCount
(
overview
);
deviceJourneyOverviewMapper
.
insertOrSumDistanceAndCount
(
overview
);
}
}
public
DeviceJourneyOverview
buildOverviewWitheJourney
(
DeviceJourneyDTO
deviceJourneyDTO
,
Long
vnId
)
{
public
DeviceJourneyOverview
buildOverviewWitheJourney
(
DeviceJourneyDTO
deviceJourneyDTO
,
Long
vnId
)
{
DeviceJourneyOverview
deviceJourneyOverview
=
new
DeviceJourneyOverview
();
DeviceJourneyOverview
deviceJourneyOverview
=
new
DeviceJourneyOverview
();
deviceJourneyOverview
.
setSn
(
deviceJourneyDTO
.
getSn
());
deviceJourneyOverview
.
setSn
(
deviceJourneyDTO
.
getSn
());
...
...
src/main/java/cn/com/glsx/stdinterface/modules/service/VehicleService.java
View file @
38056c3
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
package
cn
.
com
.
glsx
.
stdinterface
.
modules
.
service
;
import
cn.com.glsx.stdinterface.dto.DeviceJourneyDTO
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.entity.Vehicle
;
import
cn.com.glsx.stdinterface.modules.entity.VehicleDevice
;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrder
;
import
cn.com.glsx.stdinterface.modules.entity.WorkOrder
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleDeviceMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
cn.com.glsx.stdinterface.modules.mapper.VehicleMapper
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
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
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
/**
/**
* 车辆服务
* 车辆服务
...
@@ -19,8 +24,20 @@ public class VehicleService {
...
@@ -19,8 +24,20 @@ public class VehicleService {
@Autowired
@Autowired
private
VehicleMapper
vehicleMapper
;
private
VehicleMapper
vehicleMapper
;
@Autowired
private
VehicleDeviceMapper
vehicleDeviceMapper
;
public
Vehicle
getVehicleInfoBySn
(
String
sn
)
{
public
Vehicle
getVehicleInfoBySn
(
String
sn
)
{
Vehicle
vehicle
=
vehicleMapper
.
getVehicleBySn
(
sn
);
Vehicle
vehicle
=
vehicleMapper
.
getVehicleBySn
(
sn
);
return
vehicle
;
return
vehicle
;
}
}
public
Long
getVdId
(
String
sn
)
{
VehicleDevice
vehicleDevice
=
vehicleDeviceMapper
.
getVdIdbySn
(
sn
);
Long
vnId
=
null
;
if
(
Objects
.
nonNull
(
vehicleDevice
))
{
vnId
=
vehicleDevice
.
getId
();
}
return
vnId
;
}
}
}
src/main/resources/mapper/DevicePowerMapper.xml
0 → 100644
View file @
38056c3
<?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.stdinterface.modules.mapper.DevicePowerMapper"
>
<resultMap
id=
"BaseResultMap"
type=
"cn.com.glsx.stdinterface.modules.entity.DevicePower"
>
<!--
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=
"alarm_time"
jdbcType=
"TIMESTAMP"
property=
"alarmTime"
/>
<result
column=
"soc"
jdbcType=
"INTEGER"
property=
"soc"
/>
<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, alarm_time, soc, del_flag, created_date, created_by, updated_date,
updated_by
</sql>
<select
id=
"selectBySn"
resultMap=
"BaseResultMap"
>
select
<include
refid=
"Base_Column_List"
/>
from t_device_power
<where>
and sn = #{sn}
and del_flag = 0;
</where>
limit 1
</select>
</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