|
|
@@ -20,29 +20,42 @@ import com.ruoyi.common.core.validate.AddGroup;
|
|
|
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.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;
|
|
|
import com.ruoyi.shop.order.domain.vo.*;
|
|
|
-import com.ruoyi.common.enums.order.OrderType;
|
|
|
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.product.domain.bo.ProductBo;
|
|
|
-import com.ruoyi.shop.product.domain.vo.ProductVo;
|
|
|
+import com.ruoyi.shop.order.service.mqproduct.IShopOrderMqProductService;
|
|
|
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;
|
|
|
|
|
|
import javax.activation.MimetypesFileTypeMap;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
@@ -51,8 +64,7 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CompletableFuture;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -61,6 +73,7 @@ import java.util.stream.Collectors;
|
|
|
* @author lubo
|
|
|
* @date 2025-10-23
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Validated
|
|
|
@Api(value = "订单控制器", tags = {"订单管理"})
|
|
|
@RequiredArgsConstructor
|
|
|
@@ -71,8 +84,12 @@ public class ShopOrderController extends BaseController {
|
|
|
private final IShopOrderService iShopOrderService;
|
|
|
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;
|
|
|
|
|
|
/**
|
|
|
* 平台分页查询订单列表
|
|
|
@@ -578,6 +595,78 @@ public class ShopOrderController extends BaseController {
|
|
|
ExcelUtil.exportExcel(list, "待发货列表", ShopOrderWaitShipVo.class, response);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导入设置好的发货订单文件,批量发货
|
|
|
+ * @param multipartFile
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/import_ship")
|
|
|
+ public R importUser(@RequestParam("file") MultipartFile multipartFile, HttpServletResponse response) 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();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 总店导出连锁店订单列表
|
|
|
*/
|