feat(invoice): 优化发票上传和查询功能

- 修改 InvoiceController 中 uploadNew 方法返回值类型- 在 InvoiceDto 和 InvoiceEntity 中添加 detailsCount 字段
-优化 InvoiceService 中发票存在性检查逻辑
- 在 InvoiceDetailDto 和 InvoiceDetailEntity 中将 taxRate 和 tax 字段类型改为 String
This commit is contained in:
2025-02-24 22:10:15 +08:00
parent 38463e4195
commit d9fda30c3d
6 changed files with 35 additions and 8 deletions

View File

@@ -69,7 +69,6 @@ public class InvoiceController {
@PostMapping("/uploadNew")
@Operation(summary = "上传新发票")
public Object uploadNew(@RequestBody IdRequest request) {
this.service.uploadNew(request);
return true;
return this.service.uploadNew(request);
}
}

View File

@@ -98,6 +98,8 @@ public class InvoiceDto extends OrgCommonDto {
private FileEntity file;
@Comment("发票详情数量")
private Integer detailsCount;
private String archiveStatus;

View File

@@ -118,9 +118,13 @@ public class InvoiceEntity extends OrgCommonEntity {
@Comment("特殊标识信息")
private String specialTag;
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
@OneToMany(cascade = {CascadeType.PERSIST, CascadeType.REMOVE}, mappedBy = "invoice")
private List<InvoiceDetailEntity> invoiceDetails;
@Comment("发票详情数量")
private Integer detailsCount;
@ManyToOne private FileEntity file;
@Comment("归档状态")

View File

@@ -117,7 +117,27 @@ public class InvoiceService extends BaseService<InvoiceEntity, InvoiceRepository
InvoiceEntity invoice = ocr(download);
if (exists(invoice)) {
throw new BizException("发票已经存在: 发票代码 " + invoice.getInvoiceCode());
log.info("发票 已经存在", invoice.getInvoiceCode(), invoice.getInvoiceNumber());
return this.repository.findOne(
new Specification<InvoiceEntity>() {
@Override
public Predicate toPredicate(
Root<InvoiceEntity> root,
CriteriaQuery<?> query,
CriteriaBuilder criteriaBuilder) {
return criteriaBuilder.and(
criteriaBuilder.equal(
root.get("invoiceCode"), invoice.getInvoiceCode()),
criteriaBuilder.equal(
root.get("invoiceNumber"), invoice.getInvoiceNumber()),
criteriaBuilder.equal(
root.get("organizationId"),
Ctx.currentUser().getOrganizationId()));
}
});
}
if (CollectionUtils.isNotEmpty(invoice.getInvoiceDetails())) {
@@ -127,6 +147,8 @@ public class InvoiceService extends BaseService<InvoiceEntity, InvoiceRepository
detail -> {
detail.setInvoice(invoice);
});
invoice.setDetailsCount(invoice.getInvoiceDetails().size());
}
invoice.setFile(fileService.get(request.getId()));

View File

@@ -36,10 +36,10 @@ public class InvoiceDetailDto extends OrgCommonDto {
private Double amount;
@Comment("税率")
private Double taxRate;
private String taxRate;
@Comment("税额")
private Double tax;
private String tax;
private String archiveStatus;

View File

@@ -48,10 +48,10 @@ public class InvoiceDetailEntity extends OrgCommonEntity {
private Double amount;
@Comment("税率")
private Double taxRate;
private String taxRate;
@Comment("税额")
private Double tax;
private String tax;
@Comment("归档状态")
@ColumnDefault("'0'")