订单详情

This commit is contained in:
邱贞招 2025-02-26 08:55:39 +08:00
parent ea05b4dcd5
commit 5a3878645b
9 changed files with 159 additions and 7 deletions

View File

@ -1741,4 +1741,22 @@ public class AppVerifyController extends BaseController
ajax.put(AjaxResult.DATA_TAG,trajectoryDetails);
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;
}
}

View File

@ -414,6 +414,16 @@ public class ServiceConstants {
*/
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----------------------------*/
/**----------------------------退款类型start----------------------------*/

View File

@ -48,4 +48,8 @@ public class EtTripLog extends BaseEntity
@Excel(name = "车辆状态")
private String deviceStatus;
/** describe 描述 */
@Excel(name = "描述")
private String describe;
}

View File

@ -422,6 +422,11 @@ public interface IAsDeviceService extends IService<AsDevice>
*/
List<EtLocationLog> trajectoryDetails(String sn, String startTime, String endTime);
/**
* 根据订单号查询车辆轨迹
*/
List<EtLocationLog> trajectoryDetailsByOrderNo(String orderNo);
/**
* 根据订单号查询车辆轨迹
*/

View File

@ -51,6 +51,8 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
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;
/**
@ -120,6 +122,9 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
@Resource
private AsUserMapper asUserMapper;
@Autowired
private IEtTripLogService etTripLogService;
@Value(value = "${iot.iotUrl}")
private String iotUrl;
@ -2837,6 +2842,108 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
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);
}
}
/**
* 根据时间查询车辆轨迹

View File

@ -160,6 +160,9 @@ public class EtOrderServiceImpl implements IEtOrderService
@Resource
private EtReconciliationMapper reconciliationMapper;
@Resource
private IEtTripLogService tripLogService;
/**
* 查询订单
*
@ -2324,9 +2327,12 @@ public class EtOrderServiceImpl implements IEtOrderService
log.info("【换车关锁】改变订单使用过的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;
});
if(execute){
if(Boolean.TRUE.equals(execute)){
return Boolean.TRUE;
}else{
return Boolean.FALSE;
@ -2353,7 +2359,7 @@ public class EtOrderServiceImpl implements IEtOrderService
if (ObjectUtil.isNull(newDevice)) {
throw new ServiceException("设备不存在:"+ newSn);
}
if(order.getAreaId() != newDevice.getAreaId()){
if(!order.getAreaId().equals(newDevice.getAreaId())){
throw new ServiceException("不同运营区,请勿操作");
}
/** 1.获取token*/
@ -2395,9 +2401,12 @@ public class EtOrderServiceImpl implements IEtOrderService
log.info("【换车开锁】更新订单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;
});
if(!execute)throw new ServiceException("换车开锁失败");
if(Boolean.FALSE.equals(execute))throw new ServiceException("换车开锁失败");
return Boolean.TRUE;
}

View File

@ -118,13 +118,10 @@ public class EtTripLogServiceImpl implements IEtTripLogService
EtTripLog etTripLog = new EtTripLog();
etTripLog.setType(type);
etTripLog.setOrderNo(orderNo);
AsDevice asDevice = null;
if(StrUtil.isNotBlank(sn)){
asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn);
etTripLog.setLatitude(asDevice.getLatitude());
etTripLog.setLongitude(asDevice.getLongitude());
String location = asDevice.getLongitude() + ","+asDevice.getLatitude();
// etTripLog.setAddress(CommonUtil.getAddressByGeo(location));
etTripLog.setSn(sn);
}
log.info("创建行程记录:{}", JSON.toJSON(etTripLog));

View File

@ -437,6 +437,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
u.user_name AS userName,
u.phonenumber AS phonenumber,
o.rule_id,
o.user_id,
o.coupon_id,
o.log_id,
o.device_mac,

View File

@ -27,6 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="address != null and address != ''"> and address = #{address}</if>
<if test="type != null and type != ''"> and type = #{type}</if>
</where>
order by create_time
</select>
<select id="selectEtTripLogByTripId" parameterType="Long" resultMap="EtTripLogResult">