parent
							
								
									173a20d027
								
							
						
					
					
						commit
						2e79fce459
					
				| 
						 | 
				
			
			@ -298,165 +298,163 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadList
 | 
			
		|||
                            ArrayList<DynamicObject> dynamicObjects = new ArrayList<>();
 | 
			
		||||
                            Map<String, BigDecimal> 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("清单汇总识别--生产明细成功");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue