fixed:自动导入功能将根据表内字段自动创建created_at和updated_at的时间

This commit is contained in:
pixelMax(奇淼
2024-05-17 10:26:47 +08:00
parent 3c486d9117
commit de54688c56
5 changed files with 31 additions and 18 deletions

View File

@@ -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)
}