enhance(report):批量导入预置的维护费功能,会提前删除之前导入的内容。
This commit is contained in:
parent
ea929fd106
commit
f7c639cba0
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user