public boolean saveReport(ApplyReportDto dto) { BillApply billApply = billApplyMapper.selectById(dto.getBillApplyId()); ValidationUtils.checkNotNull(billApply, "未查询到开票申请"); ValidationUtils.checkMustTrue(ApplyStatusEnum.isInvoicing(billApply.getStatus()), "非开票中,无法操作开票"); //对象转化 List<BillApplyReport> map = MapperUtils.mapObjs(dto.getReportDetails(), BillApplyReport.class, (source, destination) -> { destination.setBillApplyId(billApply.getId()); destination.setCreateUser(AdminUtil.getCurrentAdminName()); }); return this.saveBatch(map, 200); }在这个接口里加个需求,列表里的billAmount的总金额要和申请记录里的billAmount总金额相等 public boolean saveReport(ApplyReportDto dto) { BillApply billApply = billApplyMapper.selectById(dto.getBillApplyId()); ValidationUtils.checkNotNull(billApply, "未查询到开票申请"); ValidationUtils.checkMustTrue(ApplyStatusEnum.isInvoicing(billApply.getStatus()), "非开票中,无法操作开票"); //对象转化 List<BillApplyReport> map = MapperUtils.mapObjs(dto.getReportDetails(), BillApplyReport.class, (source, destination) -> { destination.setBillApplyId(billApply.getId()); destination.setCreateUser(AdminUtil.getCurrentAdminName()); }); return this.saveBatch(map, 200); }在这个接口里加个需求,列表里的billAmount的总金额要和申请记录里的billAmount总金额相等 否则抛出异常
时间: 2024-04-12 16:30:25 浏览: 120
Character.UnicodeBlock中cjk的说明详解
您可以在代码中添加以下逻辑来实现您的需求:
```java
public boolean saveReport(ApplyReportDto dto) {
BillApply billApply = billApplyMapper.selectById(dto.getBillApplyId());
ValidationUtils.checkNotNull(billApply, "未查询到开票申请");
ValidationUtils.checkMustTrue(ApplyStatusEnum.isInvoicing(billApply.getStatus()), "非开票中,无法操作开票");
// 计算列表中billAmount的总金额
BigDecimal totalAmount = BigDecimal.ZERO;
for (BillApplyReport report : dto.getReportDetails()) {
totalAmount = totalAmount.add(report.getBillAmount());
}
// 验证总金额与申请记录中的billAmount总金额是否相等
if (totalAmount.compareTo(billApply.getBillAmount()) != 0) {
throw new RuntimeException("列表中的billAmount总金额与申请记录中的billAmount总金额不相等");
}
// 对象转化
List<BillApplyReport> map = MapperUtils.mapObjs(dto.getReportDetails(), BillApplyReport.class, (source, destination) -> {
destination.setBillApplyId(billApply.getId());
destination.setCreateUser(AdminUtil.getCurrentAdminName());
});
return this.saveBatch(map, 200);
}
```
在上述代码中,我们首先计算了列表中billAmount的总金额,并与申请记录中的billAmount总金额进行比较。如果不相等,则抛出异常。否则,继续执行原有的逻辑。
阅读全文