chen.yinxiang

fix:就餐人必传

......@@ -15,7 +15,8 @@ public class OrderSubscriptionMessageDTO {
@ApiModel(description = "创建订阅消息记录")
public static class CreateOrderSubscriptionMessageDTO {
@ApiModelProperty(value = "就餐人ID,可为空,后端根据实际情况处理", required = false)
@NotNull(message = "dinerId 不能为空")
@ApiModelProperty(value = "就餐人ID,必填", required = true)
private Integer dinerId;
@ApiModelProperty(value = "订阅消息模板ID,可为空,为空时使用配置的默认值", required = false)
......
......@@ -310,12 +310,12 @@ public class MealOrderServiceImpl implements MealOrderService {
if (openId == null || openId.isBlank()) {
throw new IllegalStateException("当前登录用户 openId 为空,无法创建订阅提醒");
}
if (dto.getJumpPath() == null || dto.getJumpPath().isBlank()) {
throw new IllegalArgumentException("jumpPath 不能为空");
}
// 1. 处理就餐人 ID:如果为空,从关联关系推断
int dinerId = dto.getDinerId() != null ? dto.getDinerId() : getDefaultDinerId(enterpriseId, openId);
// 1. dinerId 必传(避免默认推断导致业务歧义)
if (dto.getDinerId() == null) {
throw new IllegalArgumentException("dinerId 不能为空");
}
int dinerId = dto.getDinerId();
// 2. 处理模板 ID:如果为空,使用配置的默认值
String finalTemplateId = (dto.getTemplateId() != null && !dto.getTemplateId().isBlank())
......@@ -349,23 +349,6 @@ public class MealOrderServiceImpl implements MealOrderService {
);
}
/**
* 如果前端未传就餐人 ID,从当前用户的关联关系中推断默认值
* 如果只有一个关联的就餐人,返回该就餐人 ID;如果有多个或没有,返回 0
*/
private int getDefaultDinerId(int enterpriseId, String openId) {
final var loginInfo = LoginContextHolder.getLoginInfo();
final var mpAccountDinerRefs = mealOrderServiceRpcClient.queryMpAccountDinerRefsByCondition(
enterpriseId,
Collections.singletonList(loginInfo.getId()),
Collections.emptyList()
);
if (mpAccountDinerRefs.size() == 1) {
return mpAccountDinerRefs.get(0).getDinerId();
}
return 0;
}
private static final class Period {
final long startAt;
final Long endAt;
......