|
|
@@ -21,16 +21,9 @@ import com.ruoyi.common.core.validate.QueryGroup;
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
import com.ruoyi.common.enums.FilePathSplicingType;
|
|
|
import com.ruoyi.common.enums.order.OrderType;
|
|
|
-import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.excel.ExcelResult;
|
|
|
import com.ruoyi.common.filepathsplicing.FilePathSplicing;
|
|
|
-import com.ruoyi.common.utils.importverify.ImportVerifyHandler;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
-import com.ruoyi.common.utils.poi.ImportUtil;
|
|
|
-import com.ruoyi.message.domain.bo.MessageBo;
|
|
|
-import com.ruoyi.message.enums.MessageType;
|
|
|
-import com.ruoyi.message.enums.ModelType;
|
|
|
-import com.ruoyi.message.service.ISendPrivateMessageMsgService;
|
|
|
-import com.ruoyi.shop.order.domain.ShopOrderPackage;
|
|
|
import com.ruoyi.shop.order.domain.bo.BusinessCountBo;
|
|
|
import com.ruoyi.shop.order.domain.bo.ShopOrderBo;
|
|
|
import com.ruoyi.shop.order.domain.bo.ShopOrderBusinessRemarkBo;
|
|
|
@@ -39,20 +32,16 @@ import com.ruoyi.shop.order.enums.CancellationMethod;
|
|
|
import com.ruoyi.shop.order.enums.ShippingMethod;
|
|
|
import com.ruoyi.shop.order.enums.ShippingStatus;
|
|
|
import com.ruoyi.shop.order.enums.TransactionStatus;
|
|
|
-import com.ruoyi.shop.order.service.IShopOrderPackageService;
|
|
|
import com.ruoyi.shop.order.service.IShopOrderService;
|
|
|
-import com.ruoyi.shop.order.service.mqproduct.IShopOrderMqProductService;
|
|
|
+import com.ruoyi.shop.order.service.ShopOrderWaitShipImportListener;
|
|
|
import com.ruoyi.shop.rights.service.ISaleRightsOrderService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
-import jodd.util.StringUtil;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.Workbook;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
@@ -64,7 +53,8 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -85,11 +75,6 @@ public class ShopOrderController extends BaseController {
|
|
|
private final ISaleRightsOrderService rightsOrderService;
|
|
|
private final IBusinessService iBusinessService;
|
|
|
private final ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
- private final ImportVerifyHandler importVerifyHandler;
|
|
|
- private final ThreadPoolExecutor executor;
|
|
|
- private final IShopOrderPackageService shopOrderPackageService;
|
|
|
- private final IShopOrderMqProductService shopOrderMqProductService;
|
|
|
- private final ISendPrivateMessageMsgService sendPrivateMessageMsgService;
|
|
|
|
|
|
/**
|
|
|
* 平台分页查询订单列表
|
|
|
@@ -598,73 +583,15 @@ public class ShopOrderController extends BaseController {
|
|
|
/**
|
|
|
* 导入设置好的发货订单文件,批量发货
|
|
|
* @param multipartFile
|
|
|
- * @param response
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@PostMapping("/import_ship")
|
|
|
- public R importUser(@RequestParam("file") MultipartFile multipartFile, HttpServletResponse response) throws Exception {
|
|
|
+ public R<Void> importShip(@RequestParam("file") MultipartFile multipartFile) throws Exception {
|
|
|
Long businessId = getBusinessId(true);
|
|
|
//获得excel中的数据
|
|
|
- Map<String, Object> map = ImportUtil.importExcel(1, 1, ShopOrderWaitShipVo.class, importVerifyHandler, multipartFile, true);
|
|
|
- List<ShopOrderWaitShipVo> importList = (List<ShopOrderWaitShipVo>) map.get("success");
|
|
|
- // 创建 Future 集合,用来存储 Future 实例
|
|
|
- List<Future<ShopOrderWaitShipVo>> futureList = new ArrayList<>();
|
|
|
- if (!CollectionUtils.isEmpty(importList)) {
|
|
|
- if (importList.size() > 0) {
|
|
|
- importList.forEach(importRow -> {
|
|
|
- if (StringUtils.isNotEmpty(importRow.getLogisticCode())) {
|
|
|
- //批量导入数据库
|
|
|
- Future<ShopOrderWaitShipVo> future = executor.submit(new Callable<ShopOrderWaitShipVo>() {
|
|
|
- @Override
|
|
|
- public ShopOrderWaitShipVo call() throws Exception {
|
|
|
- if (StringUtils.isEmpty(importRow.getLogisticCode())) {
|
|
|
- importRow.setErrorMsg("运单号没有填");
|
|
|
- return importRow;
|
|
|
- }
|
|
|
- try {
|
|
|
- ShopOrderPackage shopOrderPackage = shopOrderPackageService.expressShipForImport(businessId, importRow);
|
|
|
- try
|
|
|
- {
|
|
|
- // 发送自动收货消息
|
|
|
- shopOrderMqProductService.orderPackageReceivingMqProductSend(shopOrderPackage.getPackageId());
|
|
|
- // 发送物流消息
|
|
|
- sendPrivateMessageMsgService.send(new MessageBo(MessageType.LOGISTICS_MESSAGE,
|
|
|
- ModelType.LOGISTICS, shopOrderPackage.getPackageId()));
|
|
|
- }
|
|
|
- catch (Exception e)
|
|
|
- {
|
|
|
- log.error("MQ发送自动收货消息失败", e);
|
|
|
- }
|
|
|
- } catch (Exception ex) {
|
|
|
- importRow.setErrorMsg(ex.getMessage());
|
|
|
- return importRow;
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
- });
|
|
|
- futureList.add(future);
|
|
|
- }
|
|
|
- });
|
|
|
- List<ShopOrderWaitShipVo> resultList = new ArrayList<>();
|
|
|
- for (Future<ShopOrderWaitShipVo> future : futureList) {
|
|
|
- // 获取每一个线程的返回结果,如果该线程未完成,会阻塞
|
|
|
- ShopOrderWaitShipVo vo = future.get(30, TimeUnit.SECONDS);
|
|
|
- if (vo != null) {
|
|
|
- resultList.add(vo);
|
|
|
- }
|
|
|
- }
|
|
|
- StringBuffer sbf = new StringBuffer();
|
|
|
- resultList.forEach(e ->
|
|
|
- {
|
|
|
- sbf.append("第" + (e.getRowNum() + 1) + "行存在错误:" + e.getErrorMsg()+"");
|
|
|
- });
|
|
|
- if (StringUtil.isNotEmpty(sbf.toString())) {
|
|
|
- throw new ServiceException(sbf.toString());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return R.ok();
|
|
|
+ ExcelResult<ShopOrderWaitShipVo> result = ExcelUtil.importExcel(multipartFile.getInputStream(), ShopOrderWaitShipVo.class, new ShopOrderWaitShipImportListener(businessId));
|
|
|
+ return R.ok(result.getAnalysis());
|
|
|
}
|
|
|
|
|
|
/**
|