1.优化合同清单导入功能

S
This commit is contained in:
weiyunlong 2025-03-04 14:27:27 +08:00
parent e7e7682a23
commit 92059e36b1
1 changed files with 136 additions and 104 deletions

View File

@ -60,20 +60,19 @@ import java.util.regex.Pattern;
* qeug_recon_supplyconb_ext 补充合同
* qeug_recon_temptofixb_ext 暂转固
*/
public class ContractFormPlugin extends AbstractFormPlugin implements UploadListener, BasedataEditListener, IDataModelChangeListener {
public class ContractFormPlugin extends AbstractFormPlugin implements UploadListener, BasedataEditListener, IDataModelChangeListener {
private static final Log logger = LogFactory.getLog(ContractFormPlugin.class);
private static final String BASEDATA_FIELD = "multitypepartya";
@Override
public void initialize() {
super.initialize();
this.getModel().addDataModelChangeListener(this);
BasedataEdit mulEdit = this.getControl(BASEDATA_FIELD);
if (mulEdit!=null){
if (mulEdit != null) {
mulEdit.addBasedataEditListener(this);
}
}
@ -83,7 +82,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
BasedataEdit edit = (BasedataEdit) afterBindingDataEvent.getSource();
DynamicObject dataEntity = this.getModel().getDataEntity(true);
DynamicObject basedata_field = dataEntity.getDynamicObject(BASEDATA_FIELD);
if (!basedata_field.getDynamicObjectType().getName().equals("bos_org")){
if (!basedata_field.getDynamicObjectType().getName().equals("bos_org")) {
return;
}
Object v = afterBindingDataEvent.getDataEntity();
@ -117,8 +116,8 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
Object pkValue = basedata_field.getPkValue();
String name = dt.getName();
DynamicObject single = BusinessDataServiceHelper.loadSingle(pkValue, name);
if (!single.getString(nameKey).isEmpty()){
displayProp = String.format("%s", single.getString(nameKey));
if (!single.getString(nameKey).isEmpty()) {
displayProp = String.format("%s", single.getString(nameKey));
}
//设置显示属性
afterBindingDataEvent.setDisplayProp(displayProp.toString());
@ -164,15 +163,16 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
// }
}
}
/**
* 删除汇总明细并且删除清单明细
*/
private boolean deleteList(){
private boolean deleteList() {
boolean result = true;
//合同清单汇总分录
DynamicObjectCollection qeug_invoiceentryinfos = this.getView().getModel().getEntryEntity("qeug_invoiceentryinfo");
//删除对应明细数据
long pkValue = (long)this.getModel().getDataEntity().getPkValue();
long pkValue = (long) this.getModel().getDataEntity().getPkValue();
if (0 == pkValue) {
result = false;
return result;
@ -182,9 +182,9 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
for (DynamicObject qeug_invoiceentryinfo : qeug_invoiceentryinfos) {
String qeugSummarycontent = qeug_invoiceentryinfo.getString("qeug_summarycontent");//分录中的汇总内容(sheet名字)
q2 = new QFilter("qeug_sheetname", QCP.equals, qeugSummarycontent);
DynamicObject qeug_contractsummarylist = BusinessDataServiceHelper.loadSingle("qeug_contractsummarylist", new QFilter[]{q1,q2});
DynamicObject qeug_contractsummarylist = BusinessDataServiceHelper.loadSingle("qeug_contractsummarylist", new QFilter[]{q1, q2});
if (null != qeug_contractsummarylist) {
int qeug_contractsummarylist1 = DeleteServiceHelper.delete("qeug_contractsummarylist", new QFilter[]{q1,q2});
int qeug_contractsummarylist1 = DeleteServiceHelper.delete("qeug_contractsummarylist", new QFilter[]{q1, q2});
//失败
if (0 == qeug_contractsummarylist1) {
this.getView().showTipNotification("删除失败:请联系管理员");
@ -196,7 +196,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
int size = qeug_invoiceentryinfos.size();
//删除单据体数据
for (int i = 0; i < size; i++) {
this.getView().getModel().deleteEntryRow("qeug_invoiceentryinfo",0);
this.getView().getModel().deleteEntryRow("qeug_invoiceentryinfo", 0);
}
// SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)});
this.getView().invokeOperation("save");
@ -211,7 +211,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
super.propertyChanged(e);
String name = e.getProperty().getName();//字段名称
if("qeug_chmentpanel_f".equals(name)){
if ("qeug_chmentpanel_f".equals(name)) {
Object qeugChmentpanelF = this.getModel().getValue("qeug_chmentpanel_f");
if (qeugChmentpanelF instanceof Number) {
int pkLongValue = ((Number) qeugChmentpanelF).intValue(); // 转换为 long
@ -220,14 +220,14 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
this.getView().updateView("qeug_invoiceentryinfo");
}
}
}else if("qeug_marginlevel".equals(name)){
} else if ("qeug_marginlevel".equals(name)) {
int qeug_bondentry = this.getModel().getEntryCurrentRowIndex("qeug_bondentry");
BigDecimal qeug_marginlevel = (BigDecimal)this.getModel().getValue("qeug_marginlevel", qeug_bondentry);
BigDecimal qeug_marginlevel = (BigDecimal) this.getModel().getValue("qeug_marginlevel", qeug_bondentry);
DynamicObjectCollection qeugBondentrys = this.getModel().getEntryEntity("qeug_bondentry");//保证金明细
BigDecimal qeugMarginlevel = BigDecimal.ZERO;
if (qeugBondentrys.size() > 0) {
for (DynamicObject qeugBondentry : qeugBondentrys) {
qeugMarginlevel = qeugMarginlevel.add(qeugBondentry.getBigDecimal("qeug_marginlevel")) ;
qeugMarginlevel = qeugMarginlevel.add(qeugBondentry.getBigDecimal("qeug_marginlevel"));
}
}
if (qeugMarginlevel.compareTo(BigDecimal.valueOf(100)) > 0) {
@ -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();
/**
* --------------------------------------明细------------------------------------------------
@ -296,7 +297,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
ArrayList<DynamicObject> dynamicObjects = new ArrayList<>();
Map<String, BigDecimal> amounttotalMap = new HashMap<>();
for (Sheet sheet : workbook) {
int rowNum = 0;
int rowNum = 0;
// 获取总行数
int rowCountsheet = sheet.getPhysicalNumberOfRows();//总行数
for (Row cells : sheet) {
@ -310,7 +311,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
break;
}
}
BigDecimal amounttotal =BigDecimal.ZERO;
BigDecimal amounttotal = BigDecimal.ZERO;
for (int j = rowNum; j <= rowCountsheet - 2; j++) {
Row row = sheet.getRow(j);
//第一列断号
@ -329,121 +330,118 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
//合同明细清单 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名字
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 columnIndex = cell.getColumnIndex();
switch (columnIndex){
switch (columnIndex) {
case 0:
double num = Double.parseDouble(cell.toString());
int result = (int)num;
contractsummarylist.set("qeug_seqs",result);//序号
int result = (int) num;
contractsummarylist.set("qeug_seqs", result);//序号
break;
case 1:
contractsummarylist.set("qeug_projectnumber",cell);//项目编码
contractsummarylist.set("qeug_projectnumber", cell);//项目编码
break;
case 2:
contractsummarylist.set("qeug_projectname",cell);//项目名称
contractsummarylist.set("qeug_projectname", cell);//项目名称
break;
case 3:
contractsummarylist.set("qeug_featuredescript",cell);//项目特征描述
contractsummarylist.set("qeug_featuredescript", cell);//项目特征描述
break;
case 4:
contractsummarylist.set("qeug_engincontent",cell);//工程内容
contractsummarylist.set("qeug_engincontent", cell);//工程内容
break;
case 5:
contractsummarylist.set("qeug_unit",cell);//计量单位
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());
return ;
// 处理计算失败的情况
} 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()));
contractsummarylist.set("qeug_unitprice",results);//综合单价
} catch (Exception e) {
this.getView().showErrorNotification("清单汇总识别--生成明细失败:"+e.getMessage());
return ;
// 处理计算失败的情况
BigDecimal results = new BigDecimal(value7);
contractsummarylist.set("qeug_unitprice", results);// 综合单价
} 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;
@ -451,7 +449,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
}
dynamicObjects.add(contractsummarylist);
}
amounttotalMap.put(sheet.getSheetName(),amounttotal);//一个sheet一个总金额
amounttotalMap.put(sheet.getSheetName(), amounttotal);//一个sheet一个总金额
// this.getView().showSuccessNotification("清单汇总识别--生产明细成功");
}
for (DynamicObject dynamicObject : dynamicObjects) {
@ -469,15 +467,15 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
Sheet sheet = workbook.getSheetAt(i);
qeugInvoiceentryinfo.addNew();
this.getModel().setValue("qeug_seq", i+1,i);//序号
this.getModel().setValue("qeug_summarycontent", sheet.getSheetName(),i);//汇总内容
this.getModel().setValue("qeug_seq", i + 1, i);//序号
this.getModel().setValue("qeug_summarycontent", sheet.getSheetName(), i);//汇总内容
BigDecimal bigDecimal = amounttotalMap.get(sheet.getSheetName());
this.getModel().setValue("qeug_amount", bigDecimal,i);//金额()
this.getModel().setValue("qeug_isnew", false,i);//是否新增行
this.getModel().setValue("qeug_amount", bigDecimal, i);//金额()
this.getModel().setValue("qeug_isnew", false, i);//是否新增行
DynamicObject bd_currency = BusinessDataServiceHelper.loadSingle("bd_currency",
new QFilter[]{new QFilter("number", QCP.equals, "CNY")});
if (null != bd_currency) {
this.getModel().setValue("qeug_currencylist", bd_currency,i);//清单币别
this.getModel().setValue("qeug_currencylist", bd_currency, i);//清单币别
}
}
@ -491,7 +489,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
}
break;
//下载清单模板
//下载清单模板
case "downloadlist":
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle("qeug_downloadlist", new QFilter[]{new QFilter("number", QCP.equals, "MB-0001")});
if (null != dynamicObject) {
@ -510,12 +508,45 @@ 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;
}
for (Cell cell : row) {
if (cell!= null && cell.getCellType()!= CellType.BLANK) {
if (cell != null && cell.getCellType() != CellType.BLANK) {
return false;
}
}
@ -525,7 +556,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
private static String[] getRowData(Row row) {
List<String> rowDataList = new ArrayList<>();
for (Cell cell : row) {
if (cell!= null) {
if (cell != null) {
if (cell.getCellType() == CellType.STRING) {
rowDataList.add(cell.getStringCellValue());
} else if (cell.getCellType() == CellType.NUMERIC) {
@ -562,7 +593,7 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
//分录--查看合同清单明细按钮
case "operationcolumnap":
int index = this.getModel().getEntryCurrentRowIndex("qeug_invoiceentryinfo");
boolean qeugIsnew = (boolean)this.getModel().getValue("qeug_isnew", index);
boolean qeugIsnew = (boolean) this.getModel().getValue("qeug_isnew", index);
if (qeugIsnew) {
this.getView().showTipNotification("新增行无法查看明细");
return;
@ -571,22 +602,22 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
break;
case "deleteentry1":
//用户在删除汇总明细时如果当前汇总已经生成清单一并删除掉
EntryGrid qeug_invoiceentryinfo = (EntryGrid)this.getView().getControl("qeug_invoiceentryinfo");
EntryGrid qeug_invoiceentryinfo = (EntryGrid) this.getView().getControl("qeug_invoiceentryinfo");
int[] selectRows = qeug_invoiceentryinfo.getSelectRows();
if (selectRows.length > 0) {
for (int i = 0; i < selectRows.length; i++) {
int selectRow = selectRows[i];
long pkValue = (long)this.getModel().getDataEntity().getPkValue();
long pkValue = (long) this.getModel().getDataEntity().getPkValue();
if (0 == pkValue) {
return;
}
String qeug_summarycontent = (String)this.getModel().getValue("qeug_summarycontent",selectRow);//分录中的汇总内容(sheet名字)
String qeug_summarycontent = (String) this.getModel().getValue("qeug_summarycontent", selectRow);//分录中的汇总内容(sheet名字)
QFilter q1 = new QFilter("qeug_sheetname", QCP.equals, qeug_summarycontent);
QFilter q2 = new QFilter("qeug_contractid", QCP.equals, String.valueOf(pkValue));
DynamicObject qeug_contractsummarylist = BusinessDataServiceHelper.loadSingle("qeug_contractsummarylist", new QFilter[]{q1,q2});
DynamicObject qeug_contractsummarylist = BusinessDataServiceHelper.loadSingle("qeug_contractsummarylist", new QFilter[]{q1, q2});
if (null != qeug_contractsummarylist) {
int qeug_contractsummarylist1 = DeleteServiceHelper.delete("qeug_contractsummarylist", new QFilter[]{q1,q2});
int qeug_contractsummarylist1 = DeleteServiceHelper.delete("qeug_contractsummarylist", new QFilter[]{q1, q2});
//失败
if (0 == qeug_contractsummarylist1) {
this.getView().showTipNotification("删除失败:请联系管理员");
@ -604,8 +635,9 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
/**
* 打开列表展示清单详情页
*
* @param formView 页面
* @param model 模型
* @param model 模型
*/
private void getListShowParamer(IFormView formView, IDataModel model) {
@ -624,8 +656,8 @@ public class ContractFormPlugin extends AbstractFormPlugin implements UploadLis
Object pkValue = formView.getModel().getDataEntity().getPkValue();//合同ID
QFilter q1 = new QFilter("qeug_sheetname", QCP.equals, qeug_summarycontent);
QFilter q2 = new QFilter("qeug_contractid",QCP.equals, String.valueOf(pkValue));
QFilter q3 = new QFilter("qeug_workloadcfmid",QCP.equals, "");
QFilter q2 = new QFilter("qeug_contractid", QCP.equals, String.valueOf(pkValue));
QFilter q3 = new QFilter("qeug_workloadcfmid", QCP.equals, "");
List<QFilter> listQF = Lists.newArrayList();
listQF.add(q1.and(q2).and(q3));
parameter.setListFilterParameter(new ListFilterParameter(listQF, null));