localizer
parent
4194ce06fc
commit
47918629f7
|
|
@ -45,6 +45,7 @@ public class SearchTruckResult {
|
||||||
* 车架号
|
* 车架号
|
||||||
*/
|
*/
|
||||||
private String vnCode;
|
private String vnCode;
|
||||||
|
private Boolean online;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 合格证图片
|
* 合格证图片
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class OrderInfoController {
|
public class OrderInfoController {
|
||||||
private final OrderInfoService orderInfoService;
|
private final OrderInfoService orderInfoService;
|
||||||
|
// private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 100, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
|
|
@ -43,8 +44,14 @@ public class OrderInfoController {
|
||||||
if (estimatedQuantity != null && estimatedQuantity > 0) {
|
if (estimatedQuantity != null && estimatedQuantity > 0) {
|
||||||
addOrderInfoParam.setEstimatedQuantity(estimatedQuantity / truckCount);
|
addOrderInfoParam.setEstimatedQuantity(estimatedQuantity / truckCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
orderInfoService.batchAdd(addOrderInfoParam);
|
orderInfoService.batchAdd(addOrderInfoParam);
|
||||||
|
|
||||||
|
/* CompletableFuture.runAsync(() -> {
|
||||||
|
}, threadPoolExecutor).whenComplete((v, e) -> {
|
||||||
|
if (e != null) {
|
||||||
|
log.error("新增订单失败", e);
|
||||||
|
}
|
||||||
|
}); */
|
||||||
return R.success();
|
return R.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ public class AddOrderInfoParam implements Constrained {
|
||||||
* 联系人
|
* 联系人
|
||||||
*/
|
*/
|
||||||
private String contacts;
|
private String contacts;
|
||||||
|
private String sn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系方式
|
* 联系方式
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.njzscloud.supervisory.order.service;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.img.ImgUtil;
|
import cn.hutool.core.img.ImgUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
|
@ -47,9 +48,7 @@ import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.PlatformTransactionManager;
|
import org.springframework.transaction.PlatformTransactionManager;
|
||||||
import org.springframework.transaction.TransactionStatus;
|
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
@ -57,8 +56,7 @@ import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.njzscloud.supervisory.constant.Constant.CERTIFICATE_SN_CODE;
|
import static com.njzscloud.supervisory.constant.Constant.CERTIFICATE_SN_CODE;
|
||||||
|
|
@ -84,7 +82,6 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
private final StationManageService stationManageService;
|
private final StationManageService stationManageService;
|
||||||
private final PlatformTransactionManager transactionManager;
|
private final PlatformTransactionManager transactionManager;
|
||||||
private final CloudVoiceboxService cloudVoiceboxService;
|
private final CloudVoiceboxService cloudVoiceboxService;
|
||||||
private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 100, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
|
|
||||||
|
|
||||||
private static void stopTuqiangTrack(String gpsId) {
|
private static void stopTuqiangTrack(String gpsId) {
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
|
|
@ -104,7 +101,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
*/
|
*/
|
||||||
public void add(AddOrderInfoParam addOrderInfoParam) {
|
public void add(AddOrderInfoParam addOrderInfoParam, String orderSn) {
|
||||||
AddOrderCargoPlaceParam cargoPlace = addOrderInfoParam.getCargoPlace();
|
AddOrderCargoPlaceParam cargoPlace = addOrderInfoParam.getCargoPlace();
|
||||||
long cargoPlaceId = orderCargoPlaceService.add(cargoPlace);
|
long cargoPlaceId = orderCargoPlaceService.add(cargoPlace);
|
||||||
Long userId = SecurityUtil.currentUserId();
|
Long userId = SecurityUtil.currentUserId();
|
||||||
|
|
@ -117,9 +114,8 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
|
|
||||||
Long orderGoodsId = orderGoodsService.add(goodsId);
|
Long orderGoodsId = orderGoodsService.add(goodsId);
|
||||||
|
|
||||||
String orderSn = SnUtil.next();
|
|
||||||
OrderInfoEntity orderInfoEntity = BeanUtil.copyProperties(addOrderInfoParam, OrderInfoEntity.class)
|
OrderInfoEntity orderInfoEntity = BeanUtil.copyProperties(addOrderInfoParam, OrderInfoEntity.class)
|
||||||
.setSn(orderSn)
|
.setSn(orderSn == null ? SnUtil.next() : orderSn)
|
||||||
.setCargoPlaceId(cargoPlaceId)
|
.setCargoPlaceId(cargoPlaceId)
|
||||||
.setUserId(userId)
|
.setUserId(userId)
|
||||||
.setOrderStatus(orderStatus)
|
.setOrderStatus(orderStatus)
|
||||||
|
|
@ -135,10 +131,10 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
OrderCategory orderCategory = addOrderInfoParam.getOrderCategory();
|
OrderCategory orderCategory = addOrderInfoParam.getOrderCategory();
|
||||||
if (orderCategory == OrderCategory.DuanBoChu) {
|
if (orderCategory == OrderCategory.DuanBoChu) {
|
||||||
this.add(addOrderInfoParam.setOrderCategory(OrderCategory.DuanBoRu)
|
this.add(addOrderInfoParam.setOrderCategory(OrderCategory.DuanBoRu)
|
||||||
.setTargetOrderId(orderId)
|
.setTargetOrderId(orderId)
|
||||||
.setTargetStationId(addOrderInfoParam.getStationId())
|
.setTargetStationId(addOrderInfoParam.getStationId())
|
||||||
.setStationId(addOrderInfoParam.getTargetStationId())
|
.setStationId(addOrderInfoParam.getTargetStationId()),
|
||||||
);
|
null);
|
||||||
|
|
||||||
} else if (orderCategory == OrderCategory.DuanBoRu) {
|
} else if (orderCategory == OrderCategory.DuanBoRu) {
|
||||||
this.updateById(new OrderInfoEntity().setId(addOrderInfoParam.getTargetOrderId())
|
this.updateById(new OrderInfoEntity().setId(addOrderInfoParam.getTargetOrderId())
|
||||||
|
|
@ -704,15 +700,23 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
log.info("mqtt 收到消息:{} {}", gpsId + "/track_location", realtimeLocationResult);
|
log.info("mqtt 收到消息:{} {}", gpsId + "/track_location", realtimeLocationResult);
|
||||||
|
String time = realtimeLocationResult.getTime();
|
||||||
|
double latitude = realtimeLocationResult.getLatitude();
|
||||||
|
double longitude = realtimeLocationResult.getLongitude();
|
||||||
|
|
||||||
|
if (latitude <= 0 && longitude <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TruckLocationTrackEntity entity = new TruckLocationTrackEntity()
|
TruckLocationTrackEntity entity = new TruckLocationTrackEntity()
|
||||||
.setOrderId(orderInfoId)
|
.setOrderId(orderInfoId)
|
||||||
.setTruckId(truckId)
|
.setTruckId(truckId)
|
||||||
.setTerminalId(gpsId)
|
.setTerminalId(gpsId)
|
||||||
.setLatitude(realtimeLocationResult.getLatitude())
|
.setLatitude(latitude)
|
||||||
.setLongitude(realtimeLocationResult.getLongitude())
|
.setLongitude(longitude)
|
||||||
.setAltitude(realtimeLocationResult.getAltitude())
|
.setAltitude(realtimeLocationResult.getAltitude())
|
||||||
.setSpeed(realtimeLocationResult.getSpeed())
|
.setSpeed(realtimeLocationResult.getSpeed())
|
||||||
.setLocationTime(LocalDateTime.now())
|
.setLocationTime(DateUtil.parseLocalDateTime(time))
|
||||||
.setDirection(realtimeLocationResult.getDirection())
|
.setDirection(realtimeLocationResult.getDirection())
|
||||||
.setOverspeed(realtimeLocationResult.isOverspeed())
|
.setOverspeed(realtimeLocationResult.isOverspeed())
|
||||||
.setCompensate(realtimeLocationResult.getType() == 1);
|
.setCompensate(realtimeLocationResult.getType() == 1);
|
||||||
|
|
@ -768,10 +772,12 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
.setId(orderInfo.getId())
|
.setId(orderInfo.getId())
|
||||||
.setOrderStatus(OrderStatus.YiQuXiao)
|
.setOrderStatus(OrderStatus.YiQuXiao)
|
||||||
);
|
);
|
||||||
|
Long driverId = orderInfo.getDriverId();
|
||||||
|
Long truckId = orderInfo.getTruckId();
|
||||||
|
if (driverId != null) baseMapper.busyDriver(driverId, Boolean.FALSE);
|
||||||
|
if (truckId != null) baseMapper.busyTruck(truckId, Boolean.FALSE);
|
||||||
// TODO 关闭 GPS 定位
|
// TODO 关闭 GPS 定位
|
||||||
CompletableFuture.runAsync(() -> {
|
CompletableFuture.runAsync(() -> {
|
||||||
Long truckId = orderInfo.getTruckId();
|
|
||||||
if (truckId == null) {
|
if (truckId == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1109,59 +1115,15 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
||||||
return BeanUtil.copyProperties(orderDetail, TrainBillResult.class);
|
return BeanUtil.copyProperties(orderDetail, TrainBillResult.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void batchAdd(AddOrderInfoParam addOrderInfoParam) {
|
public void batchAdd(AddOrderInfoParam addOrderInfoParam) {
|
||||||
Integer truckCount = addOrderInfoParam.getTruckCount();
|
Integer truckCount = addOrderInfoParam.getTruckCount();
|
||||||
CountDownLatch latch = new CountDownLatch(truckCount);
|
String orderSn = null;
|
||||||
AtomicBoolean hasError = new AtomicBoolean(false);
|
if (truckCount > 1) {
|
||||||
List<TransactionStatus> transactionStatuses = new CopyOnWriteArrayList<>();
|
orderSn = SnUtil.next();
|
||||||
|
}
|
||||||
for (int i = 0; i < truckCount; i++) {
|
for (int i = 0; i < truckCount; i++) {
|
||||||
CompletableFuture.runAsync(() -> {
|
add(addOrderInfoParam, orderSn == null ? null : orderSn + "-" + (i + 1));
|
||||||
// 每个线程创建独立事务
|
|
||||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
|
||||||
TransactionStatus status = transactionManager.getTransaction(def);
|
|
||||||
try {
|
|
||||||
// 执行具体的插入操作
|
|
||||||
add(addOrderInfoParam);
|
|
||||||
// 暂存事务状态
|
|
||||||
transactionStatuses.add(status);
|
|
||||||
} catch (Exception e) {
|
|
||||||
// 标记错误状态
|
|
||||||
hasError.set(true);
|
|
||||||
// 记录错误但不立即回滚,等待统一处理
|
|
||||||
transactionStatuses.add(status);
|
|
||||||
throw Exceptions.error(e, "新增订单失败");
|
|
||||||
}
|
|
||||||
}, threadPoolExecutor).whenComplete((v, e) -> {
|
|
||||||
latch.countDown();
|
|
||||||
if (e != null) {
|
|
||||||
log.error("新增订单失败", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
latch.await();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
hasError.set(true);
|
|
||||||
log.warn("任务中断", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据执行结果统一处理事务
|
|
||||||
if (hasError.get()) {
|
|
||||||
// 有错误,全部回滚
|
|
||||||
for (TransactionStatus status : transactionStatuses) {
|
|
||||||
if (!status.isCompleted()) {
|
|
||||||
transactionManager.rollback(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw Exceptions.exception("批量创建订单失败");
|
|
||||||
} else {
|
|
||||||
// 全部成功,统一提交
|
|
||||||
for (TransactionStatus status : transactionStatuses) {
|
|
||||||
if (!status.isCompleted()) {
|
|
||||||
transactionManager.commit(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
<result property="qualification" column="qualification" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
|
<result property="qualification" column="qualification" typeHandler="com.njzscloud.common.mp.support.handler.j.JsonTypeHandler"/>
|
||||||
</resultMap>
|
</resultMap>
|
||||||
<select id="paging" resultMap="SearchTruckResultMap">
|
<select id="paging" resultMap="SearchTruckResultMap">
|
||||||
SELECT
|
SELECT a.id,
|
||||||
a.id,
|
|
||||||
a.company_id,
|
a.company_id,
|
||||||
b.company_name,
|
b.company_name,
|
||||||
b.uscc,
|
b.uscc,
|
||||||
|
|
@ -33,9 +32,11 @@
|
||||||
a.gps,
|
a.gps,
|
||||||
a.picture,
|
a.picture,
|
||||||
a.truck_category,
|
a.truck_category,
|
||||||
a.disabled
|
a.disabled,
|
||||||
|
c.last_time >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) `online`
|
||||||
FROM biz_truck a
|
FROM biz_truck a
|
||||||
INNER JOIN biz_company b ON b.id = a.company_id
|
INNER JOIN biz_company b ON b.id = a.company_id
|
||||||
|
INNER JOIN device_localizer c ON c.terminal_id = a.gps
|
||||||
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
||||||
${ew.customSqlSegment}
|
${ew.customSqlSegment}
|
||||||
</if>
|
</if>
|
||||||
|
|
@ -43,32 +44,34 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDetailById" resultMap="SearchTruckResultMap">
|
<select id="selectDetailById" resultMap="SearchTruckResultMap">
|
||||||
SELECT
|
SELECT a.id,
|
||||||
a.id,
|
a.company_id,
|
||||||
a.company_id,
|
b.company_name,
|
||||||
b.company_name,
|
b.uscc,
|
||||||
b.uscc,
|
a.license_plate,
|
||||||
a.license_plate,
|
a.truck_license,
|
||||||
a.truck_license,
|
a.vn_code,
|
||||||
a.vn_code,
|
a.qualification,
|
||||||
a.qualification,
|
a.carrying_capacity,
|
||||||
a.carrying_capacity,
|
a.tare_weight,
|
||||||
a.tare_weight,
|
a.audit_status,
|
||||||
a.audit_status,
|
a.audit_memo,
|
||||||
a.audit_memo,
|
a.creator_id,
|
||||||
a.creator_id,
|
a.modifier_id,
|
||||||
a.modifier_id,
|
a.create_time,
|
||||||
a.create_time,
|
a.modify_time,
|
||||||
a.modify_time,
|
a.truck_license_date,
|
||||||
a.truck_license_date,
|
a.qualification_date,
|
||||||
a.qualification_date,
|
a.deleted,
|
||||||
a.deleted,
|
a.busy,
|
||||||
a.gps,
|
a.gps,
|
||||||
a.picture,
|
a.picture,
|
||||||
a.truck_category,
|
a.truck_category,
|
||||||
a.disabled
|
a.disabled,
|
||||||
|
c.last_time >= DATE_SUB(NOW(), INTERVAL 5 MINUTE) `online`
|
||||||
FROM biz_truck a
|
FROM biz_truck a
|
||||||
INNER JOIN biz_company b ON b.id = a.company_id AND b.deleted = 0
|
INNER JOIN biz_company b ON b.id = a.company_id
|
||||||
|
INNER JOIN device_localizer c ON c.terminal_id = a.gps
|
||||||
WHERE a.id = #{id} AND a.deleted = 0
|
WHERE a.id = #{id} AND a.deleted = 0
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue