From 2e79fce459ddaa5bde58c3fb5caa00dcef04c1e4 Mon Sep 17 00:00:00 2001 From: weiyunlong Date: Tue, 25 Mar 2025 15:17:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BC=98=E5=8C=96=E5=90=88=E5=90=8C=E8=AF=86?= =?UTF-8?q?=E5=88=ABexcel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit S --- .../recon/formplugin/ContractFormPlugin.java | 296 +++++++++--------- 1 file changed, 147 insertions(+), 149 deletions(-) diff --git a/main/java/shkd/repc/recon/formplugin/ContractFormPlugin.java b/main/java/shkd/repc/recon/formplugin/ContractFormPlugin.java index 8f29363..3e4fdb9 100644 --- a/main/java/shkd/repc/recon/formplugin/ContractFormPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ContractFormPlugin.java @@ -298,165 +298,163 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadList ArrayList dynamicObjects = new ArrayList<>(); Map amounttotalMap = new HashMap<>(); for (Sheet sheet : workbook) { - int rowNum = 0; + int rowNum = 6;//6/7 // 获取总行数 int rowCountsheet = sheet.getPhysicalNumberOfRows();//总行数 - for (Row cells : sheet) { - String billno = cells.getCell(0).toString(); - //第一列属于数字 - - Pattern pattern = Pattern.compile("^-?\\d+(\\.\\d+)?$"); - boolean matches = pattern.matcher(billno).matches(); - if (matches) { - rowNum = cells.getRowNum(); + for (Row row : sheet) { + Cell cell = row.getCell(0); + if (cell != null && cell.getCellType() == CellType.NUMERIC) { + rowNum = row.getRowNum(); break; } } BigDecimal amounttotal = BigDecimal.ZERO; for (int j = rowNum; j <= rowCountsheet - 2; j++) { Row row = sheet.getRow(j); - //第一列断号 - String seq = row.getCell(0).toString(); - seq = seq.split("\\.")[0]; // 取第一个部分 - if (StringUtils.isEmpty(seq)) { - System.out.println("第 " + (j + 1) + " 行第一列是空值,跳过"); - continue; - } - //第一列不包含数字 - boolean containsDigit = seq.matches(".*\\d.*"); - if (!containsDigit) { - System.out.println(); - continue; - } - // 第一列只能是数字 - boolean isOnlyDigits = seq.matches("\\d+"); - if (!isOnlyDigits) { - System.out.println("第 " + (j + 1) + " 行第一列不是纯数字,跳过"); - continue; - } - - //合同明细清单 qeug_contractsummarylist - // 存合同id,sheet名字 - DynamicObject contractsummarylist = BusinessDataServiceHelper.newDynamicObject("qeug_contractsummarylist"); - contractsummarylist.set("enable", "1");//使用状态 - contractsummarylist.set("status", "A");//数据状态 - contractsummarylist.set("qeug_contractid", this.getModel().getDataEntity().getPkValue().toString());//合同id - contractsummarylist.set("qeug_sheetname", sheet.getSheetName());//sheet名字 - for (Cell cell : row) { - int rowNum1 = row.getRowNum() +1;//excel行号 - int columnIndex = cell.getColumnIndex(); - switch (columnIndex) { - case 0: - double num = Double.parseDouble(cell.toString()); - int result = (int) num; - contractsummarylist.set("qeug_seqs", result);//序号 - break; - case 1: - contractsummarylist.set("qeug_projectnumber", cell);//项目编码 - break; - case 2: - contractsummarylist.set("qeug_projectname", cell);//项目名称 - break; - case 3: - contractsummarylist.set("qeug_featuredescript", cell);//项目特征描述 - break; - case 4: - contractsummarylist.set("qeug_engincontent", cell);//工程内容 - break; - case 5: - contractsummarylist.set("qeug_unit", cell);//计量单位 - break; - case 6: - String value6 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value6)) { - try { - BigDecimal results = new BigDecimal(value6); - contractsummarylist.set("qeug_decimalqty", results); - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 工程量格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 7: - String value7 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value7)) { - try { - BigDecimal results = new BigDecimal(value7); - contractsummarylist.set("qeug_unitprice", results);// 综合单价 - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 单价列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 8: - String value8 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value8)) { - try { - BigDecimal results = new BigDecimal(value8); - // 保留三位小数,采用四舍五入的舍入模式 - results = results.setScale(3, RoundingMode.HALF_UP); - contractsummarylist.set("qeug_amounttotal", results); // 合计金额 - amounttotal = amounttotal.add(results); - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 合计金额列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 9: - String value9 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value9)) { - try { - contractsummarylist.set("qeug_artificial", new BigDecimal(value9));// 人工单价 - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 人工单价列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 10: - String value10 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value10)) { - try { - contractsummarylist.set("qeug_provisional", new BigDecimal(value10));// 辅材单价 - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 辅材单价列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 11: - String value11 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value11)) { - try { - contractsummarylist.set("qeug_unitpriceofmainmater", new BigDecimal(value11));// 主材单价 - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 主材单价列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 12: - String value12 = getCellValueAsString(cell, evaluator); - if (StringUtils.isNotEmpty(value12)) { - try { - contractsummarylist.set("qeug_mechanicalunitprice", new BigDecimal(value12));// 机械,设备单价 - } catch (NumberFormatException e) { - this.getView().showErrorNotification("清单汇总识别--生成明细失败: 机械设备单价列格式错误,行数:"+ rowNum1); - return; - } - } - break; - case 13: - contractsummarylist.set("qeug_remarks", getCellValueAsString(cell, evaluator));// 备注 - break; - default: - break; + if (null != row) { + //第一列断号 + String seq = row.getCell(0).toString(); + seq = seq.split("\\.")[0]; // 取第一个部分 + if (StringUtils.isEmpty(seq)) { + System.out.println("第 " + (j + 1) + " 行第一列是空值,跳过"); + continue; } + //第一列不包含数字 + boolean containsDigit = seq.matches(".*\\d.*"); + if (!containsDigit) { + System.out.println(); + continue; + } + // 第一列只能是数字 + boolean isOnlyDigits = seq.matches("\\d+"); + if (!isOnlyDigits) { + System.out.println("第 " + (j + 1) + " 行第一列不是纯数字,跳过"); + continue; + } + + //合同明细清单 qeug_contractsummarylist + // 存合同id,sheet名字 + DynamicObject contractsummarylist = BusinessDataServiceHelper.newDynamicObject("qeug_contractsummarylist"); + contractsummarylist.set("enable", "1");//使用状态 + contractsummarylist.set("status", "A");//数据状态 + contractsummarylist.set("qeug_contractid", this.getModel().getDataEntity().getPkValue().toString());//合同id + contractsummarylist.set("qeug_sheetname", sheet.getSheetName());//sheet名字 + for (Cell cell : row) { + int rowNum1 = row.getRowNum() +1;//excel行号 + int columnIndex = cell.getColumnIndex(); + switch (columnIndex) { + case 0: + double num = Double.parseDouble(cell.toString()); + int result = (int) num; + contractsummarylist.set("qeug_seqs", result);//序号 + break; + case 1: + contractsummarylist.set("qeug_projectnumber", cell);//项目编码 + break; + case 2: + contractsummarylist.set("qeug_projectname", cell);//项目名称 + break; + case 3: + contractsummarylist.set("qeug_featuredescript", cell);//项目特征描述 + break; + case 4: + contractsummarylist.set("qeug_engincontent", cell);//工程内容 + break; + case 5: + contractsummarylist.set("qeug_unit", cell);//计量单位 + break; + case 6: + String value6 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value6)) { + try { + BigDecimal results = new BigDecimal(value6); + contractsummarylist.set("qeug_decimalqty", results); + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 工程量格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 7: + String value7 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value7)) { + try { + BigDecimal results = new BigDecimal(value7); + contractsummarylist.set("qeug_unitprice", results);// 综合单价 + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 单价列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 8: + String value8 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value8)) { + try { + BigDecimal results = new BigDecimal(value8); + // 保留三位小数,采用四舍五入的舍入模式 + results = results.setScale(3, RoundingMode.HALF_UP); + contractsummarylist.set("qeug_amounttotal", results); // 合计金额 + amounttotal = amounttotal.add(results); + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 合计金额列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 9: + String value9 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value9)) { + try { + contractsummarylist.set("qeug_artificial", new BigDecimal(value9));// 人工单价 + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 人工单价列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 10: + String value10 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value10)) { + try { + contractsummarylist.set("qeug_provisional", new BigDecimal(value10));// 辅材单价 + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 辅材单价列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 11: + String value11 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value11)) { + try { + contractsummarylist.set("qeug_unitpriceofmainmater", new BigDecimal(value11));// 主材单价 + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 主材单价列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 12: + String value12 = getCellValueAsString(cell, evaluator); + if (StringUtils.isNotEmpty(value12)) { + try { + contractsummarylist.set("qeug_mechanicalunitprice", new BigDecimal(value12));// 机械,设备单价 + } catch (NumberFormatException e) { + this.getView().showErrorNotification("清单汇总识别--生成明细失败: 机械设备单价列格式错误,行数:"+ rowNum1); + return; + } + } + break; + case 13: + contractsummarylist.set("qeug_remarks", getCellValueAsString(cell, evaluator));// 备注 + break; + default: + break; + } + } + dynamicObjects.add(contractsummarylist); } - dynamicObjects.add(contractsummarylist); } amounttotalMap.put(sheet.getSheetName(), amounttotal);//一个sheet一个总金额 // this.getView().showSuccessNotification("清单汇总识别--生产明细成功");