Commit 38056c38 by 向延琳

保存电量信息

1 parent 6a742402
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();
}
}
...@@ -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 = "/saveDeviceJourney") @PostMapping(value = "/save")
@Override @Override
public R saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) { public R saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) {
journeyService.saveDeviceJourney(deviceJourneyDTO); journeyService.saveDeviceJourney(deviceJourneyDTO);
......
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
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
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;
}
}
...@@ -38,7 +38,7 @@ public class JourneyService { ...@@ -38,7 +38,7 @@ public class JourneyService {
private VehicleMapper vehicleMapper; private VehicleMapper vehicleMapper;
@Resource @Resource
private VehicleDeviceMapper vehicleDeviceMapper; private VehicleService 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());
......
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;
}
} }
<?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
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!