订单详情
This commit is contained in:
parent
ea05b4dcd5
commit
5a3878645b
|
@ -1741,4 +1741,22 @@ public class AppVerifyController extends BaseController
|
||||||
ajax.put(AjaxResult.DATA_TAG,trajectoryDetails);
|
ajax.put(AjaxResult.DATA_TAG,trajectoryDetails);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询车辆轨迹
|
||||||
|
*/
|
||||||
|
@PostMapping("/trajectoryDetailsByOrderNo")
|
||||||
|
public AjaxResult trajectoryDetailsByOrderNo(String orderNo)
|
||||||
|
{
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
if(StrUtil.isBlank(orderNo)){
|
||||||
|
logger.info("【根据订单号查询车辆轨迹】没有orderNo参数:【orderNo={}】",orderNo);
|
||||||
|
return error("请传订单号"+"【orderNo="+orderNo+"】");
|
||||||
|
}
|
||||||
|
logger.info("【根据订单号查询车辆轨迹】:{}",orderNo);
|
||||||
|
List<EtLocationLog> trajectoryDetails = asDeviceService.trajectoryDetailsByOrderNo(orderNo);
|
||||||
|
etLocationLogService.analytic(trajectoryDetails);
|
||||||
|
ajax.put(AjaxResult.DATA_TAG,trajectoryDetails);
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -414,6 +414,16 @@ public class ServiceConstants {
|
||||||
*/
|
*/
|
||||||
public static final String TRIP_LOG_TYPE_RETRUN_LOCK = "4";
|
public static final String TRIP_LOG_TYPE_RETRUN_LOCK = "4";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量操作类型:5-换车关锁
|
||||||
|
*/
|
||||||
|
public static final String TRIP_LOG_TYPE_CHANGE_LOCK = "5";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量操作类型:6-换车开锁
|
||||||
|
*/
|
||||||
|
public static final String TRIP_LOG_TYPE_CHANGE_UNLOCK = "6";
|
||||||
|
|
||||||
|
|
||||||
/**----------------------------行程记录类型end----------------------------*/
|
/**----------------------------行程记录类型end----------------------------*/
|
||||||
/**----------------------------退款类型start----------------------------*/
|
/**----------------------------退款类型start----------------------------*/
|
||||||
|
|
|
@ -48,4 +48,8 @@ public class EtTripLog extends BaseEntity
|
||||||
@Excel(name = "车辆状态")
|
@Excel(name = "车辆状态")
|
||||||
private String deviceStatus;
|
private String deviceStatus;
|
||||||
|
|
||||||
|
/** describe 描述 */
|
||||||
|
@Excel(name = "描述")
|
||||||
|
private String describe;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,6 +422,11 @@ public interface IAsDeviceService extends IService<AsDevice>
|
||||||
*/
|
*/
|
||||||
List<EtLocationLog> trajectoryDetails(String sn, String startTime, String endTime);
|
List<EtLocationLog> trajectoryDetails(String sn, String startTime, String endTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询车辆轨迹
|
||||||
|
*/
|
||||||
|
List<EtLocationLog> trajectoryDetailsByOrderNo(String orderNo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据订单号查询车辆轨迹
|
* 根据订单号查询车辆轨迹
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -51,6 +51,8 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import static com.ruoyi.common.constant.HttpStatus.ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG;
|
import static com.ruoyi.common.constant.HttpStatus.ERROR_CODE_DEVICE_ALREADY_EXISTS_MSG;
|
||||||
|
import static com.ruoyi.common.constant.ServiceConstants.TRIP_LOG_TYPE_CHANGE_LOCK;
|
||||||
|
import static com.ruoyi.common.constant.ServiceConstants.TRIP_LOG_TYPE_CHANGE_UNLOCK;
|
||||||
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
import static com.ruoyi.common.utils.SecurityUtils.getUsername;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,6 +122,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
@Resource
|
@Resource
|
||||||
private AsUserMapper asUserMapper;
|
private AsUserMapper asUserMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IEtTripLogService etTripLogService;
|
||||||
|
|
||||||
|
|
||||||
@Value(value = "${iot.iotUrl}")
|
@Value(value = "${iot.iotUrl}")
|
||||||
private String iotUrl;
|
private String iotUrl;
|
||||||
|
@ -2837,6 +2842,108 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
return etLocationLogMapper.selectEtLocationLogListByCreateTime(device.getMac(), startTime, endTime);
|
return etLocationLogMapper.selectEtLocationLogListByCreateTime(device.getMac(), startTime, endTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号查询车辆轨迹
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<EtLocationLog> trajectoryDetailsByOrderNo(String orderNo) {
|
||||||
|
EtOrder order = etOrderMapper.selectEtOrderByOrderNo(orderNo);
|
||||||
|
ServiceUtil.assertion(ObjectUtil.isNull(order), "订单不存在");
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
if(StrUtil.isBlank(order.getUsedSn())){
|
||||||
|
return trajectoryDetails(order.getSn(), sdf.format(order.getUnlockTime()), sdf.format(order.getReturnTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<EtLocationLog> allLocationLogs = new ArrayList<>();
|
||||||
|
List<EtTripLog> tripLogs = fetchTripLogs(order);
|
||||||
|
|
||||||
|
if (ObjectUtils.isNotEmpty(tripLogs)) {
|
||||||
|
processTripLogs(tripLogs, allLocationLogs, sdf, order);
|
||||||
|
} else if (StringUtils.isBlank(order.getUsedSn())) {
|
||||||
|
// 如果没有行程记录且没有换车情况,直接查询从unlockTime到returnTime的数据
|
||||||
|
queryDeviceLocationLogs(order.getSn(), order.getUnlockTime(), order.getReturnTime(), sdf, allLocationLogs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allLocationLogs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<EtTripLog> fetchTripLogs(EtOrder order) {
|
||||||
|
EtTripLog tripLogQuery = new EtTripLog();
|
||||||
|
tripLogQuery.setOrderNo(order.getOrderNo());
|
||||||
|
return etTripLogService.selectEtTripLogList(tripLogQuery);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processTripLogs(List<EtTripLog> tripLogs, List<EtLocationLog> allLocationLogs, SimpleDateFormat sdf, EtOrder order) {
|
||||||
|
for (int i = 0; i < tripLogs.size(); i++) {
|
||||||
|
EtTripLog currentLog = tripLogs.get(i);
|
||||||
|
if (TRIP_LOG_TYPE_CHANGE_LOCK.equals(currentLog.getType())) {
|
||||||
|
handleChangeLock(currentLog, tripLogs, allLocationLogs, sdf, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(order.getUsedSn())) {
|
||||||
|
handleLastUnlockToReturnTime(tripLogs, allLocationLogs, sdf, order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleChangeLock(EtTripLog currentLog, List<EtTripLog> tripLogs, List<EtLocationLog> allLocationLogs, SimpleDateFormat sdf, int currentIndex) {
|
||||||
|
final String TRIP_LOG_TYPE_CHANGE_UNLOCK = "6";
|
||||||
|
|
||||||
|
for (int j = currentIndex + 1; j < tripLogs.size(); j++) {
|
||||||
|
EtTripLog nextLog = tripLogs.get(j);
|
||||||
|
if (TRIP_LOG_TYPE_CHANGE_UNLOCK.equals(nextLog.getType()) && nextLog.getSn() != null) {
|
||||||
|
AsDevice device = asDeviceMapper.selectAsDeviceBySn(currentLog.getSn());
|
||||||
|
if (device == null) {
|
||||||
|
throw new RuntimeException("设备SN:" + currentLog.getSn() + " 不存在");
|
||||||
|
}
|
||||||
|
List<EtLocationLog> locationLogs = etLocationLogMapper.selectEtLocationLogListByCreateTime(
|
||||||
|
device.getMac(),
|
||||||
|
sdf.format(currentLog.getCreateTime()),
|
||||||
|
sdf.format(nextLog.getCreateTime()));
|
||||||
|
if (locationLogs != null) {
|
||||||
|
allLocationLogs.addAll(locationLogs);
|
||||||
|
}
|
||||||
|
break; // 找到对应的换车开锁后跳出循环
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLastUnlockToReturnTime(List<EtTripLog> tripLogs, List<EtLocationLog> allLocationLogs, SimpleDateFormat sdf, EtOrder order) {
|
||||||
|
final String TRIP_LOG_TYPE_CHANGE_UNLOCK = "6";
|
||||||
|
Optional<EtTripLog> lastUnlockLogOpt = tripLogs.stream()
|
||||||
|
.filter(log -> TRIP_LOG_TYPE_CHANGE_UNLOCK.equals(log.getType()))
|
||||||
|
.max(Comparator.comparing(EtTripLog::getCreateTime));
|
||||||
|
if (lastUnlockLogOpt.isPresent()) {
|
||||||
|
EtTripLog lastUnlockLog = lastUnlockLogOpt.get();
|
||||||
|
AsDevice device = asDeviceMapper.selectAsDeviceBySn(lastUnlockLog.getSn());
|
||||||
|
if (device == null) {
|
||||||
|
throw new RuntimeException("设备SN:" + lastUnlockLog.getSn() + " 不存在");
|
||||||
|
}
|
||||||
|
List<EtLocationLog> finalLocationLogs = etLocationLogMapper.selectEtLocationLogListByCreateTime(
|
||||||
|
device.getMac(),
|
||||||
|
sdf.format(lastUnlockLog.getCreateTime()),
|
||||||
|
sdf.format(order.getReturnTime()));
|
||||||
|
if (finalLocationLogs != null) {
|
||||||
|
allLocationLogs.addAll(finalLocationLogs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void queryDeviceLocationLogs(String sn, Date startTime, Date endTime, SimpleDateFormat sdf, List<EtLocationLog> allLocationLogs) {
|
||||||
|
AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn);
|
||||||
|
if (device == null) {
|
||||||
|
throw new RuntimeException("设备SN:" + sn + " 不存在");
|
||||||
|
}
|
||||||
|
List<EtLocationLog> locationLogs = etLocationLogMapper.selectEtLocationLogListByCreateTime(
|
||||||
|
device.getMac(),
|
||||||
|
sdf.format(startTime),
|
||||||
|
sdf.format(endTime));
|
||||||
|
if (locationLogs != null) {
|
||||||
|
allLocationLogs.addAll(locationLogs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据时间查询车辆轨迹
|
* 根据时间查询车辆轨迹
|
||||||
|
|
|
@ -160,6 +160,9 @@ public class EtOrderServiceImpl implements IEtOrderService
|
||||||
@Resource
|
@Resource
|
||||||
private EtReconciliationMapper reconciliationMapper;
|
private EtReconciliationMapper reconciliationMapper;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IEtTripLogService tripLogService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询订单
|
* 查询订单
|
||||||
*
|
*
|
||||||
|
@ -2324,9 +2327,12 @@ public class EtOrderServiceImpl implements IEtOrderService
|
||||||
log.info("【换车关锁】改变订单使用过的sn失败");
|
log.info("【换车关锁】改变订单使用过的sn失败");
|
||||||
throw new ServiceException("【换车关锁】改变订单使用过的sn失败");
|
throw new ServiceException("【换车关锁】改变订单使用过的sn失败");
|
||||||
}
|
}
|
||||||
|
/** 5.记录行程*/
|
||||||
|
int tripLog = tripLogService.tripLog(order.getOrderNo(),sn,ServiceConstants.TRIP_LOG_TYPE_CHANGE_LOCK);
|
||||||
|
ServiceUtil.assertion(tripLog==0,"【换车关锁记录行程失败");
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
});
|
});
|
||||||
if(execute){
|
if(Boolean.TRUE.equals(execute)){
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}else{
|
}else{
|
||||||
return Boolean.FALSE;
|
return Boolean.FALSE;
|
||||||
|
@ -2353,7 +2359,7 @@ public class EtOrderServiceImpl implements IEtOrderService
|
||||||
if (ObjectUtil.isNull(newDevice)) {
|
if (ObjectUtil.isNull(newDevice)) {
|
||||||
throw new ServiceException("设备不存在:"+ newSn);
|
throw new ServiceException("设备不存在:"+ newSn);
|
||||||
}
|
}
|
||||||
if(order.getAreaId() != newDevice.getAreaId()){
|
if(!order.getAreaId().equals(newDevice.getAreaId())){
|
||||||
throw new ServiceException("不同运营区,请勿操作");
|
throw new ServiceException("不同运营区,请勿操作");
|
||||||
}
|
}
|
||||||
/** 1.获取token*/
|
/** 1.获取token*/
|
||||||
|
@ -2395,9 +2401,12 @@ public class EtOrderServiceImpl implements IEtOrderService
|
||||||
log.info("【换车开锁】更新订单sn失败");
|
log.info("【换车开锁】更新订单sn失败");
|
||||||
throw new ServiceException("【换车开锁】更新订单sn失败");
|
throw new ServiceException("【换车开锁】更新订单sn失败");
|
||||||
}
|
}
|
||||||
|
/** 5.记录行程*/
|
||||||
|
int tripLog = tripLogService.tripLog(order.getOrderNo(),newSn,ServiceConstants.TRIP_LOG_TYPE_CHANGE_UNLOCK);
|
||||||
|
ServiceUtil.assertion(tripLog==0,"【换车开锁】记录行程失败");
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
});
|
});
|
||||||
if(!execute)throw new ServiceException("换车开锁失败");
|
if(Boolean.FALSE.equals(execute))throw new ServiceException("换车开锁失败");
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,13 +118,10 @@ public class EtTripLogServiceImpl implements IEtTripLogService
|
||||||
EtTripLog etTripLog = new EtTripLog();
|
EtTripLog etTripLog = new EtTripLog();
|
||||||
etTripLog.setType(type);
|
etTripLog.setType(type);
|
||||||
etTripLog.setOrderNo(orderNo);
|
etTripLog.setOrderNo(orderNo);
|
||||||
AsDevice asDevice = null;
|
|
||||||
if(StrUtil.isNotBlank(sn)){
|
if(StrUtil.isNotBlank(sn)){
|
||||||
asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
|
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
|
||||||
etTripLog.setLatitude(asDevice.getLatitude());
|
etTripLog.setLatitude(asDevice.getLatitude());
|
||||||
etTripLog.setLongitude(asDevice.getLongitude());
|
etTripLog.setLongitude(asDevice.getLongitude());
|
||||||
String location = asDevice.getLongitude() + ","+asDevice.getLatitude();
|
|
||||||
// etTripLog.setAddress(CommonUtil.getAddressByGeo(location));
|
|
||||||
etTripLog.setSn(sn);
|
etTripLog.setSn(sn);
|
||||||
}
|
}
|
||||||
log.info("创建行程记录:{}", JSON.toJSON(etTripLog));
|
log.info("创建行程记录:{}", JSON.toJSON(etTripLog));
|
||||||
|
|
|
@ -437,6 +437,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
u.user_name AS userName,
|
u.user_name AS userName,
|
||||||
u.phonenumber AS phonenumber,
|
u.phonenumber AS phonenumber,
|
||||||
o.rule_id,
|
o.rule_id,
|
||||||
|
o.user_id,
|
||||||
o.coupon_id,
|
o.coupon_id,
|
||||||
o.log_id,
|
o.log_id,
|
||||||
o.device_mac,
|
o.device_mac,
|
||||||
|
|
|
@ -27,6 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="address != null and address != ''"> and address = #{address}</if>
|
<if test="address != null and address != ''"> and address = #{address}</if>
|
||||||
<if test="type != null and type != ''"> and type = #{type}</if>
|
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||||
</where>
|
</where>
|
||||||
|
order by create_time
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectEtTripLogByTripId" parameterType="Long" resultMap="EtTripLogResult">
|
<select id="selectEtTripLogByTripId" parameterType="Long" resultMap="EtTripLogResult">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user