|
|
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.sckw.contract.api.RemoteContractService;
|
|
|
import com.sckw.contract.api.model.dto.res.ContractCommonInfoResDto;
|
|
|
import com.sckw.core.common.enums.StringConstant;
|
|
|
@@ -58,10 +59,13 @@ import com.sckw.transport.model.param.DriverParam;
|
|
|
import com.sckw.transport.model.param.LogisticsOrderStatisticsParam;
|
|
|
import com.sckw.transport.model.vo.*;
|
|
|
import com.sckw.transport.model.vo.execlVo.AcceptCarriageOrderExcelVo;
|
|
|
+import com.sckw.transport.repository.*;
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -175,6 +179,12 @@ public class KwtAcceptCarriageOrderService {
|
|
|
@Autowired
|
|
|
public KwtLogisticsOrderLineFreightRateMapper lineFreightRateMapper;
|
|
|
|
|
|
+ private final KwtLogisticsOrderRepository logisticsOrderRepository;
|
|
|
+ private final KwtLogisticsOrderGoodsRepository logisticsOrderGoodsRepository;
|
|
|
+ private final KwtLogisticsOrderUnitRepository logisticsOrderUnitRepository;
|
|
|
+ private final KwtLogisticsOrderContractRepository logisticsOrderContractRepository;
|
|
|
+ private final KwtLogisticsOrderAddressRepository logisticsOrderAddressRepository;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 承运订单-分包托运
|
|
|
@@ -2046,6 +2056,7 @@ public class KwtAcceptCarriageOrderService {
|
|
|
return HttpResult.ok(orderFinishVO);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 承运订单-页面新建订单
|
|
|
*
|
|
|
@@ -3166,5 +3177,226 @@ public class KwtAcceptCarriageOrderService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
+ /*
|
|
|
+ * 物流订单-新建订单
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addLogisticOrder(AddLogisticOrderDTO orderDTO) {
|
|
|
+ log.info("创建物流订单请求参数:{}",JSON.toJSONString(orderDTO));
|
|
|
+ commonService.getRedisGenerateOrderNo();
|
|
|
+ /**生成订单编号*/
|
|
|
+ String lOrderNo = OrderGenerateSeqNoUtils.getSeqNo(RedisOrderGenerateEnum.LOGISTICS_ORDER, OrderRuleEnum.LOGISTICS_ORDER, "2", "0", "0");
|
|
|
+ /**保存新建数据*/
|
|
|
+
|
|
|
+ List<AddLogisticOrderDTO.LogisticInfo> logisticInfo = orderDTO.getLogisticInfo();
|
|
|
+ if (org.apache.commons.collections4.CollectionUtils.isEmpty(logisticInfo)){
|
|
|
+ throw new BusinessException("物流信息不能为空");
|
|
|
+ }
|
|
|
+ List<Long> contractIds = logisticInfo.stream()
|
|
|
+ .filter(x-> org.apache.commons.lang3.StringUtils.isNotBlank(x.getContractId()))
|
|
|
+ .map(x->Long.parseLong(x.getContractId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Map<Long, ContractCommonInfoResDto> longContractCommonInfoResDtoMap = remoteContractService.queryContractBaseInfo(contractIds);
|
|
|
+ if (MapUtils.isEmpty(longContractCommonInfoResDtoMap)) {
|
|
|
+ throw new BusinessException("合同不存在");
|
|
|
+ }
|
|
|
+ //判断是否都已经签约
|
|
|
+ boolean b = longContractCommonInfoResDtoMap.values().stream()
|
|
|
+ .allMatch(x -> Objects.equals(x.getStatus(), ContractStatusEnum.SIGNED.getCode()));
|
|
|
+ if (!b) {
|
|
|
+ throw new BusinessException("请先签约选择的所有物流合同");
|
|
|
+ }
|
|
|
+ List<KwtLogisticsOrder> saveLogisticsOrderList = Lists.newArrayList();
|
|
|
+ List<KwtLogisticsOrderAddress> saveAddressList = Lists.newArrayList();
|
|
|
+ List<KwtLogisticsOrderGoods> savelogOrderGoodsList = Lists.newArrayList();
|
|
|
+ List<KwtLogisticsOrderContract> saveContractList = Lists.newArrayList();
|
|
|
+ List<KwtLogisticsOrderUnit> savelogOrderUnitList = Lists.newArrayList();
|
|
|
+ logisticInfo.forEach(x->{
|
|
|
+ Long lOrderId = new IdWorker(NumberConstant.ONE).nextId();
|
|
|
+ //物流订单信息
|
|
|
+ setLogisticOrderInfo(orderDTO, x, lOrderId, lOrderNo, saveLogisticsOrderList);
|
|
|
+
|
|
|
+ //地址信息
|
|
|
+ setLogisticAddress(orderDTO, x, lOrderId, saveAddressList);
|
|
|
+
|
|
|
+ //商品信息
|
|
|
+ setLogisticGoodsInfo(orderDTO, lOrderId, lOrderNo, savelogOrderGoodsList);
|
|
|
+ //物流订单与合同信息
|
|
|
+ setLogisticContractInfo(x, lOrderId, saveContractList);
|
|
|
+ //企业信息数据
|
|
|
+ setLogisticUnitInfo(orderDTO, x, lOrderId, savelogOrderUnitList);
|
|
|
+
|
|
|
+ });
|
|
|
+ logisticsOrderRepository.saveBatch(saveLogisticsOrderList);
|
|
|
+ logisticsOrderAddressRepository.saveBatch(saveAddressList);
|
|
|
+ logisticsOrderGoodsRepository.saveBatch(savelogOrderGoodsList);
|
|
|
+ logisticsOrderContractRepository.saveBatch(saveContractList);
|
|
|
+ logisticsOrderUnitRepository.saveBatch(savelogOrderUnitList);
|
|
|
+ }
|
|
|
|
|
|
+ private void setLogisticUnitInfo(AddLogisticOrderDTO orderDTO, AddLogisticOrderDTO.LogisticInfo x, Long lOrderId, List<KwtLogisticsOrderUnit> savelogOrderUnitList) {
|
|
|
+ KwtLogisticsOrderUnit consignUnit = new KwtLogisticsOrderUnit();
|
|
|
+ consignUnit.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ consignUnit.setLOrderId(lOrderId);
|
|
|
+ consignUnit.setUnitType(NumberConstant.ONE);
|
|
|
+ consignUnit.setEntId(Long.parseLong(orderDTO.getConsignCompanyId()));
|
|
|
+ List<Long> entIds = new ArrayList<>();
|
|
|
+ entIds.add(Long.parseLong(orderDTO.getConsignCompanyId()));
|
|
|
+ entIds.add(Long.parseLong(x.getAcceptCompanyId()));
|
|
|
+ Map<Long, EntCacheResDto> entMap = remoteSystemService.queryEntTreeByIds(entIds);
|
|
|
+ EntCacheResDto ent = entMap.get(Long.parseLong(orderDTO.getConsignCompanyId()));
|
|
|
+ if (Objects.isNull(ent)) {
|
|
|
+ throw new BusinessException("企业:" + orderDTO.getConsignCompany() + "的一级企业信息不存在!");
|
|
|
+ }
|
|
|
+ consignUnit.setContactsId(Long.parseLong(orderDTO.getConsignContactsId()));
|
|
|
+ consignUnit.setTopEntId(ent.getId());
|
|
|
+ consignUnit.setFirmName(orderDTO.getConsignCompany());
|
|
|
+ consignUnit.setContacts(orderDTO.getConsignContacts());
|
|
|
+ consignUnit.setPhone(orderDTO.getConsignContactPhone());
|
|
|
+// consignUnit.setRemark(orderDTO.getRemark());
|
|
|
+ consignUnit.setStatus(NumberConstant.ZERO);
|
|
|
+ consignUnit.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ consignUnit.setCreateTime(new Date());
|
|
|
+ consignUnit.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ consignUnit.setUpdateTime(new Date());
|
|
|
+ savelogOrderUnitList.add(consignUnit);
|
|
|
+ //承运
|
|
|
+ KwtLogisticsOrderUnit unit = new KwtLogisticsOrderUnit();
|
|
|
+ unit.setId(new IdWorker(NumberConstant.TWO).nextId());
|
|
|
+ unit.setLOrderId(lOrderId);
|
|
|
+ unit.setUnitType(NumberConstant.TWO);
|
|
|
+ unit.setEntId(Long.parseLong(x.getAcceptCompanyId()));
|
|
|
+ EntCacheResDto ent1 = entMap.get(Long.parseLong(x.getAcceptCompanyId()));
|
|
|
+ if (Objects.isNull(ent1)) {
|
|
|
+ throw new BusinessException("企业:" + x.getAcceptCompany() + "的一级企业信息不存在!");
|
|
|
+ }
|
|
|
+ unit.setContactsId(Long.parseLong(x.getAcceptContactsId()));
|
|
|
+ unit.setTopEntId(ent1.getId());
|
|
|
+ unit.setFirmName(x.getAcceptCompany());
|
|
|
+ unit.setContacts(x.getAcceptContacts());
|
|
|
+ unit.setPhone(x.getAcceptContactPhone());
|
|
|
+// unit.setRemark(orderDTO.getRemark());
|
|
|
+ unit.setStatus(NumberConstant.ZERO);
|
|
|
+ unit.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ unit.setCreateTime(new Date());
|
|
|
+ unit.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ unit.setUpdateTime(new Date());
|
|
|
+ savelogOrderUnitList.add(unit);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setLogisticContractInfo(AddLogisticOrderDTO.LogisticInfo x, Long lOrderId, List<KwtLogisticsOrderContract> saveContractList) {
|
|
|
+ KwtLogisticsOrderContract contract = new KwtLogisticsOrderContract();
|
|
|
+ contract.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ contract.setContractId(Long.parseLong(x.getContractId()));
|
|
|
+ contract.setLOrderId(lOrderId);
|
|
|
+ contract.setContractNo(x.getContractNo());
|
|
|
+ contract.setContractName(x.getContractName());
|
|
|
+ contract.setSigningWay(x.getSigningWay());
|
|
|
+ contract.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ contract.setCreateTime(new Date());
|
|
|
+ contract.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ contract.setUpdateTime(new Date());
|
|
|
+ saveContractList.add(contract);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setLogisticGoodsInfo(AddLogisticOrderDTO orderDTO, Long lOrderId, String lOrderNo, List<KwtLogisticsOrderGoods> savelogOrderGoodsList) {
|
|
|
+ KwtLogisticsOrderGoods goods = new KwtLogisticsOrderGoods();
|
|
|
+ goods.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ goods.setLOrderId(lOrderId);
|
|
|
+ goods.setLOrderNo(lOrderNo);
|
|
|
+ goods.setGoodsName(orderDTO.getGoodsName());
|
|
|
+ goods.setGoodsType(orderDTO.getGoodsType());
|
|
|
+ goods.setStatus(NumberConstant.ZERO);
|
|
|
+ goods.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ goods.setCreateTime(new Date());
|
|
|
+ goods.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ goods.setUpdateTime(new Date());
|
|
|
+ savelogOrderGoodsList.add( goods);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setLogisticAddress(AddLogisticOrderDTO orderDTO, AddLogisticOrderDTO.LogisticInfo x, Long lOrderId, List<KwtLogisticsOrderAddress> saveAddressList) {
|
|
|
+ KwtLogisticsOrderAddress loadAddress = new KwtLogisticsOrderAddress();
|
|
|
+ loadAddress.setId(new IdWorker(NumberConstant.ONE).nextId());
|
|
|
+ loadAddress.setLOrderId(lOrderId);
|
|
|
+ loadAddress.setAddressType(NumberConstant.ONE);
|
|
|
+ loadAddress.setName(orderDTO.getLoadName() == null ? null : orderDTO.getLoadName());
|
|
|
+// loadAddress.setType();
|
|
|
+ loadAddress.setContacts(orderDTO.getLoadContacts());
|
|
|
+ loadAddress.setPhone(orderDTO.getLoadPhone());
|
|
|
+ loadAddress.setCityCode(orderDTO.getLoadCityCode());
|
|
|
+ loadAddress.setCityName(orderDTO.getLoadCityName());
|
|
|
+ loadAddress.setDetailAddress(orderDTO.getLoadDetailAddress());
|
|
|
+
|
|
|
+ loadAddress.setEntryType(NumberConstant.FOUR);
|
|
|
+ loadAddress.setStatus(NumberConstant.ZERO);
|
|
|
+ loadAddress.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ Date date1 = new Date();
|
|
|
+ loadAddress.setCreateTime(date1);
|
|
|
+ loadAddress.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ loadAddress.setUpdateTime(date1);
|
|
|
+ saveAddressList.add(loadAddress);
|
|
|
+ KwtLogisticsOrderAddress unloadAddress = new KwtLogisticsOrderAddress();
|
|
|
+ unloadAddress.setId(new IdWorker(NumberConstant.TWO).nextId());
|
|
|
+ unloadAddress.setLOrderId(lOrderId);
|
|
|
+ unloadAddress.setAddressType(NumberConstant.TWO);
|
|
|
+ unloadAddress.setName(x.getUnloadName());
|
|
|
+// unloadAddress.setType();
|
|
|
+ unloadAddress.setContacts(x.getUnloadContacts());
|
|
|
+ unloadAddress.setPhone(x.getUnloadPhone());
|
|
|
+ unloadAddress.setCityCode(x.getUnloadCityCode());
|
|
|
+ unloadAddress.setCityName(x.getUnloadCityName());
|
|
|
+ unloadAddress.setDetailAddress(x.getUnloadDetailAddress());
|
|
|
+ unloadAddress.setEntryType(NumberConstant.FOUR);
|
|
|
+ unloadAddress.setStatus(NumberConstant.ZERO);
|
|
|
+ unloadAddress.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ unloadAddress.setCreateTime(date1);
|
|
|
+ unloadAddress.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ unloadAddress.setUpdateTime(date1);
|
|
|
+ saveAddressList.add(unloadAddress);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void setLogisticOrderInfo(AddLogisticOrderDTO orderDTO, AddLogisticOrderDTO.LogisticInfo x, Long lOrderId, String lOrderNo, List<KwtLogisticsOrder> saveLogisticsOrderList) {
|
|
|
+ KwtLogisticsOrder kwtLogisticsOrder = new KwtLogisticsOrder();
|
|
|
+ kwtLogisticsOrder.setId(lOrderId);
|
|
|
+ kwtLogisticsOrder.setEntId(LoginUserHolder.getEntId());
|
|
|
+ kwtLogisticsOrder.setType(x.getType());
|
|
|
+ kwtLogisticsOrder.setTOrderId(orderDTO.getTradeOrderId());
|
|
|
+ kwtLogisticsOrder.setTOrderNo(orderDTO.getTradeOrderNo());
|
|
|
+ kwtLogisticsOrder.setLOrderNo(lOrderNo);
|
|
|
+ kwtLogisticsOrder.setPid(lOrderId);
|
|
|
+ kwtLogisticsOrder.setPids(lOrderId.toString());
|
|
|
+ kwtLogisticsOrder.setBillingMode(x.getBillingMode());
|
|
|
+ kwtLogisticsOrder.setPrice(x.getPrice());
|
|
|
+ kwtLogisticsOrder.setPriceType(x.getPriceType());
|
|
|
+ kwtLogisticsOrder.setAmount(x.getAmount());
|
|
|
+ kwtLogisticsOrder.setUnit(x.getAmountUnit());
|
|
|
+ kwtLogisticsOrder.setLoss(x.getLoss() == null ? null : x.getLoss());
|
|
|
+ kwtLogisticsOrder.setLossUnit(x.getLossUnit());
|
|
|
+ kwtLogisticsOrder.setGoodsPrice(orderDTO.getGoodsPrice());
|
|
|
+ kwtLogisticsOrder.setGoodsPriceUnit(orderDTO.getGoodsPriceUnit());
|
|
|
+ kwtLogisticsOrder.setStartTime(Objects.isNull(x.getStartTime()) ?
|
|
|
+ null : DateUtil.localDateToLocalDateTimeStart(x.getStartTime()));
|
|
|
+ kwtLogisticsOrder.setEndTime(Objects.isNull(x.getEndTime()) ?
|
|
|
+ null : DateUtil.localDateToLocalDateTimeStart(x.getEndTime()));
|
|
|
+ BigDecimal decimal = BigDecimal.ZERO ;
|
|
|
+ kwtLogisticsOrder.setSubcontractAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setEntrustAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setUnloadAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setLoadAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setIgnoreAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setDeficitAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setDeficitPrice(decimal);
|
|
|
+ kwtLogisticsOrder.setTotalUnloadAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setTotalLoadAmount(decimal);
|
|
|
+ kwtLogisticsOrder.setPayment(x.getPayment());
|
|
|
+ kwtLogisticsOrder.setRemark(x.getRemark());
|
|
|
+ kwtLogisticsOrder.setStatus(LogisticsOrderV1Enum.PENDING_ORDER.getCode());
|
|
|
+ kwtLogisticsOrder.setCreateBy(LoginUserHolder.getUserId());
|
|
|
+ Date date = new Date();
|
|
|
+ kwtLogisticsOrder.setCreateTime(date);
|
|
|
+ kwtLogisticsOrder.setUpdateBy(LoginUserHolder.getUserId());
|
|
|
+ kwtLogisticsOrder.setUpdateTime(date);
|
|
|
+ kwtLogisticsOrder.setBindStatus(String.valueOf(NumberConstant.ZERO));
|
|
|
+ saveLogisticsOrderList.add(kwtLogisticsOrder);
|
|
|
+ }
|
|
|
}
|