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 }