Commit 34d47fe1 by 向延琳

修改里程计算方法

1 parent 822c4f34
......@@ -3,6 +3,7 @@ package cn.com.glsx.stdinterface.modules.mapper;
import cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview;
import com.glsx.plat.mybatis.mapper.CommonBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 新e盾|里程表总览
......@@ -14,9 +15,10 @@ import org.apache.ibatis.annotations.Mapper;
public interface DeviceJourneyOverviewMapper extends CommonBaseMapper<DeviceJourneyOverview> {
/**
*
* 如果不存在就新增。 如果存在则累加总行程 总次数
* @param deviceJourneyOverview 传入新的行程值
* 根据sn和vdId获取唯一 的 设备 统计里程
* @param sn 设备号
* @param vdId 关联id
* @return 统计里程
*/
void insertOrSumDistanceAndCount(DeviceJourneyOverview deviceJourneyOverview);
DeviceJourneyOverview selectBySnAndVdId(@Param("sn") String sn, @Param("vdId") Long vdId);
}
\ No newline at end of file
......@@ -61,18 +61,30 @@ public class JourneyService {
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if(Objects.isNull(vehicle)) {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
}
//从关联表从获取关联id
Long vnId = vehicleService.getVdId(deviceJourneyDTO.getSn());
Long vdId = vehicleService.getVdId(deviceJourneyDTO.getSn());
//行程信息入库
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vnId, createdBy, updatedBy);
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vdId, createdBy, updatedBy);
deviceJourneyMapper.insert(deviceJourney);
//如果行程数据的设备未关联车辆 不计入从次数和总信息
if(Objects.isNull(vdId)) {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
return;
}
//更新总行程次数 总里程
DeviceJourneyOverview overview = buildOverviewWitheJourney(deviceJourneyDTO, vnId, createdBy, updatedBy);
deviceJourneyOverviewMapper.insertOrSumDistanceAndCount(overview);
DeviceJourneyOverview overviewDO = buildOverviewWitheJourney(deviceJourneyDTO, vdId, createdBy, updatedBy);
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);
}
......
......@@ -24,13 +24,17 @@
updated_date, updated_by
</sql>
<insert id="insertOrSumDistanceAndCount" parameterType="cn.com.glsx.stdinterface.modules.entity.DeviceJourneyOverview">
insert into t_device_journey_overview (sn, vd_id, total_journey_count, distance, created_date, created_by, updated_date, updated_by)
values (#{sn}, #{vdId}, #{totalJourneyCount},#{distance}, #{createdDate},#{createdBy}, #{updatedDate}, #{updatedBy})
ON DUPLICATE key
update
total_journey_count =total_journey_count + #{totalJourneyCount},
distance = distance + #{distance}
</insert>
<select id="selectBySnAndVdId" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from t_device_journey_overview
<where>
and sn = #{sn}
and vd_id = #{vdId}
</where>
limit 1
</select>
</mapper>
\ 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!