订单超时检查
parent
c5134d4c6b
commit
bbaaa45523
|
|
@ -3,6 +3,7 @@ package com.njzscloud.common.sichen.support;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.njzscloud.common.core.tuple.Tuple2;
|
import com.njzscloud.common.core.tuple.Tuple2;
|
||||||
import com.njzscloud.common.core.utils.GroupUtil;
|
import com.njzscloud.common.core.utils.GroupUtil;
|
||||||
|
|
@ -12,7 +13,9 @@ import com.njzscloud.common.sichen.contant.ScheduleType;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -20,7 +23,7 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class TaskStore implements BeanPostProcessor {
|
public class TaskStore {
|
||||||
private final Map<String, Tuple2<Object, Method>> fn = new HashMap<>();
|
private final Map<String, Tuple2<Object, Method>> fn = new HashMap<>();
|
||||||
private final List<TaskInfo> tasks = new LinkedList<>();
|
private final List<TaskInfo> tasks = new LinkedList<>();
|
||||||
private final TaskService taskService;
|
private final TaskService taskService;
|
||||||
|
|
@ -67,10 +70,19 @@ public class TaskStore implements BeanPostProcessor {
|
||||||
taskService.updateBatchById(list);
|
taskService.updateBatchById(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@EventListener(ApplicationReadyEvent.class)
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
public void onApplicationReadyEvent() {
|
||||||
|
ApplicationContext applicationContext = SpringUtil.getApplicationContext();
|
||||||
|
String[] beanNames = applicationContext.getBeanDefinitionNames();
|
||||||
|
for (String beanName : beanNames) {
|
||||||
|
Object bean = applicationContext.getBean(beanName);
|
||||||
|
process(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(Object bean) throws BeansException {
|
||||||
Class<?> clazz = bean.getClass();
|
Class<?> clazz = bean.getClass();
|
||||||
for (Method method : clazz.getDeclaredMethods()) {
|
for (Method method : clazz.getMethods()) {
|
||||||
Task task = method.getAnnotation(Task.class);
|
Task task = method.getAnnotation(Task.class);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
String value = task.value();
|
String value = task.value();
|
||||||
|
|
@ -102,6 +114,5 @@ public class TaskStore implements BeanPostProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bean;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.njzscloud.supervisory.biz.pojo.entity.BizCompanyEntity;
|
import com.njzscloud.supervisory.biz.pojo.entity.BizCompanyEntity;
|
||||||
import com.njzscloud.supervisory.biz.pojo.entity.BizTruckEntity;
|
import com.njzscloud.supervisory.biz.pojo.entity.BizTruckEntity;
|
||||||
|
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
||||||
import com.njzscloud.supervisory.order.pojo.entity.OrderInfoEntity;
|
import com.njzscloud.supervisory.order.pojo.entity.OrderInfoEntity;
|
||||||
import com.njzscloud.supervisory.order.pojo.result.OrderExportResult;
|
import com.njzscloud.supervisory.order.pojo.result.OrderExportResult;
|
||||||
import com.njzscloud.supervisory.order.pojo.result.OrderPagingResult;
|
import com.njzscloud.supervisory.order.pojo.result.OrderPagingResult;
|
||||||
|
|
@ -41,4 +42,6 @@ public interface OrderInfoMapper extends BaseMapper<OrderInfoEntity> {
|
||||||
BizTruckEntity getTruckInfo(@Param("truckId") Long truckId);
|
BizTruckEntity getTruckInfo(@Param("truckId") Long truckId);
|
||||||
|
|
||||||
BizCompanyEntity getTransInfo(@Param("transCompanyId") Long transCompanyId);
|
BizCompanyEntity getTransInfo(@Param("transCompanyId") Long transCompanyId);
|
||||||
|
|
||||||
|
DeviceLocalizerEntity gpsLastOnlineTime(@Param("gpsId") String gpsId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import com.njzscloud.supervisory.biz.service.BizWarnService;
|
||||||
import com.njzscloud.supervisory.biz.service.TruckLocationTrackService;
|
import com.njzscloud.supervisory.biz.service.TruckLocationTrackService;
|
||||||
import com.njzscloud.supervisory.config.AppProperties;
|
import com.njzscloud.supervisory.config.AppProperties;
|
||||||
import com.njzscloud.supervisory.constant.Constant;
|
import com.njzscloud.supervisory.constant.Constant;
|
||||||
|
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
||||||
import com.njzscloud.supervisory.expense.contant.ExpenseItemCategory;
|
import com.njzscloud.supervisory.expense.contant.ExpenseItemCategory;
|
||||||
import com.njzscloud.supervisory.expense.contant.Scope;
|
import com.njzscloud.supervisory.expense.contant.Scope;
|
||||||
import com.njzscloud.supervisory.expense.pojo.entity.ExpenseItemsConfigEntity;
|
import com.njzscloud.supervisory.expense.pojo.entity.ExpenseItemsConfigEntity;
|
||||||
|
|
@ -711,7 +712,6 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
.setOrderStatus(OrderStatus.QingYunZhong)
|
.setOrderStatus(OrderStatus.QingYunZhong)
|
||||||
.setTransTime(LocalDateTime.now())
|
.setTransTime(LocalDateTime.now())
|
||||||
);
|
);
|
||||||
// TODO 获取 GPS
|
|
||||||
Long truckId = orderInfo.getTruckId();
|
Long truckId = orderInfo.getTruckId();
|
||||||
Assert.notNull(truckId, () -> Exceptions.clierr("订单未分配车辆"));
|
Assert.notNull(truckId, () -> Exceptions.clierr("订单未分配车辆"));
|
||||||
BizTruckEntity truckInfo = baseMapper.getTruckInfo(truckId);
|
BizTruckEntity truckInfo = baseMapper.getTruckInfo(truckId);
|
||||||
|
|
@ -732,9 +732,44 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void orderTimeOut() {
|
||||||
|
log.info("检查超时订单");
|
||||||
|
List<OrderInfoEntity> timeOutOrderList = this.list(Wrappers.<OrderInfoEntity>lambdaQuery()
|
||||||
|
.isNotNull(OrderInfoEntity::getAuditTime)
|
||||||
|
.le(OrderInfoEntity::getAuditTime, LocalDateTime.now().minusHours(12))
|
||||||
|
.notIn(OrderInfoEntity::getOrderStatus, OrderStatus.YiJinChang, OrderStatus.YiChuChang, OrderStatus.YiWanCheng)
|
||||||
|
);
|
||||||
|
if (CollUtil.isEmpty(timeOutOrderList)) return;
|
||||||
|
log.info("有超时订单:{} 个", timeOutOrderList.size());
|
||||||
|
for (OrderInfoEntity orderInfoEntity : timeOutOrderList) {
|
||||||
|
Long id = orderInfoEntity.getId();
|
||||||
|
String sn = orderInfoEntity.getSn();
|
||||||
|
boolean exists = bizWarnService.exists(Wrappers.<BizWarnEntity>lambdaQuery().eq(BizWarnEntity::getOrderId, id).eq(BizWarnEntity::getWarnCategory, WarnCategory.SAFETY.getVal()));
|
||||||
|
if (exists) continue;
|
||||||
|
bizWarnService.save(new BizWarnEntity()
|
||||||
|
.setWarnCategory(WarnCategory.SAFETY.getVal())
|
||||||
|
.setWarnContent(StrUtil.format("订单:{},已超时", sn))
|
||||||
|
.setOrderId(id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void startTuqiangTrack(String gpsId, String licensePlate, Long orderInfoId, Long truckId) {
|
private void startTuqiangTrack(String gpsId, String licensePlate, Long orderInfoId, Long truckId) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
Assert.notEmpty(gpsId, () -> Exceptions.clierr("车辆未绑定GPS"));
|
Assert.notEmpty(gpsId, () -> Exceptions.clierr("车辆未绑定GPS"));
|
||||||
|
DeviceLocalizerEntity deviceLocalizerEntity = baseMapper.gpsLastOnlineTime(gpsId);
|
||||||
|
LocalDateTime lastTime = deviceLocalizerEntity.getLastTime();
|
||||||
|
boolean after = lastTime.isBefore(LocalDateTime.now().minusMinutes(5));
|
||||||
|
if (after) {
|
||||||
|
bizWarnService.save(new BizWarnEntity()
|
||||||
|
.setWarnCategory(WarnCategory.EQUIPMENT.getVal())
|
||||||
|
.setWarnContent(StrUtil.format("{} 绑定的 GPS 设备已离线,设备号:{}", licensePlate, gpsId))
|
||||||
|
.setOrderId(orderInfoId)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Mqtt.subscribe(gpsId + "/track_location", (msg) -> {
|
Mqtt.subscribe(gpsId + "/track_location", (msg) -> {
|
||||||
RealtimeLocationResult realtimeLocationResult = msg.getMsg(RealtimeLocationResult.class);
|
RealtimeLocationResult realtimeLocationResult = msg.getMsg(RealtimeLocationResult.class);
|
||||||
if (realtimeLocationResult == null) {
|
if (realtimeLocationResult == null) {
|
||||||
|
|
@ -769,7 +804,6 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
.setOverspeed(realtimeLocationResult.isOverspeed())
|
.setOverspeed(realtimeLocationResult.isOverspeed())
|
||||||
.setCompensate(realtimeLocationResult.getType() == 1);
|
.setCompensate(realtimeLocationResult.getType() == 1);
|
||||||
truckLocationTrackService.save(entity);
|
truckLocationTrackService.save(entity);
|
||||||
// truckLocationTrackService.cache(entity);
|
|
||||||
});
|
});
|
||||||
Mqtt.publish("location/track", MapUtil.builder()
|
Mqtt.publish("location/track", MapUtil.builder()
|
||||||
.put("terminalId", gpsId)
|
.put("terminalId", gpsId)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.njzscloud.supervisory.order.service;
|
||||||
|
|
||||||
|
import com.njzscloud.common.sichen.support.Task;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class OrderInfoServiceTask {
|
||||||
|
private final OrderInfoService orderInfoService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每 30 分钟检查一次
|
||||||
|
*/
|
||||||
|
@Task(cron = "0 0/30 * * * ?")
|
||||||
|
public void orderTimeOut() {
|
||||||
|
orderInfoService.orderTimeOut();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -295,4 +295,11 @@
|
||||||
FROM biz_company
|
FROM biz_company
|
||||||
WHERE id = #{transCompanyId}
|
WHERE id = #{transCompanyId}
|
||||||
</select>
|
</select>
|
||||||
|
<select id="gpsLastOnlineTime"
|
||||||
|
resultType="com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity">
|
||||||
|
select *
|
||||||
|
from device_localizer
|
||||||
|
where terminal_id = #{gpsId}
|
||||||
|
and deleted = 0
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue