代码拉取完成,页面将自动刷新
package net.chrisrichardson.ftgo.kitchenservice.domain;
import io.eventuate.tram.events.aggregates.ResultWithDomainEvents;
import net.chrisrichardson.ftgo.common.RevisedOrderLineItem;
import net.chrisrichardson.ftgo.kitchenservice.api.TicketDetails;
import net.chrisrichardson.ftgo.kitchenservice.api.events.TicketDomainEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public class KitchenService {
@Autowired
private TicketRepository ticketRepository;
@Autowired
private TicketDomainEventPublisher domainEventPublisher;
@Autowired
private RestaurantRepository restaurantRepository;
public void createMenu(long id, RestaurantMenu menu) {
Restaurant restaurant = new Restaurant(id, menu.getMenuItems());
restaurantRepository.save(restaurant);
}
public void reviseMenu(long ticketId, RestaurantMenu revisedMenu) {
Restaurant restaurant = restaurantRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
restaurant.reviseMenu(revisedMenu);
}
public Ticket createTicket(long restaurantId, Long ticketId, TicketDetails ticketDetails) {
ResultWithDomainEvents<Ticket, TicketDomainEvent> rwe = Ticket.create(restaurantId, ticketId, ticketDetails);
ticketRepository.save(rwe.result);
domainEventPublisher.publish(rwe.result, rwe.events);
return rwe.result;
}
@Transactional
public void accept(long ticketId, LocalDateTime readyBy) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
List<TicketDomainEvent> events = ticket.accept(readyBy);
domainEventPublisher.publish(ticket, events);
}
public void confirmCreateTicket(Long ticketId) {
Ticket ro = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
List<TicketDomainEvent> events = ro.confirmCreate();
domainEventPublisher.publish(ro, events);
}
public void cancelCreateTicket(Long ticketId) {
Ticket ro = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
List<TicketDomainEvent> events = ro.cancelCreate();
domainEventPublisher.publish(ro, events);
}
public void cancelTicket(long restaurantId, long ticketId) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.cancel();
domainEventPublisher.publish(ticket, events);
}
public void confirmCancelTicket(long restaurantId, long ticketId) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.confirmCancel();
domainEventPublisher.publish(ticket, events);
}
public void undoCancel(long restaurantId, long ticketId) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.undoCancel();
domainEventPublisher.publish(ticket, events);
}
public void beginReviseOrder(long restaurantId, Long ticketId, List<RevisedOrderLineItem> revisedOrderLineItems) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.beginReviseOrder(revisedOrderLineItems);
domainEventPublisher.publish(ticket, events);
}
public void undoBeginReviseOrder(long restaurantId, Long ticketId) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.undoBeginReviseOrder();
domainEventPublisher.publish(ticket, events);
}
public void confirmReviseTicket(long restaurantId, long ticketId, List<RevisedOrderLineItem> revisedOrderLineItems) {
Ticket ticket = ticketRepository.findById(ticketId)
.orElseThrow(() -> new TicketNotFoundException(ticketId));
// TODO - verify restaurant id
List<TicketDomainEvent> events = ticket.confirmReviseTicket(revisedOrderLineItems);
domainEventPublisher.publish(ticket, events);
}
// ...
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。