|
|
|
@ -10,13 +10,11 @@ import static org.mockito.ArgumentMatchers.anyList;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.ArgumentMatchers.eq;
|
|
|
|
import static org.mockito.Mockito.doAnswer;
|
|
|
|
import static org.mockito.Mockito.doAnswer;
|
|
|
|
import static org.mockito.Mockito.never;
|
|
|
|
import static org.mockito.Mockito.never;
|
|
|
|
import static org.mockito.Mockito.times;
|
|
|
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import com.ruoyi.asset.constant.AssetLifecycleBusinessType;
|
|
|
|
|
|
|
|
import com.ruoyi.asset.constant.AssetStatus;
|
|
|
|
import com.ruoyi.asset.constant.AssetStatus;
|
|
|
|
import com.ruoyi.asset.constant.InventoryIdentifyMethod;
|
|
|
|
import com.ruoyi.asset.constant.InventoryIdentifyMethod;
|
|
|
|
import com.ruoyi.asset.constant.InventoryResult;
|
|
|
|
import com.ruoyi.asset.constant.InventoryResult;
|
|
|
|
@ -27,7 +25,6 @@ import com.ruoyi.asset.constant.InventoryTaskStatus;
|
|
|
|
import com.ruoyi.asset.constant.RfidBindStatus;
|
|
|
|
import com.ruoyi.asset.constant.RfidBindStatus;
|
|
|
|
import com.ruoyi.asset.domain.AmsAsset;
|
|
|
|
import com.ruoyi.asset.domain.AmsAsset;
|
|
|
|
import com.ruoyi.asset.domain.AmsAssetCategory;
|
|
|
|
import com.ruoyi.asset.domain.AmsAssetCategory;
|
|
|
|
import com.ruoyi.asset.domain.AmsAssetLifecycleLog;
|
|
|
|
|
|
|
|
import com.ruoyi.asset.domain.AmsAssetLocation;
|
|
|
|
import com.ruoyi.asset.domain.AmsAssetLocation;
|
|
|
|
import com.ruoyi.asset.domain.AmsInventoryTask;
|
|
|
|
import com.ruoyi.asset.domain.AmsInventoryTask;
|
|
|
|
import com.ruoyi.asset.domain.AmsInventoryTaskItem;
|
|
|
|
import com.ruoyi.asset.domain.AmsInventoryTaskItem;
|
|
|
|
@ -40,7 +37,6 @@ import com.ruoyi.asset.mapper.AmsRfidTagMapper;
|
|
|
|
import com.ruoyi.asset.service.IAmsAssetCategoryService;
|
|
|
|
import com.ruoyi.asset.service.IAmsAssetCategoryService;
|
|
|
|
import com.ruoyi.asset.service.IAmsAssetLocationService;
|
|
|
|
import com.ruoyi.asset.service.IAmsAssetLocationService;
|
|
|
|
import com.ruoyi.asset.service.IAmsWarehouseService;
|
|
|
|
import com.ruoyi.asset.service.IAmsWarehouseService;
|
|
|
|
import com.ruoyi.asset.service.IAssetLifecycleService;
|
|
|
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
import com.ruoyi.system.service.ISysCodeRuleService;
|
|
|
|
import com.ruoyi.system.service.ISysCodeRuleService;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
@ -74,9 +70,6 @@ class AmsInventoryTaskServiceImplTest
|
|
|
|
@Mock
|
|
|
|
@Mock
|
|
|
|
private IAmsAssetCategoryService amsAssetCategoryService;
|
|
|
|
private IAmsAssetCategoryService amsAssetCategoryService;
|
|
|
|
|
|
|
|
|
|
|
|
@Mock
|
|
|
|
|
|
|
|
private IAssetLifecycleService assetLifecycleService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@InjectMocks
|
|
|
|
@InjectMocks
|
|
|
|
private AmsInventoryTaskServiceImpl service;
|
|
|
|
private AmsInventoryTaskServiceImpl service;
|
|
|
|
|
|
|
|
|
|
|
|
@ -330,56 +323,40 @@ class AmsInventoryTaskServiceImplTest
|
|
|
|
verify(amsInventoryTaskMapper, never()).insertAmsInventoryTaskSurplus(any(AmsInventoryTaskSurplus.class));
|
|
|
|
verify(amsInventoryTaskMapper, never()).insertAmsInventoryTaskSurplus(any(AmsInventoryTaskSurplus.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 确认结果只写盘点履历,不调用资产台账状态更新。 */
|
|
|
|
/** 确认结果只完成任务,不调用资产台账状态更新,也不写资产履历。 */
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void confirmResultShouldWriteLifecycleWithoutUpdatingAssetLedger()
|
|
|
|
void confirmResultShouldCompleteWithoutUpdatingAssetLedger()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AmsInventoryTask current = buildPersistedTask(InventoryTaskStatus.PENDING_RESULT_CONFIRM);
|
|
|
|
AmsInventoryTask current = buildPersistedTask(InventoryTaskStatus.PENDING_RESULT_CONFIRM);
|
|
|
|
current.setAmsInventoryTaskItemList(Collections.singletonList(buildPersistedItemWithResult()));
|
|
|
|
current.setAmsInventoryTaskItemList(Collections.singletonList(buildPersistedItemWithResult()));
|
|
|
|
when(amsInventoryTaskMapper.selectAmsInventoryTaskByTaskIdForUpdate(100L)).thenReturn(current);
|
|
|
|
when(amsInventoryTaskMapper.selectAmsInventoryTaskByTaskIdForUpdate(100L)).thenReturn(current);
|
|
|
|
when(amsAssetMapper.selectAmsAssetByAssetIdForUpdate(1L)).thenReturn(buildAsset());
|
|
|
|
|
|
|
|
when(amsInventoryTaskMapper.updateAmsInventoryTaskStatus(any(AmsInventoryTask.class))).thenReturn(1);
|
|
|
|
when(amsInventoryTaskMapper.updateAmsInventoryTaskStatus(any(AmsInventoryTask.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1, service.confirmResult(100L, 9L, "管理员", "admin"));
|
|
|
|
assertEquals(1, service.confirmResult(100L, 9L, "管理员", "admin"));
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<AmsAssetLifecycleLog> lifecycleCaptor =
|
|
|
|
verify(amsAssetMapper, never()).selectAmsAssetByAssetIdForUpdate(1L);
|
|
|
|
ArgumentCaptor.forClass(AmsAssetLifecycleLog.class);
|
|
|
|
|
|
|
|
verify(assetLifecycleService).recordLifecycle(any(AmsAsset.class), any(AmsAsset.class),
|
|
|
|
|
|
|
|
lifecycleCaptor.capture());
|
|
|
|
|
|
|
|
AmsAssetLifecycleLog lifecycleLog = lifecycleCaptor.getValue();
|
|
|
|
|
|
|
|
assertEquals(AssetLifecycleBusinessType.INVENTORY, lifecycleLog.getBusinessType());
|
|
|
|
|
|
|
|
assertEquals(100L, lifecycleLog.getSourceOrderId());
|
|
|
|
|
|
|
|
assertEquals(500L, lifecycleLog.getSourceItemId());
|
|
|
|
|
|
|
|
assertEquals(9L, lifecycleLog.getOperateUserId());
|
|
|
|
|
|
|
|
assertTrue(lifecycleLog.getRemark().contains(InventoryResult.NORMAL));
|
|
|
|
|
|
|
|
verify(amsAssetMapper, never()).updateAssetForTransition(any(AmsAsset.class));
|
|
|
|
verify(amsAssetMapper, never()).updateAssetForTransition(any(AmsAsset.class));
|
|
|
|
assertEquals(InventoryTaskStatus.INVENTORY_DONE, current.getTaskStatus());
|
|
|
|
assertEquals(InventoryTaskStatus.INVENTORY_DONE, current.getTaskStatus());
|
|
|
|
assertNotNull(current.getFinishTime());
|
|
|
|
assertNotNull(current.getFinishTime());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** 确认结果时,账内盘盈写盘点履历并把盘盈明细置为已确认。 */
|
|
|
|
/** 确认结果时,只把盘盈明细置为已确认,不写资产履历。 */
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void confirmResultShouldWriteLifecycleForKnownSurplus()
|
|
|
|
void confirmResultShouldConfirmKnownSurplusWithoutLifecycle()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AmsInventoryTask current = buildPersistedTask(InventoryTaskStatus.PENDING_RESULT_CONFIRM);
|
|
|
|
AmsInventoryTask current = buildPersistedTask(InventoryTaskStatus.PENDING_RESULT_CONFIRM);
|
|
|
|
current.setAmsInventoryTaskItemList(Collections.singletonList(buildPersistedItemWithResult()));
|
|
|
|
current.setAmsInventoryTaskItemList(Collections.singletonList(buildPersistedItemWithResult()));
|
|
|
|
current.setAmsInventoryTaskSurplusList(Collections.singletonList(buildPersistedKnownSurplus()));
|
|
|
|
current.setAmsInventoryTaskSurplusList(Collections.singletonList(buildPersistedKnownSurplus()));
|
|
|
|
when(amsInventoryTaskMapper.selectAmsInventoryTaskByTaskIdForUpdate(100L)).thenReturn(current);
|
|
|
|
when(amsInventoryTaskMapper.selectAmsInventoryTaskByTaskIdForUpdate(100L)).thenReturn(current);
|
|
|
|
when(amsAssetMapper.selectAmsAssetByAssetIdForUpdate(1L)).thenReturn(buildAsset());
|
|
|
|
|
|
|
|
when(amsAssetMapper.selectAmsAssetByAssetIdForUpdate(2L)).thenReturn(buildOutOfScopeAsset());
|
|
|
|
|
|
|
|
when(amsInventoryTaskMapper.updateAmsInventoryTaskStatus(any(AmsInventoryTask.class))).thenReturn(1);
|
|
|
|
when(amsInventoryTaskMapper.updateAmsInventoryTaskStatus(any(AmsInventoryTask.class))).thenReturn(1);
|
|
|
|
when(amsInventoryTaskMapper.confirmAmsInventoryTaskSurplusByTaskId(100L,
|
|
|
|
when(amsInventoryTaskMapper.confirmAmsInventoryTaskSurplusByTaskId(100L,
|
|
|
|
InventorySurplusStatus.CONFIRMED, "admin")).thenReturn(1);
|
|
|
|
InventorySurplusStatus.CONFIRMED, "admin")).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals(1, service.confirmResult(100L, 9L, "管理员", "admin"));
|
|
|
|
assertEquals(1, service.confirmResult(100L, 9L, "管理员", "admin"));
|
|
|
|
|
|
|
|
|
|
|
|
ArgumentCaptor<AmsAssetLifecycleLog> lifecycleCaptor =
|
|
|
|
verify(amsAssetMapper, never()).selectAmsAssetByAssetIdForUpdate(1L);
|
|
|
|
ArgumentCaptor.forClass(AmsAssetLifecycleLog.class);
|
|
|
|
verify(amsAssetMapper, never()).selectAmsAssetByAssetIdForUpdate(2L);
|
|
|
|
verify(assetLifecycleService, times(2)).recordLifecycle(any(AmsAsset.class), any(AmsAsset.class),
|
|
|
|
verify(amsAssetMapper, never()).updateAssetForTransition(any(AmsAsset.class));
|
|
|
|
lifecycleCaptor.capture());
|
|
|
|
|
|
|
|
assertTrue(lifecycleCaptor.getAllValues().stream()
|
|
|
|
|
|
|
|
.anyMatch(log -> Long.valueOf(700L).equals(log.getSourceItemId())
|
|
|
|
|
|
|
|
&& log.getRemark().contains("盘盈类型")));
|
|
|
|
|
|
|
|
verify(amsInventoryTaskMapper).confirmAmsInventoryTaskSurplusByTaskId(100L,
|
|
|
|
verify(amsInventoryTaskMapper).confirmAmsInventoryTaskSurplusByTaskId(100L,
|
|
|
|
InventorySurplusStatus.CONFIRMED, "admin");
|
|
|
|
InventorySurplusStatus.CONFIRMED, "admin");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -468,20 +445,6 @@ class AmsInventoryTaskServiceImplTest
|
|
|
|
return item;
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private AmsAsset buildAsset()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
AmsAsset asset = new AmsAsset();
|
|
|
|
|
|
|
|
asset.setAssetId(1L);
|
|
|
|
|
|
|
|
asset.setAssetCode("A001");
|
|
|
|
|
|
|
|
asset.setAssetName("资产A");
|
|
|
|
|
|
|
|
asset.setAssetStatus(AssetStatus.IN_STOCK);
|
|
|
|
|
|
|
|
asset.setWarehouseId(1L);
|
|
|
|
|
|
|
|
asset.setWarehouseName("一号仓");
|
|
|
|
|
|
|
|
asset.setLocationId(10L);
|
|
|
|
|
|
|
|
asset.setLocationName("一号仓A区");
|
|
|
|
|
|
|
|
return asset;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private AmsAsset buildOutOfScopeAsset()
|
|
|
|
private AmsAsset buildOutOfScopeAsset()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AmsAsset asset = new AmsAsset();
|
|
|
|
AmsAsset asset = new AmsAsset();
|
|
|
|
|