From 9f39fb5ffe47e2edeedaa5005fb39be2e78a7be3 Mon Sep 17 00:00:00 2001 From: lixiaolong <702156524@qq.com> Date: Tue, 3 Nov 2026 09:17:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E4=BC=98=E5=8C=96=E7=A7=BB?= =?UTF-8?q?=E5=8A=A8=E7=AB=AF=E5=BA=94=E7=94=A8=E9=85=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加生产环境服务器地址配置支持内外网切换 - 实现采购列表只看我创建的功能开关 - 更新构建脚本中的默认生产环境API地址 - 优化采购单表格单元格编辑体验改用自动补全组件 - 调整应用更新检查逻辑增强生产环境兼容性 - 修复开发服务器切换时的一些验证问题 - 增强应用启动时的服务地址配置灵活性 --- .../warehouse/SupplierInquiryMetadata.java | 63 +++++++++++++++++ .../SupplierInquirySelectedColumnsTest.java | 68 +++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/SupplierInquiryMetadata.java create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/controller/warehouse/SupplierInquirySelectedColumnsTest.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/SupplierInquiryMetadata.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/SupplierInquiryMetadata.java new file mode 100644 index 0000000..d429449 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/warehouse/SupplierInquiryMetadata.java @@ -0,0 +1,63 @@ +package com.ruoyi.web.controller.warehouse; + +import com.ruoyi.common.exception.ServiceException; +import java.io.*; +import java.util.*; +import java.util.zip.*; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +/** Row-bound matching tokens preserve quote round trips without exporting extra columns or item fields. */ +final class SupplierInquiryMetadata { + private static final String PROPERTY="CMVR.SupplierInquiry",PREFIX="CMVR-INQUIRY-2:",TOTAL="CMVR-INQUIRY-TOTAL"; + record Match(String batch,String snapshot,List rowIds) { } + static void mark(XSSFWorkbook book){book.getProperties().getCustomProperties().addProperty(PROPERTY,2);} + static boolean required(Workbook book){ + if(book instanceof XSSFWorkbook x&&x.getProperties().getCustomProperties().contains(PROPERTY)){ + var value=x.getProperties().getCustomProperties().getProperty(PROPERTY); + if(!value.isSetI4()||value.getI4()!=2)throw new ServiceException("询价单匹配信息版本无效,请重新导出");return true; + } + // Some spreadsheet editors drop custom properties but retain cell notes. + // Do not downgrade their selected-row scope to a whole-item legacy match. + if(book.getNumberOfSheets()>50)throw new ServiceException("报价工作表过多,请仅保留本批次询价单"); + for(var sheet:book)for(var note:sheet.getCellComments().values())if(note.getString().getString().contains(PREFIX))return true; + return false; + } + static void write(Row row,int column,Match match){ + try { + var bytes=new ByteArrayOutputStream(); + try(var out=new DataOutputStream(new GZIPOutputStream(bytes))){out.writeUTF(match.batch());out.writeUTF(match.snapshot());out.writeInt(match.rowIds().size());for(long id:match.rowIds())out.writeLong(id);} + comment(row.getCell(column),"报价回填匹配标记,请勿修改。\n"+PREFIX+Base64.getEncoder().encodeToString(bytes.toByteArray())); + }catch(IOException e){throw new IllegalStateException(e);} + } + static Match read(Row row){ + Match result=null; + for(var cell:row){ + var note=cell.getCellComment();if(note==null)continue; + String text=note.getString().getString();int start=text.indexOf(PREFIX);if(start<0)continue; + if(result!=null||text.length()>32767)throw invalid(); + try { + byte[] raw=Base64.getDecoder().decode(text.substring(start+PREFIX.length())); + try(var gzip=new GZIPInputStream(new ByteArrayInputStream(raw))){ + byte[] decoded=gzip.readNBytes(65537);if(decoded.length>65536)throw invalid(); + try(var in=new DataInputStream(new ByteArrayInputStream(decoded))){ + String batch=in.readUTF(),snapshot=in.readUTF();int count=in.readInt(); + if(batch.isBlank()||batch.length()>100||!snapshot.matches("[a-f0-9]{64}")||count<1||count>2000)throw invalid(); + var ids=new ArrayList();for(int i=0;i(ids).size()!=ids.size())throw invalid();result=new Match(batch,snapshot,List.copyOf(ids)); + } + } + }catch(Exception e){throw invalid();} + } + return result; + } + static void total(Cell cell){comment(cell,TOTAL);} + static boolean isTotal(Row row){for(var cell:row)if(cell.getCellComment()!=null&&TOTAL.equals(cell.getCellComment().getString().getString()))return true;return false;} + private static void comment(Cell cell,String text){ + if(cell.getCellComment()!=null)cell.removeCellComment(); + var sheet=cell.getSheet();var helper=sheet.getWorkbook().getCreationHelper();var anchor=helper.createClientAnchor(); + anchor.setCol1(cell.getColumnIndex());anchor.setCol2(cell.getColumnIndex()+3);anchor.setRow1(cell.getRowIndex());anchor.setRow2(cell.getRowIndex()+4); + var comment=sheet.createDrawingPatriarch().createCellComment(anchor);comment.setAuthor("系统匹配标记");comment.setString(helper.createRichTextString(text));comment.setVisible(false);cell.setCellComment(comment); + } + private static ServiceException invalid(){return new ServiceException("所选采购明细匹配标记缺失或已变化,请重新导出询价单");} +} diff --git a/ruoyi-admin/src/test/java/com/ruoyi/web/controller/warehouse/SupplierInquirySelectedColumnsTest.java b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/warehouse/SupplierInquirySelectedColumnsTest.java new file mode 100644 index 0000000..218122b --- /dev/null +++ b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/warehouse/SupplierInquirySelectedColumnsTest.java @@ -0,0 +1,68 @@ +package com.ruoyi.web.controller.warehouse; + +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.warehouse.domain.*; +import java.io.*; +import java.math.BigDecimal; +import java.nio.file.*; +import java.util.*; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +class SupplierInquirySelectedColumnsTest { + private PurchaseSheet purchase(){ + var batch=new PurchaseBatch();batch.setBatchNo("TEST-SELECTED");batch.setSupplierId(9L);batch.setSupplierName("测试供应商"); + var sheet=new PurchaseSheet();sheet.setBatch(batch);sheet.setVersion("v1");var rows=new ArrayList(); + for(long id=1;id<=3;id++){var r=new PurchaseRequest();r.setId(id);r.setProductId(id==3?2L:1L);r.setProductCode(id==3?"B":"A");r.setMaterialName("同名物品");r.setMaterialParams(id==3?"不应导出的规格乙":"不应导出的规格甲");r.setMaterialBrand("不应导出的品牌");r.setUnit("件");r.setPurchaseLink("https://example.com/private-item");r.setRemark("不应导出的备注");r.setQuantity(BigDecimal.valueOf(id));r.setActualUnitPrice(BigDecimal.TEN);r.setPurchaseStatus(0);r.setReceivedQuantity(BigDecimal.ZERO);rows.add(r);} + sheet.setRows(rows);return sheet; + } + private List> preview(XSSFWorkbook book,PurchaseSheet purchase)throws Exception{var out=new ByteArrayOutputStream();book.write(out);return SupplierQuoteImport.preview(new ByteArrayInputStream(out.toByteArray()),purchase);} + private void onlyColumns(XSSFWorkbook book,String...names){ + var sheet=book.getSheetAt(0);assertEquals(List.of(names),java.util.stream.StreamSupport.stream(sheet.getRow(5).spliterator(),false).map(Cell::getStringCellValue).toList()); + assertEquals(1,book.getNumberOfSheets());for(var row:sheet)assertTrue(row.getLastCellNum()<=names.length); + for(int c=0;c<64;c++)assertFalse(sheet.isColumnHidden(c),"No hidden export column "+c); + } + @Test void twoFieldsProduceExactlyTwoColumnsAndNoUnselectedBusinessData()throws Exception{ + try(var book=SupplierInquiryExport.workbook(purchase(),true,"name,quoteUnitPrice")){ + onlyColumns(book,"物品名称","报价单价(元)");var xml=book.getSharedStringSource().getSharedStringItems().toString(); + assertFalse(xml.contains("不应导出的"));assertFalse(xml.contains("private-item"));assertFalse(xml.contains("清单校验"));assertFalse(xml.contains("采购明细标识")); + var out=System.getProperty("inquirySelectedSampleOutput");if(out!=null){var root=Path.of(System.getProperty("user.dir")).toAbsolutePath();if(!Files.isDirectory(root.resolve("ruoyi-admin")))root=root.getParent();var folder=Path.of(out).toAbsolutePath().normalize();assertTrue(folder.startsWith(root.resolve(".codex-tmp")));Files.createDirectories(folder);try(var file=Files.newOutputStream(folder.resolve("two-fields.xlsx"))){book.write(file);}} + } + } + @Test void quantityCanBeOmittedWithoutBreakingTheQuoteAmountFormula()throws Exception{ + var purchase=purchase();for(String fields:List.of("name,quoteUnitPrice,quoteAmount","quantity,quoteUnitPrice,quoteAmount"))try(var book=SupplierInquiryExport.workbook(purchase,true,fields)){ + var row=book.getSheetAt(0).getRow(6);row.getCell(1).setCellValue(2.5);assertEquals(7.5,book.getCreationHelper().createFormulaEvaluator().evaluate(row.getCell(2)).getNumberValue());assertFalse(row.getCell(2).getCellFormula().contains("#REF!"));assertNull(preview(book,purchase).get(0).get("error")); + } + try(var book=SupplierInquiryExport.workbook(purchase,true,"quoteAmount")){onlyColumns(book,"报价金额(元)");assertEquals(CellType.BLANK,book.getSheetAt(0).getRow(6).getCell(0).getCellType());assertTrue(book.getSheetAt(0).getDataValidations().isEmpty());} + } + @Test void aQuoteOnlySelectedRowNeverExpandsToOtherRowsOfTheSameProduct()throws Exception{ + var purchase=purchase();var selected=SupplierInquiryExport.selected(purchase,List.of(1L)); + try(var book=SupplierInquiryExport.workbook(selected,true,"quoteUnitPrice")){onlyColumns(book,"报价单价(元)");book.getSheetAt(0).getRow(6).getCell(0).setCellValue(5);var result=preview(book,purchase);assertEquals(1,result.size());assertNull(result.get(0).get("error"));assertEquals(List.of(1L),result.get(0).get("rowIds"));} + } + @Test void matchingNotesFollowRowsWhenQuoteOnlyRowsAreReordered()throws Exception{ + var purchase=purchase();try(var book=SupplierInquiryExport.workbook(purchase,true,"quoteUnitPrice")){ + var tab=book.getSheetAt(0);tab.getRow(6).getCell(0).setCellValue(5);tab.getRow(7).getCell(0).setCellValue(8);tab.shiftRows(6,6,2);tab.shiftRows(7,7,-1);tab.shiftRows(8,8,-1); + var rows=preview(book,purchase);assertEquals(2,rows.size());assertTrue(rows.stream().allMatch(r->r.get("error")==null));assertEquals(List.of(3L),rows.get(0).get("rowIds"));assertEquals(new BigDecimal("8.0"),rows.get(0).get("unitPrice"));assertEquals(List.of(1L,2L),rows.get(1).get("rowIds")); + } + } + @Test void missingOrChangedMatchingNotesCannotFallBackToTheWholeProduct()throws Exception{ + var purchase=purchase();var selected=SupplierInquiryExport.selected(purchase,List.of(1L)); + for(var ids:List.of(List.of(),List.of(2L),List.of(999L),List.of(1L,2L),List.of(1L,1L)))try(var book=SupplierInquiryExport.workbook(selected,true,"name,quoteUnitPrice")){ + var row=book.getSheetAt(0).getRow(6);row.getCell(1).setCellValue(5);var before=SupplierInquiryMetadata.read(row);SupplierInquiryMetadata.write(row,0,new SupplierInquiryMetadata.Match(before.batch(),before.snapshot(),ids));assertNotNull(preview(book,purchase).get(0).get("error")); + } + try(var book=SupplierInquiryExport.workbook(selected,true,"name,quoteUnitPrice")){var row=book.getSheetAt(0).getRow(6);row.getCell(1).setCellValue(5);row.getCell(0).removeCellComment();var result=preview(book,purchase);assertNotNull(result.get(0).get("error"));assertEquals(List.of(),result.get(0).get("rowIds"));} + try(var book=SupplierInquiryExport.workbook(selected,true,"name,quoteUnitPrice")){book.getProperties().getCustomProperties().getUnderlyingProperties().getPropertyList().clear();book.getSheetAt(0).getRow(6).getCell(1).setCellValue(5);assertEquals(List.of(1L),preview(book,purchase).get(0).get("rowIds"));} + } + @Test void singleActualAmountColumnKeepsTheTotalWithinThatOneColumn()throws Exception{ + try(var book=SupplierInquiryExport.workbook(purchase(),true,"actualAmount")){onlyColumns(book,"实际金额(元)");assertEquals("实际金额合计",book.getSheetAt(0).getRow(8).getCell(0).getStringCellValue());assertEquals(60,book.getSheetAt(0).getRow(9).getCell(0).getNumericCellValue());assertTrue(book.getPrintArea(0).endsWith("$A$10"));} + try(var book=SupplierInquiryExport.workbook(purchase(),true,"name,quoteUnitPrice,actualAmount")){book.getSheetAt(0).getRow(6).getCell(1).setCellValue(5);assertEquals(2,preview(book,purchase()).size(),"Totals must not become quote lines");} + } + @Test void serialNumberIsOptionalAndHiddenActualFieldsCannotBeRequestedInCompactMode()throws Exception{ + try(var book=SupplierInquiryExport.workbook(purchase(),false,"index,name,actualAmount")){onlyColumns(book,"序号","物品名称");} + assertThrows(ServiceException.class,()->SupplierInquiryExport.workbook(purchase(),false,"actualAmount")); + assertThrows(ServiceException.class,()->SupplierInquiryExport.workbook(purchase(),true,"")); + assertThrows(ServiceException.class,()->SupplierInquiryExport.workbook(purchase(),true,"unknown")); + } +}