fixed:自动导入功能将根据表内字段自动创建created_at和updated_at的时间
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SysExportTemplateService struct {
|
||||
@@ -348,16 +349,15 @@ func (sysExportTemplateService *SysExportTemplateService) ImportExcel(templateID
|
||||
item[key] = value
|
||||
}
|
||||
|
||||
// 此处需要等待gorm修复HasColumn中的painc问题
|
||||
//needCreated := tx.Migrator().HasColumn(template.TableName, "created_at")
|
||||
//needUpdated := tx.Migrator().HasColumn(template.TableName, "updated_at")
|
||||
//
|
||||
//if item["created_at"] == nil && needCreated {
|
||||
// item["created_at"] = time.Now()
|
||||
//}
|
||||
//if item["updated_at"] == nil && needUpdated {
|
||||
// item["updated_at"] = time.Now()
|
||||
//}
|
||||
needCreated := tx.Migrator().HasColumn(template.TableName, "created_at")
|
||||
needUpdated := tx.Migrator().HasColumn(template.TableName, "updated_at")
|
||||
|
||||
if item["created_at"] == nil && needCreated {
|
||||
item["created_at"] = time.Now()
|
||||
}
|
||||
if item["updated_at"] == nil && needUpdated {
|
||||
item["updated_at"] = time.Now()
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
Reference in New Issue
Block a user