cmvr-wms/ruoyi-admin/src/test/java/com/ruoyi/projectdev/SupplierQuoteImportTest.java

22 lines
2.2 KiB
Java
Raw Normal View History

package com.ruoyi.projectdev;
import java.math.BigDecimal;
import java.io.*;
import java.util.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.jupiter.api.Test;
import com.ruoyi.web.controller.warehouse.SupplierQuoteImport;
import com.ruoyi.warehouse.domain.*;
import static org.junit.jupiter.api.Assertions.*;
class SupplierQuoteImportTest {
private PurchaseSheet sheet(){var s=new PurchaseSheet();var b=new PurchaseBatch();b.setBatchNo("CG2026100001");s.setBatch(b);var rows=new ArrayList<PurchaseRequest>();for(long i=1;i<=3;i++){var r=new PurchaseRequest();r.setId(i);r.setProductCode(i==3?"WP2":"WP1");r.setMaterialName(i==3?"物品2":"物品1");r.setQuantity(BigDecimal.ONE);r.setPurchaseStatus(0);rows.add(r);}s.setRows(rows);return s;}
private byte[] file(String[][] data)throws Exception{try(var b=new XSSFWorkbook();var out=new ByteArrayOutputStream()){var s=b.createSheet();String[] h={"采购批次","物品编码","最终单价"};var header=s.createRow(0);for(int i=0;i<h.length;i++)header.createCell(i).setCellValue(h[i]);for(int r=0;r<data.length;r++){var row=s.createRow(r+1);for(int c=0;c<3;c++)row.createCell(c).setCellValue(data[r][c]);}b.write(out);return out.toByteArray();}}
@Test void reorderingMatchesByCodeAndFillsAllProjectLines()throws Exception{
var result=SupplierQuoteImport.preview(new ByteArrayInputStream(file(new String[][]{{"CG2026100001","WP2","2.125"},{"CG2026100001","WP1","1.123456"}})),sheet());assertNull(result.get(0).get("error"));assertEquals(List.of(3L),result.get(0).get("rowIds"));assertEquals(List.of(1L,2L),result.get(1).get("rowIds"));assertEquals(new BigDecimal("1.123456"),result.get(1).get("unitPrice"));
}
@Test void mismatchesDuplicatesBadPriceAndReceivedItemsCannotSilentlyApply()throws Exception{
var s=sheet();s.getRows().get(0).setReceivedQuantity(BigDecimal.ONE);
var result=SupplierQuoteImport.preview(new ByteArrayInputStream(file(new String[][]{{"OTHER","WP2","2"},{"CG2026100001","WP1","1"},{"CG2026100001","WP2","-1"},{"CG2026100001","WP2","3"}})),s);
assertNotNull(result.get(0).get("error"));assertNull(result.get(1).get("error"));assertEquals(List.of(2L),result.get(1).get("rowIds"));assertNotNull(result.get(2).get("error"));assertNotNull(result.get(3).get("error"));
}
}