diff --git a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java index 123b427..fef2a57 100644 --- a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java +++ b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java @@ -432,6 +432,7 @@ public class CreditUserController extends BaseController { entity.setRole(param.getRole()); entity.setInfoType(param.getInfoType()); entity.setAddress(param.getAddress()); + entity.setPlaintiffAppellant(param.getPlaintiffAppellant()); entity.setProcurementName(param.getProcurementName()); entity.setWinningName(param.getWinningName()); entity.setWinningPrice(param.getWinningPrice()); diff --git a/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java b/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java index 1407eb1..f29220a 100644 --- a/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java +++ b/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java @@ -39,6 +39,9 @@ public class CreditUser implements Serializable { @Schema(description = "类型, 0普通用户, 1招投标") private Integer type; + @Schema(description = "原告/上诉人") + private String plaintiffAppellant; + @Schema(description = "企业角色") private String role; diff --git a/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java b/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java index e902bf2..f1f39c7 100644 --- a/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java +++ b/src/main/java/com/gxwebsoft/credit/param/CreditUserImportParam.java @@ -63,6 +63,9 @@ public class CreditUserImportParam implements Serializable { @Excel(name = "中标金额") private String winningPrice; + @Excel(name = "原告/上诉人") + private String plaintiffAppellant; + // @Excel(name = "备注") // private String comments; // diff --git a/src/main/java/com/gxwebsoft/credit/param/CreditUserParam.java b/src/main/java/com/gxwebsoft/credit/param/CreditUserParam.java index 2a74eb7..202b88f 100644 --- a/src/main/java/com/gxwebsoft/credit/param/CreditUserParam.java +++ b/src/main/java/com/gxwebsoft/credit/param/CreditUserParam.java @@ -102,4 +102,7 @@ public class CreditUserParam extends BaseParam { @QueryField(type = QueryType.EQ) private Integer userId; + @Schema(description = "申请人") + private String plaintiffAppellant; + } diff --git a/src/test/java/com/gxwebsoft/credit/controller/CreditBankruptcyImportSheetSelectionTest.java b/src/test/java/com/gxwebsoft/credit/controller/CreditBankruptcyImportSheetSelectionTest.java new file mode 100644 index 0000000..a69f6b5 --- /dev/null +++ b/src/test/java/com/gxwebsoft/credit/controller/CreditBankruptcyImportSheetSelectionTest.java @@ -0,0 +1,105 @@ +package com.gxwebsoft.credit.controller; + +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.credit.entity.CreditBankruptcy; +import com.gxwebsoft.credit.service.CreditBankruptcyService; +import com.gxwebsoft.credit.service.CreditCompanyRecordCountService; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.springframework.mock.web.MockMultipartFile; +import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.web.multipart.MultipartFile; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class CreditBankruptcyImportSheetSelectionTest { + + @Test + void import_should_prefer_sheet_named_bankruptcy_reorganization() throws Exception { + MultipartFile file = buildWorkbookWithTwoSheets(); + + CreditBankruptcyController controller = new CreditBankruptcyController(); + + CreditBankruptcyService creditBankruptcyService = Mockito.mock(CreditBankruptcyService.class); + BatchImportSupport batchImportSupport = Mockito.mock(BatchImportSupport.class); + CreditCompanyRecordCountService recordCountService = Mockito.mock(CreditCompanyRecordCountService.class); + + // Capture inserted entities; controller clears the chunk list after calling persistInsertOnlyChunk. + List inserted = new ArrayList<>(); + Mockito.when(batchImportSupport.persistInsertOnlyChunk( + Mockito.eq(creditBankruptcyService), + Mockito.anyList(), + Mockito.anyList(), + Mockito.anyInt(), + Mockito.any(), + Mockito.anyString(), + Mockito.anyList() + )) + .thenAnswer(invocation -> { + @SuppressWarnings("unchecked") + List items = new ArrayList<>((List) invocation.getArgument(1)); + inserted.addAll(items); + return items.size(); + }); + + ReflectionTestUtils.setField(controller, "creditBankruptcyService", creditBankruptcyService); + ReflectionTestUtils.setField(controller, "batchImportSupport", batchImportSupport); + ReflectionTestUtils.setField(controller, "creditCompanyRecordCountService", recordCountService); + + ApiResult> result = controller.importBatch(file, null); + + assertNotNull(result); + assertEquals(0, result.getCode()); + assertTrue(result.getMessage().contains("成功导入1条"), "message=" + result.getMessage()); + assertEquals(1, inserted.size()); + // "历史破产重整" sheet is first; we should import from "破产重整" instead. + assertEquals("R1", inserted.get(0).getCode()); + } + + private static MultipartFile buildWorkbookWithTwoSheets() throws Exception { + try (Workbook workbook = new XSSFWorkbook()) { + // Put "历史破产重整" first to ensure old readAnySheet() behavior would import the wrong sheet. + writeBankruptcySheet(workbook.createSheet("历史破产重整"), "H1"); + writeBankruptcySheet(workbook.createSheet("破产重整"), "R1"); + + try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { + workbook.write(bos); + return new MockMultipartFile( + "file", + "bankruptcy.xlsx", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + bos.toByteArray() + ); + } + } + } + + private static void writeBankruptcySheet(Sheet sheet, String code) { + // Keep it simple: a single header row + single data row. + Row header = sheet.createRow(0); + header.createCell(0).setCellValue("案号"); + header.createCell(1).setCellValue("案件类型"); + header.createCell(2).setCellValue("当事人"); + header.createCell(3).setCellValue("经办法院"); + header.createCell(4).setCellValue("公开日期"); + header.createCell(5).setCellValue("备注"); + + Row row = sheet.createRow(1); + row.createCell(0).setCellValue(code); + row.createCell(1).setCellValue("破产重整"); + row.createCell(2).setCellValue("示例公司"); + row.createCell(3).setCellValue("示例法院"); + row.createCell(4).setCellValue("2026-01-01"); + row.createCell(5).setCellValue("备注"); + } +}