Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class ExcelFileController {
*/
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//@ApiOperationLog(description = "上传Excel文件")
public Response<?> uploadAndParseExcel(@Validated ExcelFileUploadDTO excelFileUploadDTO/* 相应的请求参数类 */) {
public Response<?> uploadExcelFile(@Validated ExcelFileUploadDTO excelFileUploadDTO/* 相应的请求参数类 */) {

return excelFileService.uploadAExcel(excelFileUploadDTO);
return excelFileService.uploadExcelFile(excelFileUploadDTO);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public interface ExcelFileService {
* @param excelFileUploadDTO
* @return
*/
Response<?> uploadAExcel(ExcelFileUploadDTO excelFileUploadDTO);
Response<?> uploadExcelFile(ExcelFileUploadDTO excelFileUploadDTO);

/**
* 根据 preUploadId 查询校验失败明细。
* 说明:preUploadId 仅在 uploadAExcel 校验失败时生成并返回。
* 说明:preUploadId 仅在 uploadExcelFile 校验失败时生成并返回。
*/
Response<?> getValidationErrors(Long preUploadId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ExcelUploadAppService {
@Resource
private ExcelFileRecordSupport excelFileRecordSupport;

public Response<?> uploadAExcel(ExcelFileUploadDTO excelFileUploadDTO) {
public Response<?> uploadExcelFile(ExcelFileUploadDTO excelFileUploadDTO) {
MultipartFile file = excelFileUploadDTO.getFile();

String originalFilename = file.getOriginalFilename();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class ExcelFileServiceImpl implements ExcelFileService {
private ExcelParseAppService excelParseAppService;

@Override
public Response<?> uploadAExcel(ExcelFileUploadDTO excelFileUploadDTO) {
return excelUploadAppService.uploadAExcel(excelFileUploadDTO);
public Response<?> uploadExcelFile(ExcelFileUploadDTO excelFileUploadDTO) {
return excelUploadAppService.uploadExcelFile(excelFileUploadDTO);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void tearDown() {
}

@Test
void uploadAExcel_validExcel_shouldReturnFileIdAndUploadedStatus() throws Exception {
void uploadExcelFile_validExcel_shouldReturnFileIdAndUploadedStatus() throws Exception {
LoginUserContextHolder.setUserId(123L);
when(distributedIdGeneratorRpcService.getFileId()).thenReturn("9001");
when(ossRpcService.uploadExcel(any(), eq("9001.xlsx"))).thenReturn("excel/123/9001.xlsx");
Expand All @@ -82,7 +82,7 @@ void uploadAExcel_validExcel_shouldReturnFileIdAndUploadedStatus() throws Except
buildExcelBytes(List.of(List.of("题目一", "A", "解析一")))
));

Response<?> response = excelUploadAppService.uploadAExcel(dto);
Response<?> response = excelUploadAppService.uploadExcelFile(dto);

assertTrue(response.isSuccess());
ExcelFileUploadVO vo = (ExcelFileUploadVO) response.getData();
Expand All @@ -94,7 +94,7 @@ void uploadAExcel_validExcel_shouldReturnFileIdAndUploadedStatus() throws Except
}

@Test
void uploadAExcel_invalidExcel_shouldReturnPreUploadIdAndFailStatus() throws Exception {
void uploadExcelFile_invalidExcel_shouldReturnPreUploadIdAndFailStatus() throws Exception {
LoginUserContextHolder.setUserId(123L);
when(distributedIdGeneratorRpcService.getPreFileId()).thenReturn("7001");

Expand All @@ -112,7 +112,7 @@ void uploadAExcel_invalidExcel_shouldReturnPreUploadIdAndFailStatus() throws Exc
buildExcelBytes(List.of(List.of("错 题", "A", "解析一")))
));

Response<?> response = excelUploadAppService.uploadAExcel(dto);
Response<?> response = excelUploadAppService.uploadExcelFile(dto);

assertTrue(response.isSuccess());
ExcelFileUploadVO vo = (ExcelFileUploadVO) response.getData();
Expand All @@ -123,7 +123,7 @@ void uploadAExcel_invalidExcel_shouldReturnPreUploadIdAndFailStatus() throws Exc
}

@Test
void uploadAExcel_whenHeaderIsNotOnFirstRow_shouldReturnValidationFailure() throws Exception {
void uploadExcelFile_whenHeaderIsNotOnFirstRow_shouldReturnValidationFailure() throws Exception {
LoginUserContextHolder.setUserId(123L);
when(distributedIdGeneratorRpcService.getPreFileId()).thenReturn("7002");

Expand All @@ -145,7 +145,7 @@ void uploadAExcel_whenHeaderIsNotOnFirstRow_shouldReturnValidationFailure() thro
))
));

Response<?> response = excelUploadAppService.uploadAExcel(dto);
Response<?> response = excelUploadAppService.uploadExcelFile(dto);

assertTrue(response.isSuccess());
ExcelFileUploadVO vo = (ExcelFileUploadVO) response.getData();
Expand All @@ -156,7 +156,7 @@ void uploadAExcel_whenHeaderIsNotOnFirstRow_shouldReturnValidationFailure() thro
}

@Test
void uploadAExcel_whenOssUploadFails_shouldMarkUploadFailedAndPropagateOriginalBizException() throws Exception {
void uploadExcelFile_whenOssUploadFails_shouldMarkUploadFailedAndPropagateOriginalBizException() throws Exception {
LoginUserContextHolder.setUserId(123L);
when(distributedIdGeneratorRpcService.getFileId()).thenReturn("9002");
when(ossRpcService.uploadExcel(any(), eq("9002.xlsx")))
Expand All @@ -170,7 +170,7 @@ void uploadAExcel_whenOssUploadFails_shouldMarkUploadFailedAndPropagateOriginalB
buildExcelBytes(List.of(List.of("题目一", "A", "解析一")))
));

BizException ex = assertThrows(BizException.class, () -> excelUploadAppService.uploadAExcel(dto));
BizException ex = assertThrows(BizException.class, () -> excelUploadAppService.uploadExcelFile(dto));

assertEquals("OSS-2", ex.getErrorCode());
assertEquals("upload failed", ex.getErrorMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class ExcelFileServiceImplTest {
private ExcelFileServiceImpl excelFileService;

@Test
void uploadAExcel_shouldDelegateToUploadAppService() {
void uploadExcelFile_shouldDelegateToUploadAppService() {
ExcelFileUploadDTO dto = new ExcelFileUploadDTO();
Response<String> expected = Response.success("upload-ok");
doReturn(expected).when(excelUploadAppService).uploadAExcel(dto);
doReturn(expected).when(excelUploadAppService).uploadExcelFile(dto);

Response<?> actual = excelFileService.uploadAExcel(dto);
Response<?> actual = excelFileService.uploadExcelFile(dto);

assertSame(expected, actual);
verify(excelUploadAppService).uploadAExcel(dto);
verify(excelUploadAppService).uploadExcelFile(dto);
}

@Test
Expand Down
Loading