|
|
@@ -3,23 +3,26 @@ package com.ruoyi.logistics.service.impl;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.serializer.SerializerFeature;
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.ruoyi.common.core.exception.ServiceException;
|
|
|
import com.ruoyi.common.core.utils.DateUtils;
|
|
|
+import com.ruoyi.common.core.utils.StringUtils;
|
|
|
import com.ruoyi.common.datascope.annotation.DataScope;
|
|
|
import com.ruoyi.common.redis.service.RedisIdGenerator;
|
|
|
import com.ruoyi.common.security.utils.SecurityUtils;
|
|
|
+import com.ruoyi.logistics.constant.JDDictConstants;
|
|
|
import com.ruoyi.logistics.constant.RedisCacheConstants;
|
|
|
import com.ruoyi.logistics.domain.BizAddressBook;
|
|
|
import com.ruoyi.logistics.domain.BizWaybillCostDetails;
|
|
|
+import com.ruoyi.logistics.domain.SysDeptRate;
|
|
|
import com.ruoyi.logistics.domain.dto.OrderStatisticsDto;
|
|
|
import com.ruoyi.logistics.domain.dto.RecentAddressDto;
|
|
|
import com.ruoyi.logistics.domain.dto.JDOrderDTO;
|
|
|
@@ -66,6 +69,9 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
|
|
|
@Autowired
|
|
|
private BizAddressBookMapper bizAddressBookMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysDeptRateServiceImpl sysDeptRateService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询运单管理
|
|
|
*
|
|
|
@@ -366,15 +372,23 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
|
|
|
* @return 结果数组,每个元素表示对应订单的结果 [0:成功数,1:失败数]
|
|
|
*/
|
|
|
@Override
|
|
|
- public int[] batchInsertJDBizWaybillOrder(List<JDOrderDTO> orderList, Integer orderType) {
|
|
|
+ public int batchInsertJDBizWaybillOrder(List<JDOrderDTO> orderList, Integer orderType) {
|
|
|
int successCount = 0;
|
|
|
int failCount = 0;
|
|
|
List<String> errorMessages = new ArrayList<>();
|
|
|
|
|
|
LoginUser loginUser = SecurityUtils.getLoginUser();
|
|
|
|
|
|
+ SysDeptRate sysDeptRate = new SysDeptRate();
|
|
|
+ sysDeptRate.setDeptId(loginUser.getSysUser().getDeptId());
|
|
|
+ List<SysDeptRate> sysDeptRates = sysDeptRateService.selectSysDeptRateList(sysDeptRate);
|
|
|
+ Set<String> collect = sysDeptRates.stream().map(SysDeptRate::getProductType).collect(Collectors.toSet());
|
|
|
+
|
|
|
+ List<BizWaybillOrder> bizWaybillOrders = new ArrayList<>();
|
|
|
for (JDOrderDTO dto : orderList) {
|
|
|
try {
|
|
|
+ preDataVerify(dto, collect);
|
|
|
+
|
|
|
// 将 JDOrderDTO 转换为 BizWaybillOrder
|
|
|
BizWaybillOrder bizWaybillOrder = convertToBizWaybillOrder(dto, loginUser);
|
|
|
|
|
|
@@ -406,18 +420,8 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
|
|
|
bizWaybillOrder.setUserId(loginUser.getUserid());
|
|
|
bizWaybillOrder.setDeptId(loginUser.getSysUser().getDeptId());
|
|
|
|
|
|
- // 保存到数据库
|
|
|
- int result = bizWaybillOrderMapper.insertBizWaybillOrder(bizWaybillOrder);
|
|
|
- if (result > 0) {
|
|
|
- successCount++;
|
|
|
- // 保存最近使用地址
|
|
|
- saveRecentAddresses(bizWaybillOrder, loginUser.getUserid());
|
|
|
- } else {
|
|
|
- failCount++;
|
|
|
- errorMessages.add(String.format("订单 %s-%s 保存失败",
|
|
|
- dto.getSenderName(), dto.getReceiverName()));
|
|
|
- }
|
|
|
|
|
|
+ bizWaybillOrders.add(bizWaybillOrder);
|
|
|
} catch (Exception e) {
|
|
|
log.error("批量下单异常!发件人:{}, 收件人:{}",
|
|
|
dto.getSenderName(), dto.getReceiverName(), e);
|
|
|
@@ -427,9 +431,73 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- log.info("批量下单完成!总数:{}, 成功:{}, 失败:{}", orderList.size(), successCount, failCount);
|
|
|
+ if (failCount > 0) {
|
|
|
+ throw new ServiceException("批量下单失败!失败原因:" + StringUtils.join(errorMessages, "\n"));
|
|
|
+ }
|
|
|
+
|
|
|
+ bizWaybillOrders.forEach(bizWaybillOrder -> {
|
|
|
+ // 保存到数据库
|
|
|
+ bizWaybillOrderMapper.insertBizWaybillOrder(bizWaybillOrder);
|
|
|
+ });
|
|
|
+ return bizWaybillOrders.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void preDataVerify(JDOrderDTO dto, Set<String> collect) {
|
|
|
+ if (dto == null) {
|
|
|
+ throw new ServiceException("数据异常!订单数据不能为空");
|
|
|
+ }
|
|
|
|
|
|
- return new int[]{successCount, failCount};
|
|
|
+ // 校验寄件人信息
|
|
|
+ if (StringUtils.isBlank(dto.getSenderName())) {
|
|
|
+ throw new ServiceException("数据异常!寄件人姓名不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSenderPhone())) {
|
|
|
+ throw new ServiceException("数据异常!寄件人电话不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getSenderAddress())) {
|
|
|
+ throw new ServiceException("数据异常!寄件详细地址不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验收件人信息
|
|
|
+ if (StringUtils.isBlank(dto.getReceiverName())) {
|
|
|
+ throw new ServiceException("数据异常!收件人姓名不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getReceiverPhone())) {
|
|
|
+ throw new ServiceException("数据异常!收件人电话不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(dto.getReceiverAddress())) {
|
|
|
+ throw new ServiceException("数据异常!收件详细地址不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验货物信息
|
|
|
+ if (StringUtils.isBlank(dto.getGoodsName())) {
|
|
|
+ throw new ServiceException("数据异常!物品名称不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getGoodsWeight() == null) {
|
|
|
+ throw new ServiceException("数据异常!物品重量不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getGoodsVolume() == null) {
|
|
|
+ throw new ServiceException("数据异常!物品体积不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getGoodsQty() == null) {
|
|
|
+ throw new ServiceException("数据异常!物品数量不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验取件时间
|
|
|
+ if (dto.getSendStartTime() == null || dto.getSendEndTime() == null) {
|
|
|
+ throw new ServiceException("数据异常!上门取件开始时间和结束时间不能为空");
|
|
|
+ }
|
|
|
+ if (dto.getSendStartTime().after(dto.getSendEndTime())) {
|
|
|
+ throw new ServiceException("数据异常!上门取件开始时间不能晚于结束时间");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验产品类型
|
|
|
+ if (StringUtils.isBlank(dto.getProductCode())) {
|
|
|
+ throw new ServiceException("数据异常!产品类型不能为空");
|
|
|
+ }
|
|
|
+ if (!collect.contains(dto.getProductCode())) {
|
|
|
+ throw new ServiceException("数据异常!产品类型不存在");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -475,4 +543,37 @@ public class BizWaybillOrderServiceImpl implements IBizWaybillOrderService
|
|
|
|
|
|
return bizWaybillOrder;
|
|
|
}
|
|
|
+
|
|
|
+ private static String getProductCode(String productName) {
|
|
|
+ if (productName == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (productName.equals("京东标快")) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_ED_M_0001;
|
|
|
+ }
|
|
|
+ if (productName.equals("京东特快")) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_ED_M_0002;
|
|
|
+ }
|
|
|
+ if (productName.equals("特快重货")) {
|
|
|
+ return JDDictConstants.PRODUCT_CODE_FR_M_0004;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String getAddedService(JDOrderDTO dto) {
|
|
|
+ JSONObject addedService = new JSONObject();
|
|
|
+ addedService.put("isPack", null);
|
|
|
+ addedService.put("guaranteeMoney", null);
|
|
|
+ addedService.put("isReceiptCollect", null);
|
|
|
+ if ("是".equals(dto.getIsPack())) {
|
|
|
+ addedService.put("isPack", true);
|
|
|
+ }
|
|
|
+ if (null != dto.getGuaranteeMoney()) {
|
|
|
+ addedService.put("guaranteeMoney", dto.getGuaranteeMoney());
|
|
|
+ }
|
|
|
+ if ("是".equals(dto.getIsPack())) {
|
|
|
+ addedService.put("isReceiptCollect", true);
|
|
|
+ }
|
|
|
+ return JSON.toJSONString(addedService, SerializerFeature.WriteMapNullValue);
|
|
|
+ }
|
|
|
}
|