Commit b80116a2 by 向延琳

修改参数处理和错误的sql

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