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

@@ -44,7 +44,7 @@ require (
gorm.io/driver/mysql v1.5.6
gorm.io/driver/postgres v1.5.7
gorm.io/driver/sqlserver v1.5.1
gorm.io/gorm v1.25.9
gorm.io/gorm v1.25.10
nhooyr.io/websocket v1.8.7
)

View File

@@ -864,8 +864,8 @@ gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk=
gorm.io/gorm v1.24.3/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA=
gorm.io/gorm v1.25.1/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8=
gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/gorm v1.25.10 h1:dQpO+33KalOA+aFYGlK+EfxcI5MbO7EP2yYygwh9h+s=
gorm.io/gorm v1.25.10/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
gorm.io/plugin/dbresolver v1.4.1 h1:Ug4LcoPhrvqq71UhxtF346f+skTYoCa/nEsdjvHwEzk=
gorm.io/plugin/dbresolver v1.4.1/go.mod h1:CTbCtMWhsjXSiJqiW2R8POvJ2cq18RVOl4WGyT5nhNc=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

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