|
|
@@ -1,11 +1,19 @@
|
|
|
package com.sckw.transport.service;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.sckw.core.common.enums.NumberConstant;
|
|
|
+import com.sckw.core.utils.BeanUtils;
|
|
|
import com.sckw.core.utils.CollectionUtils;
|
|
|
import com.sckw.core.web.constant.HttpStatus;
|
|
|
+import com.sckw.core.web.context.LoginUserHolder;
|
|
|
import com.sckw.core.web.response.HttpResult;
|
|
|
+import com.sckw.excel.utils.ValidUtil;
|
|
|
+import com.sckw.mongo.enums.BusinessTypeEnum;
|
|
|
+import com.sckw.mongo.model.SckwWaybillOrder;
|
|
|
import com.sckw.mongo.model.TobleTop;
|
|
|
+import com.sckw.stream.model.SckwBusSum;
|
|
|
import com.sckw.system.api.RemoteSystemService;
|
|
|
import com.sckw.transport.common.enums.CarWaybillEnum;
|
|
|
import com.sckw.transport.dao.*;
|
|
|
@@ -13,14 +21,20 @@ import com.sckw.transport.model.KwtLogisticsOrderAddress;
|
|
|
import com.sckw.transport.model.KwtLogisticsOrderCirculate;
|
|
|
import com.sckw.transport.model.KwtLogisticsOrderGoods;
|
|
|
import com.sckw.transport.model.KwtWaybillOrder;
|
|
|
+import com.sckw.transport.model.dto.UpdateDriverCarDTO;
|
|
|
import com.sckw.transport.model.vo.WaybillOrderVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cloud.stream.function.StreamBridge;
|
|
|
+import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -36,6 +50,12 @@ public class DriverService {
|
|
|
@DubboReference(version = "2.0.0", group = "design", check = false)
|
|
|
RemoteSystemService remoteSystemService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ MongoTemplate mongoTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ StreamBridge streamBridge;
|
|
|
+
|
|
|
@Autowired
|
|
|
private KwtWaybillOrderMapper waybillOrderMapper;
|
|
|
|
|
|
@@ -153,17 +173,18 @@ public class DriverService {
|
|
|
/**趟次*/
|
|
|
tripPackageData(id, tripStatus, orderVOList);
|
|
|
/**循环*/
|
|
|
- loopPackageData(id,loopStatus,orderVOList);
|
|
|
+ loopPackageData(id, loopStatus, orderVOList);
|
|
|
orderVOList = orderVOList.stream().sorted(Comparator.comparing(WaybillOrderVO::getCreateTime)).collect(Collectors.toList());
|
|
|
return HttpResult.ok(orderVOList);
|
|
|
}
|
|
|
+
|
|
|
private void loopPackageData(Long id, List<Long> loopStatus, List<WaybillOrderVO> orderVOList) {
|
|
|
- if(CollectionUtils.isEmpty(loopStatus)){
|
|
|
+ if (CollectionUtils.isEmpty(loopStatus)) {
|
|
|
List<KwtLogisticsOrderCirculate> list = logisticsOrderCirculateMapper.selectList(new LambdaQueryWrapper<KwtLogisticsOrderCirculate>()
|
|
|
- .eq(KwtLogisticsOrderCirculate::getDriverId,id)
|
|
|
+ .eq(KwtLogisticsOrderCirculate::getDriverId, id)
|
|
|
.isNull(KwtLogisticsOrderCirculate::getWOrderId)
|
|
|
- .eq(KwtLogisticsOrderCirculate::getStatus,NumberConstant.ZERO));
|
|
|
- if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ .eq(KwtLogisticsOrderCirculate::getStatus, NumberConstant.ZERO));
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
for (KwtLogisticsOrderCirculate circulate : list) {
|
|
|
KwtLogisticsOrderAddress loadAddress = logisticsOrderAddressMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
|
|
|
.eq(KwtLogisticsOrderAddress::getLOrderId, circulate.getLOrderId()).eq(KwtLogisticsOrderAddress::getAddressType, NumberConstant.ONE));
|
|
|
@@ -201,9 +222,9 @@ public class DriverService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
List<Long> list = logisticsOrderCirculateMapper.selectDriverOrderByStatus(id, loopStatus);
|
|
|
- if (CollectionUtils.isNotEmpty(list)){
|
|
|
+ if (CollectionUtils.isNotEmpty(list)) {
|
|
|
for (Long aLong : list) {
|
|
|
KwtLogisticsOrderAddress loadAddress = logisticsOrderAddressMapper.selectOne(new LambdaQueryWrapper<KwtLogisticsOrderAddress>()
|
|
|
.eq(KwtLogisticsOrderAddress::getLOrderId, aLong).eq(KwtLogisticsOrderAddress::getAddressType, NumberConstant.ONE));
|
|
|
@@ -285,4 +306,92 @@ public class DriverService {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更换司机
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public HttpResult updateDriver(UpdateDriverCarDTO dto) {
|
|
|
+ HttpResult httpResult = new HttpResult();
|
|
|
+ httpResult.setCode(HttpStatus.SUCCESS_CODE);
|
|
|
+ HttpResult result = ValidUtil.serviceValid(dto);
|
|
|
+ if (HttpStatus.SUCCESS_CODE != result.getCode()) {
|
|
|
+ httpResult.setCode(HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ httpResult.setMsg(result.getMsg());
|
|
|
+ return httpResult;
|
|
|
+ }
|
|
|
+ /**【不分循环趟次】更换司机:【待接单】、【待出车】、【已出车】、【到达装货地点】、【已装货】、【到达卸货地点】可修改*/
|
|
|
+ //更换司机(趟次派车(-卸货前)/循环派车(接单后-卸货前))
|
|
|
+ KwtWaybillOrder waybillOrder = waybillOrderMapper.selectOne(new LambdaQueryWrapper<KwtWaybillOrder>()
|
|
|
+ .eq(KwtWaybillOrder::getStatus, dto.getWOrderId()));
|
|
|
+ if (ObjectUtils.isEmpty(waybillOrder)) {
|
|
|
+ throw new RuntimeException("运单不存在:" + dto.getWOrderNo());
|
|
|
+ }
|
|
|
+ if (waybillOrder.getStatus() > CarWaybillEnum.COMPLETION_UNLOADING.getCode()
|
|
|
+ || waybillOrder.getStatus() <= CarWaybillEnum.PENDING_ORDER.getCode()) {
|
|
|
+ throw new RuntimeException("该【" + dto.getWOrderNo() + "】运单不满足更换司机条件");
|
|
|
+ }
|
|
|
+ waybillOrderMapper.update(null, new LambdaUpdateWrapper<KwtWaybillOrder>()
|
|
|
+ .eq(KwtWaybillOrder::getId, dto.getWOrderId())
|
|
|
+ .set(KwtWaybillOrder::getDriverId, dto.getDriverId())
|
|
|
+ .set(KwtWaybillOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtWaybillOrder::getUpdateTime, new Date()));
|
|
|
+ SckwWaybillOrder sckwWaybillOrder = mongoTemplate.findById(dto.getWOrderId(), SckwWaybillOrder.class);
|
|
|
+ //更新mongodb
|
|
|
+ SckwWaybillOrder updateParam = BeanUtils.copyProperties(sckwWaybillOrder, SckwWaybillOrder.class);
|
|
|
+ updateParam.setDriverId(Long.valueOf(dto.getDriverId())).setDriverPhone(dto.getDriverPhone()).setDriverName(dto.getDriverName())
|
|
|
+ .setDriverIdcard(dto.getDriverIdCard()).setTruckId(dto.getTruckId()).setTruckNo(dto.getTruckNo()).setUpdateTime(new Date()).setUpdateBy(LoginUserHolder.getUserId())
|
|
|
+ .setUpdateByName(LoginUserHolder.getUserName()).setUpdateTime(new Date());
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.WAYBILL_ORDER_TYPE.getName());
|
|
|
+ busSum.setMethod(NumberConstant.TWO);
|
|
|
+ busSum.setObject(updateParam);
|
|
|
+ streamBridge.send("sckw-busSum", JSON.toJSONString(busSum));
|
|
|
+ return httpResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 承运订单-更换车辆
|
|
|
+ *
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public HttpResult updateCarCommit(UpdateDriverCarDTO dto) {
|
|
|
+ HttpResult httpResult = new HttpResult();
|
|
|
+ httpResult.setCode(HttpStatus.SUCCESS_CODE);
|
|
|
+ HttpResult result = ValidUtil.serviceValid(dto);
|
|
|
+ if (HttpStatus.SUCCESS_CODE != result.getCode()) {
|
|
|
+ httpResult.setCode(HttpStatus.GLOBAL_EXCEPTION_CODE);
|
|
|
+ httpResult.setMsg(result.getMsg());
|
|
|
+ return httpResult;
|
|
|
+ }
|
|
|
+ /**【不分循环趟次】更换车辆:【待接单】、【待出车】可修改*/
|
|
|
+ KwtWaybillOrder waybillOrder = waybillOrderMapper.selectOne(new LambdaQueryWrapper<KwtWaybillOrder>()
|
|
|
+ .eq(KwtWaybillOrder::getStatus, dto.getWOrderId()));
|
|
|
+ if (ObjectUtils.isEmpty(waybillOrder)) {
|
|
|
+ throw new RuntimeException("运单不存在:" + dto.getWOrderNo());
|
|
|
+ }
|
|
|
+ if (waybillOrder.getStatus() > CarWaybillEnum.PENDING_VEHICLE.getCode()) {
|
|
|
+ throw new RuntimeException("该【" + dto.getWOrderNo() + "】运单不满足更换车辆条件");
|
|
|
+ }
|
|
|
+ waybillOrderMapper.update(null, new LambdaUpdateWrapper<KwtWaybillOrder>()
|
|
|
+ .eq(KwtWaybillOrder::getId, dto.getWOrderId())
|
|
|
+ .set(KwtWaybillOrder::getTruckNo, dto.getTruckNo())
|
|
|
+ .set(KwtWaybillOrder::getUpdateBy, LoginUserHolder.getUserId())
|
|
|
+ .set(KwtWaybillOrder::getUpdateTime, new Date()));
|
|
|
+ SckwWaybillOrder sckwWaybillOrder = mongoTemplate.findById(dto.getWOrderId(), SckwWaybillOrder.class);
|
|
|
+ //更新mongodb
|
|
|
+ SckwWaybillOrder updateParam = BeanUtils.copyProperties(sckwWaybillOrder, SckwWaybillOrder.class);
|
|
|
+ updateParam.setTruckId(dto.getTruckId()).setTruckNo(dto.getTruckNo()).setTruckType(Integer.valueOf(dto.getCarType())).setUpdateTime(new Date()).setUpdateBy(LoginUserHolder.getUserId())
|
|
|
+ .setUpdateByName(LoginUserHolder.getUserName()).setUpdateTime(new Date());
|
|
|
+ SckwBusSum busSum = new SckwBusSum();
|
|
|
+ busSum.setBusSumType(BusinessTypeEnum.WAYBILL_ORDER_TYPE.getName());
|
|
|
+ busSum.setMethod(NumberConstant.TWO);
|
|
|
+ busSum.setObject(updateParam);
|
|
|
+ streamBridge.send("sckw-busSum", JSON.toJSONString(busSum));
|
|
|
+ return httpResult;
|
|
|
+ }
|
|
|
}
|