作者 唐旭辉

数据同步修正

package models
import "time"
import (
"context"
"time"
"github.com/go-pg/pg/v10"
)
// 公司信息
type Company struct {
... ... @@ -30,3 +35,18 @@ type Company struct {
// 删除时间
DeleteAt time.Time
}
var _ pg.BeforeUpdateHook = (*Company)(nil)
func (c *Company) BeforeUpdate(ctx context.Context) (context.Context, error) {
c.UpdateAt = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*Company)(nil)
func (c *Company) BeforeInsert(ctx context.Context) (context.Context, error) {
c.CreateAt = time.Now()
c.UpdateAt = time.Now()
return ctx, nil
}
... ...
package models
import (
"context"
"time"
"github.com/go-pg/pg/v10"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
)
... ... @@ -31,3 +33,18 @@ type Users struct {
UpdateAt time.Time
DeleteAt time.Time
}
var _ pg.BeforeUpdateHook = (*Users)(nil)
func (user *Users) BeforeUpdate(ctx context.Context) (context.Context, error) {
user.UpdateAt = time.Now()
return ctx, nil
}
var _ pg.BeforeInsertHook = (*Users)(nil)
func (user *Users) BeforeInsert(ctx context.Context) (context.Context, error) {
user.CreateAt = time.Now()
user.UpdateAt = time.Now()
return ctx, nil
}
... ...