feat(wcs): wire core module into RuoYi
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package com.ruoyi.wcs;
|
||||
|
||||
import com.ruoyi.wcs.application.task.CreateTransportOrderCommand;
|
||||
import com.ruoyi.wcs.application.task.TransportOrderApplicationService;
|
||||
import com.ruoyi.wcs.application.task.TransportOrderResult;
|
||||
import com.ruoyi.wcs.domain.shared.IdGenerator;
|
||||
import com.ruoyi.wcs.domain.shared.WcsClock;
|
||||
import com.ruoyi.wcs.infrastructure.persistence.task.MyBatisTransportOrderRepository;
|
||||
import com.ruoyi.wcs.infrastructure.persistence.task.TransportOrderMapper;
|
||||
import com.ruoyi.wcs.port.in.TransportOrderUseCase;
|
||||
import com.ruoyi.wcs.port.out.DomainEventPublisher;
|
||||
import com.ruoyi.wcs.port.out.TransportOrderRepository;
|
||||
import com.ruoyi.wcs.port.out.WorkflowDefinitionProvider;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
@Configuration
|
||||
@MapperScan(basePackageClasses = TransportOrderMapper.class, lazyInitialization = "true")
|
||||
public class WcsCoreConfiguration {
|
||||
|
||||
@Bean
|
||||
public WcsClock wcsClock() {
|
||||
return Instant::now;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IdGenerator wcsIdGenerator() {
|
||||
return () -> UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransportOrderRepository transportOrderRepository(
|
||||
@Lazy TransportOrderMapper mapper) {
|
||||
return new MyBatisTransportOrderRepository(mapper);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransportOrderUseCase transportOrderUseCase(
|
||||
TransportOrderRepository repository,
|
||||
ObjectProvider<WorkflowDefinitionProvider> workflowDefinitions,
|
||||
ObjectProvider<DomainEventPublisher> eventPublishers,
|
||||
IdGenerator idGenerator,
|
||||
WcsClock clock) {
|
||||
WorkflowDefinitionProvider workflowDefinitionProvider =
|
||||
workflowDefinitions.getIfAvailable();
|
||||
DomainEventPublisher eventPublisher = eventPublishers.getIfAvailable();
|
||||
if (workflowDefinitionProvider == null || eventPublisher == null) {
|
||||
return new UnavailableTransportOrderUseCase();
|
||||
}
|
||||
return new TransportOrderApplicationService(repository,
|
||||
workflowDefinitionProvider, eventPublisher, idGenerator, clock);
|
||||
}
|
||||
|
||||
private static final class UnavailableTransportOrderUseCase
|
||||
implements TransportOrderUseCase {
|
||||
@Override
|
||||
public TransportOrderResult create(CreateTransportOrderCommand command) {
|
||||
throw unavailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportOrderResult cancel(String externalRequestId) {
|
||||
throw unavailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportOrderResult suspend(String orderId, String reason) {
|
||||
throw unavailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransportOrderResult resume(String orderId) {
|
||||
throw unavailable();
|
||||
}
|
||||
|
||||
private static IllegalStateException unavailable() {
|
||||
return new IllegalStateException("WCS core adapters are not configured");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user