暂存提交
This commit is contained in:
@@ -15,8 +15,10 @@ public class PartnerQueryService {
|
||||
return repository.activeCandidates(tenantId, keyword, type);
|
||||
}
|
||||
public PartnerEntity active(long tenantId, long id) {
|
||||
PartnerEntity value=repository.findActive(tenantId,id);
|
||||
if (value==null) throw new BizException(ResultCode.NOT_FOUND,"往来单位不存在、已停用或不属于当前企业");
|
||||
PartnerEntity value=repository.findOwned(tenantId,id);
|
||||
if (value==null) throw new BizException(ResultCode.NOT_FOUND,"往来单位不存在或不属于当前企业");
|
||||
if (!"ACTIVE".equals(value.getStatus()))
|
||||
throw new BizException(ResultCode.CONFLICT,"往来单位已停用");
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -79,9 +79,12 @@ public class WarehouseApplicationService {
|
||||
}
|
||||
|
||||
public WarehouseDetailResponse activeDetail(long tenantId, long id) {
|
||||
WarehouseEntity warehouse = repository.findActiveOwned(tenantId, id);
|
||||
WarehouseEntity warehouse = repository.findOwned(tenantId, id);
|
||||
if (warehouse == null) {
|
||||
throw new BizException(ResultCode.NOT_FOUND, "仓库不存在、已停用或不属于当前企业");
|
||||
throw new BizException(ResultCode.NOT_FOUND, "仓库不存在或不属于当前企业");
|
||||
}
|
||||
if (!"ACTIVE".equals(warehouse.getStatus())) {
|
||||
throw new BizException(ResultCode.CONFLICT, "仓库已停用");
|
||||
}
|
||||
return new WarehouseDetailResponse(warehouse, repository.findAddresses(tenantId, id),
|
||||
repository.findCapabilities(tenantId, id).stream().filter(item -> Boolean.TRUE.equals(item.getEnabled())).toList());
|
||||
|
||||
@@ -25,3 +25,14 @@ baiyue:
|
||||
jwt-secret: ${JWT_SECRET:change-me-to-at-least-32-bytes-long-before-start}
|
||||
internal-service-token: ${INTERNAL_SERVICE_TOKEN:change-me-to-an-internal-token-at-least-32-bytes-long}
|
||||
management.endpoints.web.exposure.include: health,info,prometheus
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: "${LOGGING_FILE_NAME:${LOG_PATH:./logs}/${spring.application.name}.log}"
|
||||
logback:
|
||||
rollingpolicy:
|
||||
file-name-pattern: "${LOGGING_ROLLING_FILE_NAME_PATTERN:${LOG_PATH:./logs}/${spring.application.name}.%d{yyyy-MM-dd}.%i.log.gz}"
|
||||
max-file-size: "${LOGGING_ROLLING_MAX_FILE_SIZE:100MB}"
|
||||
max-history: "${LOGGING_ROLLING_MAX_HISTORY:30}"
|
||||
total-size-cap: "${LOGGING_ROLLING_TOTAL_SIZE_CAP:5GB}"
|
||||
clean-history-on-start: "${LOGGING_ROLLING_CLEAN_HISTORY_ON_START:false}"
|
||||
|
||||
+16
-5
@@ -1,6 +1,7 @@
|
||||
package com.baiyue.warehouse.service;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.core.api.ResultCode;
|
||||
import com.baiyue.warehouse.entity.WarehouseEntity;
|
||||
import com.baiyue.warehouse.repository.WarehouseRepository;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
@@ -16,19 +17,29 @@ class WarehouseApplicationServiceTest {
|
||||
void shouldReturnOnlyActiveTenantOwnedWarehouseForMerchantDetail() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseEntity warehouse=new WarehouseEntity(); warehouse.setId(1L); warehouse.setTenantId(10001L); warehouse.setStatus("ACTIVE");
|
||||
when(repository.findActiveOwned(10001,1)).thenReturn(warehouse);
|
||||
when(repository.findOwned(10001,1)).thenReturn(warehouse);
|
||||
when(repository.findAddresses(10001,1)).thenReturn(java.util.List.of());
|
||||
when(repository.findCapabilities(10001,1)).thenReturn(java.util.List.of());
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThat(service.activeDetail(10001,1).warehouse()).isSameAs(warehouse);
|
||||
verify(repository).findActiveOwned(10001,1);
|
||||
verify(repository).findOwned(10001,1);
|
||||
}
|
||||
@Test
|
||||
@DisplayName("停用或跨租户仓库按不存在处理")
|
||||
void shouldTreatInactiveOrCrossTenantWarehouseAsNotFound() {
|
||||
@DisplayName("跨租户或不存在仓库返回 404")
|
||||
void shouldTreatMissingOrCrossTenantWarehouseAsNotFound() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThatThrownBy(() -> service.activeDetail(10002,1)).isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("停用");
|
||||
.extracting(exception -> ((BizException) exception).getResultCode()).isEqualTo(ResultCode.NOT_FOUND);
|
||||
}
|
||||
@Test
|
||||
@DisplayName("停用仓库返回 409")
|
||||
void shouldTreatInactiveWarehouseAsConflict() {
|
||||
WarehouseRepository repository=mock(WarehouseRepository.class);
|
||||
WarehouseEntity warehouse=new WarehouseEntity(); warehouse.setId(1L); warehouse.setTenantId(10001L); warehouse.setStatus("INACTIVE");
|
||||
when(repository.findOwned(10001,1)).thenReturn(warehouse);
|
||||
WarehouseApplicationService service=new WarehouseApplicationService(); ReflectionTestUtils.setField(service,"repository",repository);
|
||||
assertThatThrownBy(() -> service.activeDetail(10001,1)).isInstanceOf(BizException.class)
|
||||
.extracting(exception -> ((BizException) exception).getResultCode()).isEqualTo(ResultCode.CONFLICT);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user