订单部分代码

This commit is contained in:
zjf committed 2026-04-13 18:40:41 +08:00
1 parent bfa5dc6a26
commit 554ba086a5
6 files changed
+111 -11

No files matched your search

@@ -0,0 +1,22 @@
package com.bsd.pjcloud.canteen.constants;
/**
* 预约外送:在「预约时段开始」之前多久触发骑手派单/推送、商家提醒。
* 分钟数来自 {@code sys_public_param}({@link #PARAM_RIDER_NOTIFY_BEFORE_MINUTES} 等),未配置则用默认值。
*/
public final class CanteenDeliveryScheduleConstants {
private CanteenDeliveryScheduleConstants() {
}
/** 与 db/1019 中 public_key 一致 */
public static final String PARAM_RIDER_NOTIFY_BEFORE_MINUTES = "CANTEEN_DELIVERY_SCHEDULED_RIDER_NOTIFY_BEFORE_MINUTES";
public static final String PARAM_MERCHANT_NOTIFY_BEFORE_MINUTES = "CANTEEN_DELIVERY_SCHEDULED_MERCHANT_NOTIFY_BEFORE_MINUTES";
public static final int DEFAULT_RIDER_NOTIFY_BEFORE_MINUTES = 60;
public static final int DEFAULT_MERCHANT_NOTIFY_BEFORE_MINUTES = 60;
/** 预约单:未到派单时间 */
public static final String EXPECT_TYPE_SCHEDULED = "SCHEDULED";
public static final String EXPECT_TYPE_IMMEDIATE = "IMMEDIATE";
}
@@ -4,8 +4,10 @@ import com.bsd.pjcloud.canteen.dto.delivery.CanteenDeliveryOrderSyncDTO;
import com.bsd.pjcloud.canteen.dto.delivery.CanteenDeliveryPhotoDTO;
import com.bsd.pjcloud.canteen.push.CanteenDeliveryRiderPushPublisher;
import com.bsd.pjcloud.canteen.service.CanteenDeliveryOrderService;
import com.bsd.pjcloud.canteen.entity.CanteenDeliveryOrderEntity;
import com.bsd.pjcloud.canteen.vo.app.CanteenDeliveryOrderAppVO;
import com.bsd.pjcloud.common.core.util.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.common.security.annotation.Inner;
import com.bsd.pjcloud.common.security.util.SecurityUtils;
@@ -17,8 +19,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.springdoc.core.annotations.ParameterObject;
/**
* 食堂外送:订单同步 + 骑手 App
@@ -65,10 +66,12 @@ public class CanteenDeliveryOrderController {
}
@GetMapping("/app/list")
@Operation(summary = "骑手端-我的配送单", description = "tab: pending待配送 | all全部 | completed已完成 | cancelled已取消")
public R<List<CanteenDeliveryOrderAppVO>> appList(@RequestParam(defaultValue = "pending") String tab) {
@Operation(summary = "骑手端-我的配送单",
description = "tab: pending待配送 | all全部 | completed已完成 | cancelled已取消。分页参数与 MyBatis-Plus Page 一致:current(页码,默认1)、size(每页条数,默认10,最大100)。")
public R<Page<CanteenDeliveryOrderAppVO>> appList(@RequestParam(defaultValue = "pending") String tab,
@ParameterObject Page<CanteenDeliveryOrderEntity> page) {
Long uid = SecurityUtils.getUser().getId();
return R.ok(canteenDeliveryOrderService.listForRider(uid, tab));
return R.ok(canteenDeliveryOrderService.pageForRider(uid, tab, page));
}
@GetMapping("/app/{id}")
@@ -0,0 +1,34 @@
package com.bsd.pjcloud.canteen.job;
import com.bsd.pjcloud.canteen.service.CanteenDeliveryOrderService;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 预约外送:到达配置的「时段开始前 N 分钟」后,通知商家、向骑手派单并推送 WS。
* <p>
* XXL-JOB 管理端注册 Handler 名:{@value #HANDLER_NAME},建议 Cron 每分钟一次。
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class CanteenDeliveryScheduledJob {
public static final String HANDLER_NAME = "canteenDeliveryScheduledDispatchJobHandler";
private final CanteenDeliveryOrderService canteenDeliveryOrderService;
@XxlJob(HANDLER_NAME)
public void canteenDeliveryScheduledDispatchJobHandler() {
try {
canteenDeliveryOrderService.runDueScheduledDeliveryTasks();
XxlJobHelper.handleSuccess();
} catch (Exception e) {
log.error("canteenDeliveryScheduledDispatchJobHandler 执行异常", e);
XxlJobHelper.handleFail(e.getMessage());
}
}
}
@@ -0,0 +1,27 @@
package com.bsd.pjcloud.canteen.push;
import com.bsd.pjcloud.canteen.entity.CanteenDeliveryOrderEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* 预约外送单到达「通知商家」时间点时的扩展点:当前仅打日志,后续可接 MQ、站内信、商户端 WebSocket 等。
*/
@Slf4j
@Component
public class CanteenDeliveryMerchantNotifyPublisher {
public void publishScheduledOrderNotice(CanteenDeliveryOrderEntity order) {
if (order == null) {
return;
}
log.info(
"预约外送-商家提醒(占位实现,可扩展): deliveryOrderId={} merchantId={} sourceOrderId={} expectDate={} expectStart={} expectEnd={}",
order.getId(),
order.getMerchantId(),
order.getSourceOrderId(),
order.getExpectDeliveryDate(),
order.getExpectDeliveryStart(),
order.getExpectDeliveryEnd());
}
}
@@ -1,5 +1,6 @@
package com.bsd.pjcloud.canteen.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.canteen.dto.delivery.CanteenDeliveryOrderSyncDTO;
import com.bsd.pjcloud.canteen.dto.delivery.CanteenDeliveryPhotoDTO;
@@ -7,8 +8,6 @@ import com.bsd.pjcloud.canteen.entity.CanteenDeliveryOrderEntity;
import com.bsd.pjcloud.canteen.vo.app.CanteenDeliveryOrderAppVO;
import com.bsd.pjcloud.common.core.util.R;
import java.util.List;
public interface CanteenDeliveryOrderService extends IService<CanteenDeliveryOrderEntity> {
/**
@@ -20,8 +19,9 @@ public interface CanteenDeliveryOrderService extends IService<CanteenDeliveryOrd
/**
* @param tab pending | all | completed | cancelled
* @param page 分页(current、size;与 MyBatis-Plus {@link Page} 一致)
*/
List<CanteenDeliveryOrderAppVO> listForRider(Long riderUserId, String tab);
Page<CanteenDeliveryOrderAppVO> pageForRider(Long riderUserId, String tab, Page<CanteenDeliveryOrderEntity> page);
CanteenDeliveryOrderAppVO detailForRider(Long riderUserId, Long id);
@@ -2,6 +2,7 @@ package com.bsd.pjcloud.canteen.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.admin.api.dto.UserInfo;
import com.bsd.pjcloud.admin.api.entity.SysDept;
@@ -305,8 +306,19 @@ public class CanteenDeliveryOrderServiceImpl extends ServiceImpl<CanteenDelivery
return R.ok();
}
private static final long RIDER_LIST_MAX_PAGE_SIZE = 100L;
@Override
public List<CanteenDeliveryOrderAppVO> listForRider(Long riderUserId, String tab) {
public Page<CanteenDeliveryOrderAppVO> pageForRider(Long riderUserId, String tab, Page<CanteenDeliveryOrderEntity> page) {
Page<CanteenDeliveryOrderEntity> p = page != null ? page : new Page<>(1, 10);
if (p.getCurrent() < 1) {
p.setCurrent(1);
}
if (p.getSize() < 1) {
p.setSize(10);
} else if (p.getSize() > RIDER_LIST_MAX_PAGE_SIZE) {
p.setSize(RIDER_LIST_MAX_PAGE_SIZE);
}
String t = StrUtil.emptyToDefault(tab, "all");
var q = Wrappers.<CanteenDeliveryOrderEntity>lambdaQuery()
.eq(CanteenDeliveryOrderEntity::getRiderUserId, riderUserId);
@@ -319,8 +331,10 @@ public class CanteenDeliveryOrderServiceImpl extends ServiceImpl<CanteenDelivery
}
}
q.orderByDesc(CanteenDeliveryOrderEntity::getCreateTime);
List<CanteenDeliveryOrderEntity> list = list(q);
return list.stream().map(this::toAppVoWithCart).toList();
Page<CanteenDeliveryOrderEntity> entityPage = page(p, q);
Page<CanteenDeliveryOrderAppVO> voPage = new Page<>(entityPage.getCurrent(), entityPage.getSize(), entityPage.getTotal());
voPage.setRecords(entityPage.getRecords().stream().map(this::toAppVoWithCart).toList());
return voPage;
}
@Override