|
@@ -0,0 +1,117 @@
|
|
|
+package com.zbkj.service.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.zbkj.common.constants.OrderStatusConstants;
|
|
|
+import com.zbkj.common.constants.SysConfigConstants;
|
|
|
+import com.zbkj.common.model.express.ExpressOrder;
|
|
|
+import com.zbkj.common.model.secondhand.SecondHandOrder;
|
|
|
+import com.zbkj.service.service.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.support.TransactionTemplate;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * StoreOrderServiceImpl 接口实现
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ * | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ * | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ * | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ * | Author: CRMEB Team <admin@crmeb.com>
|
|
|
+ * +----------------------------------------------------------------------
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ExpressTaskServiceImpl implements ExpressTaskService {
|
|
|
+ //日志
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(ExpressTaskServiceImpl.class);
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderStatusService orderStatusService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TransactionTemplate transactionTemplate;
|
|
|
+ @Autowired
|
|
|
+ private SystemConfigService systemConfigService;
|
|
|
+ @Autowired
|
|
|
+ private ExpressOrderDetailService orderDetailService;
|
|
|
+ @Autowired
|
|
|
+ private RiderOrderService riderOrderService;
|
|
|
+ @Autowired
|
|
|
+ private ExpressOrderService expressOrderService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void autoComplete() {
|
|
|
+ Integer autoCompleteDay = Integer.parseInt(systemConfigService.getValueByKey(SysConfigConstants.CONFIG_ORDER_AUTO_COMPLETE_DAY));
|
|
|
+ List<ExpressOrder> orderList = expressOrderService.findCanCompleteOrder(autoCompleteDay);
|
|
|
+ if (CollUtil.isEmpty(orderList)) {
|
|
|
+ logger.info("OrderTaskServiceImpl.autoComplete | size:0");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> orderNoList = orderList.stream().map(ExpressOrder::getOrderNo).collect(Collectors.toList());
|
|
|
+ Boolean execute = transactionTemplate.execute(e -> {
|
|
|
+ expressOrderService.batchCompleteByOrderNo(orderNoList);
|
|
|
+ orderNoList.forEach(orderNo -> {
|
|
|
+ orderStatusService.createLog(orderNo, OrderStatusConstants.ORDER_STATUS_COMPLETE, "订单已完成");
|
|
|
+ });
|
|
|
+ return Boolean.TRUE;
|
|
|
+ });
|
|
|
+ if (!execute) {
|
|
|
+ logger.error("取件订单自动完成:更新数据库失败,orderNoList = {}", JSON.toJSONString(orderNoList));
|
|
|
+ }else {
|
|
|
+ //后续操作放入redis
|
|
|
+ orderNoList.forEach(orderNo -> {
|
|
|
+ riderOrderService.addBalance(orderNo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void autoTakeDelivery() {
|
|
|
+ int day = 2;
|
|
|
+ String autoDay = systemConfigService.getValueByKey(SysConfigConstants.CONFIG_ORDER_AUTO_TAKE_DELIVERY_DAY);
|
|
|
+ if (StrUtil.isNotBlank(autoDay) && Integer.parseInt(autoDay) >= 1) {
|
|
|
+ day = Integer.parseInt(autoDay);
|
|
|
+ }
|
|
|
+ DateTime nowDate = DateUtil.date();
|
|
|
+ DateTime dateTime = DateUtil.offsetDay(nowDate, -day);
|
|
|
+ List<ExpressOrder> orderList = expressOrderService.findAwaitTakeDeliveryOrderList(dateTime.toString());
|
|
|
+ if (CollUtil.isEmpty(orderList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ orderList = orderList.stream().filter(order -> !order.getType().equals(1)).collect(Collectors.toList());
|
|
|
+ if (CollUtil.isEmpty(orderList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<String> orderNoList = orderList.stream().map(ExpressOrder::getOrderNo).collect(Collectors.toList());
|
|
|
+ Boolean execute = transactionTemplate.execute(e -> {
|
|
|
+ orderNoList.forEach(orderNo -> {
|
|
|
+ expressOrderService.takeDelivery(orderNo);
|
|
|
+ orderDetailService.takeDelivery(orderNo);
|
|
|
+ orderStatusService.createLog(orderNo, OrderStatusConstants.ORDER_STATUS_USER_TAKE_DELIVERY, OrderStatusConstants.ORDER_LOG_SYSTEM_AUTO_RECEIPT);
|
|
|
+ });
|
|
|
+ return Boolean.TRUE;
|
|
|
+ });
|
|
|
+ if (!execute) {
|
|
|
+ logger.error("快递自动收件操作数据数失败:订单号:{}", StringUtils.join(orderNoList, ","));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //后续操作放入redis
|
|
|
+ orderNoList.forEach(orderNo -> {
|
|
|
+ // redisUtil.lPush(TaskConstants.ORDER_TASK_REDIS_KEY_AFTER_TAKE_BY_USER, orderNo);
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|