enhance(model):增加两个用于快速转换数据结构的方法。

This commit is contained in:
徐涛 2022-09-16 17:26:41 +08:00
parent dba74ecd49
commit 7ce9abe1de
2 changed files with 14 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package model
import ( import (
"time" "time"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
"github.com/uptrace/bun" "github.com/uptrace/bun"
) )
@ -64,3 +65,9 @@ type ParkPeriodStatistics struct {
Name string `bun:",notnull" json:"name"` Name string `bun:",notnull" json:"name"`
Period *time.Time `bun:"type:date" json:"period" time_format:"simple_date" time_location:"shanghai"` Period *time.Time `bun:"type:date" json:"period" time_format:"simple_date" time_location:"shanghai"`
} }
func FromPark(park Park) ParkSimplified {
dest := ParkSimplified{}
copier.Copy(&dest, park)
return dest
}

View File

@ -3,6 +3,7 @@ package model
import ( import (
"time" "time"
"github.com/jinzhu/copier"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
"github.com/uptrace/bun" "github.com/uptrace/bun"
) )
@ -45,3 +46,9 @@ type UserDetailSimplified struct {
Contact *string `json:"contact"` Contact *string `json:"contact"`
Phone *string `json:"phone"` Phone *string `json:"phone"`
} }
func FromUserDetail(user UserDetail) UserDetailSimplified {
dest := UserDetailSimplified{}
copier.Copy(&dest, user)
return dest
}