Commit b80116a2 by 向延琳

修改参数处理和错误的sql

1 parent 6118cc46
......@@ -5,6 +5,7 @@ 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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -23,7 +24,7 @@ public class BatteryController implements BatteryClient {
@PostMapping("/save")
@Override
public R saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
public R saveBatteryInfo(@RequestBody DevicePowerDTO devicePowerDTO) {
batteryService.saveBatteryInfo(devicePowerDTO);
return R.ok();
}
......
......@@ -5,6 +5,7 @@ import cn.com.glsx.stdinterface.dto.DeviceJourneyDTO;
import cn.com.glsx.stdinterface.modules.service.JourneyService;
import com.glsx.plat.core.web.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -27,7 +28,7 @@ public class JourneyController implements JourneyClient {
@PostMapping(value = "/save")
@Override
public R saveDeviceJourney(DeviceJourneyDTO deviceJourneyDTO) {
public R saveDeviceJourney(@RequestBody DeviceJourneyDTO deviceJourneyDTO) {
journeyService.saveDeviceJourney(deviceJourneyDTO);
return R.ok();
}
......
......@@ -36,14 +36,17 @@ public class BatteryService {
public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
//从车辆信息中获取创建人信息
Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn());
if (Objects.isNull(vehicle)) {
Long createdBy = null;
Long updatedBy = null;
if(Objects.nonNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn());
return;
}
//从关联表从获取关联id
Long vnId = vehicleService.getVdId(devicePowerDTO.getSn());
DevicePower devicePower = convert(devicePowerDTO, vehicle.getCreatedBy(), vehicle.getUpdatedBy(), vnId);
DevicePower devicePower = convert(devicePowerDTO, createdBy, updatedBy, vnId);
DevicePower devicePowerOld = devicePowerMapper.selectBySn(devicePowerDTO.getSn());
if (Objects.isNull(devicePowerOld)) {
......
......@@ -9,6 +9,7 @@ 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 cn.com.glsx.stdinterface.modules.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -51,32 +52,34 @@ public class JourneyService {
DeviceJourney journey = deviceJourneyMapper.selectBySnAndBeginTime(deviceJourneyDTO.getSn(), deviceJourneyDTO.getBeginTime());
if(Objects.nonNull(journey)) {
log.warn("该设备同样的开始时间行程数据已经存在" +
"sn: " + deviceJourneyDTO.getSn() + "beginTime:" + deviceJourneyDTO.getBeginTime());
"sn: " + deviceJourneyDTO.getSn() + "beginTime:" + DateUtils.formatNormal(deviceJourneyDTO.getBeginTime()));
return;
}
//从车辆信息中获取创建人信息
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
if (Objects.isNull(vehicle)) {
Long createdBy = null;
Long updatedBy = null;
if (Objects.nonNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
return;
}
deviceJourneyDTO.setCreatedBy(vehicle.getCreatedBy());
deviceJourneyDTO.setUpdatedBy(vehicle.getUpdatedBy());
//从关联表从获取关联id
Long vnId = vehicleService.getVdId(deviceJourneyDTO.getSn());
//行程信息入库
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vnId);
DeviceJourney deviceJourney = convertTo(deviceJourneyDTO, vnId, createdBy, updatedBy);
deviceJourneyMapper.insert(deviceJourney);
//更新总行程次数 总里程
DeviceJourneyOverview overview = buildOverviewWitheJourney(deviceJourneyDTO, vnId);
DeviceJourneyOverview overview = buildOverviewWitheJourney(deviceJourneyDTO, vnId, createdBy, updatedBy);
deviceJourneyOverviewMapper.insertOrSumDistanceAndCount(overview);
}
public DeviceJourneyOverview buildOverviewWitheJourney(DeviceJourneyDTO deviceJourneyDTO, Long vnId) {
public DeviceJourneyOverview buildOverviewWitheJourney(DeviceJourneyDTO deviceJourneyDTO, Long vnId, Long createdBy, Long updatedBy) {
DeviceJourneyOverview deviceJourneyOverview = new DeviceJourneyOverview();
deviceJourneyOverview.setSn(deviceJourneyDTO.getSn());
deviceJourneyOverview.setVdId(vnId);
......@@ -88,6 +91,8 @@ public class JourneyService {
deviceJourneyOverview.setUpdatedBy(deviceJourneyDTO.getUpdatedBy());
deviceJourneyOverview.setCreatedDate(new Date());
deviceJourneyOverview.setUpdatedDate(new Date());
deviceJourneyDTO.setCreatedBy(createdBy);
deviceJourneyDTO.setUpdatedBy(updatedBy);
return deviceJourneyOverview;
}
......@@ -95,7 +100,7 @@ public class JourneyService {
/**
* 转换为数据库对象
*/
public DeviceJourney convertTo(DeviceJourneyDTO deviceJourneyDTO, Long vnId) {
public DeviceJourney convertTo(DeviceJourneyDTO deviceJourneyDTO, Long vnId, Long createdBy, Long updatedBy) {
DeviceJourney deviceJourney = new DeviceJourney();
deviceJourney.setSn(deviceJourneyDTO.getSn());
//获取关联id
......@@ -106,8 +111,8 @@ public class JourneyService {
deviceJourney.setEndAddress(deviceJourneyDTO.getEndAddress());
deviceJourney.setMileage(deviceJourneyDTO.getMileage());
deviceJourney.setId(deviceJourneyDTO.getId());
deviceJourney.setCreatedBy(deviceJourneyDTO.getCreatedBy());
deviceJourney.setUpdatedBy(deviceJourneyDTO.getUpdatedBy());
deviceJourney.setCreatedBy(createdBy);
deviceJourney.setUpdatedBy(updatedBy);
deviceJourney.setCreatedDate(new Date());
deviceJourney.setUpdatedDate(new Date());
return deviceJourney;
......
......@@ -33,7 +33,7 @@
from t_device_power
<where>
and sn = #{sn}
and del_flag = 0;
and del_flag = 0
</where>
limit 1
</select>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!