package cn.iocoder.yudao.module.crm.service.quotation;
|
|
import cn.iocoder.yudao.module.crm.controller.admin.quotation.vo.CrmSaleQuotationRespVO;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.junit.jupiter.api.Test;
|
|
import java.io.ByteArrayInputStream;
|
import java.math.BigDecimal;
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
class CrmSaleQuotationExcelRendererTest {
|
|
@Test
|
void fillsMultipleItemsAndPreservesTemplateTermsAndPrintArea() throws Exception {
|
var quote = new CrmSaleQuotationRespVO();
|
quote.setNo("BJ-123");
|
quote.setCustomerName("客户甲");
|
quote.setOwnerUserName("销售员");
|
quote.setQuotationTime(LocalDateTime.of(2026, 11, 10, 0, 0));
|
var first = new CrmSaleQuotationRespVO.Item();
|
first.setItemName("电缆A");
|
first.setCount(new BigDecimal("2.5"));
|
first.setQuotationPrice(new BigDecimal("3.20"));
|
var second = new CrmSaleQuotationRespVO.Item();
|
second.setItemName("电缆B");
|
second.setRemark("备注B");
|
quote.setItems(List.of(first, second));
|
|
byte[] bytes = CrmSaleQuotationExcelRenderer.render(quote, "测试公司", "客户地址", "联系人", "123456");
|
try (var workbook = new XSSFWorkbook(new ByteArrayInputStream(bytes))) {
|
var sheet = workbook.getSheetAt(0);
|
assertEquals("编号:BJ-123", sheet.getRow(2).getCell(0).getStringCellValue());
|
assertEquals("客户甲", sheet.getRow(4).getCell(1).getStringCellValue());
|
assertEquals("客户地址", sheet.getRow(5).getCell(1).getStringCellValue());
|
assertEquals("联系人", sheet.getRow(6).getCell(1).getStringCellValue());
|
assertEquals("123456", sheet.getRow(7).getCell(1).getStringCellValue());
|
assertEquals(2.5, sheet.getRow(10).getCell(3).getNumericCellValue());
|
assertEquals(8.0, sheet.getRow(10).getCell(5).getNumericCellValue());
|
assertEquals("电缆B", sheet.getRow(11).getCell(0).getStringCellValue());
|
assertEquals("备注B", sheet.getRow(11).getCell(7).getStringCellValue());
|
String terms = sheet.getRow(13).getCell(0).getStringCellValue();
|
assertTrue(terms.contains("110元/公斤"));
|
assertTrue(terms.contains("货到45天内付款"));
|
assertEquals("报价日期:2026年11月10日", sheet.getRow(16).getCell(6).getStringCellValue());
|
assertTrue(workbook.getPrintArea(0).contains("$H$19"));
|
assertEquals(2, workbook.getAllPictures().size());
|
}
|
}
|
}
|