From f7c639cba0f96c403a830b0dbbc6dbff7b4a2dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sun, 21 Aug 2022 21:31:10 +0800 Subject: [PATCH] =?UTF-8?q?enhance(report):=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=A2=84=E7=BD=AE=E7=9A=84=E7=BB=B4=E6=8A=A4=E8=B4=B9?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E4=BC=9A=E6=8F=90=E5=89=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E4=B9=8B=E5=89=8D=E5=AF=BC=E5=85=A5=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/report.go | 2 +- service/report.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/controller/report.go b/controller/report.go index 00a2165..4ac36d7 100644 --- a/controller/report.go +++ b/controller/report.go @@ -291,7 +291,7 @@ func importPredefinedMaintenanceFees(c *gin.Context) { return *fee }, ) - err = service.ReportService.BatchSaveMaintenanceFee(dilutedFees) + err = service.ReportService.BatchSaveMaintenanceFee(report.Id, dilutedFees) if err != nil { result.Error(http.StatusInternalServerError, err.Error()) return diff --git a/service/report.go b/service/report.go index 00d823e..2c716b5 100644 --- a/service/report.go +++ b/service/report.go @@ -220,13 +220,21 @@ func (_ReportService) CreateTemporaryWillDilutedMaintenanceFee(fee model.WillDil return err } -func (_ReportService) BatchSaveMaintenanceFee(fees []model.WillDilutedFee) error { +func (_ReportService) BatchSaveMaintenanceFee(reportId string, fees []model.WillDilutedFee) error { tx := global.DBConn.NewSession() if err := tx.Begin(); err != nil { return err } defer tx.Close() - _, err := tx.Insert(fees) + // 首先删除所有预定义的部分,条件是指定报表ID,SourceID不为空。 + cond := builder.Eq{"report_id": reportId}.And(builder.NotNull{"source_id"}) + _, err := tx.Table(new(model.WillDilutedFee)).Where(cond).Delete() + if err != nil { + tx.Rollback() + return err + } + // 然后插入新的记录 + _, err = tx.Insert(fees) if err != nil { return err }