修复pgsql和数据库导入bug,增加默认mod中的datatypes (#1712)

* 多文件: fix error specified more than once in PG

* Update sys_authority.go

* Update sys_authority.go

* sys_export_template.go: 导入Excel时使用批量插入提高性能

* 添加gorm.io/datatypes

---------

Co-authored-by: crazyrunsnail <fjyuan1991@163.com>
Co-authored-by: XiMo-210 <2831802697@qq.com>
This commit is contained in:
PiexlMax(奇淼
2024-04-13 18:46:58 +08:00
committed by GitHub
parent 61dd524c26
commit 4074a52b1b
6 changed files with 30 additions and 11 deletions

View File

@@ -336,6 +336,7 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
return db.Transaction(func(tx *gorm.DB) error {
excelTitle := rows[0]
values := rows[1:]
items := make([]map[string]interface{}, len(values))
for _, row := range values {
var item = make(map[string]interface{})
for ii, value := range row {
@@ -354,12 +355,10 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
// item["updated_at"] = time.Now()
//}
cErr := tx.Table(template.TableName).Create(&item).Error
if cErr != nil {
return cErr
}
items = append(items, item)
}
return nil
cErr := tx.Table(template.TableName).CreateInBatches(&items, 1000).Error
return cErr
})
}