1 Star 0 Fork 0

lightman911/personal_note

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
KitchenService.java 4.53 KB
一键复制 编辑 原始数据 按行查看 历史
lightman911 提交于 2023-02-21 17:12 . add
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);
}
// ...
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lightman911/personal_note.git
git@gitee.com:lightman911/personal_note.git
lightman911
personal_note
personal_note
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385