优化自动取消订单批次,改为分页
This commit is contained in:
parent
8058773aac
commit
69b195322e
@ -7,6 +7,7 @@ import com.suisung.mall.shop.config.SpringUtil;
|
||||
import com.suisung.mall.shop.distribution.service.ShopDistributionUserOrderService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderBaseService;
|
||||
import com.suisung.mall.shop.order.service.ShopOrderInfoService;
|
||||
import com.suisung.mall.shop.sixun.utils.CommonUtil;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
@ -23,6 +24,8 @@ public class UpdateOrderStatusJob extends QuartzJobBean {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(UpdateOrderStatusJob.class);
|
||||
|
||||
private static final Integer PAGESIZE = 100;
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
ShopOrderBaseService shopOrderBaseService = SpringUtil.getBean(ShopOrderBaseService.class);
|
||||
@ -36,51 +39,52 @@ public class UpdateOrderStatusJob extends QuartzJobBean {
|
||||
//shopOrderBaseService.autoCancelOrder();
|
||||
|
||||
// 更新未付款订单,取消超时订单
|
||||
List<String> order_id_row = shopOrderInfoService.getAutoCancelOrderId();
|
||||
if (CollUtil.isNotEmpty(order_id_row)) {
|
||||
for (String order_id : order_id_row) {
|
||||
try {
|
||||
List<String> ids = Collections.singletonList(order_id);
|
||||
if (!shopOrderBaseService.cancel(ids, null, true)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 取消出错"), order_id));
|
||||
long total = shopOrderInfoService.countgetAutoCancelOrderId();
|
||||
if (total > 0) {
|
||||
int pages = CommonUtil.getPagesCount(Math.toIntExact(total), PAGESIZE);
|
||||
for (int i = 1; i <= pages; i++) {
|
||||
List<String> order_id_row = shopOrderInfoService.getAutoCancelOrderIdByPage(i, PAGESIZE);
|
||||
for (String order_id : order_id_row) {
|
||||
try {
|
||||
List<String> ids = Collections.singletonList(order_id);
|
||||
if (!shopOrderBaseService.cancel(ids, null, true)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 取消出错"), order_id));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 取消出错"), order_id), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 取消出错"), order_id), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 自动确认收货
|
||||
//shopOrderBaseService.autoReceive();
|
||||
|
||||
// 自动确认收货
|
||||
//shopOrderBaseService.autoReceive();
|
||||
|
||||
|
||||
// 2. 更新为确认收货
|
||||
List<String> order_id_receipt = shopOrderInfoService.getAutoFinishOrderId();
|
||||
if (CollUtil.isNotEmpty(order_id_receipt)) {
|
||||
for (String order_id : order_id_receipt) {
|
||||
try {
|
||||
if (!shopOrderBaseService.receive(order_id, null)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货出错"), order_id));
|
||||
// 2. 更新为确认收货
|
||||
List<String> order_id_receipt = shopOrderInfoService.getAutoFinishOrderId();
|
||||
if (CollUtil.isNotEmpty(order_id_receipt)) {
|
||||
for (String order_id : order_id_receipt) {
|
||||
try {
|
||||
if (!shopOrderBaseService.receive(order_id, null)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货出错"), order_id));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货出错"), order_id), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认收货出错"), order_id), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3.分销结算
|
||||
List<String> order_id_settle_commission = shopOrderBaseService.getWaitingSettleCommissionOrder(null, null);
|
||||
if (CollUtil.isNotEmpty(order_id_settle_commission)) {
|
||||
for (String order_id : order_id_settle_commission) {
|
||||
try {
|
||||
if (!shopDistributionUserOrderService.settleDistributionUserOrder(order_id)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认佣金结算出错"), order_id));
|
||||
// 3.分销结算
|
||||
List<String> order_id_settle_commission = shopOrderBaseService.getWaitingSettleCommissionOrder(null, null);
|
||||
if (CollUtil.isNotEmpty(order_id_settle_commission)) {
|
||||
for (String order_id : order_id_settle_commission) {
|
||||
try {
|
||||
if (!shopDistributionUserOrderService.settleDistributionUserOrder(order_id)) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认佣金结算出错"), order_id));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认佣金结算出错"), order_id), e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(String.format(I18nUtil._("order_id : %s 确认佣金结算出错"), order_id), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -89,4 +89,17 @@ public interface ShopOrderInfoService extends IBaseService<ShopOrderInfo> {
|
||||
*/
|
||||
Boolean updateOrderReceived(String orderId);
|
||||
|
||||
/**
|
||||
* 分页查询取消订单
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
List<String> getAutoCancelOrderIdByPage(Integer pageNum, Integer pageSize);
|
||||
|
||||
/**
|
||||
* 查询取消订单总数
|
||||
* @return
|
||||
*/
|
||||
long countgetAutoCancelOrderId();
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.suisung.mall.common.utils.ContextUtil.getCurrentUser;
|
||||
|
||||
@ -180,6 +181,9 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
||||
return Convert.toList(String.class, findKey(queryWrapper));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取能自动确认收货的订单号
|
||||
*
|
||||
@ -781,4 +785,36 @@ public class ShopOrderInfoServiceImpl extends BaseServiceImpl<ShopOrderInfoMappe
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> getAutoCancelOrderIdByPage(Integer pageNum, Integer pageSize) {
|
||||
QueryWrapper<ShopOrderInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("order_id","order_state_id");
|
||||
queryWrapper.eq("order_state_id", StateCode.ORDER_STATE_WAIT_PAY)
|
||||
.eq("order_is_paid", StateCode.ORDER_PAID_STATE_NO)
|
||||
.eq("payment_type_id", StateCode.PAYMENT_TYPE_ONLINE);
|
||||
|
||||
Float order_autocancel_time = accountBaseConfigService.getConfig("order_autocancel_time", 0.5f);
|
||||
int second = NumberUtil.mul(order_autocancel_time, 60, 60).intValue();
|
||||
long time = DateUtil.offsetSecond(new Date(), -second).getTime();
|
||||
queryWrapper.lt("order_time", time);
|
||||
List<ShopOrderInfo> shopOrderInfos=this.lists(queryWrapper,pageNum,pageSize).getRecords();
|
||||
return shopOrderInfos.stream().map(ShopOrderInfo::getOrder_id).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countgetAutoCancelOrderId() {
|
||||
QueryWrapper<ShopOrderInfo> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_state_id", StateCode.ORDER_STATE_WAIT_PAY)
|
||||
.eq("order_is_paid", StateCode.ORDER_PAID_STATE_NO)
|
||||
.eq("payment_type_id", StateCode.PAYMENT_TYPE_ONLINE);
|
||||
|
||||
Float order_autocancel_time = accountBaseConfigService.getConfig("order_autocancel_time", 0.5f);
|
||||
int second = NumberUtil.mul(order_autocancel_time, 60, 60).intValue();
|
||||
long time = DateUtil.offsetSecond(new Date(), -second).getTime();
|
||||
queryWrapper.lt("order_time", time);
|
||||
return this.count(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user