|
|
@@ -77,7 +77,7 @@ func InsertEntity(executor Executor, tableName string, e any) error {
|
|
|
|
|
|
executeParamsMap, err := sql.InsertExecuteParams{
|
|
|
TableName: tableName,
|
|
|
- TableRow: formInsertTableRow(fields),
|
|
|
+ TableRow: formInsertTableRow(fields, time.Now().Local()),
|
|
|
}.Map()
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -104,6 +104,7 @@ func InsertEntityBatch(executor Executor, tableName string, es []any) error {
|
|
|
return errors.New("没有传递表名")
|
|
|
}
|
|
|
|
|
|
+ now := time.Now().Local()
|
|
|
tableRowBatch := make([]sql.TableRow, 0)
|
|
|
|
|
|
for _, e := range es {
|
|
|
@@ -121,7 +122,7 @@ func InsertEntityBatch(executor Executor, tableName string, es []any) error {
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
- tableRowBatch = append(tableRowBatch, *formInsertTableRow(fields))
|
|
|
+ tableRowBatch = append(tableRowBatch, *formInsertTableRow(fields, now))
|
|
|
}
|
|
|
|
|
|
executeParamsMap, err := sql.InsertBatchExecuteParams{
|
|
|
@@ -144,15 +145,14 @@ func InsertEntityBatch(executor Executor, tableName string, es []any) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func formInsertTableRow(fields []sql_mapping.Field) *sql.TableRow {
|
|
|
- now := time.Now().Local()
|
|
|
+func formInsertTableRow(fields []sql_mapping.Field, createTime time.Time) *sql.TableRow {
|
|
|
tableRow := sql.NewTableRow()
|
|
|
|
|
|
for _, field := range fields {
|
|
|
fieldValue := reflect.ValueOf(field.Value)
|
|
|
if (field.FieldName == createdTimeFieldName || field.FieldName == lastUpdatedTimeFieldName) &&
|
|
|
reflectutils.IsValueTime(fieldValue) && fieldValue.IsZero() {
|
|
|
- field.Value = now
|
|
|
+ field.Value = createTime
|
|
|
}
|
|
|
|
|
|
tableRow.Add(field.ColumnName, field.Value)
|