feat(app): 优化移动端应用配置和功能实现
- 添加生产环境服务器地址配置支持内外网切换 - 实现采购列表只看我创建的功能开关 - 更新构建脚本中的默认生产环境API地址 - 优化采购单表格单元格编辑体验改用自动补全组件 - 调整应用更新检查逻辑增强生产环境兼容性 - 修复开发服务器切换时的一些验证问题 - 增强应用启动时的服务地址配置灵活性
This commit is contained in:
parent
c9dccdae5c
commit
9f39fb5ffe
@ -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<Long> 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<Long>();for(int i=0;i<count;i++){long id=in.readLong();if(id<=0)throw invalid();ids.add(id);}
|
||||
if(in.read()!=-1||new HashSet<>(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("所选采购明细匹配标记缺失或已变化,请重新导出询价单");}
|
||||
}
|
||||
@ -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<PurchaseRequest>();
|
||||
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<Map<String,Object>> 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.<Long>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"));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user