parent
e7e7682a23
commit
92059e36b1
|
@ -67,7 +67,6 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
private static final String BASEDATA_FIELD = "multitypepartya";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
super.initialize();
|
||||
|
@ -164,6 +163,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除汇总明细并且删除清单明细
|
||||
*/
|
||||
|
@ -287,6 +287,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
InputStream in = urlConnection.getInputStream();
|
||||
// FileInputStream in = new FileInputStream(fileUrl);
|
||||
Workbook workbook = WorkbookFactory.create(in);
|
||||
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
|
||||
|
||||
/**
|
||||
* --------------------------------------明细------------------------------------------------
|
||||
|
@ -357,93 +358,90 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
contractsummarylist.set("qeug_unit", cell);//计量单位
|
||||
break;
|
||||
case 6:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
String expression = cell.toString();
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
String value6 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value6)) {
|
||||
try {
|
||||
BigDecimal results =BigDecimal.valueOf(Double.parseDouble(engine.eval(expression).toString()));
|
||||
BigDecimal results = new BigDecimal(value6);
|
||||
contractsummarylist.set("qeug_decimalqty", results);
|
||||
} catch (Exception e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败:"+e.getMessage());
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 数量列格式错误");
|
||||
return;
|
||||
// 处理计算失败的情况
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
String expression = cell.toString();
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
String value7 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value7)) {
|
||||
try {
|
||||
BigDecimal results =BigDecimal.valueOf(Double.parseDouble(engine.eval(expression).toString()));
|
||||
BigDecimal results = new BigDecimal(value7);
|
||||
contractsummarylist.set("qeug_unitprice", results);// 综合单价
|
||||
} catch (Exception e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败:"+e.getMessage());
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 单价列格式错误");
|
||||
return;
|
||||
// 处理计算失败的情况
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
//todo:保留几位有效数字
|
||||
Cell cell1 = row.getCell(6);
|
||||
Cell cell2 = row.getCell(7);
|
||||
if (cell1 != null && cell2 != null && StringUtils.isNotEmpty(cell1.toString()) && StringUtils.isNotEmpty(cell2.toString())) {
|
||||
BigDecimal results = BigDecimal.ZERO;
|
||||
String value8 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value8)) {
|
||||
try {
|
||||
double value1 = cell1.getNumericCellValue();
|
||||
double value2 = cell2.getNumericCellValue();
|
||||
results = BigDecimal.valueOf(value1 * value2).setScale(3, RoundingMode.HALF_UP);
|
||||
BigDecimal results = new BigDecimal(value8);
|
||||
// 保留三位小数,采用四舍五入的舍入模式
|
||||
results = results.setScale(3, RoundingMode.HALF_UP);
|
||||
contractsummarylist.set("qeug_amounttotal", results); // 合计金额
|
||||
} catch (Exception e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败:" + e.getMessage());
|
||||
amounttotal = amounttotal.add(results);
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 合计金额列格式错误");
|
||||
return;
|
||||
}
|
||||
amounttotal = amounttotal.add(results);
|
||||
}
|
||||
break;
|
||||
// case 8:
|
||||
// Cell cell1 = row.getCell(6);
|
||||
// Cell cell2 = row.getCell(7);
|
||||
// if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
// String expression = cell.toString();
|
||||
// ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
// BigDecimal results = BigDecimal.ZERO;
|
||||
// try {
|
||||
// results =BigDecimal.valueOf(Double.parseDouble(engine.eval(expression).toString()));
|
||||
// contractsummarylist.set("qeug_amounttotal",results);//综合单价
|
||||
// } catch (Exception e) {
|
||||
// this.getView().showErrorNotification("清单汇总识别--生成明细失败:"+e.getMessage());
|
||||
// return ;
|
||||
// // 处理计算失败的情况
|
||||
// }
|
||||
// amounttotal = amounttotal.add(results);
|
||||
// }
|
||||
// break;
|
||||
case 9:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
contractsummarylist.set("qeug_artificial",BigDecimal.valueOf(Double.parseDouble(cell.toString())));//人工单价
|
||||
String value9 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value9)) {
|
||||
try {
|
||||
contractsummarylist.set("qeug_artificial", new BigDecimal(value9));// 人工单价
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 人工单价列格式错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 10:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
contractsummarylist.set("qeug_provisional",BigDecimal.valueOf(Double.parseDouble(cell.toString())));//辅材单价
|
||||
String value10 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value10)) {
|
||||
try {
|
||||
contractsummarylist.set("qeug_provisional", new BigDecimal(value10));// 辅材单价
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 辅材单价列格式错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
contractsummarylist.set("qeug_unitpriceofmainmater",BigDecimal.valueOf(Double.parseDouble(cell.toString())));//主材单价
|
||||
String value11 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value11)) {
|
||||
try {
|
||||
contractsummarylist.set("qeug_unitpriceofmainmater", new BigDecimal(value11));// 主材单价
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 主材单价列格式错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
contractsummarylist.set("qeug_mechanicalunitprice",BigDecimal.valueOf(Double.parseDouble(cell.toString())));//机械,设备单价
|
||||
String value12 = getCellValueAsString(cell, evaluator);
|
||||
if (StringUtils.isNotEmpty(value12)) {
|
||||
try {
|
||||
contractsummarylist.set("qeug_mechanicalunitprice", new BigDecimal(value12));// 机械,设备单价
|
||||
} catch (NumberFormatException e) {
|
||||
this.getView().showErrorNotification("清单汇总识别--生成明细失败: 机械设备单价列格式错误");
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
if (StringUtils.isNotEmpty(cell.toString())) {
|
||||
contractsummarylist.set("qeug_remarks",cell);//备注
|
||||
}
|
||||
contractsummarylist.set("qeug_remarks", getCellValueAsString(cell, evaluator));// 备注
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -510,6 +508,39 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
}
|
||||
}
|
||||
|
||||
private String getCellValueAsString(Cell cell, FormulaEvaluator evaluator) {
|
||||
if (cell == null) {
|
||||
return "";
|
||||
}
|
||||
switch (cell.getCellType()) {
|
||||
case STRING:
|
||||
return cell.getStringCellValue();
|
||||
case NUMERIC:
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
// 如果是日期格式,可根据需要进行处理
|
||||
return cell.getDateCellValue().toString();
|
||||
} else {
|
||||
return String.valueOf(cell.getNumericCellValue());
|
||||
}
|
||||
case BOOLEAN:
|
||||
return String.valueOf(cell.getBooleanCellValue());
|
||||
case FORMULA:
|
||||
CellValue cellValue = evaluator.evaluate(cell);
|
||||
switch (cellValue.getCellType()) {
|
||||
case NUMERIC:
|
||||
return String.valueOf(cellValue.getNumberValue());
|
||||
case STRING:
|
||||
return cellValue.getStringValue();
|
||||
case BOOLEAN:
|
||||
return String.valueOf(cellValue.getBooleanValue());
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRowEmpty(Row row) {
|
||||
if (row == null) {
|
||||
return true;
|
||||
|
@ -604,6 +635,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
|
|||
|
||||
/**
|
||||
* 打开列表展示清单详情页
|
||||
*
|
||||
* @param formView 页面
|
||||
* @param model 模型
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue