|
|
|
|
@ -48,7 +48,10 @@ import com.njzscloud.supervisory.sys.stationletter.constant.WarnCategory;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
@ -56,7 +59,8 @@ import java.time.LocalDateTime;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.njzscloud.supervisory.constant.Constant.CERTIFICATE_SN_CODE;
|
|
|
|
|
@ -80,6 +84,8 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
private final BizWarnService bizWarnService;
|
|
|
|
|
private final AppProperties appProperties;
|
|
|
|
|
private final StationManageService stationManageService;
|
|
|
|
|
private final PlatformTransactionManager transactionManager;
|
|
|
|
|
private final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 100, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(100), new ThreadPoolExecutor.CallerRunsPolicy());
|
|
|
|
|
|
|
|
|
|
private static void stopTuqiangTrack(String gpsId) {
|
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
|
@ -99,7 +105,6 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
/**
|
|
|
|
|
* 新增
|
|
|
|
|
*/
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public void add(AddOrderInfoParam addOrderInfoParam) {
|
|
|
|
|
AddOrderCargoPlaceParam cargoPlace = addOrderInfoParam.getCargoPlace();
|
|
|
|
|
long cargoPlaceId = orderCargoPlaceService.add(cargoPlace);
|
|
|
|
|
@ -118,7 +123,8 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
.setCargoPlaceId(cargoPlaceId)
|
|
|
|
|
.setUserId(userId)
|
|
|
|
|
.setOrderStatus(orderStatus)
|
|
|
|
|
.setGoodsId(orderGoodsId);
|
|
|
|
|
.setGoodsId(orderGoodsId)
|
|
|
|
|
.setAssignmentTransTime(transCompanyId == null ? null : LocalDateTime.now());
|
|
|
|
|
this.save(orderInfoEntity);
|
|
|
|
|
|
|
|
|
|
if (transCompanyId != null) {
|
|
|
|
|
@ -177,44 +183,43 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
LocalDateTime startTime = orderPagingSearchParam.getStartTime();
|
|
|
|
|
LocalDateTime endTime = orderPagingSearchParam.getEndTime();
|
|
|
|
|
Page<OrderPagingResult> page = pageParam.toPage();
|
|
|
|
|
page.addOrder(OrderItem.desc("a.create_time"));
|
|
|
|
|
QueryWrapper<OrderPagingResult> ew = Wrappers.<OrderPagingResult>query()
|
|
|
|
|
.like(StrUtil.isNotBlank(sn), "a.sn", sn)
|
|
|
|
|
.like(StrUtil.isNotBlank(licensePlate), "a.license_plate", licensePlate)
|
|
|
|
|
.like(StrUtil.isNotBlank(nickname), "h.nickname", nickname)
|
|
|
|
|
.like(StrUtil.isNotBlank(phone), "h.phone", phone)
|
|
|
|
|
.like(StrUtil.isNotBlank(licensePlate), "e.license_plate", licensePlate)
|
|
|
|
|
.like(StrUtil.isNotBlank(nickname), "a.contacts", nickname)
|
|
|
|
|
.like(StrUtil.isNotBlank(phone), "a.phone", phone)
|
|
|
|
|
.ge(startTime != null, "a.create_time", startTime)
|
|
|
|
|
.le(endTime != null, "a.create_time", endTime);
|
|
|
|
|
OrderViewType type = orderPagingSearchParam.getType();
|
|
|
|
|
Assert.notNull(type, () -> Exceptions.clierr("订单类型不能为空"));
|
|
|
|
|
switch (type) {
|
|
|
|
|
case DaiPaiDan:
|
|
|
|
|
dispatchEW(orderPagingSearchParam, ew);
|
|
|
|
|
dispatchEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case YuYue:
|
|
|
|
|
bookingEW(orderPagingSearchParam, ew);
|
|
|
|
|
bookingEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case LiShi:
|
|
|
|
|
historyEW(orderPagingSearchParam, ew);
|
|
|
|
|
historyEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case QuXiao:
|
|
|
|
|
cancelEW(orderPagingSearchParam, ew);
|
|
|
|
|
cancelEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case ShouGong:
|
|
|
|
|
autoEW(orderPagingSearchParam, ew);
|
|
|
|
|
autoEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case ShiShi:
|
|
|
|
|
realtimeEW(orderPagingSearchParam, ew);
|
|
|
|
|
realtimeEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
case KanLiao:
|
|
|
|
|
checkEW(orderPagingSearchParam, ew);
|
|
|
|
|
checkEW(orderPagingSearchParam, page, ew);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
page.addOrder(OrderItem.desc("a.create_time"), OrderItem.desc("a.id"));
|
|
|
|
|
return PageResult.of(baseMapper.paging(page, ew));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dispatchEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void dispatchEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Long userId = SecurityUtil.currentUserId();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
@ -243,10 +248,11 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void bookingEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void bookingEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Long userId = SecurityUtil.currentUserId();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
page.addOrder(OrderItem.desc("a.assignment_trans_time"), OrderItem.desc("a.assignment_driver_time"));
|
|
|
|
|
|
|
|
|
|
if (BizObj.isWaste(bizObj)) {
|
|
|
|
|
ew
|
|
|
|
|
@ -268,10 +274,11 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void realtimeEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void realtimeEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Long userId = SecurityUtil.currentUserId();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
page.addOrder(OrderItem.desc("a.driver_confirm_time"));
|
|
|
|
|
|
|
|
|
|
if (BizObj.isWaste(bizObj)) {
|
|
|
|
|
ew
|
|
|
|
|
@ -307,11 +314,13 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void historyEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void historyEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Long userId = SecurityUtil.currentUserId();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
|
|
|
|
|
page.addOrder(OrderItem.desc("d.out_time"));
|
|
|
|
|
|
|
|
|
|
if (BizObj.isWaste(bizObj)) {
|
|
|
|
|
ew
|
|
|
|
|
.eq("a.order_status", OrderStatus.YiWanCheng)
|
|
|
|
|
@ -347,7 +356,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void cancelEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Long userId = SecurityUtil.currentUserId();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
@ -372,7 +381,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void autoEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void autoEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
UserDetail userDetail = SecurityUtil.loginUser();
|
|
|
|
|
Set<String> roles = userDetail.getRoles();
|
|
|
|
|
if (SecurityUtil.isAdmin() || roles.contains(Constant.ROLE_STATION_MANAGE)) {
|
|
|
|
|
@ -386,7 +395,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkEW(OrderPagingSearchParam orderPagingSearchParam, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
private void checkEW(OrderPagingSearchParam orderPagingSearchParam, Page<OrderPagingResult> page, QueryWrapper<OrderPagingResult> ew) {
|
|
|
|
|
MyResult userDetail = SecurityUtil.loginUser();
|
|
|
|
|
BizObj bizObj = userDetail.getBizObj();
|
|
|
|
|
if (BizObj.isSiBang(bizObj)) {
|
|
|
|
|
@ -557,9 +566,12 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
this.updateById(new OrderInfoEntity()
|
|
|
|
|
.setId(orderId)
|
|
|
|
|
.setCheckPhoto(checkGoodsParam.getCheckPhoto())
|
|
|
|
|
.setCheckTime(LocalDateTime.now())
|
|
|
|
|
.setCheckStatus(CheckStatus.YiKanLiao)
|
|
|
|
|
.setCheckerId(SecurityUtil.currentUserId())
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
truckLeaving(new TruckLeavingOrderParam().setOrderId(orderId), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@ -584,6 +596,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
this.updateById(new OrderInfoEntity()
|
|
|
|
|
.setId(orderInfo.getId())
|
|
|
|
|
.setDriverId(driverId)
|
|
|
|
|
.setAssignmentDriverTime(LocalDateTime.now())
|
|
|
|
|
.setOrderStatus(OrderStatus.DaiJieDan)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
@ -598,6 +611,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
this.updateById(new OrderInfoEntity()
|
|
|
|
|
.setId(orderInfoId)
|
|
|
|
|
.setTransCompanyId(transCompanyId)
|
|
|
|
|
.setAssignmentTransTime(LocalDateTime.now())
|
|
|
|
|
.setOrderStatus(OrderStatus.DaiPaiDan)
|
|
|
|
|
);
|
|
|
|
|
OrderInfoEntity orderInfoEntity = this.getById(orderInfoId);
|
|
|
|
|
@ -632,6 +646,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
}
|
|
|
|
|
this.updateById(new OrderInfoEntity()
|
|
|
|
|
.setId(orderInfo.getId())
|
|
|
|
|
.setDriverConfirmTime(LocalDateTime.now())
|
|
|
|
|
.setAuditStatus(auditStatus)
|
|
|
|
|
.setTruckId(truckId)
|
|
|
|
|
.setOrderStatus(OrderStatus.YiJieDan)
|
|
|
|
|
@ -736,6 +751,8 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
Assert.isTrue(orderStatus == OrderStatus.YiYuYue
|
|
|
|
|
|| orderStatus == OrderStatus.DaiPaiDan
|
|
|
|
|
|| orderStatus == OrderStatus.DaiJieDan, () -> Exceptions.clierr("当前订单状态,无法取消"));
|
|
|
|
|
AuditStatus auditStatus = orderInfo.getAuditStatus();
|
|
|
|
|
Assert.isFalse(auditStatus == AuditStatus.TongGuo || auditStatus == AuditStatus.BoHui, () -> Exceptions.clierr("当前订单状态,无法取消"));
|
|
|
|
|
this.updateById(new OrderInfoEntity()
|
|
|
|
|
.setId(orderInfo.getId())
|
|
|
|
|
.setOrderStatus(OrderStatus.YiQuXiao)
|
|
|
|
|
@ -1080,4 +1097,60 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|
|
|
|
OrderPagingResult orderDetail = detail(orderId);
|
|
|
|
|
return BeanUtil.copyProperties(orderDetail, TrainBillResult.class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void batchAdd(AddOrderInfoParam addOrderInfoParam) {
|
|
|
|
|
Integer truckCount = addOrderInfoParam.getTruckCount();
|
|
|
|
|
CountDownLatch latch = new CountDownLatch(truckCount);
|
|
|
|
|
AtomicBoolean hasError = new AtomicBoolean(false);
|
|
|
|
|
List<TransactionStatus> transactionStatuses = new CopyOnWriteArrayList<>();
|
|
|
|
|
for (int i = 0; i < truckCount; i++) {
|
|
|
|
|
CompletableFuture.runAsync(() -> {
|
|
|
|
|
// 每个线程创建独立事务
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|